@hanzogui/theme-builder 3.0.6 → 4.4.0
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.cjs +132 -68
- package/dist/cjs/ThemeBuilder.native.js +208 -132
- package/dist/cjs/ThemeBuilder.native.js.map +1 -1
- package/dist/cjs/createStudioThemes.cjs +19 -17
- package/dist/cjs/createStudioThemes.native.js +19 -17
- package/dist/cjs/createStudioThemes.native.js.map +1 -1
- package/dist/cjs/createThemes.cjs +173 -123
- package/dist/cjs/createThemes.native.js +287 -248
- package/dist/cjs/createThemes.native.js.map +1 -1
- package/dist/cjs/defaultComponentThemes.cjs +12 -10
- package/dist/cjs/defaultComponentThemes.native.js +12 -10
- package/dist/cjs/defaultComponentThemes.native.js.map +1 -1
- package/dist/cjs/defaultTemplates.cjs +137 -132
- package/dist/cjs/defaultTemplates.native.js +144 -142
- package/dist/cjs/defaultTemplates.native.js.map +1 -1
- package/dist/cjs/defaultTemplatesStronger.cjs +135 -130
- package/dist/cjs/defaultTemplatesStronger.native.js +142 -140
- package/dist/cjs/defaultTemplatesStronger.native.js.map +1 -1
- package/dist/cjs/defaultTemplatesStrongest.cjs +135 -130
- package/dist/cjs/defaultTemplatesStrongest.native.js +142 -140
- package/dist/cjs/defaultTemplatesStrongest.native.js.map +1 -1
- package/dist/cjs/getThemeSuitePalettes.cjs +61 -50
- package/dist/cjs/getThemeSuitePalettes.native.js +79 -55
- package/dist/cjs/getThemeSuitePalettes.native.js.map +1 -1
- package/dist/cjs/helpers.cjs +12 -10
- package/dist/cjs/helpers.native.js +12 -10
- package/dist/cjs/helpers.native.js.map +1 -1
- package/dist/cjs/index.cjs +19 -17
- package/dist/cjs/index.native.js +19 -17
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/masks.cjs +29 -26
- package/dist/cjs/masks.native.js +98 -96
- package/dist/cjs/masks.native.js.map +1 -1
- package/dist/cjs/types.cjs +7 -5
- package/dist/cjs/types.native.js +7 -5
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/esm/ThemeBuilder.mjs +120 -58
- package/dist/esm/ThemeBuilder.mjs.map +1 -1
- package/dist/esm/ThemeBuilder.native.js +196 -122
- package/dist/esm/ThemeBuilder.native.js.map +1 -1
- package/dist/esm/createStudioThemes.mjs +2 -2
- package/dist/esm/createStudioThemes.mjs.map +1 -1
- package/dist/esm/createStudioThemes.native.js +2 -2
- package/dist/esm/createStudioThemes.native.js.map +1 -1
- package/dist/esm/createThemes.mjs +156 -108
- package/dist/esm/createThemes.mjs.map +1 -1
- package/dist/esm/createThemes.native.js +270 -233
- package/dist/esm/createThemes.native.js.map +1 -1
- package/dist/esm/defaultTemplates.mjs +125 -122
- package/dist/esm/defaultTemplates.mjs.map +1 -1
- package/dist/esm/defaultTemplates.native.js +130 -130
- package/dist/esm/defaultTemplates.native.js.map +1 -1
- package/dist/esm/defaultTemplatesStronger.mjs +123 -120
- package/dist/esm/defaultTemplatesStronger.mjs.map +1 -1
- package/dist/esm/defaultTemplatesStronger.native.js +128 -128
- package/dist/esm/defaultTemplatesStronger.native.js.map +1 -1
- package/dist/esm/defaultTemplatesStrongest.mjs +123 -120
- package/dist/esm/defaultTemplatesStrongest.mjs.map +1 -1
- package/dist/esm/defaultTemplatesStrongest.native.js +128 -128
- package/dist/esm/defaultTemplatesStrongest.native.js.map +1 -1
- package/dist/esm/getThemeSuitePalettes.mjs +49 -40
- package/dist/esm/getThemeSuitePalettes.mjs.map +1 -1
- package/dist/esm/getThemeSuitePalettes.native.js +66 -44
- package/dist/esm/getThemeSuitePalettes.native.js.map +1 -1
- package/dist/esm/masks.mjs +17 -16
- package/dist/esm/masks.mjs.map +1 -1
- package/dist/esm/masks.native.js +18 -18
- package/dist/esm/masks.native.js.map +1 -1
- package/package.json +4 -4
|
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var ThemeBuilder_exports = {};
|
|
22
24
|
__export(ThemeBuilder_exports, {
|
|
@@ -29,115 +31,170 @@ class ThemeBuilder {
|
|
|
29
31
|
constructor(state) {
|
|
30
32
|
this.state = state;
|
|
31
33
|
}
|
|
34
|
+
state;
|
|
32
35
|
_getThemeFn;
|
|
33
36
|
addPalettes(palettes) {
|
|
34
|
-
|
|
37
|
+
this.state.palettes = {
|
|
35
38
|
// as {} prevents generic string key merge messing up types
|
|
36
39
|
...this.state.palettes,
|
|
37
40
|
...palettes
|
|
38
|
-
}
|
|
41
|
+
};
|
|
42
|
+
return this;
|
|
39
43
|
}
|
|
40
44
|
addTemplates(templates) {
|
|
41
|
-
|
|
45
|
+
this.state.templates = {
|
|
42
46
|
// as {} prevents generic string key merge messing up types
|
|
43
47
|
...this.state.templates,
|
|
44
48
|
...templates
|
|
45
|
-
}
|
|
49
|
+
};
|
|
50
|
+
return this;
|
|
46
51
|
}
|
|
47
52
|
addMasks(masks) {
|
|
48
|
-
|
|
53
|
+
this.state.masks = {
|
|
49
54
|
// as {} prevents generic string key merge messing up types
|
|
50
55
|
...this.state.masks,
|
|
51
56
|
...(0, import_create_theme.objectFromEntries)((0, import_create_theme.objectEntries)(masks).map(([key, val]) => [key, (0, import_create_theme.createMask)(val)]))
|
|
52
|
-
}
|
|
57
|
+
};
|
|
58
|
+
return this;
|
|
53
59
|
}
|
|
54
60
|
// for dev mode only really
|
|
55
61
|
_addedThemes = [];
|
|
56
62
|
addThemes(themes) {
|
|
57
|
-
|
|
63
|
+
this._addedThemes.push({
|
|
58
64
|
type: "themes",
|
|
59
65
|
args: [themes]
|
|
60
|
-
})
|
|
66
|
+
});
|
|
67
|
+
this.state.themes = {
|
|
61
68
|
// as {} prevents generic string key merge messing up types
|
|
62
69
|
...this.state.themes,
|
|
63
70
|
...themes
|
|
64
|
-
}
|
|
71
|
+
};
|
|
72
|
+
return this;
|
|
65
73
|
}
|
|
66
74
|
// these wont be typed to save some complexity and because they don't need to be typed!
|
|
67
75
|
addComponentThemes(childThemeDefinition, options) {
|
|
68
|
-
|
|
76
|
+
void this.addChildThemes(childThemeDefinition, options);
|
|
77
|
+
return this;
|
|
69
78
|
}
|
|
70
79
|
addChildThemes(childThemeDefinition, options) {
|
|
71
80
|
const currentThemes = this.state.themes;
|
|
72
|
-
if (!currentThemes)
|
|
81
|
+
if (!currentThemes) {
|
|
82
|
+
throw new Error(`No themes defined yet, use addThemes first to set your base themes`);
|
|
83
|
+
}
|
|
73
84
|
this._addedThemes.push({
|
|
74
85
|
type: "childThemes",
|
|
75
86
|
args: [childThemeDefinition, options]
|
|
76
87
|
});
|
|
77
|
-
const currentThemeNames = Object.keys(currentThemes)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
const currentThemeNames = Object.keys(currentThemes);
|
|
89
|
+
const incomingThemeNames = Object.keys(childThemeDefinition);
|
|
90
|
+
const namesWithDefinitions = currentThemeNames.flatMap(prefix => {
|
|
91
|
+
const avoidNestingWithin = options?.avoidNestingWithin;
|
|
92
|
+
if (avoidNestingWithin) {
|
|
93
|
+
if (avoidNestingWithin.some(avoidName => prefix.startsWith(avoidName) || prefix.endsWith(avoidName))) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return incomingThemeNames.map(subName => {
|
|
98
|
+
const fullName = `${prefix}_${subName}`;
|
|
99
|
+
const definition = childThemeDefinition[subName];
|
|
100
|
+
if ("avoidNestingWithin" in definition) {
|
|
101
|
+
const avoidNest = definition.avoidNestingWithin;
|
|
102
|
+
if (avoidNest.some(name => {
|
|
103
|
+
if ((name === "light" || name === "dark") && prefix.includes("_")) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return prefix.startsWith(name) || prefix.endsWith(name);
|
|
107
|
+
})) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (prefix.endsWith(`_${subName}`)) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
if (fullName in currentThemes) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return [fullName, definition];
|
|
118
|
+
}).filter(Boolean);
|
|
119
|
+
});
|
|
120
|
+
const childThemes = Object.fromEntries(namesWithDefinitions);
|
|
121
|
+
const next = {
|
|
122
|
+
// as {} prevents generic string key merge messing up types
|
|
123
|
+
...this.state.themes,
|
|
124
|
+
...childThemes
|
|
125
|
+
};
|
|
126
|
+
this.state.themes = next;
|
|
127
|
+
return this;
|
|
94
128
|
}
|
|
95
129
|
getTheme(fn) {
|
|
96
|
-
|
|
130
|
+
this._getThemeFn = fn;
|
|
131
|
+
return this;
|
|
97
132
|
}
|
|
98
133
|
build() {
|
|
99
|
-
if (!this.state.themes)
|
|
100
|
-
|
|
101
|
-
|
|
134
|
+
if (!this.state.themes) {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
const out = {};
|
|
138
|
+
const maskedThemes = [];
|
|
102
139
|
for (const themeName in this.state.themes) {
|
|
103
|
-
const nameParts = themeName.split("_")
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
140
|
+
const nameParts = themeName.split("_");
|
|
141
|
+
const parentName = nameParts.slice(0, nameParts.length - 1).join("_");
|
|
142
|
+
const definitions = this.state.themes[themeName];
|
|
143
|
+
const themeDefinition = Array.isArray(definitions) ? (() => {
|
|
144
|
+
const found = definitions.find(
|
|
145
|
+
// endWith match stronger than startsWith
|
|
146
|
+
d => d.parent ? parentName.endsWith(d.parent) || parentName.startsWith(d.parent) : true);
|
|
147
|
+
if (!found) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
return found;
|
|
151
|
+
})() : definitions;
|
|
152
|
+
if (!themeDefinition) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if ("theme" in themeDefinition) {
|
|
156
|
+
out[themeName] = themeDefinition.theme;
|
|
157
|
+
} else if ("mask" in themeDefinition) {
|
|
158
|
+
maskedThemes.push({
|
|
159
|
+
parentName,
|
|
160
|
+
themeName,
|
|
161
|
+
mask: themeDefinition
|
|
162
|
+
});
|
|
163
|
+
} else {
|
|
117
164
|
let {
|
|
118
165
|
palette: paletteName = "",
|
|
119
166
|
template: templateName,
|
|
120
167
|
...options
|
|
121
168
|
} = themeDefinition;
|
|
122
169
|
const parentDefinition = this.state.themes[parentName];
|
|
123
|
-
if (!this.state.palettes)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
170
|
+
if (!this.state.palettes) {
|
|
171
|
+
throw new Error(`No palettes defined for theme with palette expected: ${themeName}`);
|
|
172
|
+
}
|
|
173
|
+
let palette = this.state.palettes[paletteName || ""];
|
|
174
|
+
let attemptParentName = `${parentName}_${paletteName}`;
|
|
175
|
+
while (!palette && attemptParentName) {
|
|
176
|
+
if (attemptParentName in this.state.palettes) {
|
|
177
|
+
palette = this.state.palettes[attemptParentName];
|
|
178
|
+
paletteName = attemptParentName;
|
|
179
|
+
} else {
|
|
180
|
+
attemptParentName = attemptParentName.split("_").slice(0, -1).join("_");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
127
183
|
if (!palette) {
|
|
128
184
|
const msg = process.env.NODE_ENV !== "production" ? `: ${themeName}: ${paletteName}
|
|
129
185
|
Definition: ${JSON.stringify(themeDefinition)}
|
|
130
186
|
Parent: ${JSON.stringify(parentDefinition)}
|
|
131
|
-
Potential: (${Object.keys(this.state.palettes).join(", ")})` :
|
|
187
|
+
Potential: (${Object.keys(this.state.palettes).join(", ")})` : ``;
|
|
132
188
|
throw new Error(`No palette for theme${msg}`);
|
|
133
189
|
}
|
|
134
190
|
const template = this.state.templates?.[templateName] ??
|
|
135
191
|
// fall back to finding the scheme specific on if it exists
|
|
136
192
|
this.state.templates?.[`${nameParts[0]}_${templateName}`];
|
|
137
|
-
if (!template)
|
|
138
|
-
|
|
139
|
-
-
|
|
140
|
-
|
|
193
|
+
if (!template) {
|
|
194
|
+
throw new Error(`No template for theme ${themeName}: ${templateName} in templates:
|
|
195
|
+
- ${Object.keys(this.state.templates || {}).join("\n - ")}`);
|
|
196
|
+
}
|
|
197
|
+
const theme = (0, import_create_theme.createThemeWithPalettes)(this.state.palettes, paletteName, template, options, themeName, true);
|
|
141
198
|
out[themeName] = this._getThemeFn ? {
|
|
142
199
|
...theme,
|
|
143
200
|
...this._getThemeFn({
|
|
@@ -159,20 +216,27 @@ class ThemeBuilder {
|
|
|
159
216
|
parentName
|
|
160
217
|
} of maskedThemes) {
|
|
161
218
|
const parent = out[parentName];
|
|
162
|
-
if (!parent)
|
|
219
|
+
if (!parent) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
163
222
|
const {
|
|
164
223
|
mask: maskName,
|
|
165
224
|
...options
|
|
166
225
|
} = mask;
|
|
167
226
|
let maskFunction = this.state.masks?.[maskName];
|
|
168
|
-
if (!maskFunction)
|
|
227
|
+
if (!maskFunction) {
|
|
228
|
+
throw new Error(`No mask ${maskName}`);
|
|
229
|
+
}
|
|
169
230
|
const parentTheme = this.state.themes[parentName];
|
|
170
231
|
if (parentTheme && "childOptions" in parentTheme) {
|
|
171
232
|
const {
|
|
172
233
|
mask: mask2,
|
|
173
234
|
...childOpts
|
|
174
235
|
} = parentTheme.childOptions;
|
|
175
|
-
|
|
236
|
+
if (mask2) {
|
|
237
|
+
maskFunction = this.state.masks?.[mask2];
|
|
238
|
+
}
|
|
239
|
+
Object.assign(options, childOpts);
|
|
176
240
|
}
|
|
177
241
|
out[themeName] = (0, import_create_theme.applyMask)(parent, maskFunction, options, parentName, themeName);
|
|
178
242
|
}
|