tokvista 1.7.0 → 1.7.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/bin/tokvista.js +36 -10
- package/package.json +1 -1
package/dist/bin/tokvista.js
CHANGED
|
@@ -821,17 +821,35 @@ function isTokenLike2(obj) {
|
|
|
821
821
|
return isRecord4(obj) && "value" in obj;
|
|
822
822
|
}
|
|
823
823
|
function isValidColor(value) {
|
|
824
|
-
return /^#([0-9A-F]{3}|[0-9A-F]{6}|[0-9A-F]{8})$/i.test(value) || /^rgb\(/.test(value) || /^rgba\(/.test(value) || /^hsl\(/.test(value) || /^hsla\(/.test(value);
|
|
824
|
+
return /^#([0-9A-F]{3}|[0-9A-F]{6}|[0-9A-F]{8})$/i.test(value) || /^rgb\(/.test(value) || /^rgba\(/.test(value) || /^hsl\(/.test(value) || /^hsla\(/.test(value) || value === "transparent" || value === "currentColor";
|
|
825
825
|
}
|
|
826
826
|
function isValidDimension(value) {
|
|
827
|
-
return /^\d+(\.\d+)?(px|rem|em|%|vh|vw)$/.test(value);
|
|
827
|
+
return /^\d+(\.\d+)?(px|rem|em|%|vh|vw)$/.test(value) || value === "0";
|
|
828
|
+
}
|
|
829
|
+
function buildTokenMap(tokens) {
|
|
830
|
+
const tokenPaths = /* @__PURE__ */ new Set();
|
|
831
|
+
function walk(node, path2 = []) {
|
|
832
|
+
if (!isRecord4(node)) return;
|
|
833
|
+
if (path2.length === 0 && Object.keys(node).some((k) => k.includes("/"))) {
|
|
834
|
+
Object.values(node).forEach((val) => walk(val, []));
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
if (isTokenLike2(node)) {
|
|
838
|
+
tokenPaths.add(path2.join("."));
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
Object.entries(node).forEach(([key, val]) => {
|
|
842
|
+
walk(val, [...path2, key]);
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
walk(tokens);
|
|
846
|
+
return tokenPaths;
|
|
828
847
|
}
|
|
829
848
|
function validateTokens(tokens) {
|
|
830
849
|
const errors = [];
|
|
831
850
|
const warnings = [];
|
|
832
851
|
let totalTokens = 0;
|
|
833
|
-
const allAliases =
|
|
834
|
-
const definedTokens = /* @__PURE__ */ new Set();
|
|
852
|
+
const allAliases = [];
|
|
835
853
|
if (!isRecord4(tokens)) {
|
|
836
854
|
return {
|
|
837
855
|
valid: false,
|
|
@@ -840,12 +858,20 @@ function validateTokens(tokens) {
|
|
|
840
858
|
totalTokens: 0
|
|
841
859
|
};
|
|
842
860
|
}
|
|
861
|
+
const detection = detectTokenFormat(tokens);
|
|
862
|
+
let normalizedTokens = tokens;
|
|
863
|
+
if (detection.format !== "token-studio" && detection.format !== "unknown") {
|
|
864
|
+
normalizedTokens = normalizeTokenFormat(tokens, detection.format);
|
|
865
|
+
}
|
|
843
866
|
function walk(node, path2 = []) {
|
|
844
867
|
if (!isRecord4(node)) return;
|
|
868
|
+
if (path2.length === 0 && Object.keys(node).some((k) => k.includes("/"))) {
|
|
869
|
+
Object.values(node).forEach((val) => walk(val, []));
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
845
872
|
if (isTokenLike2(node)) {
|
|
846
873
|
totalTokens++;
|
|
847
874
|
const tokenPath = path2.join(".");
|
|
848
|
-
definedTokens.add(tokenPath);
|
|
849
875
|
if (!node.type) {
|
|
850
876
|
warnings.push({
|
|
851
877
|
type: "warning",
|
|
@@ -863,7 +889,7 @@ function validateTokens(tokens) {
|
|
|
863
889
|
}
|
|
864
890
|
const value = String(node.value);
|
|
865
891
|
if (value.match(/^\{(.+)\}$/)) {
|
|
866
|
-
allAliases.
|
|
892
|
+
allAliases.push({ tokenPath, reference: value });
|
|
867
893
|
}
|
|
868
894
|
if (node.type === "color" && !value.startsWith("{")) {
|
|
869
895
|
if (!isValidColor(value)) {
|
|
@@ -889,10 +915,10 @@ function validateTokens(tokens) {
|
|
|
889
915
|
walk(val, [...path2, key]);
|
|
890
916
|
});
|
|
891
917
|
}
|
|
892
|
-
walk(
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
const refPath = reference.slice(1, -1)
|
|
918
|
+
walk(normalizedTokens);
|
|
919
|
+
const definedTokens = buildTokenMap(normalizedTokens);
|
|
920
|
+
allAliases.forEach(({ tokenPath, reference }) => {
|
|
921
|
+
const refPath = reference.slice(1, -1);
|
|
896
922
|
if (!definedTokens.has(refPath)) {
|
|
897
923
|
errors.push({
|
|
898
924
|
type: "error",
|