@planningcenter/tapestry-tokens 0.0.1 → 3.0.0-rc.27

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 (41) hide show
  1. package/{src → dist}/css/components/banner.css +8 -8
  2. package/dist/css/product-tokens/accounts.css +17 -0
  3. package/dist/css/product-tokens/calendar.css +17 -0
  4. package/dist/css/product-tokens/checkins.css +17 -0
  5. package/dist/css/product-tokens/giving.css +17 -0
  6. package/dist/css/product-tokens/groups.css +17 -0
  7. package/dist/css/product-tokens/home.css +16 -0
  8. package/dist/css/product-tokens/people.css +17 -0
  9. package/dist/css/product-tokens/publishing.css +17 -0
  10. package/dist/css/product-tokens/registrations.css +17 -0
  11. package/dist/css/product-tokens/services.css +17 -0
  12. package/dist/css/tokens-alias-deprecated-removed-segments.css +48 -0
  13. package/dist/css/tokens-alias-deprecated.css +42 -0
  14. package/dist/css/tokens-alias.css +427 -0
  15. package/dist/css/tokens-dark-deprecated.css +14 -0
  16. package/dist/css/tokens-dark.css +226 -0
  17. package/dist/css/tokens-system-dark-deprecated.css +16 -0
  18. package/dist/css/tokens-system-dark.css +228 -0
  19. package/dist/js/tokens-deprecated.json +326 -0
  20. package/dist/js/tokens.json +2004 -0
  21. package/dist/ts/react-native-tokens.d.ts +1959 -0
  22. package/dist/ts/react-native-tokens.d.ts.map +1 -0
  23. package/dist/ts/react-native-tokens.js +502 -0
  24. package/dist/ts/tokens.d.ts +505 -0
  25. package/dist/ts/tokens.d.ts.map +1 -0
  26. package/dist/ts/tokens.js +504 -0
  27. package/package.json +44 -17
  28. package/CHANGELOG.md +0 -0
  29. package/rollup.config.mjs +0 -12
  30. package/src/componentNames.js +0 -10
  31. package/src/css/tokens-alias-deprecated.css +0 -42
  32. package/src/css/tokens-alias.css +0 -334
  33. package/src/css/tokens.css +0 -2
  34. package/src/index.ts +0 -11
  35. package/src/json/alias.json +0 -1628
  36. package/src/json/components.json +0 -84
  37. package/src/json/primitives.json +0 -946
  38. package/src/style-dictionary.build.js +0 -367
  39. package/src/style-dictionary.config.js +0 -67
  40. package/src/ts/tokens.ts +0 -371
  41. package/tsconfig.build.json +0 -11
