zova-module-a-style 5.0.47 → 5.1.1

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.
@@ -0,0 +1,10 @@
1
+ import type { IDecoratorCssOptions } from 'zova-module-a-style';
2
+ import { BeanBase, useComputed } from 'zova';
3
+ import { Css } from 'zova-module-a-style';
4
+
5
+ export interface ICssOptions<%=argv.beanNameCapitalize%> extends IDecoratorCssOptions {}
6
+
7
+ @Css<ICssOptions<%=argv.beanNameCapitalize%>>()
8
+ export class Css<%=argv.beanNameCapitalize%> extends BeanBase {
9
+ protected async __init__() {}
10
+ }
@@ -0,0 +1,14 @@
1
+ import type { IDecoratorThemeOptions, IThemeApplyParams, IThemeApplyResult, IThemeBase, ThemeToken } from 'zova-module-a-style';
2
+ import { BeanThemeBase, Theme } from 'zova-module-a-style';
3
+
4
+ export interface IThemeOptions<%=argv.beanNameCapitalize%> extends IDecoratorThemeOptions {}
5
+
6
+ @Theme<IThemeOptions<%=argv.beanNameCapitalize%>>()
7
+ export class Theme<%=argv.beanNameCapitalize%> extends BeanThemeBase implements IThemeBase {
8
+ async apply({ name, dark }: IThemeApplyParams): Promise<IThemeApplyResult> {
9
+ const token: ThemeToken = {};
10
+ return {
11
+ token: this.mergeOptionsToken({ name, dark }, token),
12
+ };
13
+ }
14
+ }
@@ -0,0 +1,7 @@
1
+ import { BeanBase } from 'zova';
2
+ import { Meta } from 'zova-module-a-meta';
3
+
4
+ @Meta()
5
+ export class Meta<%=argv.beanNameCapitalize%> extends BeanBase {
6
+ protected async __init__() {}
7
+ }
package/dist/index.js ADDED
@@ -0,0 +1,292 @@
1
+ import { BeanBase, BeanInfo, BeanScopeBase, BeanSimple, SymbolBeanFullName, UseScope, beanFullNameFromOnionName, cast, createBeanDecorator, deepExtend, useComputed } from "zova";
2
+ import { Bean, Scope } from "zova-module-a-bean";
3
+ import { BeanModelBase } from "zova-module-a-model";
4
+ import { createTypeStyle, cssRaw, cssRule, style } from "typestyle";
5
+ //#region src/bean/bean.theme.ts
6
+ var _dec$1, _dec2$1, _dec3, _dec4, _class$1, _class2, _descriptor;
7
+ function _initializerDefineProperty(e, i, r, l) {
8
+ r && Object.defineProperty(e, i, {
9
+ enumerable: r.enumerable,
10
+ configurable: r.configurable,
11
+ writable: r.writable,
12
+ value: r.initializer ? r.initializer.call(l) : void 0
13
+ });
14
+ }
15
+ function _applyDecoratedDescriptor(i, e, r, n, l) {
16
+ var a = {};
17
+ return Object.keys(n).forEach(function(i) {
18
+ a[i] = n[i];
19
+ }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function(r, n) {
20
+ return n(i, e, r) || r;
21
+ }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
22
+ }
23
+ var BeanTheme = (_dec$1 = Bean(), _dec2$1 = BeanInfo({ module: "a-style" }), _dec3 = UseScope("a-ssr"), _dec4 = Reflect.metadata("design:type", typeof ScopeModuleASsr === "undefined" ? Object : ScopeModuleASsr), _dec$1(_class$1 = _dec2$1(_class$1 = (_class2 = class BeanTheme extends BeanModelBase {
24
+ constructor(...args) {
25
+ super(...args);
26
+ this.name = void 0;
27
+ this.darkMode = void 0;
28
+ this._dark = void 0;
29
+ this.token = void 0;
30
+ this._mediaDark = void 0;
31
+ this._onMediaDarkChange = void 0;
32
+ _initializerDefineProperty(this, "$$scopeSsr", _descriptor, this);
33
+ }
34
+ get dark() {
35
+ return this._dark;
36
+ }
37
+ async __init__() {
38
+ const cookieTheme = this.$$scopeSsr.config.cookieTheme;
39
+ const cookieThemeDarkDefault = this.$$scopeSsr.config.cookieThemeDarkDefault;
40
+ this.name = this.$useState(cookieTheme ? "cookie" : "local", {
41
+ queryKey: ["themename"],
42
+ meta: {
43
+ persister: { maxAge: this.scope.config.model.themename.persister.maxAge },
44
+ defaultData: this.scope.config.defaultTheme
45
+ }
46
+ });
47
+ this.darkMode = this.$useState(cookieTheme ? "cookie" : "local", {
48
+ queryKey: ["themedark"],
49
+ meta: {
50
+ persister: {
51
+ maxAge: this.scope.config.model.themename.persister.maxAge,
52
+ deserialize: (value, deserializeDefault) => {
53
+ if (cookieTheme && value === "auto") value = cookieThemeDarkDefault;
54
+ return deserializeDefault(value);
55
+ }
56
+ },
57
+ defaultData: cookieTheme ? cookieThemeDarkDefault : "auto"
58
+ }
59
+ });
60
+ this._updateDark();
61
+ this.$watch(() => this.darkMode, () => {
62
+ this._updateDark();
63
+ });
64
+ if (process.env.CLIENT) this.$watch([() => this.name, () => this._dark], () => {
65
+ this._applyTheme();
66
+ });
67
+ await this._applyThemeWrapper();
68
+ }
69
+ __dispose__() {
70
+ this._listenMediaDarkChange(false);
71
+ }
72
+ _updateDark() {
73
+ this._dark = this._getDarkFromDarkMode(this.darkMode);
74
+ }
75
+ async _applyThemeWrapper() {
76
+ await this._applyTheme();
77
+ if (process.env.SERVER && !this.$$scopeSsr.config.cookieTheme) {
78
+ this.toggleDark();
79
+ await this._applyTheme();
80
+ }
81
+ }
82
+ async _applyTheme() {
83
+ const name = this.name;
84
+ const dark = this._dark;
85
+ const theme = await this._loadThemeBean(name);
86
+ if (!theme) {
87
+ this.name = this.scope.config.defaultTheme;
88
+ await this._applyTheme();
89
+ return;
90
+ }
91
+ const res = await theme.apply({
92
+ name,
93
+ dark
94
+ });
95
+ this.token = cast(res).token;
96
+ const handler = res.handler ?? this.scope.config.defaultThemeHandler;
97
+ if (handler) await (await this.bean._getBean(beanFullNameFromOnionName(handler, "meta"), true)).apply({
98
+ name,
99
+ dark,
100
+ token: this.token
101
+ });
102
+ }
103
+ async _loadThemeBean(name) {
104
+ const parts = name.split(":");
105
+ if (parts.length === 1) throw new Error(`invalid theme name: ${name}`);
106
+ const moduleName = parts[0];
107
+ if (!this.app.meta.module.exists(moduleName)) return;
108
+ return await this.bean._getBean(beanFullNameFromOnionName(name, "theme"), true);
109
+ }
110
+ toggleDark() {
111
+ this.darkMode = !this._dark;
112
+ this._updateDark();
113
+ }
114
+ _getDarkFromDarkMode(mode) {
115
+ if (mode === void 0) mode = "auto";
116
+ if (mode === "auto") {
117
+ this._listenMediaDarkChange(true);
118
+ return !!this._mediaDark?.matches;
119
+ } else {
120
+ this._listenMediaDarkChange(false);
121
+ return mode;
122
+ }
123
+ }
124
+ _listenMediaDarkChange(listen) {
125
+ if (process.env.SERVER) return;
126
+ if (listen) {
127
+ if (!this._mediaDark) {
128
+ this._mediaDark = window.matchMedia("(prefers-color-scheme: dark)");
129
+ this._onMediaDarkChange = async () => {
130
+ this._updateDark();
131
+ this._applyTheme();
132
+ };
133
+ this._mediaDark.addEventListener("change", this._onMediaDarkChange);
134
+ }
135
+ } else if (this._mediaDark) {
136
+ this._mediaDark.removeEventListener("change", this._onMediaDarkChange);
137
+ this._onMediaDarkChange = void 0;
138
+ this._mediaDark = void 0;
139
+ }
140
+ }
141
+ }, _descriptor = _applyDecoratedDescriptor(_class2.prototype, "$$scopeSsr", [_dec3, _dec4], {
142
+ configurable: true,
143
+ enumerable: true,
144
+ writable: true,
145
+ initializer: null
146
+ }), _class2)) || _class$1) || _class$1);
147
+ //#endregion
148
+ //#region src/config/config.ts
149
+ var config = (_sys) => {
150
+ return {
151
+ defaultCss: "home-base:default",
152
+ defaultTheme: "home-base:default",
153
+ defaultThemeHandler: "",
154
+ model: { themename: { persister: { maxAge: Infinity } } }
155
+ };
156
+ };
157
+ //#endregion
158
+ //#region src/.metadata/this.ts
159
+ var __ThisModule__ = "a-style";
160
+ //#endregion
161
+ //#region src/monkey.ts
162
+ var Monkey = class extends BeanSimple {
163
+ constructor(...args) {
164
+ super(...args);
165
+ this._beanTheme = void 0;
166
+ this._beanCssDefault = void 0;
167
+ this._styleInstance = void 0;
168
+ }
169
+ async appInitialize() {
170
+ if (process.env.SERVER) {
171
+ this._styleInstance = createTypeStyle();
172
+ this.ctx.meta.$ssr.context.onRendered((err) => {
173
+ if (err) return;
174
+ const styles = this._styleInstance.getStyles();
175
+ this.ctx.meta.$ssr.context._meta.endingHeadTags += `<style id="styles-target">${styles}</style>`;
176
+ });
177
+ }
178
+ if (process.env.CLIENT && this.ctx.meta.$ssr.isRuntimeSsrPreHydration) {
179
+ this._styleInstance = createTypeStyle();
180
+ this.ctx.meta.$ssr.onHydrated(() => {
181
+ this._styleInstance.setStylesTarget(document.getElementById("styles-target"));
182
+ });
183
+ }
184
+ }
185
+ async appInitialized() {
186
+ this._beanTheme = await this.bean._getBean(BeanTheme, true);
187
+ const scope = await this.bean.getScope(__ThisModule__);
188
+ this._beanCssDefault = await this.bean._getBean(beanFullNameFromOnionName(scope.config.defaultCss, "css"), true);
189
+ }
190
+ async beanInit(bean, beanInstance) {
191
+ const self = this;
192
+ bean.defineProperty(beanInstance, "$style", {
193
+ enumerable: false,
194
+ configurable: true,
195
+ get() {
196
+ return function(props, ...args) {
197
+ return self._patchStyle(beanInstance, props, ...args);
198
+ };
199
+ }
200
+ });
201
+ bean.defineProperty(beanInstance, "$cssRule", {
202
+ enumerable: false,
203
+ configurable: true,
204
+ get() {
205
+ return function(selector, ...objects) {
206
+ return self._patchCssRule(beanInstance, selector, ...objects);
207
+ };
208
+ }
209
+ });
210
+ bean.defineProperty(beanInstance, "$cssRaw", {
211
+ enumerable: false,
212
+ configurable: true,
213
+ get() {
214
+ return function(mustBeValidCSS) {
215
+ return self._patchCssRaw(beanInstance, mustBeValidCSS);
216
+ };
217
+ }
218
+ });
219
+ bean.defineProperty(beanInstance, "$css", {
220
+ enumerable: false,
221
+ configurable: true,
222
+ get() {
223
+ return self._beanCssDefault;
224
+ }
225
+ });
226
+ bean.defineProperty(beanInstance, "$theme", {
227
+ enumerable: false,
228
+ configurable: true,
229
+ get() {
230
+ return self._beanTheme;
231
+ }
232
+ });
233
+ bean.defineProperty(beanInstance, "$token", {
234
+ enumerable: false,
235
+ configurable: true,
236
+ get() {
237
+ return useComputed(() => self._beanTheme.token);
238
+ }
239
+ });
240
+ }
241
+ _patchStyle(beanInstance, props, ...args) {
242
+ if (process.env.DEV) {
243
+ if (props && typeof props === "object") props = Object.assign({ $debugName: beanInstance[SymbolBeanFullName].replaceAll(".", "_") }, props);
244
+ }
245
+ if (this._styleInstance) return this._styleInstance.style(props, ...args);
246
+ else return style(props, ...args);
247
+ }
248
+ _patchCssRule(_beanInstance, selector, ...objects) {
249
+ if (this._styleInstance) return this._styleInstance.cssRule(selector, ...objects);
250
+ else return cssRule(selector, ...objects);
251
+ }
252
+ _patchCssRaw(_beanInstance, mustBeValidCSS) {
253
+ if (this._styleInstance) return this._styleInstance.cssRaw(mustBeValidCSS);
254
+ else return cssRaw(mustBeValidCSS);
255
+ }
256
+ };
257
+ //#endregion
258
+ //#region src/.metadata/index.ts
259
+ /** monkey: end */
260
+ /** scope: begin */
261
+ var _dec, _dec2, _class;
262
+ var ScopeModuleAStyle = (_dec = Scope(), _dec2 = BeanInfo({ module: "a-style" }), _dec(_class = _dec2(_class = class ScopeModuleAStyle extends BeanScopeBase {}) || _class) || _class);
263
+ /** scope: end */
264
+ //#endregion
265
+ //#region src/lib/style.ts
266
+ function Css(options) {
267
+ return createBeanDecorator("css", "app", true, options);
268
+ }
269
+ function Theme(options) {
270
+ return createBeanDecorator("theme", "app", true, options);
271
+ }
272
+ //#endregion
273
+ //#region src/lib/theme.ts
274
+ function $getThemeName(themeName) {
275
+ return themeName;
276
+ }
277
+ //#endregion
278
+ //#region src/lib/themeBase.ts
279
+ var BeanThemeBase = class extends BeanBase {
280
+ getOptionsToken(params) {
281
+ return this.$onionOptions.token?.(params);
282
+ }
283
+ mergeOptionsToken(params, token) {
284
+ const optionsToken = this.getOptionsToken(params);
285
+ if (optionsToken) token = deepExtend(token, optionsToken);
286
+ return token;
287
+ }
288
+ };
289
+ //#endregion
290
+ export { $getThemeName, BeanTheme, BeanThemeBase, Css, Monkey, ScopeModuleAStyle, Theme, config };
291
+
292
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/bean/bean.theme.ts","../src/config/config.ts","../src/.metadata/this.ts","../src/monkey.ts","../src/.metadata/index.ts","../src/lib/style.ts","../src/lib/theme.ts","../src/lib/themeBase.ts"],"sourcesContent":["import { beanFullNameFromOnionName, cast, UseScope } from 'zova';\nimport { Bean } from 'zova-module-a-bean';\nimport { BeanModelBase } from 'zova-module-a-model';\nimport { ScopeModuleASsr } from 'zova-module-a-ssr';\n\nimport type { IThemeBase, IThemeHandler, IThemeRecord } from '../types/index.js';\n\nexport type ThemeDarkMode = 'auto' | boolean;\n\n@Bean()\nexport class BeanTheme extends BeanModelBase {\n name: keyof IThemeRecord;\n darkMode: ThemeDarkMode; // auto/true/false\n\n private _dark: boolean;\n get dark() {\n return this._dark;\n }\n\n token: unknown;\n private _mediaDark?: MediaQueryList;\n private _onMediaDarkChange?;\n\n @UseScope()\n $$scopeSsr: ScopeModuleASsr;\n\n protected async __init__() {\n const cookieTheme = this.$$scopeSsr.config.cookieTheme;\n const cookieThemeDarkDefault = this.$$scopeSsr.config.cookieThemeDarkDefault;\n // support admin\n this.name = this.$useState(cookieTheme ? 'cookie' : 'local', {\n queryKey: ['themename'],\n meta: {\n persister: {\n maxAge: this.scope.config.model.themename.persister.maxAge,\n },\n defaultData: this.scope.config.defaultTheme,\n },\n });\n this.darkMode = this.$useState(cookieTheme ? 'cookie' : 'local', {\n queryKey: ['themedark'],\n meta: {\n persister: {\n maxAge: this.scope.config.model.themename.persister.maxAge,\n deserialize: (value, deserializeDefault) => {\n if (cookieTheme && value === 'auto') value = cookieThemeDarkDefault;\n return deserializeDefault(value);\n },\n },\n defaultData: cookieTheme ? cookieThemeDarkDefault : 'auto',\n },\n });\n this._updateDark();\n\n this.$watch(\n () => this.darkMode,\n () => {\n this._updateDark();\n },\n );\n\n if (process.env.CLIENT) {\n this.$watch([() => this.name, () => this._dark], () => {\n this._applyTheme();\n });\n }\n\n // not use watch.immediate for await done\n await this._applyThemeWrapper();\n }\n\n protected __dispose__() {\n this._listenMediaDarkChange(false);\n }\n\n private _updateDark() {\n this._dark = this._getDarkFromDarkMode(this.darkMode);\n }\n\n async _applyThemeWrapper() {\n await this._applyTheme();\n if (process.env.SERVER && !this.$$scopeSsr.config.cookieTheme) {\n this.toggleDark();\n await this._applyTheme();\n }\n }\n\n async _applyTheme() {\n const name = this.name;\n const dark = this._dark;\n const theme = await this._loadThemeBean(name);\n if (!theme) {\n this.name = this.scope.config.defaultTheme;\n await this._applyTheme();\n return;\n }\n const res = await theme.apply({ name, dark });\n this.token = cast(res).token;\n const handler = res.handler ?? this.scope.config.defaultThemeHandler;\n if (handler) {\n const themeHandler = (await this.bean._getBean(beanFullNameFromOnionName(handler, 'meta'), true)) as unknown as IThemeHandler;\n await themeHandler.apply({ name, dark, token: this.token } as any);\n }\n }\n\n async _loadThemeBean(name: keyof IThemeRecord): Promise<IThemeBase | undefined> {\n const parts = name.split(':');\n if (parts.length === 1) {\n throw new Error(`invalid theme name: ${name}`);\n }\n const moduleName = parts[0];\n if (!this.app.meta.module.exists(moduleName)) return;\n return (await this.bean._getBean(beanFullNameFromOnionName(name, 'theme'), true)) as IThemeBase;\n }\n\n toggleDark() {\n this.darkMode = !this._dark;\n this._updateDark(); // immediate\n }\n\n _getDarkFromDarkMode(mode?: ThemeDarkMode) {\n if (mode === undefined) mode = 'auto';\n if (mode === 'auto') {\n this._listenMediaDarkChange(true);\n return !!this._mediaDark?.matches;\n } else {\n this._listenMediaDarkChange(false);\n return mode;\n }\n }\n\n _listenMediaDarkChange(listen: boolean) {\n if (process.env.SERVER) return;\n if (listen) {\n if (!this._mediaDark) {\n this._mediaDark = window.matchMedia('(prefers-color-scheme: dark)');\n this._onMediaDarkChange = async () => {\n this._updateDark();\n this._applyTheme();\n };\n this._mediaDark.addEventListener('change', this._onMediaDarkChange);\n }\n } else {\n if (this._mediaDark) {\n this._mediaDark.removeEventListener('change', this._onMediaDarkChange);\n this._onMediaDarkChange = undefined;\n this._mediaDark = undefined;\n }\n }\n }\n}\n","import type { ZovaSys } from 'zova';\nimport type { TypeMetaRecordSelectorSpecificNameKeys } from 'zova-module-a-meta';\n\nimport type { ICssRecord } from '../types/css.js';\nimport type { IThemeRecord } from '../types/theme.js';\n\nexport const config = (_sys: ZovaSys) => {\n return {\n defaultCss: 'home-base:default' as keyof ICssRecord,\n defaultTheme: 'home-base:default' as keyof IThemeRecord,\n defaultThemeHandler: '' as TypeMetaRecordSelectorSpecificNameKeys<'themeHandler'>,\n model: {\n themename: {\n persister: {\n maxAge: Infinity,\n },\n },\n },\n };\n};\n","export const __ThisModule__ = 'a-style';\nexport { ScopeModuleAStyle as ScopeModule } from './index.js';\n","import type { TypeStyle } from 'typestyle';\nimport type { NestedCSSProperties } from 'typestyle/lib/types.js';\nimport type { BeanBase, BeanContainer, IMonkeyAppInitialize, IMonkeyAppInitialized, IMonkeyBeanInit } from 'zova';\n\nimport { createTypeStyle, cssRaw, cssRule, style } from 'typestyle';\nimport { beanFullNameFromOnionName, BeanSimple, SymbolBeanFullName, useComputed } from 'zova';\n\nimport type { ScopeModule } from './.metadata/this.js';\n\nimport { __ThisModule__ } from './.metadata/this.js';\nimport { BeanTheme } from './bean/bean.theme.js';\n\nexport class Monkey extends BeanSimple implements IMonkeyAppInitialize, IMonkeyAppInitialized, IMonkeyBeanInit {\n private _beanTheme: BeanTheme;\n private _beanCssDefault: any;\n private _styleInstance: TypeStyle;\n\n async appInitialize() {\n if (process.env.SERVER) {\n this._styleInstance = createTypeStyle();\n this.ctx.meta.$ssr.context.onRendered((err?: Error) => {\n if (err) return;\n const styles = this._styleInstance.getStyles();\n this.ctx.meta.$ssr.context._meta.endingHeadTags += `<style id=\"styles-target\">${styles}</style>`;\n });\n }\n if (process.env.CLIENT && this.ctx.meta.$ssr.isRuntimeSsrPreHydration) {\n this._styleInstance = createTypeStyle();\n this.ctx.meta.$ssr.onHydrated(() => {\n this._styleInstance.setStylesTarget(document.getElementById('styles-target')!);\n });\n }\n }\n\n async appInitialized() {\n // theme\n this._beanTheme = await this.bean._getBean(BeanTheme, true);\n // css default\n const scope: ScopeModule = await this.bean.getScope(__ThisModule__);\n this._beanCssDefault = await this.bean._getBean(beanFullNameFromOnionName(scope.config.defaultCss, 'css'), true);\n }\n\n async beanInit(bean: BeanContainer, beanInstance: BeanBase) {\n const self = this;\n bean.defineProperty(beanInstance, '$style', {\n enumerable: false,\n configurable: true,\n get() {\n return function (props, ...args) {\n return self._patchStyle(beanInstance, props, ...args);\n };\n },\n });\n bean.defineProperty(beanInstance, '$cssRule', {\n enumerable: false,\n configurable: true,\n get() {\n return function (selector: string, ...objects: NestedCSSProperties[]) {\n return self._patchCssRule(beanInstance, selector, ...objects);\n };\n },\n });\n bean.defineProperty(beanInstance, '$cssRaw', {\n enumerable: false,\n configurable: true,\n get() {\n return function (mustBeValidCSS: string) {\n return self._patchCssRaw(beanInstance, mustBeValidCSS);\n };\n },\n });\n bean.defineProperty(beanInstance, '$css', {\n enumerable: false,\n configurable: true,\n get() {\n return self._beanCssDefault;\n },\n });\n bean.defineProperty(beanInstance, '$theme', {\n enumerable: false,\n configurable: true,\n get() {\n return self._beanTheme;\n },\n });\n bean.defineProperty(beanInstance, '$token', {\n enumerable: false,\n configurable: true,\n get() {\n return useComputed(() => self._beanTheme.token);\n },\n });\n }\n\n _patchStyle(beanInstance: BeanBase, props, ...args) {\n if (process.env.DEV) {\n if (props && typeof props === 'object') {\n props = Object.assign({ $debugName: beanInstance[SymbolBeanFullName].replaceAll('.', '_') }, props);\n }\n }\n if (this._styleInstance) {\n return this._styleInstance.style(props, ...args);\n } else {\n return style(props, ...args);\n }\n }\n\n _patchCssRule(_beanInstance: BeanBase, selector: string, ...objects: NestedCSSProperties[]) {\n if (this._styleInstance) {\n return this._styleInstance.cssRule(selector, ...objects);\n } else {\n return cssRule(selector, ...objects);\n }\n }\n\n _patchCssRaw(_beanInstance: BeanBase, mustBeValidCSS: string) {\n if (this._styleInstance) {\n return this._styleInstance.cssRaw(mustBeValidCSS);\n } else {\n return cssRaw(mustBeValidCSS);\n }\n }\n}\n","// eslint-disable\n/** bean: begin */\nexport * from '../bean/bean.theme.js';\n\nimport 'zova';\ndeclare module 'zova' {\n \n \n}\ndeclare module 'zova-module-a-style' {\n \n export interface BeanTheme {\n /** @internal */\n get scope(): ScopeModuleAStyle;\n }\n\n export interface BeanTheme {\n get $beanFullName(): 'a-style.bean.theme';\n get $onionName(): 'a-style:theme';\n \n } \n}\n/** bean: end */\n/** bean: begin */\nimport { BeanTheme } from '../bean/bean.theme.js';\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanRecordGeneral {\n 'a-style.bean.theme': BeanTheme;\n }\n}\n/** bean: end */\n/** config: begin */\nexport * from '../config/config.js';\nimport { config } from '../config/config.js';\n/** config: end */\n/** monkey: begin */\nexport * from '../monkey.js';\n/** monkey: end */\n/** scope: begin */\nimport { BeanScopeBase, type BeanScopeUtil, TypeModuleConfig } from 'zova';\nimport { Scope } from 'zova-module-a-bean';\n\n@Scope()\nexport class ScopeModuleAStyle extends BeanScopeBase {}\n\nexport interface ScopeModuleAStyle {\n util: BeanScopeUtil;\nconfig: TypeModuleConfig<typeof config>;\n}\n\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanScopeRecord {\n 'a-style': ScopeModuleAStyle;\n }\n \n export interface IBeanScopeConfig {\n 'a-style': ReturnType<typeof config>;\n }\n\n \n\n \n}\n \n/** scope: end */\n","import { createBeanDecorator } from 'zova';\n\nimport type { IDecoratorCssOptions } from '../types/css.js';\nimport type { IDecoratorThemeOptions } from '../types/theme.js';\n\nexport function Css<T extends IDecoratorCssOptions>(options?: T): ClassDecorator {\n return createBeanDecorator('css', 'app', true, options);\n}\n\nexport function Theme<T extends IDecoratorThemeOptions>(options?: T): ClassDecorator {\n return createBeanDecorator('theme', 'app', true, options);\n}\n","import type { IThemeRecord } from '../types/theme.js';\n\nexport function $getThemeName<K extends keyof IThemeRecord>(themeName: K): K {\n return themeName;\n}\n","import { BeanBase, deepExtend } from 'zova';\n\nimport type { IDecoratorThemeOptions, IThemeApplyParams, ThemeToken } from '../types/theme.js';\n\nexport class BeanThemeBase extends BeanBase {\n protected getOptionsToken(params: IThemeApplyParams) {\n const options = this.$onionOptions as IDecoratorThemeOptions;\n return options.token?.(params);\n }\n\n protected mergeOptionsToken(params: IThemeApplyParams, token: ThemeToken) {\n const optionsToken = this.getOptionsToken(params);\n if (optionsToken) {\n token = deepExtend(token, optionsToken);\n }\n return token;\n }\n}\n"],"mappings":";;;;;AAAA,IAAA,QAAS,SAAA,OAAA,OAAA,UAA2B,SAAM;AAC1C,SAAS,2BAA2B,GAAA,GAAK,GAAA,GAAA;AAAA,MAAA,OAAA,eAAA,GAAA,GAAA;EAAA,YAAA,EAAA;EAAA,cAAA,EAAA;EAAA,UAAA,EAAA;EAAA,OAAA,EAAA,cAAA,EAAA,YAAA,KAAA,EAAA,GAAA,KAAA;EAAA,CAAA;;AACzC,SAAS,0BAA0B,GAAC,GAAA,GAAQ,GAAC,GAAK;CAAC,IAAA,IAAA,EAAA;AAAA,QAAA,OAAA,KAAA,EAAA,CAAA,QAAA,SAAA,GAAA;AAAA,IAAA,KAAA,EAAA;GAAA,EAAA,EAAA,aAAA,CAAA,CAAA,EAAA,YAAA,EAAA,eAAA,CAAA,CAAA,EAAA,eAAA,WAAA,KAAA,EAAA,iBAAA,EAAA,WAAA,CAAA,IAAA,IAAA,EAAA,OAAA,CAAA,SAAA,CAAA,OAAA,SAAA,GAAA,GAAA;AAAA,SAAA,EAAA,GAAA,GAAA,EAAA,IAAA;IAAA,EAAA,EAAA,KAAA,KAAA,MAAA,EAAA,gBAAA,EAAA,QAAA,EAAA,cAAA,EAAA,YAAA,KAAA,EAAA,GAAA,KAAA,GAAA,EAAA,cAAA,KAAA,IAAA,KAAA,MAAA,EAAA,eAAA,OAAA,eAAA,GAAA,GAAA,EAAA,EAAA,QAAA;;uDAOlD,QAAK,WACN,CAAA,EAAA,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M,MAAA,SAAA,MAAA,0BAAA,cAAA,GAAA,IAAA,OAAA,IAAA;;;;;ACpBf,QAAO,oBAAO,OAAsB,OAAO,MAAG,QAAU;;;AAGxD,QAAO,oBAAsB,SAAC,OAAA,MAAqB,QAAQ;;;;ACL3D,SAAc,cAAe,WAAS;;;;;;CCEtC,gBAAc,QAAA;AAEd,SAAA,KAAA,cAAa,QAAc,OAAO;;CAEhC,kBAAkB,QAAM,OAAA;EACtB,MAAM,eAAe,KAAE,gBAAO,OAAA;AAChC,MAAA,aAAA,SAAA,WAAA,OAAA,aAAA;AAGE,SAAM"}
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "zova-module-a-style",
3
- "version": "5.0.47",
3
+ "version": "5.1.1",
4
+ "gitHead": "a1b13b06e259e4447ab2f361ec76941810bc4ad7",
5
+ "description": "style",
6
+ "keywords": [
7
+ "Zova Module"
8
+ ],
9
+ "license": "MIT",
10
+ "author": "zhennann",
11
+ "files": [
12
+ "cli",
13
+ "dist",
14
+ "src",
15
+ "icons",
16
+ "assets",
17
+ "rest"
18
+ ],
19
+ "type": "module",
20
+ "exports": {
21
+ ".": {
22
+ "types": [
23
+ "./src/index.ts",
24
+ "./dist/index.d.ts"
25
+ ],
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./*": "./*"
29
+ },
30
+ "scripts": {
31
+ "clean": "rimraf dist tsconfig.build.tsbuildinfo",
32
+ "tsc:publish": "npm run clean && zova :bin:buildModule --sourcemap",
33
+ "prepublishOnly": "npm run tsc:publish",
34
+ "prepack": "clean-package",
35
+ "postpack": "clean-package restore && npm run clean"
36
+ },
37
+ "dependencies": {
38
+ "csx": "^10.0.2",
39
+ "typestyle": "^2.4.0"
40
+ },
4
41
  "title": "a-style",
5
42
  "zovaModule": {
6
43
  "capabilities": {
@@ -13,53 +50,33 @@
13
50
  "csx": true,
14
51
  "typestyle": true
15
52
  },
53
+ "onions": {
54
+ "css": {
55
+ "optionsGlobalInterfaceName": "IDecoratorCssOptions",
56
+ "optionsGlobalInterfaceFrom": "zova-module-a-style",
57
+ "boilerplate": "css/boilerplate"
58
+ },
59
+ "theme": {
60
+ "optionsGlobalInterfaceName": "IDecoratorThemeOptions",
61
+ "optionsGlobalInterfaceFrom": "zova-module-a-style",
62
+ "boilerplate": "theme/boilerplate"
63
+ }
64
+ },
65
+ "metas": {
66
+ "themeHandler": {
67
+ "boilerplate": "themeHandler/boilerplate"
68
+ }
69
+ },
16
70
  "bundle": {
17
71
  "vendors": [
18
72
  {
19
73
  "match": [
20
- "csx"
21
- ],
22
- "output": "typestyle"
23
- },
24
- {
25
- "match": [
74
+ "csx",
26
75
  "typestyle"
27
76
  ],
28
77
  "output": "typestyle"
29
78
  }
30
79
  ]
31
80
  }
32
- },
33
- "type": "module",
34
- "exports": {
35
- ".": {
36
- "types": [
37
- "./src/index.ts",
38
- "./dist/index.d.ts"
39
- ],
40
- "import": "./src/index.ts",
41
- "default": "./dist/index.js"
42
- },
43
- "./*": "./*"
44
- },
45
- "description": "style",
46
- "keywords": [
47
- "Zova Module"
48
- ],
49
- "author": "zhennann",
50
- "license": "MIT",
51
- "files": [
52
- "dist",
53
- "src"
54
- ],
55
- "scripts": {
56
- "clean": "tsc -b --clean",
57
- "tsc:publish": "npm run clean && tsc -b",
58
- "_prepublishOnly": "npm run tsc:publish"
59
- },
60
- "dependencies": {
61
- "csx": "^10.0.2",
62
- "typestyle": "^2.4.0"
63
- },
64
- "gitHead": "04ef9dd008d3d3ef9da631c7bafb349a4f589a3d"
81
+ }
65
82
  }
@@ -1,13 +1,35 @@
1
- /** beans: begin */
1
+ // eslint-disable
2
+ /** bean: begin */
2
3
  export * from '../bean/bean.theme.js';
4
+
5
+ import 'zova';
6
+ declare module 'zova' {
7
+
8
+
9
+ }
10
+ declare module 'zova-module-a-style' {
11
+
12
+ export interface BeanTheme {
13
+ /** @internal */
14
+ get scope(): ScopeModuleAStyle;
15
+ }
16
+
17
+ export interface BeanTheme {
18
+ get $beanFullName(): 'a-style.bean.theme';
19
+ get $onionName(): 'a-style:theme';
20
+
21
+ }
22
+ }
23
+ /** bean: end */
24
+ /** bean: begin */
3
25
  import { BeanTheme } from '../bean/bean.theme.js';
4
26
  import 'zova';
5
27
  declare module 'zova' {
6
- export interface IBeanRecord {
28
+ export interface IBeanRecordGeneral {
7
29
  'a-style.bean.theme': BeanTheme;
8
30
  }
9
31
  }
10
- /** beans: end */
32
+ /** bean: end */
11
33
  /** config: begin */
12
34
  export * from '../config/config.js';
13
35
  import { config } from '../config/config.js';
@@ -16,21 +38,30 @@ import { config } from '../config/config.js';
16
38
  export * from '../monkey.js';
17
39
  /** monkey: end */
18
40
  /** scope: begin */
19
- import { BeanScopeBase, Scope, TypeModuleResource } from 'zova';
41
+ import { BeanScopeBase, type BeanScopeUtil, TypeModuleConfig } from 'zova';
42
+ import { Scope } from 'zova-module-a-bean';
20
43
 
21
44
  @Scope()
22
45
  export class ScopeModuleAStyle extends BeanScopeBase {}
23
46
 
24
- export interface ScopeModuleAStyle extends TypeModuleResource<typeof config, any, any, any, any> {}
47
+ export interface ScopeModuleAStyle {
48
+ util: BeanScopeUtil;
49
+ config: TypeModuleConfig<typeof config>;
50
+ }
25
51
 
26
52
  import 'zova';
27
53
  declare module 'zova' {
28
54
  export interface IBeanScopeRecord {
29
55
  'a-style': ScopeModuleAStyle;
30
56
  }
31
-
57
+
32
58
  export interface IBeanScopeConfig {
33
59
  'a-style': ReturnType<typeof config>;
34
60
  }
61
+
62
+
63
+
64
+
35
65
  }
66
+
36
67
  /** scope: end */
@@ -1,14 +1,15 @@
1
- import { Bean, Cast, IBeanRecord } from 'zova';
2
- import { ScopeModule } from '../.metadata/this.js';
3
- import { ThemeBase, ThemeHandler } from '../types.js';
1
+ import { beanFullNameFromOnionName, cast, UseScope } from 'zova';
2
+ import { Bean } from 'zova-module-a-bean';
4
3
  import { BeanModelBase } from 'zova-module-a-model';
5
- import { watch } from 'vue';
4
+ import { ScopeModuleASsr } from 'zova-module-a-ssr';
5
+
6
+ import type { IThemeBase, IThemeHandler, IThemeRecord } from '../types/index.js';
6
7
 
7
8
  export type ThemeDarkMode = 'auto' | boolean;
8
9
 
9
- @Bean({ containerScope: 'app' })
10
- export class BeanTheme extends BeanModelBase<ScopeModule> {
11
- name: keyof IBeanRecord;
10
+ @Bean()
11
+ export class BeanTheme extends BeanModelBase {
12
+ name: keyof IThemeRecord;
12
13
  darkMode: ThemeDarkMode; // auto/true/false
13
14
 
14
15
  private _dark: boolean;
@@ -20,11 +21,14 @@ export class BeanTheme extends BeanModelBase<ScopeModule> {
20
21
  private _mediaDark?: MediaQueryList;
21
22
  private _onMediaDarkChange?;
22
23
 
24
+ @UseScope()
25
+ $$scopeSsr: ScopeModuleASsr;
26
+
23
27
  protected async __init__() {
28
+ const cookieTheme = this.$$scopeSsr.config.cookieTheme;
29
+ const cookieThemeDarkDefault = this.$$scopeSsr.config.cookieThemeDarkDefault;
24
30
  // support admin
25
- const cookieThemeName = this.app.config.ssr.cookieThemeName;
26
- const useQueryMethodThemeName = cookieThemeName ? '$useQueryCookie' : '$useQueryLocal';
27
- this.name = this[useQueryMethodThemeName]({
31
+ this.name = this.$useState(cookieTheme ? 'cookie' : 'local', {
28
32
  queryKey: ['themename'],
29
33
  meta: {
30
34
  persister: {
@@ -33,25 +37,22 @@ export class BeanTheme extends BeanModelBase<ScopeModule> {
33
37
  defaultData: this.scope.config.defaultTheme,
34
38
  },
35
39
  });
36
- const cookieThemeDark = this.app.config.ssr.cookieThemeDark;
37
- const cookieThemeDarkDefault = this.app.config.ssr.cookieThemeDarkDefault;
38
- const useQueryMethodThemeDark = cookieThemeDark ? '$useQueryCookie' : '$useQueryLocal';
39
- this.darkMode = this[useQueryMethodThemeDark]({
40
+ this.darkMode = this.$useState(cookieTheme ? 'cookie' : 'local', {
40
41
  queryKey: ['themedark'],
41
42
  meta: {
42
43
  persister: {
43
44
  maxAge: this.scope.config.model.themename.persister.maxAge,
44
45
  deserialize: (value, deserializeDefault) => {
45
- if (cookieThemeDark && value === 'auto') value = cookieThemeDarkDefault;
46
+ if (cookieTheme && value === 'auto') value = cookieThemeDarkDefault;
46
47
  return deserializeDefault(value);
47
48
  },
48
49
  },
49
- defaultData: cookieThemeDark ? cookieThemeDarkDefault : 'auto',
50
+ defaultData: cookieTheme ? cookieThemeDarkDefault : 'auto',
50
51
  },
51
52
  });
52
53
  this._updateDark();
53
54
 
54
- watch(
55
+ this.$watch(
55
56
  () => this.darkMode,
56
57
  () => {
57
58
  this._updateDark();
@@ -59,7 +60,7 @@ export class BeanTheme extends BeanModelBase<ScopeModule> {
59
60
  );
60
61
 
61
62
  if (process.env.CLIENT) {
62
- watch([() => this.name, () => this._dark], () => {
63
+ this.$watch([() => this.name, () => this._dark], () => {
63
64
  this._applyTheme();
64
65
  });
65
66
  }
@@ -78,7 +79,7 @@ export class BeanTheme extends BeanModelBase<ScopeModule> {
78
79
 
79
80
  async _applyThemeWrapper() {
80
81
  await this._applyTheme();
81
- if (process.env.SERVER && !this.app.config.ssr.cookieThemeDark) {
82
+ if (process.env.SERVER && !this.$$scopeSsr.config.cookieTheme) {
82
83
  this.toggleDark();
83
84
  await this._applyTheme();
84
85
  }
@@ -94,18 +95,22 @@ export class BeanTheme extends BeanModelBase<ScopeModule> {
94
95
  return;
95
96
  }
96
97
  const res = await theme.apply({ name, dark });
97
- this.token = Cast(res).token;
98
+ this.token = cast(res).token;
98
99
  const handler = res.handler ?? this.scope.config.defaultThemeHandler;
99
100
  if (handler) {
100
- const themeHandler = (await this.bean._getBean(handler, true)) as unknown as ThemeHandler;
101
+ const themeHandler = (await this.bean._getBean(beanFullNameFromOnionName(handler, 'meta'), true)) as unknown as IThemeHandler;
101
102
  await themeHandler.apply({ name, dark, token: this.token } as any);
102
103
  }
103
104
  }
104
105
 
105
- async _loadThemeBean(name: string): Promise<ThemeBase | undefined> {
106
- const moduleName = name.split('.')[0];
106
+ async _loadThemeBean(name: keyof IThemeRecord): Promise<IThemeBase | undefined> {
107
+ const parts = name.split(':');
108
+ if (parts.length === 1) {
109
+ throw new Error(`invalid theme name: ${name}`);
110
+ }
111
+ const moduleName = parts[0];
107
112
  if (!this.app.meta.module.exists(moduleName)) return;
108
- return await this.bean._getBean(name as any, true);
113
+ return (await this.bean._getBean(beanFullNameFromOnionName(name, 'theme'), true)) as IThemeBase;
109
114
  }
110
115
 
111
116
  toggleDark() {
@@ -1,10 +1,14 @@
1
- import { IBeanRecord, ZovaApplication } from 'zova';
1
+ import type { ZovaSys } from 'zova';
2
+ import type { TypeMetaRecordSelectorSpecificNameKeys } from 'zova-module-a-meta';
2
3
 
3
- export const config = (_app: ZovaApplication) => {
4
+ import type { ICssRecord } from '../types/css.js';
5
+ import type { IThemeRecord } from '../types/theme.js';
6
+
7
+ export const config = (_sys: ZovaSys) => {
4
8
  return {
5
- defaultStyle: 'home-base.style.default' as keyof IBeanRecord,
6
- defaultTheme: 'home-base.theme.default' as keyof IBeanRecord,
7
- defaultThemeHandler: '' as keyof IBeanRecord,
9
+ defaultCss: 'home-base:default' as keyof ICssRecord,
10
+ defaultTheme: 'home-base:default' as keyof IThemeRecord,
11
+ defaultThemeHandler: '' as TypeMetaRecordSelectorSpecificNameKeys<'themeHandler'>,
8
12
  model: {
9
13
  themename: {
10
14
  persister: {
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './.metadata/index.js';
2
- export * from './types.js';
2
+ export * from './lib/index.js';
3
+ export * from './types/index.js';
@@ -0,0 +1,3 @@
1
+ export * from './style.js';
2
+ export * from './theme.js';
3
+ export * from './themeBase.js';
@@ -0,0 +1,12 @@
1
+ import { createBeanDecorator } from 'zova';
2
+
3
+ import type { IDecoratorCssOptions } from '../types/css.js';
4
+ import type { IDecoratorThemeOptions } from '../types/theme.js';
5
+
6
+ export function Css<T extends IDecoratorCssOptions>(options?: T): ClassDecorator {
7
+ return createBeanDecorator('css', 'app', true, options);
8
+ }
9
+
10
+ export function Theme<T extends IDecoratorThemeOptions>(options?: T): ClassDecorator {
11
+ return createBeanDecorator('theme', 'app', true, options);
12
+ }
@@ -0,0 +1,5 @@
1
+ import type { IThemeRecord } from '../types/theme.js';
2
+
3
+ export function $getThemeName<K extends keyof IThemeRecord>(themeName: K): K {
4
+ return themeName;
5
+ }
@@ -0,0 +1,18 @@
1
+ import { BeanBase, deepExtend } from 'zova';
2
+
3
+ import type { IDecoratorThemeOptions, IThemeApplyParams, ThemeToken } from '../types/theme.js';
4
+
5
+ export class BeanThemeBase extends BeanBase {
6
+ protected getOptionsToken(params: IThemeApplyParams) {
7
+ const options = this.$onionOptions as IDecoratorThemeOptions;
8
+ return options.token?.(params);
9
+ }
10
+
11
+ protected mergeOptionsToken(params: IThemeApplyParams, token: ThemeToken) {
12
+ const optionsToken = this.getOptionsToken(params);
13
+ if (optionsToken) {
14
+ token = deepExtend(token, optionsToken);
15
+ }
16
+ return token;
17
+ }
18
+ }
package/src/monkey.ts CHANGED
@@ -1,44 +1,45 @@
1
- import { style, createTypeStyle, TypeStyle } from 'typestyle';
2
- import {
3
- BeanBase,
4
- BeanContainer,
5
- BeanSimple,
6
- IMonkeyAppInitialize,
7
- IMonkeyAppInitialized,
8
- IMonkeyBeanInit,
9
- SymbolModuleName,
10
- useComputed,
11
- } from 'zova';
12
- import { ScopeModule, __ThisModule__ } from './.metadata/this.js';
1
+ import type { TypeStyle } from 'typestyle';
2
+ import type { NestedCSSProperties } from 'typestyle/lib/types.js';
3
+ import type { BeanBase, BeanContainer, IMonkeyAppInitialize, IMonkeyAppInitialized, IMonkeyBeanInit } from 'zova';
4
+
5
+ import { createTypeStyle, cssRaw, cssRule, style } from 'typestyle';
6
+ import { beanFullNameFromOnionName, BeanSimple, SymbolBeanFullName, useComputed } from 'zova';
7
+
8
+ import type { ScopeModule } from './.metadata/this.js';
9
+
10
+ import { __ThisModule__ } from './.metadata/this.js';
13
11
  import { BeanTheme } from './bean/bean.theme.js';
14
12
 
15
13
  export class Monkey extends BeanSimple implements IMonkeyAppInitialize, IMonkeyAppInitialized, IMonkeyBeanInit {
16
14
  private _beanTheme: BeanTheme;
17
- private _beanStyleDefault: any;
15
+ private _beanCssDefault: any;
18
16
  private _styleInstance: TypeStyle;
19
17
 
20
18
  async appInitialize() {
21
19
  if (process.env.SERVER) {
22
20
  this._styleInstance = createTypeStyle();
23
- this.ctx.meta.ssr.context.onRendered(() => {
21
+ this.ctx.meta.$ssr.context.onRendered((err?: Error) => {
22
+ if (err) return;
24
23
  const styles = this._styleInstance.getStyles();
25
- this.ctx.meta.ssr.context._meta.endingHeadTags += `<style id="styles-target">${styles}</style>`;
24
+ this.ctx.meta.$ssr.context._meta.endingHeadTags += `<style id="styles-target">${styles}</style>`;
26
25
  });
27
26
  }
28
- if (process.env.CLIENT && this.ctx.meta.ssr.isRuntimeSsrPreHydration) {
27
+ if (process.env.CLIENT && this.ctx.meta.$ssr.isRuntimeSsrPreHydration) {
29
28
  this._styleInstance = createTypeStyle();
30
- this.ctx.meta.ssr.onHydrated(() => {
29
+ this.ctx.meta.$ssr.onHydrated(() => {
31
30
  this._styleInstance.setStylesTarget(document.getElementById('styles-target')!);
32
31
  });
33
32
  }
34
33
  }
34
+
35
35
  async appInitialized() {
36
36
  // theme
37
37
  this._beanTheme = await this.bean._getBean(BeanTheme, true);
38
- // style default
38
+ // css default
39
39
  const scope: ScopeModule = await this.bean.getScope(__ThisModule__);
40
- this._beanStyleDefault = await this.bean._getBean(scope.config.defaultStyle, true);
40
+ this._beanCssDefault = await this.bean._getBean(beanFullNameFromOnionName(scope.config.defaultCss, 'css'), true);
41
41
  }
42
+
42
43
  async beanInit(bean: BeanContainer, beanInstance: BeanBase) {
43
44
  const self = this;
44
45
  bean.defineProperty(beanInstance, '$style', {
@@ -50,11 +51,29 @@ export class Monkey extends BeanSimple implements IMonkeyAppInitialize, IMonkeyA
50
51
  };
51
52
  },
52
53
  });
53
- bean.defineProperty(beanInstance, '$class', {
54
+ bean.defineProperty(beanInstance, '$cssRule', {
55
+ enumerable: false,
56
+ configurable: true,
57
+ get() {
58
+ return function (selector: string, ...objects: NestedCSSProperties[]) {
59
+ return self._patchCssRule(beanInstance, selector, ...objects);
60
+ };
61
+ },
62
+ });
63
+ bean.defineProperty(beanInstance, '$cssRaw', {
54
64
  enumerable: false,
55
65
  configurable: true,
56
66
  get() {
57
- return self._beanStyleDefault;
67
+ return function (mustBeValidCSS: string) {
68
+ return self._patchCssRaw(beanInstance, mustBeValidCSS);
69
+ };
70
+ },
71
+ });
72
+ bean.defineProperty(beanInstance, '$css', {
73
+ enumerable: false,
74
+ configurable: true,
75
+ get() {
76
+ return self._beanCssDefault;
58
77
  },
59
78
  });
60
79
  bean.defineProperty(beanInstance, '$theme', {
@@ -76,7 +95,7 @@ export class Monkey extends BeanSimple implements IMonkeyAppInitialize, IMonkeyA
76
95
  _patchStyle(beanInstance: BeanBase, props, ...args) {
77
96
  if (process.env.DEV) {
78
97
  if (props && typeof props === 'object') {
79
- props = Object.assign({ $debugName: beanInstance[SymbolModuleName] }, props);
98
+ props = Object.assign({ $debugName: beanInstance[SymbolBeanFullName].replaceAll('.', '_') }, props);
80
99
  }
81
100
  }
82
101
  if (this._styleInstance) {
@@ -85,4 +104,20 @@ export class Monkey extends BeanSimple implements IMonkeyAppInitialize, IMonkeyA
85
104
  return style(props, ...args);
86
105
  }
87
106
  }
107
+
108
+ _patchCssRule(_beanInstance: BeanBase, selector: string, ...objects: NestedCSSProperties[]) {
109
+ if (this._styleInstance) {
110
+ return this._styleInstance.cssRule(selector, ...objects);
111
+ } else {
112
+ return cssRule(selector, ...objects);
113
+ }
114
+ }
115
+
116
+ _patchCssRaw(_beanInstance: BeanBase, mustBeValidCSS: string) {
117
+ if (this._styleInstance) {
118
+ return this._styleInstance.cssRaw(mustBeValidCSS);
119
+ } else {
120
+ return cssRaw(mustBeValidCSS);
121
+ }
122
+ }
88
123
  }
@@ -0,0 +1,22 @@
1
+ import type { OmitNever } from 'zova';
2
+ import type { ServiceOnion } from 'zova-module-a-bean';
3
+
4
+ export interface ICssRecord {}
5
+
6
+ export interface IDecoratorCssOptions {}
7
+
8
+ declare module 'zova-module-a-bean' {
9
+ export interface SysOnion {
10
+ css: ServiceOnion<IDecoratorCssOptions, keyof ICssRecord>;
11
+ }
12
+ }
13
+
14
+ declare module 'zova' {
15
+ export interface ConfigOnions {
16
+ css: OmitNever<ICssRecord>;
17
+ }
18
+
19
+ export interface IBeanSceneRecord {
20
+ css: never;
21
+ }
22
+ }
@@ -0,0 +1,3 @@
1
+ export * from './css.js';
2
+ export * from './style.js';
3
+ export * from './theme.js';
@@ -0,0 +1,13 @@
1
+ import type { cssRaw, cssRule, style } from 'typestyle';
2
+
3
+ import type { BeanTheme } from '../bean/bean.theme.js';
4
+ import 'zova';
5
+
6
+ declare module 'zova' {
7
+ export interface BeanBase {
8
+ $style: typeof style;
9
+ $cssRule: typeof cssRule;
10
+ $cssRaw: typeof cssRaw;
11
+ $theme: BeanTheme;
12
+ }
13
+ }
@@ -0,0 +1,55 @@
1
+ import type { OmitNever, PowerPartial } from 'zova';
2
+ import type { ServiceOnion } from 'zova-module-a-bean';
3
+ import type { IMetaRecord } from 'zova-module-a-meta';
4
+
5
+ export interface IThemeRecord {}
6
+
7
+ export interface IDecoratorThemeOptions {
8
+ token?: (params: IThemeApplyParams) => PowerPartial<ThemeToken>;
9
+ }
10
+
11
+ declare module 'zova-module-a-bean' {
12
+ export interface SysOnion {
13
+ theme: ServiceOnion<IDecoratorThemeOptions, keyof IThemeRecord>;
14
+ }
15
+ }
16
+
17
+ declare module 'zova' {
18
+ export interface ConfigOnions {
19
+ theme: OmitNever<IThemeRecord>;
20
+ }
21
+
22
+ export interface IBeanSceneRecord {
23
+ theme: never;
24
+ }
25
+
26
+ export interface BeanBase {
27
+ $token: ThemeToken;
28
+ }
29
+ }
30
+
31
+ export interface ThemeToken {}
32
+
33
+ export interface IThemeApplyParams {
34
+ name: string;
35
+ dark: boolean;
36
+ }
37
+
38
+ export interface IThemeApplyResult {
39
+ token: ThemeToken;
40
+ handler?: keyof IMetaRecord;
41
+ }
42
+
43
+ export interface IThemeBase {
44
+ apply(params: IThemeApplyParams): Promise<IThemeApplyResult>;
45
+ }
46
+
47
+ export interface IThemeHandler {
48
+ apply(result: IThemeHandlerApplyParams): Promise<void>;
49
+ }
50
+
51
+ export interface IThemeHandlerApplyParams {
52
+ name: string;
53
+ dark: boolean;
54
+ token: ThemeToken;
55
+ }
@@ -1,15 +0,0 @@
1
- import 'zova-module-a-test';
2
- import 'zova-module-demo-basic';
3
- import 'zova-module-demo-todo';
4
- import 'zova-module-a-model';
5
- import 'zova-module-a-router';
6
- import 'zova-module-a-style';
7
- import 'zova-module-a-zova';
8
- import 'zova-module-home-base';
9
- import 'zova-module-home-icon';
10
- import 'zova-module-home-index';
11
- import 'zova-module-home-layout';
12
- import 'zova-module-home-user';
13
- import 'zova-module-devui-adapter';
14
- import 'zova-module-a-pinia';
15
- import 'zova-module-a-tabs';
package/src/types.ts DELETED
@@ -1,32 +0,0 @@
1
- import { style } from 'typestyle';
2
- import 'zova';
3
- import { BeanTheme } from './bean/bean.theme.js';
4
- import { IBeanRecord } from 'zova';
5
- declare module 'zova' {
6
- export interface BeanBase {
7
- $style: typeof style;
8
- $theme: BeanTheme;
9
- }
10
- }
11
-
12
- export interface ThemeApplyParams {
13
- name: string;
14
- dark: boolean;
15
- }
16
-
17
- export interface ThemeApplyResult {
18
- handler?: keyof IBeanRecord;
19
- }
20
-
21
- export interface ThemeBase {
22
- apply({ name, dark }: ThemeApplyParams): Promise<ThemeApplyResult>;
23
- }
24
-
25
- export interface ThemeHandler {
26
- apply(result: ThemeHandlerApplyParams): Promise<void>;
27
- }
28
-
29
- export interface ThemeHandlerApplyParams {
30
- name: string;
31
- dark: boolean;
32
- }