@tamagui/theme-builder 1.79.6 → 1.79.7

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.
@@ -117,40 +117,40 @@ export function buildThemeSuite({ baseTheme, subThemes }: BuildThemeSuiteProps)
117
117
  ...baseTemplate,
118
118
  }
119
119
 
120
- const accentTemplateLight = {
121
- background: 0,
122
- backgroundHover: baseTemplate.backgroundHover + 4,
123
- backgroundPress: baseTemplate.backgroundPress + 4,
124
- backgroundFocus: baseTemplate.backgroundFocus + 4,
125
- borderColor: baseTemplate.borderColor + 2,
126
- borderColorHover: baseTemplate.borderColorHover + 2,
127
- borderColorFocus: baseTemplate.borderColorFocus + 2,
128
- borderColorPress: baseTemplate.borderColorPress + 2,
129
- color: -5,
130
- colorHover: -6,
131
- colorPress: -7,
132
- colorFocus: -5,
133
- }
134
-
135
- const accentTemplateDark = {
136
- background: baseTemplate.backgroundHover + 4,
137
- backgroundHover: baseTemplate.backgroundHover + 5,
138
- backgroundPress: baseTemplate.backgroundPress + 3,
139
- backgroundFocus: baseTemplate.backgroundFocus + 5,
140
- borderColor: baseTemplate.borderColor + 2,
141
- borderColorHover: baseTemplate.borderColorHover + 2,
142
- borderColorFocus: baseTemplate.borderColorFocus + 2,
143
- borderColorPress: baseTemplate.borderColorPress + 2,
144
- color: -5,
145
- colorHover: -6,
146
- colorPress: -7,
147
- colorFocus: -5,
148
- }
120
+ // const accentTemplateLight = {
121
+ // background: 0,
122
+ // backgroundHover: 1,
123
+ // backgroundPress: baseTemplate.backgroundPress + 4,
124
+ // backgroundFocus: baseTemplate.backgroundFocus + 4,
125
+ // borderColor: baseTemplate.borderColor + 2,
126
+ // borderColorHover: baseTemplate.borderColorHover + 2,
127
+ // borderColorFocus: baseTemplate.borderColorFocus + 2,
128
+ // borderColorPress: baseTemplate.borderColorPress + 2,
129
+ // color: -5,
130
+ // colorHover: -6,
131
+ // colorPress: -7,
132
+ // colorFocus: -5,
133
+ // }
134
+
135
+ // const accentTemplateDark = {
136
+ // background: baseTemplate.background + 4,
137
+ // backgroundHover: baseTemplate.backgroundHover + 5,
138
+ // backgroundPress: baseTemplate.backgroundPress + 3,
139
+ // backgroundFocus: baseTemplate.backgroundFocus + 5,
140
+ // borderColor: baseTemplate.borderColor + 2,
141
+ // borderColorHover: baseTemplate.borderColorHover + 2,
142
+ // borderColorFocus: baseTemplate.borderColorFocus + 2,
143
+ // borderColorPress: baseTemplate.borderColorPress + 2,
144
+ // color: -5,
145
+ // colorHover: -6,
146
+ // colorPress: -7,
147
+ // colorFocus: -5,
148
+ // }
149
149
 
150
150
  return {
151
151
  base: template,
152
- accentLight: accentTemplateLight,
153
- accentDark: accentTemplateDark,
152
+ accentLight: template,
153
+ accentDark: template,
154
154
  }
155
155
  }
156
156
 
@@ -216,10 +216,7 @@ export function buildThemeSuite({ baseTheme, subThemes }: BuildThemeSuiteProps)
216
216
  ...customMaskOptions.component,
217
217
  },
218
218
 
219
- Switch: {
220
- mask: 'soften2',
221
- ...customMaskOptions.component,
222
- },
219
+ Switch: componentTheme,
223
220
 