@@ -1,367 +0,0 @@
1
- import * as ChangeCase from "change-case"
2
- import fs from "fs"
3
- import StyleDictionary from "style-dictionary"
4
- import {
5
- fileHeader,
6
- getReferences,
7
- usesReferences,
8
- } from "style-dictionary/utils"
9
- import Color from "tinycolor2"
10
-
11
- import componentNames from "./componentNames.js"
12
- import { default as config } from "./style-dictionary.config.js"
13
-
14
- const prefix = config.platforms.css.prefix
15
-
16
- const deprecatedTokensRegex = /(\[DEPRECATED\]|🚫)/
17
-
18
- // Define the array of extra token extensions patterns
19
- const extraTokenExtensions = [/\d+\s?-\s?base$/, /\d+\s?-\s?white$/]
20
-
21
- // Rename component tokens by re-ordering the path array
22
- // e.g. [1, 2, 3, 4] => [1, 4, 2, 3]
23
- // [collection, group, group, token] => [collection, token, group, group]
24
- function reorderedNameKebab(path) {
25
- return reorderedName(path).join("-")
26
- }
27
-
28
- function reorderedName(path) {
29
- const newPath = []
30
- const length = path.length
31
-
32
- newPath.push(path[0], path[length - 1])
33
- for (let i = 1; i < length - 1; i++) {
34
- newPath.push(path[i])
35
- }
36
- return newPath
37
- }
38
-
39
- function trimExtraTokenExtensions(name) {
40
- extraTokenExtensions.forEach((pattern) => {
41
- name = name.replace(pattern, (match) =>
42
- match.split("-").slice(0, -1).join("-")
43
- )
44
- })
45
- return name
46
- }
47
-
48
- function normalizeName(token, options) {
49
- let { filePath, path } = token
50
- // Remove the collection at the front for alias tokens
51
- // e.g. color, numeric
52
- if (filePath.includes("alias")) {
53
- path = path.slice(1, path.length)
54
- }
55
- const orderedPath = isComponentDefinition(token) ? reorderedName(path) : path
56
- orderedPath[orderedPath.length - 1] = trimExtraTokenExtensions(
57
- orderedPath[orderedPath.length - 1]
58
- )
59
-
60
- return [options.prefix].concat(orderedPath).join(" ")
61
- }
62
-
63
- function isComponentDefinition({ filePath, path }) {
64
- return filePath.includes("components") && path.length > 2
65
- }
66
-
67
- console.log("Build started...")
68
- console.log("\n==============================================")
69
-
70
- // REGISTER CUSTOM FORMATS
71
- StyleDictionary.registerFormat({
72
- format: async function ({ dictionary, file, options }) {
73
- let lastComponentSelector
74
- const { outputReferences } = options
75
-
76
- const variables = dictionary.allTokens
77
- .map((token) => {
78
- let { name, path } = token
79
- const topPath = path[0]
80
- let value = token.$value
81
- const originalValue = token.original.$value
82
- let returnValue = ""
83
-
84
- if (file.destination.includes("components") && path.length > 2) {
85
- name = `${prefix}-${reorderedNameKebab(path)}`
86
- }
87
-
88
- name = trimExtraTokenExtensions(name).replaceAll("-deprecated", "")
89
-
90
- const shouldOutputRefs =
91
- usesReferences(originalValue) &&
92
- (typeof outputReferences === "function"
93
- ? outputReferences(token, { dictionary })
94
- : outputReferences)
95
-
96
- // Output alias token if value has a reference
97
- if (
98
- shouldOutputRefs &&
99
- usesReferences(originalValue, dictionary.tokens)
100
- ) {
101
- const refs = getReferences(originalValue, dictionary.unfilteredTokens)
102
- refs.forEach((ref) => {
103
- if (typeof value !== "string") {
104
- value = value.toString()
105
- }
106
- value = value.replace(ref.$value, function () {
107
- let refName = ref.name
108
- if (ref.filePath.includes("components") && ref.path.length > 2) {
109
- refName = `${prefix}-${reorderedNameKebab(ref.path)}`
110
- }
111
- refName = trimExtraTokenExtensions(refName)
112
- return `var(--${refName})`
113
- })
114
- })
115
- }
116
-
117
- returnValue = ` --${name}: ${value};`
118
-
119
- // Wrap/scope component-specific tokens with parent class
120
- if (
121
- file.destination.includes("components") &&
122
- lastComponentSelector !== topPath
123
- ) {
124
- const selector =
125
- topPath.charAt(0) === "_" ? ":root" : `.${prefix}-${topPath}`
126
-
127
- returnValue = `${selector} {\n${returnValue}`
128
- if (lastComponentSelector) {
129
- returnValue = `}\n${returnValue}`
130
- }
131
- lastComponentSelector = topPath
132
- }
133
-
134
- return returnValue
135
- })
136
-
137
- .join(`\n`)
138
-
139
- let filePrepend = ":root {\n"
140
- if (file.destination.includes("components")) {
141
- filePrepend = ""
142
- }
143
-
144
- return (await fileHeader({ file })) + filePrepend + variables + "\n}\n"
145
- },
146
- name: "css/variables-custom",
147
- })
148
-
149
- const CORRECTLY_ORDERED = ["color", "numeric"]
150
-
151
- StyleDictionary.registerFormat({
152
- format: async function ({ dictionary, options }) {
153
- const formattedTokens = Object.keys(dictionary.tokens).reduce(
154
- (acc, token) => {
155
- if (token === "color-primitive") return acc // Skip color-primitive
156
- return {
157
- ...acc,
158
- [token]: buildDefinitions(dictionary.tokens[token], {
159
- ...options,
160
- reorderName: !CORRECTLY_ORDERED.includes(token),
161
- }),
162
- }
163
- },
164
- {}
165
- )
166
-
167
- return JSON.stringify(formattedTokens, null, 2)
168
- },
169
- name: "json/docs-custom",
170
- })
171
-
172
- function buildDefinitions(data, options) {
173
- const prefix = options.platforms.css.prefix
174
- return Object.values(data).reduce((acc, obj) => {
175
- if (obj.$type) {
176
- const key = options.reorderName
177
- ? `--${prefix}-${reorderedNameKebab(obj.path)}`
178
- : `--${obj.name}`
179
- return {
180
- ...acc,
181
- [key]: {
182
- type: obj.$type,
183
- value: formatVar(obj.original.$value, { prefix }) || obj.$value,
184
- },
185
- }
186
- }
187
- return {
188
- ...acc,
189
- ...buildDefinitions(obj, options),
190
- }
191
- }, {})
192
- }
193
-
194
- function formatVar(str, { prefix }) {
195
- if (typeof str !== "string" || !str || str.startsWith("#")) return
196
- const strElements = str.replace(/{|}/g, "").split(".")
197
- const group = strElements[0]
198
- if (group === "color-primitive") return // we don't reference primitives
199
-
200
- return `var(--${prefix}-${strElements.slice(1).join("-")})`
201
- }
202
-
203
- StyleDictionary.registerFormat({
204
- format: async function ({ dictionary, options, file }) {
205
- const { formatting } = options
206
- const header = await fileHeader({ file, formatting, options })
207
- const content = [
208
- header,
209
- "export const tokens = {",
210
- dictionary.allTokens
211
- .map((token) => {
212
- const value = options.usesDtcg ? token.$value : token.value
213
- return ` "${token.name}": "${value}" as const`
214
- })
215
- .join(",\n"),
216
- "}\n",
217
- ]
218
- .flat()
219
- .join("\n")
220
- return content
221
- },
222
- name: "ts/flat-object",
223
- })
224
-
225
- // REGISTER CUSTOM TRANSFORMS
226
- StyleDictionary.registerTransform({
227
- name: "name/kebab-custom",
228
- transform: function (token, options) {
229
- // Remove the collection at the front for alias tokens
230
- // e.g. color, numeric
231
- let { filePath, path } = token
232
- if (filePath.includes("alias")) {
233
- path = path.slice(1, path.length)
234
- }
235
-
236
- return ChangeCase.kebabCase([options.prefix].concat(path).join(" "))
237
- },
238
- type: "name",
239
- })
240
-
241
- // This transform handles:
242
- // - Re-ordering the path for component tokens
243
- // - Removing the unwanted suffixes from the token name
244
- // - Formats as kebab-case
245
- StyleDictionary.registerTransform({
246
- name: "name/kebab-complete",
247
- transform(token, options) {
248
- const orderedName = normalizeName(token, options)
249
- const kebabName = ChangeCase.kebabCase(orderedName, {
250
- mergeAmbiguousCharacters: true,
251
- })
252
- return `--${kebabName}`
253
- },
254
- type: "name",
255
- })
256
-
257
- StyleDictionary.registerTransform({
258
- filter: function (token) {
259
- return (
260
- (token.attributes.category === "size" ||
261
- token.$type === "dimension" ||
262
- token.$type === "number") &&
263
- !token.name.includes("weight")
264
- )
265
- },
266
- name: "size/px-custom",
267
- transform: function (token) {
268
- return `${token.$value}px`
269
- },
270
- type: "value",
271
- })
272
-
273
- StyleDictionary.registerTransform({
274
- filter: function (token) {
275
- return token.attributes.category === "color" || token.$type === "color"
276
- },
277
- name: "color/hsl-custom",
278
- transform: function (token) {
279
- return Color(token.$value).toHslString()
280
- },
281
- type: "value",
282
- })
283
-
284
- // REGISTER CUSTOM FILTERS
285
- StyleDictionary.registerFilter({
286
- filter: function (token) {
287
- return (
288
- token.filePath.includes("alias") &&
289
- !token.path.join(" ").match(deprecatedTokensRegex)
290
- )
291
- },
292
- name: "onlyAlias",
293
- })
294
-
295
- StyleDictionary.registerFilter({
296
- filter: function (token) {
297
- return (
298
- token.filePath.includes("alias") &&
299
- token.path.join(" ").match(deprecatedTokensRegex)
300
- )
301
- },
302
- name: "onlyAliasDeprecated",
303
- })
304
-
305
- StyleDictionary.registerFilter({
306
- filter: function (token) {
307
- return token.filePath.includes("alias")
308
- },
309
- name: "allAlias",
310
- })
311
-
312
- StyleDictionary.registerFilter({
313
- filter: function (token) {
314
- return token.filePath.includes("components")
315
- },
316
- name: "onlyComponents",
317
- })
318
-
319
- StyleDictionary.registerFilter({
320
- filter: function (token) {
321
- return !token.path.join(" ").match(deprecatedTokensRegex)
322
- },
323
- name: "docsNoDeprecated",
324
- })
325
-
326
- StyleDictionary.registerFilter({
327
- filter: function (token) {
328
- return token.path.join(" ").match(deprecatedTokensRegex)
329
- },
330
- name: "docsOnlyDeprecated",
331
- })
332
-
333
- componentNames.forEach((component) => {
334
- StyleDictionary.registerFilter({
335
- filter: function (token) {
336
- return (
337
- token.filePath.includes("components") &&
338
- token.attributes.category === component
339
- )
340
- },
341
- name: `component:${component}`,
342
- })
343
- })
344
-
345
- // REGISTER CUSTOM ACTIONS
346
- StyleDictionary.registerAction({
347
- do: function () {
348
- const file = "./src/js/tokens-deprecated.json"
349
-
350
- if (!fs.existsSync(file)) {
351
- fs.writeFileSync(file, "{}")
352
- }
353
- },
354
- name: "docs/create-empty-files",
355
- })
356
-
357
- // APPLY THE CONFIGURATION
358
- // IMPORTANT: the registration of custom transforms
359
- // needs to be done _before_ applying the configuration
360
- const sd = new StyleDictionary("./src/style-dictionary.config.js")
361
- await sd.hasInitialized
362
-
363
- // FINALLY, BUILD ALL THE PLATFORMS
364
- await sd.buildAllPlatforms()
365
-
366
- console.log("\n==============================================")
367
- console.log("\nBuild completed!")
@@ -1,67 +0,0 @@
1
- import componentNames from "./componentNames.js"
2
-
3
- export default {
4
- platforms: {
5
- css: {
6
- actions: ["docs/create-empty-files"],
7
- buildPath: "src/",
8
- files: [
9
- {
10
- destination: "css/tokens-alias.css",
11
- filter: "onlyAlias",
12
- format: "css/variables-custom",
13
- },
14
- {
15
- destination: "css/tokens-alias-deprecated.css",
16
- filter: "onlyAliasDeprecated",
17
- format: "css/variables-custom",
18
- },
19
- {
20
- destination: "js/tokens.json",
21
- filter: "docsNoDeprecated",
22
- format: "json/docs-custom",
23
- },
24
- {
25
- destination: "js/tokens-deprecated.json",
26
- filter: "docsOnlyDeprecated",
27
- format: "json/docs-custom",
28
- },
29
- ...componentNames.map((component) => ({
30
- destination: `css/components/${component}.css`,
31
- filter: `component:${component}`,
32
- format: "css/variables-custom",
33
- options: { outputReferences: true },
34
- })),
35
- ],
36
- prefix: "t",
37
- transforms: [
38
- "attribute/cti",
39
- "name/kebab-custom",
40
- "size/px-custom",
41
- "color/hsl-custom",
42
- ],
43
- },
44
- js: {
45
- buildPath: "src/",
46
- files: [
47
- {
48
- destination: "ts/tokens.ts",
49
- filter: "allAlias",
50
- format: "ts/flat-object",
51
- },
52
- ],
53
- prefix: "t",
54
- transforms: [
55
- "attribute/cti",
56
- "name/kebab-complete",
57
- "size/px-custom",
58
- "color/hsl-custom",
59
- ],
60
- },
61
- },
62
- source: [
63
- "src/json/primitives.json",
64
- "src/json/alias.json",
65
- "src/json/components.json",
66
- ],
67
- }