@digdir/designsystemet 0.0.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/build/bin/designsystemet.js +48 -0
- package/dist/build/bin/designsystemet.js.map +1 -0
- package/dist/build/build.js +172 -0
- package/dist/build/build.js.map +1 -0
- package/dist/build/formatters.js +94 -0
- package/dist/build/formatters.js.map +1 -0
- package/dist/build/noCase.js +31 -0
- package/dist/build/noCase.js.map +1 -0
- package/dist/build/package.json +42 -0
- package/dist/build/src/codemods/css-var-codemod.js +37 -0
- package/dist/build/src/codemods/css-var-codemod.js.map +1 -0
- package/dist/build/src/codemods/migrations/light-dark.js +20 -0
- package/dist/build/src/codemods/migrations/light-dark.js.map +1 -0
- package/dist/build/src/codemods/migrations.js +8 -0
- package/dist/build/src/codemods/migrations.js.map +1 -0
- package/dist/build/src/migrations/index.js +9 -0
- package/dist/build/src/migrations/index.js.map +1 -0
- package/dist/build/src/migrations/light-dark.js +23 -0
- package/dist/build/src/migrations/light-dark.js.map +1 -0
- package/dist/build/src/migrations/prefix-ds.js +8 -0
- package/dist/build/src/migrations/prefix-ds.js.map +1 -0
- package/dist/build/src/migrations/tokens-v2.js +211 -0
- package/dist/build/src/migrations/tokens-v2.js.map +1 -0
- package/dist/build/src/tokens/build.js +141 -0
- package/dist/build/src/tokens/build.js.map +1 -0
- package/dist/build/src/tokens/formatters.js +79 -0
- package/dist/build/src/tokens/formatters.js.map +1 -0
- package/dist/build/src/tokens/noCase.js +31 -0
- package/dist/build/src/tokens/noCase.js.map +1 -0
- package/dist/build/src/tokens/transformers.js +40 -0
- package/dist/build/src/tokens/transformers.js.map +1 -0
- package/dist/build/transformers.js +105 -0
- package/dist/build/transformers.js.map +1 -0
- package/dist/build/tsconfig.tsbuildinfo +1 -0
- package/dist/types/bin/designsystemet.d.ts +3 -0
- package/dist/types/bin/designsystemet.d.ts.map +1 -0
- package/dist/types/build.d.ts +3 -0
- package/dist/types/build.d.ts.map +1 -0
- package/dist/types/formatters.d.ts +11 -0
- package/dist/types/formatters.d.ts.map +1 -0
- package/dist/types/noCase.d.ts +11 -0
- package/dist/types/noCase.d.ts.map +1 -0
- package/dist/types/src/codemods/css-var-codemod.d.ts +7 -0
- package/dist/types/src/codemods/css-var-codemod.d.ts.map +1 -0
- package/dist/types/src/codemods/migrations/light-dark.d.ts +3 -0
- package/dist/types/src/codemods/migrations/light-dark.d.ts.map +1 -0
- package/dist/types/src/codemods/migrations.d.ts +6 -0
- package/dist/types/src/codemods/migrations.d.ts.map +1 -0
- package/dist/types/src/migrations/index.d.ts +7 -0
- package/dist/types/src/migrations/index.d.ts.map +1 -0
- package/dist/types/src/migrations/light-dark.d.ts +3 -0
- package/dist/types/src/migrations/light-dark.d.ts.map +1 -0
- package/dist/types/src/migrations/prefix-ds.d.ts +3 -0
- package/dist/types/src/migrations/prefix-ds.d.ts.map +1 -0
- package/dist/types/src/migrations/tokens-v2.d.ts +3 -0
- package/dist/types/src/migrations/tokens-v2.d.ts.map +1 -0
- package/dist/types/src/tokens/build.d.ts +7 -0
- package/dist/types/src/tokens/build.d.ts.map +1 -0
- package/dist/types/src/tokens/formatters.d.ts +10 -0
- package/dist/types/src/tokens/formatters.d.ts.map +1 -0
- package/dist/types/src/tokens/noCase.d.ts +11 -0
- package/dist/types/src/tokens/noCase.d.ts.map +1 -0
- package/dist/types/src/tokens/transformers.d.ts +5 -0
- package/dist/types/src/tokens/transformers.d.ts.map +1 -0
- package/dist/types/transformers.d.ts +11 -0
- package/dist/types/transformers.d.ts.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Argument, program } from '@commander-js/extra-typings';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import migrations from './../src/migrations/index.js';
|
|
5
|
+
import { run } from './../src/tokens/build.js';
|
|
6
|
+
program.name('Designsystemet').description('CLI for working with Designsystemet');
|
|
7
|
+
program
|
|
8
|
+
.command('tokens')
|
|
9
|
+
.showHelpAfterError()
|
|
10
|
+
.description('run Designsystemet token builder')
|
|
11
|
+
.option('-t, --tokens <string>', 'Path to "design-tokens"', '../../design-tokens')
|
|
12
|
+
.option('-p, --preview')
|
|
13
|
+
.action((opts) => {
|
|
14
|
+
const tokens = typeof opts.tokens === 'string' ? opts.tokens : '';
|
|
15
|
+
console.log(`Bulding tokens in ${chalk.green(tokens)}`);
|
|
16
|
+
return run({ tokens });
|
|
17
|
+
});
|
|
18
|
+
program
|
|
19
|
+
.command('migrate')
|
|
20
|
+
.showHelpAfterError()
|
|
21
|
+
.description('run a Designsystemet migration')
|
|
22
|
+
.addArgument(new Argument('[migration]', 'Available migrations').choices(Object.keys(migrations)))
|
|
23
|
+
.option('-l --list', 'List available migrations')
|
|
24
|
+
.option('-g --glob <glob>', 'Glob for files upon which to apply the migration', './**/*.css')
|
|
25
|
+
.action((migrationKey, opts) => {
|
|
26
|
+
const { glob, list } = opts;
|
|
27
|
+
if (list) {
|
|
28
|
+
Object.keys(migrations).forEach((key) => {
|
|
29
|
+
console.log(key);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if (migrationKey) {
|
|
33
|
+
const migration = migrations[migrationKey];
|
|
34
|
+
if (!migration) {
|
|
35
|
+
console.error('Migration not found!');
|
|
36
|
+
throw 'Aborting';
|
|
37
|
+
}
|
|
38
|
+
console.log(`Applying migration ${chalk.blue(migrationKey)} with glob: ${chalk.green(glob)}`);
|
|
39
|
+
migration?.(glob)
|
|
40
|
+
.then(() => console.log(`Migration ${chalk.blue(migrationKey)} finished`))
|
|
41
|
+
.catch((error) => console.log(error));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.log('Migrate: please specify a migration name or --list');
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
await program.parseAsync(process.argv);
|
|
48
|
+
//# sourceMappingURL=designsystemet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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AAI,EAAE,EAAE;IAC7B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAE5B,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACtC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,IAAI,YAAY,EAAE,CAAC;QACxB,MAAM,SAAS,GAAG,UAAU,CAAC,YAAuC,CAAC,CAAC;QACtE,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;YACtC,MAAM,UAAU,CAAC;QACnB,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9F,SAAS,EAAE,CAAC,IAAI,CAAC;aACd,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;aACzE,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;IACpE,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import StyleDictionary from 'style-dictionary';
|
|
4
|
+
import { registerTransforms } from '@tokens-studio/sd-transforms';
|
|
5
|
+
import yargs from 'yargs';
|
|
6
|
+
import { sizePx, nameKebab, nameKebabUnderscore, typographyShorthand, fluidFontSize, calc, fontScaleHackFormat, sizeRem, } from './transformers.js';
|
|
7
|
+
import { scopedReferenceVariables, groupedTokens, setup as setupFormatters, } from './formatters.js';
|
|
8
|
+
const argv = yargs(process.argv.slice(2))
|
|
9
|
+
.options({
|
|
10
|
+
brands: {
|
|
11
|
+
type: 'array',
|
|
12
|
+
default: [],
|
|
13
|
+
describe: 'Brand files to build',
|
|
14
|
+
alias: 'b',
|
|
15
|
+
},
|
|
16
|
+
tokens: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
describe: 'Location for design-tokens',
|
|
19
|
+
demandOption: true,
|
|
20
|
+
alias: 't',
|
|
21
|
+
},
|
|
22
|
+
preview: {
|
|
23
|
+
alias: 'p',
|
|
24
|
+
type: 'boolean',
|
|
25
|
+
describe: 'Generate typescript token preview files',
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
.parseSync();
|
|
29
|
+
void registerTransforms(StyleDictionary);
|
|
30
|
+
const pickBrands = (x) => typeof x === 'string';
|
|
31
|
+
const prefix = 'fds';
|
|
32
|
+
const basePxFontSize = 16;
|
|
33
|
+
const fileheader = {
|
|
34
|
+
name: 'fileheader',
|
|
35
|
+
fileHeader: () => [
|
|
36
|
+
'Do not edit directly',
|
|
37
|
+
`These files are generated from design tokens defined in Figma using Token Studio`,
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
const storefrontTokensPath = path.resolve('../../apps/storefront/tokens');
|
|
41
|
+
const packageTokensPath = path.resolve('../../packages/theme/brand');
|
|
42
|
+
const tokensPath = argv.tokens;
|
|
43
|
+
setupFormatters('./../../prettier.config.js');
|
|
44
|
+
StyleDictionary.registerTransform(sizePx);
|
|
45
|
+
StyleDictionary.registerTransform(sizeRem);
|
|
46
|
+
StyleDictionary.registerTransform(nameKebab);
|
|
47
|
+
StyleDictionary.registerTransform(nameKebabUnderscore);
|
|
48
|
+
StyleDictionary.registerTransform(typographyShorthand);
|
|
49
|
+
StyleDictionary.registerTransform(fluidFontSize);
|
|
50
|
+
StyleDictionary.registerTransform(calc);
|
|
51
|
+
StyleDictionary.registerFormat(fontScaleHackFormat);
|
|
52
|
+
StyleDictionary.registerFormat(scopedReferenceVariables);
|
|
53
|
+
StyleDictionary.registerFormat(groupedTokens);
|
|
54
|
+
StyleDictionary.registerFileHeader(fileheader);
|
|
55
|
+
StyleDictionary.registerTransformGroup({
|
|
56
|
+
name: 'fds/css',
|
|
57
|
+
transforms: [
|
|
58
|
+
'ts/resolveMath',
|
|
59
|
+
nameKebab.name,
|
|
60
|
+
typographyShorthand.name,
|
|
61
|
+
'ts/size/lineheight',
|
|
62
|
+
sizeRem.name,
|
|
63
|
+
'ts/shadow/css/shorthand',
|
|
64
|
+
'ts/color/modifiers',
|
|
65
|
+
'ts/color/css/hexrgba',
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
const baseConfig = (brand) => {
|
|
69
|
+
return {
|
|
70
|
+
include: [
|
|
71
|
+
`${tokensPath}/Brand/${brand}.json`,
|
|
72
|
+
`${tokensPath}/Base/Semantic.json`,
|
|
73
|
+
],
|
|
74
|
+
source: [`${tokensPath}/Base/Core.json`],
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
const excludeSource = (token) => !token.filePath.includes('Core.json');
|
|
78
|
+
const getTokensPackageConfig = (brand, targetFolder = '') => {
|
|
79
|
+
const destinationPath = `${targetFolder}/${brand.toLowerCase()}`;
|
|
80
|
+
return {
|
|
81
|
+
...baseConfig(brand),
|
|
82
|
+
platforms: {
|
|
83
|
+
hack: {
|
|
84
|
+
prefix,
|
|
85
|
+
basePxFontSize,
|
|
86
|
+
transforms: ['ts/resolveMath', nameKebab.name],
|
|
87
|
+
files: [
|
|
88
|
+
{
|
|
89
|
+
format: 'global-values-hack',
|
|
90
|
+
destination: 'ignore/hack',
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
css: {
|
|
95
|
+
prefix,
|
|
96
|
+
basePxFontSize,
|
|
97
|
+
transformGroup: 'fds/css',
|
|
98
|
+
files: [
|
|
99
|
+
{
|
|
100
|
+
destination: `${destinationPath}/tokens.css`,
|
|
101
|
+
format: 'css/variables-scoped-references',
|
|
102
|
+
// filter: excludeSource,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
options: {
|
|
106
|
+
fileHeader: fileheader.name,
|
|
107
|
+
referencesFilter: (token) => !(token.path[0] === 'viewport') &&
|
|
108
|
+
['color'].includes(token.type),
|
|
109
|
+
// outputReferences: true,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
const getStorefrontConfig = (brand, targetFolder = '') => {
|
|
116
|
+
const destinationPath = `${targetFolder}/${brand.toLowerCase()}`;
|
|
117
|
+
return {
|
|
118
|
+
...baseConfig(brand),
|
|
119
|
+
platforms: {
|
|
120
|
+
hack: {
|
|
121
|
+
prefix,
|
|
122
|
+
basePxFontSize,
|
|
123
|
+
transforms: ['ts/resolveMath', nameKebab.name],
|
|
124
|
+
files: [
|
|
125
|
+
{
|
|
126
|
+
format: 'global-values-hack',
|
|
127
|
+
destination: 'ignore/hack',
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
storefront: {
|
|
132
|
+
prefix,
|
|
133
|
+
basePxFontSize,
|
|
134
|
+
transformGroup: 'fds/css',
|
|
135
|
+
files: [
|
|
136
|
+
{
|
|
137
|
+
destination: `${destinationPath}.ts`,
|
|
138
|
+
format: groupedTokens.name,
|
|
139
|
+
filter: excludeSource,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
options: {
|
|
143
|
+
fileHeader: fileheader.name,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
const brands = argv.brands.filter(pickBrands);
|
|
150
|
+
if (brands.length > 0) {
|
|
151
|
+
console.log('➡️ Recieved following brands: ', brands);
|
|
152
|
+
console.log('🏗️ Start building CSS tokens');
|
|
153
|
+
brands.map((brand) => {
|
|
154
|
+
console.log('\n---------------------------------------');
|
|
155
|
+
console.log(`\n👷 Processing ${brand}`);
|
|
156
|
+
const tokensPackageSD = StyleDictionary.extend(getTokensPackageConfig(brand, packageTokensPath));
|
|
157
|
+
tokensPackageSD.buildAllPlatforms();
|
|
158
|
+
});
|
|
159
|
+
console.log('\n---------------------------------------');
|
|
160
|
+
console.log('\n🏁 Finished building package tokens!');
|
|
161
|
+
}
|
|
162
|
+
console.log('\n=======================================');
|
|
163
|
+
console.log('\n🏗️ Started building storefront tokens…');
|
|
164
|
+
brands.map((brand) => {
|
|
165
|
+
console.log('\n---------------------------------------');
|
|
166
|
+
console.log(`\n👷 Processing ${brand}`);
|
|
167
|
+
const storefrontSD = StyleDictionary.extend(getStorefrontConfig(brand, storefrontTokensPath));
|
|
168
|
+
storefrontSD.buildAllPlatforms();
|
|
169
|
+
});
|
|
170
|
+
console.log('\n---------------------------------------');
|
|
171
|
+
console.log('\n🏁 Finished building storefront tokens!');
|
|
172
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":";AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAO/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EACL,MAAM,EACN,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,IAAI,EACJ,mBAAmB,EACnB,OAAO,GACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,KAAK,IAAI,eAAe,GACzB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,IAAI,GAAG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C,CAAC,CAAC;AAEH,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;AAEzD,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import * as R from 'ramda';
|
|
3
|
+
import prettier from 'prettier';
|
|
4
|
+
import { fileHeader, createPropertyFormatter } from 'style-dictionary/utils';
|
|
5
|
+
let prettierOptions;
|
|
6
|
+
export const setup = (prettierConfigPath) => {
|
|
7
|
+
prettierOptions = prettier.resolveConfig.sync(path.resolve(prettierConfigPath));
|
|
8
|
+
if (!prettierOptions) {
|
|
9
|
+
throw Error(`Prettier config not found at ${prettierConfigPath}`);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* CSS variables format with option to include source references for matched token through `options.referencesFilter`
|
|
14
|
+
*/
|
|
15
|
+
export const scopedReferenceVariables = {
|
|
16
|
+
name: 'css/variables-scoped-references',
|
|
17
|
+
formatter: function ({ dictionary, options, file }) {
|
|
18
|
+
const { outputReferences } = options;
|
|
19
|
+
const includeReferences = options.referencesFilter;
|
|
20
|
+
let referencedTokens = [];
|
|
21
|
+
const format = createPropertyFormatter({
|
|
22
|
+
outputReferences,
|
|
23
|
+
dictionary,
|
|
24
|
+
format: 'css',
|
|
25
|
+
});
|
|
26
|
+
const formatWithReference = createPropertyFormatter({
|
|
27
|
+
outputReferences: true,
|
|
28
|
+
dictionary,
|
|
29
|
+
format: 'css',
|
|
30
|
+
});
|
|
31
|
+
const tokens = dictionary.allTokens
|
|
32
|
+
.map((token) => {
|
|
33
|
+
if (dictionary.usesReference(token.original.value) &&
|
|
34
|
+
includeReferences(token)) {
|
|
35
|
+
const refs = dictionary.getReferences(token.original.value);
|
|
36
|
+
referencedTokens = [
|
|
37
|
+
...referencedTokens,
|
|
38
|
+
...refs.filter((x) => x.isSource),
|
|
39
|
+
];
|
|
40
|
+
return formatWithReference(token);
|
|
41
|
+
}
|
|
42
|
+
return !token.isSource && format(token);
|
|
43
|
+
})
|
|
44
|
+
.filter((x) => x);
|
|
45
|
+
const referenceTokens = referencedTokens
|
|
46
|
+
.reduce((acc, token) => {
|
|
47
|
+
if (acc.find((x) => x.name === token.name)) {
|
|
48
|
+
return acc;
|
|
49
|
+
}
|
|
50
|
+
return [...acc, { name: token.name, formatted: format(token) }];
|
|
51
|
+
}, [])
|
|
52
|
+
.map((x) => x.formatted)
|
|
53
|
+
.filter((x) => x);
|
|
54
|
+
return (fileHeader({ file }) +
|
|
55
|
+
':root {\n' +
|
|
56
|
+
' /** Referenced source tokens */ \n' +
|
|
57
|
+
' /** DO NOT OVERRIDE */ \n' +
|
|
58
|
+
referenceTokens.join('\n') +
|
|
59
|
+
'\n\n /** Tokens */ \n' +
|
|
60
|
+
tokens.join('\n') +
|
|
61
|
+
'\n}\n');
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const groupByType = R.groupBy((token) => token.type);
|
|
65
|
+
/** Add token name with prefix to list for removal */
|
|
66
|
+
const removeUnwatedTokens = R.filter((token) => !['fds-base_spacing', 'fds-base_sizing'].includes(token.name));
|
|
67
|
+
const toCssVarName = R.pipe(R.split(':'), R.head, R.trim);
|
|
68
|
+
/**
|
|
69
|
+
* Format for displaying tokens in storefront
|
|
70
|
+
*/
|
|
71
|
+
export const groupedTokens = {
|
|
72
|
+
name: 'groupedTokens',
|
|
73
|
+
formatter: function ({ dictionary, file }) {
|
|
74
|
+
const format = createPropertyFormatter({
|
|
75
|
+
dictionary,
|
|
76
|
+
format: 'css',
|
|
77
|
+
});
|
|
78
|
+
const formatTokens = R.map((token) => ({
|
|
79
|
+
...token,
|
|
80
|
+
name: toCssVarName(format(token)),
|
|
81
|
+
}));
|
|
82
|
+
const processTokens = R.pipe(removeUnwatedTokens, formatTokens, groupByType);
|
|
83
|
+
const tokens = processTokens(dictionary.allTokens);
|
|
84
|
+
const content = fileHeader({ file }) +
|
|
85
|
+
Object.entries(tokens)
|
|
86
|
+
.map(([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2)} \n`)
|
|
87
|
+
.join('\n');
|
|
88
|
+
return prettier.format(content, {
|
|
89
|
+
...prettierOptions,
|
|
90
|
+
parser: 'babel',
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=formatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAGhC,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAI7E,IAAI,eAAwC,CAAC;AAE7C,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,kBAA0B,EAAE,EAAE;IAClD,eAAe,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAC3C,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,CACjC,CAAC;IACF,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,KAAK,CAAC,gCAAgC,kBAAkB,EAAE,CAAC,CAAC;IACpE,CAAC;AACH,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAkB;IACrD,IAAI,EAAE,iCAAiC;IACvC,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE;QAChD,MAAM,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;QACrC,MAAM,iBAAiB,GAAG,OAAO,CAAC,gBAAoC,CAAC;QACvE,IAAI,gBAAgB,GAAuB,EAAE,CAAC;QAE9C,MAAM,MAAM,GAAG,uBAAuB,CAAC;YACrC,gBAAgB;YAChB,UAAU;YACV,MAAM,EAAE,KAAK;SACd,CAAC,CA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C,IAAI,CAC1B,mBAAmB,EACnB,YAAY,EACZ,WAAW,CACZ,CAAC;QAEF,MAAM,MAAM,GAAG,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAEnD,MAAM,OAAO,GACX,UAAU,CAAC,EAAE,IAAI,EAAE,CAAC;YACpB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;iBACnB,GAAG,CACF,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAChB,iBAAiB,IAAI,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CACjE;iBACA,IAAI,CAAC,IAAI,CAAC,CAAC;QAEhB,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE;YAC9B,GAAG,eAAe;YAClB,MAAM,EAAE,OAAO;SAChB,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copied from https://github.com/blakeembrey/change-case/blob/change-case%404.1.2/packages/no-case/src/index.ts
|
|
2
|
+
const lowerCase = (text = '') => text.toLowerCase();
|
|
3
|
+
// Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
|
|
4
|
+
const DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
5
|
+
// Remove all non-word characters.
|
|
6
|
+
const DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
7
|
+
/**
|
|
8
|
+
* Normalize the string into something other libraries can manipulate easier.
|
|
9
|
+
*/
|
|
10
|
+
export function noCase(input, options = {}) {
|
|
11
|
+
const { splitRegexp = DEFAULT_SPLIT_REGEXP, stripRegexp = DEFAULT_STRIP_REGEXP, transform = lowerCase, delimiter = ' ', } = options;
|
|
12
|
+
const result = replace(replace(input, splitRegexp, '$1\0$2'), stripRegexp, '\0');
|
|
13
|
+
let start = 0;
|
|
14
|
+
let end = result.length;
|
|
15
|
+
// Trim the delimiter from around the output string.
|
|
16
|
+
while (result.charAt(start) === '\0')
|
|
17
|
+
start++;
|
|
18
|
+
while (result.charAt(end - 1) === '\0')
|
|
19
|
+
end--;
|
|
20
|
+
// Transform each token independently.
|
|
21
|
+
return result.slice(start, end).split('\0').map(transform).join(delimiter);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Replace `re` in the input string with the replacement value.
|
|
25
|
+
*/
|
|
26
|
+
function replace(input, re, value) {
|
|
27
|
+
if (re instanceof RegExp)
|
|
28
|
+
return input.replace(re, value);
|
|
29
|
+
return re.reduce((input, re) => input.replace(re, value), input);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=noCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noCase.js","sourceRoot":"","sources":["../../src/noCase.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,MAAM,SAAS,GAAG,CAAC,IAAI,GAAG,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;AASpD,oFAAoF;AACpF,MAAM,oBAAoB,GAAG,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CAAC;AAE5E,kCAAkC;AAClC,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAE5C;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,KAAa,EAAE,UAAmB,EAAE;IACzD,MAAM,EACJ,WAAW,GAAG,oBAAoB,EAClC,WAAW,GAAG,oBAAoB,EAClC,SAAS,GAAG,SAAS,EACrB,SAAS,GAAG,GAAG,GAChB,GAAG,OAAO,CAAC;IAEZ,MAAM,MAAM,GAAG,OAAO,CACpB,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,EACrC,WAAW,EACX,IAAI,CACL,CAAC;IACF,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;IAExB,oDAAoD;IACpD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI;QAAE,KAAK,EAAE,CAAC;IAC9C,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,IAAI;QAAE,GAAG,EAAE,CAAC;IAE9C,sCAAsC;IACtC,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC7E,CAAC;AAED;;GAEG;AACH,SAAS,OAAO,CAAC,KAAa,EAAE,EAAqB,EAAE,KAAa;IAClE,IAAI,EAAE,YAAY,MAAM;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IAC1D,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@digdir/designsystemet",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "CLI for Designsystemet",
|
|
5
|
+
"author": "Designsystemet team",
|
|
6
|
+
"repository": "https://github.com/digdir/designsystemet",
|
|
7
|
+
"homepage": "https://github.com/digdir/designsystemet/tree/main/scripts/cli",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"private": true,
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"start": "esno ./bin/designsystemet.ts",
|
|
16
|
+
"build": "yarn clean && yarn start tokens -t ../../design-tokens -b Digdir Tilsynet Altinn Brreg",
|
|
17
|
+
"prepublish": "tsc",
|
|
18
|
+
"clean": "yarn workspace @digdir/designsystemet-theme clean",
|
|
19
|
+
"css-light-dark-codemod": "esno ./bin/designsystemet.ts migrate tokens-rename-light-dark"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"./dist/**"
|
|
23
|
+
],
|
|
24
|
+
"bin": "./dist/build/bin/designsystemet.js",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"esno": "^4.7.0",
|
|
27
|
+
"fast-glob": "^3.3.2",
|
|
28
|
+
"postcss": "^8.4.38"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@commander-js/extra-typings": "^12.0.1",
|
|
32
|
+
"@tokens-studio/sd-transforms": "^0.15.2",
|
|
33
|
+
"@types/glob": "^8.1.0",
|
|
34
|
+
"@types/node": "^20.12.7",
|
|
35
|
+
"@types/ramda": "^0.29.9",
|
|
36
|
+
"commander": "^12.0.0",
|
|
37
|
+
"ramda": "^0.29.1",
|
|
38
|
+
"rimraf": "^5.0.5",
|
|
39
|
+
"style-dictionary": "^4.0.0-prerelease.26",
|
|
40
|
+
"typescript": "^5.4.5"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import * as R from 'ramda';
|
|
3
|
+
import postcss from 'postcss';
|
|
4
|
+
import glob from 'fast-glob';
|
|
5
|
+
export const cssVarCodemod = async ({ dictionary, globPath = './**/*.css' }) => {
|
|
6
|
+
const transformPlugin = {
|
|
7
|
+
postcssPlugin: 'Replaces referenced CSS variables',
|
|
8
|
+
Declaration(decl) {
|
|
9
|
+
Object.keys(dictionary).forEach((key) => {
|
|
10
|
+
const newValue = dictionary[key];
|
|
11
|
+
if (R.isEmpty(newValue)) {
|
|
12
|
+
//console.log(`Skipping "${key}"; missing new value`);
|
|
13
|
+
}
|
|
14
|
+
if (newValue === '[delete]') {
|
|
15
|
+
//console.log(`Found delete token "${key}"`);
|
|
16
|
+
}
|
|
17
|
+
if (decl.value.includes(key) && !R.isEmpty(newValue)) {
|
|
18
|
+
decl.value = decl.value.replace(key, newValue);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const plugins = [transformPlugin];
|
|
24
|
+
const processor = postcss(plugins);
|
|
25
|
+
const transform = async () => {
|
|
26
|
+
const files = await glob(globPath, { ignore: ['node_modules/**'] });
|
|
27
|
+
const filePromises = files.map(async (file) => {
|
|
28
|
+
const contents = fs.readFileSync(file).toString();
|
|
29
|
+
const result = await processor.process(contents, { from: undefined });
|
|
30
|
+
fs.writeFileSync(file, result.css);
|
|
31
|
+
});
|
|
32
|
+
await Promise.all(filePromises);
|
|
33
|
+
};
|
|
34
|
+
// Run the transform.
|
|
35
|
+
void transform();
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=css-var-codemod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-var-codemod.js","sourceRoot":"","sources":["../../../../src/codemods/css-var-codemod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,WAAW,CAAC;AAO7B,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,GAAG,YAAY,EAAmB,EAAE,EAAE;IAC9F,MAAM,eAAe,GAAW;QAC9B,aAAa,EAAE,mCAAmC;QAClD,WAAW,CAAC,IAAI;YACd,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACtC,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;gBAEjC,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACxB,sDAAsD;gBACxD,CAAC;gBAED,IAAI,QAAQ,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-light': '--fds-semantic-surface-first-subtle',
|
|
4
|
+
'--fds-semantic-surface-first-light-hover': '--fds-semantic-surface-first-subtle-hover',
|
|
5
|
+
'--fds-semantic-surface-first-light-active': '--fds-semantic-surface-first-subtle-active',
|
|
6
|
+
'--fds-semantic-surface-first-dark': '--fds-semantic-surface-first-strong',
|
|
7
|
+
'--fds-semantic-surface-second-light': '--fds-semantic-surface-second-subtle',
|
|
8
|
+
'--fds-semantic-surface-second-light-hover': '--fds-semantic-surface-second-subtle-hover',
|
|
9
|
+
'--fds-semantic-surface-second-light-active': '--fds-semantic-surface-second-subtle-active',
|
|
10
|
+
'--fds-semantic-surface-second-dark': '--fds-semantic-surface-second-strong',
|
|
11
|
+
'--fds-semantic-surface-third-light': '--fds-semantic-surface-third-subtle',
|
|
12
|
+
'--fds-semantic-surface-third-light-hover': '--fds-semantic-surface-third-subtle-hover',
|
|
13
|
+
'--fds-semantic-surface-third-light-active': '--fds-semantic-surface-third-subtle-active',
|
|
14
|
+
'--fds-semantic-surface-third-dark': '--fds-semantic-surface-third-strong',
|
|
15
|
+
'--fds-semantic-surface-neutral-dark': '--fds-semantic-surface-neutral-strong',
|
|
16
|
+
'--fds-semantic-surface-neutral-dark-hover': '--fds-semantic-surface-neutral-strong-hover',
|
|
17
|
+
'--fds-semantic-border-action-dark': '--fds-semantic-border-action-strong',
|
|
18
|
+
'--fds-semantic-border-action-dark-hover': '--fds-semantic-border-action-strong-hover',
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=light-dark.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"light-dark.js","sourceRoot":"","sources":["../../../../../src/codemods/migrations/light-dark.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,eAAe,GAAG,EAAE,CAClB,aAAa,CAAC;IACZ,oCAAoC,EAAE,qCAAqC;IAC3E,0CAA0C,EACxC,2CAA2C;IAC7C,2CAA2C,EACzC,4CAA4C;IAC9C,mCAAmC,EAAE,qCAAqC;IAC1E,qCAAqC,EACnC,sCAAsC;IACxC,2CAA2C,EACzC,4CAA4C;IAC9C,4CAA4C,EAC1C,6CAA6C;IAC/C,oCAAoC,EAClC,sCAAsC;IACxC,oCAAoC,EAAE,qCAAqC;IAC3E,0CAA0C,EACxC,2CAA2C;IAC7C,2CAA2C,EACzC,4CAA4C;IAC9C,mCAAmC,EAAE,qCAAqC;IAC1E,qCAAqC,EACnC,uCAAuC;IACzC,2CAA2C,EACzC,6CAA6C;IAC/C,mCAAmC,EAAE,qCAAqC;IAC1E,yCAAyC,EACvC,2CAA2C;CAC9C,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../../../src/codemods/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,4BAA4B,CAAC;AAEnD,eAAe;IACb,0BAA0B,EAAE,SAAS;IACrC,kBAAkB,EAAE,GAAG,EAAE;QACvB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import lightDark from './light-dark.js';
|
|
2
|
+
import tokensv2 from './tokens-v2.js';
|
|
3
|
+
import prefixDs from './prefix-ds.js';
|
|
4
|
+
export default {
|
|
5
|
+
'tokens-rename-light-dark': lightDark,
|
|
6
|
+
'tokens-v2': tokensv2,
|
|
7
|
+
'css-prefix-ds': prefixDs,
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/migrations/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,eAAe;IACb,0BAA0B,EAAE,SAAS;IACrC,WAAW,EAAE,QAAQ;IACrB,eAAe,EAAE,QAAQ;CAC1B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { cssVarCodemod } from '../codemods/css-var-codemod.js';
|
|
2
|
+
export default (glob) => cssVarCodemod({
|
|
3
|
+
globPath: glob,
|
|
4
|
+
dictionary: {
|
|
5
|
+
'--fds-semantic-surface-first-light': '--fds-semantic-surface-first-subtle',
|
|
6
|
+
'--fds-semantic-surface-first-light-hover': '--fds-semantic-surface-first-subtle-hover',
|
|
7
|
+
'--fds-semantic-surface-first-light-active': '--fds-semantic-surface-first-subtle-active',
|
|
8
|
+
'--fds-semantic-surface-first-dark': '--fds-semantic-surface-first-strong',
|
|
9
|
+
'--fds-semantic-surface-second-light': '--fds-semantic-surface-second-subtle',
|
|
10
|
+
'--fds-semantic-surface-second-light-hover': '--fds-semantic-surface-second-subtle-hover',
|
|
11
|
+
'--fds-semantic-surface-second-light-active': '--fds-semantic-surface-second-subtle-active',
|
|
12
|
+
'--fds-semantic-surface-second-dark': '--fds-semantic-surface-second-strong',
|
|
13
|
+
'--fds-semantic-surface-third-light': '--fds-semantic-surface-third-subtle',
|
|
14
|
+
'--fds-semantic-surface-third-light-hover': '--fds-semantic-surface-third-subtle-hover',
|
|
15
|
+
'--fds-semantic-surface-third-light-active': '--fds-semantic-surface-third-subtle-active',
|
|
16
|
+
'--fds-semantic-surface-third-dark': '--fds-semantic-surface-third-strong',
|
|
17
|
+
'--fds-semantic-surface-neutral-dark': '--fds-semantic-surface-neutral-strong',
|
|
18
|
+
'--fds-semantic-surface-neutral-dark-hover': '--fds-semantic-surface-neutral-strong-hover',
|
|
19
|
+
'--fds-semantic-border-action-dark': '--fds-semantic-border-action-strong',
|
|
20
|
+
'--fds-semantic-border-action-dark-hover': '--fds-semantic-border-action-strong-hover',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=light-dark.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"light-dark.js","sourceRoot":"","sources":["../../../../src/migrations/light-dark.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,eAAe,CAAC,IAAa,EAAE,EAAE,CAC/B,aAAa,CAAC;IACZ,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE;QACV,oCAAoC,EAAE,qCAAqC;QAC3E,0CAA0C,EAAE,2CAA2C;QACvF,2CAA2C,EAAE,4CAA4C;QACzF,mCAAmC,EAAE,qCAAqC;QAC1E,qCAAqC,EAAE,sCAAsC;QAC7E,2CAA2C,EAAE,4CAA4C;QACzF,4CAA4C,EAAE,6CAA6C;QAC3F,oCAAoC,EAAE,sCAAsC;QAC5E,oCAAoC,EAAE,qCAAqC;QAC3E,0CAA0C,EAAE,2CAA2C;QACvF,2CAA2C,EAAE,4CAA4C;QACzF,mCAAmC,EAAE,qCAAqC;QAC1E,qCAAqC,EAAE,uCAAuC;QAC9E,2CAA2C,EAAE,6CAA6C;QAC1F,mCAAmC,EAAE,qCAAqC;QAC1E,yCAAyC,EAAE,2CAA2C;KACvF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefix-ds.js","sourceRoot":"","sources":["../../../../src/migrations/prefix-ds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,eAAe,CAAC,IAAa,EAAE,EAAE,CAC/B,aAAa,CAAC;IACZ,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE;QACV,OAAO,EAAE,MAAM;KAChB;CACF,CAAC,CAAC"}
|