@tamagui/theme-builder 1.116.1 → 1.116.2
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/ThemeBuilder.js +163 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/masks.js +86 -0
- package/package.json +3 -3
- /package/dist/cjs/{ThemeBuilder.cjs.map → ThemeBuilder.js.map} +0 -0
- /package/dist/cjs/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/{masks.cjs.map → masks.js.map} +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var ThemeBuilder_exports = {};
|
|
16
|
+
__export(ThemeBuilder_exports, {
|
|
17
|
+
ThemeBuilder: () => ThemeBuilder,
|
|
18
|
+
createThemeBuilder: () => createThemeBuilder
|
|
19
|
+
});
|
|
20
|
+
module.exports = __toCommonJS(ThemeBuilder_exports);
|
|
21
|
+
var import_create_theme = require("@tamagui/create-theme");
|
|
22
|
+
class ThemeBuilder {
|
|
23
|
+
constructor(state) {
|
|
24
|
+
this.state = state;
|
|
25
|
+
}
|
|
26
|
+
addPalettes(palettes) {
|
|
27
|
+
return this.state.palettes = {
|
|
28
|
+
// as {} prevents generic string key merge messing up types
|
|
29
|
+
...this.state.palettes,
|
|
30
|
+
...palettes
|
|
31
|
+
}, this;
|
|
32
|
+
}
|
|
33
|
+
addTemplates(templates) {
|
|
34
|
+
return this.state.templates = {
|
|
35
|
+
// as {} prevents generic string key merge messing up types
|
|
36
|
+
...this.state.templates,
|
|
37
|
+
...templates
|
|
38
|
+
}, this;
|
|
39
|
+
}
|
|
40
|
+
addMasks(masks) {
|
|
41
|
+
return this.state.masks = {
|
|
42
|
+
// as {} prevents generic string key merge messing up types
|
|
43
|
+
...this.state.masks,
|
|
44
|
+
...(0, import_create_theme.objectFromEntries)(
|
|
45
|
+
(0, import_create_theme.objectEntries)(masks).map(([key, val]) => [key, (0, import_create_theme.createMask)(val)])
|
|
46
|
+
)
|
|
47
|
+
}, this;
|
|
48
|
+
}
|
|
49
|
+
// for dev mode only really
|
|
50
|
+
_addedThemes = [];
|
|
51
|
+
addThemes(themes) {
|
|
52
|
+
return this._addedThemes.push({ type: "themes", args: [themes] }), this.state.themes = {
|
|
53
|
+
// as {} prevents generic string key merge messing up types
|
|
54
|
+
...this.state.themes,
|
|
55
|
+
...themes
|
|
56
|
+
}, this;
|
|
57
|
+
}
|
|
58
|
+
// these wont be typed to save some complexity and because they don't need to be typed!
|
|
59
|
+
addComponentThemes(childThemeDefinition, options) {
|
|
60
|
+
return this.addChildThemes(childThemeDefinition, options), this;
|
|
61
|
+
}
|
|
62
|
+
addChildThemes(childThemeDefinition, options) {
|
|
63
|
+
const currentThemes = this.state.themes;
|
|
64
|
+
if (!currentThemes)
|
|
65
|
+
throw new Error(
|
|
66
|
+
"No themes defined yet, use addThemes first to set your base themes"
|
|
67
|
+
);
|
|
68
|
+
this._addedThemes.push({ type: "childThemes", args: [childThemeDefinition, options] });
|
|
69
|
+
const currentThemeNames = Object.keys(currentThemes), incomingThemeNames = Object.keys(childThemeDefinition), namesWithDefinitions = currentThemeNames.flatMap((prefix) => {
|
|
70
|
+
const avoidNestingWithin = options?.avoidNestingWithin;
|
|
71
|
+
return avoidNestingWithin && avoidNestingWithin.some(
|
|
72
|
+
(avoidName) => prefix.startsWith(avoidName) || prefix.endsWith(avoidName)
|
|
73
|
+
) ? [] : incomingThemeNames.map((subName) => {
|
|
74
|
+
const fullName = `${prefix}_${subName}`, definition = childThemeDefinition[subName];
|
|
75
|
+
return "avoidNestingWithin" in definition && definition.avoidNestingWithin.some((name) => prefix.startsWith(name) || prefix.endsWith(name)) ? null : [fullName, definition];
|
|
76
|
+
}).filter(Boolean);
|
|
77
|
+
}), childThemes = Object.fromEntries(namesWithDefinitions), next = {
|
|
78
|
+
// as {} prevents generic string key merge messing up types
|
|
79
|
+
...this.state.themes,
|
|
80
|
+
...childThemes
|
|
81
|
+
};
|
|
82
|
+
return this.state.themes = next, this;
|
|
83
|
+
}
|
|
84
|
+
build() {
|
|
85
|
+
if (!this.state.themes)
|
|
86
|
+
return {};
|
|
87
|
+
const out = {}, maskedThemes = [];
|
|
88
|
+
for (const themeName in this.state.themes) {
|
|
89
|
+
const nameParts = themeName.split("_"), parentName = nameParts.slice(0, nameParts.length - 1).join("_"), definitions = this.state.themes[themeName], themeDefinition = Array.isArray(definitions) ? (() => {
|
|
90
|
+
const found = definitions.find(
|
|
91
|
+
// endWith match stronger than startsWith
|
|
92
|
+
(d) => d.parent ? parentName.endsWith(d.parent) || parentName.startsWith(d.parent) : !0
|
|
93
|
+
);
|
|
94
|
+
return found || null;
|
|
95
|
+
})() : definitions;
|
|
96
|
+
if (themeDefinition)
|
|
97
|
+
if ("theme" in themeDefinition)
|
|
98
|
+
out[themeName] = themeDefinition.theme;
|
|
99
|
+
else if ("mask" in themeDefinition)
|
|
100
|
+
maskedThemes.push({ parentName, themeName, mask: themeDefinition });
|
|
101
|
+
else {
|
|
102
|
+
let {
|
|
103
|
+
palette: paletteName = "",
|
|
104
|
+
template: templateName,
|
|
105
|
+
...options
|
|
106
|
+
} = themeDefinition;
|
|
107
|
+
const parentDefinition = this.state.themes[parentName];
|
|
108
|
+
if (!this.state.palettes)
|
|
109
|
+
throw new Error(
|
|
110
|
+
`No palettes defined for theme with palette expected: ${themeName}`
|
|
111
|
+
);
|
|
112
|
+
let palette = this.state.palettes[paletteName || ""], attemptParentName = `${parentName}_${paletteName}`;
|
|
113
|
+
for (; !palette && attemptParentName; )
|
|
114
|
+
attemptParentName in this.state.palettes ? (palette = this.state.palettes[attemptParentName], paletteName = attemptParentName) : attemptParentName = attemptParentName.split("_").slice(0, -1).join("_");
|
|
115
|
+
if (!palette) {
|
|
116
|
+
const msg = process.env.NODE_ENV !== "production" ? `: ${themeName}: ${paletteName}
|
|
117
|
+
Definition: ${JSON.stringify(themeDefinition)}
|
|
118
|
+
Parent: ${JSON.stringify(parentDefinition)}
|
|
119
|
+
Potential: (${Object.keys(this.state.palettes).join(", ")})` : "";
|
|
120
|
+
throw new Error(`No palette for theme${msg}`);
|
|
121
|
+
}
|
|
122
|
+
const template = this.state.templates?.[templateName] ?? // fall back to finding the scheme specific on if it exists
|
|
123
|
+
this.state.templates?.[`${nameParts[0]}_${templateName}`];
|
|
124
|
+
if (!template)
|
|
125
|
+
throw new Error(`No template for theme ${themeName}: ${templateName}`);
|
|
126
|
+
out[themeName] = (0, import_create_theme.createThemeWithPalettes)(
|
|
127
|
+
this.state.palettes,
|
|
128
|
+
paletteName,
|
|
129
|
+
template,
|
|
130
|
+
options,
|
|
131
|
+
themeName,
|
|
132
|
+
!0
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
for (const { mask, themeName, parentName } of maskedThemes) {
|
|
137
|
+
const parent = out[parentName];
|
|
138
|
+
if (!parent)
|
|
139
|
+
continue;
|
|
140
|
+
const { mask: maskName, ...options } = mask;
|
|
141
|
+
let maskFunction = this.state.masks?.[maskName];
|
|
142
|
+
if (!maskFunction)
|
|
143
|
+
throw new Error(`No mask ${maskName}`);
|
|
144
|
+
const parentTheme = this.state.themes[parentName];
|
|
145
|
+
if (parentTheme && "childOptions" in parentTheme) {
|
|
146
|
+
const { mask: mask2, ...childOpts } = parentTheme.childOptions;
|
|
147
|
+
mask2 && (maskFunction = this.state.masks?.[mask2]), Object.assign(options, childOpts);
|
|
148
|
+
}
|
|
149
|
+
out[themeName] = (0, import_create_theme.applyMask)(
|
|
150
|
+
parent,
|
|
151
|
+
maskFunction,
|
|
152
|
+
options,
|
|
153
|
+
parentName,
|
|
154
|
+
themeName
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function createThemeBuilder() {
|
|
161
|
+
return new ThemeBuilder({});
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=ThemeBuilder.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
__export(src_exports, {
|
|
17
|
+
masks: () => import_masks.masks
|
|
18
|
+
});
|
|
19
|
+
module.exports = __toCommonJS(src_exports);
|
|
20
|
+
__reExport(src_exports, require("./ThemeBuilder"), module.exports);
|
|
21
|
+
__reExport(src_exports, require("@tamagui/create-theme"), module.exports);
|
|
22
|
+
var import_masks = require("./masks");
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var masks_exports = {};
|
|
16
|
+
__export(masks_exports, {
|
|
17
|
+
masks: () => masks
|
|
18
|
+
});
|
|
19
|
+
module.exports = __toCommonJS(masks_exports);
|
|
20
|
+
var import_create_theme = require("@tamagui/create-theme");
|
|
21
|
+
const masks = {
|
|
22
|
+
identity: (0, import_create_theme.createIdentityMask)(),
|
|
23
|
+
soften: (0, import_create_theme.createSoftenMask)(),
|
|
24
|
+
soften2: (0, import_create_theme.createSoftenMask)({ strength: 2 }),
|
|
25
|
+
soften3: (0, import_create_theme.createSoftenMask)({ strength: 3 }),
|
|
26
|
+
strengthen: (0, import_create_theme.createStrengthenMask)(),
|
|
27
|
+
inverse: (0, import_create_theme.createInverseMask)(),
|
|
28
|
+
inverseSoften: (0, import_create_theme.combineMasks)((0, import_create_theme.createInverseMask)(), (0, import_create_theme.createSoftenMask)({ strength: 2 })),
|
|
29
|
+
inverseSoften2: (0, import_create_theme.combineMasks)((0, import_create_theme.createInverseMask)(), (0, import_create_theme.createSoftenMask)({ strength: 3 })),
|
|
30
|
+
inverseSoften3: (0, import_create_theme.combineMasks)((0, import_create_theme.createInverseMask)(), (0, import_create_theme.createSoftenMask)({ strength: 4 })),
|
|
31
|
+
inverseStrengthen2: (0, import_create_theme.combineMasks)(
|
|
32
|
+
(0, import_create_theme.createInverseMask)(),
|
|
33
|
+
(0, import_create_theme.createStrengthenMask)({ strength: 2 })
|
|
34
|
+
),
|
|
35
|
+
strengthenButSoftenBorder: (0, import_create_theme.createMask)((template, options) => {
|
|
36
|
+
const stronger = (0, import_create_theme.createStrengthenMask)().mask(template, options), softer = (0, import_create_theme.createSoftenMask)().mask(template, options);
|
|
37
|
+
return {
|
|
38
|
+
...stronger,
|
|
39
|
+
borderColor: softer.borderColor,
|
|
40
|
+
borderColorHover: softer.borderColorHover,
|
|
41
|
+
borderColorPress: softer.borderColorPress,
|
|
42
|
+
borderColorFocus: softer.borderColorFocus
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
soften2Border1: (0, import_create_theme.createMask)((template, options) => {
|
|
46
|
+
const softer2 = (0, import_create_theme.createSoftenMask)({ strength: 2 }).mask(template, options), softer1 = (0, import_create_theme.createSoftenMask)({ strength: 1 }).mask(template, options);
|
|
47
|
+
return {
|
|
48
|
+
...softer2,
|
|
49
|
+
borderColor: softer1.borderColor,
|
|
50
|
+
borderColorHover: softer1.borderColorHover,
|
|
51
|
+
borderColorPress: softer1.borderColorPress,
|
|
52
|
+
borderColorFocus: softer1.borderColorFocus
|
|
53
|
+
};
|
|
54
|
+
}),
|
|
55
|
+
soften3FlatBorder: (0, import_create_theme.createMask)((template, options) => {
|
|
56
|
+
const borderMask = (0, import_create_theme.createSoftenMask)({ strength: 2 }).mask(template, options);
|
|
57
|
+
return {
|
|
58
|
+
...(0, import_create_theme.createSoftenMask)({ strength: 3 }).mask(template, options),
|
|
59
|
+
borderColor: borderMask.borderColor,
|
|
60
|
+
borderColorHover: borderMask.borderColorHover,
|
|
61
|
+
borderColorPress: borderMask.borderColorPress,
|
|
62
|
+
borderColorFocus: borderMask.borderColorFocus
|
|
63
|
+
};
|
|
64
|
+
}),
|
|
65
|
+
softenBorder: (0, import_create_theme.createMask)((template, options) => {
|
|
66
|
+
const plain = import_create_theme.skipMask.mask(template, options), softer = (0, import_create_theme.createSoftenMask)().mask(template, options);
|
|
67
|
+
return {
|
|
68
|
+
...plain,
|
|
69
|
+
borderColor: softer.borderColor,
|
|
70
|
+
borderColorHover: softer.borderColorHover,
|
|
71
|
+
borderColorPress: softer.borderColorPress,
|
|
72
|
+
borderColorFocus: softer.borderColorFocus
|
|
73
|
+
};
|
|
74
|
+
}),
|
|
75
|
+
softenBorder2: (0, import_create_theme.createMask)((template, options) => {
|
|
76
|
+
const plain = import_create_theme.skipMask.mask(template, options), softer = (0, import_create_theme.createSoftenMask)({ strength: 2 }).mask(template, options);
|
|
77
|
+
return {
|
|
78
|
+
...plain,
|
|
79
|
+
borderColor: softer.borderColor,
|
|
80
|
+
borderColorHover: softer.borderColorHover,
|
|
81
|
+
borderColorPress: softer.borderColorPress,
|
|
82
|
+
borderColorFocus: softer.borderColorFocus
|
|
83
|
+
};
|
|
84
|
+
})
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=masks.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/theme-builder",
|
|
3
|
-
"version": "1.116.
|
|
3
|
+
"version": "1.116.2",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@tamagui/create-theme": "1.116.
|
|
33
|
+
"@tamagui/create-theme": "1.116.2",
|
|
34
34
|
"color2k": "^2.0.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@tamagui/build": "1.116.
|
|
37
|
+
"@tamagui/build": "1.116.2"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|