@primer/primitives 7.8.1-rc.1ae7ba9 → 7.8.2
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/CHANGELOG.md +6 -0
- package/build.js +528 -0
- package/package.json +7 -4
- package/tokens/base/size/size.json +57 -0
- package/tokens/base/typography/typography.json +20 -0
- package/tokens/functional/size/border.json +40 -0
- package/tokens/functional/size/breakpoints.json +24 -0
- package/tokens/functional/size/size-coarse.json +27 -0
- package/tokens/functional/size/size-fine.json +27 -0
- package/tokens/functional/size/size.json +189 -0
- package/tokens/functional/size/viewport.json +24 -0
- package/tokens/functional/typography/typography.json +214 -0
- package/tokens-v2-private/css/tokens/base/size/size.css +1 -1
- package/tokens-v2-private/css/tokens/base/typography/typography.css +1 -1
- package/tokens-v2-private/css/tokens/functional/size/border.css +1 -1
- package/tokens-v2-private/css/tokens/functional/size/breakpoints.css +1 -1
- package/tokens-v2-private/css/tokens/functional/size/size-coarse.css +10 -0
- package/tokens-v2-private/css/tokens/functional/size/size-fine.css +4 -4
- package/tokens-v2-private/css/tokens/functional/size/size.css +7 -7
- package/tokens-v2-private/css/tokens/functional/typography/typography.css +1 -1
- package/tokens-v2-private/js/module/tokens/base/size/size.js +1 -1
- package/tokens-v2-private/js/module/tokens/base/typography/typography.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/size/border.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/size/breakpoints.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/size/size-coarse.js +73 -0
- package/tokens-v2-private/js/module/tokens/functional/size/size-fine.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/size/size.js +103 -103
- package/tokens-v2-private/js/module/tokens/functional/size/viewport.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/typography/typography.js +1 -1
- package/tokens-v2-private/js/tokens/base/size/size.js +1 -1
- package/tokens-v2-private/js/tokens/base/typography/typography.js +1 -1
- package/tokens-v2-private/js/tokens/functional/size/border.js +1 -1
- package/tokens-v2-private/js/tokens/functional/size/breakpoints.js +1 -1
- package/tokens-v2-private/js/tokens/functional/size/size-coarse.js +8 -0
- package/tokens-v2-private/js/tokens/functional/size/size-fine.js +1 -1
- package/tokens-v2-private/js/tokens/functional/size/size.js +8 -8
- package/tokens-v2-private/js/tokens/functional/size/viewport.js +1 -1
- package/tokens-v2-private/js/tokens/functional/typography/typography.js +1 -1
- package/tokens-v2-private/ts/tokens/base/size/size.d.ts +2 -2
- package/tokens-v2-private/ts/tokens/base/size/size.js +1 -1
- package/tokens-v2-private/ts/tokens/base/typography/typography.d.ts +2 -2
- package/tokens-v2-private/ts/tokens/base/typography/typography.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/border.d.ts +2 -2
- package/tokens-v2-private/ts/tokens/functional/size/border.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/breakpoints.d.ts +2 -2
- package/tokens-v2-private/ts/tokens/functional/size/breakpoints.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/size-coarse.d.ts +27 -0
- package/tokens-v2-private/ts/tokens/functional/size/size-coarse.js +26 -0
- package/tokens-v2-private/ts/tokens/functional/size/size-fine.d.ts +2 -2
- package/tokens-v2-private/ts/tokens/functional/size/size-fine.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/size.d.ts +14 -14
- package/tokens-v2-private/ts/tokens/functional/size/size.js +13 -13
- package/tokens-v2-private/ts/tokens/functional/size/viewport.d.ts +2 -2
- package/tokens-v2-private/ts/tokens/functional/size/viewport.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/typography/typography.d.ts +2 -2
- package/tokens-v2-private/ts/tokens/functional/typography/typography.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @primer/primitives
|
|
2
2
|
|
|
3
|
+
## 7.8.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#323](https://github.com/primer/primitives/pull/323) [`40f15d5`](https://github.com/primer/primitives/commit/40f15d530a130390debb794dbc4080f58b42d49e) Thanks [@rezrah](https://github.com/rezrah)! - add self serve tooling for v2 primitives
|
|
8
|
+
|
|
3
9
|
## 7.8.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/build.js
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
const glob = require('fast-glob')
|
|
2
|
+
const StyleDictionary = require('style-dictionary')
|
|
3
|
+
|
|
4
|
+
const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers
|
|
5
|
+
|
|
6
|
+
// REGISTER THE CUSTOM TRANFORMS
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* transform: css variable names
|
|
10
|
+
* example: `--namespace-item-variant-property-modifier`
|
|
11
|
+
*/
|
|
12
|
+
StyleDictionary.registerTransform({
|
|
13
|
+
name: 'name/css',
|
|
14
|
+
type: 'name',
|
|
15
|
+
transformer: (token, options) => {
|
|
16
|
+
return token.path.join('-')
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* transform: js variable names
|
|
22
|
+
* example: `namespace.item.variant.property.modifier`
|
|
23
|
+
*/
|
|
24
|
+
StyleDictionary.registerTransform({
|
|
25
|
+
name: 'name/js',
|
|
26
|
+
type: 'name',
|
|
27
|
+
transformer: (token, options) => {
|
|
28
|
+
return token.path.join('.')
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* transform: js es6 variable names
|
|
34
|
+
* example: `NamespaceItemVariantPropertyModifier`
|
|
35
|
+
*/
|
|
36
|
+
StyleDictionary.registerTransform({
|
|
37
|
+
name: 'name/js/es6',
|
|
38
|
+
type: 'name',
|
|
39
|
+
transformer: (token, options) => {
|
|
40
|
+
const tokenPath = token.path.join(' ')
|
|
41
|
+
const tokenPathItems = tokenPath.split(' ')
|
|
42
|
+
for (var i = 0; i < tokenPathItems.length; i++) {
|
|
43
|
+
tokenPathItems[i] = tokenPathItems[i].charAt(0).toUpperCase() + tokenPathItems[i].slice(1)
|
|
44
|
+
}
|
|
45
|
+
const tokenName = tokenPathItems.join('')
|
|
46
|
+
return tokenName
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// find values with px unit
|
|
51
|
+
function isPx(value) {
|
|
52
|
+
return /[\d\.]+px$/.test(value)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// transform: px to rem
|
|
56
|
+
StyleDictionary.registerTransform({
|
|
57
|
+
name: 'pxToRem',
|
|
58
|
+
type: 'value',
|
|
59
|
+
transformer: (token, options) => {
|
|
60
|
+
if (isPx(token.value)) {
|
|
61
|
+
const baseFontSize = 16
|
|
62
|
+
const floatValue = parseFloat(token.value.replace('px', ''))
|
|
63
|
+
|
|
64
|
+
if (isNaN(floatValue)) {
|
|
65
|
+
return token.value
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (floatValue === 0) {
|
|
69
|
+
return '0'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return `${floatValue / baseFontSize}rem`
|
|
73
|
+
}
|
|
74
|
+
return token.value
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
//-----
|
|
79
|
+
|
|
80
|
+
// ts output
|
|
81
|
+
StyleDictionary.registerTransform({
|
|
82
|
+
name: 'attribute/typescript',
|
|
83
|
+
type: 'attribute',
|
|
84
|
+
transformer: token => {
|
|
85
|
+
return {
|
|
86
|
+
typescript: {
|
|
87
|
+
// these transforms will need to match the ones you use for typescript
|
|
88
|
+
// or you can "chain" the transforms and use token.name and token.value
|
|
89
|
+
// like scss and less transforms do.
|
|
90
|
+
name: token.path.slice(1).join('.'),
|
|
91
|
+
value: token.value
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// css output
|
|
98
|
+
StyleDictionary.registerTransform({
|
|
99
|
+
name: 'attribute/css',
|
|
100
|
+
type: 'attribute',
|
|
101
|
+
transformer: token => {
|
|
102
|
+
const tokenName = token.path.slice(1).join('-')
|
|
103
|
+
return {
|
|
104
|
+
css: {
|
|
105
|
+
name: `--${tokenName}`,
|
|
106
|
+
value: token.value
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
// transform: composite typography to shorthands
|
|
113
|
+
StyleDictionary.registerTransform({
|
|
114
|
+
name: 'typography/shorthand',
|
|
115
|
+
type: 'value',
|
|
116
|
+
transitive: true,
|
|
117
|
+
matcher: token => token.type === 'typography',
|
|
118
|
+
transformer: token => {
|
|
119
|
+
const {value} = token
|
|
120
|
+
return `${value.fontWeight} ${value.fontSize}/${value.lineHeight} ${value.fontFamily}`
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
// REGISTER THE CUSTOM TRANFORM GROUPS
|
|
125
|
+
|
|
126
|
+
StyleDictionary.registerTransformGroup({
|
|
127
|
+
name: 'css',
|
|
128
|
+
transforms: ['name/css', 'pxToRem', 'typography/shorthand']
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
// REGISTER A CUSTOM FORMAT
|
|
132
|
+
|
|
133
|
+
// wrap mobile tokens in media query
|
|
134
|
+
StyleDictionary.registerFormat({
|
|
135
|
+
name: 'css/touch-target-mobile',
|
|
136
|
+
formatter: function({dictionary, file, options}) {
|
|
137
|
+
const {outputReferences} = options
|
|
138
|
+
return (
|
|
139
|
+
fileHeader({file}) +
|
|
140
|
+
`@media (pointer: coarse) { :root {\n` +
|
|
141
|
+
formattedVariables({format: 'css', dictionary, outputReferences}) +
|
|
142
|
+
'\n}}\n'
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
// wrap desktop tokens in media query
|
|
148
|
+
StyleDictionary.registerFormat({
|
|
149
|
+
name: 'css/touch-target-desktop',
|
|
150
|
+
formatter: function({dictionary, file, options}) {
|
|
151
|
+
const {outputReferences} = options
|
|
152
|
+
return (
|
|
153
|
+
fileHeader({file}) +
|
|
154
|
+
`@media (pointer: fine) { :root {\n` +
|
|
155
|
+
formattedVariables({format: 'css', dictionary, outputReferences}) +
|
|
156
|
+
'\n}}\n'
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
StyleDictionary.registerFormat({
|
|
162
|
+
name: 'custom/format/custom-media',
|
|
163
|
+
formatter({dictionary}) {
|
|
164
|
+
return dictionary.allProperties
|
|
165
|
+
.map(prop => {
|
|
166
|
+
const {value, path, name} = prop
|
|
167
|
+
// const tokenPath = path
|
|
168
|
+
// const tokenProperty = path[path.length - 1]
|
|
169
|
+
return `@custom-media --${name}-viewport ${value};`
|
|
170
|
+
})
|
|
171
|
+
.join('\n')
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
// format docs
|
|
176
|
+
StyleDictionary.registerFormat({
|
|
177
|
+
name: 'json/docs',
|
|
178
|
+
formatter: function({dictionary}) {
|
|
179
|
+
const groupedTokens = groupBy(dictionary.allProperties, 'filePath')
|
|
180
|
+
|
|
181
|
+
return JSON.stringify(groupedTokens, null, 2)
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Replacement format for javascript/module
|
|
187
|
+
*/
|
|
188
|
+
StyleDictionary.registerFormat({
|
|
189
|
+
name: 'javascript/module-v2',
|
|
190
|
+
formatter: function({dictionary, file}) {
|
|
191
|
+
const recursiveleyFlattenDictionary = obj => {
|
|
192
|
+
const tree = {}
|
|
193
|
+
if (typeof obj !== 'object' || Array.isArray(obj)) {
|
|
194
|
+
return obj
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (obj.hasOwnProperty('value')) {
|
|
198
|
+
return obj.value
|
|
199
|
+
} else {
|
|
200
|
+
for (const name in obj) {
|
|
201
|
+
if (obj.hasOwnProperty(name)) {
|
|
202
|
+
tree[name] = recursiveleyFlattenDictionary(obj[name])
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return tree
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
fileHeader({file}) +
|
|
211
|
+
'module.exports = ' +
|
|
212
|
+
JSON.stringify(recursiveleyFlattenDictionary(dictionary.tokens), null, 2)
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Replacement format for typescript/module-declarations
|
|
219
|
+
* Type schema corresponds to javascript/module-v2 format
|
|
220
|
+
*/
|
|
221
|
+
StyleDictionary.registerFormat({
|
|
222
|
+
name: 'typescript/module-declarations-v2',
|
|
223
|
+
formatter: function({dictionary, options, file}) {
|
|
224
|
+
const {moduleName = `tokens`} = options
|
|
225
|
+
|
|
226
|
+
const getType = value => {
|
|
227
|
+
switch (typeof value) {
|
|
228
|
+
case 'string':
|
|
229
|
+
return 'string'
|
|
230
|
+
case 'number':
|
|
231
|
+
return 'number'
|
|
232
|
+
default:
|
|
233
|
+
return 'any'
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const recursiveTypeGeneration = obj => {
|
|
238
|
+
const tree = {}
|
|
239
|
+
const shortHandSizes = ['large', 'medium', 'small']
|
|
240
|
+
if (typeof obj !== 'object' || Array.isArray(obj)) {
|
|
241
|
+
return obj
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (obj.hasOwnProperty('value') && typeof obj.value === 'string') {
|
|
245
|
+
return getType(obj.value)
|
|
246
|
+
} else {
|
|
247
|
+
for (const name in obj) {
|
|
248
|
+
if ((obj.hasOwnProperty(name) && obj.name === 'shorthand') || shortHandSizes.includes(obj.name)) {
|
|
249
|
+
for (const shorthandKey in obj.value) {
|
|
250
|
+
tree[shorthandKey] = getType(obj.value[shorthandKey])
|
|
251
|
+
}
|
|
252
|
+
return tree
|
|
253
|
+
} else if (obj.hasOwnProperty(name)) {
|
|
254
|
+
tree[name] = recursiveTypeGeneration(obj[name])
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return tree
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const output =
|
|
262
|
+
fileHeader({file}) +
|
|
263
|
+
`declare const ${moduleName}: ${JSON.stringify(recursiveTypeGeneration(dictionary.tokens), null, 2)}
|
|
264
|
+
export default ${moduleName};`
|
|
265
|
+
|
|
266
|
+
return output
|
|
267
|
+
.replace(/"any"/g, 'any')
|
|
268
|
+
.replace(/"string"/g, 'string')
|
|
269
|
+
.replace(/"number"/g, 'number')
|
|
270
|
+
}
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* @name groupBy
|
|
275
|
+
* @description Equivalent to lodash _.groupBy, to avoid creating another package dependency for users
|
|
276
|
+
* @param {Array|Object} The collection to iterate over.
|
|
277
|
+
* @param {Function} The iteratee to transform keys.
|
|
278
|
+
* @returns {Object} Returns the composed aggregate object.
|
|
279
|
+
*/
|
|
280
|
+
function groupBy(collection, iteratee = x => x) {
|
|
281
|
+
const current = typeof iteratee === 'function' ? iteratee : ({[iteratee]: prop}) => prop
|
|
282
|
+
|
|
283
|
+
const array = Array.isArray(collection) ? collection : Object.values(collection)
|
|
284
|
+
|
|
285
|
+
return array.reduce((acc, item) => {
|
|
286
|
+
const value = current(item)
|
|
287
|
+
|
|
288
|
+
acc[value] = acc[value] || []
|
|
289
|
+
|
|
290
|
+
acc[value].push(item)
|
|
291
|
+
|
|
292
|
+
return acc
|
|
293
|
+
}, {})
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* @name build
|
|
298
|
+
* @description
|
|
299
|
+
* Used to generate design tokens programmatically using StyleDictionary
|
|
300
|
+
* Called internally to build primitives and exported for self-serve use
|
|
301
|
+
*
|
|
302
|
+
* @param {Object} options
|
|
303
|
+
* @param {string} options.source glob or file path to a JSON object of tokens
|
|
304
|
+
* @param {string} options.outputPath location to write the output files
|
|
305
|
+
* @param {string} options.namespace a custom namespace to use for the output files
|
|
306
|
+
* @param {Platform} options.platforms add custom platform configurations to style-dictionary
|
|
307
|
+
* @example
|
|
308
|
+
* buildPrimitives({
|
|
309
|
+
* source: [`src/colors.json`],
|
|
310
|
+
* outputPath: 'dist',
|
|
311
|
+
* namespace: 'primer',
|
|
312
|
+
* platforms: {...}
|
|
313
|
+
* })
|
|
314
|
+
*/
|
|
315
|
+
function buildPrimitives({source, outputPath = 'tokens-v2-private', include, platforms, namespace = 'primer'}) {
|
|
316
|
+
console.log('Build started...')
|
|
317
|
+
console.log('\n==============================================')
|
|
318
|
+
|
|
319
|
+
const customParseConfig = {
|
|
320
|
+
parsers: [
|
|
321
|
+
{
|
|
322
|
+
pattern: /\.json$/,
|
|
323
|
+
parse: ({contents, filePath}) => {
|
|
324
|
+
try {
|
|
325
|
+
let mutableContent = JSON.stringify(contents)
|
|
326
|
+
|
|
327
|
+
if (filePath.includes('/functional/')) {
|
|
328
|
+
mutableContent = mutableContent.replace(/<namespace>/g, namespace)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const parsed = JSON.parse(mutableContent)
|
|
332
|
+
|
|
333
|
+
return JSON.parse(parsed)
|
|
334
|
+
} catch (error) {
|
|
335
|
+
console.log(error)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const getConfig = files => {
|
|
343
|
+
const defaultPlatformConfig = {
|
|
344
|
+
css: {
|
|
345
|
+
buildPath: `${outputPath}/css/`,
|
|
346
|
+
transformGroup: 'css',
|
|
347
|
+
// map the array of token file paths to style dictionary output files
|
|
348
|
+
files: files.map(filePath => {
|
|
349
|
+
return {
|
|
350
|
+
format: `css/variables`,
|
|
351
|
+
destination: filePath.replace(`.json`, `.css`),
|
|
352
|
+
filter: token => token.filePath === filePath,
|
|
353
|
+
options: {
|
|
354
|
+
outputReferences: true
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
})
|
|
358
|
+
},
|
|
359
|
+
cssViewport: {
|
|
360
|
+
buildPath: `${outputPath}/css/tokens/functional/size/`,
|
|
361
|
+
transformGroup: 'css',
|
|
362
|
+
files: [
|
|
363
|
+
{
|
|
364
|
+
filter: token => token.filePath.includes('viewport'),
|
|
365
|
+
format: 'custom/format/custom-media',
|
|
366
|
+
destination: 'viewport.css'
|
|
367
|
+
}
|
|
368
|
+
]
|
|
369
|
+
},
|
|
370
|
+
js: {
|
|
371
|
+
buildPath: `${outputPath}/js/`,
|
|
372
|
+
transforms: ['name/js/es6', 'pxToRem'],
|
|
373
|
+
// map the array of token file paths to style dictionary output files
|
|
374
|
+
files: files.map(filePath => {
|
|
375
|
+
return {
|
|
376
|
+
format: `javascript/es6`,
|
|
377
|
+
destination: filePath.replace(`.json`, `.js`),
|
|
378
|
+
filter: token => token.filePath === filePath
|
|
379
|
+
}
|
|
380
|
+
})
|
|
381
|
+
},
|
|
382
|
+
jsModule: {
|
|
383
|
+
buildPath: `${outputPath}/js/module/`,
|
|
384
|
+
transforms: ['pxToRem'],
|
|
385
|
+
// map the array of token file paths to style dictionary output files
|
|
386
|
+
files: files.map(filePath => {
|
|
387
|
+
return {
|
|
388
|
+
format: `javascript/module`,
|
|
389
|
+
destination: filePath.replace(`.json`, `.js`),
|
|
390
|
+
filter: token => token.filePath === filePath
|
|
391
|
+
}
|
|
392
|
+
})
|
|
393
|
+
},
|
|
394
|
+
tsTypes: {
|
|
395
|
+
buildPath: `${outputPath}/ts/`,
|
|
396
|
+
transforms: ['pxToRem'],
|
|
397
|
+
// map the array of token file paths to style dictionary output files
|
|
398
|
+
files: files.map(filePath => {
|
|
399
|
+
return {
|
|
400
|
+
format: `typescript/module-declarations-v2`,
|
|
401
|
+
destination: filePath.replace(`.json`, `.d.ts`),
|
|
402
|
+
filter: token => token.filePath === filePath
|
|
403
|
+
}
|
|
404
|
+
})
|
|
405
|
+
},
|
|
406
|
+
ts: {
|
|
407
|
+
buildPath: `${outputPath}/ts/`,
|
|
408
|
+
transforms: ['pxToRem'],
|
|
409
|
+
// map the array of token file paths to style dictionary output files
|
|
410
|
+
files: files.map(filePath => {
|
|
411
|
+
return {
|
|
412
|
+
format: `javascript/module-v2`,
|
|
413
|
+
destination: filePath.replace(`.json`, `.js`),
|
|
414
|
+
filter: token => token.filePath === filePath
|
|
415
|
+
}
|
|
416
|
+
})
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const config = {
|
|
421
|
+
...{include: include ? [include] : undefined},
|
|
422
|
+
source: files,
|
|
423
|
+
...customParseConfig,
|
|
424
|
+
platforms: platforms ? platforms : defaultPlatformConfig
|
|
425
|
+
}
|
|
426
|
+
return config
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
//build all tokens
|
|
430
|
+
StyleDictionary.extend({
|
|
431
|
+
...getConfig(glob.sync([...source]))
|
|
432
|
+
}).buildAllPlatforms()
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* @name init
|
|
437
|
+
* @description
|
|
438
|
+
* Triggers the build for @primer/primitive default tokens
|
|
439
|
+
* from an npm script. Internal use only. Use `build` for self-serve.
|
|
440
|
+
* @private
|
|
441
|
+
*/
|
|
442
|
+
function _init() {
|
|
443
|
+
const outputPath = 'tokens-v2-private'
|
|
444
|
+
//build all tokens
|
|
445
|
+
buildPrimitives({
|
|
446
|
+
source: [`tokens/**/*.json`, `!tokens/**/size-*.json`],
|
|
447
|
+
outputPath
|
|
448
|
+
})
|
|
449
|
+
|
|
450
|
+
//build size fine
|
|
451
|
+
buildPrimitives({
|
|
452
|
+
source: [`tokens/functional/size/size-fine.json`, `tokens/base/size/size.json`],
|
|
453
|
+
outputPath
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
//build size coarse
|
|
457
|
+
buildPrimitives({
|
|
458
|
+
source: [`tokens/functional/size/size-coarse.json`, `tokens/base/size/size.json`],
|
|
459
|
+
outputPath
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
buildPrimitives({
|
|
463
|
+
source: [`tokens/base/size/size.json`, `tokens/functional/size/size-fine.json`],
|
|
464
|
+
outputPath,
|
|
465
|
+
platforms: {
|
|
466
|
+
css: {
|
|
467
|
+
buildPath: `${outputPath}/css/`,
|
|
468
|
+
transformGroup: 'css',
|
|
469
|
+
files: [
|
|
470
|
+
{
|
|
471
|
+
destination: `tokens/functional/size/size-fine.css`,
|
|
472
|
+
format: `css/touch-target-desktop`,
|
|
473
|
+
filter: token => token.filePath.includes('fine'),
|
|
474
|
+
options: {
|
|
475
|
+
outputReferences: true
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
]
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
})
|
|
482
|
+
|
|
483
|
+
buildPrimitives({
|
|
484
|
+
source: [`tokens/base/size/size.json`, `tokens/functional/size/size-coarse.json`],
|
|
485
|
+
platforms: {
|
|
486
|
+
css: {
|
|
487
|
+
buildPath: `${outputPath}/css/`,
|
|
488
|
+
transformGroup: 'css',
|
|
489
|
+
files: [
|
|
490
|
+
{
|
|
491
|
+
destination: `tokens/functional/size/size-coarse.css`,
|
|
492
|
+
format: `css/touch-target-mobile`,
|
|
493
|
+
filter: token => token.filePath.includes('coarse'),
|
|
494
|
+
options: {
|
|
495
|
+
outputReferences: true
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
]
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
//build docs data
|
|
504
|
+
buildPrimitives({
|
|
505
|
+
source: [`tokens/**/*.json`],
|
|
506
|
+
outputPath,
|
|
507
|
+
platforms: {
|
|
508
|
+
docs: {
|
|
509
|
+
buildPath: `${outputPath}/docs/`,
|
|
510
|
+
transformGroup: 'css',
|
|
511
|
+
files: [
|
|
512
|
+
{
|
|
513
|
+
format: 'json/docs',
|
|
514
|
+
destination: 'docValues.json',
|
|
515
|
+
options: {
|
|
516
|
+
outputReferences: false
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
]
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
})
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
module.exports = {
|
|
526
|
+
buildPrimitives,
|
|
527
|
+
_init
|
|
528
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/primitives",
|
|
3
|
-
"version": "7.8.
|
|
3
|
+
"version": "7.8.2",
|
|
4
4
|
"description": "Typography, spacing, and color primitives for Primer design system",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
|
-
"tokens-v2-private"
|
|
7
|
+
"tokens-v2-private",
|
|
8
|
+
"build.js",
|
|
9
|
+
"tokens/"
|
|
8
10
|
],
|
|
9
11
|
"main": "dist/js/index.js",
|
|
10
12
|
"types": "dist/js/index.d.ts",
|
|
@@ -25,8 +27,9 @@
|
|
|
25
27
|
"homepage": "https://github.com/primer/primitives#readme",
|
|
26
28
|
"scripts": {
|
|
27
29
|
"build": "ts-node ./script/build.ts && tsc",
|
|
28
|
-
"build:tokens": "node ./build.
|
|
29
|
-
"prebuild": "rm -rf dist
|
|
30
|
+
"build:tokens": "node -e \"require('./build')._init()\"",
|
|
31
|
+
"prebuild": "rm -rf dist",
|
|
32
|
+
"prebuild:tokens": "rm -rf tokens-v2-private",
|
|
30
33
|
"prepack": "yarn build && yarn build:tokens",
|
|
31
34
|
"release": "changeset publish",
|
|
32
35
|
"watch": "ls data/**/*.scss script/**/*.ts | entr -s 'yarn build'"
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"base": {
|
|
3
|
+
"size": {
|
|
4
|
+
"4": {
|
|
5
|
+
"value": "4px"
|
|
6
|
+
},
|
|
7
|
+
"8": {
|
|
8
|
+
"value": "8px"
|
|
9
|
+
},
|
|
10
|
+
"12": {
|
|
11
|
+
"value": "12px"
|
|
12
|
+
},
|
|
13
|
+
"16": {
|
|
14
|
+
"value": "16px"
|
|
15
|
+
},
|
|
16
|
+
"20": {
|
|
17
|
+
"value": "20px"
|
|
18
|
+
},
|
|
19
|
+
"24": {
|
|
20
|
+
"value": "24px"
|
|
21
|
+
},
|
|
22
|
+
"28": {
|
|
23
|
+
"value": "28px"
|
|
24
|
+
},
|
|
25
|
+
"32": {
|
|
26
|
+
"value": "32px"
|
|
27
|
+
},
|
|
28
|
+
"36": {
|
|
29
|
+
"value": "36px"
|
|
30
|
+
},
|
|
31
|
+
"40": {
|
|
32
|
+
"value": "40px"
|
|
33
|
+
},
|
|
34
|
+
"44": {
|
|
35
|
+
"value": "44px"
|
|
36
|
+
},
|
|
37
|
+
"48": {
|
|
38
|
+
"value": "48px"
|
|
39
|
+
},
|
|
40
|
+
"64": {
|
|
41
|
+
"value": "64px"
|
|
42
|
+
},
|
|
43
|
+
"80": {
|
|
44
|
+
"value": "80px"
|
|
45
|
+
},
|
|
46
|
+
"96": {
|
|
47
|
+
"value": "96px"
|
|
48
|
+
},
|
|
49
|
+
"112": {
|
|
50
|
+
"value": "112px"
|
|
51
|
+
},
|
|
52
|
+
"128": {
|
|
53
|
+
"value": "128px"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"<namespace>": {
|
|
3
|
+
"borderInset": {
|
|
4
|
+
"thin": {
|
|
5
|
+
"value": "inset 0 0 0 {<namespace>.borderWidth.thin}"
|
|
6
|
+
},
|
|
7
|
+
"normal": {
|
|
8
|
+
"value": "inset 0 0 0 {<namespace>.borderWidth.normal}"
|
|
9
|
+
},
|
|
10
|
+
"thick": {
|
|
11
|
+
"value": "inset 0 0 0 {<namespace>.borderWidth.thick}"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"borderWidth": {
|
|
15
|
+
"thin": {
|
|
16
|
+
"value": "max(1px, 0.0625rem)"
|
|
17
|
+
},
|
|
18
|
+
"normal": {
|
|
19
|
+
"value": "max(2px, 0.125rem)"
|
|
20
|
+
},
|
|
21
|
+
"thick": {
|
|
22
|
+
"value": "max(4px, 0.25rem)"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"borderRadius": {
|
|
26
|
+
"small": {
|
|
27
|
+
"value": "3px"
|
|
28
|
+
},
|
|
29
|
+
"medium": {
|
|
30
|
+
"value": "6px"
|
|
31
|
+
},
|
|
32
|
+
"large": {
|
|
33
|
+
"value": "12px"
|
|
34
|
+
},
|
|
35
|
+
"full": {
|
|
36
|
+
"value": "100vh"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"<namespace>": {
|
|
3
|
+
"breakpoint": {
|
|
4
|
+
"xsmall": {
|
|
5
|
+
"value": "320px"
|
|
6
|
+
},
|
|
7
|
+
"small": {
|
|
8
|
+
"value": "544px"
|
|
9
|
+
},
|
|
10
|
+
"medium": {
|
|
11
|
+
"value": "768px"
|
|
12
|
+
},
|
|
13
|
+
"large": {
|
|
14
|
+
"value": "1012px"
|
|
15
|
+
},
|
|
16
|
+
"xlarge": {
|
|
17
|
+
"value": "1280px"
|
|
18
|
+
},
|
|
19
|
+
"xxlarge": {
|
|
20
|
+
"value": "1440px"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|