render-core 1.4.30 → 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
@@ -86,12 +86,6 @@ var RenderJS = /** @class */ (function () {
86
86
  /* init the basis extension */
87
87
  this.use_plugin(new SystemInitPlugin());
88
88
  }
89
- /**
90
- * This func is used to execute plugins
91
- */
92
- RenderJS.prototype.use_plugin = function (plugin) {
93
- plugin.plugin(new PrefaceAction(), new HooksAction());
94
- };
95
89
  /**
96
90
  * This unc is used to register component to system
97
91
  * @param component
@@ -103,6 +97,12 @@ var RenderJS = /** @class */ (function () {
103
97
  });
104
98
  registerTagLib(component);
105
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
+ };
106
106
  /**
107
107
  * This func is used to work under the route mode
108
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,6 +1,6 @@
1
1
  {
2
2
  "name": "render-core",
3
- "version": "1.4.30",
3
+ "version": "1.4.31",
4
4
  "description": "The extendable javascript web framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -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
+ }