+42 -0 +/-2 browse
1 | diff --git a/build/props.js b/build/props.js |
2 | index fc8a4f0..c62c4df 100644 |
3 | --- a/build/props.js |
4 | +++ b/build/props.js |
5 | @@ -22,6 +22,7 @@ import {buildPropsStylesheet} from './to-stylesheet.js' |
6 | import {toTokens} from './to-tokens.js' |
7 | import {toObject} from './to-object.js' |
8 | import {toFigmaTokens} from './to-figmatokens.js' |
9 | + import {toAtProperty} from './to-at-property.js' |
10 | |
11 | const [,,prefix='',useWhere,customSubject='',filePrefix=''] = process.argv |
12 | |
13 | @@ -86,6 +87,16 @@ const figmatokensSYNC = { 'open-props': { ...figmatokens } } |
14 | const FigmaTokensSync = fs.createWriteStream('../open-props.figma-tokens.sync.json') |
15 | FigmaTokensSync.end(JSON.stringify(figmatokensSYNC, null, 2)) |
16 | |
17 | + // gen @property module |
18 | + const atTokens = toAtProperty(Object.entries({ |
19 | + ...Object.assign({}, ...Object.values(individual_colors)), |
20 | + // ...Easings, |
21 | + ...Zindex, |
22 | + ...Aspects, |
23 | + })) |
24 | + const atProperty = fs.createWriteStream('../open-props.typed.js') |
25 | + atProperty.end(JSON.stringify(atTokens)+'.forEach(CSS.registerProperty)', null, 2) |
26 | + |
27 | if (!fs.existsSync('../dist')) |
28 | fs.mkdirSync('../dist') |
29 | |
30 | diff --git a/build/to-at-property.js b/build/to-at-property.js |
31 | new file mode 100644 |
32 | index 0000000..6298310 |
33 | --- /dev/null |
34 | +++ b/build/to-at-property.js |
35 | @@ -0,0 +1,31 @@ |
36 | + import * as Colors from '../src/props.colors.js' |
37 | + |
38 | + const colors = Object.keys(Colors) |
39 | + .filter(exportName => exportName !== "default") |
40 | + .map(hueName => hueName.toLowerCase()) |
41 | + |
42 | + export const toAtProperty = props => |
43 | + props.map(([key, token]) => { |
44 | + let syntax |
45 | + |
46 | + let isLength = key.includes('size') |
47 | + let isRatio = key.includes('ratio') |
48 | + let isEasing = key.includes('ease') |
49 | + let isZIndex= key.includes('layer') |
50 | + let isImage = key.includes('gradient') |
51 | + let isColor = colors.some(color => key.includes(color)) |
52 | + |
53 | + if (isLength) syntax = 'dimension' |
54 | + else if (isEasing) syntax = 'cubic-bezier' |
55 | + else if (isColor) syntax = 'color' |
56 | + else if (isRatio) syntax = 'ratio' |
57 | + else if (isImage) syntax = 'image' |
58 | + else if (isZIndex) syntax = 'number' |
59 | + |
60 | + return { |
61 | + name: key, |
62 | + syntax: `<${syntax}>`, |
63 | + initialValue: token, |
64 | + inherits: false, |
65 | + } |
66 | + }) |
67 | \ No newline at end of file |