style-dictionary 3.1.0 → 3.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.
Files changed (48) hide show
  1. package/examples/advanced/assets-base64-embed/package.json +1 -1
  2. package/examples/advanced/auto-rebuild-watcher/package.json +1 -1
  3. package/examples/advanced/component-cti/package.json +1 -1
  4. package/examples/advanced/create-react-app/package.json +2 -2
  5. package/examples/advanced/create-react-native-app/package.json +1 -1
  6. package/examples/advanced/custom-file-header/package.json +1 -1
  7. package/examples/advanced/custom-filters/README.md +99 -0
  8. package/examples/advanced/custom-filters/build.js +27 -0
  9. package/examples/advanced/custom-filters/config.json +21 -0
  10. package/examples/advanced/custom-filters/package.json +20 -0
  11. package/examples/advanced/custom-filters/tokens/spacing.json +20 -0
  12. package/examples/advanced/custom-formats-with-templates/package.json +1 -1
  13. package/examples/advanced/custom-parser/package.json +1 -1
  14. package/examples/advanced/custom-transforms/package.json +1 -1
  15. package/examples/advanced/font-face-rules/README.md +71 -0
  16. package/examples/advanced/font-face-rules/package.json +13 -0
  17. package/examples/advanced/font-face-rules/sd.config.js +102 -0
  18. package/examples/advanced/font-face-rules/tokens.json +28 -0
  19. package/examples/advanced/format-helpers/package.json +1 -1
  20. package/examples/advanced/matching-build-files/package.json +1 -1
  21. package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
  22. package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
  23. package/examples/advanced/npm-module/package.json +1 -1
  24. package/examples/advanced/referencing_aliasing/package.json +1 -1
  25. package/examples/advanced/s3/package.json +1 -1
  26. package/examples/advanced/tokens-deprecation/package.json +1 -1
  27. package/examples/advanced/transitive-transforms/package.json +1 -1
  28. package/examples/advanced/transitive-transforms/tokens/color/font.json5 +2 -1
  29. package/examples/advanced/variables-in-outputs/package.json +1 -1
  30. package/examples/advanced/yaml-tokens/package.json +1 -1
  31. package/examples/basic/config.json +17 -3
  32. package/examples/complete/package.json +1 -1
  33. package/index.js +2 -2
  34. package/lib/common/filters.js +30 -0
  35. package/lib/common/formatHelpers/createPropertyFormatter.js +14 -2
  36. package/lib/common/formatHelpers/formattedVariables.js +5 -1
  37. package/lib/common/formatHelpers/getTypeScriptType.js +2 -2
  38. package/lib/common/formatHelpers/index.js +2 -1
  39. package/lib/common/formatHelpers/setSwiftFileProperties.js +55 -0
  40. package/lib/common/formatHelpers/sortByReference.js +7 -0
  41. package/lib/common/formats.js +77 -10
  42. package/lib/common/templates/ios-swift/{class.swift.template → any.swift.template} +6 -3
  43. package/lib/common/transforms.js +2 -2
  44. package/lib/utils/references/getReferences.js +6 -5
  45. package/lib/utils/resolveObject.js +15 -7
  46. package/package.json +25 -24
  47. package/types/index.d.ts +3 -2
  48. package/lib/common/templates/ios-swift/enum.swift.template +0 -26
@@ -11,6 +11,6 @@
11
11
  "author": "",
12
12
  "license": "Apache-2.0",
13
13
  "devDependencies": {
14
- "style-dictionary": "3.1.0"
14
+ "style-dictionary": "3.7.1"
15
15
  }
16
16
  }
@@ -17,6 +17,6 @@
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
19
  "chokidar-cli": "^1.2.0",
20
- "style-dictionary": "3.1.0"
20
+ "style-dictionary": "3.7.1"
21
21
  }
22
22
  }
@@ -15,6 +15,6 @@
15
15
  "author": "",
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
- "style-dictionary": "3.1.0"
18
+ "style-dictionary": "3.7.1"
19
19
  }