224
221
  SwitchThumb: {
225
222
  mask: 'inverse',
@@ -367,6 +364,8 @@ export function buildThemeSuite({ baseTheme, subThemes }: BuildThemeSuiteProps)
367
364
 
368
365
  const built = builder.build()
369
366
 
367
+ console.info('built themes', built)
368
+
370
369
  return {
371
370
  built,
372
371
  palettes,
@@ -1,19 +1,54 @@
1
- import { parseToHsla } from 'color2k'
1
+ import { hsla, parseToHsla, toHex } from 'color2k'
2
2
 
3
3
  import { BuildTheme, ScaleTypeName } from './types'
4
4
 
5
+ export function getColorForegroundBackground(color: string, isDarkMode = false) {
6
+ const [h, s, l] = parseToHsla(color)
7
+ const isColorLight = l > 0.5
8
+ const oppositeLightness = l > 0.5 ? 1 - l : 0.5 + l
9
+ const oppositeLightnessColor = toHex(hsla(h, s, oppositeLightness, 1))
10
+ const foreground = isDarkMode ? color : oppositeLightnessColor
11
+ const background = foreground === color ? oppositeLightnessColor : color
12
+ return {
13
+ foreground,
14
+ foregroundLightness: foreground === color ? l : oppositeLightness,
15
+ background,
16
+ backgroundLightness: foreground !== color ? l : oppositeLightness,
17
+ }
18
+ }
19
+
5
20
  export const getThemeSuiteScale = (theme: BuildTheme, accent?: boolean): ScaleType => {
6
- const color = accent ? theme.accent || theme.color : theme.color
21
+ const baseColor = accent ? theme.accent || theme.color : theme.color
7
22
  const scale = accent ? theme.accentScale || theme.scale : theme.scale
8
23
 
9
- let base = scaleTypes[theme.scale || '']
24
+ let base = scaleTypes[scale]
10
25
 
11
- if (!color) {
26
+ if (!baseColor) {
12
27
  return base
13
28
  }
14
29
 
15
- const [h, s, l] = parseToHsla(color)
16
- // const isColorBright = l > 0.5
30
+ const [h, s, l] = parseToHsla(baseColor)
31
+
32
+ if (scale === 'automatic') {
33
+ const lightColors = getColorForegroundBackground(baseColor, false)
34
+ const darkColors = getColorForegroundBackground(baseColor, true)
35
+
36
+ const scaleLen = 12
37
+ const arr = new Array(scaleLen).fill(0)
38
+
39
+ function getScale(bgL: number, fgL: number) {
40
+ const stepSize = (fgL - bgL) / scaleLen
41
+ return arr.map((_, i) => bgL + i * stepSize)
42
+ }
43
+
44
+ return {
45
+ ...base,
46
+ lumScale: {
47
+ light: getScale(lightColors.backgroundLightness, lightColors.foregroundLightness),
48
+ dark: getScale(darkColors.backgroundLightness, darkColors.foregroundLightness),
49
+ },
50
+ }
51
+ }
17
52
 
18
53
  return {
19
54
  ...base,
@@ -44,6 +79,14 @@ export type ScaleType<A extends ScaleTypeName = ScaleTypeName> = {
44
79
  }
45
80
 
46
81
  export const scaleTypes: Record<ScaleTypeName, ScaleType> = {
82
+ automatic: {
83
+ createdFrom: 'automatic',
84
+ name: 'Automatic',
85
+ lumScale: {
86
+ light: [],
87
+ dark: [],
88
+ },
89
+ },
47
90
  radix: {
48
91
  name: 'Radius',
49
92
  createdFrom: 'radix',
package/src/types.ts CHANGED
@@ -21,6 +21,7 @@ export type BuildThemeSuitePalettes = {
21
21
  }
22
22
 
23
23
  export type ScaleTypeName =
24
+ | 'automatic'
24
25
  | 'radix'
25
26
  | 'radix-b'
26
27
  | 'radius-bold'
@@ -1 +1 @@
1
- {"version":3,"file":"buildThemeSuite.d.ts","sourceRoot":"","sources":["../src/buildThemeSuite.ts"],"names":[],"mappings":"AAWA,OAAO,EAAkB,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAE9D,wBAAgB,eAAe,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwW7E;AAED,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA"}
1
+ {"version":3,"file":"buildThemeSuite.d.ts","sourceRoot":"","sources":["../src/buildThemeSuite.ts"],"names":[],"mappings":"AAWA,OAAO,EAAkB,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAE9D,wBAAgB,eAAe,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuW7E;AAED,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA"}
@@ -1,4 +1,10 @@
1
1
  import { BuildTheme, ScaleTypeName } from './types';
2
+ export declare function getColorForegroundBackground(color: string, isDarkMode?: boolean): {
3
+ foreground: string;
4
+ foregroundLightness: number;
5
+ background: string;
6
+ backgroundLightness: number;
7
+ };
2
8
  export declare const getThemeSuiteScale: (theme: BuildTheme, accent?: boolean) => ScaleType;
3
9
  export type ScaleType<A extends ScaleTypeName = ScaleTypeName> = {
4
10
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"buildThemeSuiteScales.d.ts","sourceRoot":"","sources":["../src/buildThemeSuiteScales.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEnD,eAAO,MAAM,kBAAkB,UAAW,UAAU,WAAW,OAAO,KAAG,SA0BxE,CAAA;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,IAAI;IAC/D,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,CAAC,CAAA;IACf,QAAQ,EAAE;QACR,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACpB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KACpB,CAAA;IACD,QAAQ,CAAC,EAAE;QACT,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACpB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KACpB,CAAA;CACF,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,SAAS,CA0HvD,CAAA"}
1
+ {"version":3,"file":"buildThemeSuiteScales.d.ts","sourceRoot":"","sources":["../src/buildThemeSuiteScales.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEnD,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,UAAQ;;;;;EAa7E;AAED,eAAO,MAAM,kBAAkB,UAAW,UAAU,WAAW,OAAO,KAAG,SA8CxE,CAAA;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,IAAI;IAC/D,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,CAAC,CAAA;IACf,QAAQ,EAAE;QACR,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACpB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KACpB,CAAA;IACD,QAAQ,CAAC,EAAE;QACT,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACpB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KACpB,CAAA;CACF,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,SAAS,CAkIvD,CAAA"}
package/types/types.d.ts CHANGED
@@ -15,7 +15,7 @@ export type BuildThemeSuitePalettes = {
15
15
  lightAccent?: string[];
16
16
  darkAccent?: string[];
17
17
  };
18
- export type ScaleTypeName = 'radix' | 'radix-b' | 'radius-bold' | 'radius-bright' | 'linear' | 'pastel' | 'pastel-desaturating' | 'neon' | 'neon-bright' | 'neon-c';
18
+ export type ScaleTypeName = 'automatic' | 'radix' | 'radix-b' | 'radius-bold' | 'radius-bright' | 'linear' | 'pastel' | 'pastel-desaturating' | 'neon' | 'neon-bright' | 'neon-c';
19
19
  export type BuildThemeBase = {
20
20
  id: string;
21
21
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uB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