render-core 1.3.41 → 1.3.42
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/class/tips/renderTip.d.ts +2 -1
- package/core/utility/styleUtility.d.ts +11 -0
- package/core/utility/styleUtility.js +56 -12
- package/index.d.ts +3 -10
- package/index.js +10 -12
- package/package.json +1 -1
|
@@ -15,3 +15,14 @@ export declare function themeStyle(component: Component, styleLib: Map<string, o
|
|
|
15
15
|
* @param tag
|
|
16
16
|
*/
|
|
17
17
|
export declare function styleResolve(tag: string): void;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param tag
|
|
21
|
+
* @param theme
|
|
22
|
+
*/
|
|
23
|
+
export declare function changeStyle(tag: string, theme: string): void;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param theme
|
|
27
|
+
*/
|
|
28
|
+
export declare function changeTheme(theme: string): void;
|
|
@@ -36,7 +36,7 @@ export function themeStyle(component, styleLib) {
|
|
|
36
36
|
* @param tag
|
|
37
37
|
*/
|
|
38
38
|
export function styleResolve(tag) {
|
|
39
|
-
var theme =
|
|
39
|
+
var theme = sessionStorage.getItem("theme_style");
|
|
40
40
|
if (Reflect.get(window, "styleLib").get(tag.toUpperCase()).get(theme) === undefined) {
|
|
41
41
|
console.log("tag:" + tag + " has no theme " + theme);
|
|
42
42
|
if (Reflect.get(window, "styleLib").get(tag.toUpperCase()).get("default") === undefined) {
|
|
@@ -50,18 +50,62 @@ export function styleResolve(tag) {
|
|
|
50
50
|
loadStyle(tag, theme, Reflect.get(window, "styleLib").get(tag.toUpperCase()).get(theme));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
// /**
|
|
54
|
+
// * 从url中获取主题参数
|
|
55
|
+
// * @param name
|
|
56
|
+
// */
|
|
57
|
+
// function getUrlParam(name:string):string {
|
|
58
|
+
// //构造一个含有目标参数的正则表达式对象
|
|
59
|
+
// var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
|
60
|
+
// //匹配目标参数
|
|
61
|
+
// var r = window.location.search.substr(1).match(reg);
|
|
62
|
+
// //返回参数值
|
|
63
|
+
// if(r != null) {
|
|
64
|
+
// return decodeURI(r[2]);
|
|
65
|
+
// }
|
|
66
|
+
// return undefined;
|
|
67
|
+
// }
|
|
53
68
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @param
|
|
69
|
+
*
|
|
70
|
+
* @param tag
|
|
71
|
+
* @param theme
|
|
56
72
|
*/
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var r = window.location.search.substr(1).match(reg);
|
|
62
|
-
//返回参数值
|
|
63
|
-
if (r != null) {
|
|
64
|
-
return decodeURI(r[2]);
|
|
73
|
+
export function changeStyle(tag, theme) {
|
|
74
|
+
var styleTxt = Reflect.get(window, "styleLib").get(tag.toUpperCase()).get(theme);
|
|
75
|
+
if (styleTxt === undefined) {
|
|
76
|
+
console.log("Dont`t find this style!");
|
|
65
77
|
}
|
|
66
|
-
|
|
78
|
+
else {
|
|
79
|
+
var style = document.createElement('style');
|
|
80
|
+
var text = document.createTextNode(styleTxt);
|
|
81
|
+
style.appendChild(text);
|
|
82
|
+
style.setAttribute("tag", tag.toUpperCase());
|
|
83
|
+
style.setAttribute("theme", theme);
|
|
84
|
+
var head = document.getElementsByTagName('head')[0];
|
|
85
|
+
var target = head.querySelector("style" + "[tag=" + tag.toUpperCase() + "]");
|
|
86
|
+
head.replaceChild(style, target);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param theme
|
|
92
|
+
*/
|
|
93
|
+
export function changeTheme(theme) {
|
|
94
|
+
Reflect.get(window, "styleLib").forEach(function (value, key) {
|
|
95
|
+
var styles = document.getElementsByTagName("style");
|
|
96
|
+
for (var i = 0; i < styles.length; i++) {
|
|
97
|
+
if (styles[i].getAttribute("tag") === key) {
|
|
98
|
+
var style = document.createElement('style');
|
|
99
|
+
if (value.get(theme)) {
|
|
100
|
+
var text = document.createTextNode(value.get(theme));
|
|
101
|
+
style.appendChild(text);
|
|
102
|
+
style.setAttribute("tag", key.toUpperCase());
|
|
103
|
+
style.setAttribute("theme", theme);
|
|
104
|
+
var head = document.getElementsByTagName('head')[0];
|
|
105
|
+
head.replaceChild(style, styles[i]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
sessionStorage.setItem("theme_style", theme);
|
|
67
111
|
}
|
package/index.d.ts
CHANGED
|
@@ -5,17 +5,16 @@ import { RenderTip } from "./class/tips/renderTip";
|
|
|
5
5
|
* This class is the application class.
|
|
6
6
|
*/
|
|
7
7
|
export declare class RenderJS implements RenderTip {
|
|
8
|
-
readonly config: {};
|
|
9
8
|
readonly tagLib: Map<string, Component>;
|
|
10
9
|
readonly styleLib: Map<string, Map<string, string>>;
|
|
11
10
|
private readonly application;
|
|
12
11
|
page: PageController;
|
|
13
12
|
constructor();
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
14
|
+
* This func is the plugin entry to third vendor
|
|
16
15
|
* @param callable
|
|
17
16
|
*/
|
|
18
|
-
use(callable:
|
|
17
|
+
use(callable: (render: RenderJS) => void): void;
|
|
19
18
|
/**
|
|
20
19
|
* You can use the method to register your single component or an array of components.
|
|
21
20
|
* @param component
|
|
@@ -30,15 +29,9 @@ export declare class RenderJS implements RenderTip {
|
|
|
30
29
|
*/
|
|
31
30
|
run(): void;
|
|
32
31
|
/**
|
|
33
|
-
*
|
|
32
|
+
* Use the func to register some tool-functions to the windows object.
|
|
34
33
|
* @param name
|
|
35
34
|
* @param func
|
|
36
35
|
*/
|
|
37
36
|
registerElements(name: string, func: any): void;
|
|
38
37
|
}
|
|
39
|
-
/**
|
|
40
|
-
* The tool to register element to window
|
|
41
|
-
* @param name
|
|
42
|
-
* @param func
|
|
43
|
-
*/
|
|
44
|
-
export declare function registerElements(name: string, func: any): void;
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PageController } from "./class/controller/pageController";
|
|
2
2
|
import { registerTagLib, render } from "./runtime/tools";
|
|
3
3
|
import { AppController } from "./class/controller/appController";
|
|
4
|
+
import { changeStyle, changeTheme } from "./core/utility/styleUtility";
|
|
4
5
|
/**
|
|
5
6
|
* This class is the application class.
|
|
6
7
|
*/
|
|
@@ -14,11 +15,9 @@ var RenderJS = /** @class */ (function () {
|
|
|
14
15
|
this.application = new AppController();
|
|
15
16
|
//initiate the page controller
|
|
16
17
|
this.page = new PageController();
|
|
17
|
-
//initiate the config object
|
|
18
|
-
this.config = {};
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
20
|
+
* This func is the plugin entry to third vendor
|
|
22
21
|
* @param callable
|
|
23
22
|
*/
|
|
24
23
|
RenderJS.prototype.use = function (callable) {
|
|
@@ -46,11 +45,18 @@ var RenderJS = /** @class */ (function () {
|
|
|
46
45
|
RenderJS.prototype.run = function () {
|
|
47
46
|
//挂载对象
|
|
48
47
|
this.mount();
|
|
48
|
+
//注册函数
|
|
49
|
+
this.registerElements("changeStyle", changeStyle);
|
|
50
|
+
//注册函数
|
|
51
|
+
this.registerElements("changeTheme", changeTheme);
|
|
52
|
+
this.use(function (render) {
|
|
53
|
+
sessionStorage.setItem("theme_style", "default");
|
|
54
|
+
});
|
|
49
55
|
//execute
|
|
50
56
|
render(this);
|
|
51
57
|
};
|
|
52
58
|
/**
|
|
53
|
-
*
|
|
59
|
+
* Use the func to register some tool-functions to the windows object.
|
|
54
60
|
* @param name
|
|
55
61
|
* @param func
|
|
56
62
|
*/
|
|
@@ -60,11 +66,3 @@ var RenderJS = /** @class */ (function () {
|
|
|
60
66
|
return RenderJS;
|
|
61
67
|
}());
|
|
62
68
|
export { RenderJS };
|
|
63
|
-
/**
|
|
64
|
-
* The tool to register element to window
|
|
65
|
-
* @param name
|
|
66
|
-
* @param func
|
|
67
|
-
*/
|
|
68
|
-
export function registerElements(name, func) {
|
|
69
|
-
Reflect.set(window, name, func);
|
|
70
|
-
}
|