@tamagui/theme-base 1.0.1-beta.54 → 1.0.1-beta.57

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.
@@ -1,8 +1,8 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { createVariable, getVariableValue } from "@tamagui/core";
3
+ import { createTheme, getVariableValue } from "@tamagui/core";
4
4
  import { setColorAlpha } from "./colorUtils";
5
- import { colorTokens, darkColors, lightColors, tokens } from "./tokens";
5
+ import { darkColors, lightColors, tokens } from "./tokens";
6
6
  const { color } = tokens;
7
7
  const alternates = [1, 2, 3, 4];
8
8
  const alts = [1, 2, 3];
@@ -12,7 +12,7 @@ function createThemesFrom(name, getTheme, props) {
12
12
  let themeEntries = [[name, theme]];
13
13
  const altThemes = alternates.map((alt) => [
14
14
  `${name}_alt${alt}`,
15
- getTheme(alt + (props.isLight ? 1 : 0) + shift, props)
15
+ getTheme(alt + (props.isLight ? 0 : 0) + shift, props)
16
16
  ]);
17
17
  const altThemes2 = alternates.map((alt) => [
18
18
  `${name}_alt${alt}`,
@@ -59,7 +59,7 @@ function createThemesFrom(name, getTheme, props) {
59
59
  return themes2;
60
60
  }
61
61
  __name(createThemesFrom, "createThemesFrom");
62
- const createTheme = /* @__PURE__ */ __name((str = 1, {
62
+ const themeCreator = /* @__PURE__ */ __name((str = 1, {
63
63
  backgrounds,
64
64
  isLight = true,
65
65
  isBase = false,
@@ -90,14 +90,14 @@ const createTheme = /* @__PURE__ */ __name((str = 1, {
90
90
  backgroundHover: get(backgrounds, str + lighterDir),
91
91
  backgroundPress: get(backgrounds, str + darkerDir),
92
92
  backgroundFocus: get(backgrounds, str + darkerDir * 2),
93
- backgroundTransparent: color.grayA1,
93
+ backgroundTransparent: color.grayA1Light,
94
94
  color: get(colors, 0 + str, "color"),
95
95
  colorHover: get(colors, 1 + str, "color"),
96
96
  colorPress: get(colors, 2 + str, "color"),
97
97
  colorFocus: get(colors, 3 + str, "color"),
98
98
  colorTranslucent,
99
99
  colorMid: (isLight ? colors : backgrounds)[Math.floor(colors.length / 2)],
100
- shadowColor: isLight ? color.grayA2 : color.grayA8,
100
+ shadowColor: isLight ? color.grayA2Light : color.grayA8Light,
101
101
  shadowColorHover: darkColors2[!isLight ? 1 : 8],
102
102
  shadowColorPress: darkColors2[!isLight ? 1 : 8],
103
103
  shadowColorFocus: darkColors2[!isLight ? 1 : 8],
@@ -122,35 +122,23 @@ const createTheme = /* @__PURE__ */ __name((str = 1, {
122
122
  });
123
123
  }
124
124
  return theme;
125
- }, "createTheme");
126
- const colorSchemes = [
127
- { name: "blue", colors: colorTokens.light.blue, darkColors: colorTokens.dark.blue },
128
- { name: "gray", colors: colorTokens.light.gray, darkColors: colorTokens.dark.gray },
129
- { name: "green", colors: colorTokens.light.green, darkColors: colorTokens.dark.green },
130
- { name: "orange", colors: colorTokens.light.orange, darkColors: colorTokens.dark.orange },
131
- { name: "pink", colors: colorTokens.light.pink, darkColors: colorTokens.dark.pink },
132
- { name: "purple", colors: colorTokens.light.purple, darkColors: colorTokens.dark.purple },
133
- { name: "red", colors: colorTokens.light.red, darkColors: colorTokens.dark.red },
134
- { name: "violet", colors: colorTokens.light.violet, darkColors: colorTokens.dark.violet },
135
- { name: "yellow", colors: colorTokens.light.yellow, darkColors: colorTokens.dark.yellow },
136
- { name: "teal", colors: colorTokens.light.teal, darkColors: colorTokens.dark.teal }
137
- ];
125
+ }, "themeCreator");
138
126
  const themeColors = {
139
127
  light: [
140
128
  "#fff",
141
129
  "#f4f4f4",
142
- color.gray1,
143
- color.gray2,
144
- color.gray3,
145
- color.gray4,
146
- color.gray5,
147
- color.gray6,
148
- color.gray7,
149
- color.gray8,
150
- color.gray9,
151
- color.gray10,
152
- color.gray11,
153
- color.gray12
130
+ color.gray1Light,
131
+ color.gray2Light,
132
+ color.gray3Light,
133
+ color.gray4Light,
134
+ color.gray5Light,
135
+ color.gray6Light,
136
+ color.gray7Light,
137
+ color.gray8Light,
138
+ color.gray9Light,
139
+ color.gray10Light,
140
+ color.gray11Light,
141
+ color.gray12Light
154
142
  ],
155
143
  dark: [
156
144
  "#111111",
@@ -167,13 +155,13 @@ const themeColors = {
167
155
  "#777777"
168
156
  ]
169
157
  };
170
- const lightThemes = createThemesFrom("light", createTheme, {
158
+ const lightThemes = createThemesFrom("light", themeCreator, {
171
159
  backgrounds: themeColors.light,
172
160
  backgroundStrong: "#fafafa",
173
161
  borderColors: themeColors.light.slice(2),
174
162
  isLight: true
175
163
  });
176
- const darkThemes = createThemesFrom("dark", createTheme, {
164
+ const darkThemes = createThemesFrom("dark", themeCreator, {
177
165
  backgrounds: themeColors.dark,
178
166
  colors: themeColors.light.slice(2),
179
167
  backgroundStrong: "#111",
@@ -184,25 +172,17 @@ const darkThemes = createThemesFrom("dark", createTheme, {
184
172
  color: [0, 4, 5, 5, 5, 5]
185
173
  }
186
174
  });
187
- const colorNames = [
188
- "blue",
189
- "gray",
190
- "green",
191
- "indigo",
192
- "orange",
193
- "pink",
194
- "purple",
195
- "red",
196
- "violet",
197
- "yellow",
198
- "teal"
199
- ];
175
+ const light = createTheme({
176
+ ...lightColors,
177
+ ...lightThemes.light
178
+ });
179
+ const dark = createTheme({
180
+ ...darkColors,
181
+ ...darkThemes.dark
182
+ });
200
183
  const baseThemes = {
201
184
  ...lightThemes,
202
- light: {
203
- ...lightColors,
204
- ...lightThemes.light
205
- },
185
+ light,
206
186
  light_active: makeActiveTheme(lightThemes.light),
207
187
  light_Card: lightThemes.light,
208
188
  light_Button: lightThemes.light,
@@ -212,10 +192,7 @@ const baseThemes = {
212
192
  light_SwitchThumb: lightThemes.light_alt1,
213
193
  light_DrawerFrame: lightThemes.light_alt1,
214
194
  ...darkThemes,
215
- dark: {
216
- ...darkColors,
217
- ...darkThemes.dark
218
- },
195
+ dark,
219
196
  dark_active: makeActiveTheme(darkThemes.dark),
220
197
  dark_Card: darkThemes.dark,
221
198
  dark_DrawerFrame: darkThemes.dark_alt1,
@@ -234,28 +211,48 @@ function makeActiveTheme(theme) {
234
211
  return res;
235
212
  }
236
213
  __name(makeActiveTheme, "makeActiveTheme");
214
+ const darkEntries = Object.entries(dark);
215
+ const lightEntries = Object.entries(light);
216
+ function findColors(prefix, dark2 = false) {
217
+ return Object.fromEntries((dark2 ? darkEntries : lightEntries).filter(([k]) => k.startsWith(prefix)));
218
+ }
219
+ __name(findColors, "findColors");
220
+ const colorSchemes = [
221
+ { name: "blue", colors: findColors("blue"), darkColors: findColors("blue", true) },
222
+ { name: "gray", colors: findColors("gray"), darkColors: findColors("gray", true) },
223
+ { name: "green", colors: findColors("green"), darkColors: findColors("green", true) },
224
+ { name: "orange", colors: findColors("orange"), darkColors: findColors("orange", true) },
225
+ { name: "pink", colors: findColors("pink"), darkColors: findColors("pink", true) },
226
+ { name: "purple", colors: findColors("purple"), darkColors: findColors("purple", true) },
227
+ { name: "red", colors: findColors("red"), darkColors: findColors("red", true) },
228
+ { name: "yellow", colors: findColors("yellow"), darkColors: findColors("yellow", true) },
229
+ { name: "teal", colors: findColors("teal"), darkColors: findColors("teal", true) }
230
+ ];
231
+ const colorNames = [
232
+ "blue",
233
+ "gray",
234
+ "green",
235
+ "orange",
236
+ "pink",
237
+ "purple",
238
+ "red",
239
+ "yellow",
240
+ "teal"
241
+ ];
237
242
  const colorThemeEntries = colorSchemes.flatMap(({ name, colors, darkColors: darkColors2 }) => {
238
243
  const [altLightThemes, altDarkThemes] = [
239
244
  { colors: darkColors2, backgrounds: colors },
240
245
  { colors, backgrounds: darkColors2 }
241
246
  ].map((props, i) => {
242
247
  const isLight = i === 0;
248
+ const colorsBase = Object.values(props.colors).slice(2);
243
249
  const [backgrounds, colors2] = [
244
250
  Object.values(props.backgrounds),
245
- Object.values(props.colors).slice(isLight ? 2 : 2)
251
+ isLight ? colorsBase : [colorsBase[0], "#ccc", ...colorsBase.slice(1)]
246
252
  ];
247
253
  const scheme = isLight ? "light" : "dark";
248
254
  const shift = isLight ? 0 : 1;
249
- if (!isLight) {
250
- const [_, h, sp, lp] = backgrounds[0].val.match(/hsl\(([0-9\.]+), ([0-9\.]+)\%, ([0-9\.]+)\%\)/);
251
- const key = backgrounds[0].key.replace("1", "0");
252
- backgrounds.unshift(createVariable({
253
- key,
254
- name: key,
255
- val: `hsl(${h}, ${sp}%, ${parseFloat(lp) / 2}%)`
256
- }));
257
- }
258
- const themeWithAlts = createThemesFrom(name, createTheme, {
255
+ const themeWithAlts = createThemesFrom(name, themeCreator, {
259
256
  colors: colors2,
260
257
  backgrounds,
261
258
  borderColors: backgrounds,
@@ -263,7 +260,7 @@ const colorThemeEntries = colorSchemes.flatMap(({ name, colors, darkColors: dark
263
260
  shift,
264
261
  isBase: false,
265
262
  offsets: {
266
- background: isLight ? [1, 1, 1, 1, 1, 1] : null,
263
+ background: isLight ? [2, 2, 2, 2, 2, 2] : null,
267
264
  borderColor: isLight ? [2, 2, 2, 3, 2] : null,
268
265
  color: isLight ? [0, 0, -1, -2, -3, -3, -4] : [-1, -1, -1, -1, -1, -1]
269
266
  }
@@ -24,41 +24,47 @@ import {
24
24
  yellow,
25
25
  yellowDark
26
26
  } from "@tamagui/colors";
27
- import { createTokens, createVariables } from "@tamagui/core";
28
- const sizeKeys = [
29
- "true",
30
- "0",
31
- "0.25",
32
- "0.5",
33
- "1",
34
- "1.5",
35
- "2",
36
- "2.5",
37
- "3",
38
- "3.5",
39
- "4",
40
- "4.5",
41
- "5",
42
- "5.5",
43
- "6",
44
- "6.5",
45
- "7",
46
- "7.5",
47
- "8",
48
- "8.5",
49
- "9",
50
- "9.5",
51
- "10",
52
- "11",
53
- "12",
54
- "13",
55
- "14"
56
- ];
57
- const getSizeAt = /* @__PURE__ */ __name((index) => index === 0 ? 0 : Math.round(Math.pow(1.6, index)) + Math.floor(3 * index), "getSizeAt");
58
- const size = Object.fromEntries(sizeKeys.map((key) => {
59
- return [key, getSizeAt(key === "true" ? 4 : +key)];
60
- }));
61
- const spaces = Object.entries(size).map(([k, v]) => [k, Math.round(v * 0.75)]);
27
+ import { createTokens } from "@tamagui/core";
28
+ const size = {
29
+ 0: 0,
30
+ 0.25: 2,
31
+ 0.5: 4,
32
+ 0.75: 8,
33
+ 1: 20,
34
+ 1.5: 24,
35
+ 2: 28,
36
+ 2.5: 32,
37
+ 3: 36,
38
+ 3.5: 40,
39
+ 4: 44,
40
+ true: 44,
41
+ 4.5: 48,
42
+ 5: 52,
43
+ 5.5: 59,
44
+ 6: 64,
45
+ 6.5: 69,
46
+ 7: 74,
47
+ 7.6: 79,
48
+ 8: 84,
49
+ 8.5: 89,
50
+ 9: 94,
51
+ 9.5: 99,
52
+ 10: 104,
53
+ 11: 124,
54
+ 12: 144,
55
+ 13: 164,
56
+ 14: 184,
57
+ 15: 204,
58
+ 16: 224,
59
+ 17: 224,
60
+ 18: 244,
61
+ 19: 264,
62
+ 20: 284
63
+ };
64
+ const spaces = Object.entries(size).map(([k, v]) => [
65
+ k,
66
+ Math.max(0, v <= 16 ? Math.round(v * 0.333) : Math.floor(v * 0.7 - 12))
67
+ ]);
62
68
  const spacesNegative = spaces.map(([k, v]) => [`-${k}`, -v]);
63
69
  const space = {
64
70
  ...Object.fromEntries(spaces),
@@ -72,7 +78,7 @@ const zIndex = {
72
78
  4: 400,
73
79
  5: 500
74
80
  };
75
- const colorTokens = createVariables({
81
+ const colorTokens = {
76
82
  light: {
77
83
  blue,
78
84
  gray,
@@ -99,7 +105,7 @@ const colorTokens = createVariables({
99
105
  yellow: yellowDark,
100
106
  teal: tealDark
101
107
  }
102
- });
108
+ };
103
109
  const darkColors = {
104
110
  ...colorTokens.dark.blue,
105
111
  ...colorTokens.dark.gray,
@@ -127,13 +133,13 @@ const lightColors = {
127
133
  ...colorTokens.light.teal
128
134
  };
129
135
  const allColors = {
130
- ...lightColors,
131
- ...darkPostfix(darkColors)
136
+ ...postfixObjKeys(lightColors, "Light"),
137
+ ...postfixObjKeys(darkColors, "Dark")
132
138
  };
133
- function darkPostfix(obj) {
134
- return Object.fromEntries(Object.entries(obj).map(([k, v]) => [`${k}Dark`, v]));
139
+ function postfixObjKeys(obj, postfix) {
140
+ return Object.fromEntries(Object.entries(obj).map(([k, v]) => [`${k}${postfix}`, v]));
135
141
  }
136
- __name(darkPostfix, "darkPostfix");
142
+ __name(postfixObjKeys, "postfixObjKeys");
137
143
  const radius = {
138
144
  0: 0,
139
145
  1: 3,
@@ -157,7 +163,6 @@ const tokens = createTokens({
157
163
  size
158
164
  });
159
165
  export {
160
- colorTokens,
161
166
  darkColors,
162
167
  lightColors,
163
168
  tokens
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/theme-base",
3
- "version": "1.0.1-beta.54",
3
+ "version": "1.0.1-beta.57",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -16,11 +16,11 @@
16
16
  "clean:build": "tamagui-build clean:build"
17
17
  },
18
18
  "dependencies": {
19
- "@tamagui/colors": "^1.0.1-beta.54",
20
- "@tamagui/core": "^1.0.1-beta.54"
19
+ "@tamagui/colors": "^1.0.1-beta.57",
20
+ "@tamagui/core": "^1.0.1-beta.57"
21
21
  },
22
22
  "devDependencies": {
23
- "@tamagui/build": "^1.0.1-beta.54"
23
+ "@tamagui/build": "^1.0.1-beta.57"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public"