@tamagui/theme-builder 1.79.10 → 1.79.11
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/dist/cjs/buildThemeSuite.js +10 -10
- package/dist/cjs/buildThemeSuite.js.map +1 -1
- package/dist/cjs/buildThemeSuite.native.js +10 -10
- package/dist/cjs/buildThemeSuite.native.js.map +1 -1
- package/dist/cjs/buildThemeSuitePalettes.js +28 -44
- package/dist/cjs/buildThemeSuitePalettes.js.map +1 -1
- package/dist/cjs/buildThemeSuitePalettes.native.js +28 -44
- package/dist/cjs/buildThemeSuitePalettes.native.js.map +1 -1
- package/dist/cjs/masks.js +143 -0
- package/dist/cjs/masks.js.map +6 -0
- package/dist/cjs/masks.native.js +144 -0
- package/dist/cjs/masks.native.js.map +6 -0
- package/dist/esm/buildThemeSuite.js +1 -1
- package/dist/esm/buildThemeSuite.js.map +1 -1
- package/dist/esm/buildThemeSuite.native.js +1 -1
- package/dist/esm/buildThemeSuite.native.js.map +1 -1
- package/dist/esm/buildThemeSuitePalettes.js +28 -44
- package/dist/esm/buildThemeSuitePalettes.js.map +1 -1
- package/dist/esm/buildThemeSuitePalettes.native.js +28 -44
- package/dist/esm/buildThemeSuitePalettes.native.js.map +1 -1
- package/dist/esm/masks.js +130 -0
- package/dist/esm/masks.js.map +6 -0
- package/dist/esm/masks.native.js +130 -0
- package/dist/esm/masks.native.js.map +6 -0
- package/package.json +3 -3
- package/src/buildThemeSuite.ts +1 -1
- package/src/buildThemeSuitePalettes.ts +106 -73
- package/src/masks.ts +147 -0
- package/src/types.ts +20 -25
- package/types/buildThemeSuitePalettes.d.ts.map +1 -1
- package/types/masks.d.ts +110 -0
- package/types/masks.d.ts.map +1 -0
- package/types/types.d.ts +17 -19
- package/types/types.d.ts.map +1 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
combineMasks,
|
|
3
|
+
createIdentityMask,
|
|
4
|
+
createInverseMask,
|
|
5
|
+
createMask,
|
|
6
|
+
createSoftenMask,
|
|
7
|
+
createStrengthenMask,
|
|
8
|
+
skipMask
|
|
9
|
+
} from "@tamagui/create-theme";
|
|
10
|
+
const shadows = {
|
|
11
|
+
shadowColor: 0,
|
|
12
|
+
shadowColorHover: 0,
|
|
13
|
+
shadowColorPress: 0,
|
|
14
|
+
shadowColorFocus: 0
|
|
15
|
+
}, colors = {
|
|
16
|
+
...shadows,
|
|
17
|
+
color: 0,
|
|
18
|
+
colorHover: 0,
|
|
19
|
+
colorFocus: 0,
|
|
20
|
+
colorPress: 0
|
|
21
|
+
}, templateColorsSpecific = {
|
|
22
|
+
color1: 1,
|
|
23
|
+
color2: 2,
|
|
24
|
+
color3: 3,
|
|
25
|
+
color4: 4,
|
|
26
|
+
color5: 5,
|
|
27
|
+
color6: 6,
|
|
28
|
+
color7: 7,
|
|
29
|
+
color8: 8,
|
|
30
|
+
color9: 9,
|
|
31
|
+
color10: 10,
|
|
32
|
+
color11: 11,
|
|
33
|
+
color12: 12
|
|
34
|
+
}, skipShadowsAndSpecificColors = {
|
|
35
|
+
...shadows,
|
|
36
|
+
...templateColorsSpecific
|
|
37
|
+
}, PALETTE_LEN = 14, baseMaskOptions = {
|
|
38
|
+
override: shadows,
|
|
39
|
+
skip: shadows,
|
|
40
|
+
// avoids the transparent ends
|
|
41
|
+
max: PALETTE_LEN - 2,
|
|
42
|
+
min: 1
|
|
43
|
+
}, maskOptions = {
|
|
44
|
+
component: {
|
|
45
|
+
...baseMaskOptions,
|
|
46
|
+
override: colors,
|
|
47
|
+
skip: skipShadowsAndSpecificColors
|
|
48
|
+
},
|
|
49
|
+
alt: {
|
|
50
|
+
...baseMaskOptions
|
|
51
|
+
},
|
|
52
|
+
button: {
|
|
53
|
+
...baseMaskOptions,
|
|
54
|
+
override: {
|
|
55
|
+
...colors,
|
|
56
|
+
borderColor: "transparent",
|
|
57
|
+
borderColorHover: "transparent"
|
|
58
|
+
},
|
|
59
|
+
skip: skipShadowsAndSpecificColors
|
|
60
|
+
}
|
|
61
|
+
}, masks = {
|
|
62
|
+
identity: createIdentityMask(),
|
|
63
|
+
soften: createSoftenMask(),
|
|
64
|
+
soften2: createSoftenMask({ strength: 2 }),
|
|
65
|
+
soften3: createSoftenMask({ strength: 3 }),
|
|
66
|
+
strengthen: createStrengthenMask(),
|
|
67
|
+
inverse: createInverseMask(),
|
|
68
|
+
inverseSoften: combineMasks(createInverseMask(), createSoftenMask({ strength: 2 })),
|
|
69
|
+
inverseSoften2: combineMasks(createInverseMask(), createSoftenMask({ strength: 3 })),
|
|
70
|
+
inverseSoften3: combineMasks(createInverseMask(), createSoftenMask({ strength: 4 })),
|
|
71
|
+
inverseStrengthen2: combineMasks(
|
|
72
|
+
createInverseMask(),
|
|
73
|
+
createStrengthenMask({ strength: 2 })
|
|
74
|
+
),
|
|
75
|
+
strengthenButSoftenBorder: createMask((template, options) => {
|
|
76
|
+
const stronger = createStrengthenMask().mask(template, options), softer = createSoftenMask().mask(template, options);
|
|
77
|
+
return {
|
|
78
|
+
...stronger,
|
|
79
|
+
borderColor: softer.borderColor,
|
|
80
|
+
borderColorHover: softer.borderColorHover,
|
|
81
|
+
borderColorPress: softer.borderColorPress,
|
|
82
|
+
borderColorFocus: softer.borderColorFocus
|
|
83
|
+
};
|
|
84
|
+
}),
|
|
85
|
+
soften2Border1: createMask((template, options) => {
|
|
86
|
+
const softer2 = createSoftenMask({ strength: 2 }).mask(template, options), softer1 = createSoftenMask({ strength: 1 }).mask(template, options);
|
|
87
|
+
return {
|
|
88
|
+
...softer2,
|
|
89
|
+
borderColor: softer1.borderColor,
|
|
90
|
+
borderColorHover: softer1.borderColorHover,
|
|
91
|
+
borderColorPress: softer1.borderColorPress,
|
|
92
|
+
borderColorFocus: softer1.borderColorFocus
|
|
93
|
+
};
|
|
94
|
+
}),
|
|
95
|
+
soften3FlatBorder: createMask((template, options) => {
|
|
96
|
+
const borderMask = createSoftenMask({ strength: 2 }).mask(template, options);
|
|
97
|
+
return {
|
|
98
|
+
...createSoftenMask({ strength: 3 }).mask(template, options),
|
|
99
|
+
borderColor: borderMask.borderColor,
|
|
100
|
+
borderColorHover: borderMask.borderColorHover,
|
|
101
|
+
borderColorPress: borderMask.borderColorPress,
|
|
102
|
+
borderColorFocus: borderMask.borderColorFocus
|
|
103
|
+
};
|
|
104
|
+
}),
|
|
105
|
+
softenBorder: createMask((template, options) => {
|
|
106
|
+
const plain = skipMask.mask(template, options), softer = createSoftenMask().mask(template, options);
|
|
107
|
+
return {
|
|
108
|
+
...plain,
|
|
109
|
+
borderColor: softer.borderColor,
|
|
110
|
+
borderColorHover: softer.borderColorHover,
|
|
111
|
+
borderColorPress: softer.borderColorPress,
|
|
112
|
+
borderColorFocus: softer.borderColorFocus
|
|
113
|
+
};
|
|
114
|
+
}),
|
|
115
|
+
softenBorder2: createMask((template, options) => {
|
|
116
|
+
const plain = skipMask.mask(template, options), softer = createSoftenMask({ strength: 2 }).mask(template, options);
|
|
117
|
+
return {
|
|
118
|
+
...plain,
|
|
119
|
+
borderColor: softer.borderColor,
|
|
120
|
+
borderColorHover: softer.borderColorHover,
|
|
121
|
+
borderColorPress: softer.borderColorPress,
|
|
122
|
+
borderColorFocus: softer.borderColorFocus
|
|
123
|
+
};
|
|
124
|
+
})
|
|
125
|
+
};
|
|
126
|
+
export {
|
|
127
|
+
maskOptions,
|
|
128
|
+
masks
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=masks.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/masks.ts"],
|
|
4
|
+
"mappings": "AAAA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,UAAU;AAAA,EACd,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,kBAAkB;AACpB,GAEM,SAAS;AAA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D,WAAO;AAAA,MACL,GAAG;AAAA,MACH,aAAa,OAAO;AAAA,MACpB,kBAAkB,OAAO;AAAA,MACzB,kBAAkB,OAAO;AAAA,MACzB,kBAAkB,OAAO;AAAA,IAC3B;AAAA,EACF,CAAC;AAAA,EACD,eAAe,WAAW,CAAC,UAAU,YAAY;AAC/C,UAAM,QAAQ,SAAS,KAAK,UAAU,OAAO,GACvC,SAAS,iBAAiB,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,UAAU,OAAO;AACvE,WAAO;AAAA,MACL,GAAG;AAAA,MACH,aAAa,OAAO;AAAA,MACpB,kBAAkB,OAAO;AAAA,MACzB,kBAAkB,OAAO;AAAA,MACzB,kBAAkB,OAAO;AAAA,IAC3B;AAAA,EACF,CAAC;AACH;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/theme-builder",
|
|
3
|
-
"version": "1.79.
|
|
3
|
+
"version": "1.79.11",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tamagui/create-theme": "1.79.
|
|
30
|
+
"@tamagui/create-theme": "1.79.11",
|
|
31
31
|
"color2k": "^2.0.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tamagui/build": "1.79.
|
|
34
|
+
"@tamagui/build": "1.79.11"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
package/src/buildThemeSuite.ts
CHANGED
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
createMask,
|
|
5
5
|
createSoftenMask,
|
|
6
6
|
} from '@tamagui/create-theme'
|
|
7
|
-
import { masks as defaultMasks, maskOptions } from '@tamagui/themes'
|
|
8
7
|
|
|
9
8
|
import { buildMask } from './buildMask'
|
|
10
9
|
import { getThemeSuitePalettes } from './buildThemeSuitePalettes'
|
|
10
|
+
import { masks as defaultMasks, maskOptions } from './masks'
|
|
11
11
|
import { createThemeBuilder } from './ThemeBuilder'
|
|
12
12
|
import { BuildThemeMask, BuildThemeSuiteProps } from './types'
|
|
13
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hsla, parseToHsla, toHex } from 'color2k'
|
|
2
2
|
|
|
3
|
-
import { BuildTheme, BuildThemeSuitePalettes } from './types'
|
|
3
|
+
import { BuildTheme, BuildThemeAnchor, BuildThemeSuitePalettes } from './types'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* palette generally is:
|
|
@@ -8,6 +8,8 @@ import { BuildTheme, BuildThemeSuitePalettes } from './types'
|
|
|
8
8
|
* [constrastBackground, backgroundTransparent, ...background, ...foreground, foregroundTransparent, accentForeground]
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
const paletteSize = 12
|
|
12
|
+
|
|
11
13
|
const generateColorPalette = ({
|
|
12
14
|
theme,
|
|
13
15
|
scheme,
|
|
@@ -18,67 +20,104 @@ const generateColorPalette = ({
|
|
|
18
20
|
forAccent?: boolean
|
|
19
21
|
}) => {
|
|
20
22
|
const baseTheme = forAccent ? theme.accent || theme : theme
|
|
23
|
+
const { anchors, scale } = baseTheme
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
const isDark = scheme === 'dark'
|
|
25
|
+
let palette: string[] = []
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
const add = (h: number, s: number, l: number) => {
|
|
28
|
+
palette.push(hsla(h, s, l, 1))
|
|
29
|
+
}
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
const hslas = {
|
|
29
|
-
background: parseToHsla(strategy.background),
|
|
30
|
-
foreground: parseToHsla(strategy.foreground),
|
|
31
|
-
}
|
|
31
|
+
const numAnchors = Object.keys(anchors).length
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return hsla(
|
|
44
|
-
h,
|
|
45
|
-
s,
|
|
46
|
-
// go to dark or light
|
|
47
|
-
l - by * str,
|
|
48
|
-
1
|
|
49
|
-
)
|
|
50
|
-
} else {
|
|
51
|
-
const str = 9 - i
|
|
52
|
-
const maxLum = 0.95
|
|
53
|
-
const by = (maxLum - l) / 10
|
|
54
|
-
return hsla(h, s, l + by * str, 1)
|
|
55
|
-
}
|
|
56
|
-
}),
|
|
57
|
-
// colors
|
|
58
|
-
...new Array(2).fill(0).map((_, i) => {
|
|
59
|
-
const [h, s, l] = hslas.foreground
|
|
60
|
-
return hsla(
|
|
61
|
-
h,
|
|
62
|
-
s,
|
|
63
|
-
// go to dark or light
|
|
64
|
-
l - (i === 0 ? 0.1 : 0),
|
|
65
|
-
1
|
|
66
|
-
)
|
|
67
|
-
}),
|
|
68
|
-
]
|
|
69
|
-
} else {
|
|
70
|
-
const lumValues = isDark ? lumScale.dark : lumScale.light
|
|
71
|
-
palette = lumValues.map((lum, idx) => {
|
|
72
|
-
const sat = satScale[scheme][idx]
|
|
33
|
+
for (const [anchorIndex, anchor] of anchors.entries()) {
|
|
34
|
+
const [h, s, l] = [anchor.hue[scheme], anchor.sat[scheme], anchor.lum[scheme]]
|
|
35
|
+
|
|
36
|
+
if (anchorIndex !== 0) {
|
|
37
|
+
const lastAnchor = anchors[anchorIndex - 1]
|
|
38
|
+
const steps = anchor.index - lastAnchor.index
|
|
39
|
+
|
|
40
|
+
const lastHue = lastAnchor.hue[scheme]
|
|
41
|
+
const lastSat = lastAnchor.sat[scheme]
|
|
42
|
+
const lastLum = lastAnchor.lum[scheme]
|
|
73
43
|
|
|
74
|
-
|
|
75
|
-
|
|
44
|
+
const stepHue = (lastHue - h) / steps
|
|
45
|
+
const stepSat = (lastSat - s) / steps
|
|
46
|
+
const stepLum = (lastLum - l) / steps
|
|
47
|
+
|
|
48
|
+
// backfill:
|
|
49
|
+
for (let step = lastAnchor.index + 1; step < anchor.index; step++) {
|
|
50
|
+
const str = anchor.index - step
|
|
51
|
+
add(h + stepHue * str, s + stepSat * str, l + stepLum * str)
|
|
76
52
|
}
|
|
53
|
+
}
|
|
77
54
|
|
|
78
|
-
|
|
79
|
-
|
|
55
|
+
add(h, s, l)
|
|
56
|
+
|
|
57
|
+
const isLastAnchor = anchorIndex === numAnchors - 1
|
|
58
|
+
if (isLastAnchor && palette.length < paletteSize) {
|
|
59
|
+
// forwardfill:
|
|
60
|
+
for (let step = anchor.index + 1; step < paletteSize; step++) {
|
|
61
|
+
add(h, s, l)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
80
64
|
}
|
|
81
65
|
|
|
66
|
+
// if (strategy?.type === 'automatic') {
|
|
67
|
+
// const hslas = {
|
|
68
|
+
// background: parseToHsla(strategy.background),
|
|
69
|
+
// foreground: parseToHsla(strategy.foreground),
|
|
70
|
+
// }
|
|
71
|
+
|
|
72
|
+
// palette = [
|
|
73
|
+
// // backgrounds
|
|
74
|
+
// ...new Array(10).fill(0).map((_, i) => {
|
|
75
|
+
// const [h, s, l] = hslas.background
|
|
76
|
+
|
|
77
|
+
// if (isDark) {
|
|
78
|
+
// const str = 9 - i
|
|
79
|
+
// const minLum = 0.05
|
|
80
|
+
// const by = (l - minLum) / 10
|
|
81
|
+
|
|
82
|
+
// return hsla(
|
|
83
|
+
// h,
|
|
84
|
+
// s,
|
|
85
|
+
// // go to dark or light
|
|
86
|
+
// l - by * str,
|
|
87
|
+
// 1
|
|
88
|
+
// )
|
|
89
|
+
// } else {
|
|
90
|
+
// const str = 9 - i
|
|
91
|
+
// const maxLum = 0.95
|
|
92
|
+
// const by = (maxLum - l) / 10
|
|
93
|
+
// return hsla(h, s, l + by * str, 1)
|
|
94
|
+
// }
|
|
95
|
+
// }),
|
|
96
|
+
// // colors
|
|
97
|
+
// ...new Array(2).fill(0).map((_, i) => {
|
|
98
|
+
// const [h, s, l] = hslas.foreground
|
|
99
|
+
// return hsla(
|
|
100
|
+
// h,
|
|
101
|
+
// s,
|
|
102
|
+
// // go to dark or light
|
|
103
|
+
// l - (i === 0 ? 0.1 : 0) - (forAccent ? 1 - l : 0),
|
|
104
|
+
// 1
|
|
105
|
+
// )
|
|
106
|
+
// }),
|
|
107
|
+
// ]
|
|
108
|
+
// } else {
|
|
109
|
+
// const lumValues = isDark ? lumScale.dark : lumScale.light
|
|
110
|
+
// palette = lumValues.map((lum, idx) => {
|
|
111
|
+
// const sat = satScale[scheme][idx]
|
|
112
|
+
|
|
113
|
+
// if (theme.hueColor && idx >= 10) {
|
|
114
|
+
// return hsla(theme.hueColor, sat, lum, 1)
|
|
115
|
+
// }
|
|
116
|
+
|
|
117
|
+
// return hsla(hue, sat, lum, 1)
|
|
118
|
+
// })
|
|
119
|
+
// }
|
|
120
|
+
|
|
82
121
|
// add transparent values
|
|
83
122
|
const [background] = palette
|
|
84
123
|
const foreground = palette[palette.length - 1]
|
|
@@ -96,27 +135,21 @@ const generateColorPalette = ({
|
|
|
96
135
|
const reverseForeground = [...transparentValues[1]].reverse()
|
|
97
136
|
palette = [...transparentValues[0], ...palette, ...reverseForeground]
|
|
98
137
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// const oppositeLightnessAccent = isAccentLight
|
|
105
|
-
// ? toHex(hsla(accentHsla[0], accentHsla[1], 1 - accentLum, 1))
|
|
106
|
-
// : theme.accent
|
|
107
|
-
|
|
108
|
-
// const fg = isAccentLight && !isDark ? oppositeLightnessAccent : theme.accent
|
|
109
|
-
// const bg = fg === theme.accent ? oppositeLightnessAccent : theme.accent
|
|
138
|
+
if (theme.accent) {
|
|
139
|
+
const accentPalette = generateColorPalette({
|
|
140
|
+
theme: theme.accent,
|
|
141
|
+
scheme,
|
|
142
|
+
})
|
|
110
143
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
144
|
+
// unshift bg
|
|
145
|
+
palette.unshift(accentPalette[11])
|
|
146
|
+
// push color
|
|
147
|
+
palette.push(accentPalette[accentPalette.length - 6])
|
|
148
|
+
} else {
|
|
149
|
+
// were keeping the palettes the same length with or without accent to avoid headache
|
|
150
|
+
palette.unshift('rgba(0,0,0,0)')
|
|
151
|
+
palette.push('rgba(0,0,0,0)')
|
|
152
|
+
}
|
|
120
153
|
|
|
121
154
|
return palette
|
|
122
155
|
}
|
package/src/masks.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MaskDefinitions,
|
|
3
|
+
MaskOptions,
|
|
4
|
+
combineMasks,
|
|
5
|
+
createIdentityMask,
|
|
6
|
+
createInverseMask,
|
|
7
|
+
createMask,
|
|
8
|
+
createSoftenMask,
|
|
9
|
+
createStrengthenMask,
|
|
10
|
+
skipMask,
|
|
11
|
+
} from '@tamagui/create-theme'
|
|
12
|
+
|
|
13
|
+
const shadows = {
|
|
14
|
+
shadowColor: 0,
|
|
15
|
+
shadowColorHover: 0,
|
|
16
|
+
shadowColorPress: 0,
|
|
17
|
+
shadowColorFocus: 0,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const colors = {
|
|
21
|
+
...shadows,
|
|
22
|
+
color: 0,
|
|
23
|
+
colorHover: 0,
|
|
24
|
+
colorFocus: 0,
|
|
25
|
+
colorPress: 0,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const templateColorsSpecific = {
|
|
29
|
+
color1: 1,
|
|
30
|
+
color2: 2,
|
|
31
|
+
color3: 3,
|
|
32
|
+
color4: 4,
|
|
33
|
+
color5: 5,
|
|
34
|
+
color6: 6,
|
|
35
|
+
color7: 7,
|
|
36
|
+
color8: 8,
|
|
37
|
+
color9: 9,
|
|
38
|
+
color10: 10,
|
|
39
|
+
color11: 11,
|
|
40
|
+
color12: 12,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const skipShadowsAndSpecificColors = {
|
|
44
|
+
...shadows,
|
|
45
|
+
...templateColorsSpecific,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const PALETTE_LEN = 14
|
|
49
|
+
|
|
50
|
+
const baseMaskOptions: MaskOptions = {
|
|
51
|
+
override: shadows,
|
|
52
|
+
skip: shadows,
|
|
53
|
+
// avoids the transparent ends
|
|
54
|
+
max: PALETTE_LEN - 2,
|
|
55
|
+
min: 1,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const maskOptions = {
|
|
59
|
+
component: {
|
|
60
|
+
...baseMaskOptions,
|
|
61
|
+
override: colors,
|
|
62
|
+
skip: skipShadowsAndSpecificColors,
|
|
63
|
+
},
|
|
64
|
+
alt: {
|
|
65
|
+
...baseMaskOptions,
|
|
66
|
+
},
|
|
67
|
+
button: {
|
|
68
|
+
...baseMaskOptions,
|
|
69
|
+
override: {
|
|
70
|
+
...colors,
|
|
71
|
+
borderColor: 'transparent',
|
|
72
|
+
borderColorHover: 'transparent',
|
|
73
|
+
},
|
|
74
|
+
skip: skipShadowsAndSpecificColors,
|
|
75
|
+
},
|
|
76
|
+
} satisfies Record<string, MaskOptions>
|
|
77
|
+
|
|
78
|
+
export const masks = {
|
|
79
|
+
identity: createIdentityMask(),
|
|
80
|
+
soften: createSoftenMask(),
|
|
81
|
+
soften2: createSoftenMask({ strength: 2 }),
|
|
82
|
+
soften3: createSoftenMask({ strength: 3 }),
|
|
83
|
+
strengthen: createStrengthenMask(),
|
|
84
|
+
inverse: createInverseMask(),
|
|
85
|
+
inverseSoften: combineMasks(createInverseMask(), createSoftenMask({ strength: 2 })),
|
|
86
|
+
inverseSoften2: combineMasks(createInverseMask(), createSoftenMask({ strength: 3 })),
|
|
87
|
+
inverseSoften3: combineMasks(createInverseMask(), createSoftenMask({ strength: 4 })),
|
|
88
|
+
inverseStrengthen2: combineMasks(
|
|
89
|
+
createInverseMask(),
|
|
90
|
+
createStrengthenMask({ strength: 2 })
|
|
91
|
+
),
|
|
92
|
+
strengthenButSoftenBorder: createMask((template, options) => {
|
|
93
|
+
const stronger = createStrengthenMask().mask(template, options)
|
|
94
|
+
const softer = createSoftenMask().mask(template, options)
|
|
95
|
+
return {
|
|
96
|
+
...stronger,
|
|
97
|
+
borderColor: softer.borderColor,
|
|
98
|
+
borderColorHover: softer.borderColorHover,
|
|
99
|
+
borderColorPress: softer.borderColorPress,
|
|
100
|
+
borderColorFocus: softer.borderColorFocus,
|
|
101
|
+
}
|
|
102
|
+
}),
|
|
103
|
+
soften2Border1: createMask((template, options) => {
|
|
104
|
+
const softer2 = createSoftenMask({ strength: 2 }).mask(template, options)
|
|
105
|
+
const softer1 = createSoftenMask({ strength: 1 }).mask(template, options)
|
|
106
|
+
return {
|
|
107
|
+
...softer2,
|
|
108
|
+
borderColor: softer1.borderColor,
|
|
109
|
+
borderColorHover: softer1.borderColorHover,
|
|
110
|
+
borderColorPress: softer1.borderColorPress,
|
|
111
|
+
borderColorFocus: softer1.borderColorFocus,
|
|
112
|
+
}
|
|
113
|
+
}),
|
|
114
|
+
soften3FlatBorder: createMask((template, options) => {
|
|
115
|
+
const borderMask = createSoftenMask({ strength: 2 }).mask(template, options)
|
|
116
|
+
const softer3 = createSoftenMask({ strength: 3 }).mask(template, options)
|
|
117
|
+
return {
|
|
118
|
+
...softer3,
|
|
119
|
+
borderColor: borderMask.borderColor,
|
|
120
|
+
borderColorHover: borderMask.borderColorHover,
|
|
121
|
+
borderColorPress: borderMask.borderColorPress,
|
|
122
|
+
borderColorFocus: borderMask.borderColorFocus,
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
softenBorder: createMask((template, options) => {
|
|
126
|
+
const plain = skipMask.mask(template, options)
|
|
127
|
+
const softer = createSoftenMask().mask(template, options)
|
|
128
|
+
return {
|
|
129
|
+
...plain,
|
|
130
|
+
borderColor: softer.borderColor,
|
|
131
|
+
borderColorHover: softer.borderColorHover,
|
|
132
|
+
borderColorPress: softer.borderColorPress,
|
|
133
|
+
borderColorFocus: softer.borderColorFocus,
|
|
134
|
+
}
|
|
135
|
+
}),
|
|
136
|
+
softenBorder2: createMask((template, options) => {
|
|
137
|
+
const plain = skipMask.mask(template, options)
|
|
138
|
+
const softer = createSoftenMask({ strength: 2 }).mask(template, options)
|
|
139
|
+
return {
|
|
140
|
+
...plain,
|
|
141
|
+
borderColor: softer.borderColor,
|
|
142
|
+
borderColorHover: softer.borderColorHover,
|
|
143
|
+
borderColorPress: softer.borderColorPress,
|
|
144
|
+
borderColorFocus: softer.borderColorFocus,
|
|
145
|
+
}
|
|
146
|
+
}),
|
|
147
|
+
} satisfies MaskDefinitions
|
package/src/types.ts
CHANGED
|
@@ -39,37 +39,32 @@ export type BuildThemeBase = {
|
|
|
39
39
|
errors?: string[]
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
type
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// if you use a preset it sets this then clears when changed
|
|
49
|
-
createdFrom?: ScaleTypeName
|
|
50
|
-
|
|
51
|
-
satScale: {
|
|
52
|
-
light: number[]
|
|
53
|
-
dark: number[]
|
|
42
|
+
export type BuildThemeAnchor = {
|
|
43
|
+
index: number
|
|
44
|
+
hue: {
|
|
45
|
+
light: number
|
|
46
|
+
dark: number
|
|
54
47
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
dark: number[]
|
|
48
|
+
sat: {
|
|
49
|
+
light: number
|
|
50
|
+
dark: number
|
|
59
51
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
type: 'automatic'
|
|
64
|
-
foreground: string
|
|
65
|
-
background: string
|
|
52
|
+
lum: {
|
|
53
|
+
light: number
|
|
54
|
+
dark: number
|
|
66
55
|
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type BuildTheme = BuildThemeBase & {
|
|
59
|
+
type: 'theme'
|
|
60
|
+
|
|
61
|
+
scale: ScaleTypeName
|
|
62
|
+
|
|
63
|
+
anchors: BuildThemeAnchor[]
|
|
67
64
|
|
|
68
65
|
template?: Template
|
|
69
|
-
}
|
|
70
66
|
|
|
71
|
-
|
|
72
|
-
accent?: BuildThemeFromScale
|
|
67
|
+
accent?: BuildTheme
|
|
73
68
|
}
|
|
74
69
|
|
|
75
70
|
// TODO type here isnt the same as type in BuildTheme
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildThemeSuitePalettes.d.ts","sourceRoot":"","sources":["../src/buildThemeSuitePalettes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"buildThemeSuitePalettes.d.ts","sourceRoot":"","sources":["../src/buildThemeSuitePalettes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAoB,uBAAuB,EAAE,MAAM,SAAS,CAAA;AA0J/E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,uBAAuB,CAOhF"}
|