@tamagui/themes 1.88.21 → 1.88.22

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.
@@ -0,0 +1,434 @@
1
+ import { createThemeBuilder } from "@tamagui/theme-builder";
2
+ import { blue, blueDark, gray, grayDark, green, greenDark, orange, orangeDark, pink, pinkDark, purple, purpleDark, red, redDark, yellow, yellowDark } from "@tamagui/colors";
3
+ import { createTokens } from "@tamagui/web";
4
+ import { masks } from "./masks.mjs";
5
+ import { masks as masks2 } from "./masks.mjs";
6
+ const colorTokens = {
7
+ light: {
8
+ blue,
9
+ gray,
10
+ green,
11
+ orange,
12
+ pink,
13
+ purple,
14
+ red,
15
+ yellow
16
+ },
17
+ dark: {
18
+ blue: blueDark,
19
+ gray: grayDark,
20
+ green: greenDark,
21
+ orange: orangeDark,
22
+ pink: pinkDark,
23
+ purple: purpleDark,
24
+ red: redDark,
25
+ yellow: yellowDark
26
+ }
27
+ },
28
+ palettes = (() => {
29
+ const lightTransparent = "rgba(255,255,255,0)",
30
+ darkTransparent = "rgba(10,10,10,0)",
31
+ transparent = (hsl, opacity = 0) => hsl.replace("%)", `%, ${opacity})`).replace("hsl(", "hsla("),
32
+ getColorPalette = (colors, color2 = colors[0]) => {
33
+ const colorPalette = Object.values(colors),
34
+ [head, tail] = [colorPalette.slice(0, 6), colorPalette.slice(colorPalette.length - 5)];
35
+ return [transparent(colorPalette[0]), ...head, ...tail, color2, transparent(colorPalette[colorPalette.length - 1])];
36
+ },
37
+ lightColor = "hsl(0, 0%, 9.0%)",
38
+ lightPalette = [lightTransparent, "#fff", "#f8f8f8", "hsl(0, 0%, 96.3%)", "hsl(0, 0%, 94.1%)", "hsl(0, 0%, 92.0%)", "hsl(0, 0%, 90.0%)", "hsl(0, 0%, 88.5%)", "hsl(0, 0%, 81.0%)", "hsl(0, 0%, 56.1%)", "hsl(0, 0%, 50.3%)", "hsl(0, 0%, 42.5%)", lightColor, darkTransparent],
39
+ darkColor = "#fff",
40
+ darkPalette = [darkTransparent, "#050505", "#151515", "#191919", "#232323", "#282828", "#323232", "#424242", "#494949", "#545454", "#626262", "#a5a5a5", darkColor, lightTransparent],
41
+ lightPalettes = objectFromEntries(objectKeys(colorTokens.light).map(key => [`light_${key}`, getColorPalette(colorTokens.light[key], lightColor)])),
42
+ darkPalettes = objectFromEntries(objectKeys(colorTokens.dark).map(key => [`dark_${key}`, getColorPalette(colorTokens.dark[key], darkColor)])),
43
+ colorPalettes = {
44
+ ...lightPalettes,
45
+ ...darkPalettes
46
+ };
47
+ return {
48
+ light: lightPalette,
49
+ dark: darkPalette,
50
+ ...colorPalettes
51
+ };
52
+ })(),
53
+ templateColorsSpecific = {
54
+ color1: 1,
55
+ color2: 2,
56
+ color3: 3,
57
+ color4: 4,
58
+ color5: 5,
59
+ color6: 6,
60
+ color7: 7,
61
+ color8: 8,
62
+ color9: 9,
63
+ color10: 10,
64
+ color11: 11,
65
+ color12: 12
66
+ },
67
+ templates = (() => {
68
+ const base = {
69
+ ...templateColorsSpecific,
70
+ // the background, color, etc keys here work like generics - they make it so you
71
+ // can publish components for others to use without mandating a specific color scale
72
+ // the @tamagui/button Button component looks for `$background`, so you set the
73
+ // dark_red_Button theme to have a stronger background than the dark_red theme.
74
+ background: 2,
75
+ backgroundHover: 3,
76
+ backgroundPress: 4,
77
+ backgroundFocus: 5,
78
+ backgroundStrong: 1,
79
+ backgroundTransparent: 0,
80
+ color: -1,
81
+ colorHover: -2,
82
+ colorPress: -1,
83
+ colorFocus: -2,
84
+ colorTransparent: -0,
85
+ borderColor: 5,
86
+ borderColorHover: 6,
87
+ borderColorFocus: 4,
88
+ borderColorPress: 5,
89
+ placeholderColor: -4,
90
+ // in the future this should be partially transparent
91
+ outlineColor: 5
92
+ },
93
+ surface12 = {
94
+ background: base.background + 1,
95
+ backgroundHover: base.backgroundHover + 1,
96
+ backgroundPress: base.backgroundPress + 1,
97
+ backgroundFocus: base.backgroundFocus + 1,
98
+ backgroundStrong: base.backgroundStrong + 1,
99
+ borderColor: base.borderColor + 1,
100
+ borderColorHover: base.borderColorHover + 1,
101
+ borderColorFocus: base.borderColorFocus + 1,
102
+ borderColorPress: base.borderColorPress + 1,
103
+ outlineColor: base.outlineColor + 1
104
+ },
105
+ surface22 = {
106
+ background: base.background + 2,
107
+ backgroundHover: base.backgroundHover + 2,
108
+ backgroundPress: base.backgroundPress + 2,
109
+ backgroundFocus: base.backgroundFocus + 2,
110
+ backgroundStrong: base.backgroundStrong + 2,
111
+ borderColor: base.borderColor + 2,
112
+ borderColorHover: base.borderColorHover + 2,
113
+ borderColorFocus: base.borderColorFocus + 2,
114
+ borderColorPress: base.borderColorPress + 2,
115
+ outlineColor: base.outlineColor + 2
116
+ },
117
+ surface32 = {
118
+ background: base.background + 3,
119
+ backgroundHover: base.backgroundHover + 3,
120
+ backgroundPress: base.backgroundPress + 3,
121
+ backgroundFocus: base.backgroundFocus + 3,
122
+ backgroundStrong: base.backgroundStrong + 3,
123
+ borderColor: base.borderColor + 3,
124
+ borderColorHover: base.borderColorHover + 3,
125
+ borderColorFocus: base.borderColorFocus + 3,
126
+ borderColorPress: base.borderColorPress + 3,
127
+ outlineColor: base.outlineColor + 3
128
+ },
129
+ surfaceActive = {
130
+ background: base.background + 5,
131
+ backgroundHover: base.background + 5,
132
+ backgroundPress: base.backgroundPress + 5,
133
+ backgroundFocus: base.backgroundFocus + 5,
134
+ backgroundStrong: base.backgroundStrong + 5,
135
+ borderColor: base.borderColor + 5,
136
+ borderColorHover: base.borderColor + 5,
137
+ borderColorFocus: base.borderColorFocus + 5,
138
+ borderColorPress: base.borderColorPress + 5,
139
+ outlineColor: base.outlineColor + 5
140
+ };
141
+ return {
142
+ base,
143
+ surface1: surface12,
144
+ surface2: surface22,
145
+ surface3: surface32,
146
+ surfaceActive
147
+ };
148
+ })(),
149
+ maskOptions = (() => {
150
+ const shadows2 = {
151
+ shadowColor: 0,
152
+ shadowColorHover: 0,
153
+ shadowColorPress: 0,
154
+ shadowColorFocus: 0
155
+ },
156
+ colors = {
157
+ ...shadows2,
158
+ color: 0,
159
+ colorHover: 0,
160
+ colorFocus: 0,
161
+ colorPress: 0
162
+ },
163
+ baseMaskOptions = {
164
+ override: shadows2,
165
+ skip: shadows2,
166
+ // avoids the transparent ends
167
+ max: palettes.light.length - 2,
168
+ min: 1
169
+ },
170
+ skipShadowsAndSpecificColors = {
171
+ ...shadows2,
172
+ ...templateColorsSpecific
173
+ };
174
+ return {
175
+ component: {
176
+ ...baseMaskOptions,
177
+ override: colors,
178
+ skip: skipShadowsAndSpecificColors
179
+ },
180
+ alt: {
181
+ ...baseMaskOptions
182
+ },
183
+ button: {
184
+ ...baseMaskOptions,
185
+ override: {
186
+ ...colors,
187
+ borderColor: "transparent",
188
+ borderColorHover: "transparent"
189
+ },
190
+ skip: skipShadowsAndSpecificColors
191
+ }
192
+ };
193
+ })(),
194
+ lightShadowColor = "rgba(0,0,0,0.04)",
195
+ lightShadowColorStrong = "rgba(0,0,0,0.085)",
196
+ darkShadowColor = "rgba(0,0,0,0.2)",
197
+ darkShadowColorStrong = "rgba(0,0,0,0.3)",
198
+ size = {
199
+ $0: 0,
200
+ "$0.25": 2,
201
+ "$0.5": 4,
202
+ "$0.75": 8,
203
+ $1: 20,
204
+ "$1.5": 24,
205
+ $2: 28,
206
+ "$2.5": 32,
207
+ $3: 36,
208
+ "$3.5": 40,
209
+ $4: 44,
210
+ $true: 44,
211
+ "$4.5": 48,
212
+ $5: 52,
213
+ $6: 64,
214
+ $7: 74,
215
+ $8: 84,
216
+ $9: 94,
217
+ $10: 104,
218
+ $11: 124,
219
+ $12: 144,
220
+ $13: 164,
221
+ $14: 184,
222
+ $15: 204,
223
+ $16: 224,
224
+ $17: 224,
225
+ $18: 244,
226
+ $19: 264,
227
+ $20: 284
228
+ },
229
+ spaces = Object.entries(size).map(([k, v]) => [k, sizeToSpace(v)]),
230
+ spacesNegative = spaces.slice(1).map(([k, v]) => [`-${k.slice(1)}`, -v]),
231
+ space = {
232
+ ...Object.fromEntries(spaces),
233
+ ...Object.fromEntries(spacesNegative)
234
+ },
235
+ zIndex = {
236
+ 0: 0,
237
+ 1: 100,
238
+ 2: 200,
239
+ 3: 300,
240
+ 4: 400,
241
+ 5: 500
242
+ },
243
+ darkColors = {
244
+ ...colorTokens.dark.blue,
245
+ ...colorTokens.dark.gray,
246
+ ...colorTokens.dark.green,
247
+ ...colorTokens.dark.orange,
248
+ ...colorTokens.dark.pink,
249
+ ...colorTokens.dark.purple,
250
+ ...colorTokens.dark.red,
251
+ ...colorTokens.dark.yellow
252
+ },
253
+ lightColors = {
254
+ ...colorTokens.light.blue,
255
+ ...colorTokens.light.gray,
256
+ ...colorTokens.light.green,
257
+ ...colorTokens.light.orange,
258
+ ...colorTokens.light.pink,
259
+ ...colorTokens.light.purple,
260
+ ...colorTokens.light.red,
261
+ ...colorTokens.light.yellow
262
+ },
263
+ color = {
264
+ ...postfixObjKeys(lightColors, "Light"),
265
+ ...postfixObjKeys(darkColors, "Dark")
266
+ },
267
+ radius = {
268
+ 0: 0,
269
+ 1: 3,
270
+ 2: 5,
271
+ 3: 7,
272
+ 4: 9,
273
+ true: 9,
274
+ 5: 10,
275
+ 6: 16,
276
+ 7: 19,
277
+ 8: 22,
278
+ 9: 26,
279
+ 10: 34,
280
+ 11: 42,
281
+ 12: 50
282
+ },
283
+ tokens = createTokens({
284
+ color,
285
+ radius,
286
+ zIndex,
287
+ space,
288
+ size
289
+ }),
290
+ shadows = {
291
+ light: {
292
+ shadowColor: lightShadowColorStrong,
293
+ shadowColorHover: lightShadowColorStrong,
294
+ shadowColorPress: lightShadowColor,
295
+ shadowColorFocus: lightShadowColor
296
+ },
297
+ dark: {
298
+ shadowColor: darkShadowColorStrong,
299
+ shadowColorHover: darkShadowColorStrong,
300
+ shadowColorPress: darkShadowColor,
301
+ shadowColorFocus: darkShadowColor
302
+ }
303
+ },
304
+ colorThemeDefinition = colorName => ({
305
+ palette: colorName,
306
+ template: "base"
307
+ }),
308
+ nonInherited = {
309
+ light: {
310
+ ...lightColors,
311
+ ...shadows.light
312
+ },
313
+ dark: {
314
+ ...darkColors,
315
+ ...shadows.dark
316
+ }
317
+ },
318
+ overlayThemeDefinitions = [{
319
+ parent: "light",
320
+ theme: {
321
+ background: "rgba(0,0,0,0.5)"
322
+ }
323
+ }, {
324
+ parent: "dark",
325
+ theme: {
326
+ background: "rgba(0,0,0,0.9)"
327
+ }
328
+ }],
329
+ inversed = {
330
+ mask: "inverse",
331
+ ...maskOptions.component
332
+ },
333
+ surface1 = [{
334
+ parent: "active",
335
+ template: "surfaceActive"
336
+ }, {
337
+ parent: "",
338
+ template: "surface1"
339
+ }],
340
+ surface2 = [{
341
+ parent: "active",
342
+ template: "surfaceActive"
343
+ }, {
344
+ parent: "",
345
+ template: "surface2"
346
+ }],
347
+ surface3 = [{
348
+ parent: "active",
349
+ template: "surfaceActive"
350
+ }, {
351
+ parent: "",
352
+ template: "surface3"
353
+ }],
354
+ themeBuilder = createThemeBuilder().addPalettes(palettes).addTemplates(templates).addMasks(masks).addThemes({
355
+ light: {
356
+ template: "base",
357
+ palette: "light",
358
+ nonInheritedValues: nonInherited.light
359
+ },
360
+ dark: {
361
+ template: "base",
362
+ palette: "dark",
363
+ nonInheritedValues: nonInherited.dark
364
+ }
365
+ }).addChildThemes({
366
+ orange: colorThemeDefinition("orange"),
367
+ yellow: colorThemeDefinition("yellow"),
368
+ green: colorThemeDefinition("green"),
369
+ blue: colorThemeDefinition("blue"),
370
+ purple: colorThemeDefinition("purple"),
371
+ pink: colorThemeDefinition("pink"),
372
+ red: colorThemeDefinition("red"),
373
+ gray: colorThemeDefinition("gray")
374
+ }).addChildThemes({
375
+ alt1: {
376
+ template: "surface1"
377
+ },
378
+ alt2: surface2,
379
+ active: {
380
+ template: "surface3"
381
+ }
382
+ }).addChildThemes({
383
+ ListItem: {
384
+ template: "surface1"
385
+ },
386
+ Card: surface1,
387
+ Button: surface3,
388
+ Checkbox: surface2,
389
+ Switch: surface2,
390
+ SwitchThumb: inversed,
391
+ TooltipContent: surface2,
392
+ DrawerFrame: {
393
+ template: "surface1"
394
+ },
395
+ Progress: {
396
+ template: "surface1"
397
+ },
398
+ RadioGroupItem: surface2,
399
+ TooltipArrow: {
400
+ template: "surface1"
401
+ },
402
+ SliderTrackActive: {
403
+ template: "surface3"
404
+ },
405
+ SliderTrack: {
406
+ template: "surface1"
407
+ },
408
+ SliderThumb: inversed,
409
+ Tooltip: inversed,
410
+ ProgressIndicator: {
411
+ mask: "inverse",
412
+ ...maskOptions.component
413
+ },
414
+ SheetOverlay: overlayThemeDefinitions,
415
+ DialogOverlay: overlayThemeDefinitions,
416
+ ModalOverlay: overlayThemeDefinitions,
417
+ Input: surface1,
418
+ TextArea: surface1
419
+ }),
420
+ themesIn = themeBuilder.build(),
421
+ themes = themesIn;
422
+ function postfixObjKeys(obj, postfix) {
423
+ return Object.fromEntries(Object.entries(obj).map(([k, v]) => [`${k}${postfix}`, v]));
424
+ }
425
+ function sizeToSpace(v) {
426
+ return v === 0 ? 0 : v === 2 ? 0.5 : v === 4 ? 1 : v === 8 ? 1.5 : v <= 16 ? Math.round(v * 0.333) : Math.floor(v * 0.7 - 12);
427
+ }
428
+ function objectFromEntries(arr) {
429
+ return Object.fromEntries(arr);
430
+ }
431
+ function objectKeys(obj) {
432
+ return Object.keys(obj);
433
+ }
434
+ export { maskOptions, masks2 as masks, palettes, templates, themes, tokens };