@tamagui/create-theme 1.45.10 → 1.46.0-1690511385750

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/index.js CHANGED
@@ -20,12 +20,14 @@ __reExport(src_exports, require("./masks"), module.exports);
20
20
  __reExport(src_exports, require("./combineMasks"), module.exports);
21
21
  __reExport(src_exports, require("./applyMask"), module.exports);
22
22
  __reExport(src_exports, require("./createThemeTypes"), module.exports);
23
+ __reExport(src_exports, require("./helpers"), module.exports);
23
24
  // Annotate the CommonJS export names for ESM import in node:
24
25
  0 && (module.exports = {
25
26
  ...require("./createTheme"),
26
27
  ...require("./masks"),
27
28
  ...require("./combineMasks"),
28
29
  ...require("./applyMask"),
29
- ...require("./createThemeTypes")
30
+ ...require("./createThemeTypes"),
31
+ ...require("./helpers")
30
32
  });
31
33
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,0BAAd;AACA,wBAAc,oBADd;AAEA,wBAAc,2BAFd;AAGA,wBAAc,wBAHd;AAIA,wBAAc,+BAJd;",
4
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,0BAAd;AACA,wBAAc,oBADd;AAEA,wBAAc,2BAFd;AAGA,wBAAc,wBAHd;AAIA,wBAAc,+BAJd;AAKA,wBAAc,sBALd;",
5
5
  "names": []
6
6
  }
package/dist/esm/index.js CHANGED
@@ -3,4 +3,5 @@ export * from "./masks";
3
3
  export * from "./combineMasks";
4
4
  export * from "./applyMask";
5
5
  export * from "./createThemeTypes";
6
+ export * from "./helpers";
6
7
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
5
5
  "names": []
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/create-theme",
3
- "version": "1.45.10",
3
+ "version": "1.46.0-1690511385750",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -21,11 +21,6 @@
21
21
  },
22
22
  "exports": {
23
23
  "./package.json": "./package.json",
24
- "./theme-builder": {
25
- "types": "./types/ThemeBuilder.d.ts",
26
- "import": "./dist/esm/ThemeBuilder.js",
27
- "require": "./dist/cjs/ThemeBuilder.js"
28
- },
29
24
  ".": {
30
25
  "types": "./types/index.d.ts",
31
26
  "import": "./dist/esm/index.js",
@@ -33,10 +28,10 @@
33
28
  }
34
29
  },
35
30
  "dependencies": {
36
- "@tamagui/web": "1.45.10"
31
+ "@tamagui/web": "1.46.0-1690511385750"
37
32
  },
38
33
  "devDependencies": {
39
- "@tamagui/build": "1.45.10"
34
+ "@tamagui/build": "1.46.0-1690511385750"
40
35
  },
