@joker.front/core 1.2.237 → 1.2.246

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/dist/bundle.es.js CHANGED
@@ -1 +1 @@
1
- import{EXPRESSHANDLERTAG as e,createFuntionBody as t,AST as s,RENDER_HANDLER as n,createComponent as i,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 s=h.get(e);if(!s)return;s.component=t;let n=o.get(e);if(!n)return;let i=Array.from(n);n.clear(),i.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 s=a.get(e);s&&(s.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((s=>{t(s,e[s])}))}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 s=Object.keys(e);for(let n of s){let s=e[n];t[n]="object"==typeof s?f(s):s}return t}function p(e,t,s){return Array.isArray(e)&&Array.isArray(t)?function(e,t,s){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!1===m(e[n],t[n],s))return!1;return!0}(e,t,s):m(e,t,s)}function m(e,t,s){let n=l(e),i=l(t);if(n&&i){if(u(e)&&u(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;if(s){for(let s of n)if(e[s]!==t[s])return!1;return!0}return JSON.stringify(e)===JSON.stringify(t)}return e===t}return!n&&!i&&String(e)===String(t)}function y(e,t){let s=e.indexOf(t);return s>-1&&e.splice(s,1),e}function E(e,t){let s=e.findIndex((e=>t(e)));return s>-1&&e.splice(s,1),e}function v(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 n=0;n<e;n++){let e=Math.round(Math.random()*(s.length-1));t.push(s[e])}return t.join("")}function g(e){return!e||""===e.trim()}function b(e,t="-"){return(e=e||"").split(/(?=[A-Z])/).map((e=>e.toLowerCase())).join(t)}let N=(...e)=>{},w="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 A(e,t,s,n){R.indexOf(e)<=R.indexOf(w)&&(void 0===n?console[e](`${$()} [${t}]:`,s):console[e](`${$()} [${t}]:`,s,n))}let C={info:function(e,t,s){A("info",e,t,s)},warn:function(e,t,s){A("warn",e,t,s)},error:function(e,t,s){A("error",e,t,s)},setLoggerLeve:function(e){w=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{id="production"===process.env.NODE_ENV?"":v();static target;watchers=new Map;depend(e){S.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&&y(s,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)&&(Array.isArray(e)||u(e))&&Object.isExtensible(e)&&!Object.isFrozen(e)&&!(e instanceof Element)&&!(q in e)&&!(M in e)&&!(Je in e)}function k(e){if(K(e))return e;let t=Reflect.get(e,T);if(t)return t;let s=new S,n=!0,i=new Proxy(e,{get(e,t,n){if(t===T)return;if(t===P)return s;if(t===D)return;let i=Reflect.get(e,t);return!1===function(e,t){return t in e}(e,t)&&"length"!==t||(s.depend(t),_(i)&&K(i)?.depend(D)),i},set(e,t,i){if(n)return Reflect.set(e,t,i),!0;_(i)&&(i=W(i));let r=!1===function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t),o=Reflect.get(e,t)!==i;return Reflect.set(e,t,i),(o||"length"===t&&Array.isArray(e))&&Y(s,t),Array.isArray(e)?"length"===t&&Y(s,D):r&&Y(s,D),!0},deleteProperty:(e,t)=>(Reflect.deleteProperty(e,t),!1===Array.isArray(e)&&Y(s,D),!0)});var r,o,a,h;r=e,o=T,a=i,h=!1,Object.defineProperty(r,o,{value:a,enumerable:h,writable:!0,configurable:!0});for(let t in e){let s=e[t];_(s)&&!K(s)&&(i[t]=k(e[t]))}return n=!1,i}function K(e){if(l(e)){let t=Reflect.get(e,P);if(t)return t}}function W(e,t=!1){if(!1===_(e))throw new Error("当前传入的数据不是正确的数据类型,必须是数组或者对象");return k(t?f(e):e)}function V(e,t,s){let n=s;_(s)&&(n=W(s));let i=new S;Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:()=>(i.depend(t),_(n)&&K(n)?.depend(D),n),set:e=>{e!==n&&(_(e)&&(e=W(e)),n=e,Y(i,t))}})}const M=Symbol.for("JOKER_SHALLOW_OBSERVER");class L{data;[M]=!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 I=!1,j=new Map;function Y(e,t){if(!1===I)e.notify(t);else{let s=j.get(e);void 0===s&&(s=[],j.set(e,s)),!1===s.includes(t)&&s.push(t)}}function H(e){I=!0;try{e()}catch(e){return I=!1,j.clear(),void C.error("数据劫持","数据劫持组合回复在做变更采集时,遇到了阻塞错误,不做响应,请检查",e)}I=!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))}))}(j),j.clear()}function B(e){return void 0!==K(e)}const J="数据观察";class F{ob;updateCallBack;forceCallBack;id=v();getter;value;isDestroy=!1;updating=!1;runRelations=new Map;relations=new Map;constructor(e,t,s,n){if(this.ob=e,this.updateCallBack=t,this.forceCallBack=n,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&&C.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 C.error(J,`获取值失败,执行方法:${this.getter.toString()}`),e}return S.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 n=this.relations.get(e);void 0!==n&&!1!==n.includes(t)||e.addWatcher(t,this)}}update(){if(this.updating)return;let e=this.getValue(),t=this.value;if(this.forceCallBack||e!==t||l(e)){if(this.value=e,e!==t&&!this.forceCallBack&&p(e,t,!0))return;this.updating=!0;try{this.updateCallBack(e,t)}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 n of e)s?!1===s.includes(n)&&t.removeWatcher(n,this):t.removeWatcher(n,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:s=>{if(t.has(e))throw new Error(`TagId:${e.toString()}已注入实现类,请勿重复注入。`);t.set(e,s)}}},e.get=function(e,...s){let n=t.get(e);if(n)return new n(...s)}}(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,s){if(!0===t(this))return this;let n=this.parent;for(;n;){if(s&&n instanceof e.Root)return;if(!0===t(n))return n;n=n.parent}}find(e,t,s){let n=s??[];if(t??=this.childrens,t)for(let s of t){!0===e(s)&&n.push(s),s.childrens&&this.find(e,s.childrens,n)}return n}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 n of s){if(n instanceof e.Element)return n;if(n.childrens){let e=t(n.childrens);if(e)return e}}};return t(this.childrens)}}get rootElements(){if(this.childrens){let t=[],s=n=>{for(let i of n)i instanceof e.Element?t.push(i):i.childrens&&s(i.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}}}(X||(X={}));const z="DOM渲染",Z=["script","style","textarea","pre"];let Q=0;var U;function ee(e,t,s){return`${e}-${t}-${s}`}function te(e,t,s,n){e._assistEventCache??=[],e._assistEventCache.push([t,s]),document.body.addEventListener(t,s,n)}function se(e,t,s){e._assistEventCache&&t&&s?(E(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)}!function(e){e.IRENDERIOCTAGID=Symbol.for("JOKER_IRENDERIOC_TAGID"),e.ROOT_CONTAINER="";e.DomRender=class{elements;constructor(){this.elements=document.createDocumentFragment()}mount(e){if(e instanceof Element)e.appendChild(this.elements);else if(e instanceof X.Component)if(e.parent)if(e.output){let t=e.output,s=ae(e)||t.parentNode;s&&s.insertBefore(this.elements,t)}else C.error(z,"组件挂载渲染时发现该节点未定义DOM定位节点",e);else C.error(z,"mount子组件时,发现该组件无父级",e);else C.error(z,"mount只支持挂载到Element或VNode.Node类型数据中",e)}appendNode(e){if(this.renderNode(e),e.output){let t=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];for(let s of t)this.appendNodeChildren(e,s,e.parent)}else C.error(z,"未找自身节点的el属性,无法进行dom挂载",e)}updateNode(e,t){if(e instanceof X.Element)for(let t in e.attributes){let s=e.attributes[t];this.setAttribute(e.output,t,s)}else e instanceof X.Text?e.parent&&e.parent instanceof X.Element&&Z.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:C.error(z,`该节点不支持${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 X.Element&&se(e),e.output=void 0)}destroy(){this.elements=void 0}elementToEnter(e,t,s,n){e.output&&this.transitionFrame(e,t,"enter",s,n)}elementToLeave(e,t,s,n){e.output&&this.transitionFrame(e,t,"leave",s,n)}triggerEvent(e,t,s){let n=[];for(let i of e.events){let[r,o]=i;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=s.event;if((h instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(r)||h instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(r))&&!1===ie(h,o.modifiers))continue;if(o.callBack(s),o.modifiers?.includes("prevent")&&s.preventDefault(),o.modifiers?.includes("once")&&n.push(i),o.modifiers?.includes("stop"))return s.stopPropagation(),!1}}n.length&&n.forEach((t=>{y(e.events,t)}))}transitionFrame(e,t,s,n,i){re(e,ee(t,s,"from")),n||="transition";let r=e.output.__TRANSITION_EVNETID__=Q++;requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(!e.output)return;re(e,ee(t,s,"active")),oe(e,ee(t,s,"from")),re(e,ee(t,s,"to"));let o=function(e,t){let s=window.getComputedStyle(e),n=e=>(s[e]||"").split(", ");if("transition"===t){let e=n("transitionDelay"),t=n("transitionDuration"),s=he(e,t);if(s>0)return{timeout:s,count:t.length}}else if("animation"===t){let e=n("animationDelay"),t=n("animationDuration"),s=he(e,t);if(s>0)return{timeout:s,count:t.length}}}(e.output,n);if(!o)return void i?.();let a=0,h=()=>{oe(e,ee(t,s,"to")),oe(e,ee(t,s,"active")),e.output&&(e.output.removeEventListener(`${n}end`,d),r===e.output.__TRANSITION_EVNETID__&&i?.())},d=t=>{t.target===e.output&&++a>=o.count&&h()};setTimeout((()=>{a<o.count&&h()}),o.timeout+1),e.output?.addEventListener(`${n}end`,d)}))}))}renderNode(e){if(!e.output)if(e instanceof X.Text)e.parent&&e.parent instanceof X.Element&&Z.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;"svg"===e.tagName||e.parent.isSvg?(e.isSvg=!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 X.Comment?e.output=document.createComment(e.text):e.output=document.createTextNode("")}initElementEvents(e,t){for(let[s,n]of t.events){let i=n.modifiers?.includes("self"),r=n.modifiers?.includes("outside");i&&r&&(C.warn(z,"事件修饰符:self、outside不可以同时存在,将按照self处理",t),r=!1);let o,a=function(o){if(!(t.sleep||i&&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(s)||o instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(s))&&!1===ie(o,n.modifiers)||(n.callBack({eventName:s,event:o,target:t,preventDefault:()=>o.preventDefault(),stopPropagation:()=>o.stopPropagation(),data:void 0}),n.modifiers?.includes("prevent")&&o.preventDefault(),n.modifiers?.includes("stop")&&o.stopPropagation(),n.modifiers?.includes("once")&&(r?se(t,s,a):e.removeEventListener(s,a)))}};n.modifiers?.includes("passive")&&(o={passive:!0}),r?te(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 X.Component||e instanceof X.Condition||e instanceof X.List||e instanceof X.ListItem||e instanceof X.RenderSection}appendNodeChildren(e,t,s){let n=ae(e);if(n)n.appendChild(t);else if(void 0===s)this.elements.appendChild(t);else if(s)if(s instanceof X.Root){let e=s.parent;if(e&&e instanceof X.Component&&e.output){let s=e.output,n=s.parentNode;if(n)return void n.insertBefore(t,s)}this.elements.appendChild(t)}else if(s instanceof X.Element){let n=s.output;void 0===n&&C.error(z,"appendNodeChildren挂载失败,找不到父节点DOM输出",{parent:s,node:e}),n.appendChild(t)}else if(this.isCommandGroup(s)){let e=s.output,n=e.parentNode;n&&n.insertBefore(t,e)}else C.error(z,"该节点不支持嵌套子集,请检查。",{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(l(t))for(let s in t)t[s]&&e.push(s);else t&&e.push(t);s=e.join(" ")}else if(l(s)){for(let t in s)s[t]?e.classList.add(t):e.classList.remove(t);return}}else if("style"===t&&l(s)){e.removeAttribute("style");for(let t in s){let n=!1;void 0!==s[t]&&!1!==s[t]||(n=!0);let i=String(s[t]);g(i)&&(n=!0),n||(e.style[t]=i)}return}s=(s??"").toString().trim(),"class"===t&&(s=s.split(/\s/).filter((e=>e.trim())).join(" ")),"value"===t&&"value"in e?e.value=s:e.setAttribute(t,s)}else s?e.setAttribute(t,""):e.removeAttribute(t)}}}(U||(U={}));const ne={enter:"enter",backspace:"delete",tab:"tab",arrowup:"up",arrowdown:"down",arrowleft:"left",arrowright:"right",escape:"esc"," ":"space"};function ie(e,t){if(e instanceof KeyboardEvent){if(void 0===e.key)return!1;for(let s in ne)if(t?.includes(ne[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 re(e,t){e.output&&e.output.classList.add(t)}function oe(e,t){e.output&&e.output.classList.remove(t)}function ae(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){U.ROOT_CONTAINER&&(t="body"===t?U.ROOT_CONTAINER:`${U.ROOT_CONTAINER} ${t}`);let e=document.querySelector(t);if(e)return e}C.warn(z,"appendTo类型不支持",{appendTo:t,node:e})}}}function he(e,t){for(;e.length<t.length;)e.concat(e);return Math.max(...t.map(((t,s)=>de(t)+de(e[s]))))}function de(e){return"auto"===e?0:1e3*Number(e.slice(0,-1).replace(",","."))}class le extends HTMLElement{root;constructor(){super(),this.root=this.attachShadow({mode:"open"})}}!customElements.get("joker-html-shadow")&&customElements.define("joker-html-shadow",le);const ce={};function ue(e){for(let t in e)ce[t]=e[t]}const fe="Global",pe="渲染核心";function me(t){try{return new Function(e,fe,`return ${t};`)}catch{throw new Error("创建表达式运行方法时出现未知错误,表达式为"+t)}}class ye{ast;ob;parent;ext;ref="";watchers=[];node;constructor(e,t,s,n){this.ast=e,this.ob=t,this.parent=s,this.ext=n,this.parser(),this.afterParser()}beforeDestroy(e){}destroy(e){if(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.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(){this.parent.childrens&&this.node&&(this.node[X.PARSERKEY]=this,this.parent.childrens.push(this.node),this.node instanceof X.Element&&this.ob[Be]&&(this.node.attributes["data-scoped-"+this.ob[Be]]=void 0),this.ext.render?.appendNode(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 me(e).call(t,t,ce)}catch(s){C.error(pe,"运行表达式出现错误:"+e,{ob:t,e:s})}}runExpressWithWatcher(e,t,s,n){let i="string"==typeof e?me(e):e,r=new F((()=>{try{return i.call(t,t,ce)}catch(s){return void C.error(pe,"运行表达式出现错误",{ob:t,e:s,express:e,node:this.node})}}),s,void 0,n);return this.addWatch(r),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 Ee extends ye{parser(){this.node=new X.Text(this.ast.text,this.parent),this.appendNode()}}class ve extends ye{parser(){this.node=new X.Comment(this.ast.text,this.parent),this.appendNode()}}class ge extends ye{parser(){if(this.node=new X.Condition(this.ast.kind,this.parent),"else"!==this.ast.kind){g(this.ast.condition)&&C.error("条件命令",`当前条件命令${this.ast.kind}没有判断条件,请检查`);let e=this.runExpressWithWatcher(this.ast.condition,this.ob,(e=>{let t=!!e;this.node?.result!==t&&(this.node.result=t,this.reloadAllCondition())}));this.node.result=!!e}this.appendNode(),this.renderConditionChildren()}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,e?this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob):this.destroyChildrens(!0),!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 ge&&t.renderConditionChildren(),e=e.next}}}}class be extends ye{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,s=Object.create(this.ob),n=!!this.runExpressWithWatcher(function(t,s,n){try{return new Function(e,`${e}.${t}=${s}; return ${n};`)}catch{throw new Error(`For循环命令,表达式运行依赖采集出现未知错误,其中letKey:${t},keyVal:${s},condition:${n}`)}}(t.letKey,t.defaultKeyVal,t.condition),s,(()=>{this.clearWatchers(),this.renderChildrens()}),!0),i=0;for(;n;){let e=Object.create(this.ob);V(e,t.letKey,s[t.letKey]);let r=i++;this.renderItem(e,r),this.runExpress(t.step,s),n=!!this.runExpress(t.condition,s),this.runExpressWithWatcher((()=>s[t.letKey]),s,(s=>{e[t.letKey]=s,this.renderItem(e,r)}))}this.destroyOldChildrens(i)}renderInOrOfChildrens(){let e=this.ast.param,t=this.runExpressWithWatcher(e.dataKey,this.ob,(()=>{this.clearWatchers(),this.renderChildrens()})),s=0;if(t&&(Array.isArray(t)||u(t)))for(let n in t){let i=Object.create(this.ob),r=Array.isArray(t)?Number(n):n;e.indexKey&&V(i,e.indexKey,r),e.itemKey&&V(i,e.itemKey,t[n]);let o=s++;this.renderItem(i,o),e.itemKey&&this.runExpressWithWatcher((()=>t[r]),t,(t=>{i[e.itemKey]=t,this.renderItem(i,o)}))}this.destroyOldChildrens(s)}renderItem(e,t){if(!this.ast.childrens?.length)return;let s=this.node?.childrens?.[t];if(s){if(this.checkObEqual(e,s.ob))return;c(e,((e,t)=>{s.ob[e]!==t&&(s.ob[e]=t)}))}else new Ne(this.ast,e,this.node,this.ext)}destroyOldChildrens(e){for(;this.node.childrens.length>e;){let e=this.node.childrens.pop();if(!e)break;e[X.PARSERKEY]?.destroy(!1)}}checkObEqual(e,t){let s=!0;return void 0!==t&&(c(e,((e,n)=>{t?.[e]!==n&&(s=!1)})),s)}}class Ne extends ye{parser(){this.node=new X.ListItem(this.ob,this.parent),this.appendNode(),this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}}function we(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 n in e){let i,r=e[n];i=t?we(r,t):r,i instanceof Promise&&s.push(i.then((t=>{e[n]=t})))}if(s.length>0)return Promise.all(s).then((()=>Promise.resolve(e)))}else if("object"==typeof e&&null!==e&&u(e)&&e instanceof Element==!1){let s=[];for(let n in e){let i=e[n];if(i instanceof Promise)s.push(i.then((t=>{e[n]=t})));else if(t){let e=we(i,t);e instanceof Promise&&s.push(e)}}if(s.length)return Promise.all(s).then((()=>e))}return e}function Re(e,t){if(!e.constructor)return!1;let s=Object.getOwnPropertyDescriptor(e.constructor.prototype,t);return s&&s.get}class $e extends ye{parser(){if(g(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(fe+".")?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 s=we(t[0]);s instanceof Promise?s.then((e=>{this.changeValue(e)})).catch((t=>{C.error("表达式编译",`${e}异步处理失败`,t)})):this.changeValue(s)}));t||=[];let s=we(t[0]);return s instanceof Promise?("Html"===this.ast.cmdName?this.node=new X.Html("",this.parent,t[1]):this.node=new X.Text("",this.parent),s.then((e=>{this.changeValue(e)})).catch((t=>{C.error("表达式编译",`${e}异步处理失败`,t)}))):"Html"===this.ast.cmdName?this.node=new X.Html(Ae(s),this.parent,t[1]):this.node=new X.Text(Ae(s),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 Oe extends ye{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)=>{V(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])}))}));return{id:e[0]||Ce,params:e.slice(1)}}return{id:Ce,params:[]}}}const xe="组件解析";class Se extends ye{parser(){if(this.ast.node)return this.node=this.ast.node,this.node.parent=this.parent,this.initPropData(),this.appendNode(),void this.node.component?.$mount(this.node);this.node=new X.Component(this.parent),this.initPropData(),this.initEvent(),this.appendNode(),this.renderChildren()}get canReload(){return"tagName"in this.ast||"function"==typeof this.ast.component}reload(){this.canReload?(this.beforeDestroy(),this.renderChildren()):C.warn(xe,"当前组件无法实现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=>{let s=we(t);s instanceof Promise?s.then((t=>{this.node&&(this.node.propValues[e.name]=t,this.notifyNodeWatcher("update",e.name))})).catch((t=>{C.error(xe,`${e.express}异步处理失败`,t)})):(this.node.propValues[e.name]=s,this.notifyNodeWatcher("update",e.name))})),s=we(t);s instanceof Promise?(this.node.propValues[e.name]=void 0,s.then((t=>{this.node&&(this.node.propValues[e.name]=t)})).catch((t=>{C.error(xe,`${e.express}异步处理失败`,t)}))):this.node.propValues[e.name]=s}else this.node.propValues[e.name]=e.value;else{if(g(e.value)){C.warn(xe,"元素的ref值不可以为空");continue}this.ref=e.value,this.ext.addRef(e.value,this.node)}this.node.propValues=W(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:N}]):t&&"function"==typeof t?this.node.events.push([e.name,{modifiers:e.modifiers,callBack:s=>{let n=[];e.functionParam&&(n=this.runExpress(`[${e.functionParam}]`,this.ob)),t.call(this.ext.ob,s,...n)}}]):C.error(xe,`${"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]||Ze(this.ast.tagName);if(void 0===e)return void C.error(xe,`渲染组件失败,未找到名称为'${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={},n=[];return this.ast.childrens.forEach((t=>{if(t.type===s.NodeType.COMMAND&&"if"===t.cmdName&&t.childrens){let i=t,r=t.childrens.some((e=>e.type===s.NodeType.COMMAND&&"section"===e.cmdName)),o=i.condition.startsWith(e+".$sections");if(o){return this.runExpress(i.condition,this.ob)?void n.push(...t.childrens):void 0}if(r&&"if"===i.kind&&!o)return void C.warn(xe,"在解析section时,发现该section包裹在一个条件语句中,该条件语句仅支持以$sections进行if判断,已作排出")}n.push(t)})),n.forEach((e=>{if(e.type===s.NodeType.COMMAND&&"section"===e.cmdName){let s=e,n=s.id||Ce;/^(\'|\")(.*?)((\'|\"))$/.test(n)&&(n=n.slice(1,-1)),t[n]=t[n]||{asts:[],ob:this.ob,params:s.paramKeys,parser:this.ext},t[n].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)}}const Pe="Element解析";class Te extends ye{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=this.runExpressWithWatcher(e.express,this.ob,(t=>{let s=t=>{this.node&&(this.node.attributes[e.name]=this.transformAttrVal(t),this.ext.render?.updateNode(this.node,e.name),this.notifyNodeWatcher("update",e.name))},n=we(t);n instanceof Promise?n.then((e=>{s(e)})).catch((t=>{C.error(Pe,`${e.express}异步处理失败`,t)})):s(n)})),s=we(t);s instanceof Promise?s.then((t=>{this.node&&(this.node.attributes[e.name]=this.transformAttrVal(t),this.ext.render?.updateNode(this.node,e.name))})).catch((t=>{C.error(Pe,`${e.express}异步处理失败`,t)})):this.node.attributes[e.name]=this.transformAttrVal(s)}else this.node.attributes[e.name]=e.value;else{if(g(e.value)){C.warn(Pe,"元素的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 n=[];e.functionParam&&(n=this.runExpress(`[${e.functionParam}]`,this.ob)),t&&t.call(this.ext.ob,s,...n)}}])}}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,s){this.asts=e,this.ob=t,this.root.component=t,this.render=G.get(U.IRENDERIOCTAGID)??new U.DomRender,s&&s instanceof X.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(e,t,n){e.forEach((e=>{if(e.type===s.NodeType.TEXT)new Ee(e,n??this.ob,t,this);else if(e.type===s.NodeType.COMMENT)new ve(e,n??this.ob,t,this);else if(e.type===s.NodeType.COMPONENT)new Se(e,n??this.ob,t,this);else if(e.type===s.NodeType.ELEMENT){let s=e;!function(e,t){return!!t.components[e]||!!Ze(e)}(s.tagName,n??this.ob)?new Te(s,n??this.ob,t,this):new Se(s,n??this.ob,t,this)}else if(e.type===s.NodeType.COMMAND){let s=e;switch(s.cmdName){case"if":case"elseif":case"else":new ge(s,n??this.ob,t,this);break;case"for":new be(s,n??this.ob,t,this);break;case"RenderSection":new Oe(s,n??this.ob,t,this);break;case"section":break;default:new $e(s,n??this.ob,t,this)}}}))}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,s,n){this.nodeWatcherEvents[e]?.forEach((e=>{e(t,s,n)}))}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(U.IRENDERIOCTAGID)??new U.DomRender,this.asts=e}nodeTransition(e,t,s,n,i){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(s??=r?.name,i??=r?.type,!s)return!1;let o=_e(e);if(o)return"enter"===t?this.render.elementToEnter(o,s,i,(()=>{let t=e[X.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-enter"),n?.()})):this.render.elementToLeave(o,s,i,(()=>{let t=e[X.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-leave"),n?.()})),!0;C.warn("渲染核心","在执行node动画时,发现数据不完备,请检查")}return!1}}function _e(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:_e(t)}function ke(e,t,s){if(void 0===t)return;let n=Array.isArray(s)?s:[s];for(let e of n){if(e===Array&&t instanceof Array)return t;if(typeof t===e.name.toLocaleLowerCase())return t}switch(n[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 Ke(e,t,s){let n,i,r;if("symbol"!=typeof t&&(n=b(t)),t in e?i=e[t]:n&&(i=e[n]),s&&(t in s?r=s[t]:n&&n in s&&(r=s[n])),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===i)throw new Error(`props中key:${t.toString()}是必须项,请检查`);if(e.type&&(i=ke(t,i,e.type)),e.validate&&!1===e.validate(i))throw new Error(`props中key${t.toString()}的值校验错误`);i=i??e.default}else i=We(r)?ke(t,i,r):i??r;return i}return i}function We(e){return!![String,Array,Number,Object,Function,Boolean].includes(e)||e instanceof Array&&We(e[0])}const Ve="组件",Me=Symbol.for("JOKER_PROPS_DATA_KEY"),Le=Symbol.for("JOKER_PROPS_DATA_PROXY"),Ie=Symbol.for("JOKER_PRIVATE_WATCHERS"),je=Symbol.for("JOKER_EVENT_DATA_KEY"),Ye=Symbol.for("JOKER_IS_DESTROY"),He=Symbol.for("JOKER_PARSER_TEMPLATE_TARGET"),Be=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;[Be];model={};template;$root;isSleeped=!1;components={};propsOption;[Me]={};[He];[Le];[Ie]=[];[je]=new Map;[Ye]=!1;[Fe]=!1;constructor(e,t={},s){this.$sections=t,this.isKeepAlive=s,this[Me]=e||{}}get props(){if(void 0===this[Le]){let e=this;this[Le]=new Proxy(e[Me],{get:(t,s)=>Ke(e[Me],s,e.propsOption),set(){throw new Error("props 参数不允许变更,只允许单向数据传递")}})}return this[Le]}$mount(e){if(!1===this[Fe]){let e=()=>{let e=[],t=Object.getPrototypeOf(this);for(;null!==t&&t!==Object.prototype;)Object.getOwnPropertyNames(t).forEach((s=>{!1!==Ge.includes(s)||Re(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[Fe]=!0}return this.$root=e,this.isKeepAlive&&this.isSleeped?(this.isSleeped=!1,this[He]&&this.$root?(this[He].mount(this.$root),this.wakeup(),this.$trigger("wakeup"),this.$rootVNode&&Ue(this.$rootVNode),this):(C.error(Ve,"当前组件在唤醒时,发现渲染处理程序已被销毁,无法进行唤醒操作",[this,this.$root]),this)):(this.isSleeped=!1,this.model=W(this.model),this.created(),this.$trigger("created"),this.template&&this.$render(),this.mounted(),this.$trigger("mounted"),this)}$nodeTransition(e,t,s,n,i){if("string"==typeof e){let t=this.$getRef(e);if(!t)return void C.error(Ve,`执行节点动画是找不到ref=${e}的节点`);e=t}this[He]?.nodeTransition(e,t,s,n,i)}$destroy(e){if(!e&&this.isKeepAlive)return this[He]?.sleep(),this.isSleeped=!0,this.sleeped(),this.$trigger("sleeped"),void(this.$rootVNode&&Qe(this.$rootVNode));for(let e of this[Ie])e.destroy();this[Ie].length=0,this[He]?.destroyWathcers(),this.beforeDestroy(),this.$trigger("beforeDestroy"),this[He]?.destroy(),this[He]=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[Ye]=!0,this[Le]=void 0,this[Me]={},this.destroyed()}get $refs(){return this[He]?.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[He]?.root}$watchNode(e,t){if(this[He])return this[He]?.addNodeWatcher(e,t),()=>{this[He]?.removeNodeWatcher(e,t)};C.warn(Ve,"该组件还未挂载,不可以进行节点观察监听")}$watch(e,t,s){let n=new F((()=>{if(!this[Ye])return e();for(let e of this[Ie])e.destroy()}),((e,s)=>{this[Ye]||t(e,s)}),void 0,s);return this[Ie].push(n),[n.value,()=>{n.destroy(),y(this[Ie],n)}]}$on(e,t){let s=this[je].get(e);void 0===s&&(s=[],this[je].set(e,s)),!1===s?.includes(t)&&s.push(t)}$off(e,t){let s=this[je].get(e);s&&(t?y(s,t):s.length=0)}$trigger(e,t,s){if(!this.$root)return;let n={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 X.Component&&!1===this[He]?.render.triggerEvent(this.$rootVNode.parent,e,n))return;let i=this[je].get(e);i?.length&&[...i].forEach((e=>{e(n)}));let r=this[je].get("*");r?.length&&[...r].forEach((e=>{e(n)}))}$render(e,t){e??=this.template,this.template="function"==typeof e?e(n):e,this.$root&&(this.template??=[],this[He]?.reSetAsts(this.template,t),this[He]??=new De(this.template,this,this.$root),this[He].parser(),this[He].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 Ze(e){return Xe[e]}function Qe(e){e.childrens?.forEach((e=>{e instanceof X.Component&&e.component?.sleeped(),Qe(e)}))}function Ue(e){e.childrens?.forEach((e=>{e instanceof X.Component&&e.component?.wakeup(),Ue(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=W(e))}filterProps(e){if("string"!=typeof e)return!1;let t=b(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([i(t,{"transition-name":this.props["transition-name"]})],!0)}let s=this.$rootVNode?.parent?.[X.PARSERKEY]?.ob.components,n=s?.[e];void 0===n&&(n=Ze(e)),n?(Je in n||(n=(await n()).default),t=new n(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([i(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 st{eventDatas=new Map;on(e,t){let s=this.eventDatas.get(e);void 0===s&&(s=[],this.eventDatas.set(e,s));let n={callBack:t};return s.push(n),()=>{s&&y(s,n)}}once(e,t){let s=this.eventDatas.get(e);void 0===s&&(s=[],this.eventDatas.set(e,s));let n={callBack:t,once:!0};return s.push(n),()=>{s&&y(s,n)}}off(e,t){if(void 0!==e)if(t){let s=this.eventDatas.get(e),n=s?.find((e=>e.callBack===t));n&&y(s,n)}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 n=0,i=0,r=!1;for(;s[n];){let o=s[n],a=await o.callBack({stopPropagation:()=>r=!0,callTimes:i,eventName:e},t);if(o.once?y(s,o):n++,!1===a||r)return!1}}}}export{qe as Component,et as ComponentContainer,S as Dep,st as EventBus,G as IContainer,Je as JOKER_COMPONENT_TAG,q as JOKER_VNODE_TAG,P as OBJECTPROXY_DEPID,He as PARSER_TEMPLATE_TARGET,De as ParserTemplate,U as Render,Be as SCOPE_ID,L as ShallowObserver,tt as Template,X as VNode,F as Watcher,ce as __GLONAL_FUNTIONS__,d as __JOKER_HMR_RUNTIME,H as combinedReply,V as defineObserverProperty,Ze as getGlobalComponent,B as isObserverData,W as observer,ze as registerGlobalComponent,ue as registerGlobalFunction};
1
+ import{EXPRESSHANDLERTAG as e,createFuntionBody as t,AST as s,RENDER_HANDLER as n,createComponent as i,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 s=h.get(e);if(!s)return;s.component=t;let n=o.get(e);if(!n)return;let i=Array.from(n);n.clear(),i.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 s=a.get(e);s&&(s.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((s=>{t(s,e[s])}))}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 s=Object.keys(e);for(let n of s){let s=e[n];t[n]="object"==typeof s?f(s):s}return t}function p(e,t,s){return Array.isArray(e)&&Array.isArray(t)?function(e,t,s){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!1===m(e[n],t[n],s))return!1;return!0}(e,t,s):m(e,t,s)}function m(e,t,s){let n=l(e),i=l(t);if(n&&i){if(u(e)&&u(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;if(s){for(let s of n)if(e[s]!==t[s])return!1;return!0}return JSON.stringify(e)===JSON.stringify(t)}return e===t}return!n&&!i&&String(e)===String(t)}function y(e,t){let s=e.indexOf(t);return s>-1&&e.splice(s,1),e}function E(e,t){let s=e.findIndex((e=>t(e)));return s>-1&&e.splice(s,1),e}function v(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 n=0;n<e;n++){let e=Math.round(Math.random()*(s.length-1));t.push(s[e])}return t.join("")}function g(e){return!e||""===e.trim()}function b(e,t="-"){return(e=e||"").split(/(?=[A-Z])/).map((e=>e.toLowerCase())).join(t)}let N=(...e)=>{},w="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 A(e,t,s,n){R.indexOf(e)<=R.indexOf(w)&&(void 0===n?console[e](`${$()} [${t}]:`,s):console[e](`${$()} [${t}]:`,s,n))}let C={info:function(e,t,s){A("info",e,t,s)},warn:function(e,t,s){A("warn",e,t,s)},error:function(e,t,s){A("error",e,t,s)},setLoggerLeve:function(e){w=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{id="production"===process.env.NODE_ENV?"":v();static target;watchers=new Map;depend(e){S.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&&y(s,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 k(e){return l(e)&&(Array.isArray(e)||u(e))&&Object.isExtensible(e)&&!Object.isFrozen(e)&&!(e instanceof Element)&&!(q in e)&&!(L in e)&&!(Fe in e)}function _(e){if(K(e))return e;let t=Reflect.get(e,T);if(t)return t;let s=new S,n=!0,i=new Proxy(e,{get(e,t,n){if(t===T)return;if(t===P)return s;if(t===D)return;let i=Reflect.get(e,t);return!1===function(e,t){return t in e}(e,t)&&"length"!==t||(s.depend(t),k(i)&&K(i)?.depend(D)),i},set(e,t,i){if(n)return Reflect.set(e,t,i),!0;k(i)&&(i=W(i));let r=!1===function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t),o=Reflect.get(e,t)!==i;return Reflect.set(e,t,i),(o||"length"===t&&Array.isArray(e))&&Y(s,t),Array.isArray(e)?"length"===t&&Y(s,D):r&&Y(s,D),!0},deleteProperty:(e,t)=>(Reflect.deleteProperty(e,t),!1===Array.isArray(e)&&Y(s,D),!0)});var r,o,a,h;r=e,o=T,a=i,h=!1,Object.defineProperty(r,o,{value:a,enumerable:h,writable:!0,configurable:!0});for(let t in e){let s=e[t];k(s)&&!K(s)&&(i[t]=_(e[t]))}return n=!1,i}function K(e){if(l(e)){let t=Reflect.get(e,P);if(t)return t}}function W(e,t=!1){if(!1===k(e))throw new Error("当前传入的数据不是正确的数据类型,必须是数组或者对象");return _(t?f(e):e)}function V(e,t,s){let n=s;k(s)&&(n=W(s));let i=new S;Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:()=>(i.depend(t),k(n)&&K(n)?.depend(D),n),set:e=>{e!==n&&(k(e)&&(e=W(e)),n=e,Y(i,t))}})}const L=Symbol.for("JOKER_SHALLOW_OBSERVER");class M{data;[L]=!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 I=!1,j=new Map;function Y(e,t){if(!1===I)e.notify(t);else{let s=j.get(e);void 0===s&&(s=[],j.set(e,s)),!1===s.includes(t)&&s.push(t)}}function H(e){I=!0;try{e()}catch(e){return I=!1,j.clear(),void C.error("数据劫持","数据劫持组合回复在做变更采集时,遇到了阻塞错误,不做响应,请检查",e)}I=!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))}))}(j),j.clear()}function B(e){return void 0!==K(e)}const J="数据观察";class F{ob;updateCallBack;forceCallBack;id=v();getter;value;isDestroy=!1;updating=!1;runRelations=new Map;relations=new Map;constructor(e,t,s,n){if(this.ob=e,this.updateCallBack=t,this.forceCallBack=n,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&&C.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 C.error(J,`获取值失败,执行方法:${this.getter.toString()}`),e}return S.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 n=this.relations.get(e);void 0!==n&&!1!==n.includes(t)||e.addWatcher(t,this)}}update(){if(this.updating)return;let e=this.getValue(),t=this.value;if(this.forceCallBack||e!==t||l(e)){if(this.value=e,e!==t&&!this.forceCallBack&&p(e,t,!0))return;this.updating=!0;try{this.updateCallBack(e,t)}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 n of e)s?!1===s.includes(n)&&t.removeWatcher(n,this):t.removeWatcher(n,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:s=>{if(t.has(e))throw new Error(`TagId:${e.toString()}已注入实现类,请勿重复注入。`);t.set(e,s)}}},e.get=function(e,...s){let n=t.get(e);if(n)return new n(...s)}}(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,s){if(!0===t(this))return this;let n=this.parent;for(;n;){if(s&&n instanceof e.Root)return;if(!0===t(n))return n;n=n.parent}}find(e,t,s){let n=s??[];if(t??=this.childrens,t)for(let s of t){!0===e(s)&&n.push(s),s.childrens&&this.find(e,s.childrens,n)}return n}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 n of s){if(n instanceof e.Element)return n;if(n.childrens){let e=t(n.childrens);if(e)return e}}};return t(this.childrens)}}get rootElements(){if(this.childrens){let t=[],s=n=>{for(let i of n)i instanceof e.Element||i instanceof e.Html?t.push(i):i.childrens&&s(i.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}}}(X||(X={}));const z="DOM渲染",Z=["script","style","textarea","pre"];let Q=0;const U=["svg","defs","use","rect","circle","ellipse","line","polyline","polygon","path","text","g"];var ee;function te(e,t,s){return`${e}-${t}-${s}`}function se(e,t,s,n){e._assistEventCache??=[],e._assistEventCache.push([t,s]),document.body.addEventListener(t,s,n)}function ne(e,t,s){e._assistEventCache&&t&&s?(E(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)}!function(e){e.IRENDERIOCTAGID=Symbol.for("JOKER_IRENDERIOC_TAGID"),e.ROOT_CONTAINER="";e.DomRender=class{elements;constructor(){this.elements=document.createDocumentFragment()}mount(e){if(e instanceof Element)e.appendChild(this.elements);else if(e instanceof X.Component)if(e.parent)if(e.output){let t=e.output,s=he(e)||t.parentNode;s&&s.insertBefore(this.elements,t)}else C.error(z,"组件挂载渲染时发现该节点未定义DOM定位节点",e);else C.error(z,"mount子组件时,发现该组件无父级",e);else C.error(z,"mount只支持挂载到Element或VNode.Node类型数据中",e)}appendNode(e){if(this.renderNode(e),e.output){let t=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];for(let s of t)this.appendNodeChildren(e,s,e.parent)}else C.error(z,"未找自身节点的el属性,无法进行dom挂载",e)}updateNode(e,t){if(e instanceof X.Element)for(let t in e.attributes){let s=e.attributes[t];this.setAttribute(e.output,t,s)}else e instanceof X.Text?e.parent&&e.parent instanceof X.Element&&Z.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:C.error(z,`该节点不支持${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 X.Element&&ne(e),e.output=void 0)}destroy(){this.elements=void 0}elementToEnter(e,t,s,n){e.output&&this.transitionFrame(e,t,"enter",s,n)}elementToLeave(e,t,s,n){e.output&&this.transitionFrame(e,t,"leave",s,n)}triggerEvent(e,t,s){let n=[];for(let i of e.events){let[r,o]=i;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=s.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(s),o.modifiers?.includes("prevent")&&s.preventDefault(),o.modifiers?.includes("once")&&n.push(i),o.modifiers?.includes("stop"))return s.stopPropagation(),!1}}n.length&&n.forEach((t=>{y(e.events,t)}))}transitionFrame(e,t,s,n,i){oe(e,te(t,s,"from")),n||="transition";let r=e.output.__TRANSITION_EVNETID__=Q++;requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(!e.output)return;oe(e,te(t,s,"active")),ae(e,te(t,s,"from")),oe(e,te(t,s,"to"));let o=function(e,t){let s=window.getComputedStyle(e),n=e=>(s[e]||"").split(", ");if("transition"===t){let e=n("transitionDelay"),t=n("transitionDuration"),s=de(e,t);if(s>0)return{timeout:s,count:t.length}}else if("animation"===t){let e=n("animationDelay"),t=n("animationDuration"),s=de(e,t);if(s>0)return{timeout:s,count:t.length}}}(e.output,n);if(!o)return void i?.();let a=0,h=()=>{ae(e,te(t,s,"to")),ae(e,te(t,s,"active")),e.output&&(e.output.removeEventListener(`${n}end`,d),r===e.output.__TRANSITION_EVNETID__&&i?.())},d=t=>{t.target===e.output&&++a>=o.count&&h()};setTimeout((()=>{a<o.count&&h()}),o.timeout+1),e.output?.addEventListener(`${n}end`,d)}))}))}renderNode(e){if(!e.output)if(e instanceof X.Text)e.parent&&e.parent instanceof X.Element&&Z.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,t.style.display="inline-block",e.output=t}else{let t=document.createElement("joker-html-shadow");t.JOKER_NODE=e,t.style.lineHeight="1",t.style.display="inline-block",t.root.innerHTML=e.html,e.output=t}else if(e instanceof X.Element){let t,s=e.tagName.toLowerCase();"svg"===s||U.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 X.Comment?e.output=document.createComment(e.text):e.output=document.createTextNode("")}initElementEvents(e,t){for(let[s,n]of t.events){let i=n.modifiers?.includes("self"),r=n.modifiers?.includes("outside");i&&r&&(C.warn(z,"事件修饰符:self、outside不可以同时存在,将按照self处理",t),r=!1);let o,a=function(o){if(!(t.sleep||i&&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(s)||o instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(s))&&!1===re(o,n.modifiers)||(n.callBack({eventName:s,event:o,target:t,preventDefault:()=>o.preventDefault(),stopPropagation:()=>o.stopPropagation(),data:void 0}),n.modifiers?.includes("prevent")&&o.preventDefault(),n.modifiers?.includes("stop")&&o.stopPropagation(),n.modifiers?.includes("once")&&(r?ne(t,s,a):e.removeEventListener(s,a)))}};n.modifiers?.includes("passive")&&(o={passive:!0}),r?se(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 X.Component||e instanceof X.Condition||e instanceof X.List||e instanceof X.ListItem||e instanceof X.RenderSection}appendNodeChildren(e,t,s){let n=he(e);if(n)n.appendChild(t);else if(void 0===s)this.elements.appendChild(t);else if(s)if(s instanceof X.Root){let e=s.parent;if(e&&e instanceof X.Component&&e.output){let s=e.output,n=s.parentNode;if(n)return void n.insertBefore(t,s)}this.elements.appendChild(t)}else if(s instanceof X.Element){let n=s.output;void 0===n&&C.error(z,"appendNodeChildren挂载失败,找不到父节点DOM输出",{parent:s,node:e}),n.appendChild(t)}else if(this.isCommandGroup(s)){let e=s.output,n=e.parentNode;n&&n.insertBefore(t,e)}else C.error(z,"该节点不支持嵌套子集,请检查。",{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(l(t))for(let s in t)t[s]&&e.push(s);else t&&e.push(t);s=e.join(" ")}else if(l(s)){for(let t in s)s[t]?e.classList.add(t):e.classList.remove(t);return}}else if("style"===t&&l(s)){e.removeAttribute("style");for(let t in s){let n=!1;void 0!==s[t]&&!1!==s[t]||(n=!0);let i=String(s[t]);g(i)&&(n=!0),n||(e.style[t]=i)}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)}}}(ee||(ee={}));const ie={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 s in ie)if(t?.includes(ie[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 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,s)=>le(t)+le(e[s]))))}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;constructor(e,t,s,n){this.ast=e,this.ob=t,this.parent=s,this.ext=n,this.parser(),this.afterParser()}beforeDestroy(e){}destroy(e){if(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.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(){this.parent.childrens&&this.node&&(this.node[X.PARSERKEY]=this,this.parent.childrens.push(this.node),this.node instanceof X.Element&&this.ob[Je]&&(this.node.attributes["data-scoped-"+this.ob[Je]]=void 0),this.ext.render?.appendNode(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(s){C.error(me,"运行表达式出现错误:"+e,{ob:t,e:s})}}runExpressWithWatcher(e,t,s,n){let i="string"==typeof e?ye(e):e,r=new F((()=>{try{return i.call(t,t,ue)}catch(s){return void C.error(me,"运行表达式出现错误",{ob:t,e:s,express:e,node:this.node})}}),s,void 0,n);return this.addWatch(r),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){g(this.ast.condition)&&C.error("条件命令",`当前条件命令${this.ast.kind}没有判断条件,请检查`);let e=this.runExpressWithWatcher(this.ast.condition,this.ob,(e=>{let t=!!e;this.node?.result!==t&&(this.node.result=t,this.reloadAllCondition())}));this.node.result=!!e}this.appendNode(),this.renderConditionChildren()}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,e?this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob):this.destroyChildrens(!0),!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}}}}class Ne 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,s=Object.create(this.ob),n=!!this.runExpressWithWatcher(function(t,s,n){try{return new Function(e,`${e}.${t}=${s}; return ${n};`)}catch{throw new Error(`For循环命令,表达式运行依赖采集出现未知错误,其中letKey:${t},keyVal:${s},condition:${n}`)}}(t.letKey,t.defaultKeyVal,t.condition),s,(()=>{this.clearWatchers(),this.renderChildrens()}),!0),i=0;for(;n;){let e=Object.create(this.ob);V(e,t.letKey,s[t.letKey]);let r=i++;this.renderItem(e,r),this.runExpress(t.step,s),n=!!this.runExpress(t.condition,s),this.runExpressWithWatcher((()=>s[t.letKey]),s,(s=>{e[t.letKey]=s,this.renderItem(e,r)}))}this.destroyOldChildrens(i)}renderInOrOfChildrens(){let e=this.ast.param,t=this.runExpressWithWatcher(e.dataKey,this.ob,(()=>{this.clearWatchers(),this.renderChildrens()})),s=0;if(t&&(Array.isArray(t)||u(t)))for(let n in t){let i=Object.create(this.ob),r=Array.isArray(t)?Number(n):n;e.indexKey&&V(i,e.indexKey,r),e.itemKey&&V(i,e.itemKey,t[n]);let o=s++;this.renderItem(i,o),e.itemKey&&this.runExpressWithWatcher((()=>t[r]),t,(t=>{i[e.itemKey]=t,this.renderItem(i,o)}))}this.destroyOldChildrens(s)}renderItem(e,t){if(!this.ast.childrens?.length)return;let s=this.node?.childrens?.[t];if(s){if(this.checkObEqual(e,s.ob))return;c(e,((e,t)=>{s.ob[e]!==t&&(s.ob[e]=t)}))}else new we(this.ast,e,this.node,this.ext)}destroyOldChildrens(e){for(;this.node.childrens.length>e;){let e=this.node.childrens.pop();if(!e)break;e[X.PARSERKEY]?.destroy(!1)}}checkObEqual(e,t){let s=!0;return void 0!==t&&(c(e,((e,n)=>{t?.[e]!==n&&(s=!1)})),s)}}class we extends Ee{parser(){this.node=new X.ListItem(this.ob,this.parent),this.appendNode(),this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}}function Re(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 n in e){let i,r=e[n];i=t?Re(r,t):r,i instanceof Promise&&s.push(i.then((t=>{e[n]=t})))}if(s.length>0)return Promise.all(s).then((()=>Promise.resolve(e)))}else if("object"==typeof e&&null!==e&&u(e)&&e instanceof Element==!1){let s=[];for(let n in e){let i=e[n];if(i instanceof Promise)s.push(i.then((t=>{e[n]=t})));else if(t){let e=Re(i,t);e instanceof Promise&&s.push(e)}}if(s.length)return Promise.all(s).then((()=>e))}return e}function $e(e,t){if(!e.constructor)return!1;let s=Object.getOwnPropertyDescriptor(e.constructor.prototype,t);return s&&s.get}class Ae extends Ee{parser(){if(g(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,(t=>{let s=Re(t[0]);s instanceof Promise?s.then((e=>{this.changeValue(e)})).catch((t=>{C.error("表达式编译",`${e}异步处理失败`,t)})):this.changeValue(s)}));t||=[];let s=Re(t[0]);return s instanceof Promise?("Html"===this.ast.cmdName?this.node=new X.Html("",this.parent,t[1]):this.node=new X.Text("",this.parent),s.then((e=>{this.changeValue(e)})).catch((t=>{C.error("表达式编译",`${e}异步处理失败`,t)}))):"Html"===this.ast.cmdName?this.node=new X.Html(Ce(s),this.parent,t[1]):this.node=new X.Text(Ce(s),this.parent),void this.appendNode()}throw new Error(`未找到命令:${this.ast.cmdName}`)}changeValue(e){this.node&&(this.node instanceof X.Html?this.node.html=Ce(e):this.node.text=Ce(e),this.ext.render?.updateNode(this.node))}}function Ce(e){return null==e||"function"==typeof e?"":e.toString()}const Oe="default";class xe 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)=>{V(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]||Oe;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])}))}));return{id:e[0]||Oe,params:e.slice(1)}}return{id:Oe,params:[]}}}const Se="组件解析";class Pe extends Ee{parser(){if(this.ast.node)return this.node=this.ast.node,this.node.parent=this.parent,this.initPropData(),this.appendNode(),void this.node.component?.$mount(this.node);this.node=new X.Component(this.parent),this.initPropData(),this.initEvent(),this.appendNode(),this.renderChildren()}get canReload(){return"tagName"in this.ast||"function"==typeof this.ast.component}reload(){this.canReload?(this.beforeDestroy(),this.renderChildren()):C.warn(Se,"当前组件无法实现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=>{let s=Re(t);s instanceof Promise?s.then((t=>{this.node&&(this.node.propValues[e.name]=t,this.notifyNodeWatcher("update",e.name))})).catch((t=>{C.error(Se,`${e.express}异步处理失败`,t)})):(this.node.propValues[e.name]=s,this.notifyNodeWatcher("update",e.name))})),s=Re(t);s instanceof Promise?(this.node.propValues[e.name]=void 0,s.then((t=>{this.node&&(this.node.propValues[e.name]=t)})).catch((t=>{C.error(Se,`${e.express}异步处理失败`,t)}))):this.node.propValues[e.name]=s}else this.node.propValues[e.name]=e.value;else{if(g(e.value)){C.warn(Se,"元素的ref值不可以为空");continue}this.ref=e.value,this.ext.addRef(e.value,this.node)}this.node.propValues=W(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:N}]):t&&"function"==typeof t?this.node.events.push([e.name,{modifiers:e.modifiers,callBack:s=>{let n=[];e.functionParam&&(n=this.runExpress(`[${e.functionParam}]`,this.ob)),t.call(this.ext.ob,s,...n)}}]):C.error(Se,`${"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]||Qe(this.ast.tagName);if(void 0===e)return void C.error(Se,`渲染组件失败,未找到名称为'${this.ast.tagName}'的私有组件/全局组件`);if(Fe 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={},n=[];return this.ast.childrens.forEach((t=>{if(t.type===s.NodeType.COMMAND&&"if"===t.cmdName&&t.childrens){let i=t,r=t.childrens.some((e=>e.type===s.NodeType.COMMAND&&"section"===e.cmdName)),o=i.condition.startsWith(e+".$sections");if(o){return this.runExpress(i.condition,this.ob)?void n.push(...t.childrens):void 0}if(r&&"if"===i.kind&&!o)return void C.warn(Se,"在解析section时,发现该section包裹在一个条件语句中,该条件语句仅支持以$sections进行if判断,已作排出")}n.push(t)})),n.forEach((e=>{if(e.type===s.NodeType.COMMAND&&"section"===e.cmdName){let s=e,n=s.id||Oe;/^(\'|\")(.*?)((\'|\"))$/.test(n)&&(n=n.slice(1,-1)),t[n]=t[n]||{asts:[],ob:this.ob,params:s.paramKeys,parser:this.ext},t[n].asts.push(...e.childrens||[])}else t[Oe]=t[Oe]||{asts:[],ob:this.ob,parser:this.ext},t[Oe].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 Te="Element解析";class De 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=this.runExpressWithWatcher(e.express,this.ob,(t=>{let s=t=>{this.node&&(this.node.attributes[e.name]=this.transformAttrVal(t),this.ext.render?.updateNode(this.node,e.name),this.notifyNodeWatcher("update",e.name))},n=Re(t);n instanceof Promise?n.then((e=>{s(e)})).catch((t=>{C.error(Te,`${e.express}异步处理失败`,t)})):s(n)})),s=Re(t);s instanceof Promise?s.then((t=>{this.node&&(this.node.attributes[e.name]=this.transformAttrVal(t),this.ext.render?.updateNode(this.node,e.name))})).catch((t=>{C.error(Te,`${e.express}异步处理失败`,t)})):this.node.attributes[e.name]=this.transformAttrVal(s)}else this.node.attributes[e.name]=e.value;else{if(g(e.value)){C.warn(Te,"元素的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 n=[];e.functionParam&&(n=this.runExpress(`[${e.functionParam}]`,this.ob)),t&&t.call(this.ext.ob,s,...n)}}])}}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,s){this.asts=e,this.ob=t,this.root.component=t,this.render=G.get(ee.IRENDERIOCTAGID)??new ee.DomRender,s&&s instanceof X.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(e,t,n){e.forEach((e=>{if(e.type===s.NodeType.TEXT)new ve(e,n??this.ob,t,this);else if(e.type===s.NodeType.COMMENT)new ge(e,n??this.ob,t,this);else if(e.type===s.NodeType.COMPONENT)new Pe(e,n??this.ob,t,this);else if(e.type===s.NodeType.ELEMENT){let s=e;!function(e,t){return!!t.components[e]||!!Qe(e)}(s.tagName,n??this.ob)?new De(s,n??this.ob,t,this):new Pe(s,n??this.ob,t,this)}else if(e.type===s.NodeType.COMMAND){let s=e;switch(s.cmdName){case"if":case"elseif":case"else":new be(s,n??this.ob,t,this);break;case"for":new Ne(s,n??this.ob,t,this);break;case"RenderSection":new xe(s,n??this.ob,t,this);break;case"section":break;default:new Ae(s,n??this.ob,t,this)}}}))}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,s,n){this.nodeWatcherEvents[e]?.forEach((e=>{e(t,s,n)}))}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,s,n,i){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(s??=r?.name,i??=r?.type,!s)return!1;let o=_e(e);if(o)return"enter"===t?this.render.elementToEnter(o,s,i,(()=>{let t=e[X.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-enter"),n?.()})):this.render.elementToLeave(o,s,i,(()=>{let t=e[X.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-leave"),n?.()})),!0;C.warn("渲染核心","在执行node动画时,发现数据不完备,请检查")}return!1}}function _e(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:_e(t)}function Ke(e,t,s){if(void 0===t)return;let n=Array.isArray(s)?s:[s];for(let e of n){if(e===Array&&t instanceof Array)return t;if(typeof t===e.name.toLocaleLowerCase())return t}switch(n[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 We(e,t,s){let n,i,r;if("symbol"!=typeof t&&(n=b(t)),t in e?i=e[t]:n&&(i=e[n]),s&&(t in s?r=s[t]:n&&n in s&&(r=s[n])),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===i)throw new Error(`props中key:${t.toString()}是必须项,请检查`);if(e.type&&(i=Ke(t,i,e.type)),e.validate&&!1===e.validate(i))throw new Error(`props中key${t.toString()}的值校验错误`);i=i??e.default}else i=Ve(r)?Ke(t,i,r):i??r;return i}return i}function Ve(e){return!![String,Array,Number,Object,Function,Boolean].includes(e)||e instanceof Array&&Ve(e[0])}const Le="组件",Me=Symbol.for("JOKER_PROPS_DATA_KEY"),Ie=Symbol.for("JOKER_PROPS_DATA_PROXY"),je=Symbol.for("JOKER_PRIVATE_WATCHERS"),Ye=Symbol.for("JOKER_EVENT_DATA_KEY"),He=Symbol.for("JOKER_IS_DESTROY"),Be=Symbol.for("JOKER_PARSER_TEMPLATE_TARGET"),Je=Symbol.for("JOKER_SCOPE_ID"),Fe=Symbol.for("JOKER_COMPONENT_TAG"),Ge=Symbol();let qe=["constructor","$mount","$nodeTransition","$destroy","$getRef","$getRefs","$syncProp","$watchNode","$watch","$on","$off","$trigger","$render","created","mounted","beforeDestroy","sleeped","wakeup","destroyed"];class Xe{$sections;isKeepAlive;static[Fe]=!0;[Je];model={};template;$root;isSleeped=!1;components={};propsOption;[Me]={};[Be];[Ie];[je]=[];[Ye]=new Map;[He]=!1;[Ge]=!1;constructor(e,t={},s){this.$sections=t,this.isKeepAlive=s,this[Me]=e||{}}get props(){if(void 0===this[Ie]){let e=this;this[Ie]=new Proxy(e[Me],{get:(t,s)=>We(e[Me],s,e.propsOption),set(){throw new Error("props 参数不允许变更,只允许单向数据传递")}})}return this[Ie]}$mount(e){if(!1===this[Ge]){let e=()=>{let e=[],t=Object.getPrototypeOf(this);for(;null!==t&&t!==Object.prototype;)Object.getOwnPropertyNames(t).forEach((s=>{!1!==qe.includes(s)||$e(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[Ge]=!0}return this.$root=e,this.isKeepAlive&&this.isSleeped?(this.isSleeped=!1,this[Be]&&this.$root?(this[Be].mount(this.$root),this.wakeup(),this.$trigger("wakeup"),this.$rootVNode&&et(this.$rootVNode),this):(C.error(Le,"当前组件在唤醒时,发现渲染处理程序已被销毁,无法进行唤醒操作",[this,this.$root]),this)):(this.isSleeped=!1,this.model=W(this.model),this.created(),this.$trigger("created"),this.template&&this.$render(),this.mounted(),this.$trigger("mounted"),this)}$nodeTransition(e,t,s,n,i){if("string"==typeof e){let t=this.$getRef(e);if(!t)return void C.error(Le,`执行节点动画是找不到ref=${e}的节点`);e=t}this[Be]?.nodeTransition(e,t,s,n,i)}$destroy(e){if(!e&&this.isKeepAlive)return this[Be]?.sleep(),this.isSleeped=!0,this.sleeped(),this.$trigger("sleeped"),void(this.$rootVNode&&Ue(this.$rootVNode));for(let e of this[je])e.destroy();this[je].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[Ye].clear(),this.$root=void 0,this.isSleeped=!1,this.$sections={},this[He]=!0,this[Ie]=void 0,this[Me]={},this.destroyed()}get $refs(){return this[Be]?.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[Be]?.root}$watchNode(e,t){if(this[Be])return this[Be]?.addNodeWatcher(e,t),()=>{this[Be]?.removeNodeWatcher(e,t)};C.warn(Le,"该组件还未挂载,不可以进行节点观察监听")}$watch(e,t,s){let n=new F((()=>{if(!this[He])return e();for(let e of this[je])e.destroy()}),((e,s)=>{this[He]||t(e,s)}),void 0,s);return this[je].push(n),[n.value,()=>{n.destroy(),y(this[je],n)}]}$on(e,t){let s=this[Ye].get(e);void 0===s&&(s=[],this[Ye].set(e,s)),!1===s?.includes(t)&&s.push(t)}$off(e,t){let s=this[Ye].get(e);s&&(t?y(s,t):s.length=0)}$trigger(e,t,s){if(!this.$root)return;let n={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 X.Component&&!1===this[Be]?.render.triggerEvent(this.$rootVNode.parent,e,n))return;let i=this[Ye].get(e);i?.length&&[...i].forEach((e=>{e(n)}));let r=this[Ye].get("*");r?.length&&[...r].forEach((e=>{e(n)}))}$render(e,t){e??=this.template,this.template="function"==typeof e?e(n):e,this.$root&&(this.template??=[],this[Be]?.reSetAsts(this.template,t),this[Be]??=new ke(this.template,this,this.$root),this[Be].parser(),this[Be].mount(this.$root))}created(){}mounted(){}beforeDestroy(){}sleeped(){}wakeup(){}destroyed(){}}const ze={};function Ze(e,t){if("string"==typeof e)t&&(ze[e]=t);else for(let t in e)ze[t]=e[t]}function Qe(e){return ze[e]}function Ue(e){e.childrens?.forEach((e=>{e instanceof X.Component&&e.component?.sleeped(),Ue(e)}))}function et(e){e.childrens?.forEach((e=>{e instanceof X.Component&&e.component?.wakeup(),et(e)}))}class tt extends Xe{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=W(e))}filterProps(e){if("string"!=typeof e)return!1;let t=b(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([i(t,{"transition-name":this.props["transition-name"]})],!0)}let s=this.$rootVNode?.parent?.[X.PARSERKEY]?.ob.components,n=s?.[e];void 0===n&&(n=Qe(e)),n?(Fe in n||(n=(await n()).default),t=new n(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([i(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 st extends Xe{template=function(){return[r("RenderSection")]}}Ze({template:st,component:tt});class nt{eventDatas=new Map;on(e,t){let s=this.eventDatas.get(e);void 0===s&&(s=[],this.eventDatas.set(e,s));let n={callBack:t};return s.push(n),()=>{s&&y(s,n)}}once(e,t){let s=this.eventDatas.get(e);void 0===s&&(s=[],this.eventDatas.set(e,s));let n={callBack:t,once:!0};return s.push(n),()=>{s&&y(s,n)}}off(e,t){if(void 0!==e)if(t){let s=this.eventDatas.get(e),n=s?.find((e=>e.callBack===t));n&&y(s,n)}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 n=0,i=0,r=!1;for(;s[n];){let o=s[n],a=await o.callBack({stopPropagation:()=>r=!0,callTimes:i,eventName:e},t);if(o.once?y(s,o):n++,!1===a||r)return!1}}}}export{Xe as Component,tt as ComponentContainer,S as Dep,nt as EventBus,G as IContainer,Fe as JOKER_COMPONENT_TAG,q as JOKER_VNODE_TAG,P as OBJECTPROXY_DEPID,Be as PARSER_TEMPLATE_TARGET,ke as ParserTemplate,ee as Render,Je as SCOPE_ID,M as ShallowObserver,st as Template,X as VNode,F as Watcher,ue as __GLONAL_FUNTIONS__,d as __JOKER_HMR_RUNTIME,H as combinedReply,V as defineObserverProperty,Qe as getGlobalComponent,B as isObserverData,W 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 o=t.get(e);if(!o)return;let i=Array.from(o);o.clear(),i.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 o(e){return null!==e&&"object"==typeof e}function i(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(!1===l(e[r],t[r],s))return!1;return!0}(e,t,s):l(e,t,s)}function l(e,t,s){let r=o(e),n=o(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 E=(...e)=>{},y="warn";const N=["silent","error","warn","info"];function v(){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 g(e,t,s,r){N.indexOf(e)<=N.indexOf(y)&&(void 0===r?console[e](`${v()} [${t}]:`,s):console[e](`${v()} [${t}]:`,s,r))}let x={info:function(e,t,s){g("info",e,t,s)},warn:function(e,t,s){g("warn",e,t,s)},error:function(e,t,s){g("error",e,t,s)},setLoggerLeve:function(e){y=e}};const b={lt:"<",gt:">",nbsp:" ",amp:"&",quot:'"',"#39":"'"};function R(e){return e.replace(/&(lt|gt|nbsp|amp|quot|#39);/gi,((e,t)=>b[t]||""))}class w{id="production"===process.env.NODE_ENV?"":u();static target;watchers=new Map;depend(e){w.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__"),O=Symbol.for("__JOKER_OBJECT_PROXY_DATA_KEY__"),C=Symbol.for("__JOKER_OBJECTPROXY_DEPLEVE_ID__");function $(e){return o(e)&&(Array.isArray(e)||a(e))&&Object.isExtensible(e)&&!Object.isFrozen(e)&&!(e instanceof Element)&&!(I in e)&&!(D in e)&&!(De in e)}function V(e){if(S(e))return e;let t=Reflect.get(e,O);if(t)return t;let s=new w,r=!0,n=new Proxy(e,{get(e,t,r){if(t===O)return;if(t===A)return s;if(t===C)return;let n=Reflect.get(e,t);return!1===function(e,t){return t in e}(e,t)&&"length"!==t||(s.depend(t),$(n)&&S(n)?.depend(C)),n},set(e,t,n){if(r)return Reflect.set(e,t,n),!0;$(n)&&(n=T(n));let o=!1===function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t),i=Reflect.get(e,t)!==n;return Reflect.set(e,t,n),(i||"length"===t&&Array.isArray(e))&&k(s,t),Array.isArray(e)?"length"===t&&k(s,C):o&&k(s,C),!0},deleteProperty:(e,t)=>(Reflect.deleteProperty(e,t),!1===Array.isArray(e)&&k(s,C),!0)});var o,i,a,h;o=e,i=O,a=n,h=!1,Object.defineProperty(o,i,{value:a,enumerable:h,writable:!0,configurable:!0});for(let t in e){let s=e[t];$(s)&&!S(s)&&(n[t]=V(e[t]))}return r=!1,n}function S(e){if(o(e)){let t=Reflect.get(e,A);if(t)return t}}function T(e,t=!1){if(!1===$(e))throw new Error("当前传入的数据不是正确的数据类型,必须是数组或者对象");return V(t?h(e):e)}function P(e,t,s){let r=s;$(s)&&(r=T(s));let n=new w;Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:()=>(n.depend(t),$(r)&&S(r)?.depend(C),r),set:e=>{e!==r&&($(e)&&(e=T(e)),r=e,k(n,t))}})}const D=Symbol.for("JOKER_SHALLOW_OBSERVER");let _=!1,K=new Map;function k(e,t){if(!1===_)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="数据观察";class L{ob;updateCallBack;forceCallBack;id=u();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;w.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 w.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(),t=this.value;if(this.forceCallBack||e!==t||o(e)){if(this.value=e,e!==t&&!this.forceCallBack&&d(e,t,!0))return;this.updating=!0;try{this.updateCallBack(e,t)}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 I=Symbol.for("JOKER_VNODE_TAG");exports.VNode=void 0,function(e){e.PARSERKEY=Symbol.for("JOKER_PARSER_KEY");class t{parent;[I]=!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?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 j="DOM渲染",M=["script","style","textarea","pre"];let H=0;function Y(e,t,s){return`${e}-${t}-${s}`}function B(e,t,s,r){e._assistEventCache??=[],e._assistEventCache.push([t,s]),document.body.addEventListener(t,s,r)}function J(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){if(e instanceof Element)e.appendChild(this.elements);else if(e instanceof exports.VNode.Component)if(e.parent)if(e.output){let t=e.output,s=z(e)||t.parentNode;s&&s.insertBefore(this.elements,t)}else x.error(j,"组件挂载渲染时发现该节点未定义DOM定位节点",e);else x.error(j,"mount子组件时,发现该组件无父级",e);else x.error(j,"mount只支持挂载到Element或VNode.Node类型数据中",e)}appendNode(e){if(this.renderNode(e),e.output){let t=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];for(let s of t)this.appendNodeChildren(e,s,e.parent)}else x.error(j,"未找自身节点的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&&M.includes(e.parent.tagName)?(this.removeNode(e),this.appendNode(e)):e.output.textContent=R(e.text||""):e instanceof exports.VNode.Html?e.notShadow?e.output.innerHTML=e.html:e.output.root.innerHTML=e.html:x.error(j,`该节点不支持${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&&J(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[o,i]=n;if(o===t){let t=i.modifiers?.includes("self"),a=i.modifiers?.includes("outside");if(t||a){x.warn(j,"事件修饰符:self、outside在组件事件中无法使用,组件无法确认元素",e);continue}let h=s.event;if((h instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(o)||h instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(o))&&!1===F(h,i.modifiers))continue;if(i.callBack(s),i.modifiers?.includes("prevent")&&s.preventDefault(),i.modifiers?.includes("once")&&r.push(n),i.modifiers?.includes("stop"))return s.stopPropagation(),!1}}r.length&&r.forEach((t=>{c(e.events,t)}))}transitionFrame(e,t,s,r,n){X(e,Y(t,s,"from")),r||="transition";let o=e.output.__TRANSITION_EVNETID__=H++;requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(!e.output)return;X(e,Y(t,s,"active")),q(e,Y(t,s,"from")),X(e,Y(t,s,"to"));let i=function(e,t){let s=window.getComputedStyle(e),r=e=>(s[e]||"").split(", ");if("transition"===t){let e=r("transitionDelay"),t=r("transitionDuration"),s=U(e,t);if(s>0)return{timeout:s,count:t.length}}else if("animation"===t){let e=r("animationDelay"),t=r("animationDuration"),s=U(e,t);if(s>0)return{timeout:s,count:t.length}}}(e.output,r);if(!i)return void n?.();let a=0,h=()=>{q(e,Y(t,s,"to")),q(e,Y(t,s,"active")),e.output&&(e.output.removeEventListener(`${r}end`,d),o===e.output.__TRANSITION_EVNETID__&&n?.())},d=t=>{t.target===e.output&&++a>=i.count&&h()};setTimeout((()=>{a<i.count&&h()}),i.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&&M.includes(e.parent.tagName)?e.output=this.parserHtml(e.text):e.output=document.createTextNode(R(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;"svg"===e.tagName||e.parent.isSvg?(e.isSvg=!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"),o=r.modifiers?.includes("outside");n&&o&&(x.warn(j,"事件修饰符:self、outside不可以同时存在,将按照self处理",t),o=!1);let i,a=function(i){if(!(t.sleep||n&&i.target!==e)){if(o){if(i.target===e||e.contains(i.target))return;if(!1===document.contains(i.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(i.target))))return!0}(i instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(s)||i instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(s))&&!1===F(i,r.modifiers)||(r.callBack({eventName:s,event:i,target:t,preventDefault:()=>i.preventDefault(),stopPropagation:()=>i.stopPropagation(),data:void 0}),r.modifiers?.includes("prevent")&&i.preventDefault(),r.modifiers?.includes("stop")&&i.stopPropagation(),r.modifiers?.includes("once")&&(o?J(t,s,a):e.removeEventListener(s,a)))}};r.modifiers?.includes("passive")&&(i={passive:!0}),o?B(t,s,a,i):e.addEventListener(s,a,i)}}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){let r=z(e);if(r)r.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 r=s.output;void 0===r&&x.error(j,"appendNodeChildren挂载失败,找不到父节点DOM输出",{parent:s,node:e}),r.appendChild(t)}else if(this.isCommandGroup(s)){let e=s.output,r=e.parentNode;r&&r.insertBefore(t,e)}else x.error(j,"该节点不支持嵌套子集,请检查。",{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(o(t))for(let s in t)t[s]&&e.push(s);else t&&e.push(t);s=e.join(" ")}else if(o(s)){for(let t in s)s[t]?e.classList.add(t):e.classList.remove(t);return}}else if("style"===t&&o(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:e.setAttribute(t,s)}else s?e.setAttribute(t,""):e.removeAttribute(t)}}}(exports.Render||(exports.Render={}));const G={enter:"enter",backspace:"delete",tab:"tab",arrowup:"up",arrowdown:"down",arrowleft:"left",arrowright:"right",escape:"esc"," ":"space"};function F(e,t){if(e instanceof KeyboardEvent){if(void 0===e.key)return!1;for(let s in G)if(t?.includes(G[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 X(e,t){e.output&&e.output.classList.add(t)}function q(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(j,"appendTo类型不支持",{appendTo:t,node:e})}}}function U(e,t){for(;e.length<t.length;)e.concat(e);return Math.max(...t.map(((t,s)=>Z(t)+Z(e[s]))))}function Z(e){return"auto"===e?0:1e3*Number(e.slice(0,-1).replace(",","."))}class Q extends HTMLElement{root;constructor(){super(),this.root=this.attachShadow({mode:"open"})}}!customElements.get("joker-html-shadow")&&customElements.define("joker-html-shadow",Q);const ee={};const te="Global",se="渲染核心";function re(t){try{return new Function(e.EXPRESSHANDLERTAG,te,`return ${t};`)}catch{throw new Error("创建表达式运行方法时出现未知错误,表达式为"+t)}}class ne{ast;ob;parent;ext;ref="";watchers=[];node;constructor(e,t,s,r){this.ast=e,this.ob=t,this.parent=s,this.ext=r,this.parser(),this.afterParser()}beforeDestroy(e){}destroy(e){if(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.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(){this.parent.childrens&&this.node&&(this.node[exports.VNode.PARSERKEY]=this,this.parent.childrens.push(this.node),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),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 re(e).call(t,t,ee)}catch(s){x.error(se,"运行表达式出现错误:"+e,{ob:t,e:s})}}runExpressWithWatcher(e,t,s,r){let n="string"==typeof e?re(e):e,o=new L((()=>{try{return n.call(t,t,ee)}catch(s){return void x.error(se,"运行表达式出现错误",{ob:t,e:s,express:e,node:this.node})}}),s,void 0,r);return this.addWatch(o),o.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 ne{parser(){this.node=new exports.VNode.Text(this.ast.text,this.parent),this.appendNode()}}class ie extends ne{parser(){this.node=new exports.VNode.Comment(this.ast.text,this.parent),this.appendNode()}}class ae extends ne{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;this.node?.result!==t&&(this.node.result=t,this.reloadAllCondition())}));this.node.result=!!e}this.appendNode(),this.renderConditionChildren()}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,e?this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob):this.destroyChildrens(!0),!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 ae&&t.renderConditionChildren(),e=e.next}}}}class he extends ne{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);P(e,t.letKey,s[t.letKey]);let o=n++;this.renderItem(e,o),this.runExpress(t.step,s),r=!!this.runExpress(t.condition,s),this.runExpressWithWatcher((()=>s[t.letKey]),s,(s=>{e[t.letKey]=s,this.renderItem(e,o)}))}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),o=Array.isArray(t)?Number(r):r;e.indexKey&&P(n,e.indexKey,o),e.itemKey&&P(n,e.itemKey,t[r]);let i=s++;this.renderItem(n,i),e.itemKey&&this.runExpressWithWatcher((()=>t[o]),t,(t=>{n[e.itemKey]=t,this.renderItem(n,i)}))}this.destroyOldChildrens(s)}renderItem(e,t){if(!this.ast.childrens?.length)return;let s=this.node?.childrens?.[t];if(s){if(this.checkObEqual(e,s.ob))return;i(e,((e,t)=>{s.ob[e]!==t&&(s.ob[e]=t)}))}else new de(this.ast,e,this.node,this.ext)}destroyOldChildrens(e){for(;this.node.childrens.length>e;){let e=this.node.childrens.pop();if(!e)break;e[exports.VNode.PARSERKEY]?.destroy(!1)}}checkObEqual(e,t){let s=!0;return void 0!==t&&(i(e,((e,r)=>{t?.[e]!==r&&(s=!1)})),s)}}class de extends ne{parser(){this.node=new exports.VNode.ListItem(this.ob,this.parent),this.appendNode(),this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}}function le(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,o=e[r];n=t?le(o,t):o,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=le(n,t);e instanceof Promise&&s.push(e)}}if(s.length)return Promise.all(s).then((()=>e))}return e}function ce(e,t){if(!e.constructor)return!1;let s=Object.getOwnPropertyDescriptor(e.constructor.prototype,t);return s&&s.get}class pe extends ne{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(te+".")?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=le(e[0]);s instanceof Promise?s.then((e=>{this.changeValue(e)})).catch((e=>{x.error("表达式编译",`${t}异步处理失败`,e)})):this.changeValue(s)}));e||=[];let s=le(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(ue(s),this.parent,e[1]):this.node=new exports.VNode.Text(ue(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=ue(e):this.node.text=ue(e),this.ext.render?.updateNode(this.node))}}function ue(e){return null==e||"function"==typeof e?"":e.toString()}const fe="default";class me extends ne{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)=>{P(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]||fe;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])}))}));return{id:e[0]||fe,params:e.slice(1)}}return{id:fe,params:[]}}}const Ee="组件解析";class ye extends ne{parser(){if(this.ast.node)return this.node=this.ast.node,this.node.parent=this.parent,this.initPropData(),this.appendNode(),void this.node.component?.$mount(this.node);this.node=new exports.VNode.Component(this.parent),this.initPropData(),this.initEvent(),this.appendNode(),this.renderChildren()}get canReload(){return"tagName"in this.ast||"function"==typeof this.ast.component}reload(){this.canReload?(this.beforeDestroy(),this.renderChildren()):x.warn(Ee,"当前组件无法实现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=>{let s=le(t);s instanceof Promise?s.then((t=>{this.node&&(this.node.propValues[e.name]=t,this.notifyNodeWatcher("update",e.name))})).catch((t=>{x.error(Ee,`${e.express}异步处理失败`,t)})):(this.node.propValues[e.name]=s,this.notifyNodeWatcher("update",e.name))})),s=le(t);s instanceof Promise?(this.node.propValues[e.name]=void 0,s.then((t=>{this.node&&(this.node.propValues[e.name]=t)})).catch((t=>{x.error(Ee,`${e.express}异步处理失败`,t)}))):this.node.propValues[e.name]=s}else this.node.propValues[e.name]=e.value;else{if(f(e.value)){x.warn(Ee,"元素的ref值不可以为空");continue}this.ref=e.value,this.ext.addRef(e.value,this.node)}this.node.propValues=T(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:E}]):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(Ee,`${"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]||Ie(this.ast.tagName);if(void 0===e)return void x.error(Ee,`渲染组件失败,未找到名称为'${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)),o=r.condition.startsWith(e.EXPRESSHANDLERTAG+".$sections");if(o){return this.runExpress(r.condition,this.ob)?void s.push(...t.childrens):void 0}if(n&&"if"===r.kind&&!o)return void x.warn(Ee,"在解析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||fe;/^(\'|\")(.*?)((\'|\"))$/.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[fe]=t[fe]||{asts:[],ob:this.ob,parser:this.ext},t[fe].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 Ne="Element解析";class ve extends ne{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=this.runExpressWithWatcher(e.express,this.ob,(t=>{let s=t=>{this.node&&(this.node.attributes[e.name]=this.transformAttrVal(t),this.ext.render?.updateNode(this.node,e.name),this.notifyNodeWatcher("update",e.name))},r=le(t);r instanceof Promise?r.then((e=>{s(e)})).catch((t=>{x.error(Ne,`${e.express}异步处理失败`,t)})):s(r)})),s=le(t);s instanceof Promise?s.then((t=>{this.node&&(this.node.attributes[e.name]=this.transformAttrVal(t),this.ext.render?.updateNode(this.node,e.name))})).catch((t=>{x.error(Ne,`${e.express}异步处理失败`,t)})):this.node.attributes[e.name]=this.transformAttrVal(s)}else this.node.attributes[e.name]=e.value;else{if(f(e.value)){x.warn(Ne,"元素的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 ge{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){t.forEach((t=>{if(t.type===e.AST.NodeType.TEXT)new oe(t,r??this.ob,s,this);else if(t.type===e.AST.NodeType.COMMENT)new ie(t,r??this.ob,s,this);else if(t.type===e.AST.NodeType.COMPONENT)new ye(t,r??this.ob,s,this);else if(t.type===e.AST.NodeType.ELEMENT){let e=t;!function(e,t){return!!t.components[e]||!!Ie(e)}(e.tagName,r??this.ob)?new ve(e,r??this.ob,s,this):new ye(e,r??this.ob,s,this)}else if(t.type===e.AST.NodeType.COMMAND){let e=t;switch(e.cmdName){case"if":case"elseif":case"else":new ae(e,r??this.ob,s,this);break;case"for":new he(e,r??this.ob,s,this);break;case"RenderSection":new me(e,r??this.ob,s,this);break;case"section":break;default:new pe(e,r??this.ob,s,this)}}}))}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 o=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??=o?.name,n??=o?.type,!s)return!1;let i=xe(e);if(i)return"enter"===t?this.render.elementToEnter(i,s,n,(()=>{let t=e[exports.VNode.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-enter"),r?.()})):this.render.elementToLeave(i,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 xe(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:xe(t)}function be(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 Re(e,t,s){let r,n,o;if("symbol"!=typeof t&&(r=m(t)),t in e?n=e[t]:r&&(n=e[r]),s&&(t in s?o=s[t]:r&&r in s&&(o=s[r])),void 0!==o){if(a(o)&&("type"in o||"required"in o||"default"in o||"validate"in o)){let e=o;if(e.required&&void 0===n)throw new Error(`props中key:${t.toString()}是必须项,请检查`);if(e.type&&(n=be(t,n,e.type)),e.validate&&!1===e.validate(n))throw new Error(`props中key${t.toString()}的值校验错误`);n=n??e.default}else n=we(o)?be(t,n,o):n??o;return n}return n}function we(e){return!![String,Array,Number,Object,Function,Boolean].includes(e)||e instanceof Array&&we(e[0])}const Ae="组件",Oe=Symbol.for("JOKER_PROPS_DATA_KEY"),Ce=Symbol.for("JOKER_PROPS_DATA_PROXY"),$e=Symbol.for("JOKER_PRIVATE_WATCHERS"),Ve=Symbol.for("JOKER_EVENT_DATA_KEY"),Se=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;[Oe]={};[Te];[Ce];[$e]=[];[Ve]=new Map;[Se]=!1;[_e]=!1;constructor(e,t={},s){this.$sections=t,this.isKeepAlive=s,this[Oe]=e||{}}get props(){if(void 0===this[Ce]){let e=this;this[Ce]=new Proxy(e[Oe],{get:(t,s)=>Re(e[Oe],s,e.propsOption),set(){throw new Error("props 参数不允许变更,只允许单向数据传递")}})}return this[Ce]}$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)||ce(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}return this.$root=e,this.isKeepAlive&&this.isSleeped?(this.isSleeped=!1,this[Te]&&this.$root?(this[Te].mount(this.$root),this.wakeup(),this.$trigger("wakeup"),this.$rootVNode&&Me(this.$rootVNode),this):(x.error(Ae,"当前组件在唤醒时,发现渲染处理程序已被销毁,无法进行唤醒操作",[this,this.$root]),this)):(this.isSleeped=!1,this.model=T(this.model),this.created(),this.$trigger("created"),this.template&&this.$render(),this.mounted(),this.$trigger("mounted"),this)}$nodeTransition(e,t,s,r,n){if("string"==typeof e){let t=this.$getRef(e);if(!t)return void x.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&&je(this.$rootVNode));for(let e of this[$e])e.destroy();this[$e].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[Ve].clear(),this.$root=void 0,this.isSleeped=!1,this.$sections={},this[Se]=!0,this[Ce]=void 0,this[Oe]={},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)};x.warn(Ae,"该组件还未挂载,不可以进行节点观察监听")}$watch(e,t,s){let r=new L((()=>{if(!this[Se])return e();for(let e of this[$e])e.destroy()}),((e,s)=>{this[Se]||t(e,s)}),void 0,s);return this[$e].push(r),[r.value,()=>{r.destroy(),c(this[$e],r)}]}$on(e,t){let s=this[Ve].get(e);void 0===s&&(s=[],this[Ve].set(e,s)),!1===s?.includes(t)&&s.push(t)}$off(e,t){let s=this[Ve].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[Ve].get(e);n?.length&&[...n].forEach((e=>{e(r)}));let o=this[Ve].get("*");o?.length&&[...o].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 ge(this.template,this,this.$root),this[Te].parser(),this[Te].mount(this.$root))}created(){}mounted(){}beforeDestroy(){}sleeped(){}wakeup(){}destroyed(){}}const We={};function Le(e,t){if("string"==typeof e)t&&(We[e]=t);else for(let t in e)We[t]=e[t]}function Ie(e){return We[e]}function je(e){e.childrens?.forEach((e=>{e instanceof exports.VNode.Component&&e.component?.sleeped(),je(e)}))}function Me(e){e.childrens?.forEach((e=>{e instanceof exports.VNode.Component&&e.component?.wakeup(),Me(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=T(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 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=Ie(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)):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 Ye extends ke{template=function(){return[e.createCommand("RenderSection")]}}Le({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.Component=ke,exports.ComponentContainer=He,exports.Dep=w,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,o=!1;for(;s[r];){let i=s[r],a=await i.callBack({stopPropagation:()=>o=!0,callTimes:n,eventName:e},t);if(i.once?c(s,i):r++,!1===a||o)return!1}}}},exports.JOKER_COMPONENT_TAG=De,exports.JOKER_VNODE_TAG=I,exports.OBJECTPROXY_DEPID=A,exports.PARSER_TEMPLATE_TARGET=Te,exports.ParserTemplate=ge,exports.SCOPE_ID=Pe,exports.ShallowObserver=class{data;[D]=!0;dep=new w;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=L,exports.__GLONAL_FUNTIONS__=ee,exports.__JOKER_HMR_RUNTIME=n,exports.combinedReply=function(e){_=!0;try{e()}catch(e){return _=!1,K.clear(),void x.error("数据劫持","数据劫持组合回复在做变更采集时,遇到了阻塞错误,不做响应,请检查",e)}_=!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=P,exports.getGlobalComponent=Ie,exports.isObserverData=function(e){return void 0!==S(e)},exports.observer=T,exports.registerGlobalComponent=Le,exports.registerGlobalFunction=function(e){for(let t in e)ee[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 o=t.get(e);if(!o)return;let i=Array.from(o);o.clear(),i.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 o(e){return null!==e&&"object"==typeof e}function i(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(!1===l(e[r],t[r],s))return!1;return!0}(e,t,s):l(e,t,s)}function l(e,t,s){let r=o(e),n=o(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 E=(...e)=>{},y="warn";const N=["silent","error","warn","info"];function v(){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 g(e,t,s,r){N.indexOf(e)<=N.indexOf(y)&&(void 0===r?console[e](`${v()} [${t}]:`,s):console[e](`${v()} [${t}]:`,s,r))}let x={info:function(e,t,s){g("info",e,t,s)},warn:function(e,t,s){g("warn",e,t,s)},error:function(e,t,s){g("error",e,t,s)},setLoggerLeve:function(e){y=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{id="production"===process.env.NODE_ENV?"":u();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 $(e){return o(e)&&(Array.isArray(e)||a(e))&&Object.isExtensible(e)&&!Object.isFrozen(e)&&!(e instanceof Element)&&!(I in e)&&!(D in e)&&!(_e in e)}function V(e){if(S(e))return e;let t=Reflect.get(e,C);if(t)return t;let s=new R,r=!0,n=new Proxy(e,{get(e,t,r){if(t===C)return;if(t===A)return s;if(t===O)return;let n=Reflect.get(e,t);return!1===function(e,t){return t in e}(e,t)&&"length"!==t||(s.depend(t),$(n)&&S(n)?.depend(O)),n},set(e,t,n){if(r)return Reflect.set(e,t,n),!0;$(n)&&(n=T(n));let o=!1===function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t),i=Reflect.get(e,t)!==n;return Reflect.set(e,t,n),(i||"length"===t&&Array.isArray(e))&&K(s,t),Array.isArray(e)?"length"===t&&K(s,O):o&&K(s,O),!0},deleteProperty:(e,t)=>(Reflect.deleteProperty(e,t),!1===Array.isArray(e)&&K(s,O),!0)});var o,i,a,h;o=e,i=C,a=n,h=!1,Object.defineProperty(o,i,{value:a,enumerable:h,writable:!0,configurable:!0});for(let t in e){let s=e[t];$(s)&&!S(s)&&(n[t]=V(e[t]))}return r=!1,n}function S(e){if(o(e)){let t=Reflect.get(e,A);if(t)return t}}function T(e,t=!1){if(!1===$(e))throw new Error("当前传入的数据不是正确的数据类型,必须是数组或者对象");return V(t?h(e):e)}function P(e,t,s){let r=s;$(s)&&(r=T(s));let n=new R;Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:()=>(n.depend(t),$(r)&&S(r)?.depend(O),r),set:e=>{e!==r&&($(e)&&(e=T(e)),r=e,K(n,t))}})}const D=Symbol.for("JOKER_SHALLOW_OBSERVER");let _=!1,k=new Map;function K(e,t){if(!1===_)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="数据观察";class L{ob;updateCallBack;forceCallBack;id=u();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(),t=this.value;if(this.forceCallBack||e!==t||o(e)){if(this.value=e,e!==t&&!this.forceCallBack&&d(e,t,!0))return;this.updating=!0;try{this.updateCallBack(e,t)}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 I=Symbol.for("JOKER_VNODE_TAG");exports.VNode=void 0,function(e){e.PARSERKEY=Symbol.for("JOKER_PARSER_KEY");class t{parent;[I]=!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 j="DOM渲染",M=["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){if(e instanceof Element)e.appendChild(this.elements);else if(e instanceof exports.VNode.Component)if(e.parent)if(e.output){let t=e.output,s=U(e)||t.parentNode;s&&s.insertBefore(this.elements,t)}else x.error(j,"组件挂载渲染时发现该节点未定义DOM定位节点",e);else x.error(j,"mount子组件时,发现该组件无父级",e);else x.error(j,"mount只支持挂载到Element或VNode.Node类型数据中",e)}appendNode(e){if(this.renderNode(e),e.output){let t=e.output instanceof HTMLCollection||e.output instanceof NodeList||Array.isArray(e.output)?Array.from(e.output):[e.output];for(let s of t)this.appendNodeChildren(e,s,e.parent)}else x.error(j,"未找自身节点的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&&M.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(j,`该节点不支持${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[o,i]=n;if(o===t){let t=i.modifiers?.includes("self"),a=i.modifiers?.includes("outside");if(t||a){x.warn(j,"事件修饰符:self、outside在组件事件中无法使用,组件无法确认元素",e);continue}let h=s.event;if((h instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(o)||h instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(o))&&!1===X(h,i.modifiers))continue;if(i.callBack(s),i.modifiers?.includes("prevent")&&s.preventDefault(),i.modifiers?.includes("once")&&r.push(n),i.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 o=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 i=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(!i)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),o===e.output.__TRANSITION_EVNETID__&&n?.())},d=t=>{t.target===e.output&&++a>=i.count&&h()};setTimeout((()=>{a<i.count&&h()}),i.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&&M.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,t.style.display="inline-block",e.output=t}else{let t=document.createElement("joker-html-shadow");t.JOKER_NODE=e,t.style.lineHeight="1",t.style.display="inline-block",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"),o=r.modifiers?.includes("outside");n&&o&&(x.warn(j,"事件修饰符:self、outside不可以同时存在,将按照self处理",t),o=!1);let i,a=function(i){if(!(t.sleep||n&&i.target!==e)){if(o){if(i.target===e||e.contains(i.target))return;if(!1===document.contains(i.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(i.target))))return!0}(i instanceof KeyboardEvent&&["keydown","keypress","keyup"].includes(s)||i instanceof MouseEvent&&["click","dbclick","mouseup","mousedown"].includes(s))&&!1===X(i,r.modifiers)||(r.callBack({eventName:s,event:i,target:t,preventDefault:()=>i.preventDefault(),stopPropagation:()=>i.stopPropagation(),data:void 0}),r.modifiers?.includes("prevent")&&i.preventDefault(),r.modifiers?.includes("stop")&&i.stopPropagation(),r.modifiers?.includes("once")&&(o?G(t,s,a):e.removeEventListener(s,a)))}};r.modifiers?.includes("passive")&&(i={passive:!0}),o?J(t,s,a,i):e.addEventListener(s,a,i)}}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){let r=U(e);if(r)r.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 r=s.output;void 0===r&&x.error(j,"appendNodeChildren挂载失败,找不到父节点DOM输出",{parent:s,node:e}),r.appendChild(t)}else if(this.isCommandGroup(s)){let e=s.output,r=e.parentNode;r&&r.insertBefore(t,e)}else x.error(j,"该节点不支持嵌套子集,请检查。",{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(o(t))for(let s in t)t[s]&&e.push(s);else t&&e.push(t);s=e.join(" ")}else if(o(s)){for(let t in s)s[t]?e.classList.add(t):e.classList.remove(t);return}}else if("style"===t&&o(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 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}x.warn(j,"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 oe{ast;ob;parent;ext;ref="";watchers=[];node;constructor(e,t,s,r){this.ast=e,this.ob=t,this.parent=s,this.ext=r,this.parser(),this.afterParser()}beforeDestroy(e){}destroy(e){if(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.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(){this.parent.childrens&&this.node&&(this.node[exports.VNode.PARSERKEY]=this,this.parent.childrens.push(this.node),this.node instanceof exports.VNode.Element&&this.ob[De]&&(this.node.attributes["data-scoped-"+this.ob[De]]=void 0),this.ext.render?.appendNode(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){x.error(re,"运行表达式出现错误:"+e,{ob:t,e:s})}}runExpressWithWatcher(e,t,s,r){let n="string"==typeof e?ne(e):e,o=new L((()=>{try{return n.call(t,t,te)}catch(s){return void x.error(re,"运行表达式出现错误",{ob:t,e:s,express:e,node:this.node})}}),s,void 0,r);return this.addWatch(o),o.value}addWatch(e){!1===this.watchers.includes(e)&&this.watchers.push(e)}clearWatchers(){this.watchers.forEach((e=>{e.destroy()})),this.watchers.length=0}}class ie extends oe{parser(){this.node=new exports.VNode.Text(this.ast.text,this.parent),this.appendNode()}}class ae extends oe{parser(){this.node=new exports.VNode.Comment(this.ast.text,this.parent),this.appendNode()}}class he extends oe{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;this.node?.result!==t&&(this.node.result=t,this.reloadAllCondition())}));this.node.result=!!e}this.appendNode(),this.renderConditionChildren()}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,e?this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob):this.destroyChildrens(!0),!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}}}}class de extends oe{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);P(e,t.letKey,s[t.letKey]);let o=n++;this.renderItem(e,o),this.runExpress(t.step,s),r=!!this.runExpress(t.condition,s),this.runExpressWithWatcher((()=>s[t.letKey]),s,(s=>{e[t.letKey]=s,this.renderItem(e,o)}))}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),o=Array.isArray(t)?Number(r):r;e.indexKey&&P(n,e.indexKey,o),e.itemKey&&P(n,e.itemKey,t[r]);let i=s++;this.renderItem(n,i),e.itemKey&&this.runExpressWithWatcher((()=>t[o]),t,(t=>{n[e.itemKey]=t,this.renderItem(n,i)}))}this.destroyOldChildrens(s)}renderItem(e,t){if(!this.ast.childrens?.length)return;let s=this.node?.childrens?.[t];if(s){if(this.checkObEqual(e,s.ob))return;i(e,((e,t)=>{s.ob[e]!==t&&(s.ob[e]=t)}))}else new le(this.ast,e,this.node,this.ext)}destroyOldChildrens(e){for(;this.node.childrens.length>e;){let e=this.node.childrens.pop();if(!e)break;e[exports.VNode.PARSERKEY]?.destroy(!1)}}checkObEqual(e,t){let s=!0;return void 0!==t&&(i(e,((e,r)=>{t?.[e]!==r&&(s=!1)})),s)}}class le extends oe{parser(){this.node=new exports.VNode.ListItem(this.ob,this.parent),this.appendNode(),this.ast.childrens&&this.ext.parserNodes(this.ast.childrens,this.node,this.ob)}}function ce(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,o=e[r];n=t?ce(o,t):o,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=ce(n,t);e instanceof Promise&&s.push(e)}}if(s.length)return Promise.all(s).then((()=>e))}return e}function pe(e,t){if(!e.constructor)return!1;let s=Object.getOwnPropertyDescriptor(e.constructor.prototype,t);return s&&s.get}class ue extends oe{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(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=>{let s=ce(e[0]);s instanceof Promise?s.then((e=>{this.changeValue(e)})).catch((e=>{x.error("表达式编译",`${t}异步处理失败`,e)})):this.changeValue(s)}));e||=[];let s=ce(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(fe(s),this.parent,e[1]):this.node=new exports.VNode.Text(fe(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=fe(e):this.node.text=fe(e),this.ext.render?.updateNode(this.node))}}function fe(e){return null==e||"function"==typeof e?"":e.toString()}const me="default";class Ee extends oe{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)=>{P(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]||me;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])}))}));return{id:e[0]||me,params:e.slice(1)}}return{id:me,params:[]}}}const ye="组件解析";class Ne extends oe{parser(){if(this.ast.node)return this.node=this.ast.node,this.node.parent=this.parent,this.initPropData(),this.appendNode(),void this.node.component?.$mount(this.node);this.node=new exports.VNode.Component(this.parent),this.initPropData(),this.initEvent(),this.appendNode(),this.renderChildren()}get canReload(){return"tagName"in this.ast||"function"==typeof this.ast.component}reload(){this.canReload?(this.beforeDestroy(),this.renderChildren()):x.warn(ye,"当前组件无法实现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=>{let s=ce(t);s instanceof Promise?s.then((t=>{this.node&&(this.node.propValues[e.name]=t,this.notifyNodeWatcher("update",e.name))})).catch((t=>{x.error(ye,`${e.express}异步处理失败`,t)})):(this.node.propValues[e.name]=s,this.notifyNodeWatcher("update",e.name))})),s=ce(t);s instanceof Promise?(this.node.propValues[e.name]=void 0,s.then((t=>{this.node&&(this.node.propValues[e.name]=t)})).catch((t=>{x.error(ye,`${e.express}异步处理失败`,t)}))):this.node.propValues[e.name]=s}else this.node.propValues[e.name]=e.value;else{if(f(e.value)){x.warn(ye,"元素的ref值不可以为空");continue}this.ref=e.value,this.ext.addRef(e.value,this.node)}this.node.propValues=T(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:E}]):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(ye,`${"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]||je(this.ast.tagName);if(void 0===e)return void x.error(ye,`渲染组件失败,未找到名称为'${this.ast.tagName}'的私有组件/全局组件`);if(_e 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)),o=r.condition.startsWith(e.EXPRESSHANDLERTAG+".$sections");if(o){return this.runExpress(r.condition,this.ob)?void s.push(...t.childrens):void 0}if(n&&"if"===r.kind&&!o)return void x.warn(ye,"在解析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||me;/^(\'|\")(.*?)((\'|\"))$/.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[me]=t[me]||{asts:[],ob:this.ob,parser:this.ext},t[me].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 ve="Element解析";class ge extends oe{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=this.runExpressWithWatcher(e.express,this.ob,(t=>{let s=t=>{this.node&&(this.node.attributes[e.name]=this.transformAttrVal(t),this.ext.render?.updateNode(this.node,e.name),this.notifyNodeWatcher("update",e.name))},r=ce(t);r instanceof Promise?r.then((e=>{s(e)})).catch((t=>{x.error(ve,`${e.express}异步处理失败`,t)})):s(r)})),s=ce(t);s instanceof Promise?s.then((t=>{this.node&&(this.node.attributes[e.name]=this.transformAttrVal(t),this.ext.render?.updateNode(this.node,e.name))})).catch((t=>{x.error(ve,`${e.express}异步处理失败`,t)})):this.node.attributes[e.name]=this.transformAttrVal(s)}else this.node.attributes[e.name]=e.value;else{if(f(e.value)){x.warn(ve,"元素的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 xe{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){t.forEach((t=>{if(t.type===e.AST.NodeType.TEXT)new ie(t,r??this.ob,s,this);else if(t.type===e.AST.NodeType.COMMENT)new ae(t,r??this.ob,s,this);else if(t.type===e.AST.NodeType.COMPONENT)new Ne(t,r??this.ob,s,this);else if(t.type===e.AST.NodeType.ELEMENT){let e=t;!function(e,t){return!!t.components[e]||!!je(e)}(e.tagName,r??this.ob)?new ge(e,r??this.ob,s,this):new Ne(e,r??this.ob,s,this)}else if(t.type===e.AST.NodeType.COMMAND){let e=t;switch(e.cmdName){case"if":case"elseif":case"else":new he(e,r??this.ob,s,this);break;case"for":new de(e,r??this.ob,s,this);break;case"RenderSection":new Ee(e,r??this.ob,s,this);break;case"section":break;default:new ue(e,r??this.ob,s,this)}}}))}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 o=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??=o?.name,n??=o?.type,!s)return!1;let i=be(e);if(i)return"enter"===t?this.render.elementToEnter(i,s,n,(()=>{let t=e[exports.VNode.PARSERKEY];t&&t.ref&&this.notifyNodeWatcher(t.ref,e,"after-enter"),r?.()})):this.render.elementToLeave(i,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 be(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:be(t)}function we(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 Re(e,t,s){let r,n,o;if("symbol"!=typeof t&&(r=m(t)),t in e?n=e[t]:r&&(n=e[r]),s&&(t in s?o=s[t]:r&&r in s&&(o=s[r])),void 0!==o){if(a(o)&&("type"in o||"required"in o||"default"in o||"validate"in o)){let e=o;if(e.required&&void 0===n)throw new Error(`props中key:${t.toString()}是必须项,请检查`);if(e.type&&(n=we(t,n,e.type)),e.validate&&!1===e.validate(n))throw new Error(`props中key${t.toString()}的值校验错误`);n=n??e.default}else n=Ae(o)?we(t,n,o):n??o;return n}return n}function Ae(e){return!![String,Array,Number,Object,Function,Boolean].includes(e)||e instanceof Array&&Ae(e[0])}const Ce="组件",Oe=Symbol.for("JOKER_PROPS_DATA_KEY"),$e=Symbol.for("JOKER_PROPS_DATA_PROXY"),Ve=Symbol.for("JOKER_PRIVATE_WATCHERS"),Se=Symbol.for("JOKER_EVENT_DATA_KEY"),Te=Symbol.for("JOKER_IS_DESTROY"),Pe=Symbol.for("JOKER_PARSER_TEMPLATE_TARGET"),De=Symbol.for("JOKER_SCOPE_ID"),_e=Symbol.for("JOKER_COMPONENT_TAG"),ke=Symbol();let Ke=["constructor","$mount","$nodeTransition","$destroy","$getRef","$getRefs","$syncProp","$watchNode","$watch","$on","$off","$trigger","$render","created","mounted","beforeDestroy","sleeped","wakeup","destroyed"];class We{$sections;isKeepAlive;static[_e]=!0;[De];model={};template;$root;isSleeped=!1;components={};propsOption;[Oe]={};[Pe];[$e];[Ve]=[];[Se]=new Map;[Te]=!1;[ke]=!1;constructor(e,t={},s){this.$sections=t,this.isKeepAlive=s,this[Oe]=e||{}}get props(){if(void 0===this[$e]){let e=this;this[$e]=new Proxy(e[Oe],{get:(t,s)=>Re(e[Oe],s,e.propsOption),set(){throw new Error("props 参数不允许变更,只允许单向数据传递")}})}return this[$e]}$mount(e){if(!1===this[ke]){let e=()=>{let e=[],t=Object.getPrototypeOf(this);for(;null!==t&&t!==Object.prototype;)Object.getOwnPropertyNames(t).forEach((s=>{!1!==Ke.includes(s)||pe(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[ke]=!0}return this.$root=e,this.isKeepAlive&&this.isSleeped?(this.isSleeped=!1,this[Pe]&&this.$root?(this[Pe].mount(this.$root),this.wakeup(),this.$trigger("wakeup"),this.$rootVNode&&He(this.$rootVNode),this):(x.error(Ce,"当前组件在唤醒时,发现渲染处理程序已被销毁,无法进行唤醒操作",[this,this.$root]),this)):(this.isSleeped=!1,this.model=T(this.model),this.created(),this.$trigger("created"),this.template&&this.$render(),this.mounted(),this.$trigger("mounted"),this)}$nodeTransition(e,t,s,r,n){if("string"==typeof e){let t=this.$getRef(e);if(!t)return void x.error(Ce,`执行节点动画是找不到ref=${e}的节点`);e=t}this[Pe]?.nodeTransition(e,t,s,r,n)}$destroy(e){if(!e&&this.isKeepAlive)return this[Pe]?.sleep(),this.isSleeped=!0,this.sleeped(),this.$trigger("sleeped"),void(this.$rootVNode&&Me(this.$rootVNode));for(let e of this[Ve])e.destroy();this[Ve].length=0,this[Pe]?.destroyWathcers(),this.beforeDestroy(),this.$trigger("beforeDestroy"),this[Pe]?.destroy(),this[Pe]=void 0,this.template&&Array.isArray(this.template)&&(this.template.length=0),this.$trigger("destroy"),this[Se].clear(),this.$root=void 0,this.isSleeped=!1,this.$sections={},this[Te]=!0,this[$e]=void 0,this[Oe]={},this.destroyed()}get $refs(){return this[Pe]?.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[Pe]?.root}$watchNode(e,t){if(this[Pe])return this[Pe]?.addNodeWatcher(e,t),()=>{this[Pe]?.removeNodeWatcher(e,t)};x.warn(Ce,"该组件还未挂载,不可以进行节点观察监听")}$watch(e,t,s){let r=new L((()=>{if(!this[Te])return e();for(let e of this[Ve])e.destroy()}),((e,s)=>{this[Te]||t(e,s)}),void 0,s);return this[Ve].push(r),[r.value,()=>{r.destroy(),c(this[Ve],r)}]}$on(e,t){let s=this[Se].get(e);void 0===s&&(s=[],this[Se].set(e,s)),!1===s?.includes(t)&&s.push(t)}$off(e,t){let s=this[Se].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[Pe]?.render.triggerEvent(this.$rootVNode.parent,e,r))return;let n=this[Se].get(e);n?.length&&[...n].forEach((e=>{e(r)}));let o=this[Se].get("*");o?.length&&[...o].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[Pe]?.reSetAsts(this.template,s),this[Pe]??=new xe(this.template,this,this.$root),this[Pe].parser(),this[Pe].mount(this.$root))}created(){}mounted(){}beforeDestroy(){}sleeped(){}wakeup(){}destroyed(){}}const Le={};function Ie(e,t){if("string"==typeof e)t&&(Le[e]=t);else for(let t in e)Le[t]=e[t]}function je(e){return Le[e]}function Me(e){e.childrens?.forEach((e=>{e instanceof exports.VNode.Component&&e.component?.sleeped(),Me(e)}))}function He(e){e.childrens?.forEach((e=>{e instanceof exports.VNode.Component&&e.component?.wakeup(),He(e)}))}class Ye extends We{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=T(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 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=je(t)),n?(_e 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)):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 Be extends We{template=function(){return[e.createCommand("RenderSection")]}}Ie({template:Be,component:Ye});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.Component=We,exports.ComponentContainer=Ye,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,o=!1;for(;s[r];){let i=s[r],a=await i.callBack({stopPropagation:()=>o=!0,callTimes:n,eventName:e},t);if(i.once?c(s,i):r++,!1===a||o)return!1}}}},exports.JOKER_COMPONENT_TAG=_e,exports.JOKER_VNODE_TAG=I,exports.OBJECTPROXY_DEPID=A,exports.PARSER_TEMPLATE_TARGET=Pe,exports.ParserTemplate=xe,exports.SCOPE_ID=De,exports.ShallowObserver=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,K(this.dep,O))}},exports.Template=Be,exports.Watcher=L,exports.__GLONAL_FUNTIONS__=te,exports.__JOKER_HMR_RUNTIME=n,exports.combinedReply=function(e){_=!0;try{e()}catch(e){return _=!1,k.clear(),void x.error("数据劫持","数据劫持组合回复在做变更采集时,遇到了阻塞错误,不做响应,请检查",e)}_=!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=P,exports.getGlobalComponent=je,exports.isObserverData=function(e){return void 0!==S(e)},exports.observer=T,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.2.237",
3
+ "version": "1.2.246",
4
4
  "description": "",
5
5
  "main": "./dist/bundle.js",
6
6
  "module": "./dist/bundle.es.js",
@@ -149,8 +149,8 @@ export declare namespace VNode {
149
149
  * 当前组件第一个element vnode
150
150
  */
151
151
  get firstElement(): Element | undefined;
152
- /** 获取根element 节点 */
153
- get rootElements(): Element[];
152
+ /** 获取根element 节点 包含VNode.Html */
153
+ get rootElements(): (Element | Html)[];
154
154
  }
155
155
  /**
156
156
  * 条件节点