@bamboocss/token-dictionary 1.56.7 → 1.57.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.cjs +51 -27
- package/dist/index.mjs +51 -27
- package/package.json +7 -4
package/dist/index.cjs
CHANGED
|
@@ -37,7 +37,7 @@ const isCompositeShadow = (0, ts_pattern.isMatching)({
|
|
|
37
37
|
});
|
|
38
38
|
const isCompositeGradient = (0, ts_pattern.isMatching)({
|
|
39
39
|
type: ts_pattern.P.string,
|
|
40
|
-
placement: ts_pattern.P.string,
|
|
40
|
+
placement: ts_pattern.P.union(ts_pattern.P.string, ts_pattern.P.number),
|
|
41
41
|
stops: ts_pattern.P.union(ts_pattern.P.array(ts_pattern.P.string), ts_pattern.P.array({
|
|
42
42
|
color: ts_pattern.P.string,
|
|
43
43
|
position: ts_pattern.P.number
|
|
@@ -181,7 +181,7 @@ var Token = class Token {
|
|
|
181
181
|
this.path = input.path ?? [];
|
|
182
182
|
if (input.type) this.type = input.type;
|
|
183
183
|
if (input.description) this.description = input.description;
|
|
184
|
-
this.extensions = input.extensions
|
|
184
|
+
this.extensions = { ...input.extensions };
|
|
185
185
|
this.extensions.condition = input.extensions?.condition ?? "base";
|
|
186
186
|
this.deprecated = input.deprecated;
|
|
187
187
|
this.setType();
|
|
@@ -247,6 +247,7 @@ var Token = class Token {
|
|
|
247
247
|
type: this.type,
|
|
248
248
|
path: [...this.path],
|
|
249
249
|
description: this.description,
|
|
250
|
+
deprecated: this.deprecated,
|
|
250
251
|
extensions: cloneDeep(this.extensions)
|
|
251
252
|
});
|
|
252
253
|
}
|
|
@@ -550,27 +551,42 @@ function toUnit(v) {
|
|
|
550
551
|
function px(v) {
|
|
551
552
|
return (0, _bamboocss_shared.isString)(v) ? v : `${v}px`;
|
|
552
553
|
}
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
].filter(Boolean).join(" ");
|
|
570
|
-
}
|
|
571
|
-
return token.value;
|
|
554
|
+
const transformShadow = {
|
|
555
|
+
name: "tokens/shadow",
|
|
556
|
+
match: (token) => token.extensions.category === "shadows",
|
|
557
|
+
transform(token, dict) {
|
|
558
|
+
if ((0, _bamboocss_shared.isString)(token.value)) return token.value;
|
|
559
|
+
if (Array.isArray(token.value)) return token.value.map((value) => this.transform({ value }, dict)).join(", ");
|
|
560
|
+
if (isCompositeShadow(token.value)) {
|
|
561
|
+
const { offsetX, offsetY, blur, spread, color, inset } = token.value;
|
|
562
|
+
return [
|
|
563
|
+
inset ? "inset " : "",
|
|
564
|
+
px(offsetX),
|
|
565
|
+
px(offsetY),
|
|
566
|
+
px(blur),
|
|
567
|
+
px(spread),
|
|
568
|
+
color
|
|
569
|
+
].filter(Boolean).join(" ");
|
|
572
570
|
}
|
|
573
|
-
|
|
571
|
+
return token.value;
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
/**
|
|
575
|
+
* A numeric `placement`, as an angle in degrees: what `linear-gradient(90deg, …)` takes first, and
|
|
576
|
+
* `conic-gradient(from 90deg, …)` after `from`. It matched no composite gradient before, and the
|
|
577
|
+
* token reached the stylesheet as an object.
|
|
578
|
+
*
|
|
579
|
+
* A radial gradient has no angle — it is placed with a shape and a position, `'circle at top'` —
|
|
580
|
+
* so a number there is an error rather than css the browser drops without a word.
|
|
581
|
+
*/
|
|
582
|
+
const gradientAngle = (name, type, placement) => {
|
|
583
|
+
if (!Number.isFinite(placement)) throw new _bamboocss_shared.BambooError("INVALID_TOKEN", `The gradient \`${name}\` has a \`placement\` of ${placement}, which is no angle.`);
|
|
584
|
+
if (type === "linear" || type === "repeating-linear") return `${placement}deg`;
|
|
585
|
+
if (type === "conic" || type === "repeating-conic") return `from ${placement}deg`;
|
|
586
|
+
throw new _bamboocss_shared.BambooError("INVALID_TOKEN", `The ${type} gradient \`${name}\` has a numeric \`placement\`, and only a linear or conic gradient takes an angle. Place a ${type} gradient with a shape and a position, like \`'circle at top'\`.`);
|
|
587
|
+
};
|
|
588
|
+
const transforms = [
|
|
589
|
+
transformShadow,
|
|
574
590
|
{
|
|
575
591
|
name: "tokens/gradient",
|
|
576
592
|
match: (token) => token.extensions.category === "gradients",
|
|
@@ -578,11 +594,12 @@ const transforms = [
|
|
|
578
594
|
if ((0, _bamboocss_shared.isString)(token.value)) return token.value;
|
|
579
595
|
if (isCompositeGradient(token.value)) {
|
|
580
596
|
const { type, stops, placement } = token.value;
|
|
581
|
-
|
|
597
|
+
const rawStops = stops.map((stop) => {
|
|
582
598
|
if ((0, _bamboocss_shared.isString)(stop)) return stop;
|
|
583
599
|
const { color, position } = stop;
|
|
584
600
|
return `${color} ${position}px`;
|
|
585
|
-
})
|
|
601
|
+
});
|
|
602
|
+
return `${type}-gradient(${typeof placement === "number" ? gradientAngle(token.name, type, placement) : placement}, ${rawStops.join(", ")})`;
|
|
586
603
|
}
|
|
587
604
|
return token.value;
|
|
588
605
|
}
|
|
@@ -919,7 +936,8 @@ var TokenDictionary = class {
|
|
|
919
936
|
assertTokenFormat(token);
|
|
920
937
|
const category = path[0];
|
|
921
938
|
const name = this.formatTokenName(path);
|
|
922
|
-
const { value, ...restData } =
|
|
939
|
+
const { value: written, ...restData } = token;
|
|
940
|
+
const value = (0, _bamboocss_shared.isString)(written) || typeof written === "number" || isCompositeTokenValue(written) ? { base: written } : written;
|
|
923
941
|
const node = new Token({
|
|
924
942
|
...restData,
|
|
925
943
|
name,
|
|
@@ -928,6 +946,7 @@ var TokenDictionary = class {
|
|
|
928
946
|
});
|
|
929
947
|
node.setExtensions({
|
|
930
948
|
category,
|
|
949
|
+
condition: "base",
|
|
931
950
|
conditions: value,
|
|
932
951
|
rawValue: value,
|
|
933
952
|
prop: this.formatTokenName(path.slice(1))
|
|
@@ -945,8 +964,13 @@ var TokenDictionary = class {
|
|
|
945
964
|
}, { stop: isToken });
|
|
946
965
|
Object.entries(themes).forEach(([theme, themeVariant]) => {
|
|
947
966
|
const condName = "_theme" + (0, _bamboocss_shared.capitalize)(theme);
|
|
967
|
+
const themeToken = (token) => ({
|
|
968
|
+
value: { [condName]: token.value },
|
|
969
|
+
...token.description !== void 0 && { description: token.description },
|
|
970
|
+
...token.deprecated !== void 0 && { deprecated: token.deprecated }
|
|
971
|
+
});
|
|
948
972
|
(0, _bamboocss_shared.walkObject)(themeVariant.tokens ?? {}, (token, path) => {
|
|
949
|
-
const node = processSemantic(
|
|
973
|
+
const node = processSemantic(themeToken(token), path);
|
|
950
974
|
node.setExtensions({
|
|
951
975
|
theme,
|
|
952
976
|
isVirtual: true
|
|
@@ -954,7 +978,7 @@ var TokenDictionary = class {
|
|
|
954
978
|
this.registerToken(node);
|
|
955
979
|
}, { stop: isToken });
|
|
956
980
|
(0, _bamboocss_shared.walkObject)(themeVariant.semanticTokens ?? {}, (token, path) => {
|
|
957
|
-
const node = processSemantic(
|
|
981
|
+
const node = processSemantic(themeToken(token), path);
|
|
958
982
|
node.setExtensions({
|
|
959
983
|
theme,
|
|
960
984
|
isSemantic: true,
|
package/dist/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ const isCompositeShadow = isMatching({
|
|
|
13
13
|
});
|
|
14
14
|
const isCompositeGradient = isMatching({
|
|
15
15
|
type: P.string,
|
|
16
|
-
placement: P.string,
|
|
16
|
+
placement: P.union(P.string, P.number),
|
|
17
17
|
stops: P.union(P.array(P.string), P.array({
|
|
18
18
|
color: P.string,
|
|
19
19
|
position: P.number
|
|
@@ -157,7 +157,7 @@ var Token = class Token {
|
|
|
157
157
|
this.path = input.path ?? [];
|
|
158
158
|
if (input.type) this.type = input.type;
|
|
159
159
|
if (input.description) this.description = input.description;
|
|
160
|
-
this.extensions = input.extensions
|
|
160
|
+
this.extensions = { ...input.extensions };
|
|
161
161
|
this.extensions.condition = input.extensions?.condition ?? "base";
|
|
162
162
|
this.deprecated = input.deprecated;
|
|
163
163
|
this.setType();
|
|
@@ -223,6 +223,7 @@ var Token = class Token {
|
|
|
223
223
|
type: this.type,
|
|
224
224
|
path: [...this.path],
|
|
225
225
|
description: this.description,
|
|
226
|
+
deprecated: this.deprecated,
|
|
226
227
|
extensions: cloneDeep(this.extensions)
|
|
227
228
|
});
|
|
228
229
|
}
|
|
@@ -526,27 +527,42 @@ function toUnit(v) {
|
|
|
526
527
|
function px(v) {
|
|
527
528
|
return isString(v) ? v : `${v}px`;
|
|
528
529
|
}
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
].filter(Boolean).join(" ");
|
|
546
|
-
}
|
|
547
|
-
return token.value;
|
|
530
|
+
const transformShadow = {
|
|
531
|
+
name: "tokens/shadow",
|
|
532
|
+
match: (token) => token.extensions.category === "shadows",
|
|
533
|
+
transform(token, dict) {
|
|
534
|
+
if (isString(token.value)) return token.value;
|
|
535
|
+
if (Array.isArray(token.value)) return token.value.map((value) => this.transform({ value }, dict)).join(", ");
|
|
536
|
+
if (isCompositeShadow(token.value)) {
|
|
537
|
+
const { offsetX, offsetY, blur, spread, color, inset } = token.value;
|
|
538
|
+
return [
|
|
539
|
+
inset ? "inset " : "",
|
|
540
|
+
px(offsetX),
|
|
541
|
+
px(offsetY),
|
|
542
|
+
px(blur),
|
|
543
|
+
px(spread),
|
|
544
|
+
color
|
|
545
|
+
].filter(Boolean).join(" ");
|
|
548
546
|
}
|
|
549
|
-
|
|
547
|
+
return token.value;
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
/**
|
|
551
|
+
* A numeric `placement`, as an angle in degrees: what `linear-gradient(90deg, …)` takes first, and
|
|
552
|
+
* `conic-gradient(from 90deg, …)` after `from`. It matched no composite gradient before, and the
|
|
553
|
+
* token reached the stylesheet as an object.
|
|
554
|
+
*
|
|
555
|
+
* A radial gradient has no angle — it is placed with a shape and a position, `'circle at top'` —
|
|
556
|
+
* so a number there is an error rather than css the browser drops without a word.
|
|
557
|
+
*/
|
|
558
|
+
const gradientAngle = (name, type, placement) => {
|
|
559
|
+
if (!Number.isFinite(placement)) throw new BambooError("INVALID_TOKEN", `The gradient \`${name}\` has a \`placement\` of ${placement}, which is no angle.`);
|
|
560
|
+
if (type === "linear" || type === "repeating-linear") return `${placement}deg`;
|
|
561
|
+
if (type === "conic" || type === "repeating-conic") return `from ${placement}deg`;
|
|
562
|
+
throw new BambooError("INVALID_TOKEN", `The ${type} gradient \`${name}\` has a numeric \`placement\`, and only a linear or conic gradient takes an angle. Place a ${type} gradient with a shape and a position, like \`'circle at top'\`.`);
|
|
563
|
+
};
|
|
564
|
+
const transforms = [
|
|
565
|
+
transformShadow,
|
|
550
566
|
{
|
|
551
567
|
name: "tokens/gradient",
|
|
552
568
|
match: (token) => token.extensions.category === "gradients",
|
|
@@ -554,11 +570,12 @@ const transforms = [
|
|
|
554
570
|
if (isString(token.value)) return token.value;
|
|
555
571
|
if (isCompositeGradient(token.value)) {
|
|
556
572
|
const { type, stops, placement } = token.value;
|
|
557
|
-
|
|
573
|
+
const rawStops = stops.map((stop) => {
|
|
558
574
|
if (isString(stop)) return stop;
|
|
559
575
|
const { color, position } = stop;
|
|
560
576
|
return `${color} ${position}px`;
|
|
561
|
-
})
|
|
577
|
+
});
|
|
578
|
+
return `${type}-gradient(${typeof placement === "number" ? gradientAngle(token.name, type, placement) : placement}, ${rawStops.join(", ")})`;
|
|
562
579
|
}
|
|
563
580
|
return token.value;
|
|
564
581
|
}
|
|
@@ -895,7 +912,8 @@ var TokenDictionary = class {
|
|
|
895
912
|
assertTokenFormat(token);
|
|
896
913
|
const category = path[0];
|
|
897
914
|
const name = this.formatTokenName(path);
|
|
898
|
-
const { value, ...restData } =
|
|
915
|
+
const { value: written, ...restData } = token;
|
|
916
|
+
const value = isString(written) || typeof written === "number" || isCompositeTokenValue(written) ? { base: written } : written;
|
|
899
917
|
const node = new Token({
|
|
900
918
|
...restData,
|
|
901
919
|
name,
|
|
@@ -904,6 +922,7 @@ var TokenDictionary = class {
|
|
|
904
922
|
});
|
|
905
923
|
node.setExtensions({
|
|
906
924
|
category,
|
|
925
|
+
condition: "base",
|
|
907
926
|
conditions: value,
|
|
908
927
|
rawValue: value,
|
|
909
928
|
prop: this.formatTokenName(path.slice(1))
|
|
@@ -921,8 +940,13 @@ var TokenDictionary = class {
|
|
|
921
940
|
}, { stop: isToken });
|
|
922
941
|
Object.entries(themes).forEach(([theme, themeVariant]) => {
|
|
923
942
|
const condName = "_theme" + capitalize(theme);
|
|
943
|
+
const themeToken = (token) => ({
|
|
944
|
+
value: { [condName]: token.value },
|
|
945
|
+
...token.description !== void 0 && { description: token.description },
|
|
946
|
+
...token.deprecated !== void 0 && { deprecated: token.deprecated }
|
|
947
|
+
});
|
|
924
948
|
walkObject(themeVariant.tokens ?? {}, (token, path) => {
|
|
925
|
-
const node = processSemantic(
|
|
949
|
+
const node = processSemantic(themeToken(token), path);
|
|
926
950
|
node.setExtensions({
|
|
927
951
|
theme,
|
|
928
952
|
isVirtual: true
|
|
@@ -930,7 +954,7 @@ var TokenDictionary = class {
|
|
|
930
954
|
this.registerToken(node);
|
|
931
955
|
}, { stop: isToken });
|
|
932
956
|
walkObject(themeVariant.semanticTokens ?? {}, (token, path) => {
|
|
933
|
-
const node = processSemantic(
|
|
957
|
+
const node = processSemantic(themeToken(token), path);
|
|
934
958
|
node.setExtensions({
|
|
935
959
|
theme,
|
|
936
960
|
isSemantic: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/token-dictionary",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.57.1",
|
|
4
4
|
"description": "Common error messages for css bamboo",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,13 +35,16 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"picomatch": "4.0.5",
|
|
37
37
|
"ts-pattern": "5.9.0",
|
|
38
|
-
"@bamboocss/logger": "^1.
|
|
39
|
-
"@bamboocss/
|
|
40
|
-
"@bamboocss/
|
|
38
|
+
"@bamboocss/logger": "^1.57.1",
|
|
39
|
+
"@bamboocss/shared": "1.57.1",
|
|
40
|
+
"@bamboocss/types": "1.57.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/picomatch": "4.0.2"
|
|
44
44
|
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=22.12.0"
|
|
47
|
+
},
|
|
45
48
|
"scripts": {
|
|
46
49
|
"build": "tsdown src/index.ts --format=esm,cjs --dts",
|
|
47
50
|
"build-fast": "tsdown --dts=false src/index.ts --format=esm,cjs",
|