@design-factory/tokens 21.0.0-next.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/LICENSE +26 -0
- package/README.md +13 -0
- package/config.cjs +200 -0
- package/config.d.ts +58 -0
- package/config.js +200 -0
- package/css/root-dark.css +1447 -0
- package/css/root-light.css +1447 -0
- package/figma/t0.json +350 -0
- package/figma/t1.json +608 -0
- package/figma/t2-dark.json +4702 -0
- package/figma/t2-light.json +4702 -0
- package/figma/t3.json +3416 -0
- package/package.json +26 -0
- package/scss/root.scss +1444 -0
- package/scss/vars-dark.scss +1509 -0
- package/scss/vars-light.scss +1509 -0
- package/utils.d.ts +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright Amadeus SAS
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
4
|
+
are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
7
|
+
list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
|
11
|
+
other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
+
may be used to endorse or promote products derived from this software without
|
|
15
|
+
specific prior written permission.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
21
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
24
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<h1 align="center">Amadeus Design Factory Tokens</h1>
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
Design Factory Tokens is the package containing the Design Tokens used by Amadeus Design System, Design Factory.
|
|
6
|
+
|
|
7
|
+
## Exports
|
|
8
|
+
|
|
9
|
+
The package `@design-factory/tokens` exports the following entry points to interact with tokens:
|
|
10
|
+
|
|
11
|
+
- `@design-factory/tokens/figma/*.json` lists all tokens in a JSON format, by tier (t0, t1, t2 and t3)
|
|
12
|
+
- `@design-factory/tokens/style-dictionary-config` exposes the style-dictionary utilities that can be used to customize the DF theme
|
|
13
|
+
- `@design-factory/tokens/scss/*` exposes the sass vars, root css vars and bs mapping
|
package/config.cjs
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const StyleDictionary = require("style-dictionary");
|
|
4
|
+
const enums = require("style-dictionary/enums");
|
|
5
|
+
const utils = require("style-dictionary/utils");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
const tier3ScopingMap = {
|
|
8
|
+
button: `.btn,${os.EOL} .btn-close`,
|
|
9
|
+
//needing .btn-close because the alert uses it// TODO: remove when wrapping alert
|
|
10
|
+
badge: ".badge",
|
|
11
|
+
footer: ".df-app-footer",
|
|
12
|
+
navbar: ".navbar",
|
|
13
|
+
link: `a,${os.EOL} .df-app-footer,${os.EOL} button.df-collapse,${os.EOL} .breadcrumb`
|
|
14
|
+
//collapse is a button styled as a link
|
|
15
|
+
};
|
|
16
|
+
const splitTokens = (allTokens) => {
|
|
17
|
+
const rootTokens = [];
|
|
18
|
+
const tier3Tokens = [];
|
|
19
|
+
allTokens.forEach((token) => {
|
|
20
|
+
if (token.path[1] && Object.keys(tier3ScopingMap).includes(token.path[1])) {
|
|
21
|
+
tier3Tokens.push(token);
|
|
22
|
+
} else {
|
|
23
|
+
rootTokens.push(token);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const groupedT3 = tier3Tokens.reduce(
|
|
27
|
+
(acc, token) => {
|
|
28
|
+
const key = token.path[1];
|
|
29
|
+
if (acc[key]) {
|
|
30
|
+
acc[key].push(token);
|
|
31
|
+
} else {
|
|
32
|
+
acc[key] = [token];
|
|
33
|
+
}
|
|
34
|
+
return acc;
|
|
35
|
+
},
|
|
36
|
+
{}
|
|
37
|
+
);
|
|
38
|
+
return { rootTokens, groupedT3 };
|
|
39
|
+
};
|
|
40
|
+
const FONT_WEIGHT_FIGMA2CSS = {
|
|
41
|
+
light: "300",
|
|
42
|
+
regular: "400",
|
|
43
|
+
medium: "500",
|
|
44
|
+
bold: "700"
|
|
45
|
+
};
|
|
46
|
+
const transforms = {
|
|
47
|
+
/**
|
|
48
|
+
* Transform used to quote wrap font-family tokens.
|
|
49
|
+
* This is required as the font-family tokens exported from the Figma Plugin do not have the proper $type.
|
|
50
|
+
*/
|
|
51
|
+
fontFamily: "@design-factory/font-family",
|
|
52
|
+
/**
|
|
53
|
+
* Transform used to map font-weight tokens into useable css values.
|
|
54
|
+
* This is required as the font-weight tokens exported from the Figma Plugin do not have the proper $type.
|
|
55
|
+
*/
|
|
56
|
+
fontWeight: "@design-factory/font-weight",
|
|
57
|
+
/**
|
|
58
|
+
* Transform used to create token names based on DF token naming convention.
|
|
59
|
+
*/
|
|
60
|
+
tokenName: "@design-factory/token-name"
|
|
61
|
+
};
|
|
62
|
+
const transformGroups = {
|
|
63
|
+
/**
|
|
64
|
+
* Transform group that applies standard scss transforms and custom Design Factory transforms.
|
|
65
|
+
*/
|
|
66
|
+
designFactory: "@design-factory"
|
|
67
|
+
};
|
|
68
|
+
const filters = {
|
|
69
|
+
/**
|
|
70
|
+
* Filter removing invalid font-weight tokens. Should be used with {@link formats.scssVars}
|
|
71
|
+
*/
|
|
72
|
+
scssVars: "@design-factory/scss-vars-filter",
|
|
73
|
+
/**
|
|
74
|
+
* Filter removing invalid font-weight tokens and t0 tokens. Should be used with {@link formats.cssRoot}
|
|
75
|
+
*/
|
|
76
|
+
cssRoot: "@design-factory/root-filter"
|
|
77
|
+
};
|
|
78
|
+
const formats = {
|
|
79
|
+
/**
|
|
80
|
+
* Format to print a sass file containing tokens as sass variables. Should be used with {@link filters.scssVars}
|
|
81
|
+
*/
|
|
82
|
+
scssVars: "@design-factory/scss-vars",
|
|
83
|
+
/**
|
|
84
|
+
* Format to print a css file printing tokens as css variables. Should be used with {@link filters.cssRoot}
|
|
85
|
+
*/
|
|
86
|
+
cssRoot: "@design-factory/css-root"
|
|
87
|
+
};
|
|
88
|
+
const registerDf = () => {
|
|
89
|
+
StyleDictionary.registerTransform({
|
|
90
|
+
name: transforms.fontFamily,
|
|
91
|
+
type: enums.transformTypes.value,
|
|
92
|
+
filter: (token) => token.name.includes("-font-") && (token.name.includes("family") || token.name.includes("Family")),
|
|
93
|
+
transform: (token) => `'${token.$value}'`
|
|
94
|
+
});
|
|
95
|
+
StyleDictionary.registerTransform({
|
|
96
|
+
name: transforms.fontWeight,
|
|
97
|
+
type: enums.transformTypes.value,
|
|
98
|
+
filter: (token) => token.name.startsWith("df-typo-weight-"),
|
|
99
|
+
transform: (token) => FONT_WEIGHT_FIGMA2CSS[token.$value.trim().toLowerCase()] || token.$value
|
|
100
|
+
});
|
|
101
|
+
StyleDictionary.registerTransform({
|
|
102
|
+
name: transforms.tokenName,
|
|
103
|
+
type: enums.transformTypes.name,
|
|
104
|
+
transform: (token) => token.path.join("-")
|
|
105
|
+
});
|
|
106
|
+
StyleDictionary.registerTransformGroup({
|
|
107
|
+
name: transformGroups.designFactory,
|
|
108
|
+
transforms: [
|
|
109
|
+
enums.transforms.attributeCti,
|
|
110
|
+
transforms.tokenName,
|
|
111
|
+
enums.transforms.timeSeconds,
|
|
112
|
+
enums.transforms.htmlIcon,
|
|
113
|
+
enums.transforms.sizeRem,
|
|
114
|
+
enums.transforms.sizePxToRem,
|
|
115
|
+
enums.transforms.colorCss,
|
|
116
|
+
enums.transforms.assetUrl,
|
|
117
|
+
transforms.fontFamily,
|
|
118
|
+
transforms.fontWeight,
|
|
119
|
+
enums.transforms.cubicBezierCss,
|
|
120
|
+
// object-value tokens
|
|
121
|
+
enums.transforms.strokeStyleCssShorthand,
|
|
122
|
+
enums.transforms.borderCssShorthand,
|
|
123
|
+
enums.transforms.typographyCssShorthand,
|
|
124
|
+
enums.transforms.transitionCssShorthand,
|
|
125
|
+
enums.transforms.shadowCssShorthand
|
|
126
|
+
]
|
|
127
|
+
});
|
|
128
|
+
StyleDictionary.registerFilter({
|
|
129
|
+
name: filters.scssVars,
|
|
130
|
+
filter: (token) => !token.name.endsWith("Italic")
|
|
131
|
+
});
|
|
132
|
+
StyleDictionary.registerFilter({
|
|
133
|
+
name: filters.cssRoot,
|
|
134
|
+
filter: (token) => !token.name.endsWith("Italic") && !token.name.startsWith("df-colorPalette")
|
|
135
|
+
});
|
|
136
|
+
StyleDictionary.registerFormat({
|
|
137
|
+
name: formats.scssVars,
|
|
138
|
+
format: async ({ dictionary, options, file }) => {
|
|
139
|
+
const { usesDtcg, withDefault, outputReferences } = options;
|
|
140
|
+
const header = await utils.fileHeader({
|
|
141
|
+
file,
|
|
142
|
+
formatting: { lineSeparator: os.EOL, header: `/**${os.EOL}`, footer: `${os.EOL} */${os.EOL}${os.EOL}` }
|
|
143
|
+
});
|
|
144
|
+
const tokens = dictionary.tokens;
|
|
145
|
+
let allTokens = dictionary.allTokens;
|
|
146
|
+
allTokens = [...allTokens].filter((token) => !token.name.startsWith("internal-")).sort(utils.sortByReference(tokens, { unfilteredTokens: dictionary.unfilteredTokens, usesDtcg }));
|
|
147
|
+
return header + allTokens.reduce((acc, token) => {
|
|
148
|
+
let value = token.$value;
|
|
149
|
+
if (outputReferences && utils.usesReferences(token.original.$value)) {
|
|
150
|
+
let originalValue = token.original.$value;
|
|
151
|
+
while (originalValue.startsWith("{internal.df.")) {
|
|
152
|
+
originalValue = dictionary.tokenMap.get(originalValue).original.$value;
|
|
153
|
+
}
|
|
154
|
+
value = `var(--${originalValue.slice(1, -1).replace(/\./g, "-")})`;
|
|
155
|
+
}
|
|
156
|
+
return `${acc}$${token.name}: ${value}${withDefault ? " !default" : ""};${os.EOL}`;
|
|
157
|
+
}, "");
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
StyleDictionary.registerFormat({
|
|
161
|
+
name: formats.cssRoot,
|
|
162
|
+
format: async ({ dictionary, options, file }) => {
|
|
163
|
+
const { usesDtcg, outputReferences, selector = "html:root" } = options;
|
|
164
|
+
const header = await utils.fileHeader({
|
|
165
|
+
file,
|
|
166
|
+
formatting: { lineSeparator: os.EOL, header: `/**${os.EOL}`, footer: `${os.EOL} */${os.EOL}${os.EOL}` }
|
|
167
|
+
});
|
|
168
|
+
const tokens = dictionary.tokens;
|
|
169
|
+
let allTokens = dictionary.allTokens;
|
|
170
|
+
allTokens = [...allTokens].filter((token) => !token.name.startsWith("internal-")).sort(utils.sortByReference(tokens, { unfilteredTokens: dictionary.unfilteredTokens, usesDtcg }));
|
|
171
|
+
const { rootTokens, groupedT3 } = splitTokens(allTokens);
|
|
172
|
+
const getValueName = (token) => {
|
|
173
|
+
let value = token.$value;
|
|
174
|
+
if (outputReferences && utils.usesReferences(token.original.$value)) {
|
|
175
|
+
let originalValue = token.original.$value;
|
|
176
|
+
while (originalValue.startsWith("{internal.df.")) {
|
|
177
|
+
originalValue = dictionary.tokenMap.get(originalValue).original.$value;
|
|
178
|
+
}
|
|
179
|
+
value = `var(--${originalValue.slice(1, -1).replace(/\./g, "-")})`;
|
|
180
|
+
}
|
|
181
|
+
return { value, name: token.name };
|
|
182
|
+
};
|
|
183
|
+
const colorScheme = dictionary.tokenMap.get("{internal.scheme}");
|
|
184
|
+
return `${header}${selector} {${os.EOL}` + (colorScheme?.$value ? ` color-scheme: ${colorScheme.$value};${os.EOL}${os.EOL}` : "") + rootTokens.reduce((acc, token) => {
|
|
185
|
+
const { value, name } = getValueName(token);
|
|
186
|
+
return `${acc} --${name}: ${value};${os.EOL}`;
|
|
187
|
+
}, "") + (Object.keys(groupedT3).length ? `${os.EOL} /* Tier 3 Scoped tokens */${os.EOL}` + Object.entries(groupedT3).reduce((acc, [key, tokens2]) => {
|
|
188
|
+
return `${acc} ${tier3ScopingMap[key]} {${os.EOL}` + tokens2.reduce((innerAcc, token) => {
|
|
189
|
+
const { value, name } = getValueName(token);
|
|
190
|
+
return `${innerAcc} --${name}: ${value};${os.EOL}`;
|
|
191
|
+
}, "") + ` }${os.EOL}`;
|
|
192
|
+
}, "") : "") + `}${os.EOL}`;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
exports.filters = filters;
|
|
197
|
+
exports.formats = formats;
|
|
198
|
+
exports.registerDf = registerDf;
|
|
199
|
+
exports.transformGroups = transformGroups;
|
|
200
|
+
exports.transforms = transforms;
|
package/config.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Design Factory custom Style-Dictionary transforms
|
|
3
|
+
*/
|
|
4
|
+
export declare const transforms: {
|
|
5
|
+
/**
|
|
6
|
+
* Transform used to quote wrap font-family tokens.
|
|
7
|
+
* This is required as the font-family tokens exported from the Figma Plugin do not have the proper $type.
|
|
8
|
+
*/
|
|
9
|
+
readonly fontFamily: "@design-factory/font-family";
|
|
10
|
+
/**
|
|
11
|
+
* Transform used to map font-weight tokens into useable css values.
|
|
12
|
+
* This is required as the font-weight tokens exported from the Figma Plugin do not have the proper $type.
|
|
13
|
+
*/
|
|
14
|
+
readonly fontWeight: "@design-factory/font-weight";
|
|
15
|
+
/**
|
|
16
|
+
* Transform used to create token names based on DF token naming convention.
|
|
17
|
+
*/
|
|
18
|
+
readonly tokenName: "@design-factory/token-name";
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Design Factory custom Style-Dictionary transform group
|
|
22
|
+
*/
|
|
23
|
+
export declare const transformGroups: {
|
|
24
|
+
/**
|
|
25
|
+
* Transform group that applies standard scss transforms and custom Design Factory transforms.
|
|
26
|
+
*/
|
|
27
|
+
readonly designFactory: "@design-factory";
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Design Factory custom Style-Dictionary filters
|
|
31
|
+
*/
|
|
32
|
+
export declare const filters: {
|
|
33
|
+
/**
|
|
34
|
+
* Filter removing invalid font-weight tokens. Should be used with {@link formats.scssVars}
|
|
35
|
+
*/
|
|
36
|
+
readonly scssVars: "@design-factory/scss-vars-filter";
|
|
37
|
+
/**
|
|
38
|
+
* Filter removing invalid font-weight tokens and t0 tokens. Should be used with {@link formats.cssRoot}
|
|
39
|
+
*/
|
|
40
|
+
readonly cssRoot: "@design-factory/root-filter";
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Design Factory custom Style-Dictionary formats
|
|
44
|
+
*/
|
|
45
|
+
export declare const formats: {
|
|
46
|
+
/**
|
|
47
|
+
* Format to print a sass file containing tokens as sass variables. Should be used with {@link filters.scssVars}
|
|
48
|
+
*/
|
|
49
|
+
readonly scssVars: "@design-factory/scss-vars";
|
|
50
|
+
/**
|
|
51
|
+
* Format to print a css file printing tokens as css variables. Should be used with {@link filters.cssRoot}
|
|
52
|
+
*/
|
|
53
|
+
readonly cssRoot: "@design-factory/css-root";
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Registers Design Factory custom transforms, formats and filters with Style Dictionary.
|
|
57
|
+
*/
|
|
58
|
+
export declare const registerDf: () => void;
|
package/config.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import StyleDictionary from "style-dictionary";
|
|
2
|
+
import { transformTypes, transforms as transforms$1 } from "style-dictionary/enums";
|
|
3
|
+
import { fileHeader, sortByReference, usesReferences } from "style-dictionary/utils";
|
|
4
|
+
import { EOL } from "os";
|
|
5
|
+
const tier3ScopingMap = {
|
|
6
|
+
button: `.btn,${EOL} .btn-close`,
|
|
7
|
+
//needing .btn-close because the alert uses it// TODO: remove when wrapping alert
|
|
8
|
+
badge: ".badge",
|
|
9
|
+
footer: ".df-app-footer",
|
|
10
|
+
navbar: ".navbar",
|
|
11
|
+
link: `a,${EOL} .df-app-footer,${EOL} button.df-collapse,${EOL} .breadcrumb`
|
|
12
|
+
//collapse is a button styled as a link
|
|
13
|
+
};
|
|
14
|
+
const splitTokens = (allTokens) => {
|
|
15
|
+
const rootTokens = [];
|
|
16
|
+
const tier3Tokens = [];
|
|
17
|
+
allTokens.forEach((token) => {
|
|
18
|
+
if (token.path[1] && Object.keys(tier3ScopingMap).includes(token.path[1])) {
|
|
19
|
+
tier3Tokens.push(token);
|
|
20
|
+
} else {
|
|
21
|
+
rootTokens.push(token);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const groupedT3 = tier3Tokens.reduce(
|
|
25
|
+
(acc, token) => {
|
|
26
|
+
const key = token.path[1];
|
|
27
|
+
if (acc[key]) {
|
|
28
|
+
acc[key].push(token);
|
|
29
|
+
} else {
|
|
30
|
+
acc[key] = [token];
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
},
|
|
34
|
+
{}
|
|
35
|
+
);
|
|
36
|
+
return { rootTokens, groupedT3 };
|
|
37
|
+
};
|
|
38
|
+
const FONT_WEIGHT_FIGMA2CSS = {
|
|
39
|
+
light: "300",
|
|
40
|
+
regular: "400",
|
|
41
|
+
medium: "500",
|
|
42
|
+
bold: "700"
|
|
43
|
+
};
|
|
44
|
+
const transforms = {
|
|
45
|
+
/**
|
|
46
|
+
* Transform used to quote wrap font-family tokens.
|
|
47
|
+
* This is required as the font-family tokens exported from the Figma Plugin do not have the proper $type.
|
|
48
|
+
*/
|
|
49
|
+
fontFamily: "@design-factory/font-family",
|
|
50
|
+
/**
|
|
51
|
+
* Transform used to map font-weight tokens into useable css values.
|
|
52
|
+
* This is required as the font-weight tokens exported from the Figma Plugin do not have the proper $type.
|
|
53
|
+
*/
|
|
54
|
+
fontWeight: "@design-factory/font-weight",
|
|
55
|
+
/**
|
|
56
|
+
* Transform used to create token names based on DF token naming convention.
|
|
57
|
+
*/
|
|
58
|
+
tokenName: "@design-factory/token-name"
|
|
59
|
+
};
|
|
60
|
+
const transformGroups = {
|
|
61
|
+
/**
|
|
62
|
+
* Transform group that applies standard scss transforms and custom Design Factory transforms.
|
|
63
|
+
*/
|
|
64
|
+
designFactory: "@design-factory"
|
|
65
|
+
};
|
|
66
|
+
const filters = {
|
|
67
|
+
/**
|
|
68
|
+
* Filter removing invalid font-weight tokens. Should be used with {@link formats.scssVars}
|
|
69
|
+
*/
|
|
70
|
+
scssVars: "@design-factory/scss-vars-filter",
|
|
71
|
+
/**
|
|
72
|
+
* Filter removing invalid font-weight tokens and t0 tokens. Should be used with {@link formats.cssRoot}
|
|
73
|
+
*/
|
|
74
|
+
cssRoot: "@design-factory/root-filter"
|
|
75
|
+
};
|
|
76
|
+
const formats = {
|
|
77
|
+
/**
|
|
78
|
+
* Format to print a sass file containing tokens as sass variables. Should be used with {@link filters.scssVars}
|
|
79
|
+
*/
|
|
80
|
+
scssVars: "@design-factory/scss-vars",
|
|
81
|
+
/**
|
|
82
|
+
* Format to print a css file printing tokens as css variables. Should be used with {@link filters.cssRoot}
|
|
83
|
+
*/
|
|
84
|
+
cssRoot: "@design-factory/css-root"
|
|
85
|
+
};
|
|
86
|
+
const registerDf = () => {
|
|
87
|
+
StyleDictionary.registerTransform({
|
|
88
|
+
name: transforms.fontFamily,
|
|
89
|
+
type: transformTypes.value,
|
|
90
|
+
filter: (token) => token.name.includes("-font-") && (token.name.includes("family") || token.name.includes("Family")),
|
|
91
|
+
transform: (token) => `'${token.$value}'`
|
|
92
|
+
});
|
|
93
|
+
StyleDictionary.registerTransform({
|
|
94
|
+
name: transforms.fontWeight,
|
|
95
|
+
type: transformTypes.value,
|
|
96
|
+
filter: (token) => token.name.startsWith("df-typo-weight-"),
|
|
97
|
+
transform: (token) => FONT_WEIGHT_FIGMA2CSS[token.$value.trim().toLowerCase()] || token.$value
|
|
98
|
+
});
|
|
99
|
+
StyleDictionary.registerTransform({
|
|
100
|
+
name: transforms.tokenName,
|
|
101
|
+
type: transformTypes.name,
|
|
102
|
+
transform: (token) => token.path.join("-")
|
|
103
|
+
});
|
|
104
|
+
StyleDictionary.registerTransformGroup({
|
|
105
|
+
name: transformGroups.designFactory,
|
|
106
|
+
transforms: [
|
|
107
|
+
transforms$1.attributeCti,
|
|
108
|
+
transforms.tokenName,
|
|
109
|
+
transforms$1.timeSeconds,
|
|
110
|
+
transforms$1.htmlIcon,
|
|
111
|
+
transforms$1.sizeRem,
|
|
112
|
+
transforms$1.sizePxToRem,
|
|
113
|
+
transforms$1.colorCss,
|
|
114
|
+
transforms$1.assetUrl,
|
|
115
|
+
transforms.fontFamily,
|
|
116
|
+
transforms.fontWeight,
|
|
117
|
+
transforms$1.cubicBezierCss,
|
|
118
|
+
// object-value tokens
|
|
119
|
+
transforms$1.strokeStyleCssShorthand,
|
|
120
|
+
transforms$1.borderCssShorthand,
|
|
121
|
+
transforms$1.typographyCssShorthand,
|
|
122
|
+
transforms$1.transitionCssShorthand,
|
|
123
|
+
transforms$1.shadowCssShorthand
|
|
124
|
+
]
|
|
125
|
+
});
|
|
126
|
+
StyleDictionary.registerFilter({
|
|
127
|
+
name: filters.scssVars,
|
|
128
|
+
filter: (token) => !token.name.endsWith("Italic")
|
|
129
|
+
});
|
|
130
|
+
StyleDictionary.registerFilter({
|
|
131
|
+
name: filters.cssRoot,
|
|
132
|
+
filter: (token) => !token.name.endsWith("Italic") && !token.name.startsWith("df-colorPalette")
|
|
133
|
+
});
|
|
134
|
+
StyleDictionary.registerFormat({
|
|
135
|
+
name: formats.scssVars,
|
|
136
|
+
format: async ({ dictionary, options, file }) => {
|
|
137
|
+
const { usesDtcg, withDefault, outputReferences } = options;
|
|
138
|
+
const header = await fileHeader({
|
|
139
|
+
file,
|
|
140
|
+
formatting: { lineSeparator: EOL, header: `/**${EOL}`, footer: `${EOL} */${EOL}${EOL}` }
|
|
141
|
+
});
|
|
142
|
+
const tokens = dictionary.tokens;
|
|
143
|
+
let allTokens = dictionary.allTokens;
|
|
144
|
+
allTokens = [...allTokens].filter((token) => !token.name.startsWith("internal-")).sort(sortByReference(tokens, { unfilteredTokens: dictionary.unfilteredTokens, usesDtcg }));
|
|
145
|
+
return header + allTokens.reduce((acc, token) => {
|
|
146
|
+
let value = token.$value;
|
|
147
|
+
if (outputReferences && usesReferences(token.original.$value)) {
|
|
148
|
+
let originalValue = token.original.$value;
|
|
149
|
+
while (originalValue.startsWith("{internal.df.")) {
|
|
150
|
+
originalValue = dictionary.tokenMap.get(originalValue).original.$value;
|
|
151
|
+
}
|
|
152
|
+
value = `var(--${originalValue.slice(1, -1).replace(/\./g, "-")})`;
|
|
153
|
+
}
|
|
154
|
+
return `${acc}$${token.name}: ${value}${withDefault ? " !default" : ""};${EOL}`;
|
|
155
|
+
}, "");
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
StyleDictionary.registerFormat({
|
|
159
|
+
name: formats.cssRoot,
|
|
160
|
+
format: async ({ dictionary, options, file }) => {
|
|
161
|
+
const { usesDtcg, outputReferences, selector = "html:root" } = options;
|
|
162
|
+
const header = await fileHeader({
|
|
163
|
+
file,
|
|
164
|
+
formatting: { lineSeparator: EOL, header: `/**${EOL}`, footer: `${EOL} */${EOL}${EOL}` }
|
|
165
|
+
});
|
|
166
|
+
const tokens = dictionary.tokens;
|
|
167
|
+
let allTokens = dictionary.allTokens;
|
|
168
|
+
allTokens = [...allTokens].filter((token) => !token.name.startsWith("internal-")).sort(sortByReference(tokens, { unfilteredTokens: dictionary.unfilteredTokens, usesDtcg }));
|
|
169
|
+
const { rootTokens, groupedT3 } = splitTokens(allTokens);
|
|
170
|
+
const getValueName = (token) => {
|
|
171
|
+
let value = token.$value;
|
|
172
|
+
if (outputReferences && usesReferences(token.original.$value)) {
|
|
173
|
+
let originalValue = token.original.$value;
|
|
174
|
+
while (originalValue.startsWith("{internal.df.")) {
|
|
175
|
+
originalValue = dictionary.tokenMap.get(originalValue).original.$value;
|
|
176
|
+
}
|
|
177
|
+
value = `var(--${originalValue.slice(1, -1).replace(/\./g, "-")})`;
|
|
178
|
+
}
|
|
179
|
+
return { value, name: token.name };
|
|
180
|
+
};
|
|
181
|
+
const colorScheme = dictionary.tokenMap.get("{internal.scheme}");
|
|
182
|
+
return `${header}${selector} {${EOL}` + (colorScheme?.$value ? ` color-scheme: ${colorScheme.$value};${EOL}${EOL}` : "") + rootTokens.reduce((acc, token) => {
|
|
183
|
+
const { value, name } = getValueName(token);
|
|
184
|
+
return `${acc} --${name}: ${value};${EOL}`;
|
|
185
|
+
}, "") + (Object.keys(groupedT3).length ? `${EOL} /* Tier 3 Scoped tokens */${EOL}` + Object.entries(groupedT3).reduce((acc, [key, tokens2]) => {
|
|
186
|
+
return `${acc} ${tier3ScopingMap[key]} {${EOL}` + tokens2.reduce((innerAcc, token) => {
|
|
187
|
+
const { value, name } = getValueName(token);
|
|
188
|
+
return `${innerAcc} --${name}: ${value};${EOL}`;
|
|
189
|
+
}, "") + ` }${EOL}`;
|
|
190
|
+
}, "") : "") + `}${EOL}`;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
export {
|
|
195
|
+
filters,
|
|
196
|
+
formats,
|
|
197
|
+
registerDf,
|
|
198
|
+
transformGroups,
|
|
199
|
+
transforms
|
|
200
|
+
};
|