20
20
  }
@@ -3,14 +3,14 @@
3
3
  "description": "",
4
4
  "version": "1.0.0",
5
5
  "dependencies": {
6
- "node-sass": "^6.0.1",
6
+ "node-sass": "^7.0.0",
7
7
  "react": "^17.0.1",
8
8
  "react-dom": "^17.0.1",
9
9
  "react-scripts": "^4.0.3",
10
10
  "styled-components": "^5.3.0"
11
11
  },
12
12
  "devDependencies": {
13
- "style-dictionary": "3.1.0"
13
+ "style-dictionary": "3.7.1"
14
14
  },
15
15
  "resolutions": {
16
16
  "immer": "8.0.1",
@@ -27,7 +27,7 @@
27
27
  "babel-jest": "~25.2.6",
28
28
  "jest": "~25.2.6",
29
29
  "react-test-renderer": "~16.13.1",
30
- "style-dictionary": "3.1.0"
30
+ "style-dictionary": "3.7.1"
31
31
  },
32
32
  "jest": {
33
33
  "preset": "react-native"
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "devDependencies": {
13
- "style-dictionary": "3.1.0"
13
+ "style-dictionary": "3.7.1"
14
14
  }
15
15
  }
@@ -0,0 +1,99 @@
1
+ ## Filters
2
+
3
+ This example shows how to use built-in and custom filters to the design tokens.
4
+
5
+ Filters are functions that might remove according to some conditions a design token from the output distribution.
6
+
7
+ #### Running the example
8
+
9
+ First of all, set up the required dependencies running the command `npm install` in your local CLI environment (if you prefer to use *yarn* update the commands accordingly).
10
+
11
+ At this point, if you want to build the tokens you can run `npm run build`. This command will generate the files in the `build` folder.
12
+
13
+ #### How does it work a built-in filter?
14
+
15
+ Currently StyleDictionary supports just the following built-in filters:
16
+
17
+ - removePrivate
18
+
19
+ You have to apply it in the `config.json` file:
20
+
21
+ ```
22
+ "scss": {
23
+ "buildPath": "build/web/",
24
+ "files": [{
25
+ "destination": "colors.scss",
26
+ "filter": "removePrivate",
27
+ "format": "scss/variables"
28
+ }]
29
+ }
30
+ ```
31
+
32
+ The StyleDictionary will take care of filtering out proper design tokens from the source of truth:
33
+
34
+ ```
35
+ {
36
+ "color": {
37
+ "gray": {
38
+ "light" : {
39
+ "value": "#CCCCCC",
40
+ "group": "color",
41
+ "private": true
42
+ },
43
+ "medium": {
44
+ "value": "#999999",
45
+ "group": "color"
46
+ },
47
+ "dark" : {
48
+ "value": "#111111",
49
+ "group": "color"
50
+ }
51
+ },
52
+ }
53
+ }
54
+ ```
55
+
56
+ #### How does it work a custom filter?
57
+
58
+ To declare a custom **filter**, you have to call the `registerFilter` method:
59
+
60
+ ```
61
+ StyleDictionary.registerFilter({
62
+ name: 'isTextTransform',
63
+ matcher: function(token) {
64
+ return token.attributes.category === 'font' && token.value.includes['lowercase', 'uppercase]
65
+ }
66
+ });
67
+ ```
68
+
69
+ You have to apply it in the `config.json` file:
70
+
71
+ ```
72
+ "scss": {
73
+ "buildPath": "build/web/",
74
+ "files": [{
75
+ "destination": "fonts.scss",
76
+ "filter": "isTextTransform",
77
+ "format": "scss/variables"
78
+ }]
79
+ }
80
+ ```
81
+
82
+ The StyleDictionary will take care of filtering out proper design tokens from the source of truth:
83
+
84
+ ```
85
+ {
86
+ "fonts": {
87
+ "title-transform": {
88
+ "value": "uppercase", // included
89
+ "group": "font"
90
+ },
91
+ "title-size": {
92
+ "value": "36px", // excluded
93
+ "group": "font"
94
+ }
95
+ }
96
+ }
97
+ ```
98
+
99
+ More information can be found on the [documentation](https://amzn.github.io/style-dictionary/#/api?id=registerfilter).
@@ -0,0 +1,27 @@
1
+ const StyleDictionary = require('../../../index');
2
+
3
+ console.log('Build started...');
4
+ console.log('\n==============================================');
5
+
6
+
7
+ // REGISTER THE CUSTOM FILTERS
8
+
9
+ StyleDictionary.registerFilter({
10
+ name: 'removeBigSpacing',
11
+ matcher: function(token) {
12
+ return token.group === 'spacing' && token.value < 0.5
13
+ }
14
+ });
15
+
16
+ // APPLY THE CONFIGURATION
17
+ // IMPORTANT: the registration of custom transforms
18
+ // needs to be done _before_ applying the configuration
19
+ const StyleDictionaryExtended = StyleDictionary.extend(__dirname + '/config.json');
20
+
21
+
22
+ // FINALLY, BUILD ALL THE PLATFORMS
23
+ StyleDictionaryExtended.buildAllPlatforms();
24
+
25
+
26
+ console.log('\n==============================================');
27
+ console.log('\nBuild completed!');
@@ -0,0 +1,21 @@
1
+ {
2
+ "source": ["tokens/**/*.json"],
3
+ "platforms": {
4
+ "web": {
5
+ "buildPath": "build/web/",
6
+ "files": [{
7
+ "destination": "tokens.js",
8
+ "filter": "removeBigSpacing",
9
+ "format": "javascript/es6"
10
+ }]
11
+ },
12
+ "scss": {
13
+ "buildPath": "build/web/",
14
+ "files": [{
15
+ "destination": "tokens.scss",
16
+ "filter": "removeBigSpacing",
17
+ "format": "scss/variables"
18
+ }]
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "style-dictionary-filters",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "build/index.js",
6
+ "files": [
7
+ "build",
8
+ "properties"
9
+ ],
10
+ "scripts": {
11
+ "build": "node ./build.js",
12
+ "clean": "rm -rf build",
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "author": "",
16
+ "license": "Apache-2.0",
17
+ "devDependencies": {
18
+ "style-dictionary": "3.7.1"
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "margin": {
3
+ "small" : {
4
+ "value": "0.15",
5
+ "group": "spacing"
6
+ },
7
+ "medium": {
8
+ "value": "0.25",
9
+ "group": "spacing"
10
+ },
11
+ "large" : {
12
+ "value": "0.6",
13
+ "group": "spacing"
14
+ },
15
+ "extralarge" : {
16
+ "value": "1",
17
+ "group": "spacing"
18
+ }
19
+ }
20
+ }
@@ -18,6 +18,6 @@
18
18
  "handlebars": "^4.7.7",
19
19
  "lodash": "^4.17.21",
20
20
  "pug": "^3.0.2",
21
- "style-dictionary": "3.1.0"
21
+ "style-dictionary": "3.7.1"
22
22
  }
23
23
  }
@@ -9,6 +9,6 @@
9
9
  "author": "",
10
10
  "license": "Apache-2.0",
11
11
  "devDependencies": {
12
- "style-dictionary": "3.1.0"
12
+ "style-dictionary": "3.7.1"
13
13
  }
14
14
  }
@@ -15,6 +15,6 @@
15
15
  "author": "",
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
- "style-dictionary": "3.1.0"
18
+ "style-dictionary": "3.7.1"
19
19
  }
20
20
  }
