@tamagui/themes 2.0.0-1768586279389 → 2.0.0-1768636514428
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/.turbo/turbo-build.log +1 -1
- package/dist/cjs/generated-v5.cjs +453 -1039
- package/dist/cjs/generated-v5.js +693 -1419
- package/dist/cjs/generated-v5.js.map +1 -1
- package/dist/cjs/generated-v5.native.js +453 -1039
- package/dist/cjs/generated-v5.native.js.map +1 -1
- package/dist/cjs/opacify.cjs +53 -0
- package/dist/cjs/opacify.js +46 -0
- package/dist/cjs/opacify.js.map +2 -2
- package/dist/cjs/opacify.native.js +57 -0
- package/dist/cjs/opacify.native.js.map +1 -1
- package/dist/cjs/v5-themes.cjs +114 -288
- package/dist/cjs/v5-themes.js +88 -290
- package/dist/cjs/v5-themes.js.map +2 -2
- package/dist/cjs/v5-themes.native.js +125 -299
- package/dist/cjs/v5-themes.native.js.map +1 -1
- package/dist/esm/generated-v5.js +693 -1419
- package/dist/esm/generated-v5.js.map +1 -1
- package/dist/esm/generated-v5.mjs +453 -1039
- package/dist/esm/generated-v5.mjs.map +1 -1
- package/dist/esm/generated-v5.native.js +453 -1039
- package/dist/esm/generated-v5.native.js.map +1 -1
- package/dist/esm/opacify.js +46 -0
- package/dist/esm/opacify.js.map +2 -2
- package/dist/esm/opacify.mjs +53 -1
- package/dist/esm/opacify.mjs.map +1 -1
- package/dist/esm/opacify.native.js +57 -1
- package/dist/esm/opacify.native.js.map +1 -1
- package/dist/esm/v5-themes.js +99 -309
- package/dist/esm/v5-themes.js.map +1 -1
- package/dist/esm/v5-themes.mjs +112 -287
- package/dist/esm/v5-themes.mjs.map +1 -1
- package/dist/esm/v5-themes.native.js +123 -298
- package/dist/esm/v5-themes.native.js.map +1 -1
- package/package.json +7 -7
- package/src/generated-v5.ts +858 -2035
- package/src/opacify.ts +89 -0
- package/src/v5-themes.ts +215 -415
- package/tests/v5-themes.test.ts +197 -0
- package/tsconfig.json +1 -0
- package/types/generated-v5.d.ts +83 -138
- package/types/generated-v5.d.ts.map +1 -1
- package/types/opacify.d.ts +7 -0
- package/types/opacify.d.ts.map +1 -1
- package/types/v4-default.d.ts +10 -10
- package/types/v4-default.d.ts.map +1 -1
- package/types/v4-tamagui.d.ts +5 -5
- package/types/v4-tamagui.d.ts.map +1 -1
- package/types/v5-themes.d.ts +190 -590
- package/types/v5-themes.d.ts.map +1 -1
package/src/opacify.ts
CHANGED
|
@@ -1,3 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interpolate between two colors
|
|
3
|
+
* @param color1 - First color (hex or hsl)
|
|
4
|
+
* @param color2 - Second color (hex or hsl)
|
|
5
|
+
* @param amount - 0 = color1, 1 = color2, 0.5 = middle
|
|
6
|
+
*/
|
|
7
|
+
export function interpolateColor(color1: string, color2: string, amount: number): string {
|
|
8
|
+
const rgb1 = parseToRgb(color1)
|
|
9
|
+
const rgb2 = parseToRgb(color2)
|
|
10
|
+
if (!rgb1 || !rgb2) return color1
|
|
11
|
+
|
|
12
|
+
const r = Math.round(rgb1.r + (rgb2.r - rgb1.r) * amount)
|
|
13
|
+
const g = Math.round(rgb1.g + (rgb2.g - rgb1.g) * amount)
|
|
14
|
+
const b = Math.round(rgb1.b + (rgb2.b - rgb1.b) * amount)
|
|
15
|
+
|
|
16
|
+
return `rgb(${r}, ${g}, ${b})`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parseToRgb(color: string): { r: number; g: number; b: number } | null {
|
|
20
|
+
if (typeof color !== 'string') return null
|
|
21
|
+
|
|
22
|
+
// Handle hex
|
|
23
|
+
if (color.startsWith('#')) {
|
|
24
|
+
let hex = color.slice(1)
|
|
25
|
+
if (hex.length === 3) {
|
|
26
|
+
hex = hex
|
|
27
|
+
.split('')
|
|
28
|
+
.map((c) => c + c)
|
|
29
|
+
.join('')
|
|
30
|
+
}
|
|
31
|
+
if (hex.length >= 6) {
|
|
32
|
+
return {
|
|
33
|
+
r: Number.parseInt(hex.slice(0, 2), 16),
|
|
34
|
+
g: Number.parseInt(hex.slice(2, 4), 16),
|
|
35
|
+
b: Number.parseInt(hex.slice(4, 6), 16),
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Handle rgb/rgba
|
|
41
|
+
if (color.startsWith('rgb')) {
|
|
42
|
+
const match = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/)
|
|
43
|
+
if (match) {
|
|
44
|
+
return {
|
|
45
|
+
r: Number.parseInt(match[1], 10),
|
|
46
|
+
g: Number.parseInt(match[2], 10),
|
|
47
|
+
b: Number.parseInt(match[3], 10),
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Handle hsl/hsla
|
|
53
|
+
if (color.startsWith('hsl')) {
|
|
54
|
+
const match = color.match(/hsla?\((\d+),\s*(\d+)%,\s*(\d+)%/)
|
|
55
|
+
if (match) {
|
|
56
|
+
const h = Number.parseInt(match[1], 10)
|
|
57
|
+
const s = Number.parseInt(match[2], 10) / 100
|
|
58
|
+
const l = Number.parseInt(match[3], 10) / 100
|
|
59
|
+
return hslToRgb(h, s, l)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function hslToRgb(h: number, s: number, l: number): { r: number; g: number; b: number } {
|
|
67
|
+
let r: number
|
|
68
|
+
let g: number
|
|
69
|
+
let b: number
|
|
70
|
+
if (s === 0) {
|
|
71
|
+
r = g = b = l
|
|
72
|
+
} else {
|
|
73
|
+
const hue2rgb = (p: number, q: number, t: number) => {
|
|
74
|
+
if (t < 0) t += 1
|
|
75
|
+
if (t > 1) t -= 1
|
|
76
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t
|
|
77
|
+
if (t < 1 / 2) return q
|
|
78
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
|
|
79
|
+
return p
|
|
80
|
+
}
|
|
81
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s
|
|
82
|
+
const p = 2 * l - q
|
|
83
|
+
r = hue2rgb(p, q, h / 360 + 1 / 3)
|
|
84
|
+
g = hue2rgb(p, q, h / 360)
|
|
85
|
+
b = hue2rgb(p, q, h / 360 - 1 / 3)
|
|
86
|
+
}
|
|
87
|
+
return { r: Math.round(r * 255), g: Math.round(g * 255), b: Math.round(b * 255) }
|
|
88
|
+
}
|
|
89
|
+
|
|
1
90
|
export function opacify(color: string, opacity = 0.1): string {
|
|
2
91
|
// Handle dynamic color objects (from $theme-dark/$theme-light)
|
|
3
92
|
if (typeof color !== 'string') return color
|