render-core 1.4.25 → 1.4.31

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/index.d.ts CHANGED
@@ -60,15 +60,15 @@ export declare class Component extends AbstractComponent {
60
60
  export declare class RenderJS implements RenderGeneric {
61
61
  contextController: ContextController;
62
62
  constructor();
63
- /**
64
- * This func is used to execute plugins
65
- */
66
- use_plugin(plugin: PluginGeneric): void;
67
63
  /**
68
64
  * This unc is used to register component to system
69
65
  * @param component
70
66
  */
71
67
  add_tag(component: Component): void;
68
+ /**
69
+ * This func is used to execute plugins
70
+ */
71
+ use_plugin(plugin: PluginGeneric): void;
72
72
  /**
73
73
  * This func is used to work under the route mode
74
74
  */
package/index.js CHANGED
@@ -21,6 +21,8 @@ import { AbstractComponent } from "./tension/prototype/AbstractComponent";
21
21
  import { set_context_controller } from "./system/recorder/table0/system_func_0";
22
22
  import { PrefaceAction } from "./tension/prototype/PrefaceAction";
23
23
  import { SystemInitPlugin } from "./tension/SystemInitPlugin";
24
+ import { lintComponent } from "./verify/directive-linter";
25
+ import { errorDisplay } from "./system/output/errorUtility";
24
26
  /**
25
27
  * This class is used to prototype the properties type
26
28
  */
@@ -84,27 +86,23 @@ var RenderJS = /** @class */ (function () {
84
86
  /* init the basis extension */
85
87
  this.use_plugin(new SystemInitPlugin());
86
88
  }
87
- /**
88
- * This func is used to execute plugins
89
- */
90
- RenderJS.prototype.use_plugin = function (plugin) {
91
- plugin.plugin(new PrefaceAction(), new HooksAction());
92
- };
93
89
  /**
94
90
  * This unc is used to register component to system
95
91
  * @param component
96
92
  */
97
93
  RenderJS.prototype.add_tag = function (component) {
98
- // let errors:LintError[] = lintComponent(component);
99
- // if (errors.length > 0) {
100
- // errors.map(error => {
101
- // errorDisplay(component.getName(), error);
102
- // })
103
- // }else {
104
- // registerTagLib(component);
105
- // }
94
+ var errors = lintComponent(component);
95
+ errors.map(function (error) {
96
+ errorDisplay(component.getName(), error);
97
+ });
106
98
  registerTagLib(component);
107
99
  };
100
+ /**
101
+ * This func is used to execute plugins
102
+ */
103
+ RenderJS.prototype.use_plugin = function (plugin) {
104
+ plugin.plugin(new PrefaceAction(), new HooksAction());
105
+ };
108
106
  /**
109
107
  * This func is used to work under the route mode
110
108
  */
@@ -0,0 +1,13 @@
1
+ import { ContextController } from "../../../system/prototype/ContextController";
2
+ /**
3
+ * 此函数用于解析自定义元素salt
4
+ * @param tagTemplate
5
+ * @param controller
6
+ */
7
+ export declare function parse_directive_salt_collect(tagTemplate: ChildNode, controller: ContextController): void;
8
+ /**
9
+ * 此函数用于展开salt
10
+ * @param elements
11
+ * @param controller
12
+ */
13
+ export declare function parse_directive_salt_extract(elements: HTMLCollection, controller: ContextController): void;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 此函数用于解析自定义元素salt
3
+ * @param tagTemplate
4
+ * @param controller
5
+ */
6
+ export function parse_directive_salt_collect(tagTemplate, controller) {
7
+ if (tagTemplate.hasChildNodes()) {
8
+ // @ts-ignore
9
+ var list = tagTemplate.querySelectorAll("slot");
10
+ if (list.length !== 0) {
11
+ list.forEach(function (value) {
12
+ if (value.hasAttribute("name"))
13
+ controller.salt.set(value.getAttribute("name"), value.innerHTML);
14
+ else
15
+ controller.salt.set("default", value.innerHTML);
16
+ });
17
+ }
18
+ else {
19
+ // @ts-ignore
20
+ controller.salt.set("default", tagTemplate.innerHTML);
21
+ }
22
+ }
23
+ }
24
+ /**
25
+ * 此函数用于展开salt
26
+ * @param elements
27
+ * @param controller
28
+ */
29
+ export function parse_directive_salt_extract(elements, controller) {
30
+ for (var i = 0; i < elements.length; i++) {
31
+ var result = elements[i].hasAttribute("@slot");
32
+ if (result) {
33
+ var dataName = elements[i].getAttribute("@slot");
34
+ elements[i].removeAttribute("@slot");
35
+ if (!dataName) {
36
+ elements[i].innerHTML = controller.salt.get("default");
37
+ }
38
+ else {
39
+ // @ts-ignore
40
+ elements[i].innerHTML = controller.solt.get(dataName);
41
+ }
42
+ }
43
+ //深度解析
44
+ parse_directive_salt_extract(elements[i].children, controller);
45
+ }
46
+ }
@@ -9,7 +9,7 @@ import { loader_tag_style } from "../../system/utility/style/styleUtility";
9
9
  import { get_style_library } from "../../system/recorder/table0/system_func_0";
10
10
  import { get_proxy_for_computed, get_proxy_for_method, get_proxy_for_watcher } from "../proxyer/getProxy";
11
11
  import { get_commit_method, get_getter_method, get_publish_method, get_setter_method } from "../../system/injection/injection";
12
- import { parse_directive_salt_collect } from "../directive/salt/v-solt";
12
+ import { parse_directive_salt_collect } from "../directive/slot/v-slot";
13
13
  /**
14
14
  * 该函数用于处理需要更更新时候,需要从父组件提取数据状态的渲染操作
15
15
  * @param protoType
@@ -4,7 +4,7 @@ import { archive_mount, extract_mount } from "../../system/lifecycle/mount";
4
4
  import { inject_$commit_to_data, inject_$getter_to_data, inject_$http_to_data, inject_$name_to_data, inject_$pathVariable_to_data, inject_$plugins_to_data, inject_$props_to_data, inject_$publish_to_data, inject_$refs_to_data, inject_$setter_to_data, inject_computed_to_controller, inject_method_to_data, inject_watcher_to_controller, } from "../../system/injection/injector";
5
5
  import { after_process_for_post } from "../../system/lifecycle/lifeCycle";
6
6
  import { findComponent } from "../delivery/delivery";
7
- import { parse_directive_salt_collect } from "../directive/salt/v-solt";
7
+ import { parse_directive_salt_collect } from "../directive/slot/v-slot";
8
8
  import { getTemplate } from "../../system/utility/initiate/templateUtility";
9
9
  import { loader_tag_style } from "../../system/utility/style/styleUtility";
10
10
  import { get_style_library } from "../../system/recorder/table0/system_func_0";
@@ -4,7 +4,7 @@ import { archive_mount, extract_mount } from "../../system/lifecycle/mount";
4
4
  import { inject_$commit_to_data, inject_$getter_to_data, inject_$http_to_data, inject_$name_to_data, inject_$pathVariable_to_data, inject_$plugins_to_data, inject_$props_to_data, inject_$publish_to_data, inject_$refs_to_data, inject_$setter_to_data, inject_computed_to_controller, inject_method_to_data, inject_watcher_to_controller, } from "../../system/injection/injector";
5
5
  import { after_process_for_post } from "../../system/lifecycle/lifeCycle";
6
6
  import { findComponent } from "../delivery/delivery";
7
- import { parse_directive_salt_collect } from "../directive/salt/v-solt";
7
+ import { parse_directive_salt_collect } from "../directive/slot/v-slot";
8
8
  import { getTemplate } from "../../system/utility/initiate/templateUtility";
9
9
  import { loader_tag_style } from "../../system/utility/style/styleUtility";
10
10
  import { get_style_library } from "../../system/recorder/table0/system_func_0";
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "render-core",
3
- "version": "1.4.25",
3
+ "version": "1.4.31",
4
4
  "description": "The extendable javascript web framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
- "scripts": {
8
- "build": "tsc"
9
- },
10
7
  "repository": {
11
8
  "type": "git",
12
9
  "url": "https://github.com//render-js/render-core.git"
@@ -15,8 +12,5 @@
15
12
  "name": "mutian-xiangcai",
16
13
  "email": "mutian_xiangcai@outlook.com"
17
14
  },
18
- "license": "MIT",
19
- "devDependencies": {
20
- "typescript": "^5.8.3"
21
- }
15
+ "license": "MIT"
22
16
  }
@@ -9,7 +9,7 @@ import { parse_directive_render } from "../../../kernel/directive/justify/v-rend
9
9
  import { parse_directive_if } from "../../../kernel/directive/justify/v-if";
10
10
  import { parse_directive_switch } from "../../../kernel/directive/justify/v-switch";
11
11
  import { parse_directive_for_of } from "../../../kernel/directive/loop/v-array";
12
- import { parse_directive_salt_extract } from "../../../kernel/directive/salt/v-solt";
12
+ import { parse_directive_salt_extract } from "../../../kernel/directive/slot/v-slot";
13
13
  import { parse_directive_expression } from "../../../kernel/directive/data/v-el";
14
14
  import { parse_directive_for_map } from "../../../kernel/directive/loop/v-map";
15
15
  /**
@@ -1,3 +1,4 @@
1
+ import { hashName } from "../style/styleUtility";
1
2
  /**
2
3
  * This func used to add tag label to the content of the user tag
3
4
  * @param nodes
@@ -5,7 +6,7 @@
5
6
  */
6
7
  export function add_label_to_element(nodes, component) {
7
8
  for (var i = 0; i < nodes.length; i++) {
8
- nodes[i].setAttribute("cpn", component);
9
+ nodes[i].setAttribute("v-data", hashName(component));
9
10
  var kk = nodes[i].children;
10
11
  add_label_to_element(kk, component);
11
12
  }
@@ -27,3 +27,14 @@ export declare function changeStyle(tag: string, theme: string): void;
27
27
  * @param theme
28
28
  */
29
29
  export declare function changeTheme(theme: string): void;
30
+ /**
31
+ * 给 CSS 中所有选择器添加 V-data 属性选择器
32
+ * @param {string} cssText - 原始 CSS 字符串
33
+ * @param {string} salt - 盐值
34
+ * @returns {string} 处理后的 CSS 字符串
35
+ */
36
+ /**
37
+ * Simple synchronous string hash (djb2) — used to produce a unique salt per component name.
38
+ */
39
+ export declare function hashName(name: string): string;
40
+ export declare function style_slot_func(cssText: string, salt: string): string;
@@ -29,7 +29,7 @@ export function themeStyle(component, styleLib) {
29
29
  var styles = dom.getElementsByTagName("template")[0].content.querySelectorAll("style");
30
30
  var componentStyleList = new Map();
31
31
  for (var i = 0; i < styles.length; i++) {
32
- componentStyleList.set(styles[i].getAttribute("theme"), styles[i].innerText);
32
+ componentStyleList.set(styles[i].getAttribute("theme"), style_slot_func(styles[i].innerText, hashName(component.getName())));
33
33
  }
34
34
  styleLib.set(component.getName().toUpperCase(), componentStyleList);
35
35
  }
@@ -64,7 +64,7 @@ export function loader_tag_style(tag, styleLib) {
64
64
  export function changeStyle(tag, theme) {
65
65
  var styleTxt = get_style_library().get(tag.toUpperCase()).get(theme);
66
66
  if (styleTxt === undefined) {
67
- console.log("Dont`t find this style!");
67
+ console.log("Don`t find this style!");
68
68
  }
69
69
  else {
70
70
  var style = document.createElement('style');
@@ -100,3 +100,44 @@ export function changeTheme(theme) {
100
100
  });
101
101
  set_theme_style(theme);
102
102
  }
103
+ /**
104
+ * 给 CSS 中所有选择器添加 V-data 属性选择器
105
+ * @param {string} cssText - 原始 CSS 字符串
106
+ * @param {string} salt - 盐值
107
+ * @returns {string} 处理后的 CSS 字符串
108
+ */
109
+ /**
110
+ * Simple synchronous string hash (djb2) — used to produce a unique salt per component name.
111
+ */
112
+ export function hashName(name) {
113
+ var hash = 0;
114
+ for (var i = 0; i < name.length; i++) {
115
+ hash = ((hash << 5) - hash) + name.charCodeAt(i);
116
+ hash |= 0;
117
+ }
118
+ return Math.abs(hash).toString(16);
119
+ }
120
+ export function style_slot_func(cssText, salt) {
121
+ if (!cssText || !salt)
122
+ return cssText;
123
+ // 正则匹配:选择器部分 { 声明部分 }
124
+ // 注意:这里不处理嵌套规则(如 @media 内部的选择器),如果需要可以调整
125
+ return cssText.replace(/([^{]+)(\{)/g, function (match, selectors, brace) {
126
+ // 如果是 @ 开头的规则,不处理
127
+ if (selectors.trim().startsWith('@')) {
128
+ return match;
129
+ }
130
+ // 将每个选择器(以逗号分隔)都加上 [V-data="salt"]
131
+ var newSelectors = selectors
132
+ .split(',')
133
+ .map(function (sel) {
134
+ var trimmed = sel.trim();
135
+ if (!trimmed)
136
+ return '';
137
+ return "".concat(trimmed, "[v-data=\"").concat(salt, "\"]");
138
+ })
139
+ .filter(function (s) { return s; })
140
+ .join(', ');
141
+ return newSelectors + brace;
142
+ });
143
+ }
@@ -1,14 +0,0 @@
1
- /**
2
- * 遍历根元素
3
- * @param element
4
- * @param index
5
- * @param data
6
- */
7
- export declare function resolver_array_single(element: Element, index: number, data: any): void;
8
- /**
9
- * 遍历根元素的子元素
10
- * @param elements
11
- * @param index
12
- * @param data
13
- */
14
- export declare function parse_directive_array_multi(elements: HTMLCollection, index: number, data: any): void;
@@ -1,58 +0,0 @@
1
- import { resolver_map_single } from "./v-map-utility";
2
- /**
3
- * 遍历根元素
4
- * @param element
5
- * @param index
6
- * @param data
7
- */
8
- export function resolver_array_single(element, index, data) {
9
- //解析data
10
- if (element.hasAttribute("@data")) {
11
- element.removeAttribute("@data");
12
- // @ts-ignore
13
- element.innerText = data;
14
- }
15
- //解析index
16
- if (element.hasAttribute("@index")) {
17
- element.removeAttribute("@index");
18
- // @ts-ignore
19
- element.innerText = index;
20
- }
21
- parse_directive_array_multi(element.children, index, data);
22
- }
23
- /**
24
- * 遍历根元素的子元素
25
- * @param elements
26
- * @param index
27
- * @param data
28
- */
29
- export function parse_directive_array_multi(elements, index, data) {
30
- //渲染模板子元素
31
- for (var i = 0; i < elements.length; i++) {
32
- //渲染文档
33
- if (elements[i].hasAttribute("@for-document")) {
34
- elements[i].removeAttribute("@for-document");
35
- resolver_map_single(elements[i], data);
36
- }
37
- //渲染信息
38
- if (elements[i].hasAttribute("@for-message")) {
39
- var data_index = elements[i].getAttribute("@for-message");
40
- elements[i].removeAttribute("@for-message");
41
- // @ts-ignore
42
- elements[i].innerText = data[data_index];
43
- }
44
- //解析data
45
- if (elements[i].hasAttribute("@data")) {
46
- elements[i].removeAttribute("@data");
47
- // @ts-ignore
48
- elements[i].innerText = data;
49
- }
50
- //解析index
51
- if (elements[i].hasAttribute("@index")) {
52
- elements[i].removeAttribute("@index");
53
- // @ts-ignore
54
- elements[i].innerText = index;
55
- }
56
- parse_directive_array_multi(elements[i].children, index, data);
57
- }
58
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * 展开数据
3
- * @param elements
4
- * @param data
5
- */
6
- export declare function parse_directive_for_of(elements: HTMLCollection, data: {}): void;
7
- /**
8
- *
9
- * @param baseRoot
10
- * @param temp
11
- * @param index
12
- * @param data
13
- */
14
- export declare function extractForArray(baseRoot: ParentNode, temp: Node, index: number, data: any): void;
15
- /**
16
- * 该函数用于处理数组类型数据的展开
17
- * @param baseRoot
18
- * @param temp
19
- * @param index
20
- * @param data
21
- */
22
- export declare function part_render_array(baseRoot: ParentNode, temp: Node, index: number, data: any): void;
@@ -1,64 +0,0 @@
1
- import { resolver_array_single } from "./v-for-utility";
2
- /**
3
- * 展开数据
4
- * @param elements
5
- * @param data
6
- */
7
- export function parse_directive_for_of(elements, data) {
8
- var _loop_1 = function (i) {
9
- var result = elements[i].hasAttribute("@for");
10
- if (result) {
11
- var dataName = elements[i].getAttribute("@for");
12
- elements[i].removeAttribute("@for");
13
- if (data[dataName] instanceof Array) {
14
- data[dataName].forEach(function (value, index) {
15
- //从数组中取出一条信息,然后开始渲染
16
- extractForArray(elements[i].parentNode, elements[i], index, value);
17
- i++;
18
- });
19
- //将模板节点删除
20
- elements[i].parentNode.removeChild(elements[i]);
21
- //重新回到原来的索引值
22
- i--;
23
- }
24
- else {
25
- console.log("Instruction @for need an array datatype to extract!");
26
- }
27
- }
28
- if (elements[i]) {
29
- parse_directive_for_of(elements[i].children, data);
30
- }
31
- out_i_1 = i;
32
- };
33
- var out_i_1;
34
- for (var i = 0; i < elements.length; i++) {
35
- _loop_1(i);
36
- i = out_i_1;
37
- }
38
- }
39
- /**
40
- *
41
- * @param baseRoot
42
- * @param temp
43
- * @param index
44
- * @param data
45
- */
46
- export function extractForArray(baseRoot, temp, index, data) {
47
- //将渲染出来的数据模板插入到根元素下
48
- part_render_array(baseRoot, temp, index, data);
49
- }
50
- /**
51
- * 该函数用于处理数组类型数据的展开
52
- * @param baseRoot
53
- * @param temp
54
- * @param index
55
- * @param data
56
- */
57
- export function part_render_array(baseRoot, temp, index, data) {
58
- // @ts-ignore
59
- var clone = temp.cloneNode(true);
60
- // @ts-ignore
61
- resolver_array_single(clone, index, data);
62
- //插入模板节点
63
- baseRoot.insertBefore(clone, temp);
64
- }