41
36
  "publishConfig": {
42
37
  "access": "public"
@@ -26,3 +26,53 @@ export type CreateMask = {
26
26
  export type CreateThemeOptions = {
27
27
  nonInheritedValues?: GenericTheme
28
28
  }
29
+
30
+ export type Palette = string[]
31
+
32
+ export type Template = {
33
+ [key: string]: number
34
+ }
35
+
36
+ export type ThemeUsingMask<Masks = string> = MaskOptions & {
37
+ mask: Masks
38
+ }
39
+
40
+ type ThemeUsingTemplate = CreateThemeOptions & {
41
+ palette: string
42
+ template: string
43
+ }
44
+
45
+ type ThemePreDefined = {
46
+ theme: { [key: string]: string }
47
+ }
48
+
49
+ export type Theme<Masks = string> =
50
+ | ThemePreDefined
51
+ | ThemeUsingTemplate
52
+ | ThemeUsingMask<Masks>
53
+
54
+ export type ThemeWithParent<Masks = string> = Theme<Masks> & {
55
+ parent: string
56
+ }
57
+
58
+ export type PaletteDefinitions = {
59
+ [key: string]: Palette
60
+ }
61
+
62
+ export type ThemeDefinition<Masks extends string = string> =
63
+ | Theme<Masks>
64
+ | ThemeWithParent<Masks>[]
65
+
66
+ type UnionableString = string & {}
67
+
68
+ export type ThemeDefinitions<Masks extends string = string> = {
69
+ [key: string]: ThemeDefinition<Masks | UnionableString>
70
+ }
71
+
72
+ export type TemplateDefinitions = {
73
+ [key: string]: Template
74
+ }
75
+
76
+ export type MaskDefinitions = {
77
+ [key: string]: CreateMask | CreateMask['mask']
78
+ }
package/src/index.tsx CHANGED
@@ -3,4 +3,4 @@ export * from './masks'
3
3
  export * from './combineMasks'
4
4
  export * from './applyMask'
5
5
  export * from './createThemeTypes'
6
- // export * from './ThemeBuilder'
6
+ export * from './helpers'
@@ -21,4 +21,39 @@ export type CreateMask = {
21
21
  export type CreateThemeOptions = {
22
22
  nonInheritedValues?: GenericTheme;
23
23
  };
24
+ export type Palette = string[];
25
+ export type Template = {
26
+ [key: string]: number;
27
+ };
28
+ export type ThemeUsingMask<Masks = string> = MaskOptions & {
29
+ mask: Masks;
30
+ };
31
+ type ThemeUsingTemplate = CreateThemeOptions & {
32
+ palette: string;
33
+ template: string;
34
+ };
35
+ type ThemePreDefined = {
36
+ theme: {
37
+ [key: string]: string;
38
+ };
39
+ };
40
+ export type Theme<Masks = string> = ThemePreDefined | ThemeUsingTemplate | ThemeUsingMask<Masks>;
41
+ export type ThemeWithParent<Masks = string> = Theme<Masks> & {
42
+ parent: string;
43
+ };
44
+ export type PaletteDefinitions = {
45
+ [key: string]: Palette;
46
+ };
47
+ export type ThemeDefinition<Masks extends string = string> = Theme<Masks> | ThemeWithParent<Masks>[];
48
+ type UnionableString = string & {};
49
+ export type ThemeDefinitions<Masks extends string = string> = {
50
+ [key: string]: ThemeDefinition<Masks | UnionableString>;
51
+ };
52
+ export type TemplateDefinitions = {
53
+ [key: string]: Template;
54
+ };
55
+ export type MaskDefinitions = {
56
+ [key: string]: CreateMask | CreateMask['mask'];
57
+ };
58
+ export {};
24
59
  //# sourceMappingURL=createThemeTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createThemeTypes.d.ts","sourceRoot":"","sources":["../src/createThemeTypes.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAE5C,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,EAAE,CAAA;AAEtD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEvD,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,kBAAkB,CAAA;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AAE/D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,SAAS,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,KAAK,CAAC,CAAA;AAExF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,YAAY,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,kBAAkB,CAAC,EAAE,YAAY,CAAA;CAClC,CAAA"}
1
+ {"version":3,"file":"createThemeTypes.d.ts","sourceRoot":"","sources":["../src/createThemeTypes.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAE5C,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,EAAE,CAAA;AAEtD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEvD,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,kBAAkB,CAAA;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AAE/D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,SAAS,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,KAAK,CAAC,CAAA;AAExF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,YAAY,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,kBAAkB,CAAC,EAAE,YAAY,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,MAAM,EAAE,CAAA;AAE9B,MAAM,MAAM,QAAQ,GAAG;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,cAAc,CAAC,KAAK,GAAG,MAAM,IAAI,WAAW,GAAG;IACzD,IAAI,EAAE,KAAK,CAAA;CACZ,CAAA;AAED,KAAK,kBAAkB,GAAG,kBAAkB,GAAG;IAC7C,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,KAAK,CAAC,KAAK,GAAG,MAAM,IAC5B,eAAe,GACf,kBAAkB,GAClB,cAAc,CAAC,KAAK,CAAC,CAAA;AAEzB,MAAM,MAAM,eAAe,CAAC,KAAK,GAAG,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG;IAC3D,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,IACrD,KAAK,CAAC,KAAK,CAAC,GACZ,eAAe,CAAC,KAAK,CAAC,EAAE,CAAA;AAE5B,KAAK,eAAe,GAAG,MAAM,GAAG,EAAE,CAAA;AAElC,MAAM,MAAM,gBAAgB,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,IAAI;IAC5D,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC,KAAK,GAAG,eAAe,CAAC,CAAA;CACxD,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;CAC/C,CAAA"}
package/types/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export * from './masks';
3
3
  export * from './combineMasks';
4
4
  export * from './applyMask';
5
5
  export * from './createThemeTypes';
6
+ export * from './helpers';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA"}
@@ -1,375 +0,0 @@
1
- import type { Narrow } from '@tamagui/web'
2
-
3
- import { applyMask } from './applyMask'
4
- import { createTheme } from './createTheme'
5
- import { CreateMask, CreateThemeOptions, MaskOptions } from './createThemeTypes'
6
- import { objectEntries, objectFromEntries, objectKeys } from './helpers'
7
- import { createMask } from './masks'
8
-
9
- export type Palette = string[]
10
-
11
- type GenericTheme = {
12
- [key: string]: string
13
- }
14
-
15
- export type Template = {
16
- [key: string]: number
17
- }
18
-
19
- type ThemeUsingMask<Masks = string> = MaskOptions & {
20
- mask: Masks
21
- }
22
-
23
- type ThemeUsingTemplate = CreateThemeOptions & {
24
- palette: string
25
- template: string
26
- }
27
-
28
- type ThemePreDefined = {
29
- theme: GenericTheme
30
- }
31
-
32
- export type Theme<Masks = string> =
33
- | ThemePreDefined
34
- | ThemeUsingTemplate
35
- | ThemeUsingMask<Masks>
36
-
37
- export type ThemeWithParent<Masks = string> = Theme<Masks> & {
38
- parent: string
39
- }
40
-
41
- export type PaletteDefinitions = {
42
- [key: string]: Palette
43
- }
44
-
45
- export type ThemeDefinition<Masks extends string = string> =
46
- | Theme<Masks>
47
- | ThemeWithParent<Masks>[]
48
-
49
- type UnionableString = string & {}
50
-
51
- export type ThemeDefinitions<Masks extends string = string> = {
52
- [key: string]: ThemeDefinition<Masks | UnionableString>
53
- }
54
-
55
- export type TemplateDefinitions = {
56
- [key: string]: Template
57
- }
58
-
59
- export type MaskDefinitions = {
60
- [key: string]: CreateMask | CreateMask['mask']
61
- }
62
-
63
- type ThemeBuilderState = {
64
- palettes?: PaletteDefinitions
65
- templates?: TemplateDefinitions
66
- themes?: ThemeDefinitions
67
- masks?: MaskDefinitions
68
- }
69
-
70
- type ObjectStringKeys<A extends Object | undefined> = A extends Object
71
- ? Exclude<keyof A, symbol | number>
72
- : never
73
-
74
- type GetGeneratedThemeFromTemplate<Template> = {
75
- [key in keyof Template]: string
76
- }
77
-
78
- type GetParentTheme<P, Themes extends ThemeDefinitions | undefined> = P extends string
79
- ? P extends keyof Themes
80
- ? Themes[P]
81
- : GetParentName<P> extends keyof Themes
82
- ? Themes[GetParentName<P>]
83
- : GetParentName<GetParentName<P>> extends keyof Themes
84
- ? Themes[GetParentName<GetParentName<P>>]
85
- : GetParentName<GetParentName<GetParentName<P>>> extends keyof Themes
86
- ? Themes[GetParentName<GetParentName<GetParentName<P>>>]
87
- : never
88
- : never
89
-
90
- type GetGeneratedTheme<TD extends any, S extends ThemeBuilderState> = TD extends {
91
- theme: infer T
92
- }
93
- ? T
94
- : TD extends { parent: infer P }
95
- ? // ? GetGeneratedThemeFromTemplate<GetParentTheme<P, S['templates']>>
96
- GetGeneratedTheme<GetParentTheme<P, S['themes']>, S>
97
- : TD extends { template: infer T }
98
- ? T extends keyof S['templates']
99
- ? GetGeneratedThemeFromTemplate<S['templates'][T]>
100
- : TD
101
- : TD
102
-
103
- type ThemeBuilderBuildResult<S extends ThemeBuilderState> = {
104
- [Key in keyof S['themes']]: GetGeneratedTheme<S['themes'][Key], S>
105
- }
106
-
107
- type GetParentName<N extends string> =
108
- N extends `${infer A}_${infer B}_${infer C}_${infer D}_${string}`
109
- ? `${A}_${B}_${C}_${D}`
110
- : N extends `${infer A}_${infer B}_${infer C}_${string}`
111
- ? `${A}_${B}_${C}`
112
- : N extends `${infer A}_${infer B}_${string}`
113
- ? `${A}_${B}`
114
- : N extends `${infer A}_${string}`
115
- ? `${A}`
116
- : never
117
-
118
- export class ThemeBuilder<State extends ThemeBuilderState> {
119
- constructor(public state: State) {}
120
-
121
- addPalettes<const P extends PaletteDefinitions>(palettes: P) {
122
- this.state.palettes = {
123
- // as {} prevents generic string key merge messing up types
124
- ...(this.state.palettes as {}),
125
- ...palettes,
126
- }
127
- return this as any as ThemeBuilder<
128
- State & {
129
- palettes: P
130
- }
131
- >
132
- }
133
-
134
- addTemplates<const T extends TemplateDefinitions>(templates: T) {
135
- this.state.templates = {
136
- // as {} prevents generic string key merge messing up types
137
- ...(this.state.templates as {}),
138
- ...templates,
139
- }
140
- return this as any as ThemeBuilder<
141
- State & {
142
- templates: T
143
- }
144
- >
145
- }
146
-
147
- addMasks<const M extends MaskDefinitions>(masks: M) {
148
- this.state.masks = {
149
- // as {} prevents generic string key merge messing up types
150
- ...(this.state.masks as {}),
151
- ...(objectFromEntries(
152
- objectEntries(masks).map(([key, val]) => [key, createMask(val)])
153
- ) as M),
154
- }
155
- return this as any as ThemeBuilder<
156
- State & {
157
- masks: M
158
- }
159
- >
160
- }
161
-
162
- addThemes<const T extends ThemeDefinitions<ObjectStringKeys<State['masks']>>>(
163
- themes: T
164
- ) {
165
- this.state.themes = {
166
- // as {} prevents generic string key merge messing up types
167
- ...(this.state.themes as {}),
168
- ...themes,
169
- }
170
- return this as any as ThemeBuilder<
171
- State & {
172
- themes: T
173
- }
174
- >
175
- }
176
-
177
- addChildThemes<
178
- CTD extends Narrow<ThemeDefinitions<ObjectStringKeys<State['masks']>>>,
179
- const AvoidNestingWithin extends string[] = []
180
- >(
181
- childThemeDefinition: CTD,
182
- options?: {
183
- avoidNestingWithin?: AvoidNestingWithin
184
- }
185
- ) {
186
- const currentThemes = this.state.themes as State['themes']
187
- if (!currentThemes) {
188
- throw new Error(
189
- `No themes defined yet, use addThemes first to set your base themes`
190
- )
191
- }
192
-
193
- // AvoidNestingWithin[number] exclude isn't working here...
194
- type CurrentNames = Exclude<keyof typeof currentThemes, symbol | number>
195
- type ChildNames = Exclude<keyof CTD, symbol | number>
196
-
197
- const currentThemeNames = objectKeys(currentThemes) as CurrentNames[]
198
- const incomingThemeNames = objectKeys(childThemeDefinition) as ChildNames[]
199
-
200
- const namesWithDefinitions = currentThemeNames.flatMap((prefix) => {
201
- if (options?.avoidNestingWithin) {
202
- if (
203
- options.avoidNestingWithin.some(
204
- (avoidName) => prefix.startsWith(avoidName) || prefix.endsWith(avoidName)
205
- )
206
- ) {
207
- return []
208
- }
209
- }
210
-
211
- return incomingThemeNames.map((subName) => {
212
- const fullName = `${prefix}_${subName}`
213
- const definition = childThemeDefinition[subName]
214
- return [fullName, definition] as const
215
- })
216
- })
217
-
218
- type ChildThemes = {
219
- [key in `${CurrentNames}_${ChildNames}`]: CTD & {
220
- parent: GetParentName<key>
221
- }
222
- }
223
-
224
- const childThemes = objectFromEntries(namesWithDefinitions) as ChildThemes
225
-
226
- const next = {
227
- // as {} prevents generic string key merge messing up types
228
- ...(this.state.themes as {}),
229
- ...childThemes,
230
- }
231
-
232
- // @ts-ignore
233
- this.state.themes = next
234
-
235
- return this as any as ThemeBuilder<
236
- State & {
237
- themes: ChildThemes
238
- }
239
- >
240
- }
241
-
242
- build(): ThemeBuilderBuildResult<State> {
243
- if (!this.state.themes) {
244
- return {} as any
245
- }
246
-
247
- const out = {}
248
- const maskedThemes: {
249
- parentName: string
250
- themeName: string
251
- mask: ThemeUsingMask
252
- }[] = []
253
-
254
- for (const themeName in this.state.themes) {
255
- const nameParts = themeName.split('_')
256
- const parentName = nameParts.slice(0, nameParts.length - 1).join('_')
257
-
258
- const definitions = this.state.themes[themeName]
259
- const themeDefinition = Array.isArray(definitions)
260
- ? (() => {
261
- const found = definitions.find((d) => parentName.startsWith(d.parent!))
262
- if (!found) {
263
- throw new Error(`No parent for ${themeName}: ${parentName}`)
264
- }
265
- return found
266
- })()
267
- : definitions
268
-
269
- if ('theme' in themeDefinition) {
270
- out[themeName] = themeDefinition.theme
271
- } else if ('mask' in themeDefinition) {
272
- maskedThemes.push({ parentName, themeName, mask: themeDefinition })
273
- } else {
274
- const {
275
- palette: paletteName,
276
- template: templateName,
277
- ...options
278
- } = themeDefinition
279
-
280
- if (!this.state.palettes) {
281
- throw new Error(
282
- `No palettes defined for theme with palette expected: ${themeName}`
283
- )
284
- }
285
-
286
- let palette = this.state.palettes[paletteName]
287
-
288
- if (!palette) {
289
- const fullPaletteName = `${parentName}_${paletteName}`
290
- palette = this.state.palettes[fullPaletteName]
291
- // try using the prefix
292
- }
293
-
294
- if (!palette) {
295
- throw new Error(`No palette for theme ${themeName}: ${paletteName}`)
296
- }
297
-
298
- const template = this.state.templates?.[templateName]
299
- if (!template) {
300
- throw new Error(`No template for theme ${themeName}: ${templateName}`)
301
- }
302
-
303
- out[themeName] = createTheme(palette, template, options, themeName)
304
- }
305
- }
306
-
307
- for (const { mask, themeName, parentName } of maskedThemes) {
308
- const parent = out[parentName]
309
-
310
- if (!parent) {
311
- throw new Error(
312
- `No parent theme found with name ${parentName} for theme ${themeName} to use as a mask target`
313
- )
314
- }
315
-
316
- const { mask: maskName, ...options } = mask
317
- const maskFunction = this.state.masks?.[maskName]
318
-
319
- if (!maskFunction) {
320
- throw new Error(`No mask ${maskFunction}`)
321
- }
322
-
323
- out[themeName] = applyMask(
324
- parent,
325
- maskFunction as any,
326
- options,
327
- parentName,
328
- themeName
329
- )
330
- }
331
-
332
- return out as any
333
- }
334
- }
335
-
336
- export function createThemeBuilder() {
337
- return new ThemeBuilder({})
338
- }
339
-
340
- // // test types
341
- // let x = createThemeBuilder()
342
- // .addMasks({
343
- // test: {
344
- // name: 'mask',
345
- // mask: (() => {}) as any,
346
- // },
347
- // })
348
- // .addThemes({
349
- // light: {
350
- // template: '',
351
- // palette: '',
352
- // },
353
- // dark: {
354
- // mask: 'test',
355
- // },
356
- // })
357
- // .addChildThemes({
358
- // List: [
359
- // {
360
- // parent: '',
361
- // mask: 'test',
362
- // },
363
- // ],
364
- // })
365
-
366
- // x
367
-
368
- // x.state.themes
369
- // x.state.masks
370
-
371
- // let y = x.addChildThemes({
372
- // blue: {
373
- // mask: 'ok',
374
- // },
375
- // })
@@ -1 +0,0 @@
1
- export * from '../src/ThemeBuilder'
@@ -1 +0,0 @@
1
- Object.assign(module.exports, require('../dist/cjs/ThemeBuilder'))