@primer/primitives 0.0.0-20250120093846 → 0.0.0-20250120143739
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.
|
@@ -8,7 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { format } from 'prettier';
|
|
11
|
-
import { fileHeader,
|
|
11
|
+
import { fileHeader, sortByName } from 'style-dictionary/utils';
|
|
12
|
+
import getFormattedVariables from './utilities/getFormattedVariables.js';
|
|
12
13
|
const wrapWithSelector = (css, selector) => {
|
|
13
14
|
// return without selector
|
|
14
15
|
if (selector === false || selector.trim().length === 0)
|
|
@@ -69,9 +70,10 @@ export const cssAdvanced = (_a) => __awaiter(void 0, [_a], void 0, function* ({
|
|
|
69
70
|
if (!filteredDictionary.allTokens.length)
|
|
70
71
|
continue;
|
|
71
72
|
// add tokens into root
|
|
72
|
-
const css =
|
|
73
|
+
const css = getFormattedVariables({
|
|
73
74
|
format: 'css',
|
|
74
75
|
dictionary: filteredDictionary,
|
|
76
|
+
// @ts-ignore
|
|
75
77
|
outputReferences,
|
|
76
78
|
formatting: mergedFormatting,
|
|
77
79
|
usesDtcg,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Dictionary } from 'style-dictionary/types';
|
|
2
|
+
export default function getFormattedVariables({ format, dictionary, outputReferences, outputReferenceFallbacks, formatting, themeable, usesDtcg, }: {
|
|
3
|
+
format: string;
|
|
4
|
+
dictionary: Dictionary;
|
|
5
|
+
outputReferences?: boolean;
|
|
6
|
+
outputReferenceFallbacks?: boolean;
|
|
7
|
+
formatting?: {
|
|
8
|
+
lineSeparator?: string;
|
|
9
|
+
};
|
|
10
|
+
themeable?: boolean;
|
|
11
|
+
usesDtcg?: boolean;
|
|
12
|
+
}): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createPropertyFormatter, sortByReference } from 'style-dictionary/utils';
|
|
2
|
+
const defaultFormatting = {
|
|
3
|
+
lineSeparator: '\n',
|
|
4
|
+
};
|
|
5
|
+
export default function getFormattedVariables({ format, dictionary, outputReferences = false, outputReferenceFallbacks, formatting = {}, themeable = false, usesDtcg = false, }) {
|
|
6
|
+
// typecast, we know that by know the tokens have been transformed
|
|
7
|
+
let allTokens = dictionary.allTokens;
|
|
8
|
+
const tokens = dictionary.tokens;
|
|
9
|
+
const { lineSeparator } = Object.assign({}, defaultFormatting, formatting);
|
|
10
|
+
// Some languages are imperative, meaning a variable has to be defined
|
|
11
|
+
// before it is used. If `outputReferences` is true, check if the token
|
|
12
|
+
// has a reference, and if it does send it to the end of the array.
|
|
13
|
+
// We also need to account for nested references, a -> b -> c. They
|
|
14
|
+
// need to be defined in reverse order: c, b, a so that the reference always
|
|
15
|
+
// comes after the definition
|
|
16
|
+
if (outputReferences) {
|
|
17
|
+
// note: using the spread operator here so we get a new array rather than
|
|
18
|
+
// mutating the original
|
|
19
|
+
allTokens = [...allTokens].sort(sortByReference(tokens, { unfilteredTokens: dictionary.unfilteredTokens, usesDtcg }));
|
|
20
|
+
}
|
|
21
|
+
return allTokens
|
|
22
|
+
.map(createPropertyFormatter({
|
|
23
|
+
outputReferences,
|
|
24
|
+
outputReferenceFallbacks,
|
|
25
|
+
dictionary,
|
|
26
|
+
format,
|
|
27
|
+
formatting,
|
|
28
|
+
themeable,
|
|
29
|
+
usesDtcg,
|
|
30
|
+
}))
|
|
31
|
+
.filter(function (strVal) {
|
|
32
|
+
return !!strVal;
|
|
33
|
+
})
|
|
34
|
+
.join(lineSeparator);
|
|
35
|
+
}
|