@joker.front/core 1.3.54 → 1.3.57

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Zohar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,39 +1,38 @@
1
- # Joker ![npm](https://img.shields.io/npm/v/%40joker.front%2Fcore) ![NPM Downloads](https://img.shields.io/npm/dw/%40joker.front%2Fcore)
1
+ # Joker ![npm](https://img.shields.io/npm/v/%40joker.front%2Fcore)![NPM Downloads](https://img.shields.io/npm/dw/%40joker.front%2Fcore)
2
2
 
3
- A Front-End Framework with a Built-in Low-Code Platform
4
- [Low-Code Platform](https://lowcode.jokers.pub)
5
-
6
- Joker is a framework platform designed to support all development scenarios. Among them, Joker.front is the front-end development framework under the Joker platform. It provides standardized front-end development standards and uses an object-oriented and component-based programming model to help you develop user interfaces efficiently. Whether it is a simple or complex interface, Joker.front can handle it with ease.
3
+ Joker is a framework platform designed to support all development scenarios. Among them, Joker.front is a front-end development framework under the Joker platform. It provides standardized front-end development standards and adopts an object-oriented and component-based programming model to help you develop user interfaces efficiently. Whether it's a simple or complex interface, Joker.front can handle it with ease.
7
4
 
8
5
  ## What is Joker?
9
6
 
10
- Joker is a framework platform that aims to support all development scenarios. Specifically, Joker.front, which is part of the Joker platform, is a front-end development framework. It offers standardized front-end development norms and employs an object-oriented and component-based programming approach to assist in the efficient creation of user interfaces. Regardless of whether the interface is simple or intricate, Joker.front can manage it smoothly.
7
+ Joker is a framework platform dedicated to supporting all development scenarios. Among them, Joker.front, as a part of the Joker platform, is a front-end development framework. It provides standardized front-end development specifications and uses object-oriented and component-based programming methods to assist in efficiently constructing user interfaces. No matter whether the interface is simple or complex, Joker.front can handle it smoothly.
11
8
 
12
- Joker is an all-round development platform constructed with TypeScript. It exhibits outstanding performance and stability, whether dealing with basic interface development requirements or complex user interface tasks. It encompasses the following significant features:
9
+ Joker is an all-round development platform built based on TypeScript. Whether it is to meet the needs of simple interface development or handle complex user interface tasks, it shows excellent performance and stability. It has the following important features:
13
10
 
14
- - **Powerful Extensibility**: Joker offers a component-based framework. With extensibility in mind during its initial design, it can be effortlessly integrated into existing projects or systems and supports the construction of scalable web applications, enabling customized development according to project needs.
15
- - **Abundant Component Library**: Joker.front provides a comprehensive set of front-end component libraries. These include carefully designed and optimized features and UI components such as routing and scaffolding, which assist developers in rapidly constructing aesthetically pleasing and high-performance user interfaces.
16
- - **Comprehensive Development Tools**: To further enhance development efficiency, Joker also supplies a series of supporting development tools, including debugging and building tools. These thoughtfully designed tools are intended to streamline the development process, facilitating developers in accurately and swiftly developing, building, testing, and updating code.
17
- - **Class API**: Joker utilizes TypeScript as the scripting development standard and adopts the standard Class API as the development guideline, which better aligns with object-oriented development requirements.
18
- - **Responsiveness**: Joker automatically tracks the state of JavaScript and updates the DOM in a reactive manner when changes occur. The reactive updates are instantaneous and do not involve virtual DOM difference comparison.
11
+ - **Powerful Extensibility**: Joker provides a component-based framework. Its extensibility has been taken into account from the very beginning of the design, so it can be easily integrated into existing projects or systems, supports the construction of scalable web applications, and can be customized according to project requirements.
12
+ - **Rich Component Library**: Joker.front provides a complete set of front-end component libraries, including carefully designed and optimized functional and UI components such as routing and scaffolding, which can help developers quickly build beautiful and high-performance user interfaces.
13
+ - **Complete Development Tools**: To further improve development efficiency, Joker also provides a series of supporting development tools, including debugging tools, building tools, etc. These carefully designed tools are aimed at making the development process smoother and helping developers develop, build, test and update code accurately and quickly.
14
+ - **Class API**: Joker uses TypeScript as the script development standard and adopts the standard Class API as the development specification, which is more in line with the requirements of object-oriented development.
15
+ - **Responsiveness**: Joker will automatically track the state of JavaScript. When it changes, it can update the DOM in a responsive manner immediately, and there is no difference comparison of the virtual DOM.
19
16
 
20
17
  ## How to Use
21
18
 
22
- You can utilize the Joker CLI to create projects, generate application and library code, and carry out various continuous development tasks such as testing, packaging, and deployment.
19
+ You can use the Joker CLI to create projects, generate application and library code, and perform various continuous development tasks, such as testing, packaging, and deployment.
20
+
21
+ [Help Documentation](https://front.jokers.pub)
23
22
 
24
- To install the Joker CLI, open a terminal/console window and execute the following command:
23
+ To install the Joker CLI, please open the terminal/console window and run the following command:
25
24
 
26
25
  ```
27
26
  pnpm i -g @joker.front/cli
28
27
  ```
29
28
 
30
- 1. Run the CLI command **joker create** and supply the name my-app as a parameter, as shown below:
29
+ 1. Run the CLI command **joker create** and provide the name my-app as a parameter, as shown below:
31
30
 
32
31
  ```
33
32
  joker create my-app
34
33
  ```
35
34
 
36
- 2. In the my-app working directory, install the dependencies.
35
+ 2. Install the dependencies in the working directory of my-app.
37
36
 
38
37
  ```
39
38
  cd my-app
@@ -41,13 +40,13 @@ cd my-app
41
40
  pnpm i
42
41
  ```
43
42
 
44
- The CLI will create a new workspace and a simple welcome application that you can run at any time.
43
+ The CLI will create a new workspace and a simple welcome application, which you can run at any time.
45
44
 
46
45
  ## Running the Application
47
46
 
48
- The Joker CLI includes a server command and a build command. The server command enables you to build and serve applications locally.
47
+ The Joker CLI includes a server command and a build command. The server command makes it convenient for you to build and provide application services locally.
49
48
 
50
- We provide two commands by default, namely `dev` and `build`, representing the development environment and code building respectively.
49
+ We provide two commands by default, namely `dev` and `build`, which represent the development environment and code building respectively.
51
50
 
52
51
  1. Navigate to the workspace folder, such as my-app.
53
52
 
@@ -61,15 +60,16 @@ cd my-app
61
60
  npm run dev
62
61
  ```
63
62
 
64
- Upon successful execution, a simple sample page will be displayed.
63
+ After successful operation, a simple sample page will be displayed.
64
+
65
+ ## Visual Development Tools
65
66
 
66
- ## Low-Code Visual Development
67
+ A front-end framework with a built-in visualization tool: [Low-code Platform](https://lowcode.jokers.pub)
67
68
 
68
- ![Low-Code Platform](readme/img4.png)
69
- ![Low-Code Platform](readme/img.jpg)
70
- ![Low-Code Platform](readme/img1.jpg)
71
- ![Low-Code Platform](readme/img3.jpg)
72
- ![Low-Code Platform](readme/img2.png)
69
+ ![Joker Low-code Platform](https://gitee.com/joker_pub/joker-front-core/raw/main/readme/img4.png)
70
+ ![Joker Low-code Platform](https://gitee.com/joker_pub/joker-front-core/raw/main/readme/img2.png)
71
+ ![Joker Low-code Platform](https://gitee.com/joker_pub/joker-front-core/raw/main/readme/img1.jpg)
72
+ ![Joker Low-code Platform](https://gitee.com/joker_pub/joker-front-core/raw/main/readme/img3.jpg)
73
73
 
74
74
  ## Documentation
75
75
 
@@ -77,13 +77,10 @@ Upon successful execution, a simple sample page will be displayed.
77
77
 
78
78
  [Official UI Library](https://ui.jokers.pub)
79
79
 
80
- [Low-Code Platform](https://jokers.pub)
80
+ [Low-code Platform](https://jokers.pub)
81
81
 
82
82
  # Joker
83
83
 
84
- 一个自带低代码平台的前端框架
85
- [低代码平台](https://lowcode.jokers.pub)
86
-
87
84
  Joker 是一个旨在为所有开发场景提供支持的框架平台。其中,Joker.front 是 Joker 平台下的前端开发框架,它提供标准化的前端开发标准,采用面向对象、组件化的编程模型,助力您高效开发用户界面。无论是简单还是复杂的界面,Joker.front 都能轻松应对。
88
85
 
89
86
  ## 什么是 Joker?
@@ -102,6 +99,8 @@ Joker 是一个基于 TypeScript 构建的全能开发平台。无论是应对
102
99
 
103
100
  您可以使用 Joker CLI 来创建项目、生成应用和库代码,以及执行各类持续开发任务,如测试、打包和部署。
104
101
 
102
+ [帮助文档](https://front.jokers.pub)
103
+
105
104
  要安装 Joker CLI,请打开终端/控制台窗口,并运行如下命令:
106
105
 
107
106
  ```
@@ -144,13 +143,14 @@ npm run dev
144
143
 
145
144
  成功运行后,将会显示一个简单的示例页面。
146
145
 
147
- ## 低代码可视化开发
146
+ ## 可视化开发工具
147
+
148
+ 一个自带可视化工具的前端框架:[低代码平台](https://lowcode.jokers.pub)
148
149
 
149
- ![低代码平台](readme/img4.png)
150
- ![低代码平台](readme/img.jpg)
151
- ![低代码平台](readme/img1.jpg)
152
- ![低代码平台](readme/img3.jpg)
153
- ![低代码平台](readme/img2.png)
150
+ ![Joker Platform](https://gitee.com/joker_pub/joker-front-core/raw/main/readme/img4.png)
151
+ ![Joker Platform](https://gitee.com/joker_pub/joker-front-core/raw/main/readme/img2.png)
152
+ ![Joker Platform](https://gitee.com/joker_pub/joker-front-core/raw/main/readme/img1.jpg)
153
+ ![Joker Platform](https://gitee.com/joker_pub/joker-front-core/raw/main/readme/img3.jpg)
154
154
 
155
155
  ## 文档
156
156
 
package/dist/bundle.es.js CHANGED
@@ -1 +1 @@
1
- import{EXPRESSHANDLERTAG as e,createFuntionBody as t,AST as i,RENDER_HANDLER as s,createComponent as n,createCommand as r}from"@joker.front/ast";export{AST,EXPRESSHANDLERTAG,RENDER_HANDLER,createCodeFunction,createCommand,createComment,createComponent,createElement,createFuntionBody,createText}from"@joker.front/ast";const o=new Map,a=new Map,h=new Map;let d={recordRender:(e,t)=>{a.set(e,t)},recordComponent:(e,t)=>{h.set(e,t)},record:(e,t)=>{void 0===o.get(e)&&o.set(e,new Set),o.get(e).add(t),t.$on("destroy",(()=>{o.get(e)?.delete(t)}))},reload:(e,t)=>{let i=h.get(e);if(!i)return;i.component=t;let s=o.get(e);if(!s)return;let n=Array.from(s);s.clear(),n.forEach((e=>{if(e.$root){if(!e.$rootVNode?.parent)return window.onbeforeunload=null,void location.reload();{let t=e.$rootVNode.parent;if(!(t instanceof X.Component&&t[X.PARSERKEY]&&t[X.PARSERKEY].canReload))return window.onbeforeunload=null,void location.reload();t[X.PARSERKEY].reload()}}}))},rerender:(e,t)=>{let i=a.get(e);i&&(i.render=t),o.get(e)?.forEach((e=>{e.$render(t)}))}};function l(e){return null!==e&&"object"==typeof e}function c(e,t){Object.getOwnPropertyNames(e).forEach((i=>{t(i,e[i])}))}function u(e){return"[object Object]"===Object.prototype.toString.call(e)}function f(e){if(null===e)return e;if("object"!=typeof e)return e;let t;t=Array.isArray(e)?[]:{};let i=Object.keys(e);for(let s of i){let i=e[s];t[s]="object"==typeof i?f(i):i}return t}function p(e,t,i){return Array.isArray(e)&&Array.isArray(t)?function(e,t,i){if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(i){if(e[s]!==t[s])return!1}else if(!1===m(e[s],t[s],i))return!1;return!0}(e,t,i):m(e,t,i)}function m(e,t,i){if(e===t)return!0;let s=l(e),n=l(t);if(s&&n){if(u(e)&&u(t)){let s=Object.keys(e);if(s.length!==Object.keys(t).length)return!1;if(i){for(let i of s)if(e[i]!==t[i])return!1;return!0}return JSON.stringify(e)===JSON.stringify(t)}return e===t}return!s&&!n&&String(e)===String(t)}function y(e,t){let i=e.indexOf(t);return i>-1&&e.splice(i,1),e}function E(e,t){let i=e.findIndex((e=>t(e)));return i>-1&&e.splice(i,1),e}function v(e=32){let t=[],i=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];for(let s=0;s<e;s++){let e=Math.round(Math.random()*(i.length-1));t.push(i[e])}return t.join("")}function g(e){return!e||""===e.trim()}function w(e,t="-"){return(e=e||"").split(/(?=[A-Z])/).map((e=>e.toLowerCase())).join(t)}let b=(...e)=>{},N="warn";const R=["silent","error","warn","info"];function $(){let e=new Date;function t(e,t=2){return e.toString().padStart(t,"0")}return t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+":"+t(e.getMilliseconds(),3)}function C(e,t,i,s){R.indexOf(e)<=R.indexOf(N)&&(void 0===s?console[e](`${$()} [${t}]:`,i):console[e](`${$()} [${t}]:`,i,s))}let A={info:function(e,t,i){C("info",e,t,i)},warn:function(e,t,i){C("warn",e,t,i)},error:function(e,t,i){C("error",e,t,i)},setLoggerLeve:function(e){N=e}};const O={lt:"<",gt:">",nbsp:" ",amp:"&",quot:'"',"#39":"'"};function x(e){return e.replace(/&(lt|gt|nbsp|amp|quot|#39);/gi,((e,t)=>O[t]||""))}class S{static target;watchers=new Map;depend(e){S.target?.addDep(this,e)}addWatcher(e,t){let i=this.watchers.get(e)||[];i.push(t),this.watchers.set(e,i)}removeWatcher(e,t){let i=this.watchers.get(e);i&&y(i,t)}notify(e){let t=this.watchers.get(e);if(t){E(t,(e=>e.isDestroy)),[...t].forEach((e=>{!1===e.isDestroy&&e.update()}))}}}const P=Symbol.for("__JOKER_OBJECT_PROXY_DEP_ID__"),T=Symbol.for("__JOKER_OBJECT_PROXY_DATA_KEY__"),D=Symbol.for("__JOKER_OBJECTPROXY_DEPLEVE_ID__");function _(e){return l(e)&&e instanceof Window==!1&&e instanceof q==!1&&e!==window.parent&&(Array.isArray(e)||u(e)||e instanceof Set||e instanceof Map)&&!Object.isFrozen(e)&&!(e instanceof Element)&&!(z in e)&&!(V in e)&&!(ze in e)}function K(e){if(k(e))return e;if(Object.hasOwn(e,T)){let t=Reflect.get(e,T);if(t)return t}let t=new S,i=!0,s=new Proxy(e,{get(e,i,s){if(e instanceof Set||e instanceof Map){if("add"===i){let s=Reflect.get(e,i);return i=>{_(i)&&(i=W(i));let n=s.call(e,i);return Y(t,"size"),Y(t,D),n}}if("set"===i){let s=Reflect.get(e,i);return(i,n)=>{_(n)&&(n=W(n));let r=s.call(e,i,n);return Y(t,"size"),Y(t,D),r}}if("delete"===i||"clear"===i){let s=Reflect.get(e,i);return n=>{let r=s.call(e,n);return("clear"===i||r)&&(Y(t,"size"),Y(t,D)),r}}let s=Reflect.get(e,i);if("function"==typeof s)return s.bind(e)}if(i===T)return;if(i===P)return t;if(i===D)return;let n=Reflect.get(e,i);return i===Symbol.toStringTag||!1===function(e,t){return t in e}(e,i)&&"length"!==i&&"size"!==i||(t.depend(i),_(n)&&k(n)?.depend(D)),n},set(e,s,n){if(i)return Reflect.set(e,s,n),!0;_(n)&&(n=W(n));let r=!1===function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,s),o=Reflect.get(e,s)!==n;return Reflect.set(e,s,n),(o||"length"===s&&Array.isArray(e))&&Y(t,s),Array.isArray(e)?"length"===s&&Y(t,D):r&&Y(t,D),!0},deleteProperty:(e,i)=>(Reflect.deleteProperty(e,i),!1===Array.isArray(e)&&Y(t,D),!0)});var n,r,o,a;n=e,r=T,o=s,a=!1,Object.defineProperty(n,r,{value:o,enumerable:a,writable:!0,configurable:!0});for(let t in e){let i=e[t];_(i)&&!k(i)&&(s[t]=K(e[t]))}return i=!1,s}function k(e){if(l(e))return Reflect.get(e,P)}function W(e,t=!1){if(!1===_(e))throw new Error("当前传入的数据不是正确的数据类型,必须是数组或者对象");return K(t?f(e):e)}function I(e,t,i){let s=i;_(i)&&(s=W(i));let n=new S;Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:()=>(n.depend(t),k(s)?.depend(D),s),set:e=>{e!==s&&(_(e)&&(e=W(e)),s=e,Y(n,t))}})}const V=Symbol.for("JOKER_SHALLOW_OBSERVER");class L{data;[V]=!0;dep=new S;constructor(e){this.data=e}isChanged=!1;get value(){return this.dep.depend(D),this.data}set value(e){!1===Object.is(e,this.data)&&(this.isChanged=!0,this.data=e,Y(this.dep,D))}}let M=!1,j=new Map;function Y(e,t){if(!1===M)e.notify(t);else{let i=j.get(e);void 0===i&&(i=[],j.set(e,i)),!1===i.includes(t)&&i.push(t)}}function B(e){M=!0;try{e()}catch(e){return M=!1,j.clear(),void A.error("数据劫持","数据劫持组合回复在做变更采集时,遇到了阻塞错误,不做响应,请检查",e)}M=!1,function(e){let t=[],i=[];e.forEach(((e,i)=>{e.forEach((e=>{t.push(...i.watchers.get(e)||[])}))})),t.forEach((e=>{i.includes(e)||(!1===e.isDestroy&&e.update(),i.push(e))}))}(j),j.clear()}function H(e){return void 0!==k(e)}const J="数据观察",F=Symbol.for("JOKER_BREAK_WATCH_UPDATE");class q{ob;updateCallBack;forceCallBack;getter;value;isDestroy=!1;updating=!1;runRelations=new Map;relations=new Map;constructor(e,t,i,s){if(this.ob=e,this.updateCallBack=t,this.forceCallBack=s,void 0===e)throw new Error("无法对underfind进行变更观察");if(void 0===i)this.getter=e=>e;else if("function"==typeof i)this.getter=i;else{let e=function(e){if(/[^\w.$]/.test(e))return;let t=e.split(".");return function(e){let i=e;return t.forEach((e=>{i&&(i=i[e])})),i}}(i);if(void 0===e)throw new Error(i+"解析失败,无法明确读取表达式,请检查expOrFn参数,或采用function模式");this.getter=e}void 0===this.getter&&A.error(J,"getter创建失败",arguments),this.value=this.getValue()}getValue(){if(void 0===this.getter)return;S.target=this;let e,t="function"==typeof this.ob?this.ob():this.ob;try{e=this.getter.call(t,t)}catch(e){throw A.error(J,`获取值失败,执行方法:${this.getter.toString()}`),e}return S.target=void 0,this.clearnDeps(),e}addDep(e,t){let i=this.runRelations.get(e);if(void 0===i||!1===i.includes(t)){i=i||[],i.push(t),this.runRelations.set(e,i);let s=this.relations.get(e);void 0!==s&&!1!==s.includes(t)||e.addWatcher(t,this)}}update(){if(this.updating)return;let e=this.getValue();if(e===F)return;let t=this.value;if(this.forceCallBack||e!==t||l(e)){this.value=e;let i=e!==t&&p(e,t,!0);if(i&&!this.forceCallBack)return;this.updating=!0;try{this.updateCallBack(e,t,i,this)}catch(e){throw e}finally{this.updating=!1}}}destroy(){this.relations.forEach(((e,t)=>{for(let i of e)t.removeWatcher(i,this)})),this.isDestroy=!0,this.relations.clear(),this.runRelations.clear(),this.ob=void 0,this.value=void 0,this.getter=void 0}clearnDeps(){this.relations.forEach(((e,t)=>{let i=this.runRelations.get(t);for(let s of e)i?!1===i.includes(s)&&t.removeWatcher(s,this):t.removeWatcher(s,this)})),this.relations.clear(),this.relations=this.runRelations,this.runRelations=new Map}}var G;!function(e){let t=new Map;e.bind=function(e){return{to:i=>{if(t.has(e))throw new Error(`TagId:${e.toString()}已注入实现类,请勿重复注入。`);t.set(e,i)}}},e.get=function(e,...i){let s=t.get(e);if(s)return new s(...i)}}(G||(G={}));const z=Symbol.for("JOKER_VNODE_TAG");var X;!function(e){e.PARSERKEY=Symbol.for("JOKER_PARSER_KEY");class t{parent;[z]=!0;static;output;[e.PARSERKEY];childrens;sleep=!1;constructor(e){this.parent=e}get prev(){if(this.parent)return this.parent.childrens?.[this.parent.childrens?.indexOf(this)-1]}get next(){if(this.parent)return this.parent.childrens?.[this.parent.childrens?.indexOf(this)+1]}closest(t,i){if(!0===t(this))return this;let s=this.parent;for(;s;){if(i&&s instanceof e.Root)return;if(!0===t(s))return s;s=s.parent}}find(e,t,i){let s=i??[];if(t??=this.childrens,t)for(let i of t){!0===e(i)&&s.push(i),i.childrens&&this.find(e,i.childrens,s)}return s}contains(e,t){if(t??=this.childrens,t)for(let i of t){if(!0===e(i))return!0;if(i.childrens&&i.childrens.length&&this.contains(e,i.childrens))return!0}return!1}first(e,t){if(t??=this.childrens,t)for(let i of t){if(!0===e(i))return i;if(i.childrens&&i.childrens.length){let t=this.first(e,i.childrens);if(t)return t}}}}e.Node=t;e.Root=class extends t{childrens=[];component;constructor(){super()}};e.Text=class extends t{text;static=!0;constructor(e,t){super(t),this.text=e}};e.Html=class extends t{html;notShadow;static=!0;constructor(e,t,i){super(t),this.html=e,this.notShadow=i}};e.Comment=class extends t{text;static=!0;constructor(e,t){super(t),this.text=e}};e.Element=class extends t{tagName;static=!0;attributes={};childrens=[];events=[];_assistEventCache;constructor(e,t){super(t),this.tagName=e}};e.Component=class extends t{name;component;events=[];propValues={};keepalive;get firstElement(){if(this.childrens){let t=i=>{for(let s of i){if(s instanceof e.Element)return s;if(s.childrens){let e=t(s.childrens);if(e)return e}}};return t(this.childrens)}}get rootElements(){if(this.childrens){let t=[],i=s=>{for(let n of s)n instanceof e.Element||n instanceof e.Html?t.push(n):n.childrens&&i(n.childrens)};return i(this.childrens),t}return[]}};e.Condition=class extends t{cmdName;result=!1;childrens=[];isShow=!1;constructor(e,t){super(t),this.cmdName=e}};e.List=class extends t{childrens=[]};e.ListItem=class extends t{ob;childrens=[];constructor(e,t){super(t),this.ob=e}};e.RenderSection=class extends t{id="unknown";params=[];section;childrens=[];ob;constructor(e,t){super(t),"string"==typeof e?this.id=e:this.section=e}}}(X||(X={}));const Q="DOM渲染",U=["script","style","textarea","pre"];let Z=0;const ee=["svg","defs","use","rect","circle","ellipse","line","polyline","polygon","path","text","g"];var te;function ie(e,t,i){return`${e}-${t}-${i}`}function se(e,t,i,s){e._assistEventCache??=[],e._assistEventCache.push([t,i]),document.body.addEventListener(t,i,s)}function ne(e,t,i){e._assistEventCache&&t&&i?(E(e._assistEventCache,(e=>e[0]===t&&e[1]===i)),document.body.removeEventListener(t,i)):(e._assistEventCache?.forEach((e=>{document.body.removeEventListener(e[0],e[1])})),e._assistEventCache&&(e._assistEventCache.length=0),e._assistEventCache=void 0)}!function(e){e.IRENDERIOCTAGID=Symbol.for("JOKER_IRENDERIOC_TAGID"),e.ROOT_CONTAINER="";e.DomRender=class{elements;constructor(){this.elements=document.createDocumentFragment()}mount(e,t){if(e instanceof Element)e.appendChild(this.elements),t?.();else if(e instanceof X.Component)if(e.parent)if(e.output){let i=e.output,s=de(e)||i.parentNode;s&&(s.insertBefore(this.elements,i),document.contains(s)&&t?.())}else A.error(Q,"组件挂载渲染时发现该节点未定义DOM定位节点",e);else A.error(Q,"mount子组件时,发现该组件无父级",e);else A.error(Q,"mount只支持挂载到Element或VNode.Node类型数据中",e)}appendNode(e,t){if(this.renderNode(e),e.output){let i=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];for(let s of i)this.appendNodeChildren(e,s,e.parent,t)}else A.error(Q,"未找自身节点的el属性,无法进行dom挂载",e)}updateNode(e,t){if(e instanceof X.Element)for(let t in e.attributes){let i=e.attributes[t];this.setAttribute(e.output,t,i)}else e instanceof X.Text?e.parent&&e.parent instanceof X.Element&&U.includes(e.parent.tagName)?(this.removeNode(e),this.appendNode(e)):e.output.textContent=x(e.text||""):e instanceof X.Html?e.notShadow?e.output.innerHTML=e.html:e.output.root.innerHTML=e.html:A.error(Q,`该节点不支持${t}的更新`,e)}removeNode(e,t){let i=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];i?.forEach((e=>{e?.remove()})),t||(e instanceof X.Element&&ne(e),e.output=void 0)}destroy(){this.elements=void 0}elementToEnter(e,t,i,s){e.output&&this.transitionFrame(e,t,"enter",i,s)}elementToLeave(e,t,i,s){e.output&&this.transitionFrame(e,t,"leave",i,s)}triggerEvent(e,t,i){let s=[];for(let n of e.events){let[r,o]=n;if(r===t){let t=o.modifiers?.includes("self"),a=o.modifiers?.includes("outside");if(t||a){A.warn(Q,"事件修饰符:self、outside在组件事件中无法使用,组件无法确认元素",e);continue}let h=i.event;if((h instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(r)||h instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(r))&&!1===oe(h,o.modifiers))continue;if(o.callBack(i),o.modifiers?.includes("prevent")&&i.preventDefault(),o.modifiers?.includes("once")&&s.push(n),o.modifiers?.includes("stop"))return i.stopPropagation(),!1}}s.length&&s.forEach((t=>{y(e.events,t)}))}transitionFrame(e,t,i,s,n){ae(e,ie(t,i,"from")),s||="transition";let r=e.output.__TRANSITION_EVNETID__=Z++;requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(!e.output)return;ae(e,ie(t,i,"active")),he(e,ie(t,i,"from")),ae(e,ie(t,i,"to"));let o=function(e,t){let i=window.getComputedStyle(e),s=e=>(i[e]||"").split(", ");if("transition"===t){let e=s("transitionDelay"),t=s("transitionDuration"),i=le(e,t);if(i>0)return{timeout:i,count:t.length}}else if("animation"===t){let e=s("animationDelay"),t=s("animationDuration"),i=le(e,t);if(i>0)return{timeout:i,count:t.length}}}(e.output,s);if(!o)return void n?.();let a=0,h=()=>{he(e,ie(t,i,"to")),he(e,ie(t,i,"active")),e.output&&(e.output.removeEventListener(`${s}end`,d),r===e.output.__TRANSITION_EVNETID__&&n?.())},d=t=>{t.target===e.output&&++a>=o.count&&h()};setTimeout((()=>{a<o.count&&h()}),o.timeout+1),e.output?.addEventListener(`${s}end`,d)}))}))}renderNode(e){if(!e.output)if(e instanceof X.Text)e.parent&&e.parent instanceof X.Element&&U.includes(e.parent.tagName)?e.output=this.parserHtml(e.text):e.output=document.createTextNode(x(e.text||""));else if(e instanceof X.Html)if(e.notShadow){let t=document.createElement("joker-html-container");t.JOKER_NODE=e,t.innerHTML=e.html,e.output=t}else{let t=document.createElement("joker-html-shadow");t.JOKER_NODE=e,t.style.lineHeight="1",t.root.innerHTML=e.html,e.output=t}else if(e instanceof X.Element){let t,i=e.tagName.toLowerCase();"svg"===i||ee.includes(i)||e.parent?.inSvg?(e.inSvg=!0,t=document.createElementNS("http://www.w3.org/2000/svg",e.tagName)):t=document.createElement(e.tagName);for(let i in e.attributes)this.setAttribute(t,i,e.attributes[i]);t.JOKER_NODE=e,e.output=t,e.events.some((e=>"click"===e[0]&&e[1].modifiers?.includes("outside")))?setTimeout((()=>{this.initElementEvents(t,e)})):this.initElementEvents(t,e)}else e instanceof X.Comment?e.output=document.createComment(e.text):e.output=document.createTextNode("")}initElementEvents(e,t){for(let[i,s]of t.events){let n=s.modifiers?.includes("self"),r=s.modifiers?.includes("outside");n&&r&&(A.warn(Q,"事件修饰符:self、outside不可以同时存在,将按照self处理",t),r=!1);let o,a=function(o){if(!(t.sleep||n&&o.target!==e)){if(r){if(o.target===e||e.contains(o.target))return;if(!1===document.contains(o.target))return;if(t.contains((e=>(e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output]).includes(o.target))))return!0}(o instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(i)||o instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(i))&&!1===oe(o,s.modifiers)||(s.callBack({eventName:i,event:o,target:t,preventDefault:()=>o.preventDefault(),stopPropagation:()=>o.stopPropagation(),data:void 0}),s.modifiers?.includes("prevent")&&o.preventDefault(),s.modifiers?.includes("stop")&&o.stopPropagation(),s.modifiers?.includes("once")&&(r?ne(t,i,a):e.removeEventListener(i,a)))}};s.modifiers?.includes("passive")&&(o={passive:!0}),r?se(t,i,a,o):e.addEventListener(i,a,o)}}parserHtml(e){var t=document.createElement("div");return t.innerHTML=e,t.childNodes}isCommandGroup(e){return e instanceof X.Component||e instanceof X.Condition||e instanceof X.List||e instanceof X.ListItem||e instanceof X.RenderSection}appendNodeChildren(e,t,i,s){let n=de(e);if(n)n.appendChild(t);else if(void 0===i)this.elements?.appendChild(t);else if(i)if(i instanceof X.Root){let e=i.parent;if(e&&e instanceof X.Component&&e.output){let i=e.output,s=i?.parentNode;if(s)return void s.insertBefore(t,i)}this.elements?.appendChild(t)}else if(i instanceof X.Element){let e=i.output;if(void 0===e)return;e.appendChild(t)}else if(this.isCommandGroup(i)){let e=i.output,n=e?.parentNode;if(void 0!==s&&i.childrens?.length&&n){let e=s-1;if(e<0)return void n.insertBefore(t,n.firstChild);{let s=i.childrens[e];if(s){let e=s.output;if(e)return void e.after(t)}}}n&&n.insertBefore(t,e)}else A.error(Q,"该节点不支持嵌套子集,请检查。",{node:e,parent:i})}setAttribute(e,t,i){if(e)if("boolean"!=typeof i){if("class"===t){if(Array.isArray(i)){let e=[];for(let t of i)if(l(t))for(let i in t)t[i]&&e.push(i);else t&&e.push(t);i=e.join(" ")}else if(l(i)){for(let t in i)i[t]?e.classList.add(t):e.classList.remove(t);return}}else if("style"===t&&l(i)){e.removeAttribute("style");for(let t in i){let s=!1;void 0!==i[t]&&!1!==i[t]||(s=!0);let n=String(i[t]);g(n)&&(s=!0),s||(e.style[t]=n)}return}i=(i??"").toString().trim(),"class"===t&&(i=i.split(/\s/).filter((e=>e.trim())).join(" ")),"value"===t&&"value"in e?e.value=i:"xlink:href"===t?e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",i):e.setAttribute(t,i)}else i?e.setAttribute(t,""):e.removeAttribute(t)}}}(te||(te={}));const re={enter:"enter",backspace:"delete",tab:"tab",arrowup:"up",arrowdown:"down",arrowleft:"left",arrowright:"right",escape:"esc"," ":"space"};function oe(e,t){if(e instanceof KeyboardEvent){if(void 0===e.key)return!1;for(let i in re)if(t?.includes(re[i])&&e.key.toLowerCase()!==i)return!1}else{if(t?.includes("left")&&0!==e.button)return!1;if(t?.includes("right")&&2!==e.button)return!1;if(t?.includes("middle")&&1!==e.button)return!1}return(!t?.includes("ctrl")||!1!==e.ctrlKey)&&((!t?.includes("alt")||!1!==e.altKey)&&(!t?.includes("shift")||!1!==e.shiftKey))}function ae(e,t){e.output&&e.output.classList.add(t)}function he(e,t){e.output&&e.output.classList.remove(t)}function de(e){if(e instanceof X.Element||e instanceof X.Component){let t=e instanceof X.Component?e.propValues["append-to"]:e.attributes["append-to"];if(t){if(t instanceof X.Element)return t.output;if("string"==typeof t){te.ROOT_CONTAINER&&(t="body"===t?te.ROOT_CONTAINER:`${te.ROOT_CONTAINER} ${t}`);let e=document.querySelector(t);if(e)return e}A.warn(Q,"appendTo类型不支持",{appendTo:t,node:e})}}}function le(e,t){for(;e.length<t.length;)e.concat(e);return Math.max(...t.map(((t,i)=>ce(t)+ce(e[i]))))}function ce(e){return"auto"===e?0:1e3*Number(e.slice(0,-1).replace(",","."))}class ue extends HTMLElement{root;constructor(){super(),this.root=this.attachShadow({mode:"open"})}}!customElements.get("joker-html-shadow")&&customElements.define("joker-html-shadow",ue);const fe={};function pe(e){for(let t in e)fe[t]=e[t]}const me="Global",ye="渲染核心";function Ee(t){try{return new Function(e,me,`return ${t};`)}catch{throw new Error("创建表达式运行方法时出现未知错误,表达式为"+t)}}class ve{ast;ob;parent;ext;ref="";watchers=[];node;isDestroy=!1;constructor(e,t,i,s){this.ast=e,this.ob=t,this.parent=i,this.ext=s}init(e){let t=this.parser(e);if(this.afterParser(),t)return t}beforeDestroy(e){}destroy(e){if(this.isDestroy=!0,this.clearWatchers(),this.parent.childrens&&this.node){(this.node instanceof X.Element||this.node instanceof X.Component)&&this.ext.removeRef(this.node);let t=()=>{this.parent&&this.node&&(this.beforeDestroy(e),this.destroyChildrens(e),this.ext.render?.removeNode(this.node),this.parent.childrens&&y(this.parent.childrens,this.node),this.notifyNodeWatcher("remove"),this.destroyOtherData())};if(this.ext.nodeTransition(this.node,"leave",void 0,(()=>{t()})))return y(this.parent.childrens,this.node),void this.destroyChildrensWatcher(this.node);t()}else this.destroyOtherData()}destroyWathcers(){this.isDestroy=!0,this.clearWatchers(),this.destroyChildrensWatcher(this.node)}destroyOtherData(){this.node&&(this.node[X.PARSERKEY]=void 0),this.node=void 0,this.parent=void 0}destroyChildrens(e){for(;this.node?.childrens?.length;){let t=this.node.childrens[0];t[X.PARSERKEY]?t[X.PARSERKEY].destroy(e):y(this.node.childrens,t)}}destroyChildrensWatcher(e){if(e?.childrens?.length)for(let t of e?.childrens)t[X.PARSERKEY]&&(t[X.PARSERKEY].clearWatchers(),this.destroyChildrensWatcher(t))}appendNode(e){this.parent?.childrens&&this.node&&!this.isDestroy&&(this.node[X.PARSERKEY]=this,this.node instanceof X.Element&&this.ob[Ge]&&(this.node.attributes["data-scoped-"+this.ob[Ge]]=void 0),this.ext.render?.appendNode(this.node,e),void 0===e?this.parent.childrens.push(this.node):this.parent.childrens.splice(e,0,this.node),this.notifyNodeWatcher("append"))}afterParser(){this.ext.nodeTransition(this.node,"enter")}notifyNodeWatcher(e,t){this.ext.notifyNodeWatcher(this.ref,this.node,e,t)}runExpress(e,t){try{return Ee(e).call(t,t,fe)}catch(i){A.error(ye,"运行表达式出现错误:"+e,{ob:t}),console.error(i)}}runExpressWithWatcher(e,t,i,s){if(this.isDestroy)return;let n="string"==typeof e?Ee(e):e,r=new q((()=>{if(this.isDestroy||t[Je])return F;try{return n.call(t,t,fe)}catch(i){return A.error(ye,"运行表达式出现错误",{ob:t,express:e,node:this.node}),console.error(i),F}}),i,void 0,s);return this.addWatch(r),r.value===F?void 0:r.value}addWatch(e){!1===this.watchers.includes(e)&&this.watchers.push(e)}clearWatchers(){this.watchers.forEach((e=>{e.destroy()})),this.watchers.length=0}}class ge extends ve{parser(){this.node=new X.Text(this.ast.text,this.parent),this.appendNode()}}class we extends ve{parser(){this.node=new X.Comment(this.ast.text,this.parent),this.appendNode()}}class be extends ve{async parser(){if(this.node=new X.Condition(this.ast.kind,this.parent),"else"!==this.ast.kind){g(this.ast.condition)&&A.error("条件命令",`当前条件命令${this.ast.kind}没有判断条件,请检查`);let e=this.runExpressWithWatcher(this.ast.condition,this.ob,(e=>{let t=!!e;if(this.node?.result!==t){if(this.node.result=t,!1===t&&this.node?.isShow)this.destroyChildrens(!0);else if(t&&!this.node?.isShow){let e=this.getElseNode();if(e&&e.isShow&&e.childrens?.length){let t=e[X.PARSERKEY];t&&t instanceof be&&t.renderConditionChildren()}}this.renderId=v(),this.reloadAllCondition(this.renderId)}}));this.node.result=!!e}this.appendNode(),this.renderId=v(),await this.renderConditionChildren()}renderId;getElseNode(){let e=this.node?.next;for(;e&&e instanceof X.Condition&&"if"!==e.cmdName;){if("else"===e.cmdName)return e;e=e.next}}async renderConditionChildren(){let e=!1;return this.getPrevIfResult()?e=!1:"else"===this.ast.kind?e=!0:(this.node.result=!!this.runExpress(this.ast.condition,this.ob),this.node.result&&(e=!0)),e!==this.node.isShow&&(this.node.isShow=e,this.destroyChildrens(!0),e&&this.ast.childrens&&await this.ext.parserNodes(this.ast.childrens,this.node,this.ob),!0)}getPrevIfResult(){if("if"===this.ast.kind)return!1;let e=this.node?.prev;for(;e&&e instanceof X.Condition;){if(e.result)return!0;if("if"===e.cmdName)break;e=e.prev}return!1}async reloadAllCondition(e){if(await this.renderConditionChildren()&&e===this.renderId){let t=this.node?.next;for(;t&&t instanceof X.Condition&&"if"!==t.cmdName;){let i=t[X.PARSERKEY];if(i&&i instanceof be&&(await i.renderConditionChildren(),e!==this.renderId))return;t=t.next}}if(e===this.renderId){let t=this.node?.next;for(this.node?.result||this.destroyChildrens(!0);t&&t instanceof X.Condition&&"if"!==t.cmdName;){let i=t[X.PARSERKEY];if(i&&i instanceof be&&(await i.renderConditionChildren(),e!==this.renderId))return;t=t.next}}}}class Ne extends ve{async parser(){this.node=new X.List(this.parent),this.appendNode(),await this.renderChildrens()}async renderChildrens(){switch(this.renderId=v(),this.ast.keyType){case"condition":await this.renderConditionChildrens();break;case"in":case"of":await this.renderInOrOfChildrens()}}async renderConditionChildrens(){let t=this.ast.param,i=Object.create(this.ob),s=!!this.runExpressWithWatcher(function(t,i,s){try{return new Function(e,`${e}.${t}=${i}; return ${s};`)}catch{throw new Error(`For循环命令,表达式运行依赖采集出现未知错误,其中letKey:${t},keyVal:${i},condition:${s}`)}}(t.letKey,t.defaultKeyVal,t.condition),i,(()=>{this.clearWatchers(),this.renderChildrens()}),!0);await(async e=>{let n=0,r=[];for(;s;){let o=Object.create(this.ob);I(o,t.letKey,i[t.letKey]);let a=n++,h=this.renderItem(o,a),d=()=>{this.renderId===e&&this.runExpressWithWatcher((()=>i[t.letKey]),i,((e,i,s,n)=>{Promise.resolve().then((()=>{n.isDestroy||(o[t.letKey]=e,s||this.updateListItemOb(o,a))}))}),!0)};h instanceof Promise?r.push(h.then((()=>d()))):d(),this.runExpress(t.step,i),s=!!this.runExpress(t.condition,i)}if(r.length)await Promise.all(r).then((()=>{this.renderId===e&&this.destroyOldChildrens(n)}));else{if(this.renderId!==e)return;this.destroyOldChildrens(n)}})(this.renderId)}renderId;async renderInOrOfChildrens(){let e=this.ast.param,t=this.runExpressWithWatcher(e.dataKey,this.ob,(()=>{this.clearWatchers(),this.renderChildrens()}));await(async i=>{let s=0,n=[];if(t&&(Array.isArray(t)||u(t)))for(let r in t){let o=Object.create(this.ob),a=Array.isArray(t)?Number(r):r;e.indexKey&&I(o,e.indexKey,a),e.itemKey&&I(o,e.itemKey,t[r]);let h=s++,d=()=>{this.renderId===i&&e.itemKey&&this.runExpressWithWatcher((()=>t[a]),t,((i,s,n,r)=>{a in t&&Promise.resolve().then((()=>{r.isDestroy||(o[e.itemKey]=i,n||this.updateListItemOb(o,h))}))}),!0)},l=this.renderItem(o,h,e.indexKey);l instanceof Promise?n.push(l.then((()=>d()))):d()}if(n.length)await Promise.all(n).then((()=>{this.renderId===i&&this.destroyOldChildrens(s)}));else{if(this.renderId!==i)return;this.destroyOldChildrens(s)}})(this.renderId)}findIndexByIndex(e,t,i){let s=-1;if(this.node)for(let n=t;n<this.node.childrens.length;n++)if(this.checkObEqual(e,this.node.childrens[n]?.ob,i?[i]:void 0)){s=n;break}return s}renderItem(e,t,i){if(!this.ast.childrens?.length||!this.node)return;let s=this.node.childrens?.[t];if(s){if(this.checkObEqual(e,s.ob,i?[i]:void 0))return void(i&&s.ob[i]!==e[i]&&(s.ob[i]=e[i]));let n=this.findIndexByIndex(e,t+1,i);if(n>-1){if(t+1===n)this.node.childrens?.[t]?.[X.PARSERKEY]?.destroy();else for(let e=0;e<n-t-1;e++)this.node.childrens?.[t]?.[X.PARSERKEY]?.destroy();return this.renderItem(e,t,i)}return new Re(this.ast,e,this.node,this.ext).init(t)}return new Re(this.ast,e,this.node,this.ext).init()}updateListItemOb(e,t){if(!this.ast.childrens?.length||!this.node)return;let i=this.node.childrens?.[t];c(e,((e,t)=>{i.ob[e]!==t&&(i.ob[e]=t)}))}destroyOldChildrens(e){if(this.node)for(;this.node.childrens.length>e;){let e=this.node.childrens.pop();if(!e)break;e[X.PARSERKEY]?.destroy(!1)}}checkObEqual(e,t,i){let s=!0;return void 0!==t&&(c(e,((e,n)=>{i?.includes(e)||t?.[e]===n||(s=!1)})),s)}}class Re extends ve{async parser(e){this.node=new X.ListItem(this.ob,this.parent),this.appendNode(e),this.ast.childrens&&await this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}}function $e(e,t){if(!e)return e;if(e instanceof Promise)return e.then((e=>Promise.resolve(e)));if(Array.isArray(e)&&e.length){let i=[];for(let s in e){let n,r=e[s];n=t?$e(r,t):r,n instanceof Promise&&i.push(n.then((t=>{e[s]=t})))}if(i.length>0)return Promise.all(i).then((()=>Promise.resolve(e)))}else if("object"==typeof e&&null!==e&&u(e)&&e instanceof Element==!1){let i=[];for(let s in e){let n=e[s];if(n instanceof Promise)i.push(n.then((t=>{e[s]=t})));else if(t){let e=$e(n,t);e instanceof Promise&&i.push(e)}}if(i.length)return Promise.all(i).then((()=>e))}return e}function Ce(e,t){if(!e.constructor)return!1;let i=Object.getOwnPropertyDescriptor(e.constructor.prototype,t);return i&&i.get}class Ae extends ve{parser(){if(g(this.ast.cmdName))throw A.error("模板指令","解析AST转换VNode时发生错误,未找到指令名称",this.ast),new Error("解析AST转换VNode时发生错误,未找到指令名称");let e;if("Html"===this.ast.cmdName||"Text"===this.ast.cmdName?e=this.ast.param:this.ast.cmdName.startsWith(me+".")?e=`${this.ast.cmdName}(${this.ast.param})`:this.ast.cmdName in this.ob&&"function"==typeof this.ob[this.ast.cmdName]&&(e=`${t(this.ast.cmdName)}(${this.ast.param})`),e){let t=this.runExpressWithWatcher(`[${e}]`,this.ob,(t=>{let i=$e(t[0]);i instanceof Promise?i.then((e=>{this.changeValue(e)})).catch((t=>{A.error("表达式编译",`${e}异步处理失败`,t)})):this.changeValue(i)}));t||=[];let i=$e(t[0]);return i instanceof Promise?("Html"===this.ast.cmdName?this.node=new X.Html("",this.parent,t[1]):this.node=new X.Text("",this.parent),i.then((e=>{this.changeValue(e)})).catch((t=>{A.error("表达式编译",`${e}异步处理失败`,t)}))):"Html"===this.ast.cmdName?this.node=new X.Html(Oe(i),this.parent,t[1]):this.node=new X.Text(Oe(i),this.parent),void this.appendNode()}throw new Error(`未找到命令:${this.ast.cmdName}`)}changeValue(e){this.node&&(this.node instanceof X.Html?this.node.html=Oe(e):this.node.text=Oe(e),this.ext.render?.updateNode(this.node))}}function Oe(e){return null==e||"function"==typeof e?"":e.toString()}const xe="default";class Se extends ve{async parser(){let e=this.transformParam();this.node=new X.RenderSection(e.id,this.parent),this.node.params=e.params,this.node.section??=this.ob.$sections?.[e.id],this.appendNode(),this.node.section&&(this.node.section.params?(this.node.ob=Object.create(this.node.section.ob||this.ob),this.node.section.params?.forEach(((e,t)=>{I(this.node.ob,e,this.node.params[t])}))):this.node.ob=this.node.section.ob||this.ob,await(this.node.section.parser||this.ext).parserNodes(this.node.section.asts,this.node,this.node.ob))}transformParam(){if(this.ast.param){let e=this.runExpressWithWatcher(`[${this.ast.param}]`,this.ob,(e=>{let t=e?.[0]||xe;if("string"==typeof t&&t!==this.node.id)throw new Error("section id 不可动态变更");this.node.params=e.slice(1),this.node?.ob&&this.node.section&&this.node.section.params?.forEach(((e,t)=>{this.node?.ob&&this.node.ob[e]!==this.node.params[t]&&(this.node.ob[e]=this.node.params[t])}))}),!0);return{id:e?.[0]||xe,params:e?.slice(1)||[]}}return{id:xe,params:[]}}}const Pe="组件解析";function Te(e,t){return!!t.components[e]||!!tt(e)}class De extends ve{async parser(){if(this.ast.node)return this.node=this.ast.node,this.node.parent=this.parent,this.initPropData(),void(this.node&&(this.appendNode(),this.node.component?.$mount(this.node)));this.node=new X.Component(this.parent);let e=this.initPropData();this.appendNode(),this.node&&this.initEvent(),e.length&&await Promise.all(e),await this.renderChildren()}get canReload(){return"tagName"in this.ast||"function"==typeof this.ast.component}reload(){this.canReload?(this.beforeDestroy(),this.renderChildren()):A.warn(Pe,"当前组件无法实现reload",this.node)}initPropData(){let e=[];for(let t of this.ast.attributes)if("ref"!==t.name)if("keep-alive"===t.name&&"false"!==t.value&&(this.node.keepalive=!0),t.express){let i=this.runExpressWithWatcher(t.express,this.ob,(e=>{let i=$e(e);i instanceof Promise?i.then((e=>{this.node&&(this.node.propValues[t.name]=e,this.notifyNodeWatcher("update",t.name))})).catch((e=>{A.error(Pe,`${t.express}异步处理失败`,e)})):(this.node.propValues[t.name]=i,this.notifyNodeWatcher("update",t.name))}),!0),s=$e(i);s instanceof Promise?(s.then((e=>{this.node&&(this.node.propValues[t.name]=e)})).catch((e=>{A.error(Pe,`${t.express}异步处理失败`,e)})),e.push(s)):this.node.propValues[t.name]=s}else this.node.propValues[t.name]=t.value;else{if(g(t.value)){A.warn(Pe,"元素的ref值不可以为空");continue}this.ref=t.value,this.ext.addRef(t.value,this.node)}return this.node.propValues=W(this.node.propValues),e}initEvent(){this.ast.events.forEach((e=>{let t=e.functionName?this.ob[e.functionName]:void 0;void 0===e.functionName?this.node.events.push([e.name,{modifiers:e.modifiers,callBack:b}]):t&&"function"==typeof t?this.node.events.push([e.name,{modifiers:e.modifiers,callBack:i=>{let s=[];e.functionParam&&(s=this.runExpress(`[${e.functionParam}]`,this.ob)),t.call(this.ext.ob,i,...s)}}]):A.error(Pe,`${"tagName"in this.ast?this.ast.tagName:""}元素中${e.name}事件所指定的回调(${e.functionName})方法未找到,请检查`)}))}async renderChildren(){if("tagName"in this.ast){let e=this.ob.components[this.ast.tagName]||tt(this.ast.tagName);if(void 0===e)return void A.error(Pe,`渲染组件失败,未找到名称为'${this.ast.tagName}'的私有组件/全局组件`);if(ze in e||(e=(await e()).default),!this.node)return;{let t=this.getSections();this.node.name=this.ast.tagName,this.node.component=new e(this.node?.propValues,t,this.node?.keepalive)}}else if("function"==typeof this.ast.component){let e=this.getSections();this.node.component=new this.ast.component(this.node?.propValues,e,this.node?.keepalive)}else this.node.component=this.ast.component;if(!this.node)return;if(!this.node.name&&"name"in this.node.component&&this.node.component.name&&"string"==typeof this.node.component.name&&(this.node.name=this.node.component.name),await this.node.component.$mount(this.node),!this.node)return;let e=this.node?.component;e.isKeepAlive&&(this.ast.node=this.node)}getSections(){let t={},s=[];return this.ast.childrens.forEach((t=>{if(t.type===i.NodeType.COMMAND&&"if"===t.cmdName&&t.childrens){let n=t,r=t.childrens.some((e=>e.type===i.NodeType.COMMAND&&"section"===e.cmdName)),o=n.condition.startsWith(e+".$sections");if(o){return this.runExpress(n.condition,this.ob)?void s.push(...t.childrens):void 0}if(r&&"if"===n.kind&&!o)return void A.warn(Pe,"在解析section时,发现该section包裹在一个条件语句中,该条件语句仅支持以$sections进行if判断,已作排出")}s.push(t)})),s.forEach((e=>{if(e.type===i.NodeType.COMMAND&&"section"===e.cmdName){let i=e,s=i.id||xe;/^(\'|\")(.*?)((\'|\"))$/.test(s)&&(s=s.slice(1,-1)),t[s]=t[s]||{asts:[],ob:this.ob,params:i.paramKeys,parser:this.ext},t[s].asts.push(...e.childrens||[])}else t[xe]=t[xe]||{asts:[],ob:this.ob,parser:this.ext},t[xe].asts.push(e)})),t}beforeDestroy(e){!0===e&&this.node?.component?.isKeepAlive?this.node?.component?.$destroy():(this.node?.component?.$destroy(!0),this.ast.node=void 0)}}const _e="Element解析";class Ke extends ve{async parser(){this.node=new X.Element(this.ast.tagName,this.parent);let e=this.initAttributes();this.initEvents(),this.appendNode(),e.length&&await Promise.all(e),await this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}initAttributes(){let e=[];for(let t of this.ast.attributes)if("ref"!==t.name)if(t.express){let i=e=>{this.node&&(this.node.attributes[t.name]=this.transformAttrVal(e),this.ext.render?.updateNode(this.node,t.name),this.notifyNodeWatcher("update",t.name))},s=this.runExpressWithWatcher(t.express,this.ob,(e=>{let s=$e(e);s instanceof Promise?s.then((e=>{i(e)})).catch((e=>{A.error(_e,`${t.express}异步处理失败`,e)})):i(s)})),n=$e(s);n instanceof Promise?(n.then((e=>{i(e)})).catch((e=>{A.error(_e,`${t.express}异步处理失败`,e)})),e.push(n)):this.node.attributes[t.name]=this.transformAttrVal(n)}else this.node.attributes[t.name]=t.value;else{if(g(t.value)){A.warn(_e,"元素的ref值不可以为空");continue}this.ref=t.value,this.ext.addRef(t.value,this.node)}return e}initEvents(){for(let e of this.ast.events){let t=e.functionName?this.ob[e.functionName]:void 0;if(!(void 0===e.functionName||t&&"function"==typeof t))throw new Error(`${this.ast.tagName}元素中${e.name}事件所指定的回调(${e.functionName})方法未找到,请检查`);this.node?.events.push([e.name,{modifiers:e.modifiers,callBack:i=>{if(void 0===t)return;let s=[];e.functionParam&&(s=this.runExpress(`[${e.functionParam}]`,this.ob)),t&&t.call(this.ext.ob,i,...s)}}])}}transformAttrVal(e){return void 0!==e&&("string"==typeof e||"boolean"==typeof e||"function"!=typeof e&&Object.prototype.toString()?e:void 0)}}class ke{asts;ob;root=new X.Root;refs={};sleeped=!1;nodeWatcherEvents={};render;constructor(e,t,i){this.asts=e,this.ob=t,this.root.component=t,this.render=G.get(te.IRENDERIOCTAGID)??new te.DomRender,i&&i instanceof X.Node&&(this.root.parent=i,i.childrens??=[],i.childrens.push(this.root))}async parser(){await this.parserNodes(this.asts,this.root)}mount(e){this.sleeped&&this.weakup(),this.render?.mount(e,(()=>{this.ob[Fe].value=!0,this.root.find((e=>e instanceof X.Component&&!e.component?.[Fe].value)).forEach((e=>{e.component&&(e.component[Fe].value=!0)}))}))}promiseQueue=new Set;async parserNodes(e,t,s){if(0!==this.asts.length)for(let n of e){if(0===this.asts.length)return;let e;if(n.type===i.NodeType.TEXT)e=new ge(n,s??this.ob,t,this);else if(n.type===i.NodeType.COMMENT)e=new we(n,s??this.ob,t,this);else if(n.type===i.NodeType.COMPONENT)e=new De(n,s??this.ob,t,this);else if(n.type===i.NodeType.ELEMENT){let i=n;e=Te(i.tagName,s??this.ob)?new De(i,s??this.ob,t,this):new Ke(i,s??this.ob,t,this)}else if(n.type===i.NodeType.COMMAND){let i=n;switch(i.cmdName){case"if":case"elseif":case"else":e=new be(i,s??this.ob,t,this);break;case"for":e=new Ne(i,s??this.ob,t,this);break;case"RenderSection":e=new Se(i,s??this.ob,t,this);break;case"section":break;default:e=new Ae(i,s??this.ob,t,this)}}if(e){let t=e.init();t instanceof Promise&&(this.promiseQueue.add(t),await t.finally((()=>{this.promiseQueue.delete(t),0===this.asts.length&&e&&!1===e.isDestroy&&e?.destroy()})))}}}addRef(e,t){this.refs[e]=this.refs[e]||[],this.refs[e].push(t)}removeRef(e){for(let t in this.refs)this.refs[t].includes(e)&&y(this.refs[t],e)}addNodeWatcher(e,t){this.nodeWatcherEvents[e]=this.nodeWatcherEvents[e]||[],this.nodeWatcherEvents[e].push(t)}removeNodeWatcher(e,t){y(this.nodeWatcherEvents[e]||[],t)}notifyNodeWatcher(e,t,i,s){this.nodeWatcherEvents[e]?.forEach((e=>{e(t,i,s)}))}sleep(e){let t=e||this.root;t.childrens?.forEach((e=>{let t=()=>{e.childrens&&this.sleep(e),e.sleep=!0,this.render?.removeNode(e,!0)};this.nodeTransition(e,"leave",void 0,(()=>{t()}))||t()})),void 0===e&&(this.sleeped=!0)}weakup(e){let t=e||this.root;t.childrens?.forEach((e=>{e.sleep=!1,this.render?.appendNode(e),e.childrens&&this.weakup(e),this.nodeTransition(e,"enter")})),void 0===e&&(this.sleeped=!1)}destroy(e){for(;this.root.childrens.length;){let t=this.root.childrens[0];t[X.PARSERKEY]?t[X.PARSERKEY].destroy(e):y(this.root.childrens,t)}this.render.destroy(),this.refs={},this.root.childrens.length=0,this.nodeWatcherEvents={},this.asts.length=0}destroyWathcers(){for(let e of this.root.childrens)e[X.PARSERKEY]&&e[X.PARSERKEY].destroyWathcers()}reSetAsts(e,t){this.destroy(t),this.render=G.get(te.IRENDERIOCTAGID)??new te.DomRender,this.asts=e}nodeTransition(e,t,i,s,n){if(e&&e.parent?.childrens&&(e instanceof X.Element||e instanceof X.Component)){let r=function(e){if(e instanceof X.Element||e instanceof X.Component){let t=e instanceof X.Element?e.attributes:e.propValues;return{name:t["transition-name"],type:t["transition-type"]}}}(e);if(i??=r?.name,n??=r?.type,!i)return!1;let o=We(e);if(o)return"enter"===t?this.render.elementToEnter(o,i,n,(()=>{let t=e[X.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-enter"),s?.()})):this.render.elementToLeave(o,i,n,(()=>{let t=e[X.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-leave"),s?.()})),!0;A.warn("渲染核心","在执行node动画时,发现数据不完备,请检查")}return!1}}function We(e){if(e instanceof X.Element)return e;if(e.childrens&&e.childrens.length)for(let t of e.childrens)return t instanceof X.Element?t:We(t)}function Ie(e,t,i){if(void 0===t)return;let s=Array.isArray(i)?i:[i];for(let e of s){if(e===Array&&t instanceof Array)return t;if(typeof t===e.name.toLocaleLowerCase())return t}switch(s[0]){case Number:let e=Number(t);if(!1===isNaN(e))return e;break;case String:return String(t)}throw new Error(`props中${e.toString()}的类型不符合约束类型`)}function Ve(e,t,i){let s,n,r;if("symbol"!=typeof t&&(s=w(t)),t in e?n=e[t]:s&&(n=e[s]),i&&(t in i?r=i[t]:s&&s in i&&(r=i[s])),void 0!==r){if(u(r)&&("type"in r||"required"in r||"default"in r||"validate"in r)){let e=r;if(e.required&&void 0===n)throw new Error(`props中key:${t.toString()}是必须项,请检查`);if(e.type&&(n=Ie(t,n,e.type)),e.validate&&!1===e.validate(n))throw new Error(`props中key${t.toString()}的值校验错误`);n=n??e.default}else n=Le(r)?Ie(t,n,r):n??r;return n}return n}function Le(e){return!![String,Array,Number,Object,Function,Boolean].includes(e)||e instanceof Array&&Le(e[0])}const Me="组件",je=Symbol.for("JOKER_PROPS_DATA_KEY"),Ye=Symbol.for("JOKER_PROPS_DATA_PROXY"),Be=Symbol.for("JOKER_PRIVATE_WATCHERS"),He=Symbol.for("JOKER_EVENT_DATA_KEY"),Je=Symbol.for("JOKER_IS_DESTROY"),Fe=Symbol.for("JOKER_IS_RENDER"),qe=Symbol.for("JOKER_PARSER_TEMPLATE_TARGET"),Ge=Symbol.for("JOKER_SCOPE_ID"),ze=Symbol.for("JOKER_COMPONENT_TAG"),Xe=Symbol();let Qe=["constructor","$mount","$nodeTransition","$destroy","$getRef","$getRefs","$syncProp","$watchNode","$watch","$on","$off","$trigger","$render","created","mounted","beforeDestroy","sleeped","wakeup","destroyed"];class Ue{$sections;isKeepAlive;static[ze]=!0;[Ge];model={};template;$root;isSleeped=!1;components={};propsOption;[je]={};[qe];[Ye];[Be]=[];[He]=new Map;[Je]=!1;[Fe]=new L(!1);[Xe]=!1;constructor(e,t={},i){this.$sections=t,this.isKeepAlive=i,this[je]=e||{}}get props(){if(void 0===this[Ye]){let e=this;this[Ye]=new Proxy(e[je],{get:(t,i)=>Ve(e[je],i,e.propsOption),set(){throw new Error("props 参数不允许变更,只允许单向数据传递")}})}return this[Ye]}async $mount(e){if(!1===this[Xe]){let e=()=>{let e=[],t=Object.getPrototypeOf(this);for(;null!==t&&t!==Object.prototype;)Object.getOwnPropertyNames(t).forEach((i=>{!1!==Qe.includes(i)||Ce(t,i)||"function"!=typeof t[i]||t[i].prototype?.hasOwnProperty("constructor")||e.push(i)})),t=Object.getPrototypeOf(t);return e};for(let t of e())this[t]=this[t].bind(this);this[Xe]=!0}return this.$root=e,this.isKeepAlive&&this.isSleeped?(this.isSleeped=!1,this[qe]&&this.$root?(this[qe].mount(this.$root),this.wakeup(),this.$trigger("wakeup"),this.$rootVNode&&st(this.$rootVNode),this):(A.error(Me,"当前组件在唤醒时,发现渲染处理程序已被销毁,无法进行唤醒操作",[this,this.$root]),this)):(this.isSleeped=!1,this.model=W(this.model),await this.created(),this[Je]?this:(this.$trigger("created"),this.template&&await this.$render(),this[Je]||(await this.mounted(),this.$trigger("mounted"),this.$root||(this[Fe].value=!0)),this))}$nodeTransition(e,t,i,s,n){if("string"==typeof e){let t=this.$getRef(e);if(!t)return void A.error(Me,`执行节点动画是找不到ref=${e}的节点`);e=t}this[qe]?.nodeTransition(e,t,i,s,n)}async $updatedRender(e){if(!this[Je])return new Promise((t=>{let i=async()=>{await Promise.resolve();let i=[...this[qe]?.promiseQueue||[]],s=this.$rootVNode?.find((e=>e instanceof X.Component));if(s?.forEach((e=>{e?.component&&i.push(...e.component[qe]?.promiseQueue||[])})),i.length)Promise.all(i).finally((()=>{this[Je]||(e?.(),t(void 0))}));else{if(this[Je])return;e?.(),t(void 0)}};if(this[Fe].value)setTimeout((()=>{i()}));else{let[e,t]=this.$watch((()=>this[Fe].value),(e=>{t(),e&&i()}))}}))}$destroy(e){if(!e&&this.isKeepAlive)return this[qe]?.sleep(),this.isSleeped=!0,this.sleeped(),this.$trigger("sleeped"),void(this.$rootVNode&&it(this.$rootVNode));this[Je]=!0;for(let e of this[Be])e.destroy();this[Be].length=0,this[qe]?.destroyWathcers(),this.beforeDestroy(),this.$trigger("beforeDestroy"),this[qe]?.destroy(),this[qe]=void 0,this.template&&Array.isArray(this.template)&&(this.template.length=0),this.$trigger("destroy"),this[He].clear(),this.$root=void 0,this.isSleeped=!1,this.$sections={},this[Ye]=void 0,this[je]={},this.destroyed()}get $refs(){return this[qe]?.refs||{}}$getRef(e){return this.$refs[e]?.[0]}$getRefs(e){return this.$refs[e]}$syncProp(e,t,i){"function"==typeof t&&(i=t,t=void 0),t??=e,i??=e=>e,this.model[t]=i(this.props[e]),this.$watch((()=>this.props[e]),(()=>{this.model[t]=i?.(this.props[e])}))}get $rootVNode(){return this[qe]?.root}$watchNode(e,t){if(this[qe])return this[qe]?.addNodeWatcher(e,t),()=>{this[qe]?.removeNodeWatcher(e,t)};A.warn(Me,"该组件还未挂载,不可以进行节点观察监听")}$watch(e,t,i){let s=new q((()=>{if(this[Je]){for(let e of this[Be])e.destroy();return F}return e()}),((e,i)=>{this[Je]||t(e,i)}),void 0,i);return this[Be].push(s),[s.value,()=>{s.destroy(),y(this[Be],s)}]}$on(e,t){let i=this[He].get(e);void 0===i&&(i=[],this[He].set(e,i)),!1===i?.includes(t)&&i.push(t)}$off(e,t){let i=this[He].get(e);i&&(t?y(i,t):i.length=0)}$trigger(e,t,i){if(!this.$root)return;let s={eventName:e,stopPropagation:i?.stopPropagation??(()=>{}),preventDefault:i?.preventDefault??(()=>{}),data:t,target:i?.target??this.$rootVNode,event:i?.event};if(this.$rootVNode&&this.$rootVNode.parent&&this.$rootVNode.parent instanceof X.Component&&!1===this[qe]?.render.triggerEvent(this.$rootVNode.parent,e,s))return;let n=this[He].get(e);n?.length&&[...n].forEach((e=>{e(s)}));let r=this[He].get("*");r?.length&&[...r].forEach((e=>{e(s)}))}async $render(e,t){e??=this.template,this.template="function"==typeof e?e(s):e,this.$root&&(this.template??=[],this[qe]?.reSetAsts(this.template,t),this[qe]??=new ke(this.template,this,this.$root),await this[qe].parser(),this.$root&&this[qe].mount(this.$root))}created(){}mounted(){}beforeDestroy(){}sleeped(){}wakeup(){}destroyed(){}}const Ze={};function et(e,t){if("string"==typeof e)t&&(Ze[e]=t);else for(let t in e)Ze[t]=e[t]}function tt(e){return Ze[e]}function it(e){e.childrens?.forEach((e=>{e instanceof X.Component&&e.component?.sleeped(),it(e)}))}function st(e){e.childrens?.forEach((e=>{e instanceof X.Component&&e.component?.wakeup(),st(e)}))}class nt extends Ue{template=[];cache=new Map;async mounted(){this.$watch((()=>this.props.name),(async e=>{await this.$render([],!0),await Promise.resolve(),this.$root&&this.loadComponent(e)})),await this.loadComponent(this.props.name)}propsVaule;created(){this.initProps()}initProps(){let e={};this.props.props||(Object.keys(this.props).forEach((t=>{!1!==this.filterProps(t)&&(e[t]=this.props[t],this.$watch((()=>this.props[t]),(()=>{this.propsVaule[t]=this.props[t]})))})),this.propsVaule=W(e))}filterProps(e){if("string"!=typeof e)return!1;let t=w(e);return"transition-name"!==t&&"name"!==t&&"keep-alive"!==t&&"ref"!==t&&void 0}async loadComponent(e){if(!e)return void await this.$render([],this.isKeepAlive);let t;if(this.isKeepAlive){let t=this.cache.get(e);if(t)return void await this.$render([n(t,{"transition-name":this.props["transition-name"]})],!0)}let i=this.$rootVNode?.parent?.[X.PARSERKEY]?.ob.components,s=i?.[e];void 0===s&&(s=tt(e)),s?(ze in s||(s=(await s()).default),t=new s(this.props.props||this.propsVaule,this.$sections,this.isKeepAlive),t.$on("*",(e=>{this.$trigger(e.eventName,e.data,e)})),this.isKeepAlive&&this.cache.set(e,t),await this.$render([n(t,{"transition-name":this.props["transition-name"]})],this.isKeepAlive)):A.warn("component",`未找到${e}的组件`)}beforeDestroy(){this.removeCache()}removeCache(e){if(e){let t=this.cache.get(e);this.cache.delete(e),t&&t.$destroy(!0)}else this.cache.forEach((e=>{e.$destroy(!0)})),this.cache.clear()}}class rt extends Ue{template=function(){return[r("RenderSection")]}}et({template:rt,component:nt});class ot{eventDatas=new Map;on(e,t){let i=this.eventDatas.get(e);void 0===i&&(i=[],this.eventDatas.set(e,i));let s={callBack:t};return i.push(s),()=>{i&&y(i,s)}}once(e,t){let i=this.eventDatas.get(e);void 0===i&&(i=[],this.eventDatas.set(e,i));let s={callBack:t,once:!0};return i.push(s),()=>{i&&y(i,s)}}off(e,t){if(void 0!==e)if(t){let i=this.eventDatas.get(e),s=i?.find((e=>e.callBack===t));s&&y(i,s)}else this.eventDatas.delete(e);else this.eventDatas.clear()}async trigger(e,t){let i=[...this.eventDatas.get(e)||[]];if(i.push(...this.eventDatas.get("*")||[]),i&&i.length){let s=0,n=0,r=!1;for(;i[s];){let o=i[s],a=await o.callBack({stopPropagation:()=>r=!0,callTimes:n,eventName:e},t);if(o.once?y(i,o):s++,!1===a||r)return!1}}}}export{F as BREAK_WATCH_UPDATE,Ue as Component,nt as ComponentContainer,S as Dep,ot as EventBus,G as IContainer,Je as IS_DESTROY,Fe as IS_RENDER,ze as JOKER_COMPONENT_TAG,z as JOKER_VNODE_TAG,P as OBJECTPROXY_DEPID,qe as PARSER_TEMPLATE_TARGET,ke as ParserTemplate,te as Render,Ge as SCOPE_ID,L as ShallowObserver,rt as Template,X as VNode,q as Watcher,fe as __GLONAL_FUNTIONS__,d as __JOKER_HMR_RUNTIME,B as combinedReply,I as defineObserverProperty,tt as getGlobalComponent,H as isObserverData,W as observer,et as registerGlobalComponent,pe as registerGlobalFunction};
1
+ import{EXPRESSHANDLERTAG as e,createFuntionBody as t,AST as i,RENDER_HANDLER as s,createComponent as n,createCommand as r}from"@joker.front/ast";export{AST,EXPRESSHANDLERTAG,RENDER_HANDLER,createCodeFunction,createCommand,createComment,createComponent,createElement,createFuntionBody,createText}from"@joker.front/ast";const o=new Map,a=new Map,h=new Map;let d={recordRender:(e,t)=>{a.set(e,t)},recordComponent:(e,t)=>{h.set(e,t)},record:(e,t)=>{void 0===o.get(e)&&o.set(e,new Set),o.get(e).add(t),t.$on("destroy",(()=>{o.get(e)?.delete(t)}))},reload:(e,t)=>{let i=h.get(e);if(!i)return;i.component=t;let s=o.get(e);if(!s)return;let n=Array.from(s);s.clear(),n.forEach((e=>{if(e.$root){if(!e.$rootVNode?.parent)return window.onbeforeunload=null,void location.reload();{let t=e.$rootVNode.parent;if(!(t instanceof X.Component&&t[X.PARSERKEY]&&t[X.PARSERKEY].canReload))return window.onbeforeunload=null,void location.reload();t[X.PARSERKEY].reload()}}}))},rerender:(e,t)=>{let i=a.get(e);i&&(i.render=t),o.get(e)?.forEach((e=>{e.$render(t)}))}};function l(e){return null!==e&&"object"==typeof e}function c(e,t){Object.getOwnPropertyNames(e).forEach((i=>{t(i,e[i])}))}function u(e){return"[object Object]"===Object.prototype.toString.call(e)}function f(e){if(null===e)return e;if("object"!=typeof e)return e;let t;t=Array.isArray(e)?[]:{};let i=Object.keys(e);for(let s of i){let i=e[s];t[s]="object"==typeof i?f(i):i}return t}function p(e,t,i){return Array.isArray(e)&&Array.isArray(t)?function(e,t,i){if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(i){if(e[s]!==t[s])return!1}else if(!1===m(e[s],t[s],i))return!1;return!0}(e,t,i):m(e,t,i)}function m(e,t,i){if(e===t)return!0;let s=l(e),n=l(t);if(s&&n){if(u(e)&&u(t)){let s=Object.keys(e);if(s.length!==Object.keys(t).length)return!1;if(i){for(let i of s)if(e[i]!==t[i])return!1;return!0}return JSON.stringify(e)===JSON.stringify(t)}return e===t}return!s&&!n&&String(e)===String(t)}function y(e,t){let i=e.indexOf(t);return i>-1&&e.splice(i,1),e}function E(e,t){let i=e.findIndex((e=>t(e)));return i>-1&&e.splice(i,1),e}function v(e){return!e||""===e.trim()}function g(e,t="-"){return(e=e||"").split(/(?=[A-Z])/).map((e=>e.toLowerCase())).join(t)}let b=(...e)=>{},w="warn";const N=["silent","error","warn","info"];function R(){let e=new Date;function t(e,t=2){return e.toString().padStart(t,"0")}return t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+":"+t(e.getMilliseconds(),3)}function A(e,t,i,s){N.indexOf(e)<=N.indexOf(w)&&(void 0===s?console[e](`${R()} [${t}]:`,i):console[e](`${R()} [${t}]:`,i,s))}let C={info:function(e,t,i){A("info",e,t,i)},warn:function(e,t,i){A("warn",e,t,i)},error:function(e,t,i){A("error",e,t,i)},setLoggerLeve:function(e){w=e}};const $={lt:"<",gt:">",nbsp:" ",amp:"&",quot:'"',"#39":"'"};function O(e){return e.replace(/&(lt|gt|nbsp|amp|quot|#39);/gi,((e,t)=>$[t]||""))}class x{static target;watchers=new Map;depend(e){x.target?.addDep(this,e)}addWatcher(e,t){let i=this.watchers.get(e)||[];i.push(t),this.watchers.set(e,i)}removeWatcher(e,t){let i=this.watchers.get(e);i&&y(i,t)}notify(e){let t=this.watchers.get(e);if(t){E(t,(e=>e.isDestroy)),[...t].forEach((e=>{!1===e.isDestroy&&e.update()}))}}}const S=Symbol.for("__JOKER_OBJECT_PROXY_DEP_ID__"),T=Symbol.for("__JOKER_OBJECT_PROXY_DATA_KEY__"),D=Symbol.for("__JOKER_OBJECTPROXY_DEPLEVE_ID__");function P(e){return l(e)&&e instanceof Window==!1&&e instanceof F==!1&&e!==window.parent&&(Array.isArray(e)||u(e)||e instanceof Set||e instanceof Map)&&!Object.isFrozen(e)&&!(e instanceof Element)&&!(q in e)&&!(I in e)&&!(Je in e)}function K(e){if(_(e))return e;if(e&&e.hasOwnProperty(T)){let t=Reflect.get(e,T);if(t)return t}let t=new x,i=!0,s=new Proxy(e,{get(e,i,s){if(e instanceof Set||e instanceof Map){if("add"===i){let s=Reflect.get(e,i);return i=>{P(i)&&(i=k(i));let n=s.call(e,i);return j(t,"size"),j(t,D),n}}if("set"===i){let s=Reflect.get(e,i);return(i,n)=>{P(n)&&(n=k(n));let r=s.call(e,i,n);return j(t,"size"),j(t,D),r}}if("delete"===i||"clear"===i){let s=Reflect.get(e,i);return n=>{let r=s.call(e,n);return("clear"===i||r)&&(j(t,"size"),j(t,D)),r}}let s=Reflect.get(e,i);if("function"==typeof s)return s.bind(e)}if(i===T)return;if(i===S)return t;if(i===D)return;let n=Reflect.get(e,i);return i===Symbol.toStringTag||!1===function(e,t){return t in e}(e,i)&&"length"!==i&&"size"!==i||(t.depend(i),P(n)&&_(n)?.depend(D)),n},set(e,s,n){if(i)return Reflect.set(e,s,n),!0;P(n)&&(n=k(n));let r=!1===function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,s),o=Reflect.get(e,s)!==n;return Reflect.set(e,s,n),(o||"length"===s&&Array.isArray(e))&&j(t,s),Array.isArray(e)?"length"===s&&j(t,D):r&&j(t,D),!0},deleteProperty:(e,i)=>(Reflect.deleteProperty(e,i),!1===Array.isArray(e)&&j(t,D),!0)});var n,r,o,a;n=e,r=T,o=s,a=!1,Object.defineProperty(n,r,{value:o,enumerable:a,writable:!0,configurable:!0});for(let t in e){let i=e[t];P(i)&&!_(i)&&(s[t]=K(e[t]))}return i=!1,s}function _(e){if(l(e))return Reflect.get(e,S)}function k(e,t=!1){if(!1===P(e))throw new Error("当前传入的数据不是正确的数据类型,必须是数组或者对象");return K(t?f(e):e)}function W(e,t,i){let s=i;P(i)&&(s=k(i));let n=new x;Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:()=>(n.depend(t),_(s)?.depend(D),s),set:e=>{e!==s&&(P(e)&&(e=k(e)),s=e,j(n,t))}})}const I=Symbol.for("JOKER_SHALLOW_OBSERVER");class L{data;[I]=!0;dep=new x;constructor(e){this.data=e}isChanged=!1;get value(){return this.dep.depend(D),this.data}set value(e){!1===Object.is(e,this.data)&&(this.isChanged=!0,this.data=e,j(this.dep,D))}}let V=!1,M=new Map;function j(e,t){if(!1===V)e.notify(t);else{let i=M.get(e);void 0===i&&(i=[],M.set(e,i)),!1===i.includes(t)&&i.push(t)}}function Y(e){V=!0;try{e()}catch(e){return V=!1,M.clear(),void C.error("数据劫持","数据劫持组合回复在做变更采集时,遇到了阻塞错误,不做响应,请检查",e)}V=!1,function(e){let t=[],i=[];e.forEach(((e,i)=>{e.forEach((e=>{t.push(...i.watchers.get(e)||[])}))})),t.forEach((e=>{i.includes(e)||(!1===e.isDestroy&&e.update(),i.push(e))}))}(M),M.clear()}function B(e){return void 0!==_(e)}const H="数据观察",J=Symbol.for("JOKER_BREAK_WATCH_UPDATE");class F{ob;updateCallBack;forceCallBack;getter;value;isDestroy=!1;updating=!1;runRelations=new Map;relations=new Map;constructor(e,t,i,s){if(this.ob=e,this.updateCallBack=t,this.forceCallBack=s,void 0===e)throw new Error("无法对underfind进行变更观察");if(void 0===i)this.getter=e=>e;else if("function"==typeof i)this.getter=i;else{let e=function(e){if(/[^\w.$]/.test(e))return;let t=e.split(".");return function(e){let i=e;return t.forEach((e=>{i&&(i=i[e])})),i}}(i);if(void 0===e)throw new Error(i+"解析失败,无法明确读取表达式,请检查expOrFn参数,或采用function模式");this.getter=e}void 0===this.getter&&C.error(H,"getter创建失败",arguments),this.value=this.getValue()}getValue(){if(void 0===this.getter)return;x.target=this;let e,t="function"==typeof this.ob?this.ob():this.ob;try{e=this.getter.call(t,t)}catch(e){throw C.error(H,`获取值失败,执行方法:${this.getter.toString()}`),e}return x.target=void 0,this.clearnDeps(),e}addDep(e,t){let i=this.runRelations.get(e);if(void 0===i||!1===i.includes(t)){i=i||[],i.push(t),this.runRelations.set(e,i);let s=this.relations.get(e);void 0!==s&&!1!==s.includes(t)||e.addWatcher(t,this)}}update(){if(this.updating)return;let e=this.getValue();if(e===J)return;let t=this.value;if(this.forceCallBack||e!==t||l(e)){this.value=e;let i=e!==t&&p(e,t,!0);if(i&&!this.forceCallBack)return;this.updating=!0;try{this.updateCallBack(e,t,i,this)}catch(e){throw e}finally{this.updating=!1}}}destroy(){this.relations.forEach(((e,t)=>{for(let i of e)t.removeWatcher(i,this)})),this.isDestroy=!0,this.relations.clear(),this.runRelations.clear(),this.ob=void 0,this.value=void 0,this.getter=void 0}clearnDeps(){this.relations.forEach(((e,t)=>{let i=this.runRelations.get(t);for(let s of e)i?!1===i.includes(s)&&t.removeWatcher(s,this):t.removeWatcher(s,this)})),this.relations.clear(),this.relations=this.runRelations,this.runRelations=new Map}}var G;!function(e){let t=new Map;e.bind=function(e){return{to:i=>{if(t.has(e))throw new Error(`TagId:${e.toString()}已注入实现类,请勿重复注入。`);t.set(e,i)}}},e.get=function(e,...i){let s=t.get(e);if(s)return new s(...i)}}(G||(G={}));const q=Symbol.for("JOKER_VNODE_TAG");var X;!function(e){e.PARSERKEY=Symbol.for("JOKER_PARSER_KEY");class t{parent;[q]=!0;static;output;[e.PARSERKEY];childrens;sleep=!1;constructor(e){this.parent=e}get prev(){if(this.parent)return this.parent.childrens?.[this.parent.childrens?.indexOf(this)-1]}get next(){if(this.parent)return this.parent.childrens?.[this.parent.childrens?.indexOf(this)+1]}closest(t,i){if(!0===t(this))return this;let s=this.parent;for(;s;){if(i&&s instanceof e.Root)return;if(!0===t(s))return s;s=s.parent}}find(e,t,i){let s=i??[];if(t??=this.childrens,t)for(let i of t){!0===e(i)&&s.push(i),i.childrens&&this.find(e,i.childrens,s)}return s}contains(e,t){if(t??=this.childrens,t)for(let i of t){if(!0===e(i))return!0;if(i.childrens&&i.childrens.length&&this.contains(e,i.childrens))return!0}return!1}first(e,t){if(t??=this.childrens,t)for(let i of t){if(!0===e(i))return i;if(i.childrens&&i.childrens.length){let t=this.first(e,i.childrens);if(t)return t}}}}e.Node=t;e.Root=class extends t{childrens=[];component;constructor(){super()}};e.Text=class extends t{text;static=!0;constructor(e,t){super(t),this.text=e}};e.Html=class extends t{html;notShadow;static=!0;constructor(e,t,i){super(t),this.html=e,this.notShadow=i}};e.Comment=class extends t{text;static=!0;constructor(e,t){super(t),this.text=e}};e.Element=class extends t{tagName;static=!0;attributes={};childrens=[];events=[];_assistEventCache;constructor(e,t){super(t),this.tagName=e}};e.Component=class extends t{name;component;events=[];propValues={};keepalive;get firstElement(){if(this.childrens){let t=i=>{for(let s of i){if(s instanceof e.Element)return s;if(s.childrens){let e=t(s.childrens);if(e)return e}}};return t(this.childrens)}}get rootElements(){if(this.childrens){let t=[],i=s=>{for(let n of s)n instanceof e.Element||n instanceof e.Html?t.push(n):n.childrens&&i(n.childrens)};return i(this.childrens),t}return[]}};e.Condition=class extends t{cmdName;result=!1;childrens=[];isShow=!1;constructor(e,t){super(t),this.cmdName=e}};e.List=class extends t{childrens=[]};e.ListItem=class extends t{ob;childrens=[];constructor(e,t){super(t),this.ob=e}};e.RenderSection=class extends t{id="unknown";params=[];section;childrens=[];ob;constructor(e,t){super(t),"string"==typeof e?this.id=e:this.section=e}}}(X||(X={}));const z="DOM渲染",U=["script","style","textarea","pre"];let Z=0;const Q=["svg","defs","use","rect","circle","ellipse","line","polyline","polygon","path","text","g"];var ee;function te(e,t,i){return`${e}-${t}-${i}`}function ie(e,t,i,s){e._assistEventCache??=[],e._assistEventCache.push([t,i]),document.body.addEventListener(t,i,s)}function se(e,t,i){e._assistEventCache&&t&&i?(E(e._assistEventCache,(e=>e[0]===t&&e[1]===i)),document.body.removeEventListener(t,i)):(e._assistEventCache?.forEach((e=>{document.body.removeEventListener(e[0],e[1])})),e._assistEventCache&&(e._assistEventCache.length=0),e._assistEventCache=void 0)}!function(e){e.IRENDERIOCTAGID=Symbol.for("JOKER_IRENDERIOC_TAGID"),e.ROOT_CONTAINER="";e.DomRender=class{elements;constructor(){this.elements=document.createDocumentFragment()}mount(e,t){if(e instanceof Element)e.appendChild(this.elements),t?.();else if(e instanceof X.Component)if(e.parent)if(e.output){let i=e.output,s=he(e)||i.parentNode;s&&(s.insertBefore(this.elements,i),document.contains(s)&&t?.())}else C.error(z,"组件挂载渲染时发现该节点未定义DOM定位节点",e);else C.error(z,"mount子组件时,发现该组件无父级",e);else C.error(z,"mount只支持挂载到Element或VNode.Node类型数据中",e)}appendNode(e,t){if(this.renderNode(e),e.output){let i=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];for(let s of i)this.appendNodeChildren(e,s,e.parent,t)}else C.error(z,"未找自身节点的el属性,无法进行dom挂载",e)}updateNode(e,t){if(e instanceof X.Element)for(let t in e.attributes){let i=e.attributes[t];this.setAttribute(e.output,t,i)}else e instanceof X.Text?e.parent&&e.parent instanceof X.Element&&U.includes(e.parent.tagName)?(this.removeNode(e),this.appendNode(e)):e.output.textContent=O(e.text||""):e instanceof X.Html?e.notShadow?e.output.innerHTML=e.html:e.output.root.innerHTML=e.html:C.error(z,`该节点不支持${t}的更新`,e)}removeNode(e,t){let i=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];i?.forEach((e=>{e?.remove()})),t||(e instanceof X.Element&&se(e),e.output=void 0)}destroy(){this.elements=void 0}elementToEnter(e,t,i,s){e.output&&this.transitionFrame(e,t,"enter",i,s)}elementToLeave(e,t,i,s){e.output&&this.transitionFrame(e,t,"leave",i,s)}triggerEvent(e,t,i){let s=[];for(let n of e.events){let[r,o]=n;if(r===t){let t=o.modifiers?.includes("self"),a=o.modifiers?.includes("outside");if(t||a){C.warn(z,"事件修饰符:self、outside在组件事件中无法使用,组件无法确认元素",e);continue}let h=i.event;if((h instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(r)||h instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(r))&&!1===re(h,o.modifiers))continue;if(o.callBack(i),o.modifiers?.includes("prevent")&&i.preventDefault(),o.modifiers?.includes("once")&&s.push(n),o.modifiers?.includes("stop"))return i.stopPropagation(),!1}}s.length&&s.forEach((t=>{y(e.events,t)}))}transitionFrame(e,t,i,s,n){oe(e,te(t,i,"from")),s||="transition";let r=e.output.__TRANSITION_EVNETID__=Z++;requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(!e.output)return;oe(e,te(t,i,"active")),ae(e,te(t,i,"from")),oe(e,te(t,i,"to"));let o=function(e,t){let i=window.getComputedStyle(e),s=e=>(i[e]||"").split(", ");if("transition"===t){let e=s("transitionDelay"),t=s("transitionDuration"),i=de(e,t);if(i>0)return{timeout:i,count:t.length}}else if("animation"===t){let e=s("animationDelay"),t=s("animationDuration"),i=de(e,t);if(i>0)return{timeout:i,count:t.length}}}(e.output,s);if(!o)return void n?.();let a=0,h=()=>{ae(e,te(t,i,"to")),ae(e,te(t,i,"active")),e.output&&(e.output.removeEventListener(`${s}end`,d),r===e.output.__TRANSITION_EVNETID__&&n?.())},d=t=>{t.target===e.output&&++a>=o.count&&h()};setTimeout((()=>{a<o.count&&h()}),o.timeout+1),e.output?.addEventListener(`${s}end`,d)}))}))}renderNode(e){if(!e.output)if(e instanceof X.Text)e.parent&&e.parent instanceof X.Element&&U.includes(e.parent.tagName)?e.output=this.parserHtml(e.text):e.output=document.createTextNode(O(e.text||""));else if(e instanceof X.Html)if(e.notShadow){let t=document.createElement("joker-html-container");t.JOKER_NODE=e,t.innerHTML=e.html,e.output=t}else{let t=document.createElement("joker-html-shadow");t.JOKER_NODE=e,t.style.lineHeight="1",t.root.innerHTML=e.html,e.output=t}else if(e instanceof X.Element){let t,i=e.tagName.toLowerCase();"svg"===i||Q.includes(i)||e.parent?.inSvg?(e.inSvg=!0,t=document.createElementNS("http://www.w3.org/2000/svg",e.tagName)):t=document.createElement(e.tagName);for(let i in e.attributes)this.setAttribute(t,i,e.attributes[i]);t.JOKER_NODE=e,e.output=t,e.events.some((e=>"click"===e[0]&&e[1].modifiers?.includes("outside")))?setTimeout((()=>{this.initElementEvents(t,e)})):this.initElementEvents(t,e)}else e instanceof X.Comment?e.output=document.createComment(e.text):e.output=document.createTextNode("")}initElementEvents(e,t){for(let[i,s]of t.events){let n=s.modifiers?.includes("self"),r=s.modifiers?.includes("outside");n&&r&&(C.warn(z,"事件修饰符:self、outside不可以同时存在,将按照self处理",t),r=!1);let o,a=function(o){if(!(t.sleep||n&&o.target!==e)){if(r){if(o.target===e||e.contains(o.target))return;if(!1===document.contains(o.target))return;if(t.contains((e=>(e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output]).includes(o.target))))return!0}(o instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(i)||o instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(i))&&!1===re(o,s.modifiers)||(s.callBack({eventName:i,event:o,target:t,preventDefault:()=>o.preventDefault(),stopPropagation:()=>o.stopPropagation(),data:void 0}),s.modifiers?.includes("prevent")&&o.preventDefault(),s.modifiers?.includes("stop")&&o.stopPropagation(),s.modifiers?.includes("once")&&(r?se(t,i,a):e.removeEventListener(i,a)))}};s.modifiers?.includes("passive")&&(o={passive:!0}),r?ie(t,i,a,o):e.addEventListener(i,a,o)}}parserHtml(e){var t=document.createElement("div");return t.innerHTML=e,t.childNodes}isCommandGroup(e){return e instanceof X.Component||e instanceof X.Condition||e instanceof X.List||e instanceof X.ListItem||e instanceof X.RenderSection}appendNodeChildren(e,t,i,s){let n=he(e);if(n)n.appendChild(t);else if(void 0===i)this.elements?.appendChild(t);else if(i)if(i instanceof X.Root){let e=i.parent;if(e&&e instanceof X.Component&&e.output){let i=e.output,s=i?.parentNode;if(s)return void s.insertBefore(t,i)}this.elements?.appendChild(t)}else if(i instanceof X.Element){let e=i.output;if(void 0===e)return;e.appendChild(t)}else if(this.isCommandGroup(i)){let e=i.output,n=e?.parentNode;if(void 0!==s&&i.childrens?.length&&n){let e=s-1;if(e<0)return void n.insertBefore(t,n.firstChild);{let s=i.childrens[e];if(s){let e=s.output;if(e)return void e.after(t)}}}n&&n.insertBefore(t,e)}else C.error(z,"该节点不支持嵌套子集,请检查。",{node:e,parent:i})}setAttribute(e,t,i){if(e)if("boolean"!=typeof i){if("class"===t){if(Array.isArray(i)){let e=[];for(let t of i)if(l(t))for(let i in t)t[i]&&e.push(i);else t&&e.push(t);i=e.join(" ")}else if(l(i)){for(let t in i)i[t]?e.classList.add(t):e.classList.remove(t);return}}else if("style"===t&&l(i)){e.removeAttribute("style");for(let t in i){let s=!1;void 0!==i[t]&&!1!==i[t]||(s=!0);let n=String(i[t]);v(n)&&(s=!0),s||(e.style[t]=n)}return}i=(i??"").toString().trim(),"class"===t&&(i=i.split(/\s/).filter((e=>e.trim())).join(" ")),"value"===t&&"value"in e?e.value=i:"xlink:href"===t?e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",i):e.setAttribute(t,i)}else i?e.setAttribute(t,""):e.removeAttribute(t)}}}(ee||(ee={}));const ne={enter:"enter",backspace:"delete",tab:"tab",arrowup:"up",arrowdown:"down",arrowleft:"left",arrowright:"right",escape:"esc"," ":"space"};function re(e,t){if(e instanceof KeyboardEvent){if(void 0===e.key)return!1;for(let i in ne)if(t?.includes(ne[i])&&e.key.toLowerCase()!==i)return!1}else{if(t?.includes("left")&&0!==e.button)return!1;if(t?.includes("right")&&2!==e.button)return!1;if(t?.includes("middle")&&1!==e.button)return!1}return(!t?.includes("ctrl")||!1!==e.ctrlKey)&&((!t?.includes("alt")||!1!==e.altKey)&&(!t?.includes("shift")||!1!==e.shiftKey))}function oe(e,t){e.output&&e.output.classList.add(t)}function ae(e,t){e.output&&e.output.classList.remove(t)}function he(e){if(e instanceof X.Element||e instanceof X.Component){let t=e instanceof X.Component?e.propValues["append-to"]:e.attributes["append-to"];if(t){if(t instanceof X.Element)return t.output;if("string"==typeof t){ee.ROOT_CONTAINER&&(t="body"===t?ee.ROOT_CONTAINER:`${ee.ROOT_CONTAINER} ${t}`);let e=document.querySelector(t);if(e)return e}C.warn(z,"appendTo类型不支持",{appendTo:t,node:e})}}}function de(e,t){for(;e.length<t.length;)e.concat(e);return Math.max(...t.map(((t,i)=>le(t)+le(e[i]))))}function le(e){return"auto"===e?0:1e3*Number(e.slice(0,-1).replace(",","."))}class ce extends HTMLElement{root;constructor(){super(),this.root=this.attachShadow({mode:"open"})}}!customElements.get("joker-html-shadow")&&customElements.define("joker-html-shadow",ce);const ue={};function fe(e){for(let t in e)ue[t]=e[t]}const pe="Global",me="渲染核心";function ye(t){try{return new Function(e,pe,`return ${t};`)}catch{throw new Error("创建表达式运行方法时出现未知错误,表达式为"+t)}}class Ee{ast;ob;parent;ext;ref="";watchers=[];node;isDestroy=!1;constructor(e,t,i,s){this.ast=e,this.ob=t,this.parent=i,this.ext=s}init(e){this.parser(e),this.afterParser()}beforeDestroy(e){}destroy(e){if(this.isDestroy=!0,this.clearWatchers(),this.parent.childrens&&this.node){(this.node instanceof X.Element||this.node instanceof X.Component)&&this.ext.removeRef(this.node);let t=()=>{this.parent&&this.node&&(this.beforeDestroy(e),this.destroyChildrens(e),this.ext.render?.removeNode(this.node),this.parent.childrens&&y(this.parent.childrens,this.node),this.notifyNodeWatcher("remove"),this.destroyOtherData())};if(this.ext.nodeTransition(this.node,"leave",void 0,(()=>{t()})))return y(this.parent.childrens,this.node),void this.destroyChildrensWatcher(this.node);t()}else this.destroyOtherData()}destroyWathcers(){this.isDestroy=!0,this.clearWatchers(),this.destroyChildrensWatcher(this.node)}destroyOtherData(){this.node&&(this.node[X.PARSERKEY]=void 0),this.node=void 0,this.parent=void 0}destroyChildrens(e){for(;this.node?.childrens?.length;){let t=this.node.childrens[0];t[X.PARSERKEY]?t[X.PARSERKEY].destroy(e):y(this.node.childrens,t)}}destroyChildrensWatcher(e){if(e?.childrens?.length)for(let t of e?.childrens)t[X.PARSERKEY]&&(t[X.PARSERKEY].clearWatchers(),this.destroyChildrensWatcher(t))}appendNode(e){this.parent?.childrens&&this.node&&!this.isDestroy&&(this.node[X.PARSERKEY]=this,this.node instanceof X.Element&&this.ob[He]&&(this.node.attributes["data-scoped-"+this.ob[He]]=void 0),this.ext.render?.appendNode(this.node,e),void 0===e?this.parent.childrens.push(this.node):this.parent.childrens.splice(e,0,this.node),this.notifyNodeWatcher("append"))}afterParser(){this.ext.nodeTransition(this.node,"enter")}notifyNodeWatcher(e,t){this.ext.notifyNodeWatcher(this.ref,this.node,e,t)}runExpress(e,t){try{return ye(e).call(t,t,ue)}catch(i){C.error(me,"运行表达式出现错误:"+e,{ob:t}),console.error(i)}}runExpressWithWatcher(e,t,i,s){if(this.isDestroy)return;let n="string"==typeof e?ye(e):e,r=new F((()=>{if(this.isDestroy||t[Ye])return J;try{return n.call(t,t,ue)}catch(i){return C.error(me,"运行表达式出现错误",{ob:t,express:e,node:this.node}),console.error(i),J}}),i,void 0,s);return this.addWatch(r),r.value===J?void 0:r.value}addWatch(e){!1===this.watchers.includes(e)&&this.watchers.push(e)}clearWatchers(){this.watchers.forEach((e=>{e.destroy()})),this.watchers.length=0}}class ve extends Ee{parser(){this.node=new X.Text(this.ast.text,this.parent),this.appendNode()}}class ge extends Ee{parser(){this.node=new X.Comment(this.ast.text,this.parent),this.appendNode()}}class be extends Ee{parser(){if(this.node=new X.Condition(this.ast.kind,this.parent),"else"!==this.ast.kind){v(this.ast.condition)&&C.error("条件命令",`当前条件命令${this.ast.kind}没有判断条件,请检查`);let e=this.runExpressWithWatcher(this.ast.condition,this.ob,(e=>{let t=!!e;if(this.node?.result!==t){if(this.node.result=t,!1===t&&this.node?.isShow)this.destroyChildrens(!0);else if(t&&!this.node?.isShow){let e=this.getElseNode();if(e&&e.isShow&&e.childrens?.length){let t=e[X.PARSERKEY];t&&t instanceof be&&t.renderConditionChildren()}}this.reloadAllCondition()}}));this.node.result=!!e}this.appendNode(),this.renderConditionChildren()}renderId;getElseNode(){let e=this.node?.next;for(;e&&e instanceof X.Condition&&"if"!==e.cmdName;){if("else"===e.cmdName)return e;e=e.next}}renderConditionChildren(){let e=!1;return this.getPrevIfResult()?e=!1:"else"===this.ast.kind?e=!0:(this.node.result=!!this.runExpress(this.ast.condition,this.ob),this.node.result&&(e=!0)),e!==this.node.isShow&&(this.node.isShow=e,this.destroyChildrens(!0),e&&this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob),!0)}getPrevIfResult(){if("if"===this.ast.kind)return!1;let e=this.node?.prev;for(;e&&e instanceof X.Condition;){if(e.result)return!0;if("if"===e.cmdName)break;e=e.prev}return!1}reloadAllCondition(){if(this.renderConditionChildren()){let e=this.node?.next;for(;e&&e instanceof X.Condition&&"if"!==e.cmdName;){let t=e[X.PARSERKEY];t&&t instanceof be&&t.renderConditionChildren(),e=e.next}}let e=this.node?.next;for(this.node?.result||this.destroyChildrens(!0);e&&e instanceof X.Condition&&"if"!==e.cmdName;){let t=e[X.PARSERKEY];t&&t instanceof be&&t.renderConditionChildren(),e=e.next}}}class we extends Ee{parser(){this.node=new X.List(this.parent),this.appendNode(),this.renderChildrens()}renderChildrens(){switch(this.ast.keyType){case"condition":this.renderConditionChildrens();break;case"in":case"of":this.renderInOrOfChildrens()}}renderConditionChildrens(){let t=this.ast.param,i=Object.create(this.ob),s=!!this.runExpressWithWatcher(function(t,i,s){try{return new Function(e,`${e}.${t}=${i}; return ${s};`)}catch{throw new Error(`For循环命令,表达式运行依赖采集出现未知错误,其中letKey:${t},keyVal:${i},condition:${s}`)}}(t.letKey,t.defaultKeyVal,t.condition),i,(()=>{this.clearWatchers(),this.renderChildrens()}),!0),n=0;for(;s;){let e=Object.create(this.ob);W(e,t.letKey,i[t.letKey]);let r=n++;this.renderItem(e,r),this.runExpressWithWatcher((()=>i[t.letKey]),i,(async(i,s,n,o)=>{await Promise.resolve(),o.isDestroy||(e[t.letKey]=i,n||this.updateListItemOb(e,r))}),!0),this.runExpress(t.step,i),s=!!this.runExpress(t.condition,i)}this.destroyOldChildrens(n)}renderInOrOfChildrens(){let e=this.ast.param,t=this.runExpressWithWatcher(e.dataKey,this.ob,(()=>{this.clearWatchers(),this.renderChildrens()})),i=0;if(t&&(Array.isArray(t)||u(t)))for(let s in t){let n=Object.create(this.ob),r=Array.isArray(t)?Number(s):s;e.indexKey&&W(n,e.indexKey,r),e.itemKey&&W(n,e.itemKey,t[s]);let o=i++;this.renderItem(n,o,e.indexKey),e.itemKey&&this.runExpressWithWatcher((()=>t[r]),t,(async(i,s,a,h)=>{await Promise.resolve(),h.isDestroy||r in t&&(n[e.itemKey]=i,a||this.updateListItemOb(n,o))}),!0)}this.destroyOldChildrens(i)}findIndexByIndex(e,t,i){let s=-1;if(this.node)for(let n=t;n<this.node.childrens.length;n++)if(this.checkObEqual(e,this.node.childrens[n]?.ob,i?[i]:void 0)){s=n;break}return s}renderItem(e,t,i){if(!this.ast.childrens?.length||!this.node)return;let s=this.node.childrens?.[t];if(s){if(this.checkObEqual(e,s.ob,i?[i]:void 0))return void(i&&s.ob[i]!==e[i]&&(s.ob[i]=e[i]));let n=this.findIndexByIndex(e,t+1,i);if(n>-1){if(t+1===n)this.node.childrens?.[t]?.[X.PARSERKEY]?.destroy();else for(let e=0;e<n-t-1;e++)this.node.childrens?.[t]?.[X.PARSERKEY]?.destroy();return this.renderItem(e,t,i)}return new Ne(this.ast,e,this.node,this.ext).init(t)}return new Ne(this.ast,e,this.node,this.ext).init()}updateListItemOb(e,t){if(!this.ast.childrens?.length||!this.node)return;let i=this.node.childrens?.[t];c(e,((e,t)=>{i.ob[e]!==t&&(i.ob[e]=t)}))}destroyOldChildrens(e){if(this.node)for(;this.node.childrens.length>e;){let e=this.node.childrens.pop();if(!e)break;e[X.PARSERKEY]?.destroy(!1)}}checkObEqual(e,t,i){let s=!0;return void 0!==t&&(c(e,((e,n)=>{i?.includes(e)||t?.[e]===n||(s=!1)})),s)}}class Ne extends Ee{parser(e){this.node=new X.ListItem(this.ob,this.parent),this.appendNode(e),this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}}class Re extends Ee{parser(){if(v(this.ast.cmdName))throw C.error("模板指令","解析AST转换VNode时发生错误,未找到指令名称",this.ast),new Error("解析AST转换VNode时发生错误,未找到指令名称");let e;if("Html"===this.ast.cmdName||"Text"===this.ast.cmdName?e=this.ast.param:this.ast.cmdName.startsWith(pe+".")?e=`${this.ast.cmdName}(${this.ast.param})`:this.ast.cmdName in this.ob&&"function"==typeof this.ob[this.ast.cmdName]&&(e=`${t(this.ast.cmdName)}(${this.ast.param})`),e){let t=this.runExpressWithWatcher(`[${e}]`,this.ob,(e=>{this.changeValue(e?.[0])}));return t||=[],"Html"===this.ast.cmdName?this.node=new X.Html(Ae(t[0]),this.parent,t[1]):this.node=new X.Text(Ae(t[0]),this.parent),void this.appendNode()}throw new Error(`未找到命令:${this.ast.cmdName}`)}changeValue(e){this.node&&(this.node instanceof X.Html?this.node.html=Ae(e):this.node.text=Ae(e),this.ext.render?.updateNode(this.node))}}function Ae(e){return null==e||"function"==typeof e?"":e.toString()}const Ce="default";class $e extends Ee{parser(){let e=this.transformParam();this.node=new X.RenderSection(e.id,this.parent),this.node.params=e.params,this.node.section??=this.ob.$sections?.[e.id],this.appendNode(),this.node.section&&(this.node.section.params?(this.node.ob=Object.create(this.node.section.ob||this.ob),this.node.section.params?.forEach(((e,t)=>{W(this.node.ob,e,this.node.params[t])}))):this.node.ob=this.node.section.ob||this.ob,(this.node.section.parser||this.ext).parserNodes(this.node.section.asts,this.node,this.node.ob))}transformParam(){if(this.ast.param){let e=this.runExpressWithWatcher(`[${this.ast.param}]`,this.ob,(e=>{let t=e?.[0]||Ce;if("string"==typeof t&&t!==this.node.id)throw new Error("section id 不可动态变更");this.node.params=e.slice(1),this.node?.ob&&this.node.section&&this.node.section.params?.forEach(((e,t)=>{this.node?.ob&&this.node.ob[e]!==this.node.params[t]&&(this.node.ob[e]=this.node.params[t])}))}),!0);return{id:e?.[0]||Ce,params:e?.slice(1)||[]}}return{id:Ce,params:[]}}}const Oe="组件解析";function xe(e,t){return!!t.components[e]||!!Ue(e)}class Se extends Ee{parser(){if(this.ast.node)return this.node=this.ast.node,this.node.parent=this.parent,this.initPropData(),void(this.node&&(this.appendNode(),this.node.component?.$mount(this.node)));this.node=new X.Component(this.parent),this.initPropData(),this.appendNode(),this.initEvent(),this.renderChildren()}get canReload(){return"tagName"in this.ast||"function"==typeof this.ast.component}reload(){this.canReload?(this.beforeDestroy(),this.renderChildren()):C.warn(Oe,"当前组件无法实现reload",this.node)}initPropData(){for(let e of this.ast.attributes)if("ref"!==e.name)if("keep-alive"===e.name&&"false"!==e.value&&(this.node.keepalive=!0),e.express){let t=this.runExpressWithWatcher(e.express,this.ob,(t=>{this.node.propValues[e.name]=t,this.notifyNodeWatcher("update",e.name)}),!0);this.node.propValues[e.name]=t}else this.node.propValues[e.name]=e.value;else{if(v(e.value)){C.warn(Oe,"元素的ref值不可以为空");continue}this.ref=e.value,this.ext.addRef(e.value,this.node)}this.node.propValues=k(this.node.propValues)}initEvent(){this.ast.events.forEach((e=>{let t=e.functionName?this.ob[e.functionName]:void 0;void 0===e.functionName?this.node.events.push([e.name,{modifiers:e.modifiers,callBack:b}]):t&&"function"==typeof t?this.node.events.push([e.name,{modifiers:e.modifiers,callBack:i=>{let s=[];e.functionParam&&(s=this.runExpress(`[${e.functionParam}]`,this.ob)),t.call(this.ext.ob,i,...s)}}]):C.error(Oe,`${"tagName"in this.ast?this.ast.tagName:""}元素中${e.name}事件所指定的回调(${e.functionName})方法未找到,请检查`)}))}async renderChildren(){if("tagName"in this.ast){let e=this.ob.components[this.ast.tagName]||Ue(this.ast.tagName);if(void 0===e)return void C.error(Oe,`渲染组件失败,未找到名称为'${this.ast.tagName}'的私有组件/全局组件`);if(Je in e||(e=(await e()).default),!this.node)return;{let t=this.getSections();this.node.name=this.ast.tagName,this.node.component=new e(this.node?.propValues,t,this.node?.keepalive)}}else if("function"==typeof this.ast.component){let e=this.getSections();this.node.component=new this.ast.component(this.node?.propValues,e,this.node?.keepalive)}else this.node.component=this.ast.component;if(!this.node)return;if(!this.node.name&&"name"in this.node.component&&this.node.component.name&&"string"==typeof this.node.component.name&&(this.node.name=this.node.component.name),this.node.component.$mount(this.node),!this.node)return;let e=this.node?.component;e.isKeepAlive&&(this.ast.node=this.node)}getSections(){let t={},s=[];return this.ast.childrens.forEach((t=>{if(t.type===i.NodeType.COMMAND&&"if"===t.cmdName&&t.childrens){let n=t,r=t.childrens.some((e=>e.type===i.NodeType.COMMAND&&"section"===e.cmdName)),o=n.condition.startsWith(e+".$sections");if(o){return this.runExpress(n.condition,this.ob)?void s.push(...t.childrens):void 0}if(r&&"if"===n.kind&&!o)return void C.warn(Oe,"在解析section时,发现该section包裹在一个条件语句中,该条件语句仅支持以$sections进行if判断,已作排出")}s.push(t)})),s.forEach((e=>{if(e.type===i.NodeType.COMMAND&&"section"===e.cmdName){let i=e,s=i.id||Ce;/^(\'|\")(.*?)((\'|\"))$/.test(s)&&(s=s.slice(1,-1)),t[s]=t[s]||{asts:[],ob:this.ob,params:i.paramKeys,parser:this.ext},t[s].asts.push(...e.childrens||[])}else t[Ce]=t[Ce]||{asts:[],ob:this.ob,parser:this.ext},t[Ce].asts.push(e)})),t}beforeDestroy(e){!0===e&&this.node?.component?.isKeepAlive?this.node?.component?.$destroy():(this.node?.component?.$destroy(!0),this.ast.node=void 0)}}class Te extends Ee{parser(){this.node=new X.Element(this.ast.tagName,this.parent),this.initAttributes(),this.initEvents(),this.appendNode(),this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}initAttributes(){for(let e of this.ast.attributes)if("ref"!==e.name)if(e.express){let t=t=>{this.node&&(this.node.attributes[e.name]=this.transformAttrVal(t),this.ext.render?.updateNode(this.node,e.name),this.notifyNodeWatcher("update",e.name))},i=this.runExpressWithWatcher(e.express,this.ob,(e=>{t(e)}));this.node.attributes[e.name]=this.transformAttrVal(i)}else this.node.attributes[e.name]=e.value;else{if(v(e.value)){C.warn("Element解析","元素的ref值不可以为空");continue}this.ref=e.value,this.ext.addRef(e.value,this.node)}}initEvents(){for(let e of this.ast.events){let t=e.functionName?this.ob[e.functionName]:void 0;if(!(void 0===e.functionName||t&&"function"==typeof t))throw new Error(`${this.ast.tagName}元素中${e.name}事件所指定的回调(${e.functionName})方法未找到,请检查`);this.node?.events.push([e.name,{modifiers:e.modifiers,callBack:i=>{if(void 0===t)return;let s=[];e.functionParam&&(s=this.runExpress(`[${e.functionParam}]`,this.ob)),t&&t.call(this.ext.ob,i,...s)}}])}}transformAttrVal(e){return void 0!==e&&("string"==typeof e||"boolean"==typeof e||"function"!=typeof e&&Object.prototype.toString()?e:void 0)}}class De{asts;ob;root=new X.Root;refs={};sleeped=!1;nodeWatcherEvents={};render;constructor(e,t,i){this.asts=e,this.ob=t,this.root.component=t,this.render=G.get(ee.IRENDERIOCTAGID)??new ee.DomRender,i&&i instanceof X.Node&&(this.root.parent=i,i.childrens??=[],i.childrens.push(this.root))}parser(){this.parserNodes(this.asts,this.root)}mount(e){this.sleeped&&this.weakup(),this.render?.mount(e)}parserNodes(e,t,s){if(0!==this.asts.length)for(let n of e)if(n.type===i.NodeType.TEXT)new ve(n,s??this.ob,t,this).init();else if(n.type===i.NodeType.COMMENT)new ge(n,s??this.ob,t,this).init();else if(n.type===i.NodeType.COMPONENT)new Se(n,s??this.ob,t,this).init();else if(n.type===i.NodeType.ELEMENT){let e=n;xe(e.tagName,s??this.ob)?new Se(e,s??this.ob,t,this).init():new Te(e,s??this.ob,t,this).init()}else if(n.type===i.NodeType.COMMAND){let e=n;switch(e.cmdName){case"if":case"elseif":case"else":new be(e,s??this.ob,t,this).init();break;case"for":new we(e,s??this.ob,t,this).init();break;case"RenderSection":new $e(e,s??this.ob,t,this).init();break;case"section":break;default:new Re(e,s??this.ob,t,this).init()}}}addRef(e,t){this.refs[e]=this.refs[e]||[],this.refs[e].push(t)}removeRef(e){for(let t in this.refs)this.refs[t].includes(e)&&y(this.refs[t],e)}addNodeWatcher(e,t){this.nodeWatcherEvents[e]=this.nodeWatcherEvents[e]||[],this.nodeWatcherEvents[e].push(t)}removeNodeWatcher(e,t){y(this.nodeWatcherEvents[e]||[],t)}notifyNodeWatcher(e,t,i,s){this.nodeWatcherEvents[e]?.forEach((e=>{e(t,i,s)}))}sleep(e){let t=e||this.root;t.childrens?.forEach((e=>{let t=()=>{e.childrens&&this.sleep(e),e.sleep=!0,this.render?.removeNode(e,!0)};this.nodeTransition(e,"leave",void 0,(()=>{t()}))||t()})),void 0===e&&(this.sleeped=!0)}weakup(e){let t=e||this.root;t.childrens?.forEach((e=>{e.sleep=!1,this.render?.appendNode(e),e.childrens&&this.weakup(e),this.nodeTransition(e,"enter")})),void 0===e&&(this.sleeped=!1)}destroy(e){for(;this.root.childrens.length;){let t=this.root.childrens[0];t[X.PARSERKEY]?t[X.PARSERKEY].destroy(e):y(this.root.childrens,t)}this.render.destroy(),this.refs={},this.root.childrens.length=0,this.nodeWatcherEvents={},this.asts.length=0}destroyWathcers(){for(let e of this.root.childrens)e[X.PARSERKEY]&&e[X.PARSERKEY].destroyWathcers()}reSetAsts(e,t){this.destroy(t),this.render=G.get(ee.IRENDERIOCTAGID)??new ee.DomRender,this.asts=e}nodeTransition(e,t,i,s,n){if(e&&e.parent?.childrens&&(e instanceof X.Element||e instanceof X.Component)){let r=function(e){if(e instanceof X.Element||e instanceof X.Component){let t=e instanceof X.Element?e.attributes:e.propValues;return{name:t["transition-name"],type:t["transition-type"]}}}(e);if(i??=r?.name,n??=r?.type,!i)return!1;let o=Pe(e);if(o)return"enter"===t?this.render.elementToEnter(o,i,n,(()=>{let t=e[X.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-enter"),s?.()})):this.render.elementToLeave(o,i,n,(()=>{let t=e[X.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-leave"),s?.()})),!0;C.warn("渲染核心","在执行node动画时,发现数据不完备,请检查")}return!1}}function Pe(e){if(e instanceof X.Element)return e;if(e.childrens&&e.childrens.length)for(let t of e.childrens)return t instanceof X.Element?t:Pe(t)}function Ke(e,t,i){if(void 0===t)return;let s=Array.isArray(i)?i:[i];for(let e of s){if(e===Array&&t instanceof Array)return t;if(typeof t===e.name.toLocaleLowerCase())return t}switch(s[0]){case Number:let e=Number(t);if(!1===isNaN(e))return e;break;case String:return String(t)}throw new Error(`props中${e.toString()}的类型不符合约束类型`)}function _e(e,t,i){let s,n,r;if("symbol"!=typeof t&&(s=g(t)),t in e?n=e[t]:s&&(n=e[s]),i&&(t in i?r=i[t]:s&&s in i&&(r=i[s])),void 0!==r){if(u(r)&&("type"in r||"required"in r||"default"in r||"validate"in r)){let e=r;if(e.required&&void 0===n)throw new Error(`props中key:${t.toString()}是必须项,请检查`);if(e.type&&(n=Ke(t,n,e.type)),e.validate&&!1===e.validate(n))throw new Error(`props中key${t.toString()}的值校验错误`);n=n??e.default}else n=ke(r)?Ke(t,n,r):n??r;return n}return n}function ke(e){return!![String,Array,Number,Object,Function,Boolean].includes(e)||e instanceof Array&&ke(e[0])}function We(e,t){if(!e.constructor)return!1;let i=Object.getOwnPropertyDescriptor(e.constructor.prototype,t);return i&&i.get}const Ie="组件",Le=Symbol.for("JOKER_PROPS_DATA_KEY"),Ve=Symbol.for("JOKER_PROPS_DATA_PROXY"),Me=Symbol.for("JOKER_PRIVATE_WATCHERS"),je=Symbol.for("JOKER_EVENT_DATA_KEY"),Ye=Symbol.for("JOKER_IS_DESTROY"),Be=Symbol.for("JOKER_PARSER_TEMPLATE_TARGET"),He=Symbol.for("JOKER_SCOPE_ID"),Je=Symbol.for("JOKER_COMPONENT_TAG"),Fe=Symbol();let Ge=["constructor","$mount","$nodeTransition","$destroy","$getRef","$getRefs","$syncProp","$watchNode","$watch","$on","$off","$trigger","$render","created","mounted","beforeDestroy","sleeped","wakeup","destroyed"];class qe{$sections;isKeepAlive;static[Je]=!0;[He];model={};template;$root;isSleeped=!1;components={};propsOption;[Le]={};[Be];[Ve];[Me]=[];[je]=new Map;[Ye]=!1;[Fe]=!1;constructor(e,t={},i){this.$sections=t,this.isKeepAlive=i,this[Le]=e||{}}get props(){if(void 0===this[Ve]){let e=this;this[Ve]=new Proxy(e[Le],{get:(t,i)=>_e(e[Le],i,e.propsOption),set(){throw new Error("props 参数不允许变更,只允许单向数据传递")}})}return this[Ve]}$mount(e){if(!1===this[Fe]){let e=()=>{let e=[],t=Object.getPrototypeOf(this);for(;null!==t&&t!==Object.prototype;)Object.getOwnPropertyNames(t).forEach((i=>{!1!==Ge.includes(i)||We(t,i)||"function"!=typeof t[i]||t[i].prototype?.hasOwnProperty("constructor")||e.push(i)})),t=Object.getPrototypeOf(t);return e};for(let t of e())this[t]=this[t].bind(this);this[Fe]=!0}if(this.$root=e,this.isKeepAlive&&this.isSleeped)return this.isSleeped=!1,this[Be]&&this.$root?(this[Be].mount(this.$root),this.wakeup(),this.$trigger("wakeup"),this.$rootVNode&&Qe(this.$rootVNode),this):(C.error(Ie,"当前组件在唤醒时,发现渲染处理程序已被销毁,无法进行唤醒操作",[this,this.$root]),this);this.isSleeped=!1,this.model=k(this.model);let t=this.created(),i=()=>{this.$trigger("created"),this.template&&this.$render(),this.mounted(),this.$trigger("mounted")};return t&&t instanceof Promise?t.then((()=>{this[Ye]||i()})):i(),this}$nodeTransition(e,t,i,s,n){if("string"==typeof e){let t=this.$getRef(e);if(!t)return void C.error(Ie,`执行节点动画是找不到ref=${e}的节点`);e=t}this[Be]?.nodeTransition(e,t,i,s,n)}$destroy(e){if(!e&&this.isKeepAlive)return this[Be]?.sleep(),this.isSleeped=!0,this.sleeped(),this.$trigger("sleeped"),void(this.$rootVNode&&Ze(this.$rootVNode));this[Ye]=!0;for(let e of this[Me])e.destroy();this[Me].length=0,this[Be]?.destroyWathcers(),this.beforeDestroy(),this.$trigger("beforeDestroy"),this[Be]?.destroy(),this[Be]=void 0,this.template&&Array.isArray(this.template)&&(this.template.length=0),this.$trigger("destroy"),this[je].clear(),this.$root=void 0,this.isSleeped=!1,this.$sections={},this[Ve]=void 0,this[Le]={},this.destroyed()}get $refs(){return this[Be]?.refs||{}}$getRef(e){return this.$refs[e]?.[0]}$getRefs(e){return this.$refs[e]}$syncProp(e,t,i){"function"==typeof t&&(i=t,t=void 0),t??=e,i??=e=>e,this.model[t]=i(this.props[e]),this.$watch((()=>this.props[e]),(()=>{this.model[t]=i?.(this.props[e])}))}get $rootVNode(){return this[Be]?.root}$watchNode(e,t){if(this[Be])return this[Be]?.addNodeWatcher(e,t),()=>{this[Be]?.removeNodeWatcher(e,t)};C.warn(Ie,"该组件还未挂载,不可以进行节点观察监听")}$watch(e,t,i){let s=new F((()=>{if(this[Ye]){for(let e of this[Me])e.destroy();return J}return e()}),((e,i)=>{this[Ye]||t(e,i)}),void 0,i);return this[Me].push(s),[s.value,()=>{s.destroy(),y(this[Me],s)}]}$on(e,t){let i=this[je].get(e);void 0===i&&(i=[],this[je].set(e,i)),!1===i?.includes(t)&&i.push(t)}$off(e,t){let i=this[je].get(e);i&&(t?y(i,t):i.length=0)}$trigger(e,t,i){if(!this.$root)return;let s={eventName:e,stopPropagation:i?.stopPropagation??(()=>{}),preventDefault:i?.preventDefault??(()=>{}),data:t,target:i?.target??this.$rootVNode,event:i?.event};if(this.$rootVNode&&this.$rootVNode.parent&&this.$rootVNode.parent instanceof X.Component&&!1===this[Be]?.render.triggerEvent(this.$rootVNode.parent,e,s))return;let n=this[je].get(e);n?.length&&[...n].forEach((e=>{e(s)}));let r=this[je].get("*");r?.length&&[...r].forEach((e=>{e(s)}))}$render(e,t){e??=this.template,this.template="function"==typeof e?e(s):e,this.$root&&(this.template??=[],this[Be]?.reSetAsts(this.template,t),this[Be]??=new De(this.template,this,this.$root),this[Be].parser(),this.$root&&this[Be].mount(this.$root))}created(){}mounted(){}beforeDestroy(){}sleeped(){}wakeup(){}destroyed(){}}const Xe={};function ze(e,t){if("string"==typeof e)t&&(Xe[e]=t);else for(let t in e)Xe[t]=e[t]}function Ue(e){return Xe[e]}function Ze(e){e.childrens?.forEach((e=>{e instanceof X.Component&&e.component?.sleeped(),Ze(e)}))}function Qe(e){e.childrens?.forEach((e=>{e instanceof X.Component&&e.component?.wakeup(),Qe(e)}))}class et extends qe{template=[];cache=new Map;mounted(){this.$watch((()=>this.props.name),(async e=>{this.$render([],!0),await Promise.resolve(),this.$root&&this.loadComponent(e)})),this.loadComponent(this.props.name)}propsVaule;created(){this.initProps()}initProps(){let e={};this.props.props||(Object.keys(this.props).forEach((t=>{!1!==this.filterProps(t)&&(e[t]=this.props[t],this.$watch((()=>this.props[t]),(()=>{this.propsVaule[t]=this.props[t]})))})),this.propsVaule=k(e))}filterProps(e){if("string"!=typeof e)return!1;let t=g(e);return"transition-name"!==t&&"name"!==t&&"keep-alive"!==t&&"ref"!==t&&void 0}async loadComponent(e){if(!e)return void this.$render([],this.isKeepAlive);let t;if(this.isKeepAlive){let t=this.cache.get(e);if(t)return void this.$render([n(t,{"transition-name":this.props["transition-name"]})],!0)}let i=this.$rootVNode?.parent?.[X.PARSERKEY]?.ob.components,s=i?.[e];void 0===s&&(s=Ue(e)),s?(Je in s||(s=(await s()).default),t=new s(this.props.props||this.propsVaule,this.$sections,this.isKeepAlive),t.$on("*",(e=>{this.$trigger(e.eventName,e.data,e)})),this.isKeepAlive&&this.cache.set(e,t),this.$render([n(t,{"transition-name":this.props["transition-name"]})],this.isKeepAlive)):C.warn("component",`未找到${e}的组件`)}beforeDestroy(){this.removeCache()}removeCache(e){if(e){let t=this.cache.get(e);this.cache.delete(e),t&&t.$destroy(!0)}else this.cache.forEach((e=>{e.$destroy(!0)})),this.cache.clear()}}class tt extends qe{template=function(){return[r("RenderSection")]}}ze({template:tt,component:et});class it{eventDatas=new Map;on(e,t){let i=this.eventDatas.get(e);void 0===i&&(i=[],this.eventDatas.set(e,i));let s={callBack:t};return i.push(s),()=>{i&&y(i,s)}}once(e,t){let i=this.eventDatas.get(e);void 0===i&&(i=[],this.eventDatas.set(e,i));let s={callBack:t,once:!0};return i.push(s),()=>{i&&y(i,s)}}off(e,t){if(void 0!==e)if(t){let i=this.eventDatas.get(e),s=i?.find((e=>e.callBack===t));s&&y(i,s)}else this.eventDatas.delete(e);else this.eventDatas.clear()}async trigger(e,t){let i=[...this.eventDatas.get(e)||[]];if(i.push(...this.eventDatas.get("*")||[]),i&&i.length){let s=0,n=0,r=!1;for(;i[s];){let o=i[s],a=await o.callBack({stopPropagation:()=>r=!0,callTimes:n,eventName:e},t);if(o.once?y(i,o):s++,!1===a||r)return!1}}}}export{J as BREAK_WATCH_UPDATE,qe as Component,et as ComponentContainer,x as Dep,it as EventBus,G as IContainer,Ye as IS_DESTROY,Je as JOKER_COMPONENT_TAG,q as JOKER_VNODE_TAG,S as OBJECTPROXY_DEPID,Be as PARSER_TEMPLATE_TARGET,De as ParserTemplate,ee as Render,He as SCOPE_ID,L as ShallowObserver,tt as Template,X as VNode,F as Watcher,ue as __GLONAL_FUNTIONS__,d as __JOKER_HMR_RUNTIME,Y as combinedReply,W as defineObserverProperty,Ue as getGlobalComponent,B as isObserverData,k as observer,ze as registerGlobalComponent,fe as registerGlobalFunction};
package/dist/bundle.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("@joker.front/ast");const t=new Map,s=new Map,r=new Map;let n={recordRender:(e,t)=>{s.set(e,t)},recordComponent:(e,t)=>{r.set(e,t)},record:(e,s)=>{void 0===t.get(e)&&t.set(e,new Set),t.get(e).add(s),s.$on("destroy",(()=>{t.get(e)?.delete(s)}))},reload:(e,s)=>{let n=r.get(e);if(!n)return;n.component=s;let i=t.get(e);if(!i)return;let o=Array.from(i);i.clear(),o.forEach((e=>{if(e.$root){if(!e.$rootVNode?.parent)return window.onbeforeunload=null,void location.reload();{let t=e.$rootVNode.parent;if(!(t instanceof exports.VNode.Component&&t[exports.VNode.PARSERKEY]&&t[exports.VNode.PARSERKEY].canReload))return window.onbeforeunload=null,void location.reload();t[exports.VNode.PARSERKEY].reload()}}}))},rerender:(e,r)=>{let n=s.get(e);n&&(n.render=r),t.get(e)?.forEach((e=>{e.$render(r)}))}};function i(e){return null!==e&&"object"==typeof e}function o(e,t){Object.getOwnPropertyNames(e).forEach((s=>{t(s,e[s])}))}function a(e){return"[object Object]"===Object.prototype.toString.call(e)}function h(e){if(null===e)return e;if("object"!=typeof e)return e;let t;t=Array.isArray(e)?[]:{};let s=Object.keys(e);for(let r of s){let s=e[r];t[r]="object"==typeof s?h(s):s}return t}function d(e,t,s){return Array.isArray(e)&&Array.isArray(t)?function(e,t,s){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(s){if(e[r]!==t[r])return!1}else if(!1===l(e[r],t[r],s))return!1;return!0}(e,t,s):l(e,t,s)}function l(e,t,s){if(e===t)return!0;let r=i(e),n=i(t);if(r&&n){if(a(e)&&a(t)){let r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;if(s){for(let s of r)if(e[s]!==t[s])return!1;return!0}return JSON.stringify(e)===JSON.stringify(t)}return e===t}return!r&&!n&&String(e)===String(t)}function c(e,t){let s=e.indexOf(t);return s>-1&&e.splice(s,1),e}function p(e,t){let s=e.findIndex((e=>t(e)));return s>-1&&e.splice(s,1),e}function u(e=32){let t=[],s=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];for(let r=0;r<e;r++){let e=Math.round(Math.random()*(s.length-1));t.push(s[e])}return t.join("")}function f(e){return!e||""===e.trim()}function m(e,t="-"){return(e=e||"").split(/(?=[A-Z])/).map((e=>e.toLowerCase())).join(t)}let y=(...e)=>{},E="warn";const N=["silent","error","warn","info"];function g(){let e=new Date;function t(e,t=2){return e.toString().padStart(t,"0")}return t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+":"+t(e.getMilliseconds(),3)}function v(e,t,s,r){N.indexOf(e)<=N.indexOf(E)&&(void 0===r?console[e](`${g()} [${t}]:`,s):console[e](`${g()} [${t}]:`,s,r))}let x={info:function(e,t,s){v("info",e,t,s)},warn:function(e,t,s){v("warn",e,t,s)},error:function(e,t,s){v("error",e,t,s)},setLoggerLeve:function(e){E=e}};const b={lt:"<",gt:">",nbsp:" ",amp:"&",quot:'"',"#39":"'"};function w(e){return e.replace(/&(lt|gt|nbsp|amp|quot|#39);/gi,((e,t)=>b[t]||""))}class R{static target;watchers=new Map;depend(e){R.target?.addDep(this,e)}addWatcher(e,t){let s=this.watchers.get(e)||[];s.push(t),this.watchers.set(e,s)}removeWatcher(e,t){let s=this.watchers.get(e);s&&c(s,t)}notify(e){let t=this.watchers.get(e);if(t){p(t,(e=>e.isDestroy)),[...t].forEach((e=>{!1===e.isDestroy&&e.update()}))}}}const A=Symbol.for("__JOKER_OBJECT_PROXY_DEP_ID__"),C=Symbol.for("__JOKER_OBJECT_PROXY_DATA_KEY__"),O=Symbol.for("__JOKER_OBJECTPROXY_DEPLEVE_ID__");function S(e){return i(e)&&e instanceof Window==!1&&e instanceof M==!1&&e!==window.parent&&(Array.isArray(e)||a(e)||e instanceof Set||e instanceof Map)&&!Object.isFrozen(e)&&!(e instanceof Element)&&!(j in e)&&!(D in e)&&!(We in e)}function $(e){if(V(e))return e;if(Object.hasOwn(e,C)){let t=Reflect.get(e,C);if(t)return t}let t=new R,s=!0,r=new Proxy(e,{get(e,s,r){if(e instanceof Set||e instanceof Map){if("add"===s){let r=Reflect.get(e,s);return s=>{S(s)&&(s=P(s));let n=r.call(e,s);return I(t,"size"),I(t,O),n}}if("set"===s){let r=Reflect.get(e,s);return(s,n)=>{S(n)&&(n=P(n));let i=r.call(e,s,n);return I(t,"size"),I(t,O),i}}if("delete"===s||"clear"===s){let r=Reflect.get(e,s);return n=>{let i=r.call(e,n);return("clear"===s||i)&&(I(t,"size"),I(t,O)),i}}let r=Reflect.get(e,s);if("function"==typeof r)return r.bind(e)}if(s===C)return;if(s===A)return t;if(s===O)return;let n=Reflect.get(e,s);return s===Symbol.toStringTag||!1===function(e,t){return t in e}(e,s)&&"length"!==s&&"size"!==s||(t.depend(s),S(n)&&V(n)?.depend(O)),n},set(e,r,n){if(s)return Reflect.set(e,r,n),!0;S(n)&&(n=P(n));let i=!1===function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,r),o=Reflect.get(e,r)!==n;return Reflect.set(e,r,n),(o||"length"===r&&Array.isArray(e))&&I(t,r),Array.isArray(e)?"length"===r&&I(t,O):i&&I(t,O),!0},deleteProperty:(e,s)=>(Reflect.deleteProperty(e,s),!1===Array.isArray(e)&&I(t,O),!0)});var n,i,o,a;n=e,i=C,o=r,a=!1,Object.defineProperty(n,i,{value:o,enumerable:a,writable:!0,configurable:!0});for(let t in e){let s=e[t];S(s)&&!V(s)&&(r[t]=$(e[t]))}return s=!1,r}function V(e){if(i(e))return Reflect.get(e,A)}function P(e,t=!1){if(!1===S(e))throw new Error("当前传入的数据不是正确的数据类型,必须是数组或者对象");return $(t?h(e):e)}function T(e,t,s){let r=s;S(s)&&(r=P(s));let n=new R;Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:()=>(n.depend(t),V(r)?.depend(O),r),set:e=>{e!==r&&(S(e)&&(e=P(e)),r=e,I(n,t))}})}const D=Symbol.for("JOKER_SHALLOW_OBSERVER");class _{data;[D]=!0;dep=new R;constructor(e){this.data=e}isChanged=!1;get value(){return this.dep.depend(O),this.data}set value(e){!1===Object.is(e,this.data)&&(this.isChanged=!0,this.data=e,I(this.dep,O))}}let K=!1,k=new Map;function I(e,t){if(!1===K)e.notify(t);else{let s=k.get(e);void 0===s&&(s=[],k.set(e,s)),!1===s.includes(t)&&s.push(t)}}const W="数据观察",L=Symbol.for("JOKER_BREAK_WATCH_UPDATE");class M{ob;updateCallBack;forceCallBack;getter;value;isDestroy=!1;updating=!1;runRelations=new Map;relations=new Map;constructor(e,t,s,r){if(this.ob=e,this.updateCallBack=t,this.forceCallBack=r,void 0===e)throw new Error("无法对underfind进行变更观察");if(void 0===s)this.getter=e=>e;else if("function"==typeof s)this.getter=s;else{let e=function(e){if(/[^\w.$]/.test(e))return;let t=e.split(".");return function(e){let s=e;return t.forEach((e=>{s&&(s=s[e])})),s}}(s);if(void 0===e)throw new Error(s+"解析失败,无法明确读取表达式,请检查expOrFn参数,或采用function模式");this.getter=e}void 0===this.getter&&x.error(W,"getter创建失败",arguments),this.value=this.getValue()}getValue(){if(void 0===this.getter)return;R.target=this;let e,t="function"==typeof this.ob?this.ob():this.ob;try{e=this.getter.call(t,t)}catch(e){throw x.error(W,`获取值失败,执行方法:${this.getter.toString()}`),e}return R.target=void 0,this.clearnDeps(),e}addDep(e,t){let s=this.runRelations.get(e);if(void 0===s||!1===s.includes(t)){s=s||[],s.push(t),this.runRelations.set(e,s);let r=this.relations.get(e);void 0!==r&&!1!==r.includes(t)||e.addWatcher(t,this)}}update(){if(this.updating)return;let e=this.getValue();if(e===L)return;let t=this.value;if(this.forceCallBack||e!==t||i(e)){this.value=e;let s=e!==t&&d(e,t,!0);if(s&&!this.forceCallBack)return;this.updating=!0;try{this.updateCallBack(e,t,s,this)}catch(e){throw e}finally{this.updating=!1}}}destroy(){this.relations.forEach(((e,t)=>{for(let s of e)t.removeWatcher(s,this)})),this.isDestroy=!0,this.relations.clear(),this.runRelations.clear(),this.ob=void 0,this.value=void 0,this.getter=void 0}clearnDeps(){this.relations.forEach(((e,t)=>{let s=this.runRelations.get(t);for(let r of e)s?!1===s.includes(r)&&t.removeWatcher(r,this):t.removeWatcher(r,this)})),this.relations.clear(),this.relations=this.runRelations,this.runRelations=new Map}}exports.IContainer=void 0,function(e){let t=new Map;e.bind=function(e){return{to:s=>{if(t.has(e))throw new Error(`TagId:${e.toString()}已注入实现类,请勿重复注入。`);t.set(e,s)}}},e.get=function(e,...s){let r=t.get(e);if(r)return new r(...s)}}(exports.IContainer||(exports.IContainer={}));const j=Symbol.for("JOKER_VNODE_TAG");exports.VNode=void 0,function(e){e.PARSERKEY=Symbol.for("JOKER_PARSER_KEY");class t{parent;[j]=!0;static;output;[e.PARSERKEY];childrens;sleep=!1;constructor(e){this.parent=e}get prev(){if(this.parent)return this.parent.childrens?.[this.parent.childrens?.indexOf(this)-1]}get next(){if(this.parent)return this.parent.childrens?.[this.parent.childrens?.indexOf(this)+1]}closest(t,s){if(!0===t(this))return this;let r=this.parent;for(;r;){if(s&&r instanceof e.Root)return;if(!0===t(r))return r;r=r.parent}}find(e,t,s){let r=s??[];if(t??=this.childrens,t)for(let s of t){!0===e(s)&&r.push(s),s.childrens&&this.find(e,s.childrens,r)}return r}contains(e,t){if(t??=this.childrens,t)for(let s of t){if(!0===e(s))return!0;if(s.childrens&&s.childrens.length&&this.contains(e,s.childrens))return!0}return!1}first(e,t){if(t??=this.childrens,t)for(let s of t){if(!0===e(s))return s;if(s.childrens&&s.childrens.length){let t=this.first(e,s.childrens);if(t)return t}}}}e.Node=t;e.Root=class extends t{childrens=[];component;constructor(){super()}};e.Text=class extends t{text;static=!0;constructor(e,t){super(t),this.text=e}};e.Html=class extends t{html;notShadow;static=!0;constructor(e,t,s){super(t),this.html=e,this.notShadow=s}};e.Comment=class extends t{text;static=!0;constructor(e,t){super(t),this.text=e}};e.Element=class extends t{tagName;static=!0;attributes={};childrens=[];events=[];_assistEventCache;constructor(e,t){super(t),this.tagName=e}};e.Component=class extends t{name;component;events=[];propValues={};keepalive;get firstElement(){if(this.childrens){let t=s=>{for(let r of s){if(r instanceof e.Element)return r;if(r.childrens){let e=t(r.childrens);if(e)return e}}};return t(this.childrens)}}get rootElements(){if(this.childrens){let t=[],s=r=>{for(let n of r)n instanceof e.Element||n instanceof e.Html?t.push(n):n.childrens&&s(n.childrens)};return s(this.childrens),t}return[]}};e.Condition=class extends t{cmdName;result=!1;childrens=[];isShow=!1;constructor(e,t){super(t),this.cmdName=e}};e.List=class extends t{childrens=[]};e.ListItem=class extends t{ob;childrens=[];constructor(e,t){super(t),this.ob=e}};e.RenderSection=class extends t{id="unknown";params=[];section;childrens=[];ob;constructor(e,t){super(t),"string"==typeof e?this.id=e:this.section=e}}}(exports.VNode||(exports.VNode={}));const H="DOM渲染",Y=["script","style","textarea","pre"];let B=0;const J=["svg","defs","use","rect","circle","ellipse","line","polyline","polygon","path","text","g"];function G(e,t,s){return`${e}-${t}-${s}`}function F(e,t,s,r){e._assistEventCache??=[],e._assistEventCache.push([t,s]),document.body.addEventListener(t,s,r)}function q(e,t,s){e._assistEventCache&&t&&s?(p(e._assistEventCache,(e=>e[0]===t&&e[1]===s)),document.body.removeEventListener(t,s)):(e._assistEventCache?.forEach((e=>{document.body.removeEventListener(e[0],e[1])})),e._assistEventCache&&(e._assistEventCache.length=0),e._assistEventCache=void 0)}exports.Render=void 0,function(e){e.IRENDERIOCTAGID=Symbol.for("JOKER_IRENDERIOC_TAGID"),e.ROOT_CONTAINER="";e.DomRender=class{elements;constructor(){this.elements=document.createDocumentFragment()}mount(e,t){if(e instanceof Element)e.appendChild(this.elements),t?.();else if(e instanceof exports.VNode.Component)if(e.parent)if(e.output){let s=e.output,r=Z(e)||s.parentNode;r&&(r.insertBefore(this.elements,s),document.contains(r)&&t?.())}else x.error(H,"组件挂载渲染时发现该节点未定义DOM定位节点",e);else x.error(H,"mount子组件时,发现该组件无父级",e);else x.error(H,"mount只支持挂载到Element或VNode.Node类型数据中",e)}appendNode(e,t){if(this.renderNode(e),e.output){let s=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];for(let r of s)this.appendNodeChildren(e,r,e.parent,t)}else x.error(H,"未找自身节点的el属性,无法进行dom挂载",e)}updateNode(e,t){if(e instanceof exports.VNode.Element)for(let t in e.attributes){let s=e.attributes[t];this.setAttribute(e.output,t,s)}else e instanceof exports.VNode.Text?e.parent&&e.parent instanceof exports.VNode.Element&&Y.includes(e.parent.tagName)?(this.removeNode(e),this.appendNode(e)):e.output.textContent=w(e.text||""):e instanceof exports.VNode.Html?e.notShadow?e.output.innerHTML=e.html:e.output.root.innerHTML=e.html:x.error(H,`该节点不支持${t}的更新`,e)}removeNode(e,t){let s=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];s?.forEach((e=>{e?.remove()})),t||(e instanceof exports.VNode.Element&&q(e),e.output=void 0)}destroy(){this.elements=void 0}elementToEnter(e,t,s,r){e.output&&this.transitionFrame(e,t,"enter",s,r)}elementToLeave(e,t,s,r){e.output&&this.transitionFrame(e,t,"leave",s,r)}triggerEvent(e,t,s){let r=[];for(let n of e.events){let[i,o]=n;if(i===t){let t=o.modifiers?.includes("self"),a=o.modifiers?.includes("outside");if(t||a){x.warn(H,"事件修饰符:self、outside在组件事件中无法使用,组件无法确认元素",e);continue}let h=s.event;if((h instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(i)||h instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(i))&&!1===z(h,o.modifiers))continue;if(o.callBack(s),o.modifiers?.includes("prevent")&&s.preventDefault(),o.modifiers?.includes("once")&&r.push(n),o.modifiers?.includes("stop"))return s.stopPropagation(),!1}}r.length&&r.forEach((t=>{c(e.events,t)}))}transitionFrame(e,t,s,r,n){Q(e,G(t,s,"from")),r||="transition";let i=e.output.__TRANSITION_EVNETID__=B++;requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(!e.output)return;Q(e,G(t,s,"active")),U(e,G(t,s,"from")),Q(e,G(t,s,"to"));let o=function(e,t){let s=window.getComputedStyle(e),r=e=>(s[e]||"").split(", ");if("transition"===t){let e=r("transitionDelay"),t=r("transitionDuration"),s=ee(e,t);if(s>0)return{timeout:s,count:t.length}}else if("animation"===t){let e=r("animationDelay"),t=r("animationDuration"),s=ee(e,t);if(s>0)return{timeout:s,count:t.length}}}(e.output,r);if(!o)return void n?.();let a=0,h=()=>{U(e,G(t,s,"to")),U(e,G(t,s,"active")),e.output&&(e.output.removeEventListener(`${r}end`,d),i===e.output.__TRANSITION_EVNETID__&&n?.())},d=t=>{t.target===e.output&&++a>=o.count&&h()};setTimeout((()=>{a<o.count&&h()}),o.timeout+1),e.output?.addEventListener(`${r}end`,d)}))}))}renderNode(e){if(!e.output)if(e instanceof exports.VNode.Text)e.parent&&e.parent instanceof exports.VNode.Element&&Y.includes(e.parent.tagName)?e.output=this.parserHtml(e.text):e.output=document.createTextNode(w(e.text||""));else if(e instanceof exports.VNode.Html)if(e.notShadow){let t=document.createElement("joker-html-container");t.JOKER_NODE=e,t.innerHTML=e.html,e.output=t}else{let t=document.createElement("joker-html-shadow");t.JOKER_NODE=e,t.style.lineHeight="1",t.root.innerHTML=e.html,e.output=t}else if(e instanceof exports.VNode.Element){let t,s=e.tagName.toLowerCase();"svg"===s||J.includes(s)||e.parent?.inSvg?(e.inSvg=!0,t=document.createElementNS("http://www.w3.org/2000/svg",e.tagName)):t=document.createElement(e.tagName);for(let s in e.attributes)this.setAttribute(t,s,e.attributes[s]);t.JOKER_NODE=e,e.output=t,e.events.some((e=>"click"===e[0]&&e[1].modifiers?.includes("outside")))?setTimeout((()=>{this.initElementEvents(t,e)})):this.initElementEvents(t,e)}else e instanceof exports.VNode.Comment?e.output=document.createComment(e.text):e.output=document.createTextNode("")}initElementEvents(e,t){for(let[s,r]of t.events){let n=r.modifiers?.includes("self"),i=r.modifiers?.includes("outside");n&&i&&(x.warn(H,"事件修饰符:self、outside不可以同时存在,将按照self处理",t),i=!1);let o,a=function(o){if(!(t.sleep||n&&o.target!==e)){if(i){if(o.target===e||e.contains(o.target))return;if(!1===document.contains(o.target))return;if(t.contains((e=>(e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output]).includes(o.target))))return!0}(o instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(s)||o instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(s))&&!1===z(o,r.modifiers)||(r.callBack({eventName:s,event:o,target:t,preventDefault:()=>o.preventDefault(),stopPropagation:()=>o.stopPropagation(),data:void 0}),r.modifiers?.includes("prevent")&&o.preventDefault(),r.modifiers?.includes("stop")&&o.stopPropagation(),r.modifiers?.includes("once")&&(i?q(t,s,a):e.removeEventListener(s,a)))}};r.modifiers?.includes("passive")&&(o={passive:!0}),i?F(t,s,a,o):e.addEventListener(s,a,o)}}parserHtml(e){var t=document.createElement("div");return t.innerHTML=e,t.childNodes}isCommandGroup(e){return e instanceof exports.VNode.Component||e instanceof exports.VNode.Condition||e instanceof exports.VNode.List||e instanceof exports.VNode.ListItem||e instanceof exports.VNode.RenderSection}appendNodeChildren(e,t,s,r){let n=Z(e);if(n)n.appendChild(t);else if(void 0===s)this.elements?.appendChild(t);else if(s)if(s instanceof exports.VNode.Root){let e=s.parent;if(e&&e instanceof exports.VNode.Component&&e.output){let s=e.output,r=s?.parentNode;if(r)return void r.insertBefore(t,s)}this.elements?.appendChild(t)}else if(s instanceof exports.VNode.Element){let e=s.output;if(void 0===e)return;e.appendChild(t)}else if(this.isCommandGroup(s)){let e=s.output,n=e?.parentNode;if(void 0!==r&&s.childrens?.length&&n){let e=r-1;if(e<0)return void n.insertBefore(t,n.firstChild);{let r=s.childrens[e];if(r){let e=r.output;if(e)return void e.after(t)}}}n&&n.insertBefore(t,e)}else x.error(H,"该节点不支持嵌套子集,请检查。",{node:e,parent:s})}setAttribute(e,t,s){if(e)if("boolean"!=typeof s){if("class"===t){if(Array.isArray(s)){let e=[];for(let t of s)if(i(t))for(let s in t)t[s]&&e.push(s);else t&&e.push(t);s=e.join(" ")}else if(i(s)){for(let t in s)s[t]?e.classList.add(t):e.classList.remove(t);return}}else if("style"===t&&i(s)){e.removeAttribute("style");for(let t in s){let r=!1;void 0!==s[t]&&!1!==s[t]||(r=!0);let n=String(s[t]);f(n)&&(r=!0),r||(e.style[t]=n)}return}s=(s??"").toString().trim(),"class"===t&&(s=s.split(/\s/).filter((e=>e.trim())).join(" ")),"value"===t&&"value"in e?e.value=s:"xlink:href"===t?e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",s):e.setAttribute(t,s)}else s?e.setAttribute(t,""):e.removeAttribute(t)}}}(exports.Render||(exports.Render={}));const X={enter:"enter",backspace:"delete",tab:"tab",arrowup:"up",arrowdown:"down",arrowleft:"left",arrowright:"right",escape:"esc"," ":"space"};function z(e,t){if(e instanceof KeyboardEvent){if(void 0===e.key)return!1;for(let s in X)if(t?.includes(X[s])&&e.key.toLowerCase()!==s)return!1}else{if(t?.includes("left")&&0!==e.button)return!1;if(t?.includes("right")&&2!==e.button)return!1;if(t?.includes("middle")&&1!==e.button)return!1}return(!t?.includes("ctrl")||!1!==e.ctrlKey)&&((!t?.includes("alt")||!1!==e.altKey)&&(!t?.includes("shift")||!1!==e.shiftKey))}function Q(e,t){e.output&&e.output.classList.add(t)}function U(e,t){e.output&&e.output.classList.remove(t)}function Z(e){if(e instanceof exports.VNode.Element||e instanceof exports.VNode.Component){let t=e instanceof exports.VNode.Component?e.propValues["append-to"]:e.attributes["append-to"];if(t){if(t instanceof exports.VNode.Element)return t.output;if("string"==typeof t){exports.Render.ROOT_CONTAINER&&(t="body"===t?exports.Render.ROOT_CONTAINER:`${exports.Render.ROOT_CONTAINER} ${t}`);let e=document.querySelector(t);if(e)return e}x.warn(H,"appendTo类型不支持",{appendTo:t,node:e})}}}function ee(e,t){for(;e.length<t.length;)e.concat(e);return Math.max(...t.map(((t,s)=>te(t)+te(e[s]))))}function te(e){return"auto"===e?0:1e3*Number(e.slice(0,-1).replace(",","."))}class se extends HTMLElement{root;constructor(){super(),this.root=this.attachShadow({mode:"open"})}}!customElements.get("joker-html-shadow")&&customElements.define("joker-html-shadow",se);const re={};const ne="Global",ie="渲染核心";function oe(t){try{return new Function(e.EXPRESSHANDLERTAG,ne,`return ${t};`)}catch{throw new Error("创建表达式运行方法时出现未知错误,表达式为"+t)}}class ae{ast;ob;parent;ext;ref="";watchers=[];node;isDestroy=!1;constructor(e,t,s,r){this.ast=e,this.ob=t,this.parent=s,this.ext=r}init(e){let t=this.parser(e);if(this.afterParser(),t)return t}beforeDestroy(e){}destroy(e){if(this.isDestroy=!0,this.clearWatchers(),this.parent.childrens&&this.node){(this.node instanceof exports.VNode.Element||this.node instanceof exports.VNode.Component)&&this.ext.removeRef(this.node);let t=()=>{this.parent&&this.node&&(this.beforeDestroy(e),this.destroyChildrens(e),this.ext.render?.removeNode(this.node),this.parent.childrens&&c(this.parent.childrens,this.node),this.notifyNodeWatcher("remove"),this.destroyOtherData())};if(this.ext.nodeTransition(this.node,"leave",void 0,(()=>{t()})))return c(this.parent.childrens,this.node),void this.destroyChildrensWatcher(this.node);t()}else this.destroyOtherData()}destroyWathcers(){this.isDestroy=!0,this.clearWatchers(),this.destroyChildrensWatcher(this.node)}destroyOtherData(){this.node&&(this.node[exports.VNode.PARSERKEY]=void 0),this.node=void 0,this.parent=void 0}destroyChildrens(e){for(;this.node?.childrens?.length;){let t=this.node.childrens[0];t[exports.VNode.PARSERKEY]?t[exports.VNode.PARSERKEY].destroy(e):c(this.node.childrens,t)}}destroyChildrensWatcher(e){if(e?.childrens?.length)for(let t of e?.childrens)t[exports.VNode.PARSERKEY]&&(t[exports.VNode.PARSERKEY].clearWatchers(),this.destroyChildrensWatcher(t))}appendNode(e){this.parent?.childrens&&this.node&&!this.isDestroy&&(this.node[exports.VNode.PARSERKEY]=this,this.node instanceof exports.VNode.Element&&this.ob[Ie]&&(this.node.attributes["data-scoped-"+this.ob[Ie]]=void 0),this.ext.render?.appendNode(this.node,e),void 0===e?this.parent.childrens.push(this.node):this.parent.childrens.splice(e,0,this.node),this.notifyNodeWatcher("append"))}afterParser(){this.ext.nodeTransition(this.node,"enter")}notifyNodeWatcher(e,t){this.ext.notifyNodeWatcher(this.ref,this.node,e,t)}runExpress(e,t){try{return oe(e).call(t,t,re)}catch(s){x.error(ie,"运行表达式出现错误:"+e,{ob:t}),console.error(s)}}runExpressWithWatcher(e,t,s,r){if(this.isDestroy)return;let n="string"==typeof e?oe(e):e,i=new M((()=>{if(this.isDestroy||t[_e])return L;try{return n.call(t,t,re)}catch(s){return x.error(ie,"运行表达式出现错误",{ob:t,express:e,node:this.node}),console.error(s),L}}),s,void 0,r);return this.addWatch(i),i.value===L?void 0:i.value}addWatch(e){!1===this.watchers.includes(e)&&this.watchers.push(e)}clearWatchers(){this.watchers.forEach((e=>{e.destroy()})),this.watchers.length=0}}class he extends ae{parser(){this.node=new exports.VNode.Text(this.ast.text,this.parent),this.appendNode()}}class de extends ae{parser(){this.node=new exports.VNode.Comment(this.ast.text,this.parent),this.appendNode()}}class le extends ae{async parser(){if(this.node=new exports.VNode.Condition(this.ast.kind,this.parent),"else"!==this.ast.kind){f(this.ast.condition)&&x.error("条件命令",`当前条件命令${this.ast.kind}没有判断条件,请检查`);let e=this.runExpressWithWatcher(this.ast.condition,this.ob,(e=>{let t=!!e;if(this.node?.result!==t){if(this.node.result=t,!1===t&&this.node?.isShow)this.destroyChildrens(!0);else if(t&&!this.node?.isShow){let e=this.getElseNode();if(e&&e.isShow&&e.childrens?.length){let t=e[exports.VNode.PARSERKEY];t&&t instanceof le&&t.renderConditionChildren()}}this.renderId=u(),this.reloadAllCondition(this.renderId)}}));this.node.result=!!e}this.appendNode(),this.renderId=u(),await this.renderConditionChildren()}renderId;getElseNode(){let e=this.node?.next;for(;e&&e instanceof exports.VNode.Condition&&"if"!==e.cmdName;){if("else"===e.cmdName)return e;e=e.next}}async renderConditionChildren(){let e=!1;return this.getPrevIfResult()?e=!1:"else"===this.ast.kind?e=!0:(this.node.result=!!this.runExpress(this.ast.condition,this.ob),this.node.result&&(e=!0)),e!==this.node.isShow&&(this.node.isShow=e,this.destroyChildrens(!0),e&&this.ast.childrens&&await this.ext.parserNodes(this.ast.childrens,this.node,this.ob),!0)}getPrevIfResult(){if("if"===this.ast.kind)return!1;let e=this.node?.prev;for(;e&&e instanceof exports.VNode.Condition;){if(e.result)return!0;if("if"===e.cmdName)break;e=e.prev}return!1}async reloadAllCondition(e){if(await this.renderConditionChildren()&&e===this.renderId){let t=this.node?.next;for(;t&&t instanceof exports.VNode.Condition&&"if"!==t.cmdName;){let s=t[exports.VNode.PARSERKEY];if(s&&s instanceof le&&(await s.renderConditionChildren(),e!==this.renderId))return;t=t.next}}if(e===this.renderId){let t=this.node?.next;for(this.node?.result||this.destroyChildrens(!0);t&&t instanceof exports.VNode.Condition&&"if"!==t.cmdName;){let s=t[exports.VNode.PARSERKEY];if(s&&s instanceof le&&(await s.renderConditionChildren(),e!==this.renderId))return;t=t.next}}}}class ce extends ae{async parser(){this.node=new exports.VNode.List(this.parent),this.appendNode(),await this.renderChildrens()}async renderChildrens(){switch(this.renderId=u(),this.ast.keyType){case"condition":await this.renderConditionChildrens();break;case"in":case"of":await this.renderInOrOfChildrens()}}async renderConditionChildrens(){let t=this.ast.param,s=Object.create(this.ob),r=!!this.runExpressWithWatcher(function(t,s,r){try{return new Function(e.EXPRESSHANDLERTAG,`${e.EXPRESSHANDLERTAG}.${t}=${s}; return ${r};`)}catch{throw new Error(`For循环命令,表达式运行依赖采集出现未知错误,其中letKey:${t},keyVal:${s},condition:${r}`)}}(t.letKey,t.defaultKeyVal,t.condition),s,(()=>{this.clearWatchers(),this.renderChildrens()}),!0);await(async e=>{let n=0,i=[];for(;r;){let o=Object.create(this.ob);T(o,t.letKey,s[t.letKey]);let a=n++,h=this.renderItem(o,a),d=()=>{this.renderId===e&&this.runExpressWithWatcher((()=>s[t.letKey]),s,((e,s,r,n)=>{Promise.resolve().then((()=>{n.isDestroy||(o[t.letKey]=e,r||this.updateListItemOb(o,a))}))}),!0)};h instanceof Promise?i.push(h.then((()=>d()))):d(),this.runExpress(t.step,s),r=!!this.runExpress(t.condition,s)}if(i.length)await Promise.all(i).then((()=>{this.renderId===e&&this.destroyOldChildrens(n)}));else{if(this.renderId!==e)return;this.destroyOldChildrens(n)}})(this.renderId)}renderId;async renderInOrOfChildrens(){let e=this.ast.param,t=this.runExpressWithWatcher(e.dataKey,this.ob,(()=>{this.clearWatchers(),this.renderChildrens()}));await(async s=>{let r=0,n=[];if(t&&(Array.isArray(t)||a(t)))for(let i in t){let o=Object.create(this.ob),a=Array.isArray(t)?Number(i):i;e.indexKey&&T(o,e.indexKey,a),e.itemKey&&T(o,e.itemKey,t[i]);let h=r++,d=()=>{this.renderId===s&&e.itemKey&&this.runExpressWithWatcher((()=>t[a]),t,((s,r,n,i)=>{a in t&&Promise.resolve().then((()=>{i.isDestroy||(o[e.itemKey]=s,n||this.updateListItemOb(o,h))}))}),!0)},l=this.renderItem(o,h,e.indexKey);l instanceof Promise?n.push(l.then((()=>d()))):d()}if(n.length)await Promise.all(n).then((()=>{this.renderId===s&&this.destroyOldChildrens(r)}));else{if(this.renderId!==s)return;this.destroyOldChildrens(r)}})(this.renderId)}findIndexByIndex(e,t,s){let r=-1;if(this.node)for(let n=t;n<this.node.childrens.length;n++)if(this.checkObEqual(e,this.node.childrens[n]?.ob,s?[s]:void 0)){r=n;break}return r}renderItem(e,t,s){if(!this.ast.childrens?.length||!this.node)return;let r=this.node.childrens?.[t];if(r){if(this.checkObEqual(e,r.ob,s?[s]:void 0))return void(s&&r.ob[s]!==e[s]&&(r.ob[s]=e[s]));let n=this.findIndexByIndex(e,t+1,s);if(n>-1){if(t+1===n)this.node.childrens?.[t]?.[exports.VNode.PARSERKEY]?.destroy();else for(let e=0;e<n-t-1;e++)this.node.childrens?.[t]?.[exports.VNode.PARSERKEY]?.destroy();return this.renderItem(e,t,s)}return new pe(this.ast,e,this.node,this.ext).init(t)}return new pe(this.ast,e,this.node,this.ext).init()}updateListItemOb(e,t){if(!this.ast.childrens?.length||!this.node)return;let s=this.node.childrens?.[t];o(e,((e,t)=>{s.ob[e]!==t&&(s.ob[e]=t)}))}destroyOldChildrens(e){if(this.node)for(;this.node.childrens.length>e;){let e=this.node.childrens.pop();if(!e)break;e[exports.VNode.PARSERKEY]?.destroy(!1)}}checkObEqual(e,t,s){let r=!0;return void 0!==t&&(o(e,((e,n)=>{s?.includes(e)||t?.[e]===n||(r=!1)})),r)}}class pe extends ae{async parser(e){this.node=new exports.VNode.ListItem(this.ob,this.parent),this.appendNode(e),this.ast.childrens&&await this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}}function ue(e,t){if(!e)return e;if(e instanceof Promise)return e.then((e=>Promise.resolve(e)));if(Array.isArray(e)&&e.length){let s=[];for(let r in e){let n,i=e[r];n=t?ue(i,t):i,n instanceof Promise&&s.push(n.then((t=>{e[r]=t})))}if(s.length>0)return Promise.all(s).then((()=>Promise.resolve(e)))}else if("object"==typeof e&&null!==e&&a(e)&&e instanceof Element==!1){let s=[];for(let r in e){let n=e[r];if(n instanceof Promise)s.push(n.then((t=>{e[r]=t})));else if(t){let e=ue(n,t);e instanceof Promise&&s.push(e)}}if(s.length)return Promise.all(s).then((()=>e))}return e}function fe(e,t){if(!e.constructor)return!1;let s=Object.getOwnPropertyDescriptor(e.constructor.prototype,t);return s&&s.get}class me extends ae{parser(){if(f(this.ast.cmdName))throw x.error("模板指令","解析AST转换VNode时发生错误,未找到指令名称",this.ast),new Error("解析AST转换VNode时发生错误,未找到指令名称");let t;if("Html"===this.ast.cmdName||"Text"===this.ast.cmdName?t=this.ast.param:this.ast.cmdName.startsWith(ne+".")?t=`${this.ast.cmdName}(${this.ast.param})`:this.ast.cmdName in this.ob&&"function"==typeof this.ob[this.ast.cmdName]&&(t=`${e.createFuntionBody(this.ast.cmdName)}(${this.ast.param})`),t){let e=this.runExpressWithWatcher(`[${t}]`,this.ob,(e=>{let s=ue(e[0]);s instanceof Promise?s.then((e=>{this.changeValue(e)})).catch((e=>{x.error("表达式编译",`${t}异步处理失败`,e)})):this.changeValue(s)}));e||=[];let s=ue(e[0]);return s instanceof Promise?("Html"===this.ast.cmdName?this.node=new exports.VNode.Html("",this.parent,e[1]):this.node=new exports.VNode.Text("",this.parent),s.then((e=>{this.changeValue(e)})).catch((e=>{x.error("表达式编译",`${t}异步处理失败`,e)}))):"Html"===this.ast.cmdName?this.node=new exports.VNode.Html(ye(s),this.parent,e[1]):this.node=new exports.VNode.Text(ye(s),this.parent),void this.appendNode()}throw new Error(`未找到命令:${this.ast.cmdName}`)}changeValue(e){this.node&&(this.node instanceof exports.VNode.Html?this.node.html=ye(e):this.node.text=ye(e),this.ext.render?.updateNode(this.node))}}function ye(e){return null==e||"function"==typeof e?"":e.toString()}const Ee="default";class Ne extends ae{async parser(){let e=this.transformParam();this.node=new exports.VNode.RenderSection(e.id,this.parent),this.node.params=e.params,this.node.section??=this.ob.$sections?.[e.id],this.appendNode(),this.node.section&&(this.node.section.params?(this.node.ob=Object.create(this.node.section.ob||this.ob),this.node.section.params?.forEach(((e,t)=>{T(this.node.ob,e,this.node.params[t])}))):this.node.ob=this.node.section.ob||this.ob,await(this.node.section.parser||this.ext).parserNodes(this.node.section.asts,this.node,this.node.ob))}transformParam(){if(this.ast.param){let e=this.runExpressWithWatcher(`[${this.ast.param}]`,this.ob,(e=>{let t=e?.[0]||Ee;if("string"==typeof t&&t!==this.node.id)throw new Error("section id 不可动态变更");this.node.params=e.slice(1),this.node?.ob&&this.node.section&&this.node.section.params?.forEach(((e,t)=>{this.node?.ob&&this.node.ob[e]!==this.node.params[t]&&(this.node.ob[e]=this.node.params[t])}))}),!0);return{id:e?.[0]||Ee,params:e?.slice(1)||[]}}return{id:Ee,params:[]}}}const ge="组件解析";function ve(e,t){return!!t.components[e]||!!Be(e)}class xe extends ae{async parser(){if(this.ast.node)return this.node=this.ast.node,this.node.parent=this.parent,this.initPropData(),void(this.node&&(this.appendNode(),this.node.component?.$mount(this.node)));this.node=new exports.VNode.Component(this.parent);let e=this.initPropData();this.appendNode(),this.node&&this.initEvent(),e.length&&await Promise.all(e),await this.renderChildren()}get canReload(){return"tagName"in this.ast||"function"==typeof this.ast.component}reload(){this.canReload?(this.beforeDestroy(),this.renderChildren()):x.warn(ge,"当前组件无法实现reload",this.node)}initPropData(){let e=[];for(let t of this.ast.attributes)if("ref"!==t.name)if("keep-alive"===t.name&&"false"!==t.value&&(this.node.keepalive=!0),t.express){let s=this.runExpressWithWatcher(t.express,this.ob,(e=>{let s=ue(e);s instanceof Promise?s.then((e=>{this.node&&(this.node.propValues[t.name]=e,this.notifyNodeWatcher("update",t.name))})).catch((e=>{x.error(ge,`${t.express}异步处理失败`,e)})):(this.node.propValues[t.name]=s,this.notifyNodeWatcher("update",t.name))}),!0),r=ue(s);r instanceof Promise?(r.then((e=>{this.node&&(this.node.propValues[t.name]=e)})).catch((e=>{x.error(ge,`${t.express}异步处理失败`,e)})),e.push(r)):this.node.propValues[t.name]=r}else this.node.propValues[t.name]=t.value;else{if(f(t.value)){x.warn(ge,"元素的ref值不可以为空");continue}this.ref=t.value,this.ext.addRef(t.value,this.node)}return this.node.propValues=P(this.node.propValues),e}initEvent(){this.ast.events.forEach((e=>{let t=e.functionName?this.ob[e.functionName]:void 0;void 0===e.functionName?this.node.events.push([e.name,{modifiers:e.modifiers,callBack:y}]):t&&"function"==typeof t?this.node.events.push([e.name,{modifiers:e.modifiers,callBack:s=>{let r=[];e.functionParam&&(r=this.runExpress(`[${e.functionParam}]`,this.ob)),t.call(this.ext.ob,s,...r)}}]):x.error(ge,`${"tagName"in this.ast?this.ast.tagName:""}元素中${e.name}事件所指定的回调(${e.functionName})方法未找到,请检查`)}))}async renderChildren(){if("tagName"in this.ast){let e=this.ob.components[this.ast.tagName]||Be(this.ast.tagName);if(void 0===e)return void x.error(ge,`渲染组件失败,未找到名称为'${this.ast.tagName}'的私有组件/全局组件`);if(We in e||(e=(await e()).default),!this.node)return;{let t=this.getSections();this.node.name=this.ast.tagName,this.node.component=new e(this.node?.propValues,t,this.node?.keepalive)}}else if("function"==typeof this.ast.component){let e=this.getSections();this.node.component=new this.ast.component(this.node?.propValues,e,this.node?.keepalive)}else this.node.component=this.ast.component;if(!this.node)return;if(!this.node.name&&"name"in this.node.component&&this.node.component.name&&"string"==typeof this.node.component.name&&(this.node.name=this.node.component.name),await this.node.component.$mount(this.node),!this.node)return;let e=this.node?.component;e.isKeepAlive&&(this.ast.node=this.node)}getSections(){let t={},s=[];return this.ast.childrens.forEach((t=>{if(t.type===e.AST.NodeType.COMMAND&&"if"===t.cmdName&&t.childrens){let r=t,n=t.childrens.some((t=>t.type===e.AST.NodeType.COMMAND&&"section"===t.cmdName)),i=r.condition.startsWith(e.EXPRESSHANDLERTAG+".$sections");if(i){return this.runExpress(r.condition,this.ob)?void s.push(...t.childrens):void 0}if(n&&"if"===r.kind&&!i)return void x.warn(ge,"在解析section时,发现该section包裹在一个条件语句中,该条件语句仅支持以$sections进行if判断,已作排出")}s.push(t)})),s.forEach((s=>{if(s.type===e.AST.NodeType.COMMAND&&"section"===s.cmdName){let e=s,r=e.id||Ee;/^(\'|\")(.*?)((\'|\"))$/.test(r)&&(r=r.slice(1,-1)),t[r]=t[r]||{asts:[],ob:this.ob,params:e.paramKeys,parser:this.ext},t[r].asts.push(...s.childrens||[])}else t[Ee]=t[Ee]||{asts:[],ob:this.ob,parser:this.ext},t[Ee].asts.push(s)})),t}beforeDestroy(e){!0===e&&this.node?.component?.isKeepAlive?this.node?.component?.$destroy():(this.node?.component?.$destroy(!0),this.ast.node=void 0)}}const be="Element解析";class we extends ae{async parser(){this.node=new exports.VNode.Element(this.ast.tagName,this.parent);let e=this.initAttributes();this.initEvents(),this.appendNode(),e.length&&await Promise.all(e),await this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}initAttributes(){let e=[];for(let t of this.ast.attributes)if("ref"!==t.name)if(t.express){let s=e=>{this.node&&(this.node.attributes[t.name]=this.transformAttrVal(e),this.ext.render?.updateNode(this.node,t.name),this.notifyNodeWatcher("update",t.name))},r=this.runExpressWithWatcher(t.express,this.ob,(e=>{let r=ue(e);r instanceof Promise?r.then((e=>{s(e)})).catch((e=>{x.error(be,`${t.express}异步处理失败`,e)})):s(r)})),n=ue(r);n instanceof Promise?(n.then((e=>{s(e)})).catch((e=>{x.error(be,`${t.express}异步处理失败`,e)})),e.push(n)):this.node.attributes[t.name]=this.transformAttrVal(n)}else this.node.attributes[t.name]=t.value;else{if(f(t.value)){x.warn(be,"元素的ref值不可以为空");continue}this.ref=t.value,this.ext.addRef(t.value,this.node)}return e}initEvents(){for(let e of this.ast.events){let t=e.functionName?this.ob[e.functionName]:void 0;if(!(void 0===e.functionName||t&&"function"==typeof t))throw new Error(`${this.ast.tagName}元素中${e.name}事件所指定的回调(${e.functionName})方法未找到,请检查`);this.node?.events.push([e.name,{modifiers:e.modifiers,callBack:s=>{if(void 0===t)return;let r=[];e.functionParam&&(r=this.runExpress(`[${e.functionParam}]`,this.ob)),t&&t.call(this.ext.ob,s,...r)}}])}}transformAttrVal(e){return void 0!==e&&("string"==typeof e||"boolean"==typeof e||"function"!=typeof e&&Object.prototype.toString()?e:void 0)}}class Re{asts;ob;root=new exports.VNode.Root;refs={};sleeped=!1;nodeWatcherEvents={};render;constructor(e,t,s){this.asts=e,this.ob=t,this.root.component=t,this.render=exports.IContainer.get(exports.Render.IRENDERIOCTAGID)??new exports.Render.DomRender,s&&s instanceof exports.VNode.Node&&(this.root.parent=s,s.childrens??=[],s.childrens.push(this.root))}async parser(){await this.parserNodes(this.asts,this.root)}mount(e){this.sleeped&&this.weakup(),this.render?.mount(e,(()=>{this.ob[Ke].value=!0,this.root.find((e=>e instanceof exports.VNode.Component&&!e.component?.[Ke].value)).forEach((e=>{e.component&&(e.component[Ke].value=!0)}))}))}promiseQueue=new Set;async parserNodes(t,s,r){if(0!==this.asts.length)for(let n of t){if(0===this.asts.length)return;let t;if(n.type===e.AST.NodeType.TEXT)t=new he(n,r??this.ob,s,this);else if(n.type===e.AST.NodeType.COMMENT)t=new de(n,r??this.ob,s,this);else if(n.type===e.AST.NodeType.COMPONENT)t=new xe(n,r??this.ob,s,this);else if(n.type===e.AST.NodeType.ELEMENT){let e=n;t=ve(e.tagName,r??this.ob)?new xe(e,r??this.ob,s,this):new we(e,r??this.ob,s,this)}else if(n.type===e.AST.NodeType.COMMAND){let e=n;switch(e.cmdName){case"if":case"elseif":case"else":t=new le(e,r??this.ob,s,this);break;case"for":t=new ce(e,r??this.ob,s,this);break;case"RenderSection":t=new Ne(e,r??this.ob,s,this);break;case"section":break;default:t=new me(e,r??this.ob,s,this)}}if(t){let e=t.init();e instanceof Promise&&(this.promiseQueue.add(e),await e.finally((()=>{this.promiseQueue.delete(e),0===this.asts.length&&t&&!1===t.isDestroy&&t?.destroy()})))}}}addRef(e,t){this.refs[e]=this.refs[e]||[],this.refs[e].push(t)}removeRef(e){for(let t in this.refs)this.refs[t].includes(e)&&c(this.refs[t],e)}addNodeWatcher(e,t){this.nodeWatcherEvents[e]=this.nodeWatcherEvents[e]||[],this.nodeWatcherEvents[e].push(t)}removeNodeWatcher(e,t){c(this.nodeWatcherEvents[e]||[],t)}notifyNodeWatcher(e,t,s,r){this.nodeWatcherEvents[e]?.forEach((e=>{e(t,s,r)}))}sleep(e){let t=e||this.root;t.childrens?.forEach((e=>{let t=()=>{e.childrens&&this.sleep(e),e.sleep=!0,this.render?.removeNode(e,!0)};this.nodeTransition(e,"leave",void 0,(()=>{t()}))||t()})),void 0===e&&(this.sleeped=!0)}weakup(e){let t=e||this.root;t.childrens?.forEach((e=>{e.sleep=!1,this.render?.appendNode(e),e.childrens&&this.weakup(e),this.nodeTransition(e,"enter")})),void 0===e&&(this.sleeped=!1)}destroy(e){for(;this.root.childrens.length;){let t=this.root.childrens[0];t[exports.VNode.PARSERKEY]?t[exports.VNode.PARSERKEY].destroy(e):c(this.root.childrens,t)}this.render.destroy(),this.refs={},this.root.childrens.length=0,this.nodeWatcherEvents={},this.asts.length=0}destroyWathcers(){for(let e of this.root.childrens)e[exports.VNode.PARSERKEY]&&e[exports.VNode.PARSERKEY].destroyWathcers()}reSetAsts(e,t){this.destroy(t),this.render=exports.IContainer.get(exports.Render.IRENDERIOCTAGID)??new exports.Render.DomRender,this.asts=e}nodeTransition(e,t,s,r,n){if(e&&e.parent?.childrens&&(e instanceof exports.VNode.Element||e instanceof exports.VNode.Component)){let i=function(e){if(e instanceof exports.VNode.Element||e instanceof exports.VNode.Component){let t=e instanceof exports.VNode.Element?e.attributes:e.propValues;return{name:t["transition-name"],type:t["transition-type"]}}}(e);if(s??=i?.name,n??=i?.type,!s)return!1;let o=Ae(e);if(o)return"enter"===t?this.render.elementToEnter(o,s,n,(()=>{let t=e[exports.VNode.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-enter"),r?.()})):this.render.elementToLeave(o,s,n,(()=>{let t=e[exports.VNode.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-leave"),r?.()})),!0;x.warn("渲染核心","在执行node动画时,发现数据不完备,请检查")}return!1}}function Ae(e){if(e instanceof exports.VNode.Element)return e;if(e.childrens&&e.childrens.length)for(let t of e.childrens)return t instanceof exports.VNode.Element?t:Ae(t)}function Ce(e,t,s){if(void 0===t)return;let r=Array.isArray(s)?s:[s];for(let e of r){if(e===Array&&t instanceof Array)return t;if(typeof t===e.name.toLocaleLowerCase())return t}switch(r[0]){case Number:let e=Number(t);if(!1===isNaN(e))return e;break;case String:return String(t)}throw new Error(`props中${e.toString()}的类型不符合约束类型`)}function Oe(e,t,s){let r,n,i;if("symbol"!=typeof t&&(r=m(t)),t in e?n=e[t]:r&&(n=e[r]),s&&(t in s?i=s[t]:r&&r in s&&(i=s[r])),void 0!==i){if(a(i)&&("type"in i||"required"in i||"default"in i||"validate"in i)){let e=i;if(e.required&&void 0===n)throw new Error(`props中key:${t.toString()}是必须项,请检查`);if(e.type&&(n=Ce(t,n,e.type)),e.validate&&!1===e.validate(n))throw new Error(`props中key${t.toString()}的值校验错误`);n=n??e.default}else n=Se(i)?Ce(t,n,i):n??i;return n}return n}function Se(e){return!![String,Array,Number,Object,Function,Boolean].includes(e)||e instanceof Array&&Se(e[0])}const $e="组件",Ve=Symbol.for("JOKER_PROPS_DATA_KEY"),Pe=Symbol.for("JOKER_PROPS_DATA_PROXY"),Te=Symbol.for("JOKER_PRIVATE_WATCHERS"),De=Symbol.for("JOKER_EVENT_DATA_KEY"),_e=Symbol.for("JOKER_IS_DESTROY"),Ke=Symbol.for("JOKER_IS_RENDER"),ke=Symbol.for("JOKER_PARSER_TEMPLATE_TARGET"),Ie=Symbol.for("JOKER_SCOPE_ID"),We=Symbol.for("JOKER_COMPONENT_TAG"),Le=Symbol();let Me=["constructor","$mount","$nodeTransition","$destroy","$getRef","$getRefs","$syncProp","$watchNode","$watch","$on","$off","$trigger","$render","created","mounted","beforeDestroy","sleeped","wakeup","destroyed"];class je{$sections;isKeepAlive;static[We]=!0;[Ie];model={};template;$root;isSleeped=!1;components={};propsOption;[Ve]={};[ke];[Pe];[Te]=[];[De]=new Map;[_e]=!1;[Ke]=new _(!1);[Le]=!1;constructor(e,t={},s){this.$sections=t,this.isKeepAlive=s,this[Ve]=e||{}}get props(){if(void 0===this[Pe]){let e=this;this[Pe]=new Proxy(e[Ve],{get:(t,s)=>Oe(e[Ve],s,e.propsOption),set(){throw new Error("props 参数不允许变更,只允许单向数据传递")}})}return this[Pe]}async $mount(e){if(!1===this[Le]){let e=()=>{let e=[],t=Object.getPrototypeOf(this);for(;null!==t&&t!==Object.prototype;)Object.getOwnPropertyNames(t).forEach((s=>{!1!==Me.includes(s)||fe(t,s)||"function"!=typeof t[s]||t[s].prototype?.hasOwnProperty("constructor")||e.push(s)})),t=Object.getPrototypeOf(t);return e};for(let t of e())this[t]=this[t].bind(this);this[Le]=!0}return this.$root=e,this.isKeepAlive&&this.isSleeped?(this.isSleeped=!1,this[ke]&&this.$root?(this[ke].mount(this.$root),this.wakeup(),this.$trigger("wakeup"),this.$rootVNode&&Ge(this.$rootVNode),this):(x.error($e,"当前组件在唤醒时,发现渲染处理程序已被销毁,无法进行唤醒操作",[this,this.$root]),this)):(this.isSleeped=!1,this.model=P(this.model),await this.created(),this[_e]?this:(this.$trigger("created"),this.template&&await this.$render(),this[_e]||(await this.mounted(),this.$trigger("mounted"),this.$root||(this[Ke].value=!0)),this))}$nodeTransition(e,t,s,r,n){if("string"==typeof e){let t=this.$getRef(e);if(!t)return void x.error($e,`执行节点动画是找不到ref=${e}的节点`);e=t}this[ke]?.nodeTransition(e,t,s,r,n)}async $updatedRender(e){if(!this[_e])return new Promise((t=>{let s=async()=>{await Promise.resolve();let s=[...this[ke]?.promiseQueue||[]],r=this.$rootVNode?.find((e=>e instanceof exports.VNode.Component));if(r?.forEach((e=>{e?.component&&s.push(...e.component[ke]?.promiseQueue||[])})),s.length)Promise.all(s).finally((()=>{this[_e]||(e?.(),t(void 0))}));else{if(this[_e])return;e?.(),t(void 0)}};if(this[Ke].value)setTimeout((()=>{s()}));else{let[e,t]=this.$watch((()=>this[Ke].value),(e=>{t(),e&&s()}))}}))}$destroy(e){if(!e&&this.isKeepAlive)return this[ke]?.sleep(),this.isSleeped=!0,this.sleeped(),this.$trigger("sleeped"),void(this.$rootVNode&&Je(this.$rootVNode));this[_e]=!0;for(let e of this[Te])e.destroy();this[Te].length=0,this[ke]?.destroyWathcers(),this.beforeDestroy(),this.$trigger("beforeDestroy"),this[ke]?.destroy(),this[ke]=void 0,this.template&&Array.isArray(this.template)&&(this.template.length=0),this.$trigger("destroy"),this[De].clear(),this.$root=void 0,this.isSleeped=!1,this.$sections={},this[Pe]=void 0,this[Ve]={},this.destroyed()}get $refs(){return this[ke]?.refs||{}}$getRef(e){return this.$refs[e]?.[0]}$getRefs(e){return this.$refs[e]}$syncProp(e,t,s){"function"==typeof t&&(s=t,t=void 0),t??=e,s??=e=>e,this.model[t]=s(this.props[e]),this.$watch((()=>this.props[e]),(()=>{this.model[t]=s?.(this.props[e])}))}get $rootVNode(){return this[ke]?.root}$watchNode(e,t){if(this[ke])return this[ke]?.addNodeWatcher(e,t),()=>{this[ke]?.removeNodeWatcher(e,t)};x.warn($e,"该组件还未挂载,不可以进行节点观察监听")}$watch(e,t,s){let r=new M((()=>{if(this[_e]){for(let e of this[Te])e.destroy();return L}return e()}),((e,s)=>{this[_e]||t(e,s)}),void 0,s);return this[Te].push(r),[r.value,()=>{r.destroy(),c(this[Te],r)}]}$on(e,t){let s=this[De].get(e);void 0===s&&(s=[],this[De].set(e,s)),!1===s?.includes(t)&&s.push(t)}$off(e,t){let s=this[De].get(e);s&&(t?c(s,t):s.length=0)}$trigger(e,t,s){if(!this.$root)return;let r={eventName:e,stopPropagation:s?.stopPropagation??(()=>{}),preventDefault:s?.preventDefault??(()=>{}),data:t,target:s?.target??this.$rootVNode,event:s?.event};if(this.$rootVNode&&this.$rootVNode.parent&&this.$rootVNode.parent instanceof exports.VNode.Component&&!1===this[ke]?.render.triggerEvent(this.$rootVNode.parent,e,r))return;let n=this[De].get(e);n?.length&&[...n].forEach((e=>{e(r)}));let i=this[De].get("*");i?.length&&[...i].forEach((e=>{e(r)}))}async $render(t,s){t??=this.template,this.template="function"==typeof t?t(e.RENDER_HANDLER):t,this.$root&&(this.template??=[],this[ke]?.reSetAsts(this.template,s),this[ke]??=new Re(this.template,this,this.$root),await this[ke].parser(),this.$root&&this[ke].mount(this.$root))}created(){}mounted(){}beforeDestroy(){}sleeped(){}wakeup(){}destroyed(){}}const He={};function Ye(e,t){if("string"==typeof e)t&&(He[e]=t);else for(let t in e)He[t]=e[t]}function Be(e){return He[e]}function Je(e){e.childrens?.forEach((e=>{e instanceof exports.VNode.Component&&e.component?.sleeped(),Je(e)}))}function Ge(e){e.childrens?.forEach((e=>{e instanceof exports.VNode.Component&&e.component?.wakeup(),Ge(e)}))}class Fe extends je{template=[];cache=new Map;async mounted(){this.$watch((()=>this.props.name),(async e=>{await this.$render([],!0),await Promise.resolve(),this.$root&&this.loadComponent(e)})),await this.loadComponent(this.props.name)}propsVaule;created(){this.initProps()}initProps(){let e={};this.props.props||(Object.keys(this.props).forEach((t=>{!1!==this.filterProps(t)&&(e[t]=this.props[t],this.$watch((()=>this.props[t]),(()=>{this.propsVaule[t]=this.props[t]})))})),this.propsVaule=P(e))}filterProps(e){if("string"!=typeof e)return!1;let t=m(e);return"transition-name"!==t&&"name"!==t&&"keep-alive"!==t&&"ref"!==t&&void 0}async loadComponent(t){if(!t)return void await this.$render([],this.isKeepAlive);let s;if(this.isKeepAlive){let s=this.cache.get(t);if(s)return void await this.$render([e.createComponent(s,{"transition-name":this.props["transition-name"]})],!0)}let r=this.$rootVNode?.parent?.[exports.VNode.PARSERKEY]?.ob.components,n=r?.[t];void 0===n&&(n=Be(t)),n?(We in n||(n=(await n()).default),s=new n(this.props.props||this.propsVaule,this.$sections,this.isKeepAlive),s.$on("*",(e=>{this.$trigger(e.eventName,e.data,e)})),this.isKeepAlive&&this.cache.set(t,s),await this.$render([e.createComponent(s,{"transition-name":this.props["transition-name"]})],this.isKeepAlive)):x.warn("component",`未找到${t}的组件`)}beforeDestroy(){this.removeCache()}removeCache(e){if(e){let t=this.cache.get(e);this.cache.delete(e),t&&t.$destroy(!0)}else this.cache.forEach((e=>{e.$destroy(!0)})),this.cache.clear()}}class qe extends je{template=function(){return[e.createCommand("RenderSection")]}}Ye({template:qe,component:Fe});Object.defineProperty(exports,"AST",{enumerable:!0,get:function(){return e.AST}}),Object.defineProperty(exports,"EXPRESSHANDLERTAG",{enumerable:!0,get:function(){return e.EXPRESSHANDLERTAG}}),Object.defineProperty(exports,"RENDER_HANDLER",{enumerable:!0,get:function(){return e.RENDER_HANDLER}}),Object.defineProperty(exports,"createCodeFunction",{enumerable:!0,get:function(){return e.createCodeFunction}}),Object.defineProperty(exports,"createCommand",{enumerable:!0,get:function(){return e.createCommand}}),Object.defineProperty(exports,"createComment",{enumerable:!0,get:function(){return e.createComment}}),Object.defineProperty(exports,"createComponent",{enumerable:!0,get:function(){return e.createComponent}}),Object.defineProperty(exports,"createElement",{enumerable:!0,get:function(){return e.createElement}}),Object.defineProperty(exports,"createFuntionBody",{enumerable:!0,get:function(){return e.createFuntionBody}}),Object.defineProperty(exports,"createText",{enumerable:!0,get:function(){return e.createText}}),exports.BREAK_WATCH_UPDATE=L,exports.Component=je,exports.ComponentContainer=Fe,exports.Dep=R,exports.EventBus=class{eventDatas=new Map;on(e,t){let s=this.eventDatas.get(e);void 0===s&&(s=[],this.eventDatas.set(e,s));let r={callBack:t};return s.push(r),()=>{s&&c(s,r)}}once(e,t){let s=this.eventDatas.get(e);void 0===s&&(s=[],this.eventDatas.set(e,s));let r={callBack:t,once:!0};return s.push(r),()=>{s&&c(s,r)}}off(e,t){if(void 0!==e)if(t){let s=this.eventDatas.get(e),r=s?.find((e=>e.callBack===t));r&&c(s,r)}else this.eventDatas.delete(e);else this.eventDatas.clear()}async trigger(e,t){let s=[...this.eventDatas.get(e)||[]];if(s.push(...this.eventDatas.get("*")||[]),s&&s.length){let r=0,n=0,i=!1;for(;s[r];){let o=s[r],a=await o.callBack({stopPropagation:()=>i=!0,callTimes:n,eventName:e},t);if(o.once?c(s,o):r++,!1===a||i)return!1}}}},exports.IS_DESTROY=_e,exports.IS_RENDER=Ke,exports.JOKER_COMPONENT_TAG=We,exports.JOKER_VNODE_TAG=j,exports.OBJECTPROXY_DEPID=A,exports.PARSER_TEMPLATE_TARGET=ke,exports.ParserTemplate=Re,exports.SCOPE_ID=Ie,exports.ShallowObserver=_,exports.Template=qe,exports.Watcher=M,exports.__GLONAL_FUNTIONS__=re,exports.__JOKER_HMR_RUNTIME=n,exports.combinedReply=function(e){K=!0;try{e()}catch(e){return K=!1,k.clear(),void x.error("数据劫持","数据劫持组合回复在做变更采集时,遇到了阻塞错误,不做响应,请检查",e)}K=!1,function(e){let t=[],s=[];e.forEach(((e,s)=>{e.forEach((e=>{t.push(...s.watchers.get(e)||[])}))})),t.forEach((e=>{s.includes(e)||(!1===e.isDestroy&&e.update(),s.push(e))}))}(k),k.clear()},exports.defineObserverProperty=T,exports.getGlobalComponent=Be,exports.isObserverData=function(e){return void 0!==V(e)},exports.observer=P,exports.registerGlobalComponent=Ye,exports.registerGlobalFunction=function(e){for(let t in e)re[t]=e[t]};
1
+ "use strict";var e=require("@joker.front/ast");const t=new Map,s=new Map,r=new Map;let n={recordRender:(e,t)=>{s.set(e,t)},recordComponent:(e,t)=>{r.set(e,t)},record:(e,s)=>{void 0===t.get(e)&&t.set(e,new Set),t.get(e).add(s),s.$on("destroy",(()=>{t.get(e)?.delete(s)}))},reload:(e,s)=>{let n=r.get(e);if(!n)return;n.component=s;let i=t.get(e);if(!i)return;let o=Array.from(i);i.clear(),o.forEach((e=>{if(e.$root){if(!e.$rootVNode?.parent)return window.onbeforeunload=null,void location.reload();{let t=e.$rootVNode.parent;if(!(t instanceof exports.VNode.Component&&t[exports.VNode.PARSERKEY]&&t[exports.VNode.PARSERKEY].canReload))return window.onbeforeunload=null,void location.reload();t[exports.VNode.PARSERKEY].reload()}}}))},rerender:(e,r)=>{let n=s.get(e);n&&(n.render=r),t.get(e)?.forEach((e=>{e.$render(r)}))}};function i(e){return null!==e&&"object"==typeof e}function o(e,t){Object.getOwnPropertyNames(e).forEach((s=>{t(s,e[s])}))}function a(e){return"[object Object]"===Object.prototype.toString.call(e)}function h(e){if(null===e)return e;if("object"!=typeof e)return e;let t;t=Array.isArray(e)?[]:{};let s=Object.keys(e);for(let r of s){let s=e[r];t[r]="object"==typeof s?h(s):s}return t}function d(e,t,s){return Array.isArray(e)&&Array.isArray(t)?function(e,t,s){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(s){if(e[r]!==t[r])return!1}else if(!1===l(e[r],t[r],s))return!1;return!0}(e,t,s):l(e,t,s)}function l(e,t,s){if(e===t)return!0;let r=i(e),n=i(t);if(r&&n){if(a(e)&&a(t)){let r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;if(s){for(let s of r)if(e[s]!==t[s])return!1;return!0}return JSON.stringify(e)===JSON.stringify(t)}return e===t}return!r&&!n&&String(e)===String(t)}function c(e,t){let s=e.indexOf(t);return s>-1&&e.splice(s,1),e}function p(e,t){let s=e.findIndex((e=>t(e)));return s>-1&&e.splice(s,1),e}function u(e){return!e||""===e.trim()}function f(e,t="-"){return(e=e||"").split(/(?=[A-Z])/).map((e=>e.toLowerCase())).join(t)}let m=(...e)=>{},E="warn";const y=["silent","error","warn","info"];function N(){let e=new Date;function t(e,t=2){return e.toString().padStart(t,"0")}return t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+":"+t(e.getMilliseconds(),3)}function v(e,t,s,r){y.indexOf(e)<=y.indexOf(E)&&(void 0===r?console[e](`${N()} [${t}]:`,s):console[e](`${N()} [${t}]:`,s,r))}let g={info:function(e,t,s){v("info",e,t,s)},warn:function(e,t,s){v("warn",e,t,s)},error:function(e,t,s){v("error",e,t,s)},setLoggerLeve:function(e){E=e}};const x={lt:"<",gt:">",nbsp:" ",amp:"&",quot:'"',"#39":"'"};function b(e){return e.replace(/&(lt|gt|nbsp|amp|quot|#39);/gi,((e,t)=>x[t]||""))}class R{static target;watchers=new Map;depend(e){R.target?.addDep(this,e)}addWatcher(e,t){let s=this.watchers.get(e)||[];s.push(t),this.watchers.set(e,s)}removeWatcher(e,t){let s=this.watchers.get(e);s&&c(s,t)}notify(e){let t=this.watchers.get(e);if(t){p(t,(e=>e.isDestroy)),[...t].forEach((e=>{!1===e.isDestroy&&e.update()}))}}}const w=Symbol.for("__JOKER_OBJECT_PROXY_DEP_ID__"),A=Symbol.for("__JOKER_OBJECT_PROXY_DATA_KEY__"),C=Symbol.for("__JOKER_OBJECTPROXY_DEPLEVE_ID__");function O(e){return i(e)&&e instanceof Window==!1&&e instanceof I==!1&&e!==window.parent&&(Array.isArray(e)||a(e)||e instanceof Set||e instanceof Map)&&!Object.isFrozen(e)&&!(e instanceof Element)&&!(L in e)&&!(P in e)&&!(De in e)}function S(e){if($(e))return e;if(e&&e.hasOwnProperty(A)){let t=Reflect.get(e,A);if(t)return t}let t=new R,s=!0,r=new Proxy(e,{get(e,s,r){if(e instanceof Set||e instanceof Map){if("add"===s){let r=Reflect.get(e,s);return s=>{O(s)&&(s=V(s));let n=r.call(e,s);return K(t,"size"),K(t,C),n}}if("set"===s){let r=Reflect.get(e,s);return(s,n)=>{O(n)&&(n=V(n));let i=r.call(e,s,n);return K(t,"size"),K(t,C),i}}if("delete"===s||"clear"===s){let r=Reflect.get(e,s);return n=>{let i=r.call(e,n);return("clear"===s||i)&&(K(t,"size"),K(t,C)),i}}let r=Reflect.get(e,s);if("function"==typeof r)return r.bind(e)}if(s===A)return;if(s===w)return t;if(s===C)return;let n=Reflect.get(e,s);return s===Symbol.toStringTag||!1===function(e,t){return t in e}(e,s)&&"length"!==s&&"size"!==s||(t.depend(s),O(n)&&$(n)?.depend(C)),n},set(e,r,n){if(s)return Reflect.set(e,r,n),!0;O(n)&&(n=V(n));let i=!1===function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,r),o=Reflect.get(e,r)!==n;return Reflect.set(e,r,n),(o||"length"===r&&Array.isArray(e))&&K(t,r),Array.isArray(e)?"length"===r&&K(t,C):i&&K(t,C),!0},deleteProperty:(e,s)=>(Reflect.deleteProperty(e,s),!1===Array.isArray(e)&&K(t,C),!0)});var n,i,o,a;n=e,i=A,o=r,a=!1,Object.defineProperty(n,i,{value:o,enumerable:a,writable:!0,configurable:!0});for(let t in e){let s=e[t];O(s)&&!$(s)&&(r[t]=S(e[t]))}return s=!1,r}function $(e){if(i(e))return Reflect.get(e,w)}function V(e,t=!1){if(!1===O(e))throw new Error("当前传入的数据不是正确的数据类型,必须是数组或者对象");return S(t?h(e):e)}function T(e,t,s){let r=s;O(s)&&(r=V(s));let n=new R;Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:()=>(n.depend(t),$(r)?.depend(C),r),set:e=>{e!==r&&(O(e)&&(e=V(e)),r=e,K(n,t))}})}const P=Symbol.for("JOKER_SHALLOW_OBSERVER");let D=!1,_=new Map;function K(e,t){if(!1===D)e.notify(t);else{let s=_.get(e);void 0===s&&(s=[],_.set(e,s)),!1===s.includes(t)&&s.push(t)}}const k="数据观察",W=Symbol.for("JOKER_BREAK_WATCH_UPDATE");class I{ob;updateCallBack;forceCallBack;getter;value;isDestroy=!1;updating=!1;runRelations=new Map;relations=new Map;constructor(e,t,s,r){if(this.ob=e,this.updateCallBack=t,this.forceCallBack=r,void 0===e)throw new Error("无法对underfind进行变更观察");if(void 0===s)this.getter=e=>e;else if("function"==typeof s)this.getter=s;else{let e=function(e){if(/[^\w.$]/.test(e))return;let t=e.split(".");return function(e){let s=e;return t.forEach((e=>{s&&(s=s[e])})),s}}(s);if(void 0===e)throw new Error(s+"解析失败,无法明确读取表达式,请检查expOrFn参数,或采用function模式");this.getter=e}void 0===this.getter&&g.error(k,"getter创建失败",arguments),this.value=this.getValue()}getValue(){if(void 0===this.getter)return;R.target=this;let e,t="function"==typeof this.ob?this.ob():this.ob;try{e=this.getter.call(t,t)}catch(e){throw g.error(k,`获取值失败,执行方法:${this.getter.toString()}`),e}return R.target=void 0,this.clearnDeps(),e}addDep(e,t){let s=this.runRelations.get(e);if(void 0===s||!1===s.includes(t)){s=s||[],s.push(t),this.runRelations.set(e,s);let r=this.relations.get(e);void 0!==r&&!1!==r.includes(t)||e.addWatcher(t,this)}}update(){if(this.updating)return;let e=this.getValue();if(e===W)return;let t=this.value;if(this.forceCallBack||e!==t||i(e)){this.value=e;let s=e!==t&&d(e,t,!0);if(s&&!this.forceCallBack)return;this.updating=!0;try{this.updateCallBack(e,t,s,this)}catch(e){throw e}finally{this.updating=!1}}}destroy(){this.relations.forEach(((e,t)=>{for(let s of e)t.removeWatcher(s,this)})),this.isDestroy=!0,this.relations.clear(),this.runRelations.clear(),this.ob=void 0,this.value=void 0,this.getter=void 0}clearnDeps(){this.relations.forEach(((e,t)=>{let s=this.runRelations.get(t);for(let r of e)s?!1===s.includes(r)&&t.removeWatcher(r,this):t.removeWatcher(r,this)})),this.relations.clear(),this.relations=this.runRelations,this.runRelations=new Map}}exports.IContainer=void 0,function(e){let t=new Map;e.bind=function(e){return{to:s=>{if(t.has(e))throw new Error(`TagId:${e.toString()}已注入实现类,请勿重复注入。`);t.set(e,s)}}},e.get=function(e,...s){let r=t.get(e);if(r)return new r(...s)}}(exports.IContainer||(exports.IContainer={}));const L=Symbol.for("JOKER_VNODE_TAG");exports.VNode=void 0,function(e){e.PARSERKEY=Symbol.for("JOKER_PARSER_KEY");class t{parent;[L]=!0;static;output;[e.PARSERKEY];childrens;sleep=!1;constructor(e){this.parent=e}get prev(){if(this.parent)return this.parent.childrens?.[this.parent.childrens?.indexOf(this)-1]}get next(){if(this.parent)return this.parent.childrens?.[this.parent.childrens?.indexOf(this)+1]}closest(t,s){if(!0===t(this))return this;let r=this.parent;for(;r;){if(s&&r instanceof e.Root)return;if(!0===t(r))return r;r=r.parent}}find(e,t,s){let r=s??[];if(t??=this.childrens,t)for(let s of t){!0===e(s)&&r.push(s),s.childrens&&this.find(e,s.childrens,r)}return r}contains(e,t){if(t??=this.childrens,t)for(let s of t){if(!0===e(s))return!0;if(s.childrens&&s.childrens.length&&this.contains(e,s.childrens))return!0}return!1}first(e,t){if(t??=this.childrens,t)for(let s of t){if(!0===e(s))return s;if(s.childrens&&s.childrens.length){let t=this.first(e,s.childrens);if(t)return t}}}}e.Node=t;e.Root=class extends t{childrens=[];component;constructor(){super()}};e.Text=class extends t{text;static=!0;constructor(e,t){super(t),this.text=e}};e.Html=class extends t{html;notShadow;static=!0;constructor(e,t,s){super(t),this.html=e,this.notShadow=s}};e.Comment=class extends t{text;static=!0;constructor(e,t){super(t),this.text=e}};e.Element=class extends t{tagName;static=!0;attributes={};childrens=[];events=[];_assistEventCache;constructor(e,t){super(t),this.tagName=e}};e.Component=class extends t{name;component;events=[];propValues={};keepalive;get firstElement(){if(this.childrens){let t=s=>{for(let r of s){if(r instanceof e.Element)return r;if(r.childrens){let e=t(r.childrens);if(e)return e}}};return t(this.childrens)}}get rootElements(){if(this.childrens){let t=[],s=r=>{for(let n of r)n instanceof e.Element||n instanceof e.Html?t.push(n):n.childrens&&s(n.childrens)};return s(this.childrens),t}return[]}};e.Condition=class extends t{cmdName;result=!1;childrens=[];isShow=!1;constructor(e,t){super(t),this.cmdName=e}};e.List=class extends t{childrens=[]};e.ListItem=class extends t{ob;childrens=[];constructor(e,t){super(t),this.ob=e}};e.RenderSection=class extends t{id="unknown";params=[];section;childrens=[];ob;constructor(e,t){super(t),"string"==typeof e?this.id=e:this.section=e}}}(exports.VNode||(exports.VNode={}));const M="DOM渲染",j=["script","style","textarea","pre"];let H=0;const Y=["svg","defs","use","rect","circle","ellipse","line","polyline","polygon","path","text","g"];function B(e,t,s){return`${e}-${t}-${s}`}function J(e,t,s,r){e._assistEventCache??=[],e._assistEventCache.push([t,s]),document.body.addEventListener(t,s,r)}function G(e,t,s){e._assistEventCache&&t&&s?(p(e._assistEventCache,(e=>e[0]===t&&e[1]===s)),document.body.removeEventListener(t,s)):(e._assistEventCache?.forEach((e=>{document.body.removeEventListener(e[0],e[1])})),e._assistEventCache&&(e._assistEventCache.length=0),e._assistEventCache=void 0)}exports.Render=void 0,function(e){e.IRENDERIOCTAGID=Symbol.for("JOKER_IRENDERIOC_TAGID"),e.ROOT_CONTAINER="";e.DomRender=class{elements;constructor(){this.elements=document.createDocumentFragment()}mount(e,t){if(e instanceof Element)e.appendChild(this.elements),t?.();else if(e instanceof exports.VNode.Component)if(e.parent)if(e.output){let s=e.output,r=U(e)||s.parentNode;r&&(r.insertBefore(this.elements,s),document.contains(r)&&t?.())}else g.error(M,"组件挂载渲染时发现该节点未定义DOM定位节点",e);else g.error(M,"mount子组件时,发现该组件无父级",e);else g.error(M,"mount只支持挂载到Element或VNode.Node类型数据中",e)}appendNode(e,t){if(this.renderNode(e),e.output){let s=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];for(let r of s)this.appendNodeChildren(e,r,e.parent,t)}else g.error(M,"未找自身节点的el属性,无法进行dom挂载",e)}updateNode(e,t){if(e instanceof exports.VNode.Element)for(let t in e.attributes){let s=e.attributes[t];this.setAttribute(e.output,t,s)}else e instanceof exports.VNode.Text?e.parent&&e.parent instanceof exports.VNode.Element&&j.includes(e.parent.tagName)?(this.removeNode(e),this.appendNode(e)):e.output.textContent=b(e.text||""):e instanceof exports.VNode.Html?e.notShadow?e.output.innerHTML=e.html:e.output.root.innerHTML=e.html:g.error(M,`该节点不支持${t}的更新`,e)}removeNode(e,t){let s=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];s?.forEach((e=>{e?.remove()})),t||(e instanceof exports.VNode.Element&&G(e),e.output=void 0)}destroy(){this.elements=void 0}elementToEnter(e,t,s,r){e.output&&this.transitionFrame(e,t,"enter",s,r)}elementToLeave(e,t,s,r){e.output&&this.transitionFrame(e,t,"leave",s,r)}triggerEvent(e,t,s){let r=[];for(let n of e.events){let[i,o]=n;if(i===t){let t=o.modifiers?.includes("self"),a=o.modifiers?.includes("outside");if(t||a){g.warn(M,"事件修饰符:self、outside在组件事件中无法使用,组件无法确认元素",e);continue}let h=s.event;if((h instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(i)||h instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(i))&&!1===X(h,o.modifiers))continue;if(o.callBack(s),o.modifiers?.includes("prevent")&&s.preventDefault(),o.modifiers?.includes("once")&&r.push(n),o.modifiers?.includes("stop"))return s.stopPropagation(),!1}}r.length&&r.forEach((t=>{c(e.events,t)}))}transitionFrame(e,t,s,r,n){q(e,B(t,s,"from")),r||="transition";let i=e.output.__TRANSITION_EVNETID__=H++;requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(!e.output)return;q(e,B(t,s,"active")),z(e,B(t,s,"from")),q(e,B(t,s,"to"));let o=function(e,t){let s=window.getComputedStyle(e),r=e=>(s[e]||"").split(", ");if("transition"===t){let e=r("transitionDelay"),t=r("transitionDuration"),s=Z(e,t);if(s>0)return{timeout:s,count:t.length}}else if("animation"===t){let e=r("animationDelay"),t=r("animationDuration"),s=Z(e,t);if(s>0)return{timeout:s,count:t.length}}}(e.output,r);if(!o)return void n?.();let a=0,h=()=>{z(e,B(t,s,"to")),z(e,B(t,s,"active")),e.output&&(e.output.removeEventListener(`${r}end`,d),i===e.output.__TRANSITION_EVNETID__&&n?.())},d=t=>{t.target===e.output&&++a>=o.count&&h()};setTimeout((()=>{a<o.count&&h()}),o.timeout+1),e.output?.addEventListener(`${r}end`,d)}))}))}renderNode(e){if(!e.output)if(e instanceof exports.VNode.Text)e.parent&&e.parent instanceof exports.VNode.Element&&j.includes(e.parent.tagName)?e.output=this.parserHtml(e.text):e.output=document.createTextNode(b(e.text||""));else if(e instanceof exports.VNode.Html)if(e.notShadow){let t=document.createElement("joker-html-container");t.JOKER_NODE=e,t.innerHTML=e.html,e.output=t}else{let t=document.createElement("joker-html-shadow");t.JOKER_NODE=e,t.style.lineHeight="1",t.root.innerHTML=e.html,e.output=t}else if(e instanceof exports.VNode.Element){let t,s=e.tagName.toLowerCase();"svg"===s||Y.includes(s)||e.parent?.inSvg?(e.inSvg=!0,t=document.createElementNS("http://www.w3.org/2000/svg",e.tagName)):t=document.createElement(e.tagName);for(let s in e.attributes)this.setAttribute(t,s,e.attributes[s]);t.JOKER_NODE=e,e.output=t,e.events.some((e=>"click"===e[0]&&e[1].modifiers?.includes("outside")))?setTimeout((()=>{this.initElementEvents(t,e)})):this.initElementEvents(t,e)}else e instanceof exports.VNode.Comment?e.output=document.createComment(e.text):e.output=document.createTextNode("")}initElementEvents(e,t){for(let[s,r]of t.events){let n=r.modifiers?.includes("self"),i=r.modifiers?.includes("outside");n&&i&&(g.warn(M,"事件修饰符:self、outside不可以同时存在,将按照self处理",t),i=!1);let o,a=function(o){if(!(t.sleep||n&&o.target!==e)){if(i){if(o.target===e||e.contains(o.target))return;if(!1===document.contains(o.target))return;if(t.contains((e=>(e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output]).includes(o.target))))return!0}(o instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(s)||o instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(s))&&!1===X(o,r.modifiers)||(r.callBack({eventName:s,event:o,target:t,preventDefault:()=>o.preventDefault(),stopPropagation:()=>o.stopPropagation(),data:void 0}),r.modifiers?.includes("prevent")&&o.preventDefault(),r.modifiers?.includes("stop")&&o.stopPropagation(),r.modifiers?.includes("once")&&(i?G(t,s,a):e.removeEventListener(s,a)))}};r.modifiers?.includes("passive")&&(o={passive:!0}),i?J(t,s,a,o):e.addEventListener(s,a,o)}}parserHtml(e){var t=document.createElement("div");return t.innerHTML=e,t.childNodes}isCommandGroup(e){return e instanceof exports.VNode.Component||e instanceof exports.VNode.Condition||e instanceof exports.VNode.List||e instanceof exports.VNode.ListItem||e instanceof exports.VNode.RenderSection}appendNodeChildren(e,t,s,r){let n=U(e);if(n)n.appendChild(t);else if(void 0===s)this.elements?.appendChild(t);else if(s)if(s instanceof exports.VNode.Root){let e=s.parent;if(e&&e instanceof exports.VNode.Component&&e.output){let s=e.output,r=s?.parentNode;if(r)return void r.insertBefore(t,s)}this.elements?.appendChild(t)}else if(s instanceof exports.VNode.Element){let e=s.output;if(void 0===e)return;e.appendChild(t)}else if(this.isCommandGroup(s)){let e=s.output,n=e?.parentNode;if(void 0!==r&&s.childrens?.length&&n){let e=r-1;if(e<0)return void n.insertBefore(t,n.firstChild);{let r=s.childrens[e];if(r){let e=r.output;if(e)return void e.after(t)}}}n&&n.insertBefore(t,e)}else g.error(M,"该节点不支持嵌套子集,请检查。",{node:e,parent:s})}setAttribute(e,t,s){if(e)if("boolean"!=typeof s){if("class"===t){if(Array.isArray(s)){let e=[];for(let t of s)if(i(t))for(let s in t)t[s]&&e.push(s);else t&&e.push(t);s=e.join(" ")}else if(i(s)){for(let t in s)s[t]?e.classList.add(t):e.classList.remove(t);return}}else if("style"===t&&i(s)){e.removeAttribute("style");for(let t in s){let r=!1;void 0!==s[t]&&!1!==s[t]||(r=!0);let n=String(s[t]);u(n)&&(r=!0),r||(e.style[t]=n)}return}s=(s??"").toString().trim(),"class"===t&&(s=s.split(/\s/).filter((e=>e.trim())).join(" ")),"value"===t&&"value"in e?e.value=s:"xlink:href"===t?e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",s):e.setAttribute(t,s)}else s?e.setAttribute(t,""):e.removeAttribute(t)}}}(exports.Render||(exports.Render={}));const F={enter:"enter",backspace:"delete",tab:"tab",arrowup:"up",arrowdown:"down",arrowleft:"left",arrowright:"right",escape:"esc"," ":"space"};function X(e,t){if(e instanceof KeyboardEvent){if(void 0===e.key)return!1;for(let s in F)if(t?.includes(F[s])&&e.key.toLowerCase()!==s)return!1}else{if(t?.includes("left")&&0!==e.button)return!1;if(t?.includes("right")&&2!==e.button)return!1;if(t?.includes("middle")&&1!==e.button)return!1}return(!t?.includes("ctrl")||!1!==e.ctrlKey)&&((!t?.includes("alt")||!1!==e.altKey)&&(!t?.includes("shift")||!1!==e.shiftKey))}function q(e,t){e.output&&e.output.classList.add(t)}function z(e,t){e.output&&e.output.classList.remove(t)}function U(e){if(e instanceof exports.VNode.Element||e instanceof exports.VNode.Component){let t=e instanceof exports.VNode.Component?e.propValues["append-to"]:e.attributes["append-to"];if(t){if(t instanceof exports.VNode.Element)return t.output;if("string"==typeof t){exports.Render.ROOT_CONTAINER&&(t="body"===t?exports.Render.ROOT_CONTAINER:`${exports.Render.ROOT_CONTAINER} ${t}`);let e=document.querySelector(t);if(e)return e}g.warn(M,"appendTo类型不支持",{appendTo:t,node:e})}}}function Z(e,t){for(;e.length<t.length;)e.concat(e);return Math.max(...t.map(((t,s)=>Q(t)+Q(e[s]))))}function Q(e){return"auto"===e?0:1e3*Number(e.slice(0,-1).replace(",","."))}class ee extends HTMLElement{root;constructor(){super(),this.root=this.attachShadow({mode:"open"})}}!customElements.get("joker-html-shadow")&&customElements.define("joker-html-shadow",ee);const te={};const se="Global",re="渲染核心";function ne(t){try{return new Function(e.EXPRESSHANDLERTAG,se,`return ${t};`)}catch{throw new Error("创建表达式运行方法时出现未知错误,表达式为"+t)}}class ie{ast;ob;parent;ext;ref="";watchers=[];node;isDestroy=!1;constructor(e,t,s,r){this.ast=e,this.ob=t,this.parent=s,this.ext=r}init(e){this.parser(e),this.afterParser()}beforeDestroy(e){}destroy(e){if(this.isDestroy=!0,this.clearWatchers(),this.parent.childrens&&this.node){(this.node instanceof exports.VNode.Element||this.node instanceof exports.VNode.Component)&&this.ext.removeRef(this.node);let t=()=>{this.parent&&this.node&&(this.beforeDestroy(e),this.destroyChildrens(e),this.ext.render?.removeNode(this.node),this.parent.childrens&&c(this.parent.childrens,this.node),this.notifyNodeWatcher("remove"),this.destroyOtherData())};if(this.ext.nodeTransition(this.node,"leave",void 0,(()=>{t()})))return c(this.parent.childrens,this.node),void this.destroyChildrensWatcher(this.node);t()}else this.destroyOtherData()}destroyWathcers(){this.isDestroy=!0,this.clearWatchers(),this.destroyChildrensWatcher(this.node)}destroyOtherData(){this.node&&(this.node[exports.VNode.PARSERKEY]=void 0),this.node=void 0,this.parent=void 0}destroyChildrens(e){for(;this.node?.childrens?.length;){let t=this.node.childrens[0];t[exports.VNode.PARSERKEY]?t[exports.VNode.PARSERKEY].destroy(e):c(this.node.childrens,t)}}destroyChildrensWatcher(e){if(e?.childrens?.length)for(let t of e?.childrens)t[exports.VNode.PARSERKEY]&&(t[exports.VNode.PARSERKEY].clearWatchers(),this.destroyChildrensWatcher(t))}appendNode(e){this.parent?.childrens&&this.node&&!this.isDestroy&&(this.node[exports.VNode.PARSERKEY]=this,this.node instanceof exports.VNode.Element&&this.ob[Pe]&&(this.node.attributes["data-scoped-"+this.ob[Pe]]=void 0),this.ext.render?.appendNode(this.node,e),void 0===e?this.parent.childrens.push(this.node):this.parent.childrens.splice(e,0,this.node),this.notifyNodeWatcher("append"))}afterParser(){this.ext.nodeTransition(this.node,"enter")}notifyNodeWatcher(e,t){this.ext.notifyNodeWatcher(this.ref,this.node,e,t)}runExpress(e,t){try{return ne(e).call(t,t,te)}catch(s){g.error(re,"运行表达式出现错误:"+e,{ob:t}),console.error(s)}}runExpressWithWatcher(e,t,s,r){if(this.isDestroy)return;let n="string"==typeof e?ne(e):e,i=new I((()=>{if(this.isDestroy||t[Ve])return W;try{return n.call(t,t,te)}catch(s){return g.error(re,"运行表达式出现错误",{ob:t,express:e,node:this.node}),console.error(s),W}}),s,void 0,r);return this.addWatch(i),i.value===W?void 0:i.value}addWatch(e){!1===this.watchers.includes(e)&&this.watchers.push(e)}clearWatchers(){this.watchers.forEach((e=>{e.destroy()})),this.watchers.length=0}}class oe extends ie{parser(){this.node=new exports.VNode.Text(this.ast.text,this.parent),this.appendNode()}}class ae extends ie{parser(){this.node=new exports.VNode.Comment(this.ast.text,this.parent),this.appendNode()}}class he extends ie{parser(){if(this.node=new exports.VNode.Condition(this.ast.kind,this.parent),"else"!==this.ast.kind){u(this.ast.condition)&&g.error("条件命令",`当前条件命令${this.ast.kind}没有判断条件,请检查`);let e=this.runExpressWithWatcher(this.ast.condition,this.ob,(e=>{let t=!!e;if(this.node?.result!==t){if(this.node.result=t,!1===t&&this.node?.isShow)this.destroyChildrens(!0);else if(t&&!this.node?.isShow){let e=this.getElseNode();if(e&&e.isShow&&e.childrens?.length){let t=e[exports.VNode.PARSERKEY];t&&t instanceof he&&t.renderConditionChildren()}}this.reloadAllCondition()}}));this.node.result=!!e}this.appendNode(),this.renderConditionChildren()}renderId;getElseNode(){let e=this.node?.next;for(;e&&e instanceof exports.VNode.Condition&&"if"!==e.cmdName;){if("else"===e.cmdName)return e;e=e.next}}renderConditionChildren(){let e=!1;return this.getPrevIfResult()?e=!1:"else"===this.ast.kind?e=!0:(this.node.result=!!this.runExpress(this.ast.condition,this.ob),this.node.result&&(e=!0)),e!==this.node.isShow&&(this.node.isShow=e,this.destroyChildrens(!0),e&&this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob),!0)}getPrevIfResult(){if("if"===this.ast.kind)return!1;let e=this.node?.prev;for(;e&&e instanceof exports.VNode.Condition;){if(e.result)return!0;if("if"===e.cmdName)break;e=e.prev}return!1}reloadAllCondition(){if(this.renderConditionChildren()){let e=this.node?.next;for(;e&&e instanceof exports.VNode.Condition&&"if"!==e.cmdName;){let t=e[exports.VNode.PARSERKEY];t&&t instanceof he&&t.renderConditionChildren(),e=e.next}}let e=this.node?.next;for(this.node?.result||this.destroyChildrens(!0);e&&e instanceof exports.VNode.Condition&&"if"!==e.cmdName;){let t=e[exports.VNode.PARSERKEY];t&&t instanceof he&&t.renderConditionChildren(),e=e.next}}}class de extends ie{parser(){this.node=new exports.VNode.List(this.parent),this.appendNode(),this.renderChildrens()}renderChildrens(){switch(this.ast.keyType){case"condition":this.renderConditionChildrens();break;case"in":case"of":this.renderInOrOfChildrens()}}renderConditionChildrens(){let t=this.ast.param,s=Object.create(this.ob),r=!!this.runExpressWithWatcher(function(t,s,r){try{return new Function(e.EXPRESSHANDLERTAG,`${e.EXPRESSHANDLERTAG}.${t}=${s}; return ${r};`)}catch{throw new Error(`For循环命令,表达式运行依赖采集出现未知错误,其中letKey:${t},keyVal:${s},condition:${r}`)}}(t.letKey,t.defaultKeyVal,t.condition),s,(()=>{this.clearWatchers(),this.renderChildrens()}),!0),n=0;for(;r;){let e=Object.create(this.ob);T(e,t.letKey,s[t.letKey]);let i=n++;this.renderItem(e,i),this.runExpressWithWatcher((()=>s[t.letKey]),s,(async(s,r,n,o)=>{await Promise.resolve(),o.isDestroy||(e[t.letKey]=s,n||this.updateListItemOb(e,i))}),!0),this.runExpress(t.step,s),r=!!this.runExpress(t.condition,s)}this.destroyOldChildrens(n)}renderInOrOfChildrens(){let e=this.ast.param,t=this.runExpressWithWatcher(e.dataKey,this.ob,(()=>{this.clearWatchers(),this.renderChildrens()})),s=0;if(t&&(Array.isArray(t)||a(t)))for(let r in t){let n=Object.create(this.ob),i=Array.isArray(t)?Number(r):r;e.indexKey&&T(n,e.indexKey,i),e.itemKey&&T(n,e.itemKey,t[r]);let o=s++;this.renderItem(n,o,e.indexKey),e.itemKey&&this.runExpressWithWatcher((()=>t[i]),t,(async(s,r,a,h)=>{await Promise.resolve(),h.isDestroy||i in t&&(n[e.itemKey]=s,a||this.updateListItemOb(n,o))}),!0)}this.destroyOldChildrens(s)}findIndexByIndex(e,t,s){let r=-1;if(this.node)for(let n=t;n<this.node.childrens.length;n++)if(this.checkObEqual(e,this.node.childrens[n]?.ob,s?[s]:void 0)){r=n;break}return r}renderItem(e,t,s){if(!this.ast.childrens?.length||!this.node)return;let r=this.node.childrens?.[t];if(r){if(this.checkObEqual(e,r.ob,s?[s]:void 0))return void(s&&r.ob[s]!==e[s]&&(r.ob[s]=e[s]));let n=this.findIndexByIndex(e,t+1,s);if(n>-1){if(t+1===n)this.node.childrens?.[t]?.[exports.VNode.PARSERKEY]?.destroy();else for(let e=0;e<n-t-1;e++)this.node.childrens?.[t]?.[exports.VNode.PARSERKEY]?.destroy();return this.renderItem(e,t,s)}return new le(this.ast,e,this.node,this.ext).init(t)}return new le(this.ast,e,this.node,this.ext).init()}updateListItemOb(e,t){if(!this.ast.childrens?.length||!this.node)return;let s=this.node.childrens?.[t];o(e,((e,t)=>{s.ob[e]!==t&&(s.ob[e]=t)}))}destroyOldChildrens(e){if(this.node)for(;this.node.childrens.length>e;){let e=this.node.childrens.pop();if(!e)break;e[exports.VNode.PARSERKEY]?.destroy(!1)}}checkObEqual(e,t,s){let r=!0;return void 0!==t&&(o(e,((e,n)=>{s?.includes(e)||t?.[e]===n||(r=!1)})),r)}}class le extends ie{parser(e){this.node=new exports.VNode.ListItem(this.ob,this.parent),this.appendNode(e),this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}}class ce extends ie{parser(){if(u(this.ast.cmdName))throw g.error("模板指令","解析AST转换VNode时发生错误,未找到指令名称",this.ast),new Error("解析AST转换VNode时发生错误,未找到指令名称");let t;if("Html"===this.ast.cmdName||"Text"===this.ast.cmdName?t=this.ast.param:this.ast.cmdName.startsWith(se+".")?t=`${this.ast.cmdName}(${this.ast.param})`:this.ast.cmdName in this.ob&&"function"==typeof this.ob[this.ast.cmdName]&&(t=`${e.createFuntionBody(this.ast.cmdName)}(${this.ast.param})`),t){let e=this.runExpressWithWatcher(`[${t}]`,this.ob,(e=>{this.changeValue(e?.[0])}));return e||=[],"Html"===this.ast.cmdName?this.node=new exports.VNode.Html(pe(e[0]),this.parent,e[1]):this.node=new exports.VNode.Text(pe(e[0]),this.parent),void this.appendNode()}throw new Error(`未找到命令:${this.ast.cmdName}`)}changeValue(e){this.node&&(this.node instanceof exports.VNode.Html?this.node.html=pe(e):this.node.text=pe(e),this.ext.render?.updateNode(this.node))}}function pe(e){return null==e||"function"==typeof e?"":e.toString()}const ue="default";class fe extends ie{parser(){let e=this.transformParam();this.node=new exports.VNode.RenderSection(e.id,this.parent),this.node.params=e.params,this.node.section??=this.ob.$sections?.[e.id],this.appendNode(),this.node.section&&(this.node.section.params?(this.node.ob=Object.create(this.node.section.ob||this.ob),this.node.section.params?.forEach(((e,t)=>{T(this.node.ob,e,this.node.params[t])}))):this.node.ob=this.node.section.ob||this.ob,(this.node.section.parser||this.ext).parserNodes(this.node.section.asts,this.node,this.node.ob))}transformParam(){if(this.ast.param){let e=this.runExpressWithWatcher(`[${this.ast.param}]`,this.ob,(e=>{let t=e?.[0]||ue;if("string"==typeof t&&t!==this.node.id)throw new Error("section id 不可动态变更");this.node.params=e.slice(1),this.node?.ob&&this.node.section&&this.node.section.params?.forEach(((e,t)=>{this.node?.ob&&this.node.ob[e]!==this.node.params[t]&&(this.node.ob[e]=this.node.params[t])}))}),!0);return{id:e?.[0]||ue,params:e?.slice(1)||[]}}return{id:ue,params:[]}}}const me="组件解析";function Ee(e,t){return!!t.components[e]||!!Le(e)}class ye extends ie{parser(){if(this.ast.node)return this.node=this.ast.node,this.node.parent=this.parent,this.initPropData(),void(this.node&&(this.appendNode(),this.node.component?.$mount(this.node)));this.node=new exports.VNode.Component(this.parent),this.initPropData(),this.appendNode(),this.initEvent(),this.renderChildren()}get canReload(){return"tagName"in this.ast||"function"==typeof this.ast.component}reload(){this.canReload?(this.beforeDestroy(),this.renderChildren()):g.warn(me,"当前组件无法实现reload",this.node)}initPropData(){for(let e of this.ast.attributes)if("ref"!==e.name)if("keep-alive"===e.name&&"false"!==e.value&&(this.node.keepalive=!0),e.express){let t=this.runExpressWithWatcher(e.express,this.ob,(t=>{this.node.propValues[e.name]=t,this.notifyNodeWatcher("update",e.name)}),!0);this.node.propValues[e.name]=t}else this.node.propValues[e.name]=e.value;else{if(u(e.value)){g.warn(me,"元素的ref值不可以为空");continue}this.ref=e.value,this.ext.addRef(e.value,this.node)}this.node.propValues=V(this.node.propValues)}initEvent(){this.ast.events.forEach((e=>{let t=e.functionName?this.ob[e.functionName]:void 0;void 0===e.functionName?this.node.events.push([e.name,{modifiers:e.modifiers,callBack:m}]):t&&"function"==typeof t?this.node.events.push([e.name,{modifiers:e.modifiers,callBack:s=>{let r=[];e.functionParam&&(r=this.runExpress(`[${e.functionParam}]`,this.ob)),t.call(this.ext.ob,s,...r)}}]):g.error(me,`${"tagName"in this.ast?this.ast.tagName:""}元素中${e.name}事件所指定的回调(${e.functionName})方法未找到,请检查`)}))}async renderChildren(){if("tagName"in this.ast){let e=this.ob.components[this.ast.tagName]||Le(this.ast.tagName);if(void 0===e)return void g.error(me,`渲染组件失败,未找到名称为'${this.ast.tagName}'的私有组件/全局组件`);if(De in e||(e=(await e()).default),!this.node)return;{let t=this.getSections();this.node.name=this.ast.tagName,this.node.component=new e(this.node?.propValues,t,this.node?.keepalive)}}else if("function"==typeof this.ast.component){let e=this.getSections();this.node.component=new this.ast.component(this.node?.propValues,e,this.node?.keepalive)}else this.node.component=this.ast.component;if(!this.node)return;if(!this.node.name&&"name"in this.node.component&&this.node.component.name&&"string"==typeof this.node.component.name&&(this.node.name=this.node.component.name),this.node.component.$mount(this.node),!this.node)return;let e=this.node?.component;e.isKeepAlive&&(this.ast.node=this.node)}getSections(){let t={},s=[];return this.ast.childrens.forEach((t=>{if(t.type===e.AST.NodeType.COMMAND&&"if"===t.cmdName&&t.childrens){let r=t,n=t.childrens.some((t=>t.type===e.AST.NodeType.COMMAND&&"section"===t.cmdName)),i=r.condition.startsWith(e.EXPRESSHANDLERTAG+".$sections");if(i){return this.runExpress(r.condition,this.ob)?void s.push(...t.childrens):void 0}if(n&&"if"===r.kind&&!i)return void g.warn(me,"在解析section时,发现该section包裹在一个条件语句中,该条件语句仅支持以$sections进行if判断,已作排出")}s.push(t)})),s.forEach((s=>{if(s.type===e.AST.NodeType.COMMAND&&"section"===s.cmdName){let e=s,r=e.id||ue;/^(\'|\")(.*?)((\'|\"))$/.test(r)&&(r=r.slice(1,-1)),t[r]=t[r]||{asts:[],ob:this.ob,params:e.paramKeys,parser:this.ext},t[r].asts.push(...s.childrens||[])}else t[ue]=t[ue]||{asts:[],ob:this.ob,parser:this.ext},t[ue].asts.push(s)})),t}beforeDestroy(e){!0===e&&this.node?.component?.isKeepAlive?this.node?.component?.$destroy():(this.node?.component?.$destroy(!0),this.ast.node=void 0)}}class Ne extends ie{parser(){this.node=new exports.VNode.Element(this.ast.tagName,this.parent),this.initAttributes(),this.initEvents(),this.appendNode(),this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}initAttributes(){for(let e of this.ast.attributes)if("ref"!==e.name)if(e.express){let t=t=>{this.node&&(this.node.attributes[e.name]=this.transformAttrVal(t),this.ext.render?.updateNode(this.node,e.name),this.notifyNodeWatcher("update",e.name))},s=this.runExpressWithWatcher(e.express,this.ob,(e=>{t(e)}));this.node.attributes[e.name]=this.transformAttrVal(s)}else this.node.attributes[e.name]=e.value;else{if(u(e.value)){g.warn("Element解析","元素的ref值不可以为空");continue}this.ref=e.value,this.ext.addRef(e.value,this.node)}}initEvents(){for(let e of this.ast.events){let t=e.functionName?this.ob[e.functionName]:void 0;if(!(void 0===e.functionName||t&&"function"==typeof t))throw new Error(`${this.ast.tagName}元素中${e.name}事件所指定的回调(${e.functionName})方法未找到,请检查`);this.node?.events.push([e.name,{modifiers:e.modifiers,callBack:s=>{if(void 0===t)return;let r=[];e.functionParam&&(r=this.runExpress(`[${e.functionParam}]`,this.ob)),t&&t.call(this.ext.ob,s,...r)}}])}}transformAttrVal(e){return void 0!==e&&("string"==typeof e||"boolean"==typeof e||"function"!=typeof e&&Object.prototype.toString()?e:void 0)}}class ve{asts;ob;root=new exports.VNode.Root;refs={};sleeped=!1;nodeWatcherEvents={};render;constructor(e,t,s){this.asts=e,this.ob=t,this.root.component=t,this.render=exports.IContainer.get(exports.Render.IRENDERIOCTAGID)??new exports.Render.DomRender,s&&s instanceof exports.VNode.Node&&(this.root.parent=s,s.childrens??=[],s.childrens.push(this.root))}parser(){this.parserNodes(this.asts,this.root)}mount(e){this.sleeped&&this.weakup(),this.render?.mount(e)}parserNodes(t,s,r){if(0!==this.asts.length)for(let n of t)if(n.type===e.AST.NodeType.TEXT)new oe(n,r??this.ob,s,this).init();else if(n.type===e.AST.NodeType.COMMENT)new ae(n,r??this.ob,s,this).init();else if(n.type===e.AST.NodeType.COMPONENT)new ye(n,r??this.ob,s,this).init();else if(n.type===e.AST.NodeType.ELEMENT){let e=n;Ee(e.tagName,r??this.ob)?new ye(e,r??this.ob,s,this).init():new Ne(e,r??this.ob,s,this).init()}else if(n.type===e.AST.NodeType.COMMAND){let e=n;switch(e.cmdName){case"if":case"elseif":case"else":new he(e,r??this.ob,s,this).init();break;case"for":new de(e,r??this.ob,s,this).init();break;case"RenderSection":new fe(e,r??this.ob,s,this).init();break;case"section":break;default:new ce(e,r??this.ob,s,this).init()}}}addRef(e,t){this.refs[e]=this.refs[e]||[],this.refs[e].push(t)}removeRef(e){for(let t in this.refs)this.refs[t].includes(e)&&c(this.refs[t],e)}addNodeWatcher(e,t){this.nodeWatcherEvents[e]=this.nodeWatcherEvents[e]||[],this.nodeWatcherEvents[e].push(t)}removeNodeWatcher(e,t){c(this.nodeWatcherEvents[e]||[],t)}notifyNodeWatcher(e,t,s,r){this.nodeWatcherEvents[e]?.forEach((e=>{e(t,s,r)}))}sleep(e){let t=e||this.root;t.childrens?.forEach((e=>{let t=()=>{e.childrens&&this.sleep(e),e.sleep=!0,this.render?.removeNode(e,!0)};this.nodeTransition(e,"leave",void 0,(()=>{t()}))||t()})),void 0===e&&(this.sleeped=!0)}weakup(e){let t=e||this.root;t.childrens?.forEach((e=>{e.sleep=!1,this.render?.appendNode(e),e.childrens&&this.weakup(e),this.nodeTransition(e,"enter")})),void 0===e&&(this.sleeped=!1)}destroy(e){for(;this.root.childrens.length;){let t=this.root.childrens[0];t[exports.VNode.PARSERKEY]?t[exports.VNode.PARSERKEY].destroy(e):c(this.root.childrens,t)}this.render.destroy(),this.refs={},this.root.childrens.length=0,this.nodeWatcherEvents={},this.asts.length=0}destroyWathcers(){for(let e of this.root.childrens)e[exports.VNode.PARSERKEY]&&e[exports.VNode.PARSERKEY].destroyWathcers()}reSetAsts(e,t){this.destroy(t),this.render=exports.IContainer.get(exports.Render.IRENDERIOCTAGID)??new exports.Render.DomRender,this.asts=e}nodeTransition(e,t,s,r,n){if(e&&e.parent?.childrens&&(e instanceof exports.VNode.Element||e instanceof exports.VNode.Component)){let i=function(e){if(e instanceof exports.VNode.Element||e instanceof exports.VNode.Component){let t=e instanceof exports.VNode.Element?e.attributes:e.propValues;return{name:t["transition-name"],type:t["transition-type"]}}}(e);if(s??=i?.name,n??=i?.type,!s)return!1;let o=ge(e);if(o)return"enter"===t?this.render.elementToEnter(o,s,n,(()=>{let t=e[exports.VNode.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-enter"),r?.()})):this.render.elementToLeave(o,s,n,(()=>{let t=e[exports.VNode.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-leave"),r?.()})),!0;g.warn("渲染核心","在执行node动画时,发现数据不完备,请检查")}return!1}}function ge(e){if(e instanceof exports.VNode.Element)return e;if(e.childrens&&e.childrens.length)for(let t of e.childrens)return t instanceof exports.VNode.Element?t:ge(t)}function xe(e,t,s){if(void 0===t)return;let r=Array.isArray(s)?s:[s];for(let e of r){if(e===Array&&t instanceof Array)return t;if(typeof t===e.name.toLocaleLowerCase())return t}switch(r[0]){case Number:let e=Number(t);if(!1===isNaN(e))return e;break;case String:return String(t)}throw new Error(`props中${e.toString()}的类型不符合约束类型`)}function be(e,t,s){let r,n,i;if("symbol"!=typeof t&&(r=f(t)),t in e?n=e[t]:r&&(n=e[r]),s&&(t in s?i=s[t]:r&&r in s&&(i=s[r])),void 0!==i){if(a(i)&&("type"in i||"required"in i||"default"in i||"validate"in i)){let e=i;if(e.required&&void 0===n)throw new Error(`props中key:${t.toString()}是必须项,请检查`);if(e.type&&(n=xe(t,n,e.type)),e.validate&&!1===e.validate(n))throw new Error(`props中key${t.toString()}的值校验错误`);n=n??e.default}else n=Re(i)?xe(t,n,i):n??i;return n}return n}function Re(e){return!![String,Array,Number,Object,Function,Boolean].includes(e)||e instanceof Array&&Re(e[0])}function we(e,t){if(!e.constructor)return!1;let s=Object.getOwnPropertyDescriptor(e.constructor.prototype,t);return s&&s.get}const Ae="组件",Ce=Symbol.for("JOKER_PROPS_DATA_KEY"),Oe=Symbol.for("JOKER_PROPS_DATA_PROXY"),Se=Symbol.for("JOKER_PRIVATE_WATCHERS"),$e=Symbol.for("JOKER_EVENT_DATA_KEY"),Ve=Symbol.for("JOKER_IS_DESTROY"),Te=Symbol.for("JOKER_PARSER_TEMPLATE_TARGET"),Pe=Symbol.for("JOKER_SCOPE_ID"),De=Symbol.for("JOKER_COMPONENT_TAG"),_e=Symbol();let Ke=["constructor","$mount","$nodeTransition","$destroy","$getRef","$getRefs","$syncProp","$watchNode","$watch","$on","$off","$trigger","$render","created","mounted","beforeDestroy","sleeped","wakeup","destroyed"];class ke{$sections;isKeepAlive;static[De]=!0;[Pe];model={};template;$root;isSleeped=!1;components={};propsOption;[Ce]={};[Te];[Oe];[Se]=[];[$e]=new Map;[Ve]=!1;[_e]=!1;constructor(e,t={},s){this.$sections=t,this.isKeepAlive=s,this[Ce]=e||{}}get props(){if(void 0===this[Oe]){let e=this;this[Oe]=new Proxy(e[Ce],{get:(t,s)=>be(e[Ce],s,e.propsOption),set(){throw new Error("props 参数不允许变更,只允许单向数据传递")}})}return this[Oe]}$mount(e){if(!1===this[_e]){let e=()=>{let e=[],t=Object.getPrototypeOf(this);for(;null!==t&&t!==Object.prototype;)Object.getOwnPropertyNames(t).forEach((s=>{!1!==Ke.includes(s)||we(t,s)||"function"!=typeof t[s]||t[s].prototype?.hasOwnProperty("constructor")||e.push(s)})),t=Object.getPrototypeOf(t);return e};for(let t of e())this[t]=this[t].bind(this);this[_e]=!0}if(this.$root=e,this.isKeepAlive&&this.isSleeped)return this.isSleeped=!1,this[Te]&&this.$root?(this[Te].mount(this.$root),this.wakeup(),this.$trigger("wakeup"),this.$rootVNode&&je(this.$rootVNode),this):(g.error(Ae,"当前组件在唤醒时,发现渲染处理程序已被销毁,无法进行唤醒操作",[this,this.$root]),this);this.isSleeped=!1,this.model=V(this.model);let t=this.created(),s=()=>{this.$trigger("created"),this.template&&this.$render(),this.mounted(),this.$trigger("mounted")};return t&&t instanceof Promise?t.then((()=>{this[Ve]||s()})):s(),this}$nodeTransition(e,t,s,r,n){if("string"==typeof e){let t=this.$getRef(e);if(!t)return void g.error(Ae,`执行节点动画是找不到ref=${e}的节点`);e=t}this[Te]?.nodeTransition(e,t,s,r,n)}$destroy(e){if(!e&&this.isKeepAlive)return this[Te]?.sleep(),this.isSleeped=!0,this.sleeped(),this.$trigger("sleeped"),void(this.$rootVNode&&Me(this.$rootVNode));this[Ve]=!0;for(let e of this[Se])e.destroy();this[Se].length=0,this[Te]?.destroyWathcers(),this.beforeDestroy(),this.$trigger("beforeDestroy"),this[Te]?.destroy(),this[Te]=void 0,this.template&&Array.isArray(this.template)&&(this.template.length=0),this.$trigger("destroy"),this[$e].clear(),this.$root=void 0,this.isSleeped=!1,this.$sections={},this[Oe]=void 0,this[Ce]={},this.destroyed()}get $refs(){return this[Te]?.refs||{}}$getRef(e){return this.$refs[e]?.[0]}$getRefs(e){return this.$refs[e]}$syncProp(e,t,s){"function"==typeof t&&(s=t,t=void 0),t??=e,s??=e=>e,this.model[t]=s(this.props[e]),this.$watch((()=>this.props[e]),(()=>{this.model[t]=s?.(this.props[e])}))}get $rootVNode(){return this[Te]?.root}$watchNode(e,t){if(this[Te])return this[Te]?.addNodeWatcher(e,t),()=>{this[Te]?.removeNodeWatcher(e,t)};g.warn(Ae,"该组件还未挂载,不可以进行节点观察监听")}$watch(e,t,s){let r=new I((()=>{if(this[Ve]){for(let e of this[Se])e.destroy();return W}return e()}),((e,s)=>{this[Ve]||t(e,s)}),void 0,s);return this[Se].push(r),[r.value,()=>{r.destroy(),c(this[Se],r)}]}$on(e,t){let s=this[$e].get(e);void 0===s&&(s=[],this[$e].set(e,s)),!1===s?.includes(t)&&s.push(t)}$off(e,t){let s=this[$e].get(e);s&&(t?c(s,t):s.length=0)}$trigger(e,t,s){if(!this.$root)return;let r={eventName:e,stopPropagation:s?.stopPropagation??(()=>{}),preventDefault:s?.preventDefault??(()=>{}),data:t,target:s?.target??this.$rootVNode,event:s?.event};if(this.$rootVNode&&this.$rootVNode.parent&&this.$rootVNode.parent instanceof exports.VNode.Component&&!1===this[Te]?.render.triggerEvent(this.$rootVNode.parent,e,r))return;let n=this[$e].get(e);n?.length&&[...n].forEach((e=>{e(r)}));let i=this[$e].get("*");i?.length&&[...i].forEach((e=>{e(r)}))}$render(t,s){t??=this.template,this.template="function"==typeof t?t(e.RENDER_HANDLER):t,this.$root&&(this.template??=[],this[Te]?.reSetAsts(this.template,s),this[Te]??=new ve(this.template,this,this.$root),this[Te].parser(),this.$root&&this[Te].mount(this.$root))}created(){}mounted(){}beforeDestroy(){}sleeped(){}wakeup(){}destroyed(){}}const We={};function Ie(e,t){if("string"==typeof e)t&&(We[e]=t);else for(let t in e)We[t]=e[t]}function Le(e){return We[e]}function Me(e){e.childrens?.forEach((e=>{e instanceof exports.VNode.Component&&e.component?.sleeped(),Me(e)}))}function je(e){e.childrens?.forEach((e=>{e instanceof exports.VNode.Component&&e.component?.wakeup(),je(e)}))}class He extends ke{template=[];cache=new Map;mounted(){this.$watch((()=>this.props.name),(async e=>{this.$render([],!0),await Promise.resolve(),this.$root&&this.loadComponent(e)})),this.loadComponent(this.props.name)}propsVaule;created(){this.initProps()}initProps(){let e={};this.props.props||(Object.keys(this.props).forEach((t=>{!1!==this.filterProps(t)&&(e[t]=this.props[t],this.$watch((()=>this.props[t]),(()=>{this.propsVaule[t]=this.props[t]})))})),this.propsVaule=V(e))}filterProps(e){if("string"!=typeof e)return!1;let t=f(e);return"transition-name"!==t&&"name"!==t&&"keep-alive"!==t&&"ref"!==t&&void 0}async loadComponent(t){if(!t)return void this.$render([],this.isKeepAlive);let s;if(this.isKeepAlive){let s=this.cache.get(t);if(s)return void this.$render([e.createComponent(s,{"transition-name":this.props["transition-name"]})],!0)}let r=this.$rootVNode?.parent?.[exports.VNode.PARSERKEY]?.ob.components,n=r?.[t];void 0===n&&(n=Le(t)),n?(De in n||(n=(await n()).default),s=new n(this.props.props||this.propsVaule,this.$sections,this.isKeepAlive),s.$on("*",(e=>{this.$trigger(e.eventName,e.data,e)})),this.isKeepAlive&&this.cache.set(t,s),this.$render([e.createComponent(s,{"transition-name":this.props["transition-name"]})],this.isKeepAlive)):g.warn("component",`未找到${t}的组件`)}beforeDestroy(){this.removeCache()}removeCache(e){if(e){let t=this.cache.get(e);this.cache.delete(e),t&&t.$destroy(!0)}else this.cache.forEach((e=>{e.$destroy(!0)})),this.cache.clear()}}class Ye extends ke{template=function(){return[e.createCommand("RenderSection")]}}Ie({template:Ye,component:He});Object.defineProperty(exports,"AST",{enumerable:!0,get:function(){return e.AST}}),Object.defineProperty(exports,"EXPRESSHANDLERTAG",{enumerable:!0,get:function(){return e.EXPRESSHANDLERTAG}}),Object.defineProperty(exports,"RENDER_HANDLER",{enumerable:!0,get:function(){return e.RENDER_HANDLER}}),Object.defineProperty(exports,"createCodeFunction",{enumerable:!0,get:function(){return e.createCodeFunction}}),Object.defineProperty(exports,"createCommand",{enumerable:!0,get:function(){return e.createCommand}}),Object.defineProperty(exports,"createComment",{enumerable:!0,get:function(){return e.createComment}}),Object.defineProperty(exports,"createComponent",{enumerable:!0,get:function(){return e.createComponent}}),Object.defineProperty(exports,"createElement",{enumerable:!0,get:function(){return e.createElement}}),Object.defineProperty(exports,"createFuntionBody",{enumerable:!0,get:function(){return e.createFuntionBody}}),Object.defineProperty(exports,"createText",{enumerable:!0,get:function(){return e.createText}}),exports.BREAK_WATCH_UPDATE=W,exports.Component=ke,exports.ComponentContainer=He,exports.Dep=R,exports.EventBus=class{eventDatas=new Map;on(e,t){let s=this.eventDatas.get(e);void 0===s&&(s=[],this.eventDatas.set(e,s));let r={callBack:t};return s.push(r),()=>{s&&c(s,r)}}once(e,t){let s=this.eventDatas.get(e);void 0===s&&(s=[],this.eventDatas.set(e,s));let r={callBack:t,once:!0};return s.push(r),()=>{s&&c(s,r)}}off(e,t){if(void 0!==e)if(t){let s=this.eventDatas.get(e),r=s?.find((e=>e.callBack===t));r&&c(s,r)}else this.eventDatas.delete(e);else this.eventDatas.clear()}async trigger(e,t){let s=[...this.eventDatas.get(e)||[]];if(s.push(...this.eventDatas.get("*")||[]),s&&s.length){let r=0,n=0,i=!1;for(;s[r];){let o=s[r],a=await o.callBack({stopPropagation:()=>i=!0,callTimes:n,eventName:e},t);if(o.once?c(s,o):r++,!1===a||i)return!1}}}},exports.IS_DESTROY=Ve,exports.JOKER_COMPONENT_TAG=De,exports.JOKER_VNODE_TAG=L,exports.OBJECTPROXY_DEPID=w,exports.PARSER_TEMPLATE_TARGET=Te,exports.ParserTemplate=ve,exports.SCOPE_ID=Pe,exports.ShallowObserver=class{data;[P]=!0;dep=new R;constructor(e){this.data=e}isChanged=!1;get value(){return this.dep.depend(C),this.data}set value(e){!1===Object.is(e,this.data)&&(this.isChanged=!0,this.data=e,K(this.dep,C))}},exports.Template=Ye,exports.Watcher=I,exports.__GLONAL_FUNTIONS__=te,exports.__JOKER_HMR_RUNTIME=n,exports.combinedReply=function(e){D=!0;try{e()}catch(e){return D=!1,_.clear(),void g.error("数据劫持","数据劫持组合回复在做变更采集时,遇到了阻塞错误,不做响应,请检查",e)}D=!1,function(e){let t=[],s=[];e.forEach(((e,s)=>{e.forEach((e=>{t.push(...s.watchers.get(e)||[])}))})),t.forEach((e=>{s.includes(e)||(!1===e.isDestroy&&e.update(),s.push(e))}))}(_),_.clear()},exports.defineObserverProperty=T,exports.getGlobalComponent=Le,exports.isObserverData=function(e){return void 0!==$(e)},exports.observer=V,exports.registerGlobalComponent=Ie,exports.registerGlobalFunction=function(e){for(let t in e)te[t]=e[t]};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joker.front/core",
3
- "version": "1.3.54",
3
+ "version": "1.3.57",
4
4
  "description": "",
5
5
  "main": "./dist/bundle.js",
6
6
  "module": "./dist/bundle.es.js",
@@ -18,6 +18,10 @@
18
18
  "types/*",
19
19
  "README.md"
20
20
  ],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/jokers-pub/front-core.git"
24
+ },
21
25
  "scripts": {
22
26
  "test": "jest",
23
27
  "test:temp": "jest test/other/for-update.spec.ts",
@@ -28,14 +32,11 @@
28
32
  },
29
33
  "author": "Zohar",
30
34
  "license": "MIT",
31
- "repository": {
32
- "type": "git"
33
- },
35
+ "homepage": "https://front.jokers.pub",
34
36
  "keywords": [
35
37
  "joker",
36
38
  "front"
37
39
  ],
38
- "homepage": "jokers.pub",
39
40
  "dependencies": {
40
41
  "@joker.front/ast": "^1.3.24"
41
42
  },
@@ -7,7 +7,6 @@ declare const PROPS_DATA_PROXY: unique symbol;
7
7
  declare const PRIVATE_WATCHERS: unique symbol;
8
8
  declare const EVENT_DATA_KEY: unique symbol;
9
9
  export declare const IS_DESTROY: unique symbol;
10
- export declare const IS_RENDER: unique symbol;
11
10
  export declare const PARSER_TEMPLATE_TARGET: unique symbol;
12
11
  export type TemplateType = Array<AST.Node> | ((h: typeof RENDER_HANDLER) => Array<AST.Node>);
13
12
  export declare const SCOPE_ID: unique symbol;
@@ -67,7 +66,6 @@ export declare class Component<T extends DefaultKeyVal = {}> implements ICompone
67
66
  private [PRIVATE_WATCHERS];
68
67
  private [EVENT_DATA_KEY];
69
68
  private [IS_DESTROY];
70
- private [IS_RENDER];
71
69
  private [TRANSFORM_FUNCTION_FLAG];
72
70
  /**
73
71
  * @param propData prop参数
@@ -84,17 +82,11 @@ export declare class Component<T extends DefaultKeyVal = {}> implements ICompone
84
82
  * 挂载
85
83
  * @param root
86
84
  */
87
- $mount(root: any | VNode.Component): Promise<this>;
85
+ $mount(root: any | VNode.Component): this;
88
86
  /**
89
87
  * 节点动画,仅支持 element及组件节点
90
88
  */
91
89
  $nodeTransition(nodeOrRef: string | VNode.Node, mode: "enter" | "leave", name?: string, callBack?: Function, type?: "transition" | "animation"): void;
92
- /**
93
- * 等待下次渲染更新
94
- * @param callBack
95
- * @returns
96
- */
97
- $updatedRender(callBack?: Function): Promise<unknown>;
98
90
  /**
99
91
  * 销毁
100
92
  */
@@ -165,7 +157,7 @@ export declare class Component<T extends DefaultKeyVal = {}> implements ICompone
165
157
  * @param keepalive 渲染新模板时,是否要保留之前的存活组件(高级用法)
166
158
  * @returns
167
159
  */
168
- $render(newTemplate?: TemplateType, keepalive?: boolean): Promise<void>;
160
+ $render(newTemplate?: TemplateType, keepalive?: boolean): void;
169
161
  /**
170
162
  * 生命周期函数(完成初始化)
171
163
  */
@@ -214,7 +206,7 @@ export declare class ComponentContainer extends Component<{
214
206
  }> {
215
207
  template: never[];
216
208
  private cache;
217
- mounted(): Promise<void>;
209
+ mounted(): void;
218
210
  private propsVaule;
219
211
  created(): void;
220
212
  initProps(): void;
@@ -2,7 +2,7 @@ import { AST } from "@joker.front/ast";
2
2
  import { IParser } from "../parser";
3
3
  import { VNode } from "../vnode";
4
4
  export declare class ParserCondition extends IParser<AST.IfCommand, VNode.Condition> {
5
- parser(): Promise<void>;
5
+ parser(): void;
6
6
  renderId?: string;
7
7
  private getElseNode;
8
8
  /**
@@ -3,10 +3,9 @@ import { ObType } from "../index";
3
3
  import { IParser } from "../parser";
4
4
  import { VNode } from "../vnode";
5
5
  export declare class ParserList extends IParser<AST.ForCommand, VNode.List> {
6
- parser(): Promise<void>;
6
+ parser(): void;
7
7
  private renderChildrens;
8
8
  private renderConditionChildrens;
9
- renderId?: string;
10
9
  private renderInOrOfChildrens;
11
10
  findIndexByIndex(ob: ObType, startIndex: number, indexKey?: string): number;
12
11
  /**
@@ -24,5 +23,5 @@ export declare class ParserList extends IParser<AST.ForCommand, VNode.List> {
24
23
  private checkObEqual;
25
24
  }
26
25
  export declare class ParserListeItem extends IParser<AST.ForCommand, VNode.ListItem> {
27
- parser(index?: number): Promise<void>;
26
+ parser(index?: number): void;
28
27
  }
@@ -3,6 +3,6 @@ import { IParser } from "../parser";
3
3
  import { VNode } from "../vnode";
4
4
  export declare const DEFAULT_SECTION_TAG = "default";
5
5
  export declare class ParserRenderSection extends IParser<AST.PropertyOrFunctionCommand, VNode.RenderSection> {
6
- parser(): Promise<void>;
6
+ parser(): void;
7
7
  private transformParam;
8
8
  }
@@ -6,7 +6,7 @@ export declare function checkIsComponent(tagName: string, ob: Component): boolea
6
6
  export declare class ParserComponent extends IParser<(AST.Element | AST.Component) & {
7
7
  node?: VNode.Component;
8
8
  }, VNode.Component> {
9
- parser(): Promise<void>;
9
+ parser(): void;
10
10
  /**
11
11
  * 是否允许重载
12
12
  * 直接指向内存的组件,无法重新实例化
@@ -2,7 +2,7 @@ import { AST } from "@joker.front/ast";
2
2
  import { IParser } from "./parser";
3
3
  import { VNode } from "./vnode";
4
4
  export declare class ParserElement extends IParser<AST.Element, VNode.Element> {
5
- parser(): Promise<void>;
5
+ parser(): void;
6
6
  private initAttributes;
7
7
  private initEvents;
8
8
  private transformAttrVal;
@@ -19,19 +19,18 @@ export declare class ParserTemplate {
19
19
  /** VNode 渲染处理程序 (依赖注入) */
20
20
  render: Render.IRender;
21
21
  constructor(asts: AST.Node[], ob: ObType, parent?: VNode.Node);
22
- parser(): Promise<void>;
22
+ parser(): void;
23
23
  /**
24
24
  * VNode挂载
25
25
  * @param root
26
26
  */
27
27
  mount(root: any): void;
28
- promiseQueue: Set<Promise<any>>;
29
28
  /**
30
29
  * 编译AST子集
31
30
  * @param asts
32
31
  * @param parent
33
32
  */
34
- parserNodes(asts: AST.Node[], parent: VNode.Node, ob?: Component & Record<string, any>): Promise<void>;
33
+ parserNodes(asts: AST.Node[], parent: VNode.Node, ob?: Component & Record<string, any>): void;
35
34
  /**
36
35
  * 添加ref
37
36
  * @param refName ref值
@@ -27,11 +27,11 @@ export declare abstract class IParser<T extends AST.Node, N extends VNode.Node>
27
27
  parent: VNode.Node,
28
28
  /** 外部处理(ParserTemplate) */
29
29
  ext: ParserTemplate);
30
- init(index?: number): Promise<void> | undefined;
30
+ init(index?: number): void;
31
31
  /**
32
32
  * 上游主入口方法(初始化执行)
33
33
  */
34
- abstract parser(index?: number): void | Promise<void>;
34
+ abstract parser(index?: number): void;
35
35
  protected beforeDestroy(keepalive?: boolean): void | boolean;
36
36
  /**
37
37
  * 销毁流程
@@ -1,2 +1 @@
1
- export declare function resolveDeepPromisesInPlace(obj: any, deep?: boolean): Promise<any> | undefined;
2
1
  export declare function isGetterProperty(obj: object, prop: string): false | (() => any) | undefined;
package/types/export.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export { AST, RENDER_HANDLER, EXPRESSHANDLERTAG, createCodeFunction, createCommand, createComment, createElement, createFuntionBody, createText, createComponent } from "@joker.front/ast";
2
- export * from "./component";
3
- export * from "./parser/vnode";
4
- export { ParserTemplate, NodeChangeType } from "./parser/index";
5
- export * from "./observer/watcher";
6
- export { Dep } from "./observer/dep";
7
- export * from "./observer/index";
8
- export * from "./utils/DI";
9
- export * from "./event-bus";
10
- export { registerGlobalFunction } from "./global";
11
- export { Render } from "./parser/render";