@@ -0,0 +1,71 @@
1
+ ## Generating @font-face rules
2
+
3
+ To generate `@font-face` rules, we will need a few moving parts (described below). The final output will look like:
4
+
5
+ ```css
6
+ /** build/css/fonts.css */
7
+ @font-face {
8
+ font-family: "Roboto";
9
+ font-style: normal;
10
+ font-weight: 400;
11
+ src: url("../fonts/Roboto.woff2") format("woff2"),
12
+ url("../fonts/Roboto.woff") format("woff");
13
+ font-display: fallback;
14
+ }
15
+ ```
16
+
17
+ ```scss
18
+ // build/scss/_fonts.scss
19
+ @font-face {
20
+ font-family: "Roboto";
21
+ font-style: normal;
22
+ font-weight: 400;
23
+ src: url("#{$font-path}/fonts/Roboto.woff2") format("woff2"),
24
+ url("#{$font-path}/fonts/Roboto.woff") format("woff");
25
+ font-display: fallback;
26
+ }
27
+ ```
28
+
29
+ #### Running the example
30
+
31
+ Set up the required dependencies by running the command `npm install` in your local CLI environment (if you prefer to use _yarn_, update the commands accordingly).
32
+
33
+ At this point, if you want to build the tokens you can run `npm run build`. This command will generate the files in the `build` folder.
34
+
35
+ Note, running this example will generate a "While building fonts.css, token collisions were found; output may be unexpected." warning. The warning is expected and can be ignored.
36
+
37
+ #### How does it work
38
+
39
+ - Each font is defined using a specific structure:
40
+ ```json
41
+ {
42
+ "asset": {
43
+ "font": {
44
+ "<family>": {
45
+ "<weight>": {
46
+ "<style>": {
47
+ "value": "<path>",
48
+ "formats": ["<list of formats, e.g. woff2, woff>"]
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ }
55
+ ```
56
+ - A custom _transform_ will promote the family name, weight and style to their own named attributes on the token object.
57
+ - A custom _format_ will generate the `@font-face` rules.
58
+ - A _platform_ ties it all together.
59
+
60
+ #### What to look at
61
+
62
+ Open `tokens.json`:
63
+
64
+ - To distinguish font-face tokens from other font tokens, the "**asset**" category is used.
65
+ - Each font-face token is structured so that the font's _family name_, _weight_ (400, 700, etc.), and _style_ (normal or italics) can be determined at runtime.
66
+
67
+ Compare this example's `tokens.json` to the generated files `css/fonts.css`, and `scss/_fonts.scss`.
68
+
69
+ Next up, open `sd.config.js` to see how the "css-font-face" and "scss-font-face" platforms are configured. Note the `transforms`, `format`, `filter`, and the custom `options.fontPathPrefix` properties.
70
+
71
+ Lastly, in the same file, check out the code for the `attribute/font` transform, and `font-face` format.
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "font-face-rules",
3
+ "version": "1.0.0",
4
+ "description": "Example showing one way to generate @font-face rules",
5
+ "main": "sd.config.js",
6
+ "scripts": {
7
+ "build": "style-dictionary build --config ./sd.config.js"
8
+ },
9
+ "license": "Apache-2.0",
10
+ "devDependencies": {
11
+ "style-dictionary": "3.7.1"
12
+ }
13
+ }
@@ -0,0 +1,102 @@
1
+ const StyleDictionary = require('style-dictionary');
2
+
3
+ // Register an "attribute" transform to codify the font's details
4
+ // as named attributes.
5
+ StyleDictionary.registerTransform({
6
+ name: 'attribute/font',
7
+ type: 'attribute',
8
+ transformer: prop => ({
9
+ category: prop.path[0],
10
+ type: prop.path[1],
11
+ family: prop.path[2],
12
+ weight: prop.path[3],
13
+ style: prop.path[4]
14
+ })
15
+ });
16
+
17
+ // Register a custom format to generate @font-face rules.
18
+ StyleDictionary.registerFormat({
19
+ name: 'font-face',
20
+ formatter: ({ dictionary: { allTokens }, options }) => {
21
+ const fontPathPrefix = options.fontPathPrefix || '../';
22
+
23
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src
24
+ const formatsMap = {
25
+ 'woff2': 'woff2',
26
+ 'woff': 'woff',
27
+ 'ttf': 'truetype',
28
+ 'otf': 'opentype',
29
+ 'svg': 'svg',
30
+ 'eot': 'embedded-opentype'
31
+ };
32
+
33
+ return allTokens.reduce((fontList, prop) => {
34
+ const {
35
+ attributes: { family, weight, style },
36
+ formats,
37
+ value: path
38
+ } = prop;
39
+
40
+ const urls = formats
41
+ .map(extension => `url("${fontPathPrefix}${path}.${extension}") format("${formatsMap[extension]}")`);
42
+
43
+ const fontCss = [
44
+ '@font-face {',
45
+ `\n\tfont-family: "${family}";`,
46
+ `\n\tfont-style: ${style};`,
47
+ `\n\tfont-weight: ${weight};`,
48
+ `\n\tsrc: ${urls.join(',\n\t\t\t ')};`,
49
+ '\n\tfont-display: fallback;',
50
+ '\n}\n'
51
+ ].join('');
52
+
53
+ fontList.push(fontCss);
54
+
55
+ return fontList;
56
+ }, []).join('\n');
57
+ }
58
+ });
59
+
60
+ module.exports = {
61
+ source: ['tokens.json'],
62
+ platforms: {
63
+ 'css-font-face': {
64
+ transforms: ['attribute/font'],
65
+ buildPath: 'build/css/',
66
+ files: [
67
+ {
68
+ destination: 'fonts.css',
69
+ format: 'font-face',
70
+ filter: {
71
+ attributes: {
72
+ category: 'asset',
73
+ type: 'font'
74
+ }
75
+ },
76
+ options: {
77
+ fontPathPrefix: '../'
78
+ }
79
+ }
80
+ ]
81
+ },
82
+ 'scss-font-face': {
83
+ transforms: ['attribute/font'],
84
+ buildPath: 'build/scss/',
85
+ files: [
86
+ {
87
+ destination: '_fonts.scss',
88
+ format: 'font-face',
89
+ filter: {
90
+ attributes: {
91
+ category: 'asset',
92
+ type: 'font'
93
+ }
94
+ },
95
+ options: {
96
+ fontPathPrefix: '#{$font-path}/'
97
+ }
98
+ }
99
+ ]
100
+ }
101
+ }
102
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "asset": {
3
+ "font": {
4
+ "Roboto": {
5
+ "400": {
6
+ "normal": {
7
+ "value": "fonts/roboto-V20-latin-regular",
8
+ "formats": ["woff2", "woff"]
9
+ },
10
+ "italic": {
11
+ "value": "fonts/roboto-V20-latin-italic",
12
+ "formats": ["woff2", "woff"]
13
+ }
14
+ },
15
+ "700": {
16
+ "normal": {
17
+ "value": "fonts/roboto-V20-latin-700",
18
+ "formats": ["woff2", "woff"]
19
+ },
20
+ "italic": {
21
+ "value": "fonts/roboto-V20-latin-700italic",
22
+ "formats": ["woff2", "woff"]
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "Apache-2.0",
12
12
  "devDependencies": {
13
- "style-dictionary": "3.1.0"
13
+ "style-dictionary": "3.7.1"
14
14
  }
15
15
  }
@@ -16,6 +16,6 @@
16
16
  "author": "Kelly Harrop <kn.harrop@gmail.com>",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "3.1.0"
19
+ "style-dictionary": "3.7.1"
20
20
  }
21
21
  }
@@ -15,6 +15,6 @@
15
15
  "author": "",
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
- "style-dictionary": "3.1.0"
18
+ "style-dictionary": "3.7.1"
19
19
  }
20
20
  }
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "homepage": "https://github.com/dbanksdesign/style-dictionary-node#readme",
21
21
  "devDependencies": {
22
- "style-dictionary": "3.1.0",
22
+ "style-dictionary": "3.7.1",
23
23
  "tinycolor2": "^1.4.1"
24
24
  }
25
25
  }
