-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: evaluate math in complex token value types
- Loading branch information
1 parent
a25a1ff
commit acd3ddb
Showing
9 changed files
with
138 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@tokens-studio/sd-transforms': patch | ||
--- | ||
|
||
Evaluate math expressions within complex value types like border, typography, shadow. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { expect } from '@esm-bundle/chai'; | ||
import StyleDictionary from 'style-dictionary'; | ||
import { promises } from 'fs'; | ||
import path from 'path'; | ||
import { cleanup, init } from './utils.js'; | ||
|
||
const outputDir = 'test/integration/tokens/'; | ||
const outputFileName = 'vars.css'; | ||
const outputFilePath = path.resolve(outputDir, outputFileName); | ||
|
||
const cfg = { | ||
source: ['test/integration/tokens/math-in-complex-values.tokens.json'], | ||
platforms: { | ||
css: { | ||
transformGroup: 'tokens-studio', | ||
prefix: 'sd', | ||
buildPath: outputDir, | ||
files: [ | ||
{ | ||
destination: outputFileName, | ||
format: 'css/variables', | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
let dict: StyleDictionary.Core | undefined; | ||
|
||
describe('sd-transforms advanced tests', () => { | ||
beforeEach(() => { | ||
if (dict) { | ||
cleanup(dict); | ||
} | ||
dict = init(cfg); | ||
}); | ||
|
||
afterEach(() => { | ||
if (dict) { | ||
cleanup(dict); | ||
} | ||
}); | ||
|
||
it('supports typography tokens with math or fontweight alias', async () => { | ||
const file = await promises.readFile(outputFilePath, 'utf-8'); | ||
expect(file).to.include(`--sdTypo: 400 24px/1.125 Arial Black;`); | ||
}); | ||
|
||
it('supports border tokens with math width and hexrgba color', async () => { | ||
const file = await promises.readFile(outputFilePath, 'utf-8'); | ||
expect(file).to.include(`--sdBorder: 24px dashed rgba(255, 255, 0, 0.5);`); | ||
}); | ||
|
||
it('supports box shadow tokens with math dimensions, hexrgba color', async () => { | ||
const file = await promises.readFile(outputFilePath, 'utf-8'); | ||
expect(file).to.include(`--sdShadowSingle: inset 0 4px 10px 0 rgba(0, 0, 0, 0.4);`); | ||
expect(file).to.include( | ||
`--sdShadowDouble: inset 0 4px 10px 0 rgba(0, 0, 0, 0.4), inset 0 4px 10px 0 rgba(255, 255, 255, 0.2);`, | ||
); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
test/integration/tokens/math-in-complex-values.tokens.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"typo": { | ||
"value": { | ||
"fontFamily": "Arial Black", | ||
"fontSize": "16 * 1.5", | ||
"fontWeight": "regular", | ||
"lineHeight": "0.75 * 1.5" | ||
}, | ||
"type": "typography" | ||
}, | ||
"border": { | ||
"value": { | ||
"color": "rgba(#FFFF00, 0.5)", | ||
"width": "16 * 1.5", | ||
"style": "dashed" | ||
}, | ||
"type": "border" | ||
}, | ||
"shadow": { | ||
"single": { | ||
"value": { | ||
"x": "0", | ||
"y": "3 + 1", | ||
"blur": "100 / 10", | ||
"spread": "0", | ||
"color": "rgba(#000000,0.4)", | ||
"type": "innerShadow" | ||
}, | ||
"type": "boxShadow" | ||
}, | ||
"double": { | ||
"value": [ | ||
{ | ||
"x": "0", | ||
"y": "3 + 1", | ||
"blur": "100 / 10", | ||
"spread": "0", | ||
"color": "rgba(#000000,0.4)", | ||
"type": "innerShadow" | ||
}, | ||
{ | ||
"x": "0", | ||
"y": "5 - 1", | ||
"blur": "1 * 10", | ||
"spread": "0", | ||
"color": "rgba(#FFFFFF,0.2)", | ||
"type": "innerShadow" | ||
} | ||
], | ||
"type": "boxShadow" | ||
} | ||
} | ||
} |