@@ -16,6 +16,6 @@
16
16
  "author": "",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "3.1.0"
19
+ "style-dictionary": "3.7.1"
20
20
  }
21
21
  }
@@ -15,6 +15,6 @@
15
15
  "author": "",
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
- "style-dictionary": "3.1.0"
18
+ "style-dictionary": "3.7.1"
19
19
  }
20
20
  }
@@ -15,6 +15,6 @@
15
15
  "devDependencies": {
16
16
  "aws-sdk": "^2.7.21",
17
17
  "fs-extra": "^1.0.0",
18
- "style-dictionary": "3.1.0"
18
+ "style-dictionary": "3.7.1"
19
19
  }
20
20
  }
@@ -16,6 +16,6 @@
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
18
  "lodash": "^4.17.11",
19
- "style-dictionary": "3.1.0"
19
+ "style-dictionary": "3.7.1"
20
20
  }
21
21
  }
@@ -11,6 +11,6 @@
11
11
  "license": "ISC",
12
12
  "devDependencies": {
13
13
  "chroma-js": "^2.1.0",
14
- "style-dictionary": "3.1.0"
14
+ "style-dictionary": "3.7.1"
15
15
  }
16
16
  }
@@ -13,7 +13,8 @@
13
13
  },
14
14
  tertiary: {
15
15
  // transitive transforms allow you to modify a modified reference
16
- value: "{color.font.secondary.value}",
16
+ // You can use references with or without `.value`
17
+ value: "{color.font.secondary}",
17
18
  modify: [{
18
19
  // this will brighten the secondary value, which is a brightened version
19
20
  // of primary
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "MIT",
12
12
  "devDependencies": {
13
- "style-dictionary": "3.1.0"
13
+ "style-dictionary": "3.7.1"
14
14
  }
15
15
  }
@@ -9,7 +9,7 @@
9
9
  "author": "",
10
10
  "license": "Apache-2.0",
11
11
  "devDependencies": {
12
- "style-dictionary": "3.1.0",
12
+ "style-dictionary": "3.7.1",
13
13
  "yaml": "^1.10.0"
14
14
  }
15
15
  }
@@ -95,10 +95,25 @@
95
95
  "transformGroup": "ios-swift",
96
96
  "buildPath": "build/ios-swift/",
97
97
  "files": [{
98
- "destination": "StyleDictionary.swift",
98
+ "destination": "StyleDictionary+Class.swift",
99
99
  "format": "ios-swift/class.swift",
100
- "className": "StyleDictionary",
100
+ "className": "StyleDictionaryClass",
101
101
  "filter": {}
102
+ },{
103
+ "destination": "StyleDictionary+Enum.swift",
104
+ "format": "ios-swift/enum.swift",
105
+ "className": "StyleDictionaryEnum",
106
+ "filter": {}
107
+ },{
108
+ "destination": "StyleDictionary+Struct.swift",
109
+ "format": "ios-swift/any.swift",
110
+ "className": "StyleDictionaryStruct",
111
+ "filter": {},
112
+ "options": {
113
+ "imports": "SwiftUI",
114
+ "objectType": "struct",
115
+ "accessControl": "internal"
116
+ }
102
117
  }]
103
118
  },
104
119
  "ios-swift-separate-enums": {
@@ -117,7 +132,6 @@
117
132
  "destination": "StyleDictionarySize.swift",
118
133
  "format": "ios-swift/enum.swift",
119
134
  "className": "StyleDictionarySize",
120
- "type": "float",
121
135
  "filter": {
122
136
  "attributes": {
123
137
  "category": "size"
@@ -11,6 +11,6 @@
11
11
  "author": "",
12
12
  "license": "Apache-2.0",
13
13
  "devDependencies": {
14
- "style-dictionary": "2.9.0"
14
+ "style-dictionary": "latest"
15
15
  }
16
16
  }