rumious 0.0.10 → 0.0.12

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.
@@ -1 +1 @@
1
- "use strict";class e{constructor(e){this.target=e,this.app=e.app,this.hooks={onRendered:[],onBeforeRender:[]}}find(e){return this.target[e]}get(e){return this.target[e]}addHook(e,t){if(!this.hooks[e])throw new Error(`Hook type "${e}" is not defined!`);this.hooks[e].push(t)}async runHooks(e,...t){if(this.hooks[e])for(const n of this.hooks[e])await n(...t)}}class t{constructor(){this.renderOptions={mode:"linear"},this.element=null,this.app=null,this.props={},this.forwardRefs={},this.renderContext=new e(this),this.renderer=null,this.wrapped=null}prepare(e,t,n={},r=null){this.element=e,this.props=t,this.renderer=r,this.wrapped=n,this.renderContext.app=this.app}template(){return{}}render(e){return this.renderer(e,document.createDocumentFragment(),this.renderContext)}requestRender(){let e=this.template(),t=this.renderer(e,document.createDocumentFragment(),this.renderContext);this.element.appendChild(t),this.onRender()}async requestCleanUp(){if(this.element){let e=this.element.cloneNode(!0);for(this.element.replaceWith(e),this.element=e;this.element.firstChild;)this.element.removeChild(this.element.firstChild)}}onInit(){}onCreate(){}onRender(){}onUpdate(){}onDestroy(){}}function n(e){return Object.getPrototypeOf(e)===t}class r{constructor(e,t,n=[]){this.type=e,this.props=t,this.children=n}}class o{constructor(e){this.type="ELEMENT_LIST",this.children=e}forEach(e){this.children.forEach(e)}}function i(e){return"function"==typeof e}class s{constructor(e,t,n){this.type=e,this.name=t,this.value=n}init(){}}class a extends s{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return null;const n=t.get(e);if(!i(n))throw new Error(`${e} is not a function!`);return n.bind(t.target)};if("string"===this.value.type)n=r(this.value.value);else if("expression"===this.value.type){if(n=this.value.value,!i(n))throw new Error("Event handler requires a function!")}else"dynamic_value"===this.value.type&&(n=r(this.value.value.objectName));n&&e.addEventListener(this.name,n)}}class l extends s{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");t.reactor.addBinding((()=>{let n=t.get();this.bindAttr(e,n)})),this.bindAttr(e,t.get())}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target),r=t.find(this.value.value.objectName);if(!r)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");r.reactor.addBinding((()=>{let n=this.value.evaluator?.(t.target);this.bindAttr(e,n)})),this.bindAttr(e,n)}}normalizeValue(e){return"object"==typeof e?e.toString?.()??"":e}async bindAttr(e,t){switch(this.name){case"html":e.innerHTML=this.normalizeValue(t);break;case"text":e.textContent=this.normalizeValue(t);break;case"show":e.style.display=this.normalizeValue(t)?"block":"none";break;case"hide":e.style.display=this.normalizeValue(t)?"none":"block";break;case"className":e.className=this.normalizeValue(t);break;case"style":Object.assign(e.style,t);break;case"disabled":e.disabled=!!this.normalizeValue(t);break;case"visible":e.style.visibility=this.normalizeValue(t)?"visible":"hidden";break;case"value":e.value=this.normalizeValue(t);break;case"checked":e.checked=this.normalizeValue(t);break;default:e.setAttribute(this.name,this.normalizeValue(t))}}}class c extends s{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");n.set(e)}}}class u extends s{async init(e,t){let n;"expression"===this.value.type?n=this.value.value:"dynamic_value"===this.value.type&&(n=t.find(this.value.value.objectName));const r=()=>{"checkbox"===e.type?n.set(e.checked):"radio"===e.type?e.checked&&n.set(e.value):n.set(e.value)};e.addEventListener("input",r),e.addEventListener("change",r)}}class p extends s{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");n.set(e)}}}const h={on:(e,t)=>new a("on",e,t),bind:(e,t)=>new l("bind",e,t),ref:(e,t)=>new c("ref",e,t),childsRef:(e,t)=>new p("childsRef",e,t),model:(e,t)=>new u("model",e,t)};function f(e,t,n){return function(e,t,n){return h[e]?.(t,n)}(e,t,n)}function d(e,t,...o){return n(e)?g(e,t,o):e===v?v(...o):new r(e,t||{},m(o))}function y(e){return new r("TEXT_ELEMENT",{nodeValue:e},[])}function g(e,t,n){let i=new r("COMPONENT",{...t},new o(m(n)));return i.component=e,i}function v(...e){return new r("FRAGMENT",{},m(e))}function m(e){return e.map((e=>"object"==typeof e?e:y(e)))}window.RUMIOUS_JSX_SUPPORT={createElement:d,createFragment:v,createDirective:f};class b extends HTMLElement{constructor(){super(),this.instance=null,this.ref=null}cleanUp(){Object.setPrototypeOf(this,HTMLUnknownElement.prototype),this.remove()}init(e,t,n={},r,o){this.instance=new e,this.instance.element=this,this.instance.app=o,this.instance.prepare(this,t,n,r),this.instance.onInit()}connectedCallback(){switch(this.instance.renderOptions.mode){case"linear":this.instance.onCreate(),this.instance.requestRender();break;case"async":(async()=>{this.instance.onCreate(),this.instance.requestRender()})();break;case"animate":requestAnimationFrame((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"idle":requestIdleCallback((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"defer":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),0);break;case"delay":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),this.instance.renderOptions.time);break;case"visible":new IntersectionObserver(((e,t)=>{for(const n of e)n.isIntersecting&&(t.disconnect(),this.instance.onCreate(),this.instance.requestRender())})).observe(this)}}disconnectedCallback(){this.instance.onDestroy(),this.instance.requestCleanUp(),this.cleanUp()}}function w(e="r-component"){return window.customElements.get(e)||window.customElements.define(e,class extends b{static tag=e}),document.createElement(e)}class O{constructor(){this.contents=[],this.targets=[],this.observers=new WeakMap}commit(e=[]){this.contents=e}setTarget(e,t,n){this.targets.push({element:e,context:n,renderer:t}),this.observeTarget(e)}observeTarget(e){if(this.observers.has(e))return;const t=new MutationObserver((()=>{e.parentNode||this.removeTarget(e)}));t.observe(document.body,{childList:!0}),this.observers.set(e,t)}removeTarget(e){const t=this.observers.get(e);t&&(t.disconnect(),this.observers.delete(e)),this.targets=this.targets.filter((t=>t.element!==e))}inject(e=!1){for(let t of this.targets)e&&(t.element.textContent=""),this.contents.forEach((e=>{"html"===e.type?t.element.innerHTML=e.value:"text"===e.type?t.element.textContent=e.value:"component"===e.type&&t.renderer(d(e.value,e.props??{},e.child??{}),t.element,t.context)}))}}function x(e,t,n={}){if(!e)return t;if(null===(o=e)||"object"!=typeof o&&"function"!=typeof o)return x(y(e),t,n);var o;if(Array.isArray(e)){for(const r of e)x(r,t,n);return t}if(e instanceof r){let r;switch(e.type){case"COMPONENT":return function(e,t,n,r){const o=function(e,t,n,r,o=null){const i=w(e.tag??"r-component");return i.init(e,t,n,r,o?.app),i}(e.component,e.props,e.children,n,r);return t.appendChild(o),t}(e,t,x,n);case"FRAGMENT":case"ELEMENT_LIST":for(const r of e.children)x(r,t,n);return t;case"TEXT_ELEMENT":r=function(e){return document.createTextNode(e.props.nodeValue)}(e);break;default:r=function(e,t){const n=document.createElement(e.type);!function(e,t,n){for(const[r,o]of Object.entries(t||{}))o instanceof s?o.init(e,n):r.startsWith("on")&&/^[a-zA-Z]+([A-Z][a-z]*)*$/.test(r)?e.addEventListener(r.substring(2).toLowerCase(),o):e.setAttribute(r,o)}(n,e.props,t);for(const r of e.children)x(r,n,t);return n}(e,n)}return t.appendChild(r),t}if(e instanceof HTMLElement)return t.appendChild(e),t;if(e instanceof O){if(t instanceof HTMLDocument)throw"Rumious Render: Unsupported inject content in HTMLDocument!";return e.setTarget(t,x,n),e.inject(!0),t}return x(y(JSON.stringify(e)),t,n)}class k{constructor(e=null,t=[]){this.target=e,this.bindings=t}react(){this.bindings.forEach((e=>e()))}removeBinding(e){for(let t=this.bindings.length-1;t>=0;t--)this.bindings[t]===e&&this.bindings.splice(t,1)}addBinding(e){this.bindings.push(e)}}class E{constructor(e,t="",n){this.state=e,this.path=t,this.fn=n}trigger(...e){let t=this.fn(...e);this.state.set(this.path,t)}}const M="remove",R="replace",j="add",S=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),C=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),T=Symbol.iterator,A={mutable:"mutable",immutable:"immutable"},P={};function z(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function D(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const e=Reflect.getOwnPropertyDescriptor(n,t);if(e)return e;n=Reflect.getPrototypeOf(n)}}}function I(e){return Object.getPrototypeOf(e)===Set.prototype}function L(e){return Object.getPrototypeOf(e)===Map.prototype}function N(e){var t;return null!==(t=e.copy)&&void 0!==t?t:e.original}function _(e){return!!q(e)}function q(e){return"object"!=typeof e?null:null==e?void 0:e[S]}function V(e){var t;const n=q(e);return n?null!==(t=n.copy)&&void 0!==t?t:n.original:e}function U(e,t){if(!e||"object"!=typeof e)return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!(null==t?void 0:t.mark)&&((n=t.mark(e,A))===A.immutable||"function"==typeof n)}function F(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,r=q($(n,e.key));if(null!==r&&(null==r?void 0:r.original)!==e.original)return null;const o=3===e.parent.type,i=o?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(o&&n.size>i||z(n,i)))return null;t.push(i)}if(e.parent)return F(e.parent,t);t.reverse();try{!function(e,t){for(let n=0;n<t.length-1;n+=1){const r=t[n];if("object"!=typeof(e=$(3===H(e)?Array.from(e):e,r)))throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}}(e.copy,t)}catch(e){return null}return t}function H(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function $(e,t){return 2===H(e)?e.get(t):e[t]}function B(e,t,n){2===H(e)?e.set(t,n):e[t]=n}function W(e,t){const n=q(e);return(n?N(n):e)[t]}function X(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function K(e){if(e)for(;e.finalities.revoke.length>0;)e.finalities.revoke.pop()()}function Y(e,t){return t?e:[""].concat(e).map((e=>{const t=`${e}`;return-1===t.indexOf("/")&&-1===t.indexOf("~")?t:t.replace(/~/g,"~0").replace(/\//g,"~1")})).join("/")}const Z=Object.prototype.propertyIsEnumerable;function G(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set)return I(e)?Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values()):new(0,Object.getPrototypeOf(e).constructor)(e.values());if(e instanceof Map)return L(e)?new Map(e):new(0,Object.getPrototypeOf(e).constructor)(e);if((null==t?void 0:t.mark)&&(n=t.mark(e,A),void 0!==n)&&n!==A.mutable){if(n===A.immutable)return function(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((n=>{let r=Reflect.getOwnPropertyDescriptor(e,n);r.enumerable&&r.configurable&&r.writable?t[n]=e[n]:(r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:e[n]}),Reflect.defineProperty(t,n,r))})),t}(e);if("function"==typeof n){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return n()}throw new Error(`Unsupported mark result: ${n}`)}if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype){const t={};return Object.keys(e).forEach((n=>{t[n]=e[n]})),Object.getOwnPropertySymbols(e).forEach((n=>{Z.call(e,n)&&(t[n]=e[n])})),t}throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function J(e){e.copy||(e.copy=G(e.original,e.options))}function Q(e){if(!U(e))return V(e);if(Array.isArray(e))return e.map(Q);if(e instanceof Map){const t=Array.from(e.entries()).map((([e,t])=>[e,Q(t)]));return L(e)?new Map(t):new(0,Object.getPrototypeOf(e).constructor)(t)}if(e instanceof Set){const t=Array.from(e).map(Q);return I(e)?new Set(t):new(0,Object.getPrototypeOf(e).constructor)(t)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=Q(e[n]);return t}function ee(e){return _(e)?Q(e):e}function te(e){var t;e.assignedMap=null!==(t=e.assignedMap)&&void 0!==t?t:new Map,e.operated||(e.operated=!0,e.parent&&te(e.parent))}function ne(){throw new Error("Cannot modify frozen object")}function re(e,t,n,r,o){{n=null!=n?n:new WeakMap,r=null!=r?r:[],o=null!=o?o:[];const i=n.has(e)?n.get(e):e;if(r.length>0){const e=r.indexOf(i);if(i&&"object"==typeof i&&-1!==e){if(r[0]===i)throw new Error("Forbids circular reference");throw new Error(`Forbids circular reference: ~/${o.slice(0,e).map(((e,t)=>{if("symbol"==typeof e)return`[${e.toString()}]`;const n=r[t];return"object"==typeof e&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(e):e})).join("/")}`)}r.push(i),o.push(t)}else r.push(i)}if(Object.isFrozen(e)||_(e))return r.pop(),void o.pop();switch(H(e)){case 2:for(const[t,i]of e)re(t,t,n,r,o),re(i,t,n,r,o);e.set=e.clear=e.delete=ne;break;case 3:for(const t of e)re(t,t,n,r,o);e.add=e.clear=e.delete=ne;break;case 1:Object.freeze(e);let t=0;for(const i of e)re(i,t,n,r,o),t+=1;break;default:Object.freeze(e),Object.keys(e).forEach((t=>{re(e[t],t,n,r,o)}))}r.pop(),o.pop()}function oe(e,t){const n=H(e);if(0===n)Reflect.ownKeys(e).forEach((n=>{t(n,e[n],e)}));else if(1===n){let n=0;for(const r of e)t(n,r,e),n+=1}else e.forEach(((n,r)=>t(r,n,e)))}function ie(e,t,n){if(_(e)||!U(e,n)||t.has(e)||Object.isFrozen(e))return;const r=e instanceof Set,o=r?new Map:void 0;if(t.add(e),oe(e,((i,s)=>{var a;if(_(s)){const t=q(s);J(t);const n=(null===(a=t.assignedMap)||void 0===a?void 0:a.size)||t.operated?t.copy:t.original;B(r?o:e,i,n)}else ie(s,t,n)})),o){const t=e,n=Array.from(t);t.clear(),n.forEach((e=>{t.add(o.has(e)?o.get(e):e)}))}}function se(e,t){const n=3===e.type?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&ie($(n,t),e.finalities.handledSet,e.options)}function ae(e){3===e.type&&e.copy&&(e.copy.clear(),e.setMap.forEach((t=>{e.copy.add(V(t))})))}function le(e,t,n,r){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&r){const o=F(e);o&&t(e,o,n,r)}e.finalized=!0}}function ce(e,t,n,r){const o=q(n);o&&(o.callbacks||(o.callbacks=[]),o.callbacks.push(((i,s)=>{var a;const l=3===e.type?e.setMap:e.copy;if(X($(l,t),n)){let n=o.original;o.copy&&(n=o.copy),ae(e),le(e,r,i,s),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(a=e.options.updatedValues)&&void 0!==a?a:new WeakMap,e.options.updatedValues.set(n,o.original)),B(l,t,n)}})),e.options.enableAutoFreeze&&o.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),U(n,e.options)&&e.finalities.draft.push((()=>{X($(3===e.type?e.setMap:e.copy,t),n)&&se(e,t)}))}function ue(e,t,n,r){const{pathAsArray:o=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return function({original:e,copy:t,assignedMap:n},r,o,i,s){n.forEach(((n,a)=>{const l=$(e,a),c=ee($(t,a)),u=n?z(e,a)?R:j:M;if(X(l,c)&&u===R)return;const p=Y(r.concat(a),s);o.push(u===M?{op:u,path:p}:{op:u,path:p,value:c}),i.push(u===j?{op:M,path:p}:u===M?{op:j,path:p,value:l}:{op:R,path:p,value:l})}))}(e,t,n,r,o);case 1:return function(e,t,n,r,o){let{original:i,assignedMap:s,options:a}=e,l=e.copy;l.length<i.length&&([i,l]=[l,i],[n,r]=[r,n]);for(let e=0;e<i.length;e+=1)if(s.get(e.toString())&&l[e]!==i[e]){const s=Y(t.concat([e]),o);n.push({op:R,path:s,value:ee(l[e])}),r.push({op:R,path:s,value:ee(i[e])})}for(let e=i.length;e<l.length;e+=1){const r=Y(t.concat([e]),o);n.push({op:j,path:r,value:ee(l[e])})}if(i.length<l.length){const{arrayLengthAssignment:e=!0}=a.enablePatches;if(e){const e=Y(t.concat(["length"]),o);r.push({op:R,path:e,value:i.length})}else for(let e=l.length;i.length<e;e-=1){const n=Y(t.concat([e-1]),o);r.push({op:M,path:n})}}}(e,t,n,r,o);case 3:return function({original:e,copy:t},n,r,o,i){let s=0;e.forEach((e=>{if(!t.has(e)){const t=Y(n.concat([s]),i);r.push({op:M,path:t,value:e}),o.unshift({op:j,path:t,value:e})}s+=1})),s=0,t.forEach((t=>{if(!e.has(t)){const e=Y(n.concat([s]),i);r.push({op:j,path:e,value:t}),o.unshift({op:M,path:e,value:t})}s+=1}))}(e,t,n,r,o)}}const pe=(e,t,n=!1)=>{if("object"==typeof e&&null!==e&&(!U(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},he={get size(){return N(q(this)).size},has(e){return N(q(this)).has(e)},set(e,t){const n=q(this),r=N(n);return r.has(e)&&X(r.get(e),t)||(J(n),te(n),n.assignedMap.set(e,!0),n.copy.set(e,t),ce(n,e,t,ue)),this},delete(e){if(!this.has(e))return!1;const t=q(this);return J(t),te(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=q(this);if(this.size){J(e),te(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){N(q(this)).forEach(((n,r)=>{e.call(t,this.get(r),r,this)}))},get(e){var t,n;const r=q(this),o=N(r).get(e),i=(null===(n=(t=r.options).mark)||void 0===n?void 0:n.call(t,o,A))===A.mutable;if(r.options.strict&&pe(o,r.options,i),i)return o;if(r.finalized||!U(o,r.options))return o;if(o!==r.original.get(e))return o;const s=P.createDraft({original:o,parentDraft:r,key:e,finalities:r.finalities,options:r.options});return J(r),r.copy.set(e,s),s},keys(){return N(q(this)).keys()},values(){const e=this.keys();return{[T]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[T]:()=>this.entries(),next:()=>{const t=e.next();if(t.done)return t;const n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[T](){return this.entries()}},fe=Reflect.ownKeys(he),de=(e,t,{isValuesIterator:n})=>()=>{var r,o;const i=t.next();if(i.done)return i;const s=i.value;let a=e.setMap.get(s);const l=q(a),c=(null===(o=(r=e.options).mark)||void 0===o?void 0:o.call(r,a,A))===A.mutable;if(e.options.strict&&pe(s,e.options,c),c||l||!U(s,e.options)||e.finalized||!e.original.has(s))l&&(a=l.proxy);else{const t=P.createDraft({original:s,parentDraft:e,key:s,finalities:e.finalities,options:e.options});e.setMap.set(s,t),a=t}return{done:!1,value:n?a:[a,a]}},ye={get size(){return q(this).setMap.size},has(e){const t=q(this);if(t.setMap.has(e))return!0;J(t);const n=q(e);return!(!n||!t.setMap.has(n.original))},add(e){const t=q(this);return this.has(e)||(J(t),te(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),ce(t,e,e,ue)),this},delete(e){if(!this.has(e))return!1;const t=q(this);J(t),te(t);const n=q(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;const e=q(this);J(e),te(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=q(this);J(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:de(e,t,{isValuesIterator:!0})}},entries(){const e=q(this);J(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:de(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[T](){return this.values()},forEach(e,t){const n=this.values();let r=n.next();for(;!r.done;)e.call(t,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(ye,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const ge=Reflect.ownKeys(ye),ve=new WeakSet,me={get(e,t,n){var r,o;const i=null===(r=e.copy)||void 0===r?void 0:r[t];if(i&&ve.has(i))return i;if(t===S)return e;let s;if(e.options.mark){const r="size"===t&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(s=e.options.mark(r,A),s===A.mutable)return e.options.strict&&pe(r,e.options,!0),r}const a=N(e);if(a instanceof Map&&fe.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(he,"size").get.call(e.proxy);const n=he[t];if(n)return n.bind(e.proxy)}if(a instanceof Set&&ge.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(ye,"size").get.call(e.proxy);const n=ye[t];if(n)return n.bind(e.proxy)}if(!z(a,t)){const n=D(a,t);return n?"value"in n?n.value:null===(o=n.get)||void 0===o?void 0:o.call(e.proxy):void 0}const l=a[t];if(e.options.strict&&pe(l,e.options),e.finalized||!U(l,e.options))return l;if(l===W(e.original,t)){if(J(e),e.copy[t]=be({original:e.original[t],parentDraft:e,key:1===e.type?Number(t):t,finalities:e.finalities,options:e.options}),"function"==typeof s){const n=q(e.copy[t]);return J(n),te(n),n.copy}return e.copy[t]}return l},set(e,t,n){var r;if(3===e.type||2===e.type)throw new Error("Map/Set draft does not support any property assignment.");let o;if(1===e.type&&"length"!==t&&(!(Number.isInteger(o=Number(t))&&o>=0)||0!==t&&0!==o&&String(o)!==String(t)))throw new Error("Only supports setting array indices and the 'length' property.");const i=D(N(e),t);if(null==i?void 0:i.set)return i.set.call(e.proxy,n),!0;const s=W(N(e),t),a=q(s);return a&&X(a.original,n)?(e.copy[t]=n,e.assignedMap=null!==(r=e.assignedMap)&&void 0!==r?r:new Map,e.assignedMap.set(t,!1),!0):(X(n,s)&&(void 0!==n||z(e.original,t))||(J(e),te(e),z(e.original,t)&&X(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,ce(e,t,n,ue)),!0)},has:(e,t)=>t in N(e),ownKeys:e=>Reflect.ownKeys(N(e)),getOwnPropertyDescriptor(e,t){const n=N(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{writable:!0,configurable:1!==e.type||"length"!==t,enumerable:r.enumerable,value:n[t]}:r},getPrototypeOf:e=>Reflect.getPrototypeOf(e.original),setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(e,t){var n;return 1===e.type?me.set.call(this,e,t,void 0,e.proxy):(void 0!==W(e.original,t)||t in e.original?(J(e),te(e),e.assignedMap.set(t,!1)):(e.assignedMap=null!==(n=e.assignedMap)&&void 0!==n?n:new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function be(e){const{original:t,parentDraft:n,key:r,finalities:o,options:i}=e,s=H(t),a={type:s,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:o,options:i,setMap:3===s?new Map(t.entries()):void 0};(r||"key"in e)&&(a.key=r);const{proxy:l,revoke:c}=Proxy.revocable(1===s?Object.assign([],a):a,me);if(o.revoke.push(c),ve.add(l),a.proxy=l,n){const e=n;e.finalities.draft.push(((t,n)=>{var o,i;const s=q(l);let a=3===e.type?e.setMap:e.copy;const c=$(a,r),u=q(c);if(u){let i=u.original;u.operated&&(i=V(c)),ae(u),le(u,ue,t,n),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(o=e.options.updatedValues)&&void 0!==o?o:new WeakMap,e.options.updatedValues.set(i,u.original)),B(a,r,i)}null===(i=s.callbacks)||void 0===i||i.forEach((e=>{e(t,n)}))}))}else{const e=q(l);e.finalities.draft.push(((t,n)=>{ae(e),le(e,ue,t,n)}))}return l}function we(e,t,n,r,o){var i;const s=q(e),a=null!==(i=null==s?void 0:s.original)&&void 0!==i?i:e,l=!!t.length;if(null==s?void 0:s.operated)for(;s.finalities.draft.length>0;)s.finalities.draft.pop()(n,r);const c=l?t[0]:s?s.operated?s.copy:s.original:e;return s&&K(s),o&&re(c,c,null==s?void 0:s.options.updatedValues),[c,n&&l?[{op:R,path:[],value:t[0]}]:n,r&&l?[{op:R,path:[],value:a}]:r]}function Oe(e){const{rootDraft:t,value:n,useRawReturn:r=!1,isRoot:o=!0}=e;oe(n,((n,r,o)=>{const i=q(r);if(i&&t&&i.finalities===t.finalities){e.isContainDraft=!0;const t=i.original;if(o instanceof Set){const e=Array.from(o);o.clear(),e.forEach((e=>o.add(n===e?t:e)))}else B(o,n,t)}else"object"==typeof r&&null!==r&&(e.value=r,e.isRoot=!1,Oe(e))})),o&&e.isContainDraft}function xe(e){var t;const n=q(e);if(!U(e,null==n?void 0:n.options))return e;const r=H(e);if(n&&!n.operated)return n.original;let o;function i(){o=2===r?L(e)?new Map(e):new(Object.getPrototypeOf(e).constructor)(e):3===r?Array.from(n.setMap.values()):G(e,null==n?void 0:n.options)}if(n){n.finalized=!0;try{i()}finally{n.finalized=!1}}else o=e;if(oe(o,((t,r)=>{if(n&&X($(n.original,t),r))return;const s=xe(r);s!==r&&(o===e&&i(),B(o,t,s))})),3===r){const e=null!==(t=null==n?void 0:n.original)&&void 0!==t?t:o;return I(e)?new Set(o):new(Object.getPrototypeOf(e).constructor)(o)}return o}function ke(e){if(!_(e))throw new Error(`current() is only used for Draft, parameter: ${e}`);return xe(e)}P.createDraft=be;const Ee=function e(t,n,r){var o,i,s;if("function"==typeof t&&"function"!=typeof n)return function(r,...o){return e(r,(e=>t.call(this,e,...o)),n)};const a=t,l=n;let c=r;if("function"!=typeof n&&(c=n),void 0!==c&&"[object Object]"!==Object.prototype.toString.call(c))throw new Error(`Invalid options: ${c}, 'options' should be an object.`);c=Object.assign(Object.assign({},void 0),c);const u=_(a)?ke(a):a,p=Array.isArray(c.mark)?(e,t)=>{for(const n of c.mark){if("function"!=typeof n)throw new Error(`Invalid mark: ${n}, 'mark' should be a function.`);const r=n(e,t);if(r)return r}}:c.mark,h=null!==(o=c.enablePatches)&&void 0!==o&&o,f=null!==(i=c.strict)&&void 0!==i&&i,d={enableAutoFreeze:null!==(s=c.enableAutoFreeze)&&void 0!==s&&s,mark:p,strict:f,enablePatches:h};if(!U(u,d)&&"object"==typeof u&&null!==u)throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");const[y,g]=function(e,t){var n;const r={draft:[],revoke:[],handledSet:new WeakSet};let o,i;t.enablePatches&&(o=[],i=[]);const s=(null===(n=t.mark)||void 0===n?void 0:n.call(t,e,A))!==A.mutable&&U(e,t)?be({original:e,parentDraft:null,finalities:r,options:t}):e;return[s,(e=[])=>{const[n,r,a]=we(s,e,o,i,t.enableAutoFreeze);return t.enablePatches?[n,r,a]:n}]}(u,d);if("function"!=typeof n){if(!U(u,d))throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");return[y,g]}let v;try{v=l(y)}catch(e){throw K(q(y)),e}const m=e=>{const t=q(y);if(!_(e)){if(void 0!==e&&!X(e,y)&&(null==t?void 0:t.operated))throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");const n=null==e?void 0:e[C];if(n){const r=n[0];return d.strict&&"object"==typeof e&&null!==e&&Oe({rootDraft:t,value:e,useRawReturn:!0}),g([r])}if(void 0!==e)return"object"==typeof e&&null!==e&&Oe({rootDraft:t,value:e}),g([e])}if(e===y||void 0===e)return g([]);const n=q(e);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return g([ke(e)])}return g([e])};return v instanceof Promise?v.then(m,(e=>{throw K(q(y)),e})):m(v)};function Me(e,t){e.set(Ee(e.get(),t))}Object.prototype.constructor.toString();class Re{constructor(e,t=null){this.value=e,this.reactor=t??new k(this,[])}produce(e){return Me(this,e)}reducer(...e){let t;return t=1===e.length?new E(this,"",e[0]):new E(this,e[0],e[1]),t.trigger.bind(t)}setObjectByPath(e="",t){if(0===e.length)return void(this.value=t);if("string"!=typeof e||!e)throw new Error("Invalid path");let n=e.split("."),r=this.value;for(let e=0;e<n.length-1;e++){let t=n[e];t in r||(r[t]={}),r=r[t]}r[n[n.length-1]]=t}set(...e){if(1===e.length)this.value=e[0];else{let t=e[0],n=e[1];this.setObjectByPath(t,n)}this.reactor.react()}get(){return this.value}}function je(e){return new Re(e)}class Se{constructor(e){this.target=e}set html(e){this.target.innerHTML=e}query(e){return this.target.querySelectorAll(e)}set text(e){this.target.textContent=e}on(e,t){this.target.addEventListener(e,t)}off(e,t){this.target.removeEventListener(e,t)}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}class Ce{constructor(e){this.target=e}query(e){return this.target.querySelectorAll(e)}index(e){return Array.from(this.target.children)[e]}list(){return Array.from(this.target.children)}get parent(){return this.target}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}class Te{constructor(e){this.target=e}set(e){this.target=e.forwardRefs}}window.RUMIOUS_CONTEXTS||(window.RUMIOUS_CONTEXTS={});class Ae{constructor(e={}){this.data=e,this.events={}}on(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)))}emit(e,...t){this.events[e]&&this.events[e].forEach((e=>e(...t)))}set(e,t){let n=je(t);return this.data[e]=n,n}get(e){return this.data[e]}}class Pe{constructor(e,t={}){this.hasExecuted=!1,this.result=null,this.callback=e,this.dependents=[],this.options=t}onLoad(e){this.hasExecuted?e(this.result):this.dependents.push(e)}execute(){return new Promise(((e,t)=>{if(this.hasExecuted)return e(this.result);this.hasExecuted=!0;const n=async()=>{try{this.result=await this.callback(),e(this.result),this.dependents.forEach((e=>e(this.result)))}catch(e){t(e)}};this.options.idle&&"requestIdleCallback"in window?requestIdleCallback(n):n()}))}}const ze=new Map;exports.Pending=class extends t{static tag="r-pending";constructor(){super(),this.asynchronousRender=!0}async setLoader(e){this.loader=e;try{this.result=await this.loader.execute(),this.renderResult()}catch(e){this.error=e,this.renderError()}}renderResult(){if(!this.result)throw"Rumious Render: Cannot find component when lazy loading!";this.element.before(this.render(d(this.result,{}))),this.element.remove()}renderError(){this.element.appendChild(this.render(this.props.errorComponent??this.error))}onRender(){let{loader:e}=this.props;this.setLoader(e)}template(){return this.props.fallback}},exports.RumiousApp=class{constructor(t=document.createElement("span"),n={}){this.root=t,this.app=this,this.modules=[],this.configs=n,this.renderContext=new e(this)}render(e){this.renderContext.runHooks("onBeforeRender",this.renderContext),x(e,this.root,this.renderContext),this.renderContext.runHooks("onRendered",this.renderContext)}addModule(e,t={}){return e.init(this,t)}},exports.RumiousChildrensRef=Ce,exports.RumiousComponent=t,exports.RumiousComponentElement=b,exports.RumiousComponentRef=Te,exports.RumiousContext=Ae,exports.RumiousDymanicInjector=O,exports.RumiousElementRef=Se,exports.RumiousLazyLoader=Pe,exports.RumiousReactor=k,exports.RumiousReducer=E,exports.RumiousState=Re,exports.createChildrensRef=function(e){return new Ce(e)},exports.createComponent=g,exports.createComponentElement=w,exports.createComponentRef=function(e){return new Te(e)},exports.createContext=function(e="",t={}){if(!t||"object"!=typeof t)throw"Rumious context: Initial value must be object !";return window.RUMIOUS_CONTEXTS[e]||(window.RUMIOUS_CONTEXTS[e]=new Ae(t)),window.RUMIOUS_CONTEXTS[e]},exports.createDirective=f,exports.createElement=d,exports.createElementRef=function(e){return new Se(e)},exports.createState=je,exports.createTextElement=y,exports.denounce=function(e,t){let n;return function(...r){clearTimeout(n),n=setTimeout((()=>e.apply(this,r)),t)}},exports.injectHTML=function(e){let t=new O;return t.commit([{type:"html",value:e}]),t},exports.injectText=function(e){let t=new O;return t.commit([{type:"text",value:e}]),t},exports.isComponent=n,exports.isState=function(e){return e instanceof Re},exports.lazyLoad=function(e,t={}){const n=t.key||e.toString();return ze.has(n)||ze.set(n,new Pe(e,t)),ze.get(n)},exports.leadingTrailingDebounce=function(e,t){let n,r=!0;return function(...o){r&&(e.apply(this,o),r=!1),clearTimeout(n),n=setTimeout((()=>{e.apply(this,o),r=!0}),t)}},exports.produceState=Me,exports.rafThrottle=function(e){let t=!1;return function(...n){t||(t=!0,requestAnimationFrame((()=>{e.apply(this,n),t=!1})))}},exports.styleHelper=function(e){let t="";for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){t+=`${n} {`;const r=e[n];for(const e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t+=`${e.replace(/[A-Z]/g,(e=>`-${e.toLowerCase()}`))}: ${r[e]};`);t+="} "}return t.trim()},exports.tholle=function(e,t){let n=0;return function(...r){const o=Date.now();o-n>=t&&(n=o,e.apply(this,r))}},exports.trailingThrottle=function(e,t){let n=0,r=null,o=null;function i(){n=Date.now(),e.apply(this,r),r=null}return function(...e){const s=Date.now();r=e,s-n>=t?i():o||(o=setTimeout((()=>{o=null,i()}),t-(s-n)))}},exports.unwatch=function(e,t){e.reactor.removeBinding(t)},exports.watch=function(e,t){e.reactor.addBinding(t)};
1
+ "use strict";class e{constructor(e){this.target=e,this.app=e.app,this.hooks={onRendered:[],onBeforeRender:[]}}find(e){return this.target[e]}get(e){return this.target[e]}addHook(e,t){if(!this.hooks[e])throw new Error(`Hook type "${e}" is not defined!`);this.hooks[e].push(t)}async runHooks(e,...t){if(this.hooks[e])for(const n of this.hooks[e])await n(...t)}}class t{constructor(){this.renderOptions={mode:"linear"},this.element=null,this.app=null,this.props={},this.forwardRefs={},this.renderContext=new e(this),this.renderer=null,this.wrapped=null}prepare(e,t,n={},r=null){this.element=e,this.props=t,this.renderer=r,this.wrapped=n,this.renderContext.app=this.app}template(){return{}}render(e){return this.renderer(e,document.createDocumentFragment(),this.renderContext)}async requestRender(){await this.onBeforeRender();let e=this.template(),t=this.renderer(e,document.createDocumentFragment(),this.renderContext);this.element.appendChild(t),this.onRender()}async requestCleanUp(){if(this.element){let e=this.element.cloneNode(!0);for(this.element.replaceWith(e),this.element=e;this.element.firstChild;)this.element.removeChild(this.element.firstChild)}}onInit(){}onCreate(){}async onBeforeRender(){}onRender(){}onUpdate(){}onDestroy(){}}function n(e){return Object.getPrototypeOf(e)===t}class r{constructor(e,t,n=[]){this.type=e,this.props=t,this.children=n}}class i{constructor(e){this.type="ELEMENT_LIST",this.children=e}forEach(e){this.children.forEach(e)}}function s(e){return"function"==typeof e}class o{constructor(e,t,n){this.type=e,this.name=t,this.value=n}init(){}}class a extends o{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return null;const n=t.get(e);if(!s(n))throw new Error(`${e} is not a function!`);return n.bind(t.target)};if("string"===this.value.type)n=r(this.value.value);else if("expression"===this.value.type){if(n=this.value.value,!s(n))throw new Error("Event handler requires a function!")}else"dynamic_value"===this.value.type&&(n=r(this.value.value.objectName));n&&e.addEventListener(this.name,n)}}class l extends o{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");t.reactor.addBinding((()=>{let n=t.get();this.bindAttr(e,n)})),this.bindAttr(e,t.get())}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target),r=t.find(this.value.value.objectName);if(!r)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");r.reactor.addBinding((()=>{let n=this.value.evaluator?.(t.target);this.bindAttr(e,n)})),this.bindAttr(e,n)}}normalizeValue(e){return"object"==typeof e?e.toString?.()??"":e}async bindAttr(e,t){switch(this.name){case"html":e.innerHTML=this.normalizeValue(t);break;case"text":e.textContent=this.normalizeValue(t);break;case"show":e.style.display=this.normalizeValue(t)?"block":"none";break;case"hide":e.style.display=this.normalizeValue(t)?"none":"block";break;case"className":e.className=this.normalizeValue(t);break;case"style":Object.assign(e.style,t);break;case"disabled":e.disabled=!!this.normalizeValue(t);break;case"visible":e.style.visibility=this.normalizeValue(t)?"visible":"hidden";break;case"value":e.value=this.normalizeValue(t);break;case"checked":e.checked=this.normalizeValue(t);break;default:e.setAttribute(this.name,this.normalizeValue(t))}}}class c extends o{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");n.set(e)}}}class u extends o{async init(e,t){let n;"expression"===this.value.type?n=this.value.value:"dynamic_value"===this.value.type&&(n=t.find(this.value.value.objectName));const r=()=>{"checkbox"===e.type?n.set(e.checked):"radio"===e.type?e.checked&&n.set(e.value):n.set(e.value)};e.addEventListener("input",r),e.addEventListener("change",r)}}class p extends o{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");n.set(e)}}}const h={on:(e,t)=>new a("on",e,t),bind:(e,t)=>new l("bind",e,t),ref:(e,t)=>new c("ref",e,t),childsRef:(e,t)=>new p("childsRef",e,t),model:(e,t)=>new u("model",e,t)};function f(e,t,n){return function(e,t,n){return h[e]?.(t,n)}(e,t,n)}function d(e,t,...i){return n(e)?v(e,t,i):e===g?g(...i):new r(e,t||{},m(i))}function y(e){return new r("TEXT_ELEMENT",{nodeValue:e},[])}function v(e,t,n){let s=new r("COMPONENT",{...t},new i(m(n)));return s.component=e,s}function g(...e){return new r("FRAGMENT",{},m(e))}function m(e){return e.map((e=>"object"==typeof e?e:y(e)))}window.RUMIOUS_JSX_SUPPORT={createElement:d,createFragment:g,createDirective:f};class b extends HTMLElement{constructor(){super(),this.instance=null,this.ref=null}cleanUp(){Object.setPrototypeOf(this,HTMLUnknownElement.prototype),this.remove()}init(e,t,n={},r,i){this.instance=new e,this.instance.element=this,this.instance.app=i,this.instance.prepare(this,t,n,r),this.instance.onInit()}connectedCallback(){switch(this.instance.renderOptions.mode){case"linear":this.instance.onCreate(),this.instance.requestRender();break;case"async":(async()=>{this.instance.onCreate(),this.instance.requestRender()})();break;case"animate":requestAnimationFrame((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"idle":requestIdleCallback((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"defer":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),0);break;case"delay":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),this.instance.renderOptions.time);break;case"visible":new IntersectionObserver(((e,t)=>{for(const n of e)n.isIntersecting&&(t.disconnect(),this.instance.onCreate(),this.instance.requestRender())})).observe(this)}}disconnectedCallback(){this.instance.onDestroy(),this.instance.requestCleanUp(),this.cleanUp()}}function w(e="r-component"){return window.customElements.get(e)||window.customElements.define(e,class extends b{static tag=e}),document.createElement(e)}class E{constructor(){this.contents=[],this.targets=[],this.observers=new WeakMap}commit(e=[]){this.contents=e}setTarget(e,t,n){this.targets.push({element:e,context:n,renderer:t}),this.observeTarget(e)}observeTarget(e){if(this.observers.has(e))return;const t=new MutationObserver((()=>{e.parentNode||this.removeTarget(e)}));t.observe(document.body,{childList:!0}),this.observers.set(e,t)}removeTarget(e){const t=this.observers.get(e);t&&(t.disconnect(),this.observers.delete(e)),this.targets=this.targets.filter((t=>t.element!==e))}inject(e=!1){for(let t of this.targets)e&&(t.element.textContent=""),this.contents.forEach((e=>{"html"===e.type?t.element.innerHTML=e.value:"text"===e.type?t.element.textContent=e.value:"component"===e.type&&t.renderer(d(e.value,e.props??{},e.child??{}),t.element,t.context)}))}}class x{constructor(e,t){this.state=e,this.template=t,this.target=null}setTarget(e,t,n){this.target={element:e,context:n,renderer:t}}sync(){this.target&&(this.renderAll(),this.state.reactor.addBinding((e=>this.onChange(e))))}renderAll(){this.target.element.textContent="",this.state.value.forEach(((e,t)=>this.appendElement(e,t)))}appendElement(e,t){let n=this.template(e,t),r=this.target.renderer(n,document.createDocumentFragment(),this.target.context);this.target.element.appendChild(r)}onChange(e){if(this.target)switch(e.type){case"REMOVE_ELEMENT":{let t=this.target.element.children[e.index];t&&this.target.element.removeChild(t);break}case"SET_VALUE":this.renderAll();break;case"ADD_ELEMENT":this.appendElement(e.value,e.index);break;case"SET_ELEMENT":{let t=this.template(e.value,e.index),n=this.target.renderer(t,document.createDocumentFragment(),this.target.context);!function(e,t,n){let r=e.children;t>=0&&t<r.length?e.replaceChild(n,r[t]):e.appendChild(n)}(this.target.element,e.index,n);break}case"INSERT_ELEMENT":{let t=this.template(e.value,e.index),n=this.target.renderer(t,document.createDocumentFragment(),this.target.context),r=this.target.element.children;e.index>=r.length?this.target.element.appendChild(n):this.target.element.insertBefore(n.children[0],r[e.index]);break}}}}function O(e,t,n={}){if(!e)return t;if(null===(i=e)||"object"!=typeof i&&"function"!=typeof i)return O(y(e),t,n);var i;if(Array.isArray(e)){for(const r of e)O(r,t,n);return t}if(e instanceof r){let r;switch(e.type){case"COMPONENT":return function(e,t,n,r){const i=function(e,t,n,r,i=null){const s=w(e.tag??"r-component");return s.init(e,t,n,r,i?.app),s}(e.component,e.props,e.children,n,r);return t.appendChild(i),t}(e,t,O,n);case"FRAGMENT":case"ELEMENT_LIST":for(const r of e.children)O(r,t,n);return t;case"TEXT_ELEMENT":r=function(e){return document.createTextNode(e.props.nodeValue)}(e);break;default:r=function(e,t){const n=document.createElement(e.type);!function(e,t,n){for(const[r,i]of Object.entries(t||{}))i instanceof o?i.init(e,n):r.startsWith("on")&&/^[a-zA-Z]+([A-Z][a-z]*)*$/.test(r)?e.addEventListener(r.substring(2).toLowerCase(),i):e.setAttribute(r,i)}(n,e.props,t);for(const r of e.children)O(r,n,t);return n}(e,n)}return t.appendChild(r),t}if(e instanceof HTMLElement)return t.appendChild(e),t;if(e instanceof E){if(t instanceof HTMLDocument)throw"Rumious Render: Unsupported inject content in HTMLDocument!";return e.setTarget(t,O,n),e.inject(!0),t}if(e instanceof x){if(t instanceof HTMLDocument)throw"Rumious Render: Unsupported sync data of array in HTMLDocument!";return e.setTarget(t,O,n),e.sync(),t}return O(y(JSON.stringify(e)),t,n)}class k{constructor(e=null,t=[]){this.target=e,this.bindings=t}react(e){this.bindings.forEach((t=>t(e)))}removeBinding(e){for(let t=this.bindings.length-1;t>=0;t--)this.bindings[t]===e&&this.bindings.splice(t,1)}addBinding(e){this.bindings.push(e)}}class M{constructor(e,t="",n){this.state=e,this.path=t,this.fn=n}trigger(...e){let t=this.fn(...e);this.state.set(this.path,t)}}const R="remove",j="replace",S="add",T=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),C=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),A=Symbol.iterator,P={mutable:"mutable",immutable:"immutable"},D={};function z(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function L(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const e=Reflect.getOwnPropertyDescriptor(n,t);if(e)return e;n=Reflect.getPrototypeOf(n)}}}function _(e){return Object.getPrototypeOf(e)===Set.prototype}function N(e){return Object.getPrototypeOf(e)===Map.prototype}function I(e){var t;return null!==(t=e.copy)&&void 0!==t?t:e.original}function V(e){return!!U(e)}function U(e){return"object"!=typeof e?null:null==e?void 0:e[T]}function q(e){var t;const n=U(e);return n?null!==(t=n.copy)&&void 0!==t?t:n.original:e}function F(e,t){if(!e||"object"!=typeof e)return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!(null==t?void 0:t.mark)&&((n=t.mark(e,P))===P.immutable||"function"==typeof n)}function H(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,r=U($(n,e.key));if(null!==r&&(null==r?void 0:r.original)!==e.original)return null;const i=3===e.parent.type,s=i?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(i&&n.size>s||z(n,s)))return null;t.push(s)}if(e.parent)return H(e.parent,t);t.reverse();try{!function(e,t){for(let n=0;n<t.length-1;n+=1){const r=t[n];if("object"!=typeof(e=$(3===B(e)?Array.from(e):e,r)))throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}}(e.copy,t)}catch(e){return null}return t}function B(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function $(e,t){return 2===B(e)?e.get(t):e[t]}function W(e,t,n){2===B(e)?e.set(t,n):e[t]=n}function X(e,t){const n=U(e);return(n?I(n):e)[t]}function K(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function G(e){if(e)for(;e.finalities.revoke.length>0;)e.finalities.revoke.pop()()}function Y(e,t){return t?e:[""].concat(e).map((e=>{const t=`${e}`;return-1===t.indexOf("/")&&-1===t.indexOf("~")?t:t.replace(/~/g,"~0").replace(/\//g,"~1")})).join("/")}const Z=Object.prototype.propertyIsEnumerable;function J(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set)return _(e)?Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values()):new(0,Object.getPrototypeOf(e).constructor)(e.values());if(e instanceof Map)return N(e)?new Map(e):new(0,Object.getPrototypeOf(e).constructor)(e);if((null==t?void 0:t.mark)&&(n=t.mark(e,P),void 0!==n)&&n!==P.mutable){if(n===P.immutable)return function(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((n=>{let r=Reflect.getOwnPropertyDescriptor(e,n);r.enumerable&&r.configurable&&r.writable?t[n]=e[n]:(r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:e[n]}),Reflect.defineProperty(t,n,r))})),t}(e);if("function"==typeof n){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return n()}throw new Error(`Unsupported mark result: ${n}`)}if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype){const t={};return Object.keys(e).forEach((n=>{t[n]=e[n]})),Object.getOwnPropertySymbols(e).forEach((n=>{Z.call(e,n)&&(t[n]=e[n])})),t}throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function Q(e){e.copy||(e.copy=J(e.original,e.options))}function ee(e){if(!F(e))return q(e);if(Array.isArray(e))return e.map(ee);if(e instanceof Map){const t=Array.from(e.entries()).map((([e,t])=>[e,ee(t)]));return N(e)?new Map(t):new(0,Object.getPrototypeOf(e).constructor)(t)}if(e instanceof Set){const t=Array.from(e).map(ee);return _(e)?new Set(t):new(0,Object.getPrototypeOf(e).constructor)(t)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=ee(e[n]);return t}function te(e){return V(e)?ee(e):e}function ne(e){var t;e.assignedMap=null!==(t=e.assignedMap)&&void 0!==t?t:new Map,e.operated||(e.operated=!0,e.parent&&ne(e.parent))}function re(){throw new Error("Cannot modify frozen object")}function ie(e,t,n,r,i){{n=null!=n?n:new WeakMap,r=null!=r?r:[],i=null!=i?i:[];const s=n.has(e)?n.get(e):e;if(r.length>0){const e=r.indexOf(s);if(s&&"object"==typeof s&&-1!==e){if(r[0]===s)throw new Error("Forbids circular reference");throw new Error(`Forbids circular reference: ~/${i.slice(0,e).map(((e,t)=>{if("symbol"==typeof e)return`[${e.toString()}]`;const n=r[t];return"object"==typeof e&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(e):e})).join("/")}`)}r.push(s),i.push(t)}else r.push(s)}if(Object.isFrozen(e)||V(e))return r.pop(),void i.pop();switch(B(e)){case 2:for(const[t,s]of e)ie(t,t,n,r,i),ie(s,t,n,r,i);e.set=e.clear=e.delete=re;break;case 3:for(const t of e)ie(t,t,n,r,i);e.add=e.clear=e.delete=re;break;case 1:Object.freeze(e);let t=0;for(const s of e)ie(s,t,n,r,i),t+=1;break;default:Object.freeze(e),Object.keys(e).forEach((t=>{ie(e[t],t,n,r,i)}))}r.pop(),i.pop()}function se(e,t){const n=B(e);if(0===n)Reflect.ownKeys(e).forEach((n=>{t(n,e[n],e)}));else if(1===n){let n=0;for(const r of e)t(n,r,e),n+=1}else e.forEach(((n,r)=>t(r,n,e)))}function oe(e,t,n){if(V(e)||!F(e,n)||t.has(e)||Object.isFrozen(e))return;const r=e instanceof Set,i=r?new Map:void 0;if(t.add(e),se(e,((s,o)=>{var a;if(V(o)){const t=U(o);Q(t);const n=(null===(a=t.assignedMap)||void 0===a?void 0:a.size)||t.operated?t.copy:t.original;W(r?i:e,s,n)}else oe(o,t,n)})),i){const t=e,n=Array.from(t);t.clear(),n.forEach((e=>{t.add(i.has(e)?i.get(e):e)}))}}function ae(e,t){const n=3===e.type?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&oe($(n,t),e.finalities.handledSet,e.options)}function le(e){3===e.type&&e.copy&&(e.copy.clear(),e.setMap.forEach((t=>{e.copy.add(q(t))})))}function ce(e,t,n,r){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&r){const i=H(e);i&&t(e,i,n,r)}e.finalized=!0}}function ue(e,t,n,r){const i=U(n);i&&(i.callbacks||(i.callbacks=[]),i.callbacks.push(((s,o)=>{var a;const l=3===e.type?e.setMap:e.copy;if(K($(l,t),n)){let n=i.original;i.copy&&(n=i.copy),le(e),ce(e,r,s,o),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(a=e.options.updatedValues)&&void 0!==a?a:new WeakMap,e.options.updatedValues.set(n,i.original)),W(l,t,n)}})),e.options.enableAutoFreeze&&i.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),F(n,e.options)&&e.finalities.draft.push((()=>{K($(3===e.type?e.setMap:e.copy,t),n)&&ae(e,t)}))}function pe(e,t,n,r){const{pathAsArray:i=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return function({original:e,copy:t,assignedMap:n},r,i,s,o){n.forEach(((n,a)=>{const l=$(e,a),c=te($(t,a)),u=n?z(e,a)?j:S:R;if(K(l,c)&&u===j)return;const p=Y(r.concat(a),o);i.push(u===R?{op:u,path:p}:{op:u,path:p,value:c}),s.push(u===S?{op:R,path:p}:u===R?{op:S,path:p,value:l}:{op:j,path:p,value:l})}))}(e,t,n,r,i);case 1:return function(e,t,n,r,i){let{original:s,assignedMap:o,options:a}=e,l=e.copy;l.length<s.length&&([s,l]=[l,s],[n,r]=[r,n]);for(let e=0;e<s.length;e+=1)if(o.get(e.toString())&&l[e]!==s[e]){const o=Y(t.concat([e]),i);n.push({op:j,path:o,value:te(l[e])}),r.push({op:j,path:o,value:te(s[e])})}for(let e=s.length;e<l.length;e+=1){const r=Y(t.concat([e]),i);n.push({op:S,path:r,value:te(l[e])})}if(s.length<l.length){const{arrayLengthAssignment:e=!0}=a.enablePatches;if(e){const e=Y(t.concat(["length"]),i);r.push({op:j,path:e,value:s.length})}else for(let e=l.length;s.length<e;e-=1){const n=Y(t.concat([e-1]),i);r.push({op:R,path:n})}}}(e,t,n,r,i);case 3:return function({original:e,copy:t},n,r,i,s){let o=0;e.forEach((e=>{if(!t.has(e)){const t=Y(n.concat([o]),s);r.push({op:R,path:t,value:e}),i.unshift({op:S,path:t,value:e})}o+=1})),o=0,t.forEach((t=>{if(!e.has(t)){const e=Y(n.concat([o]),s);r.push({op:S,path:e,value:t}),i.unshift({op:R,path:e,value:t})}o+=1}))}(e,t,n,r,i)}}const he=(e,t,n=!1)=>{if("object"==typeof e&&null!==e&&(!F(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},fe={get size(){return I(U(this)).size},has(e){return I(U(this)).has(e)},set(e,t){const n=U(this),r=I(n);return r.has(e)&&K(r.get(e),t)||(Q(n),ne(n),n.assignedMap.set(e,!0),n.copy.set(e,t),ue(n,e,t,pe)),this},delete(e){if(!this.has(e))return!1;const t=U(this);return Q(t),ne(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=U(this);if(this.size){Q(e),ne(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){I(U(this)).forEach(((n,r)=>{e.call(t,this.get(r),r,this)}))},get(e){var t,n;const r=U(this),i=I(r).get(e),s=(null===(n=(t=r.options).mark)||void 0===n?void 0:n.call(t,i,P))===P.mutable;if(r.options.strict&&he(i,r.options,s),s)return i;if(r.finalized||!F(i,r.options))return i;if(i!==r.original.get(e))return i;const o=D.createDraft({original:i,parentDraft:r,key:e,finalities:r.finalities,options:r.options});return Q(r),r.copy.set(e,o),o},keys(){return I(U(this)).keys()},values(){const e=this.keys();return{[A]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[A]:()=>this.entries(),next:()=>{const t=e.next();if(t.done)return t;const n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[A](){return this.entries()}},de=Reflect.ownKeys(fe),ye=(e,t,{isValuesIterator:n})=>()=>{var r,i;const s=t.next();if(s.done)return s;const o=s.value;let a=e.setMap.get(o);const l=U(a),c=(null===(i=(r=e.options).mark)||void 0===i?void 0:i.call(r,a,P))===P.mutable;if(e.options.strict&&he(o,e.options,c),c||l||!F(o,e.options)||e.finalized||!e.original.has(o))l&&(a=l.proxy);else{const t=D.createDraft({original:o,parentDraft:e,key:o,finalities:e.finalities,options:e.options});e.setMap.set(o,t),a=t}return{done:!1,value:n?a:[a,a]}},ve={get size(){return U(this).setMap.size},has(e){const t=U(this);if(t.setMap.has(e))return!0;Q(t);const n=U(e);return!(!n||!t.setMap.has(n.original))},add(e){const t=U(this);return this.has(e)||(Q(t),ne(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),ue(t,e,e,pe)),this},delete(e){if(!this.has(e))return!1;const t=U(this);Q(t),ne(t);const n=U(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;const e=U(this);Q(e),ne(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=U(this);Q(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:ye(e,t,{isValuesIterator:!0})}},entries(){const e=U(this);Q(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:ye(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[A](){return this.values()},forEach(e,t){const n=this.values();let r=n.next();for(;!r.done;)e.call(t,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(ve,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const ge=Reflect.ownKeys(ve),me=new WeakSet,be={get(e,t,n){var r,i;const s=null===(r=e.copy)||void 0===r?void 0:r[t];if(s&&me.has(s))return s;if(t===T)return e;let o;if(e.options.mark){const r="size"===t&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(o=e.options.mark(r,P),o===P.mutable)return e.options.strict&&he(r,e.options,!0),r}const a=I(e);if(a instanceof Map&&de.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(fe,"size").get.call(e.proxy);const n=fe[t];if(n)return n.bind(e.proxy)}if(a instanceof Set&&ge.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(ve,"size").get.call(e.proxy);const n=ve[t];if(n)return n.bind(e.proxy)}if(!z(a,t)){const n=L(a,t);return n?"value"in n?n.value:null===(i=n.get)||void 0===i?void 0:i.call(e.proxy):void 0}const l=a[t];if(e.options.strict&&he(l,e.options),e.finalized||!F(l,e.options))return l;if(l===X(e.original,t)){if(Q(e),e.copy[t]=we({original:e.original[t],parentDraft:e,key:1===e.type?Number(t):t,finalities:e.finalities,options:e.options}),"function"==typeof o){const n=U(e.copy[t]);return Q(n),ne(n),n.copy}return e.copy[t]}return l},set(e,t,n){var r;if(3===e.type||2===e.type)throw new Error("Map/Set draft does not support any property assignment.");let i;if(1===e.type&&"length"!==t&&(!(Number.isInteger(i=Number(t))&&i>=0)||0!==t&&0!==i&&String(i)!==String(t)))throw new Error("Only supports setting array indices and the 'length' property.");const s=L(I(e),t);if(null==s?void 0:s.set)return s.set.call(e.proxy,n),!0;const o=X(I(e),t),a=U(o);return a&&K(a.original,n)?(e.copy[t]=n,e.assignedMap=null!==(r=e.assignedMap)&&void 0!==r?r:new Map,e.assignedMap.set(t,!1),!0):(K(n,o)&&(void 0!==n||z(e.original,t))||(Q(e),ne(e),z(e.original,t)&&K(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,ue(e,t,n,pe)),!0)},has:(e,t)=>t in I(e),ownKeys:e=>Reflect.ownKeys(I(e)),getOwnPropertyDescriptor(e,t){const n=I(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{writable:!0,configurable:1!==e.type||"length"!==t,enumerable:r.enumerable,value:n[t]}:r},getPrototypeOf:e=>Reflect.getPrototypeOf(e.original),setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(e,t){var n;return 1===e.type?be.set.call(this,e,t,void 0,e.proxy):(void 0!==X(e.original,t)||t in e.original?(Q(e),ne(e),e.assignedMap.set(t,!1)):(e.assignedMap=null!==(n=e.assignedMap)&&void 0!==n?n:new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function we(e){const{original:t,parentDraft:n,key:r,finalities:i,options:s}=e,o=B(t),a={type:o,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:i,options:s,setMap:3===o?new Map(t.entries()):void 0};(r||"key"in e)&&(a.key=r);const{proxy:l,revoke:c}=Proxy.revocable(1===o?Object.assign([],a):a,be);if(i.revoke.push(c),me.add(l),a.proxy=l,n){const e=n;e.finalities.draft.push(((t,n)=>{var i,s;const o=U(l);let a=3===e.type?e.setMap:e.copy;const c=$(a,r),u=U(c);if(u){let s=u.original;u.operated&&(s=q(c)),le(u),ce(u,pe,t,n),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(i=e.options.updatedValues)&&void 0!==i?i:new WeakMap,e.options.updatedValues.set(s,u.original)),W(a,r,s)}null===(s=o.callbacks)||void 0===s||s.forEach((e=>{e(t,n)}))}))}else{const e=U(l);e.finalities.draft.push(((t,n)=>{le(e),ce(e,pe,t,n)}))}return l}function Ee(e,t,n,r,i){var s;const o=U(e),a=null!==(s=null==o?void 0:o.original)&&void 0!==s?s:e,l=!!t.length;if(null==o?void 0:o.operated)for(;o.finalities.draft.length>0;)o.finalities.draft.pop()(n,r);const c=l?t[0]:o?o.operated?o.copy:o.original:e;return o&&G(o),i&&ie(c,c,null==o?void 0:o.options.updatedValues),[c,n&&l?[{op:j,path:[],value:t[0]}]:n,r&&l?[{op:j,path:[],value:a}]:r]}function xe(e){const{rootDraft:t,value:n,useRawReturn:r=!1,isRoot:i=!0}=e;se(n,((n,r,i)=>{const s=U(r);if(s&&t&&s.finalities===t.finalities){e.isContainDraft=!0;const t=s.original;if(i instanceof Set){const e=Array.from(i);i.clear(),e.forEach((e=>i.add(n===e?t:e)))}else W(i,n,t)}else"object"==typeof r&&null!==r&&(e.value=r,e.isRoot=!1,xe(e))})),i&&e.isContainDraft}function Oe(e){var t;const n=U(e);if(!F(e,null==n?void 0:n.options))return e;const r=B(e);if(n&&!n.operated)return n.original;let i;function s(){i=2===r?N(e)?new Map(e):new(Object.getPrototypeOf(e).constructor)(e):3===r?Array.from(n.setMap.values()):J(e,null==n?void 0:n.options)}if(n){n.finalized=!0;try{s()}finally{n.finalized=!1}}else i=e;if(se(i,((t,r)=>{if(n&&K($(n.original,t),r))return;const o=Oe(r);o!==r&&(i===e&&s(),W(i,t,o))})),3===r){const e=null!==(t=null==n?void 0:n.original)&&void 0!==t?t:i;return _(e)?new Set(i):new(Object.getPrototypeOf(e).constructor)(i)}return i}function ke(e){if(!V(e))throw new Error(`current() is only used for Draft, parameter: ${e}`);return Oe(e)}D.createDraft=we;const Me=function e(t,n,r){var i,s,o;if("function"==typeof t&&"function"!=typeof n)return function(r,...i){return e(r,(e=>t.call(this,e,...i)),n)};const a=t,l=n;let c=r;if("function"!=typeof n&&(c=n),void 0!==c&&"[object Object]"!==Object.prototype.toString.call(c))throw new Error(`Invalid options: ${c}, 'options' should be an object.`);c=Object.assign(Object.assign({},void 0),c);const u=V(a)?ke(a):a,p=Array.isArray(c.mark)?(e,t)=>{for(const n of c.mark){if("function"!=typeof n)throw new Error(`Invalid mark: ${n}, 'mark' should be a function.`);const r=n(e,t);if(r)return r}}:c.mark,h=null!==(i=c.enablePatches)&&void 0!==i&&i,f=null!==(s=c.strict)&&void 0!==s&&s,d={enableAutoFreeze:null!==(o=c.enableAutoFreeze)&&void 0!==o&&o,mark:p,strict:f,enablePatches:h};if(!F(u,d)&&"object"==typeof u&&null!==u)throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");const[y,v]=function(e,t){var n;const r={draft:[],revoke:[],handledSet:new WeakSet};let i,s;t.enablePatches&&(i=[],s=[]);const o=(null===(n=t.mark)||void 0===n?void 0:n.call(t,e,P))!==P.mutable&&F(e,t)?we({original:e,parentDraft:null,finalities:r,options:t}):e;return[o,(e=[])=>{const[n,r,a]=Ee(o,e,i,s,t.enableAutoFreeze);return t.enablePatches?[n,r,a]:n}]}(u,d);if("function"!=typeof n){if(!F(u,d))throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");return[y,v]}let g;try{g=l(y)}catch(e){throw G(U(y)),e}const m=e=>{const t=U(y);if(!V(e)){if(void 0!==e&&!K(e,y)&&(null==t?void 0:t.operated))throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");const n=null==e?void 0:e[C];if(n){const r=n[0];return d.strict&&"object"==typeof e&&null!==e&&xe({rootDraft:t,value:e,useRawReturn:!0}),v([r])}if(void 0!==e)return"object"==typeof e&&null!==e&&xe({rootDraft:t,value:e}),v([e])}if(e===y||void 0===e)return v([]);const n=U(e);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return v([ke(e)])}return v([e])};return g instanceof Promise?g.then(m,(e=>{throw G(U(y)),e})):m(g)};function Re(e,t){e.set(Me(e.get(),t))}Object.prototype.constructor.toString();class je{constructor(e,t=null){this.value=e,this.reactor=t??new k(this,[])}produce(e){return Re(this,e)}reducer(...e){let t;return t=1===e.length?new M(this,"",e[0]):new M(this,e[0],e[1]),t.trigger.bind(t)}setObjectByPath(e="",t){if(0===e.length)return void(this.value=t);if("string"!=typeof e||!e)throw new Error("Invalid path");let n=e.split("."),r=this.value;for(let e=0;e<n.length-1;e++){let t=n[e];t in r||(r[t]={}),r=r[t]}r[n[n.length-1]]=t}set(...e){if(1===e.length)this.value=e[0],this.reactor.react({type:"SET_VALUE",value:e[0]});else{let t=e[0],n=e[1];this.setObjectByPath(t,n),this.reactor.react({type:"SET_VALUE",path:t,value:n})}}get(){return this.value}}class Se extends je{constructor(e,t=null){if(!(e instanceof Array))throw Error("RumiousArrayState: The initial value must be an array.");super(e,t)}set(...e){if(1===e.length)this.value=e[0],this.reactor.react({type:"SET_VALUE",value:e[0]});else{let t=e[0],n=e[1];this.value[t]=n,this.reactor.react({type:"SET_ELEMENT",index:t,value:n})}}append(e){this.value.push(e),this.reactor.react({type:"ADD_ELEMENT",value:e,index:this.value.length-1})}index(e){return this.value[e]}remove(e){e>=0&&e<this.value.length&&(this.value.splice(e,1),this.reactor.react({type:"REMOVE_ELEMENT",index:e}))}insert(e,t){e>=0&&e<=this.value.length&&(this.value.splice(e,0,t),this.reactor.react({type:"INSERT_ELEMENT",index:e,value:t}))}find(e){return this.value.find(e)}}class Te extends je{constructor(e,t=null){if(!(e instanceof Object))throw Error("RumiousObjectState: The initial value must be an object.");super(e,t)}set(...e){if(1===e.length)this.value=e[0],this.reactor.react({type:"SET_VALUE",value:e[0]});else{let t=e[0],n=e[1];this.value[t]=n,this.reactor.react({type:"SET_VALUE",index:t,value:n})}}keys(){return Object.keys(this.value)}values(){return Object.values(this.value)}each(e){for(let[t,n]of Object.entries(this.value))e(n,t)}has(e){return void 0!==this.value[e]}remove(e){delete this.value[e]}entries(){return Object.entries(this.value)}clear(){this.value={},this.reactor.react({type:"CLEAR"})}merge(e){e instanceof Object&&(Object.assign(this.value,e),this.reactor.react({type:"MERGE",value:e}))}map(e){return Object.entries(this.value).map((([t,n],r)=>e(n,t,r)))}}class Ce{constructor(e){this.target=e}set html(e){this.target.innerHTML=e}query(e){return this.target.querySelectorAll(e)}set text(e){this.target.textContent=e}on(e,t){this.target.addEventListener(e,t)}off(e,t){this.target.removeEventListener(e,t)}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}class Ae{constructor(e){this.target=e}query(e){return this.target.querySelectorAll(e)}index(e){return Array.from(this.target.children)[e]}list(){return Array.from(this.target.children)}get parent(){return this.target}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}class Pe{constructor(e){this.target=e}set(e){this.target=e.forwardRefs}}window.RUMIOUS_CONTEXTS||(window.RUMIOUS_CONTEXTS={});class De{constructor(e={}){this.data=e,this.events={}}on(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)))}emit(e,...t){this.events[e]&&this.events[e].forEach((e=>e(...t)))}set(e,t){return this.data[e]=t,t}get(e){return this.data[e]}}class ze{constructor(e,t={}){this.hasExecuted=!1,this.result=null,this.callback=e,this.dependents=[],this.options=t}onLoad(e){this.hasExecuted?e(this.result):this.dependents.push(e)}execute(){return new Promise(((e,t)=>{if(this.hasExecuted)return e(this.result);this.hasExecuted=!0;const n=async()=>{try{this.result=await this.callback(),e(this.result),this.dependents.forEach((e=>e(this.result)))}catch(e){t(e)}};this.options.idle&&"requestIdleCallback"in window?requestIdleCallback(n):n()}))}}const Le=new Map;exports.Pending=class extends t{static tag="r-pending";constructor(){super(),this.asynchronousRender=!0}async setLoader(e){this.loader=e;try{this.result=await this.loader.execute(),this.renderResult()}catch(e){this.error=e,this.renderError()}}renderResult(){if(!this.result)throw"Rumious Render: Cannot find component when lazy loading!";this.element.before(this.render(d(this.result,{}))),this.element.remove()}renderError(){this.element.appendChild(this.render(this.props.errorComponent??this.error))}onRender(){let{loader:e}=this.props;this.setLoader(e)}template(){return this.props.fallback}},exports.RumiousApp=class{constructor(t=document.createElement("span"),n={}){this.root=t,this.app=this,this.modules=[],this.configs=n,this.renderContext=new e(this)}render(e){this.renderContext.runHooks("onBeforeRender",this.renderContext),O(e,this.root,this.renderContext),this.renderContext.runHooks("onRendered",this.renderContext)}addModule(e,t={}){return e.init(this,t)}},exports.RumiousArraySync=x,exports.RumiousChildrensRef=Ae,exports.RumiousComponent=t,exports.RumiousComponentElement=b,exports.RumiousComponentRef=Pe,exports.RumiousContext=De,exports.RumiousDymanicInjector=E,exports.RumiousElementRef=Ce,exports.RumiousLazyLoader=ze,exports.RumiousReactor=k,exports.RumiousReducer=M,exports.RumiousState=je,exports.createArrayState=function(e=[]){return new Se(e)},exports.createChildrensRef=function(e){return new Ae(e)},exports.createComponent=v,exports.createComponentElement=w,exports.createComponentRef=function(e){return new Pe(e)},exports.createContext=function(e="",t={}){if(!t||"object"!=typeof t)throw new Error("Rumious context: Initial value must be an object!");return window.RUMIOUS_CONTEXTS[e]||(window.RUMIOUS_CONTEXTS[e]=new De(t)),window.RUMIOUS_CONTEXTS[e]},exports.createDirective=f,exports.createElement=d,exports.createElementRef=function(e){return new Ce(e)},exports.createObjectState=function(e={}){return new Te(e)},exports.createState=function(e){return new je(e)},exports.createTextElement=y,exports.denounce=function(e,t){let n;return function(...r){clearTimeout(n),n=setTimeout((()=>e.apply(this,r)),t)}},exports.injectHTML=function(e){let t=new E;return t.commit([{type:"html",value:e}]),t},exports.injectText=function(e){let t=new E;return t.commit([{type:"text",value:e}]),t},exports.isComponent=n,exports.isState=function(e){return e instanceof je},exports.lazyLoad=function(e,t={}){const n=t.key||e.toString();return Le.has(n)||Le.set(n,new ze(e,t)),Le.get(n)},exports.leadingTrailingDebounce=function(e,t){let n,r=!0;return function(...i){r&&(e.apply(this,i),r=!1),clearTimeout(n),n=setTimeout((()=>{e.apply(this,i),r=!0}),t)}},exports.produceState=Re,exports.rafThrottle=function(e){let t=!1;return function(...n){t||(t=!0,requestAnimationFrame((()=>{e.apply(this,n),t=!1})))}},exports.styleHelper=function(e){let t="";for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){t+=`${n} {`;const r=e[n];for(const e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t+=`${e.replace(/[A-Z]/g,(e=>`-${e.toLowerCase()}`))}: ${r[e]};`);t+="} "}return t.trim()},exports.syncArray=function(e,t){return new x(e,t)},exports.tholle=function(e,t){let n=0;return function(...r){const i=Date.now();i-n>=t&&(n=i,e.apply(this,r))}},exports.trailingThrottle=function(e,t){let n=0,r=null,i=null;function s(){n=Date.now(),e.apply(this,r),r=null}return function(...e){const o=Date.now();r=e,o-n>=t?s():i||(i=setTimeout((()=>{i=null,s()}),t-(o-n)))}},exports.unwatch=function(e,t){e.reactor.removeBinding(t)},exports.watch=function(e,t){e.reactor.addBinding(t)};
@@ -1 +1 @@
1
- class e{constructor(e){this.target=e,this.app=e.app,this.hooks={onRendered:[],onBeforeRender:[]}}find(e){return this.target[e]}get(e){return this.target[e]}addHook(e,t){if(!this.hooks[e])throw new Error(`Hook type "${e}" is not defined!`);this.hooks[e].push(t)}async runHooks(e,...t){if(this.hooks[e])for(const n of this.hooks[e])await n(...t)}}class t{constructor(){this.renderOptions={mode:"linear"},this.element=null,this.app=null,this.props={},this.forwardRefs={},this.renderContext=new e(this),this.renderer=null,this.wrapped=null}prepare(e,t,n={},r=null){this.element=e,this.props=t,this.renderer=r,this.wrapped=n,this.renderContext.app=this.app}template(){return{}}render(e){return this.renderer(e,document.createDocumentFragment(),this.renderContext)}requestRender(){let e=this.template(),t=this.renderer(e,document.createDocumentFragment(),this.renderContext);this.element.appendChild(t),this.onRender()}async requestCleanUp(){if(this.element){let e=this.element.cloneNode(!0);for(this.element.replaceWith(e),this.element=e;this.element.firstChild;)this.element.removeChild(this.element.firstChild)}}onInit(){}onCreate(){}onRender(){}onUpdate(){}onDestroy(){}}function n(e){return Object.getPrototypeOf(e)===t}class r{constructor(e,t,n=[]){this.type=e,this.props=t,this.children=n}}class i{constructor(e){this.type="ELEMENT_LIST",this.children=e}forEach(e){this.children.forEach(e)}}function s(e){return"function"==typeof e}class o{constructor(e,t,n){this.type=e,this.name=t,this.value=n}init(){}}class a extends o{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return null;const n=t.get(e);if(!s(n))throw new Error(`${e} is not a function!`);return n.bind(t.target)};if("string"===this.value.type)n=r(this.value.value);else if("expression"===this.value.type){if(n=this.value.value,!s(n))throw new Error("Event handler requires a function!")}else"dynamic_value"===this.value.type&&(n=r(this.value.value.objectName));n&&e.addEventListener(this.name,n)}}class l extends o{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");t.reactor.addBinding((()=>{let n=t.get();this.bindAttr(e,n)})),this.bindAttr(e,t.get())}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target),r=t.find(this.value.value.objectName);if(!r)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");r.reactor.addBinding((()=>{let n=this.value.evaluator?.(t.target);this.bindAttr(e,n)})),this.bindAttr(e,n)}}normalizeValue(e){return"object"==typeof e?e.toString?.()??"":e}async bindAttr(e,t){switch(this.name){case"html":e.innerHTML=this.normalizeValue(t);break;case"text":e.textContent=this.normalizeValue(t);break;case"show":e.style.display=this.normalizeValue(t)?"block":"none";break;case"hide":e.style.display=this.normalizeValue(t)?"none":"block";break;case"className":e.className=this.normalizeValue(t);break;case"style":Object.assign(e.style,t);break;case"disabled":e.disabled=!!this.normalizeValue(t);break;case"visible":e.style.visibility=this.normalizeValue(t)?"visible":"hidden";break;case"value":e.value=this.normalizeValue(t);break;case"checked":e.checked=this.normalizeValue(t);break;default:e.setAttribute(this.name,this.normalizeValue(t))}}}class c extends o{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");n.set(e)}}}class u extends o{async init(e,t){let n;"expression"===this.value.type?n=this.value.value:"dynamic_value"===this.value.type&&(n=t.find(this.value.value.objectName));const r=()=>{"checkbox"===e.type?n.set(e.checked):"radio"===e.type?e.checked&&n.set(e.value):n.set(e.value)};e.addEventListener("input",r),e.addEventListener("change",r)}}class p extends o{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");n.set(e)}}}const h={on:(e,t)=>new a("on",e,t),bind:(e,t)=>new l("bind",e,t),ref:(e,t)=>new c("ref",e,t),childsRef:(e,t)=>new p("childsRef",e,t),model:(e,t)=>new u("model",e,t)};function f(e,t,n){return function(e,t,n){return h[e]?.(t,n)}(e,t,n)}function d(e,t,...i){return n(e)?g(e,t,i):e===v?v(...i):new r(e,t||{},m(i))}function y(e){return new r("TEXT_ELEMENT",{nodeValue:e},[])}function g(e,t,n){let s=new r("COMPONENT",{...t},new i(m(n)));return s.component=e,s}function v(...e){return new r("FRAGMENT",{},m(e))}function m(e){return e.map((e=>"object"==typeof e?e:y(e)))}window.RUMIOUS_JSX_SUPPORT={createElement:d,createFragment:v,createDirective:f};class b extends HTMLElement{constructor(){super(),this.instance=null,this.ref=null}cleanUp(){Object.setPrototypeOf(this,HTMLUnknownElement.prototype),this.remove()}init(e,t,n={},r,i){this.instance=new e,this.instance.element=this,this.instance.app=i,this.instance.prepare(this,t,n,r),this.instance.onInit()}connectedCallback(){switch(this.instance.renderOptions.mode){case"linear":this.instance.onCreate(),this.instance.requestRender();break;case"async":(async()=>{this.instance.onCreate(),this.instance.requestRender()})();break;case"animate":requestAnimationFrame((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"idle":requestIdleCallback((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"defer":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),0);break;case"delay":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),this.instance.renderOptions.time);break;case"visible":new IntersectionObserver(((e,t)=>{for(const n of e)n.isIntersecting&&(t.disconnect(),this.instance.onCreate(),this.instance.requestRender())})).observe(this)}}disconnectedCallback(){this.instance.onDestroy(),this.instance.requestCleanUp(),this.cleanUp()}}function w(e="r-component"){return window.customElements.get(e)||window.customElements.define(e,class extends b{static tag=e}),document.createElement(e)}class O{constructor(){this.contents=[],this.targets=[],this.observers=new WeakMap}commit(e=[]){this.contents=e}setTarget(e,t,n){this.targets.push({element:e,context:n,renderer:t}),this.observeTarget(e)}observeTarget(e){if(this.observers.has(e))return;const t=new MutationObserver((()=>{e.parentNode||this.removeTarget(e)}));t.observe(document.body,{childList:!0}),this.observers.set(e,t)}removeTarget(e){const t=this.observers.get(e);t&&(t.disconnect(),this.observers.delete(e)),this.targets=this.targets.filter((t=>t.element!==e))}inject(e=!1){for(let t of this.targets)e&&(t.element.textContent=""),this.contents.forEach((e=>{"html"===e.type?t.element.innerHTML=e.value:"text"===e.type?t.element.textContent=e.value:"component"===e.type&&t.renderer(d(e.value,e.props??{},e.child??{}),t.element,t.context)}))}}function k(e){let t=new O;return t.commit([{type:"html",value:e}]),t}function M(e){let t=new O;return t.commit([{type:"text",value:e}]),t}function E(e,t,n={}){if(!e)return t;if(null===(i=e)||"object"!=typeof i&&"function"!=typeof i)return E(y(e),t,n);var i;if(Array.isArray(e)){for(const r of e)E(r,t,n);return t}if(e instanceof r){let r;switch(e.type){case"COMPONENT":return function(e,t,n,r){const i=function(e,t,n,r,i=null){const s=w(e.tag??"r-component");return s.init(e,t,n,r,i?.app),s}(e.component,e.props,e.children,n,r);return t.appendChild(i),t}(e,t,E,n);case"FRAGMENT":case"ELEMENT_LIST":for(const r of e.children)E(r,t,n);return t;case"TEXT_ELEMENT":r=function(e){return document.createTextNode(e.props.nodeValue)}(e);break;default:r=function(e,t){const n=document.createElement(e.type);!function(e,t,n){for(const[r,i]of Object.entries(t||{}))i instanceof o?i.init(e,n):r.startsWith("on")&&/^[a-zA-Z]+([A-Z][a-z]*)*$/.test(r)?e.addEventListener(r.substring(2).toLowerCase(),i):e.setAttribute(r,i)}(n,e.props,t);for(const r of e.children)E(r,n,t);return n}(e,n)}return t.appendChild(r),t}if(e instanceof HTMLElement)return t.appendChild(e),t;if(e instanceof O){if(t instanceof HTMLDocument)throw"Rumious Render: Unsupported inject content in HTMLDocument!";return e.setTarget(t,E,n),e.inject(!0),t}return E(y(JSON.stringify(e)),t,n)}class j{constructor(t=document.createElement("span"),n={}){this.root=t,this.app=this,this.modules=[],this.configs=n,this.renderContext=new e(this)}render(e){this.renderContext.runHooks("onBeforeRender",this.renderContext),E(e,this.root,this.renderContext),this.renderContext.runHooks("onRendered",this.renderContext)}addModule(e,t={}){return e.init(this,t)}}function S(e){let t="";for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){t+=`${n} {`;const r=e[n];for(const e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t+=`${e.replace(/[A-Z]/g,(e=>`-${e.toLowerCase()}`))}: ${r[e]};`);t+="} "}return t.trim()}class R{constructor(e=null,t=[]){this.target=e,this.bindings=t}react(){this.bindings.forEach((e=>e()))}removeBinding(e){for(let t=this.bindings.length-1;t>=0;t--)this.bindings[t]===e&&this.bindings.splice(t,1)}addBinding(e){this.bindings.push(e)}}class x{constructor(e,t="",n){this.state=e,this.path=t,this.fn=n}trigger(...e){let t=this.fn(...e);this.state.set(this.path,t)}}const C="remove",A="replace",P="add",T=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),z=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),D=Symbol.iterator,I={mutable:"mutable",immutable:"immutable"},N={};function _(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function L(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const e=Reflect.getOwnPropertyDescriptor(n,t);if(e)return e;n=Reflect.getPrototypeOf(n)}}}function q(e){return Object.getPrototypeOf(e)===Set.prototype}function V(e){return Object.getPrototypeOf(e)===Map.prototype}function U(e){var t;return null!==(t=e.copy)&&void 0!==t?t:e.original}function F(e){return!!$(e)}function $(e){return"object"!=typeof e?null:null==e?void 0:e[T]}function H(e){var t;const n=$(e);return n?null!==(t=n.copy)&&void 0!==t?t:n.original:e}function B(e,t){if(!e||"object"!=typeof e)return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!(null==t?void 0:t.mark)&&((n=t.mark(e,I))===I.immutable||"function"==typeof n)}function W(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,r=$(K(n,e.key));if(null!==r&&(null==r?void 0:r.original)!==e.original)return null;const i=3===e.parent.type,s=i?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(i&&n.size>s||_(n,s)))return null;t.push(s)}if(e.parent)return W(e.parent,t);t.reverse();try{!function(e,t){for(let n=0;n<t.length-1;n+=1){const r=t[n];if("object"!=typeof(e=K(3===X(e)?Array.from(e):e,r)))throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}}(e.copy,t)}catch(e){return null}return t}function X(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function K(e,t){return 2===X(e)?e.get(t):e[t]}function Y(e,t,n){2===X(e)?e.set(t,n):e[t]=n}function Z(e,t){const n=$(e);return(n?U(n):e)[t]}function G(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function J(e){if(e)for(;e.finalities.revoke.length>0;)e.finalities.revoke.pop()()}function Q(e,t){return t?e:[""].concat(e).map((e=>{const t=`${e}`;return-1===t.indexOf("/")&&-1===t.indexOf("~")?t:t.replace(/~/g,"~0").replace(/\//g,"~1")})).join("/")}const ee=Object.prototype.propertyIsEnumerable;function te(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set)return q(e)?Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values()):new(0,Object.getPrototypeOf(e).constructor)(e.values());if(e instanceof Map)return V(e)?new Map(e):new(0,Object.getPrototypeOf(e).constructor)(e);if((null==t?void 0:t.mark)&&(n=t.mark(e,I),void 0!==n)&&n!==I.mutable){if(n===I.immutable)return function(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((n=>{let r=Reflect.getOwnPropertyDescriptor(e,n);r.enumerable&&r.configurable&&r.writable?t[n]=e[n]:(r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:e[n]}),Reflect.defineProperty(t,n,r))})),t}(e);if("function"==typeof n){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return n()}throw new Error(`Unsupported mark result: ${n}`)}if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype){const t={};return Object.keys(e).forEach((n=>{t[n]=e[n]})),Object.getOwnPropertySymbols(e).forEach((n=>{ee.call(e,n)&&(t[n]=e[n])})),t}throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function ne(e){e.copy||(e.copy=te(e.original,e.options))}function re(e){if(!B(e))return H(e);if(Array.isArray(e))return e.map(re);if(e instanceof Map){const t=Array.from(e.entries()).map((([e,t])=>[e,re(t)]));return V(e)?new Map(t):new(0,Object.getPrototypeOf(e).constructor)(t)}if(e instanceof Set){const t=Array.from(e).map(re);return q(e)?new Set(t):new(0,Object.getPrototypeOf(e).constructor)(t)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=re(e[n]);return t}function ie(e){return F(e)?re(e):e}function se(e){var t;e.assignedMap=null!==(t=e.assignedMap)&&void 0!==t?t:new Map,e.operated||(e.operated=!0,e.parent&&se(e.parent))}function oe(){throw new Error("Cannot modify frozen object")}function ae(e,t,n,r,i){{n=null!=n?n:new WeakMap,r=null!=r?r:[],i=null!=i?i:[];const s=n.has(e)?n.get(e):e;if(r.length>0){const e=r.indexOf(s);if(s&&"object"==typeof s&&-1!==e){if(r[0]===s)throw new Error("Forbids circular reference");throw new Error(`Forbids circular reference: ~/${i.slice(0,e).map(((e,t)=>{if("symbol"==typeof e)return`[${e.toString()}]`;const n=r[t];return"object"==typeof e&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(e):e})).join("/")}`)}r.push(s),i.push(t)}else r.push(s)}if(Object.isFrozen(e)||F(e))return r.pop(),void i.pop();switch(X(e)){case 2:for(const[t,s]of e)ae(t,t,n,r,i),ae(s,t,n,r,i);e.set=e.clear=e.delete=oe;break;case 3:for(const t of e)ae(t,t,n,r,i);e.add=e.clear=e.delete=oe;break;case 1:Object.freeze(e);let t=0;for(const s of e)ae(s,t,n,r,i),t+=1;break;default:Object.freeze(e),Object.keys(e).forEach((t=>{ae(e[t],t,n,r,i)}))}r.pop(),i.pop()}function le(e,t){const n=X(e);if(0===n)Reflect.ownKeys(e).forEach((n=>{t(n,e[n],e)}));else if(1===n){let n=0;for(const r of e)t(n,r,e),n+=1}else e.forEach(((n,r)=>t(r,n,e)))}function ce(e,t,n){if(F(e)||!B(e,n)||t.has(e)||Object.isFrozen(e))return;const r=e instanceof Set,i=r?new Map:void 0;if(t.add(e),le(e,((s,o)=>{var a;if(F(o)){const t=$(o);ne(t);const n=(null===(a=t.assignedMap)||void 0===a?void 0:a.size)||t.operated?t.copy:t.original;Y(r?i:e,s,n)}else ce(o,t,n)})),i){const t=e,n=Array.from(t);t.clear(),n.forEach((e=>{t.add(i.has(e)?i.get(e):e)}))}}function ue(e,t){const n=3===e.type?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&ce(K(n,t),e.finalities.handledSet,e.options)}function pe(e){3===e.type&&e.copy&&(e.copy.clear(),e.setMap.forEach((t=>{e.copy.add(H(t))})))}function he(e,t,n,r){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&r){const i=W(e);i&&t(e,i,n,r)}e.finalized=!0}}function fe(e,t,n,r){const i=$(n);i&&(i.callbacks||(i.callbacks=[]),i.callbacks.push(((s,o)=>{var a;const l=3===e.type?e.setMap:e.copy;if(G(K(l,t),n)){let n=i.original;i.copy&&(n=i.copy),pe(e),he(e,r,s,o),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(a=e.options.updatedValues)&&void 0!==a?a:new WeakMap,e.options.updatedValues.set(n,i.original)),Y(l,t,n)}})),e.options.enableAutoFreeze&&i.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),B(n,e.options)&&e.finalities.draft.push((()=>{G(K(3===e.type?e.setMap:e.copy,t),n)&&ue(e,t)}))}function de(e,t,n,r){const{pathAsArray:i=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return function({original:e,copy:t,assignedMap:n},r,i,s,o){n.forEach(((n,a)=>{const l=K(e,a),c=ie(K(t,a)),u=n?_(e,a)?A:P:C;if(G(l,c)&&u===A)return;const p=Q(r.concat(a),o);i.push(u===C?{op:u,path:p}:{op:u,path:p,value:c}),s.push(u===P?{op:C,path:p}:u===C?{op:P,path:p,value:l}:{op:A,path:p,value:l})}))}(e,t,n,r,i);case 1:return function(e,t,n,r,i){let{original:s,assignedMap:o,options:a}=e,l=e.copy;l.length<s.length&&([s,l]=[l,s],[n,r]=[r,n]);for(let e=0;e<s.length;e+=1)if(o.get(e.toString())&&l[e]!==s[e]){const o=Q(t.concat([e]),i);n.push({op:A,path:o,value:ie(l[e])}),r.push({op:A,path:o,value:ie(s[e])})}for(let e=s.length;e<l.length;e+=1){const r=Q(t.concat([e]),i);n.push({op:P,path:r,value:ie(l[e])})}if(s.length<l.length){const{arrayLengthAssignment:e=!0}=a.enablePatches;if(e){const e=Q(t.concat(["length"]),i);r.push({op:A,path:e,value:s.length})}else for(let e=l.length;s.length<e;e-=1){const n=Q(t.concat([e-1]),i);r.push({op:C,path:n})}}}(e,t,n,r,i);case 3:return function({original:e,copy:t},n,r,i,s){let o=0;e.forEach((e=>{if(!t.has(e)){const t=Q(n.concat([o]),s);r.push({op:C,path:t,value:e}),i.unshift({op:P,path:t,value:e})}o+=1})),o=0,t.forEach((t=>{if(!e.has(t)){const e=Q(n.concat([o]),s);r.push({op:P,path:e,value:t}),i.unshift({op:C,path:e,value:t})}o+=1}))}(e,t,n,r,i)}}const ye=(e,t,n=!1)=>{if("object"==typeof e&&null!==e&&(!B(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},ge={get size(){return U($(this)).size},has(e){return U($(this)).has(e)},set(e,t){const n=$(this),r=U(n);return r.has(e)&&G(r.get(e),t)||(ne(n),se(n),n.assignedMap.set(e,!0),n.copy.set(e,t),fe(n,e,t,de)),this},delete(e){if(!this.has(e))return!1;const t=$(this);return ne(t),se(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=$(this);if(this.size){ne(e),se(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){U($(this)).forEach(((n,r)=>{e.call(t,this.get(r),r,this)}))},get(e){var t,n;const r=$(this),i=U(r).get(e),s=(null===(n=(t=r.options).mark)||void 0===n?void 0:n.call(t,i,I))===I.mutable;if(r.options.strict&&ye(i,r.options,s),s)return i;if(r.finalized||!B(i,r.options))return i;if(i!==r.original.get(e))return i;const o=N.createDraft({original:i,parentDraft:r,key:e,finalities:r.finalities,options:r.options});return ne(r),r.copy.set(e,o),o},keys(){return U($(this)).keys()},values(){const e=this.keys();return{[D]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[D]:()=>this.entries(),next:()=>{const t=e.next();if(t.done)return t;const n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[D](){return this.entries()}},ve=Reflect.ownKeys(ge),me=(e,t,{isValuesIterator:n})=>()=>{var r,i;const s=t.next();if(s.done)return s;const o=s.value;let a=e.setMap.get(o);const l=$(a),c=(null===(i=(r=e.options).mark)||void 0===i?void 0:i.call(r,a,I))===I.mutable;if(e.options.strict&&ye(o,e.options,c),c||l||!B(o,e.options)||e.finalized||!e.original.has(o))l&&(a=l.proxy);else{const t=N.createDraft({original:o,parentDraft:e,key:o,finalities:e.finalities,options:e.options});e.setMap.set(o,t),a=t}return{done:!1,value:n?a:[a,a]}},be={get size(){return $(this).setMap.size},has(e){const t=$(this);if(t.setMap.has(e))return!0;ne(t);const n=$(e);return!(!n||!t.setMap.has(n.original))},add(e){const t=$(this);return this.has(e)||(ne(t),se(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),fe(t,e,e,de)),this},delete(e){if(!this.has(e))return!1;const t=$(this);ne(t),se(t);const n=$(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;const e=$(this);ne(e),se(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=$(this);ne(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:me(e,t,{isValuesIterator:!0})}},entries(){const e=$(this);ne(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:me(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[D](){return this.values()},forEach(e,t){const n=this.values();let r=n.next();for(;!r.done;)e.call(t,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(be,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const we=Reflect.ownKeys(be),Oe=new WeakSet,ke={get(e,t,n){var r,i;const s=null===(r=e.copy)||void 0===r?void 0:r[t];if(s&&Oe.has(s))return s;if(t===T)return e;let o;if(e.options.mark){const r="size"===t&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(o=e.options.mark(r,I),o===I.mutable)return e.options.strict&&ye(r,e.options,!0),r}const a=U(e);if(a instanceof Map&&ve.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(ge,"size").get.call(e.proxy);const n=ge[t];if(n)return n.bind(e.proxy)}if(a instanceof Set&&we.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(be,"size").get.call(e.proxy);const n=be[t];if(n)return n.bind(e.proxy)}if(!_(a,t)){const n=L(a,t);return n?"value"in n?n.value:null===(i=n.get)||void 0===i?void 0:i.call(e.proxy):void 0}const l=a[t];if(e.options.strict&&ye(l,e.options),e.finalized||!B(l,e.options))return l;if(l===Z(e.original,t)){if(ne(e),e.copy[t]=Me({original:e.original[t],parentDraft:e,key:1===e.type?Number(t):t,finalities:e.finalities,options:e.options}),"function"==typeof o){const n=$(e.copy[t]);return ne(n),se(n),n.copy}return e.copy[t]}return l},set(e,t,n){var r;if(3===e.type||2===e.type)throw new Error("Map/Set draft does not support any property assignment.");let i;if(1===e.type&&"length"!==t&&(!(Number.isInteger(i=Number(t))&&i>=0)||0!==t&&0!==i&&String(i)!==String(t)))throw new Error("Only supports setting array indices and the 'length' property.");const s=L(U(e),t);if(null==s?void 0:s.set)return s.set.call(e.proxy,n),!0;const o=Z(U(e),t),a=$(o);return a&&G(a.original,n)?(e.copy[t]=n,e.assignedMap=null!==(r=e.assignedMap)&&void 0!==r?r:new Map,e.assignedMap.set(t,!1),!0):(G(n,o)&&(void 0!==n||_(e.original,t))||(ne(e),se(e),_(e.original,t)&&G(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,fe(e,t,n,de)),!0)},has:(e,t)=>t in U(e),ownKeys:e=>Reflect.ownKeys(U(e)),getOwnPropertyDescriptor(e,t){const n=U(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{writable:!0,configurable:1!==e.type||"length"!==t,enumerable:r.enumerable,value:n[t]}:r},getPrototypeOf:e=>Reflect.getPrototypeOf(e.original),setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(e,t){var n;return 1===e.type?ke.set.call(this,e,t,void 0,e.proxy):(void 0!==Z(e.original,t)||t in e.original?(ne(e),se(e),e.assignedMap.set(t,!1)):(e.assignedMap=null!==(n=e.assignedMap)&&void 0!==n?n:new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function Me(e){const{original:t,parentDraft:n,key:r,finalities:i,options:s}=e,o=X(t),a={type:o,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:i,options:s,setMap:3===o?new Map(t.entries()):void 0};(r||"key"in e)&&(a.key=r);const{proxy:l,revoke:c}=Proxy.revocable(1===o?Object.assign([],a):a,ke);if(i.revoke.push(c),Oe.add(l),a.proxy=l,n){const e=n;e.finalities.draft.push(((t,n)=>{var i,s;const o=$(l);let a=3===e.type?e.setMap:e.copy;const c=K(a,r),u=$(c);if(u){let s=u.original;u.operated&&(s=H(c)),pe(u),he(u,de,t,n),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(i=e.options.updatedValues)&&void 0!==i?i:new WeakMap,e.options.updatedValues.set(s,u.original)),Y(a,r,s)}null===(s=o.callbacks)||void 0===s||s.forEach((e=>{e(t,n)}))}))}else{const e=$(l);e.finalities.draft.push(((t,n)=>{pe(e),he(e,de,t,n)}))}return l}function Ee(e,t,n,r,i){var s;const o=$(e),a=null!==(s=null==o?void 0:o.original)&&void 0!==s?s:e,l=!!t.length;if(null==o?void 0:o.operated)for(;o.finalities.draft.length>0;)o.finalities.draft.pop()(n,r);const c=l?t[0]:o?o.operated?o.copy:o.original:e;return o&&J(o),i&&ae(c,c,null==o?void 0:o.options.updatedValues),[c,n&&l?[{op:A,path:[],value:t[0]}]:n,r&&l?[{op:A,path:[],value:a}]:r]}function je(e){const{rootDraft:t,value:n,useRawReturn:r=!1,isRoot:i=!0}=e;le(n,((n,r,i)=>{const s=$(r);if(s&&t&&s.finalities===t.finalities){e.isContainDraft=!0;const t=s.original;if(i instanceof Set){const e=Array.from(i);i.clear(),e.forEach((e=>i.add(n===e?t:e)))}else Y(i,n,t)}else"object"==typeof r&&null!==r&&(e.value=r,e.isRoot=!1,je(e))})),i&&e.isContainDraft}function Se(e){var t;const n=$(e);if(!B(e,null==n?void 0:n.options))return e;const r=X(e);if(n&&!n.operated)return n.original;let i;function s(){i=2===r?V(e)?new Map(e):new(Object.getPrototypeOf(e).constructor)(e):3===r?Array.from(n.setMap.values()):te(e,null==n?void 0:n.options)}if(n){n.finalized=!0;try{s()}finally{n.finalized=!1}}else i=e;if(le(i,((t,r)=>{if(n&&G(K(n.original,t),r))return;const o=Se(r);o!==r&&(i===e&&s(),Y(i,t,o))})),3===r){const e=null!==(t=null==n?void 0:n.original)&&void 0!==t?t:i;return q(e)?new Set(i):new(Object.getPrototypeOf(e).constructor)(i)}return i}function Re(e){if(!F(e))throw new Error(`current() is only used for Draft, parameter: ${e}`);return Se(e)}N.createDraft=Me;const xe=function e(t,n,r){var i,s,o;if("function"==typeof t&&"function"!=typeof n)return function(r,...i){return e(r,(e=>t.call(this,e,...i)),n)};const a=t,l=n;let c=r;if("function"!=typeof n&&(c=n),void 0!==c&&"[object Object]"!==Object.prototype.toString.call(c))throw new Error(`Invalid options: ${c}, 'options' should be an object.`);c=Object.assign(Object.assign({},void 0),c);const u=F(a)?Re(a):a,p=Array.isArray(c.mark)?(e,t)=>{for(const n of c.mark){if("function"!=typeof n)throw new Error(`Invalid mark: ${n}, 'mark' should be a function.`);const r=n(e,t);if(r)return r}}:c.mark,h=null!==(i=c.enablePatches)&&void 0!==i&&i,f=null!==(s=c.strict)&&void 0!==s&&s,d={enableAutoFreeze:null!==(o=c.enableAutoFreeze)&&void 0!==o&&o,mark:p,strict:f,enablePatches:h};if(!B(u,d)&&"object"==typeof u&&null!==u)throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");const[y,g]=function(e,t){var n;const r={draft:[],revoke:[],handledSet:new WeakSet};let i,s;t.enablePatches&&(i=[],s=[]);const o=(null===(n=t.mark)||void 0===n?void 0:n.call(t,e,I))!==I.mutable&&B(e,t)?Me({original:e,parentDraft:null,finalities:r,options:t}):e;return[o,(e=[])=>{const[n,r,a]=Ee(o,e,i,s,t.enableAutoFreeze);return t.enablePatches?[n,r,a]:n}]}(u,d);if("function"!=typeof n){if(!B(u,d))throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");return[y,g]}let v;try{v=l(y)}catch(e){throw J($(y)),e}const m=e=>{const t=$(y);if(!F(e)){if(void 0!==e&&!G(e,y)&&(null==t?void 0:t.operated))throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");const n=null==e?void 0:e[z];if(n){const r=n[0];return d.strict&&"object"==typeof e&&null!==e&&je({rootDraft:t,value:e,useRawReturn:!0}),g([r])}if(void 0!==e)return"object"==typeof e&&null!==e&&je({rootDraft:t,value:e}),g([e])}if(e===y||void 0===e)return g([]);const n=$(e);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return g([Re(e)])}return g([e])};return v instanceof Promise?v.then(m,(e=>{throw J($(y)),e})):m(v)};function Ce(e,t){e.set(xe(e.get(),t))}Object.prototype.constructor.toString();class Ae{constructor(e,t=null){this.value=e,this.reactor=t??new R(this,[])}produce(e){return Ce(this,e)}reducer(...e){let t;return t=1===e.length?new x(this,"",e[0]):new x(this,e[0],e[1]),t.trigger.bind(t)}setObjectByPath(e="",t){if(0===e.length)return void(this.value=t);if("string"!=typeof e||!e)throw new Error("Invalid path");let n=e.split("."),r=this.value;for(let e=0;e<n.length-1;e++){let t=n[e];t in r||(r[t]={}),r=r[t]}r[n[n.length-1]]=t}set(...e){if(1===e.length)this.value=e[0];else{let t=e[0],n=e[1];this.setObjectByPath(t,n)}this.reactor.react()}get(){return this.value}}function Pe(e){return new Ae(e)}function Te(e){return e instanceof Ae}function ze(e,t){e.reactor.addBinding(t)}function De(e,t){e.reactor.removeBinding(t)}class Ie{constructor(e){this.target=e}set html(e){this.target.innerHTML=e}query(e){return this.target.querySelectorAll(e)}set text(e){this.target.textContent=e}on(e,t){this.target.addEventListener(e,t)}off(e,t){this.target.removeEventListener(e,t)}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}function Ne(e){return new Ie(e)}class _e{constructor(e){this.target=e}query(e){return this.target.querySelectorAll(e)}index(e){return Array.from(this.target.children)[e]}list(){return Array.from(this.target.children)}get parent(){return this.target}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}function Le(e){return new _e(e)}class qe{constructor(e){this.target=e}set(e){this.target=e.forwardRefs}}function Ve(e){return new qe(e)}window.RUMIOUS_CONTEXTS||(window.RUMIOUS_CONTEXTS={});class Ue{constructor(e={}){this.data=e,this.events={}}on(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)))}emit(e,...t){this.events[e]&&this.events[e].forEach((e=>e(...t)))}set(e,t){let n=Pe(t);return this.data[e]=n,n}get(e){return this.data[e]}}function Fe(e="",t={}){if(!t||"object"!=typeof t)throw"Rumious context: Initial value must be object !";return window.RUMIOUS_CONTEXTS[e]||(window.RUMIOUS_CONTEXTS[e]=new Ue(t)),window.RUMIOUS_CONTEXTS[e]}class $e extends t{static tag="r-pending";constructor(){super(),this.asynchronousRender=!0}async setLoader(e){this.loader=e;try{this.result=await this.loader.execute(),this.renderResult()}catch(e){this.error=e,this.renderError()}}renderResult(){if(!this.result)throw"Rumious Render: Cannot find component when lazy loading!";this.element.before(this.render(d(this.result,{}))),this.element.remove()}renderError(){this.element.appendChild(this.render(this.props.errorComponent??this.error))}onRender(){let{loader:e}=this.props;this.setLoader(e)}template(){return this.props.fallback}}class He{constructor(e,t={}){this.hasExecuted=!1,this.result=null,this.callback=e,this.dependents=[],this.options=t}onLoad(e){this.hasExecuted?e(this.result):this.dependents.push(e)}execute(){return new Promise(((e,t)=>{if(this.hasExecuted)return e(this.result);this.hasExecuted=!0;const n=async()=>{try{this.result=await this.callback(),e(this.result),this.dependents.forEach((e=>e(this.result)))}catch(e){t(e)}};this.options.idle&&"requestIdleCallback"in window?requestIdleCallback(n):n()}))}}const Be=new Map;function We(e,t={}){const n=t.key||e.toString();return Be.has(n)||Be.set(n,new He(e,t)),Be.get(n)}function Xe(e,t){let n=0;return function(...r){const i=Date.now();i-n>=t&&(n=i,e.apply(this,r))}}function Ke(e,t){let n;return function(...r){clearTimeout(n),n=setTimeout((()=>e.apply(this,r)),t)}}function Ye(e,t){let n=0,r=null,i=null;function s(){n=Date.now(),e.apply(this,r),r=null}return function(...e){const o=Date.now();r=e,o-n>=t?s():i||(i=setTimeout((()=>{i=null,s()}),t-(o-n)))}}function Ze(e,t){let n,r=!0;return function(...i){r&&(e.apply(this,i),r=!1),clearTimeout(n),n=setTimeout((()=>{e.apply(this,i),r=!0}),t)}}function Ge(e){let t=!1;return function(...n){t||(t=!0,requestAnimationFrame((()=>{e.apply(this,n),t=!1})))}}export{$e as Pending,j as RumiousApp,_e as RumiousChildrensRef,t as RumiousComponent,b as RumiousComponentElement,qe as RumiousComponentRef,Ue as RumiousContext,O as RumiousDymanicInjector,Ie as RumiousElementRef,He as RumiousLazyLoader,R as RumiousReactor,x as RumiousReducer,Ae as RumiousState,Le as createChildrensRef,g as createComponent,w as createComponentElement,Ve as createComponentRef,Fe as createContext,f as createDirective,d as createElement,Ne as createElementRef,Pe as createState,y as createTextElement,Ke as denounce,k as injectHTML,M as injectText,n as isComponent,Te as isState,We as lazyLoad,Ze as leadingTrailingDebounce,Ce as produceState,Ge as rafThrottle,S as styleHelper,Xe as tholle,Ye as trailingThrottle,De as unwatch,ze as watch};
1
+ class e{constructor(e){this.target=e,this.app=e.app,this.hooks={onRendered:[],onBeforeRender:[]}}find(e){return this.target[e]}get(e){return this.target[e]}addHook(e,t){if(!this.hooks[e])throw new Error(`Hook type "${e}" is not defined!`);this.hooks[e].push(t)}async runHooks(e,...t){if(this.hooks[e])for(const n of this.hooks[e])await n(...t)}}class t{constructor(){this.renderOptions={mode:"linear"},this.element=null,this.app=null,this.props={},this.forwardRefs={},this.renderContext=new e(this),this.renderer=null,this.wrapped=null}prepare(e,t,n={},r=null){this.element=e,this.props=t,this.renderer=r,this.wrapped=n,this.renderContext.app=this.app}template(){return{}}render(e){return this.renderer(e,document.createDocumentFragment(),this.renderContext)}async requestRender(){await this.onBeforeRender();let e=this.template(),t=this.renderer(e,document.createDocumentFragment(),this.renderContext);this.element.appendChild(t),this.onRender()}async requestCleanUp(){if(this.element){let e=this.element.cloneNode(!0);for(this.element.replaceWith(e),this.element=e;this.element.firstChild;)this.element.removeChild(this.element.firstChild)}}onInit(){}onCreate(){}async onBeforeRender(){}onRender(){}onUpdate(){}onDestroy(){}}function n(e){return Object.getPrototypeOf(e)===t}class r{constructor(e,t,n=[]){this.type=e,this.props=t,this.children=n}}class i{constructor(e){this.type="ELEMENT_LIST",this.children=e}forEach(e){this.children.forEach(e)}}function s(e){return"function"==typeof e}class o{constructor(e,t,n){this.type=e,this.name=t,this.value=n}init(){}}class a extends o{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return null;const n=t.get(e);if(!s(n))throw new Error(`${e} is not a function!`);return n.bind(t.target)};if("string"===this.value.type)n=r(this.value.value);else if("expression"===this.value.type){if(n=this.value.value,!s(n))throw new Error("Event handler requires a function!")}else"dynamic_value"===this.value.type&&(n=r(this.value.value.objectName));n&&e.addEventListener(this.name,n)}}class l extends o{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");t.reactor.addBinding((()=>{let n=t.get();this.bindAttr(e,n)})),this.bindAttr(e,t.get())}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target),r=t.find(this.value.value.objectName);if(!r)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");r.reactor.addBinding((()=>{let n=this.value.evaluator?.(t.target);this.bindAttr(e,n)})),this.bindAttr(e,n)}}normalizeValue(e){return"object"==typeof e?e.toString?.()??"":e}async bindAttr(e,t){switch(this.name){case"html":e.innerHTML=this.normalizeValue(t);break;case"text":e.textContent=this.normalizeValue(t);break;case"show":e.style.display=this.normalizeValue(t)?"block":"none";break;case"hide":e.style.display=this.normalizeValue(t)?"none":"block";break;case"className":e.className=this.normalizeValue(t);break;case"style":Object.assign(e.style,t);break;case"disabled":e.disabled=!!this.normalizeValue(t);break;case"visible":e.style.visibility=this.normalizeValue(t)?"visible":"hidden";break;case"value":e.value=this.normalizeValue(t);break;case"checked":e.checked=this.normalizeValue(t);break;default:e.setAttribute(this.name,this.normalizeValue(t))}}}class c extends o{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");n.set(e)}}}class u extends o{async init(e,t){let n;"expression"===this.value.type?n=this.value.value:"dynamic_value"===this.value.type&&(n=t.find(this.value.value.objectName));const r=()=>{"checkbox"===e.type?n.set(e.checked):"radio"===e.type?e.checked&&n.set(e.value):n.set(e.value)};e.addEventListener("input",r),e.addEventListener("change",r)}}class h extends o{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");n.set(e)}}}const p={on:(e,t)=>new a("on",e,t),bind:(e,t)=>new l("bind",e,t),ref:(e,t)=>new c("ref",e,t),childsRef:(e,t)=>new h("childsRef",e,t),model:(e,t)=>new u("model",e,t)};function f(e,t,n){return function(e,t,n){return p[e]?.(t,n)}(e,t,n)}function d(e,t,...i){return n(e)?v(e,t,i):e===g?g(...i):new r(e,t||{},m(i))}function y(e){return new r("TEXT_ELEMENT",{nodeValue:e},[])}function v(e,t,n){let s=new r("COMPONENT",{...t},new i(m(n)));return s.component=e,s}function g(...e){return new r("FRAGMENT",{},m(e))}function m(e){return e.map((e=>"object"==typeof e?e:y(e)))}window.RUMIOUS_JSX_SUPPORT={createElement:d,createFragment:g,createDirective:f};class b extends HTMLElement{constructor(){super(),this.instance=null,this.ref=null}cleanUp(){Object.setPrototypeOf(this,HTMLUnknownElement.prototype),this.remove()}init(e,t,n={},r,i){this.instance=new e,this.instance.element=this,this.instance.app=i,this.instance.prepare(this,t,n,r),this.instance.onInit()}connectedCallback(){switch(this.instance.renderOptions.mode){case"linear":this.instance.onCreate(),this.instance.requestRender();break;case"async":(async()=>{this.instance.onCreate(),this.instance.requestRender()})();break;case"animate":requestAnimationFrame((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"idle":requestIdleCallback((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"defer":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),0);break;case"delay":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),this.instance.renderOptions.time);break;case"visible":new IntersectionObserver(((e,t)=>{for(const n of e)n.isIntersecting&&(t.disconnect(),this.instance.onCreate(),this.instance.requestRender())})).observe(this)}}disconnectedCallback(){this.instance.onDestroy(),this.instance.requestCleanUp(),this.cleanUp()}}function w(e="r-component"){return window.customElements.get(e)||window.customElements.define(e,class extends b{static tag=e}),document.createElement(e)}class E{constructor(){this.contents=[],this.targets=[],this.observers=new WeakMap}commit(e=[]){this.contents=e}setTarget(e,t,n){this.targets.push({element:e,context:n,renderer:t}),this.observeTarget(e)}observeTarget(e){if(this.observers.has(e))return;const t=new MutationObserver((()=>{e.parentNode||this.removeTarget(e)}));t.observe(document.body,{childList:!0}),this.observers.set(e,t)}removeTarget(e){const t=this.observers.get(e);t&&(t.disconnect(),this.observers.delete(e)),this.targets=this.targets.filter((t=>t.element!==e))}inject(e=!1){for(let t of this.targets)e&&(t.element.textContent=""),this.contents.forEach((e=>{"html"===e.type?t.element.innerHTML=e.value:"text"===e.type?t.element.textContent=e.value:"component"===e.type&&t.renderer(d(e.value,e.props??{},e.child??{}),t.element,t.context)}))}}function O(e){let t=new E;return t.commit([{type:"html",value:e}]),t}function k(e){let t=new E;return t.commit([{type:"text",value:e}]),t}function M(e,t){return new j(e,t)}class j{constructor(e,t){this.state=e,this.template=t,this.target=null}setTarget(e,t,n){this.target={element:e,context:n,renderer:t}}sync(){this.target&&(this.renderAll(),this.state.reactor.addBinding((e=>this.onChange(e))))}renderAll(){this.target.element.textContent="",this.state.value.forEach(((e,t)=>this.appendElement(e,t)))}appendElement(e,t){let n=this.template(e,t),r=this.target.renderer(n,document.createDocumentFragment(),this.target.context);this.target.element.appendChild(r)}onChange(e){if(this.target)switch(e.type){case"REMOVE_ELEMENT":{let t=this.target.element.children[e.index];t&&this.target.element.removeChild(t);break}case"SET_VALUE":this.renderAll();break;case"ADD_ELEMENT":this.appendElement(e.value,e.index);break;case"SET_ELEMENT":{let t=this.template(e.value,e.index),n=this.target.renderer(t,document.createDocumentFragment(),this.target.context);!function(e,t,n){let r=e.children;t>=0&&t<r.length?e.replaceChild(n,r[t]):e.appendChild(n)}(this.target.element,e.index,n);break}case"INSERT_ELEMENT":{let t=this.template(e.value,e.index),n=this.target.renderer(t,document.createDocumentFragment(),this.target.context),r=this.target.element.children;e.index>=r.length?this.target.element.appendChild(n):this.target.element.insertBefore(n.children[0],r[e.index]);break}}}}function x(e,t,n={}){if(!e)return t;if(null===(i=e)||"object"!=typeof i&&"function"!=typeof i)return x(y(e),t,n);var i;if(Array.isArray(e)){for(const r of e)x(r,t,n);return t}if(e instanceof r){let r;switch(e.type){case"COMPONENT":return function(e,t,n,r){const i=function(e,t,n,r,i=null){const s=w(e.tag??"r-component");return s.init(e,t,n,r,i?.app),s}(e.component,e.props,e.children,n,r);return t.appendChild(i),t}(e,t,x,n);case"FRAGMENT":case"ELEMENT_LIST":for(const r of e.children)x(r,t,n);return t;case"TEXT_ELEMENT":r=function(e){return document.createTextNode(e.props.nodeValue)}(e);break;default:r=function(e,t){const n=document.createElement(e.type);!function(e,t,n){for(const[r,i]of Object.entries(t||{}))i instanceof o?i.init(e,n):r.startsWith("on")&&/^[a-zA-Z]+([A-Z][a-z]*)*$/.test(r)?e.addEventListener(r.substring(2).toLowerCase(),i):e.setAttribute(r,i)}(n,e.props,t);for(const r of e.children)x(r,n,t);return n}(e,n)}return t.appendChild(r),t}if(e instanceof HTMLElement)return t.appendChild(e),t;if(e instanceof E){if(t instanceof HTMLDocument)throw"Rumious Render: Unsupported inject content in HTMLDocument!";return e.setTarget(t,x,n),e.inject(!0),t}if(e instanceof j){if(t instanceof HTMLDocument)throw"Rumious Render: Unsupported sync data of array in HTMLDocument!";return e.setTarget(t,x,n),e.sync(),t}return x(y(JSON.stringify(e)),t,n)}class S{constructor(t=document.createElement("span"),n={}){this.root=t,this.app=this,this.modules=[],this.configs=n,this.renderContext=new e(this)}render(e){this.renderContext.runHooks("onBeforeRender",this.renderContext),x(e,this.root,this.renderContext),this.renderContext.runHooks("onRendered",this.renderContext)}addModule(e,t={}){return e.init(this,t)}}function R(e){let t="";for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){t+=`${n} {`;const r=e[n];for(const e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t+=`${e.replace(/[A-Z]/g,(e=>`-${e.toLowerCase()}`))}: ${r[e]};`);t+="} "}return t.trim()}class T{constructor(e=null,t=[]){this.target=e,this.bindings=t}react(e){this.bindings.forEach((t=>t(e)))}removeBinding(e){for(let t=this.bindings.length-1;t>=0;t--)this.bindings[t]===e&&this.bindings.splice(t,1)}addBinding(e){this.bindings.push(e)}}class C{constructor(e,t="",n){this.state=e,this.path=t,this.fn=n}trigger(...e){let t=this.fn(...e);this.state.set(this.path,t)}}const A="remove",P="replace",z="add",D=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),L=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),_=Symbol.iterator,N={mutable:"mutable",immutable:"immutable"},I={};function V(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function U(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const e=Reflect.getOwnPropertyDescriptor(n,t);if(e)return e;n=Reflect.getPrototypeOf(n)}}}function q(e){return Object.getPrototypeOf(e)===Set.prototype}function F(e){return Object.getPrototypeOf(e)===Map.prototype}function B(e){var t;return null!==(t=e.copy)&&void 0!==t?t:e.original}function H(e){return!!$(e)}function $(e){return"object"!=typeof e?null:null==e?void 0:e[D]}function W(e){var t;const n=$(e);return n?null!==(t=n.copy)&&void 0!==t?t:n.original:e}function X(e,t){if(!e||"object"!=typeof e)return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!(null==t?void 0:t.mark)&&((n=t.mark(e,N))===N.immutable||"function"==typeof n)}function K(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,r=$(Y(n,e.key));if(null!==r&&(null==r?void 0:r.original)!==e.original)return null;const i=3===e.parent.type,s=i?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(i&&n.size>s||V(n,s)))return null;t.push(s)}if(e.parent)return K(e.parent,t);t.reverse();try{!function(e,t){for(let n=0;n<t.length-1;n+=1){const r=t[n];if("object"!=typeof(e=Y(3===G(e)?Array.from(e):e,r)))throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}}(e.copy,t)}catch(e){return null}return t}function G(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function Y(e,t){return 2===G(e)?e.get(t):e[t]}function Z(e,t,n){2===G(e)?e.set(t,n):e[t]=n}function J(e,t){const n=$(e);return(n?B(n):e)[t]}function Q(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function ee(e){if(e)for(;e.finalities.revoke.length>0;)e.finalities.revoke.pop()()}function te(e,t){return t?e:[""].concat(e).map((e=>{const t=`${e}`;return-1===t.indexOf("/")&&-1===t.indexOf("~")?t:t.replace(/~/g,"~0").replace(/\//g,"~1")})).join("/")}const ne=Object.prototype.propertyIsEnumerable;function re(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set)return q(e)?Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values()):new(0,Object.getPrototypeOf(e).constructor)(e.values());if(e instanceof Map)return F(e)?new Map(e):new(0,Object.getPrototypeOf(e).constructor)(e);if((null==t?void 0:t.mark)&&(n=t.mark(e,N),void 0!==n)&&n!==N.mutable){if(n===N.immutable)return function(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((n=>{let r=Reflect.getOwnPropertyDescriptor(e,n);r.enumerable&&r.configurable&&r.writable?t[n]=e[n]:(r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:e[n]}),Reflect.defineProperty(t,n,r))})),t}(e);if("function"==typeof n){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return n()}throw new Error(`Unsupported mark result: ${n}`)}if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype){const t={};return Object.keys(e).forEach((n=>{t[n]=e[n]})),Object.getOwnPropertySymbols(e).forEach((n=>{ne.call(e,n)&&(t[n]=e[n])})),t}throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function ie(e){e.copy||(e.copy=re(e.original,e.options))}function se(e){if(!X(e))return W(e);if(Array.isArray(e))return e.map(se);if(e instanceof Map){const t=Array.from(e.entries()).map((([e,t])=>[e,se(t)]));return F(e)?new Map(t):new(0,Object.getPrototypeOf(e).constructor)(t)}if(e instanceof Set){const t=Array.from(e).map(se);return q(e)?new Set(t):new(0,Object.getPrototypeOf(e).constructor)(t)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=se(e[n]);return t}function oe(e){return H(e)?se(e):e}function ae(e){var t;e.assignedMap=null!==(t=e.assignedMap)&&void 0!==t?t:new Map,e.operated||(e.operated=!0,e.parent&&ae(e.parent))}function le(){throw new Error("Cannot modify frozen object")}function ce(e,t,n,r,i){{n=null!=n?n:new WeakMap,r=null!=r?r:[],i=null!=i?i:[];const s=n.has(e)?n.get(e):e;if(r.length>0){const e=r.indexOf(s);if(s&&"object"==typeof s&&-1!==e){if(r[0]===s)throw new Error("Forbids circular reference");throw new Error(`Forbids circular reference: ~/${i.slice(0,e).map(((e,t)=>{if("symbol"==typeof e)return`[${e.toString()}]`;const n=r[t];return"object"==typeof e&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(e):e})).join("/")}`)}r.push(s),i.push(t)}else r.push(s)}if(Object.isFrozen(e)||H(e))return r.pop(),void i.pop();switch(G(e)){case 2:for(const[t,s]of e)ce(t,t,n,r,i),ce(s,t,n,r,i);e.set=e.clear=e.delete=le;break;case 3:for(const t of e)ce(t,t,n,r,i);e.add=e.clear=e.delete=le;break;case 1:Object.freeze(e);let t=0;for(const s of e)ce(s,t,n,r,i),t+=1;break;default:Object.freeze(e),Object.keys(e).forEach((t=>{ce(e[t],t,n,r,i)}))}r.pop(),i.pop()}function ue(e,t){const n=G(e);if(0===n)Reflect.ownKeys(e).forEach((n=>{t(n,e[n],e)}));else if(1===n){let n=0;for(const r of e)t(n,r,e),n+=1}else e.forEach(((n,r)=>t(r,n,e)))}function he(e,t,n){if(H(e)||!X(e,n)||t.has(e)||Object.isFrozen(e))return;const r=e instanceof Set,i=r?new Map:void 0;if(t.add(e),ue(e,((s,o)=>{var a;if(H(o)){const t=$(o);ie(t);const n=(null===(a=t.assignedMap)||void 0===a?void 0:a.size)||t.operated?t.copy:t.original;Z(r?i:e,s,n)}else he(o,t,n)})),i){const t=e,n=Array.from(t);t.clear(),n.forEach((e=>{t.add(i.has(e)?i.get(e):e)}))}}function pe(e,t){const n=3===e.type?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&he(Y(n,t),e.finalities.handledSet,e.options)}function fe(e){3===e.type&&e.copy&&(e.copy.clear(),e.setMap.forEach((t=>{e.copy.add(W(t))})))}function de(e,t,n,r){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&r){const i=K(e);i&&t(e,i,n,r)}e.finalized=!0}}function ye(e,t,n,r){const i=$(n);i&&(i.callbacks||(i.callbacks=[]),i.callbacks.push(((s,o)=>{var a;const l=3===e.type?e.setMap:e.copy;if(Q(Y(l,t),n)){let n=i.original;i.copy&&(n=i.copy),fe(e),de(e,r,s,o),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(a=e.options.updatedValues)&&void 0!==a?a:new WeakMap,e.options.updatedValues.set(n,i.original)),Z(l,t,n)}})),e.options.enableAutoFreeze&&i.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),X(n,e.options)&&e.finalities.draft.push((()=>{Q(Y(3===e.type?e.setMap:e.copy,t),n)&&pe(e,t)}))}function ve(e,t,n,r){const{pathAsArray:i=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return function({original:e,copy:t,assignedMap:n},r,i,s,o){n.forEach(((n,a)=>{const l=Y(e,a),c=oe(Y(t,a)),u=n?V(e,a)?P:z:A;if(Q(l,c)&&u===P)return;const h=te(r.concat(a),o);i.push(u===A?{op:u,path:h}:{op:u,path:h,value:c}),s.push(u===z?{op:A,path:h}:u===A?{op:z,path:h,value:l}:{op:P,path:h,value:l})}))}(e,t,n,r,i);case 1:return function(e,t,n,r,i){let{original:s,assignedMap:o,options:a}=e,l=e.copy;l.length<s.length&&([s,l]=[l,s],[n,r]=[r,n]);for(let e=0;e<s.length;e+=1)if(o.get(e.toString())&&l[e]!==s[e]){const o=te(t.concat([e]),i);n.push({op:P,path:o,value:oe(l[e])}),r.push({op:P,path:o,value:oe(s[e])})}for(let e=s.length;e<l.length;e+=1){const r=te(t.concat([e]),i);n.push({op:z,path:r,value:oe(l[e])})}if(s.length<l.length){const{arrayLengthAssignment:e=!0}=a.enablePatches;if(e){const e=te(t.concat(["length"]),i);r.push({op:P,path:e,value:s.length})}else for(let e=l.length;s.length<e;e-=1){const n=te(t.concat([e-1]),i);r.push({op:A,path:n})}}}(e,t,n,r,i);case 3:return function({original:e,copy:t},n,r,i,s){let o=0;e.forEach((e=>{if(!t.has(e)){const t=te(n.concat([o]),s);r.push({op:A,path:t,value:e}),i.unshift({op:z,path:t,value:e})}o+=1})),o=0,t.forEach((t=>{if(!e.has(t)){const e=te(n.concat([o]),s);r.push({op:z,path:e,value:t}),i.unshift({op:A,path:e,value:t})}o+=1}))}(e,t,n,r,i)}}const ge=(e,t,n=!1)=>{if("object"==typeof e&&null!==e&&(!X(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},me={get size(){return B($(this)).size},has(e){return B($(this)).has(e)},set(e,t){const n=$(this),r=B(n);return r.has(e)&&Q(r.get(e),t)||(ie(n),ae(n),n.assignedMap.set(e,!0),n.copy.set(e,t),ye(n,e,t,ve)),this},delete(e){if(!this.has(e))return!1;const t=$(this);return ie(t),ae(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=$(this);if(this.size){ie(e),ae(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){B($(this)).forEach(((n,r)=>{e.call(t,this.get(r),r,this)}))},get(e){var t,n;const r=$(this),i=B(r).get(e),s=(null===(n=(t=r.options).mark)||void 0===n?void 0:n.call(t,i,N))===N.mutable;if(r.options.strict&&ge(i,r.options,s),s)return i;if(r.finalized||!X(i,r.options))return i;if(i!==r.original.get(e))return i;const o=I.createDraft({original:i,parentDraft:r,key:e,finalities:r.finalities,options:r.options});return ie(r),r.copy.set(e,o),o},keys(){return B($(this)).keys()},values(){const e=this.keys();return{[_]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[_]:()=>this.entries(),next:()=>{const t=e.next();if(t.done)return t;const n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[_](){return this.entries()}},be=Reflect.ownKeys(me),we=(e,t,{isValuesIterator:n})=>()=>{var r,i;const s=t.next();if(s.done)return s;const o=s.value;let a=e.setMap.get(o);const l=$(a),c=(null===(i=(r=e.options).mark)||void 0===i?void 0:i.call(r,a,N))===N.mutable;if(e.options.strict&&ge(o,e.options,c),c||l||!X(o,e.options)||e.finalized||!e.original.has(o))l&&(a=l.proxy);else{const t=I.createDraft({original:o,parentDraft:e,key:o,finalities:e.finalities,options:e.options});e.setMap.set(o,t),a=t}return{done:!1,value:n?a:[a,a]}},Ee={get size(){return $(this).setMap.size},has(e){const t=$(this);if(t.setMap.has(e))return!0;ie(t);const n=$(e);return!(!n||!t.setMap.has(n.original))},add(e){const t=$(this);return this.has(e)||(ie(t),ae(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),ye(t,e,e,ve)),this},delete(e){if(!this.has(e))return!1;const t=$(this);ie(t),ae(t);const n=$(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;const e=$(this);ie(e),ae(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=$(this);ie(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:we(e,t,{isValuesIterator:!0})}},entries(){const e=$(this);ie(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:we(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[_](){return this.values()},forEach(e,t){const n=this.values();let r=n.next();for(;!r.done;)e.call(t,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(Ee,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const Oe=Reflect.ownKeys(Ee),ke=new WeakSet,Me={get(e,t,n){var r,i;const s=null===(r=e.copy)||void 0===r?void 0:r[t];if(s&&ke.has(s))return s;if(t===D)return e;let o;if(e.options.mark){const r="size"===t&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(o=e.options.mark(r,N),o===N.mutable)return e.options.strict&&ge(r,e.options,!0),r}const a=B(e);if(a instanceof Map&&be.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(me,"size").get.call(e.proxy);const n=me[t];if(n)return n.bind(e.proxy)}if(a instanceof Set&&Oe.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(Ee,"size").get.call(e.proxy);const n=Ee[t];if(n)return n.bind(e.proxy)}if(!V(a,t)){const n=U(a,t);return n?"value"in n?n.value:null===(i=n.get)||void 0===i?void 0:i.call(e.proxy):void 0}const l=a[t];if(e.options.strict&&ge(l,e.options),e.finalized||!X(l,e.options))return l;if(l===J(e.original,t)){if(ie(e),e.copy[t]=je({original:e.original[t],parentDraft:e,key:1===e.type?Number(t):t,finalities:e.finalities,options:e.options}),"function"==typeof o){const n=$(e.copy[t]);return ie(n),ae(n),n.copy}return e.copy[t]}return l},set(e,t,n){var r;if(3===e.type||2===e.type)throw new Error("Map/Set draft does not support any property assignment.");let i;if(1===e.type&&"length"!==t&&(!(Number.isInteger(i=Number(t))&&i>=0)||0!==t&&0!==i&&String(i)!==String(t)))throw new Error("Only supports setting array indices and the 'length' property.");const s=U(B(e),t);if(null==s?void 0:s.set)return s.set.call(e.proxy,n),!0;const o=J(B(e),t),a=$(o);return a&&Q(a.original,n)?(e.copy[t]=n,e.assignedMap=null!==(r=e.assignedMap)&&void 0!==r?r:new Map,e.assignedMap.set(t,!1),!0):(Q(n,o)&&(void 0!==n||V(e.original,t))||(ie(e),ae(e),V(e.original,t)&&Q(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,ye(e,t,n,ve)),!0)},has:(e,t)=>t in B(e),ownKeys:e=>Reflect.ownKeys(B(e)),getOwnPropertyDescriptor(e,t){const n=B(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{writable:!0,configurable:1!==e.type||"length"!==t,enumerable:r.enumerable,value:n[t]}:r},getPrototypeOf:e=>Reflect.getPrototypeOf(e.original),setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(e,t){var n;return 1===e.type?Me.set.call(this,e,t,void 0,e.proxy):(void 0!==J(e.original,t)||t in e.original?(ie(e),ae(e),e.assignedMap.set(t,!1)):(e.assignedMap=null!==(n=e.assignedMap)&&void 0!==n?n:new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function je(e){const{original:t,parentDraft:n,key:r,finalities:i,options:s}=e,o=G(t),a={type:o,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:i,options:s,setMap:3===o?new Map(t.entries()):void 0};(r||"key"in e)&&(a.key=r);const{proxy:l,revoke:c}=Proxy.revocable(1===o?Object.assign([],a):a,Me);if(i.revoke.push(c),ke.add(l),a.proxy=l,n){const e=n;e.finalities.draft.push(((t,n)=>{var i,s;const o=$(l);let a=3===e.type?e.setMap:e.copy;const c=Y(a,r),u=$(c);if(u){let s=u.original;u.operated&&(s=W(c)),fe(u),de(u,ve,t,n),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(i=e.options.updatedValues)&&void 0!==i?i:new WeakMap,e.options.updatedValues.set(s,u.original)),Z(a,r,s)}null===(s=o.callbacks)||void 0===s||s.forEach((e=>{e(t,n)}))}))}else{const e=$(l);e.finalities.draft.push(((t,n)=>{fe(e),de(e,ve,t,n)}))}return l}function xe(e,t,n,r,i){var s;const o=$(e),a=null!==(s=null==o?void 0:o.original)&&void 0!==s?s:e,l=!!t.length;if(null==o?void 0:o.operated)for(;o.finalities.draft.length>0;)o.finalities.draft.pop()(n,r);const c=l?t[0]:o?o.operated?o.copy:o.original:e;return o&&ee(o),i&&ce(c,c,null==o?void 0:o.options.updatedValues),[c,n&&l?[{op:P,path:[],value:t[0]}]:n,r&&l?[{op:P,path:[],value:a}]:r]}function Se(e){const{rootDraft:t,value:n,useRawReturn:r=!1,isRoot:i=!0}=e;ue(n,((n,r,i)=>{const s=$(r);if(s&&t&&s.finalities===t.finalities){e.isContainDraft=!0;const t=s.original;if(i instanceof Set){const e=Array.from(i);i.clear(),e.forEach((e=>i.add(n===e?t:e)))}else Z(i,n,t)}else"object"==typeof r&&null!==r&&(e.value=r,e.isRoot=!1,Se(e))})),i&&e.isContainDraft}function Re(e){var t;const n=$(e);if(!X(e,null==n?void 0:n.options))return e;const r=G(e);if(n&&!n.operated)return n.original;let i;function s(){i=2===r?F(e)?new Map(e):new(Object.getPrototypeOf(e).constructor)(e):3===r?Array.from(n.setMap.values()):re(e,null==n?void 0:n.options)}if(n){n.finalized=!0;try{s()}finally{n.finalized=!1}}else i=e;if(ue(i,((t,r)=>{if(n&&Q(Y(n.original,t),r))return;const o=Re(r);o!==r&&(i===e&&s(),Z(i,t,o))})),3===r){const e=null!==(t=null==n?void 0:n.original)&&void 0!==t?t:i;return q(e)?new Set(i):new(Object.getPrototypeOf(e).constructor)(i)}return i}function Te(e){if(!H(e))throw new Error(`current() is only used for Draft, parameter: ${e}`);return Re(e)}I.createDraft=je;const Ce=function e(t,n,r){var i,s,o;if("function"==typeof t&&"function"!=typeof n)return function(r,...i){return e(r,(e=>t.call(this,e,...i)),n)};const a=t,l=n;let c=r;if("function"!=typeof n&&(c=n),void 0!==c&&"[object Object]"!==Object.prototype.toString.call(c))throw new Error(`Invalid options: ${c}, 'options' should be an object.`);c=Object.assign(Object.assign({},void 0),c);const u=H(a)?Te(a):a,h=Array.isArray(c.mark)?(e,t)=>{for(const n of c.mark){if("function"!=typeof n)throw new Error(`Invalid mark: ${n}, 'mark' should be a function.`);const r=n(e,t);if(r)return r}}:c.mark,p=null!==(i=c.enablePatches)&&void 0!==i&&i,f=null!==(s=c.strict)&&void 0!==s&&s,d={enableAutoFreeze:null!==(o=c.enableAutoFreeze)&&void 0!==o&&o,mark:h,strict:f,enablePatches:p};if(!X(u,d)&&"object"==typeof u&&null!==u)throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");const[y,v]=function(e,t){var n;const r={draft:[],revoke:[],handledSet:new WeakSet};let i,s;t.enablePatches&&(i=[],s=[]);const o=(null===(n=t.mark)||void 0===n?void 0:n.call(t,e,N))!==N.mutable&&X(e,t)?je({original:e,parentDraft:null,finalities:r,options:t}):e;return[o,(e=[])=>{const[n,r,a]=xe(o,e,i,s,t.enableAutoFreeze);return t.enablePatches?[n,r,a]:n}]}(u,d);if("function"!=typeof n){if(!X(u,d))throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");return[y,v]}let g;try{g=l(y)}catch(e){throw ee($(y)),e}const m=e=>{const t=$(y);if(!H(e)){if(void 0!==e&&!Q(e,y)&&(null==t?void 0:t.operated))throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");const n=null==e?void 0:e[L];if(n){const r=n[0];return d.strict&&"object"==typeof e&&null!==e&&Se({rootDraft:t,value:e,useRawReturn:!0}),v([r])}if(void 0!==e)return"object"==typeof e&&null!==e&&Se({rootDraft:t,value:e}),v([e])}if(e===y||void 0===e)return v([]);const n=$(e);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return v([Te(e)])}return v([e])};return g instanceof Promise?g.then(m,(e=>{throw ee($(y)),e})):m(g)};function Ae(e,t){e.set(Ce(e.get(),t))}Object.prototype.constructor.toString();class Pe{constructor(e,t=null){this.value=e,this.reactor=t??new T(this,[])}produce(e){return Ae(this,e)}reducer(...e){let t;return t=1===e.length?new C(this,"",e[0]):new C(this,e[0],e[1]),t.trigger.bind(t)}setObjectByPath(e="",t){if(0===e.length)return void(this.value=t);if("string"!=typeof e||!e)throw new Error("Invalid path");let n=e.split("."),r=this.value;for(let e=0;e<n.length-1;e++){let t=n[e];t in r||(r[t]={}),r=r[t]}r[n[n.length-1]]=t}set(...e){if(1===e.length)this.value=e[0],this.reactor.react({type:"SET_VALUE",value:e[0]});else{let t=e[0],n=e[1];this.setObjectByPath(t,n),this.reactor.react({type:"SET_VALUE",path:t,value:n})}}get(){return this.value}}function ze(e){return new Pe(e)}function De(e){return e instanceof Pe}class Le extends Pe{constructor(e,t=null){if(!(e instanceof Array))throw Error("RumiousArrayState: The initial value must be an array.");super(e,t)}set(...e){if(1===e.length)this.value=e[0],this.reactor.react({type:"SET_VALUE",value:e[0]});else{let t=e[0],n=e[1];this.value[t]=n,this.reactor.react({type:"SET_ELEMENT",index:t,value:n})}}append(e){this.value.push(e),this.reactor.react({type:"ADD_ELEMENT",value:e,index:this.value.length-1})}index(e){return this.value[e]}remove(e){e>=0&&e<this.value.length&&(this.value.splice(e,1),this.reactor.react({type:"REMOVE_ELEMENT",index:e}))}insert(e,t){e>=0&&e<=this.value.length&&(this.value.splice(e,0,t),this.reactor.react({type:"INSERT_ELEMENT",index:e,value:t}))}find(e){return this.value.find(e)}}function _e(e=[]){return new Le(e)}function Ne(e,t){e.reactor.addBinding(t)}function Ie(e,t){e.reactor.removeBinding(t)}class Ve extends Pe{constructor(e,t=null){if(!(e instanceof Object))throw Error("RumiousObjectState: The initial value must be an object.");super(e,t)}set(...e){if(1===e.length)this.value=e[0],this.reactor.react({type:"SET_VALUE",value:e[0]});else{let t=e[0],n=e[1];this.value[t]=n,this.reactor.react({type:"SET_VALUE",index:t,value:n})}}keys(){return Object.keys(this.value)}values(){return Object.values(this.value)}each(e){for(let[t,n]of Object.entries(this.value))e(n,t)}has(e){return void 0!==this.value[e]}remove(e){delete this.value[e]}entries(){return Object.entries(this.value)}clear(){this.value={},this.reactor.react({type:"CLEAR"})}merge(e){e instanceof Object&&(Object.assign(this.value,e),this.reactor.react({type:"MERGE",value:e}))}map(e){return Object.entries(this.value).map((([t,n],r)=>e(n,t,r)))}}function Ue(e={}){return new Ve(e)}class qe{constructor(e){this.target=e}set html(e){this.target.innerHTML=e}query(e){return this.target.querySelectorAll(e)}set text(e){this.target.textContent=e}on(e,t){this.target.addEventListener(e,t)}off(e,t){this.target.removeEventListener(e,t)}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}function Fe(e){return new qe(e)}class Be{constructor(e){this.target=e}query(e){return this.target.querySelectorAll(e)}index(e){return Array.from(this.target.children)[e]}list(){return Array.from(this.target.children)}get parent(){return this.target}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}function He(e){return new Be(e)}class $e{constructor(e){this.target=e}set(e){this.target=e.forwardRefs}}function We(e){return new $e(e)}window.RUMIOUS_CONTEXTS||(window.RUMIOUS_CONTEXTS={});class Xe{constructor(e={}){this.data=e,this.events={}}on(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)))}emit(e,...t){this.events[e]&&this.events[e].forEach((e=>e(...t)))}set(e,t){return this.data[e]=t,t}get(e){return this.data[e]}}function Ke(e="",t={}){if(!t||"object"!=typeof t)throw new Error("Rumious context: Initial value must be an object!");return window.RUMIOUS_CONTEXTS[e]||(window.RUMIOUS_CONTEXTS[e]=new Xe(t)),window.RUMIOUS_CONTEXTS[e]}class Ge extends t{static tag="r-pending";constructor(){super(),this.asynchronousRender=!0}async setLoader(e){this.loader=e;try{this.result=await this.loader.execute(),this.renderResult()}catch(e){this.error=e,this.renderError()}}renderResult(){if(!this.result)throw"Rumious Render: Cannot find component when lazy loading!";this.element.before(this.render(d(this.result,{}))),this.element.remove()}renderError(){this.element.appendChild(this.render(this.props.errorComponent??this.error))}onRender(){let{loader:e}=this.props;this.setLoader(e)}template(){return this.props.fallback}}class Ye{constructor(e,t={}){this.hasExecuted=!1,this.result=null,this.callback=e,this.dependents=[],this.options=t}onLoad(e){this.hasExecuted?e(this.result):this.dependents.push(e)}execute(){return new Promise(((e,t)=>{if(this.hasExecuted)return e(this.result);this.hasExecuted=!0;const n=async()=>{try{this.result=await this.callback(),e(this.result),this.dependents.forEach((e=>e(this.result)))}catch(e){t(e)}};this.options.idle&&"requestIdleCallback"in window?requestIdleCallback(n):n()}))}}const Ze=new Map;function Je(e,t={}){const n=t.key||e.toString();return Ze.has(n)||Ze.set(n,new Ye(e,t)),Ze.get(n)}function Qe(e,t){let n=0;return function(...r){const i=Date.now();i-n>=t&&(n=i,e.apply(this,r))}}function et(e,t){let n;return function(...r){clearTimeout(n),n=setTimeout((()=>e.apply(this,r)),t)}}function tt(e,t){let n=0,r=null,i=null;function s(){n=Date.now(),e.apply(this,r),r=null}return function(...e){const o=Date.now();r=e,o-n>=t?s():i||(i=setTimeout((()=>{i=null,s()}),t-(o-n)))}}function nt(e,t){let n,r=!0;return function(...i){r&&(e.apply(this,i),r=!1),clearTimeout(n),n=setTimeout((()=>{e.apply(this,i),r=!0}),t)}}function rt(e){let t=!1;return function(...n){t||(t=!0,requestAnimationFrame((()=>{e.apply(this,n),t=!1})))}}export{Ge as Pending,S as RumiousApp,j as RumiousArraySync,Be as RumiousChildrensRef,t as RumiousComponent,b as RumiousComponentElement,$e as RumiousComponentRef,Xe as RumiousContext,E as RumiousDymanicInjector,qe as RumiousElementRef,Ye as RumiousLazyLoader,T as RumiousReactor,C as RumiousReducer,Pe as RumiousState,_e as createArrayState,He as createChildrensRef,v as createComponent,w as createComponentElement,We as createComponentRef,Ke as createContext,f as createDirective,d as createElement,Fe as createElementRef,Ue as createObjectState,ze as createState,y as createTextElement,et as denounce,O as injectHTML,k as injectText,n as isComponent,De as isState,Je as lazyLoad,nt as leadingTrailingDebounce,Ae as produceState,rt as rafThrottle,R as styleHelper,M as syncArray,Qe as tholle,tt as trailingThrottle,Ie as unwatch,Ne as watch};
package/dist/index.min.js CHANGED
@@ -1 +1 @@
1
- var Rumious=function(e){"use strict";class t{constructor(e){this.target=e,this.app=e.app,this.hooks={onRendered:[],onBeforeRender:[]}}find(e){return this.target[e]}get(e){return this.target[e]}addHook(e,t){if(!this.hooks[e])throw new Error(`Hook type "${e}" is not defined!`);this.hooks[e].push(t)}async runHooks(e,...t){if(this.hooks[e])for(const n of this.hooks[e])await n(...t)}}class n{constructor(){this.renderOptions={mode:"linear"},this.element=null,this.app=null,this.props={},this.forwardRefs={},this.renderContext=new t(this),this.renderer=null,this.wrapped=null}prepare(e,t,n={},r=null){this.element=e,this.props=t,this.renderer=r,this.wrapped=n,this.renderContext.app=this.app}template(){return{}}render(e){return this.renderer(e,document.createDocumentFragment(),this.renderContext)}requestRender(){let e=this.template(),t=this.renderer(e,document.createDocumentFragment(),this.renderContext);this.element.appendChild(t),this.onRender()}async requestCleanUp(){if(this.element){let e=this.element.cloneNode(!0);for(this.element.replaceWith(e),this.element=e;this.element.firstChild;)this.element.removeChild(this.element.firstChild)}}onInit(){}onCreate(){}onRender(){}onUpdate(){}onDestroy(){}}function r(e){return Object.getPrototypeOf(e)===n}class i{constructor(e,t,n=[]){this.type=e,this.props=t,this.children=n}}class o{constructor(e){this.type="ELEMENT_LIST",this.children=e}forEach(e){this.children.forEach(e)}}function s(e){return"function"==typeof e}class a{constructor(e,t,n){this.type=e,this.name=t,this.value=n}init(){}}class l extends a{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return null;const n=t.get(e);if(!s(n))throw new Error(`${e} is not a function!`);return n.bind(t.target)};if("string"===this.value.type)n=r(this.value.value);else if("expression"===this.value.type){if(n=this.value.value,!s(n))throw new Error("Event handler requires a function!")}else"dynamic_value"===this.value.type&&(n=r(this.value.value.objectName));n&&e.addEventListener(this.name,n)}}class c extends a{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");t.reactor.addBinding((()=>{let n=t.get();this.bindAttr(e,n)})),this.bindAttr(e,t.get())}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target),r=t.find(this.value.value.objectName);if(!r)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");r.reactor.addBinding((()=>{let n=this.value.evaluator?.(t.target);this.bindAttr(e,n)})),this.bindAttr(e,n)}}normalizeValue(e){return"object"==typeof e?e.toString?.()??"":e}async bindAttr(e,t){switch(this.name){case"html":e.innerHTML=this.normalizeValue(t);break;case"text":e.textContent=this.normalizeValue(t);break;case"show":e.style.display=this.normalizeValue(t)?"block":"none";break;case"hide":e.style.display=this.normalizeValue(t)?"none":"block";break;case"className":e.className=this.normalizeValue(t);break;case"style":Object.assign(e.style,t);break;case"disabled":e.disabled=!!this.normalizeValue(t);break;case"visible":e.style.visibility=this.normalizeValue(t)?"visible":"hidden";break;case"value":e.value=this.normalizeValue(t);break;case"checked":e.checked=this.normalizeValue(t);break;default:e.setAttribute(this.name,this.normalizeValue(t))}}}class u extends a{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");n.set(e)}}}class p extends a{async init(e,t){let n;"expression"===this.value.type?n=this.value.value:"dynamic_value"===this.value.type&&(n=t.find(this.value.value.objectName));const r=()=>{"checkbox"===e.type?n.set(e.checked):"radio"===e.type?e.checked&&n.set(e.value):n.set(e.value)};e.addEventListener("input",r),e.addEventListener("change",r)}}class h extends a{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");n.set(e)}}}const f={on:(e,t)=>new l("on",e,t),bind:(e,t)=>new c("bind",e,t),ref:(e,t)=>new u("ref",e,t),childsRef:(e,t)=>new h("childsRef",e,t),model:(e,t)=>new p("model",e,t)};function d(e,t,n){return function(e,t,n){return f[e]?.(t,n)}(e,t,n)}function y(e,t,...n){return r(e)?v(e,t,n):e===m?m(...n):new i(e,t||{},b(n))}function g(e){return new i("TEXT_ELEMENT",{nodeValue:e},[])}function v(e,t,n){let r=new i("COMPONENT",{...t},new o(b(n)));return r.component=e,r}function m(...e){return new i("FRAGMENT",{},b(e))}function b(e){return e.map((e=>"object"==typeof e?e:g(e)))}window.RUMIOUS_JSX_SUPPORT={createElement:y,createFragment:m,createDirective:d};class w extends HTMLElement{constructor(){super(),this.instance=null,this.ref=null}cleanUp(){Object.setPrototypeOf(this,HTMLUnknownElement.prototype),this.remove()}init(e,t,n={},r,i){this.instance=new e,this.instance.element=this,this.instance.app=i,this.instance.prepare(this,t,n,r),this.instance.onInit()}connectedCallback(){switch(this.instance.renderOptions.mode){case"linear":this.instance.onCreate(),this.instance.requestRender();break;case"async":(async()=>{this.instance.onCreate(),this.instance.requestRender()})();break;case"animate":requestAnimationFrame((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"idle":requestIdleCallback((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"defer":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),0);break;case"delay":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),this.instance.renderOptions.time);break;case"visible":new IntersectionObserver(((e,t)=>{for(const n of e)n.isIntersecting&&(t.disconnect(),this.instance.onCreate(),this.instance.requestRender())})).observe(this)}}disconnectedCallback(){this.instance.onDestroy(),this.instance.requestCleanUp(),this.cleanUp()}}function O(e="r-component"){return window.customElements.get(e)||window.customElements.define(e,class extends w{static tag=e}),document.createElement(e)}class k{constructor(){this.contents=[],this.targets=[],this.observers=new WeakMap}commit(e=[]){this.contents=e}setTarget(e,t,n){this.targets.push({element:e,context:n,renderer:t}),this.observeTarget(e)}observeTarget(e){if(this.observers.has(e))return;const t=new MutationObserver((()=>{e.parentNode||this.removeTarget(e)}));t.observe(document.body,{childList:!0}),this.observers.set(e,t)}removeTarget(e){const t=this.observers.get(e);t&&(t.disconnect(),this.observers.delete(e)),this.targets=this.targets.filter((t=>t.element!==e))}inject(e=!1){for(let t of this.targets)e&&(t.element.textContent=""),this.contents.forEach((e=>{"html"===e.type?t.element.innerHTML=e.value:"text"===e.type?t.element.textContent=e.value:"component"===e.type&&t.renderer(y(e.value,e.props??{},e.child??{}),t.element,t.context)}))}}function E(e,t,n={}){if(!e)return t;if(null===(r=e)||"object"!=typeof r&&"function"!=typeof r)return E(g(e),t,n);var r;if(Array.isArray(e)){for(const r of e)E(r,t,n);return t}if(e instanceof i){let r;switch(e.type){case"COMPONENT":return function(e,t,n,r){const i=function(e,t,n,r,i=null){const o=O(e.tag??"r-component");return o.init(e,t,n,r,i?.app),o}(e.component,e.props,e.children,n,r);return t.appendChild(i),t}(e,t,E,n);case"FRAGMENT":case"ELEMENT_LIST":for(const r of e.children)E(r,t,n);return t;case"TEXT_ELEMENT":r=function(e){return document.createTextNode(e.props.nodeValue)}(e);break;default:r=function(e,t){const n=document.createElement(e.type);!function(e,t,n){for(const[r,i]of Object.entries(t||{}))i instanceof a?i.init(e,n):r.startsWith("on")&&/^[a-zA-Z]+([A-Z][a-z]*)*$/.test(r)?e.addEventListener(r.substring(2).toLowerCase(),i):e.setAttribute(r,i)}(n,e.props,t);for(const r of e.children)E(r,n,t);return n}(e,n)}return t.appendChild(r),t}if(e instanceof HTMLElement)return t.appendChild(e),t;if(e instanceof k){if(t instanceof HTMLDocument)throw"Rumious Render: Unsupported inject content in HTMLDocument!";return e.setTarget(t,E,n),e.inject(!0),t}return E(g(JSON.stringify(e)),t,n)}class M{constructor(e=null,t=[]){this.target=e,this.bindings=t}react(){this.bindings.forEach((e=>e()))}removeBinding(e){for(let t=this.bindings.length-1;t>=0;t--)this.bindings[t]===e&&this.bindings.splice(t,1)}addBinding(e){this.bindings.push(e)}}class R{constructor(e,t="",n){this.state=e,this.path=t,this.fn=n}trigger(...e){let t=this.fn(...e);this.state.set(this.path,t)}}const j="remove",S="replace",x="add",C=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),T=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),A=Symbol.iterator,P={mutable:"mutable",immutable:"immutable"},z={};function D(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function I(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const e=Reflect.getOwnPropertyDescriptor(n,t);if(e)return e;n=Reflect.getPrototypeOf(n)}}}function L(e){return Object.getPrototypeOf(e)===Set.prototype}function N(e){return Object.getPrototypeOf(e)===Map.prototype}function _(e){var t;return null!==(t=e.copy)&&void 0!==t?t:e.original}function q(e){return!!V(e)}function V(e){return"object"!=typeof e?null:null==e?void 0:e[C]}function U(e){var t;const n=V(e);return n?null!==(t=n.copy)&&void 0!==t?t:n.original:e}function F(e,t){if(!e||"object"!=typeof e)return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!(null==t?void 0:t.mark)&&((n=t.mark(e,P))===P.immutable||"function"==typeof n)}function H(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,r=V(B(n,e.key));if(null!==r&&(null==r?void 0:r.original)!==e.original)return null;const i=3===e.parent.type,o=i?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(i&&n.size>o||D(n,o)))return null;t.push(o)}if(e.parent)return H(e.parent,t);t.reverse();try{!function(e,t){for(let n=0;n<t.length-1;n+=1){const r=t[n];if("object"!=typeof(e=B(3===$(e)?Array.from(e):e,r)))throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}}(e.copy,t)}catch(e){return null}return t}function $(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function B(e,t){return 2===$(e)?e.get(t):e[t]}function W(e,t,n){2===$(e)?e.set(t,n):e[t]=n}function X(e,t){const n=V(e);return(n?_(n):e)[t]}function K(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function Y(e){if(e)for(;e.finalities.revoke.length>0;)e.finalities.revoke.pop()()}function Z(e,t){return t?e:[""].concat(e).map((e=>{const t=`${e}`;return-1===t.indexOf("/")&&-1===t.indexOf("~")?t:t.replace(/~/g,"~0").replace(/\//g,"~1")})).join("/")}const G=Object.prototype.propertyIsEnumerable;function J(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set)return L(e)?Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values()):new(0,Object.getPrototypeOf(e).constructor)(e.values());if(e instanceof Map)return N(e)?new Map(e):new(0,Object.getPrototypeOf(e).constructor)(e);if((null==t?void 0:t.mark)&&(n=t.mark(e,P),void 0!==n)&&n!==P.mutable){if(n===P.immutable)return function(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((n=>{let r=Reflect.getOwnPropertyDescriptor(e,n);r.enumerable&&r.configurable&&r.writable?t[n]=e[n]:(r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:e[n]}),Reflect.defineProperty(t,n,r))})),t}(e);if("function"==typeof n){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return n()}throw new Error(`Unsupported mark result: ${n}`)}if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype){const t={};return Object.keys(e).forEach((n=>{t[n]=e[n]})),Object.getOwnPropertySymbols(e).forEach((n=>{G.call(e,n)&&(t[n]=e[n])})),t}throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function Q(e){e.copy||(e.copy=J(e.original,e.options))}function ee(e){if(!F(e))return U(e);if(Array.isArray(e))return e.map(ee);if(e instanceof Map){const t=Array.from(e.entries()).map((([e,t])=>[e,ee(t)]));return N(e)?new Map(t):new(0,Object.getPrototypeOf(e).constructor)(t)}if(e instanceof Set){const t=Array.from(e).map(ee);return L(e)?new Set(t):new(0,Object.getPrototypeOf(e).constructor)(t)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=ee(e[n]);return t}function te(e){return q(e)?ee(e):e}function ne(e){var t;e.assignedMap=null!==(t=e.assignedMap)&&void 0!==t?t:new Map,e.operated||(e.operated=!0,e.parent&&ne(e.parent))}function re(){throw new Error("Cannot modify frozen object")}function ie(e,t,n,r,i){{n=null!=n?n:new WeakMap,r=null!=r?r:[],i=null!=i?i:[];const o=n.has(e)?n.get(e):e;if(r.length>0){const e=r.indexOf(o);if(o&&"object"==typeof o&&-1!==e){if(r[0]===o)throw new Error("Forbids circular reference");throw new Error(`Forbids circular reference: ~/${i.slice(0,e).map(((e,t)=>{if("symbol"==typeof e)return`[${e.toString()}]`;const n=r[t];return"object"==typeof e&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(e):e})).join("/")}`)}r.push(o),i.push(t)}else r.push(o)}if(Object.isFrozen(e)||q(e))return r.pop(),void i.pop();switch($(e)){case 2:for(const[t,o]of e)ie(t,t,n,r,i),ie(o,t,n,r,i);e.set=e.clear=e.delete=re;break;case 3:for(const t of e)ie(t,t,n,r,i);e.add=e.clear=e.delete=re;break;case 1:Object.freeze(e);let t=0;for(const o of e)ie(o,t,n,r,i),t+=1;break;default:Object.freeze(e),Object.keys(e).forEach((t=>{ie(e[t],t,n,r,i)}))}r.pop(),i.pop()}function oe(e,t){const n=$(e);if(0===n)Reflect.ownKeys(e).forEach((n=>{t(n,e[n],e)}));else if(1===n){let n=0;for(const r of e)t(n,r,e),n+=1}else e.forEach(((n,r)=>t(r,n,e)))}function se(e,t,n){if(q(e)||!F(e,n)||t.has(e)||Object.isFrozen(e))return;const r=e instanceof Set,i=r?new Map:void 0;if(t.add(e),oe(e,((o,s)=>{var a;if(q(s)){const t=V(s);Q(t);const n=(null===(a=t.assignedMap)||void 0===a?void 0:a.size)||t.operated?t.copy:t.original;W(r?i:e,o,n)}else se(s,t,n)})),i){const t=e,n=Array.from(t);t.clear(),n.forEach((e=>{t.add(i.has(e)?i.get(e):e)}))}}function ae(e,t){const n=3===e.type?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&se(B(n,t),e.finalities.handledSet,e.options)}function le(e){3===e.type&&e.copy&&(e.copy.clear(),e.setMap.forEach((t=>{e.copy.add(U(t))})))}function ce(e,t,n,r){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&r){const i=H(e);i&&t(e,i,n,r)}e.finalized=!0}}function ue(e,t,n,r){const i=V(n);i&&(i.callbacks||(i.callbacks=[]),i.callbacks.push(((o,s)=>{var a;const l=3===e.type?e.setMap:e.copy;if(K(B(l,t),n)){let n=i.original;i.copy&&(n=i.copy),le(e),ce(e,r,o,s),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(a=e.options.updatedValues)&&void 0!==a?a:new WeakMap,e.options.updatedValues.set(n,i.original)),W(l,t,n)}})),e.options.enableAutoFreeze&&i.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),F(n,e.options)&&e.finalities.draft.push((()=>{K(B(3===e.type?e.setMap:e.copy,t),n)&&ae(e,t)}))}function pe(e,t,n,r){const{pathAsArray:i=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return function({original:e,copy:t,assignedMap:n},r,i,o,s){n.forEach(((n,a)=>{const l=B(e,a),c=te(B(t,a)),u=n?D(e,a)?S:x:j;if(K(l,c)&&u===S)return;const p=Z(r.concat(a),s);i.push(u===j?{op:u,path:p}:{op:u,path:p,value:c}),o.push(u===x?{op:j,path:p}:u===j?{op:x,path:p,value:l}:{op:S,path:p,value:l})}))}(e,t,n,r,i);case 1:return function(e,t,n,r,i){let{original:o,assignedMap:s,options:a}=e,l=e.copy;l.length<o.length&&([o,l]=[l,o],[n,r]=[r,n]);for(let e=0;e<o.length;e+=1)if(s.get(e.toString())&&l[e]!==o[e]){const s=Z(t.concat([e]),i);n.push({op:S,path:s,value:te(l[e])}),r.push({op:S,path:s,value:te(o[e])})}for(let e=o.length;e<l.length;e+=1){const r=Z(t.concat([e]),i);n.push({op:x,path:r,value:te(l[e])})}if(o.length<l.length){const{arrayLengthAssignment:e=!0}=a.enablePatches;if(e){const e=Z(t.concat(["length"]),i);r.push({op:S,path:e,value:o.length})}else for(let e=l.length;o.length<e;e-=1){const n=Z(t.concat([e-1]),i);r.push({op:j,path:n})}}}(e,t,n,r,i);case 3:return function({original:e,copy:t},n,r,i,o){let s=0;e.forEach((e=>{if(!t.has(e)){const t=Z(n.concat([s]),o);r.push({op:j,path:t,value:e}),i.unshift({op:x,path:t,value:e})}s+=1})),s=0,t.forEach((t=>{if(!e.has(t)){const e=Z(n.concat([s]),o);r.push({op:x,path:e,value:t}),i.unshift({op:j,path:e,value:t})}s+=1}))}(e,t,n,r,i)}}const he=(e,t,n=!1)=>{if("object"==typeof e&&null!==e&&(!F(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},fe={get size(){return _(V(this)).size},has(e){return _(V(this)).has(e)},set(e,t){const n=V(this),r=_(n);return r.has(e)&&K(r.get(e),t)||(Q(n),ne(n),n.assignedMap.set(e,!0),n.copy.set(e,t),ue(n,e,t,pe)),this},delete(e){if(!this.has(e))return!1;const t=V(this);return Q(t),ne(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=V(this);if(this.size){Q(e),ne(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){_(V(this)).forEach(((n,r)=>{e.call(t,this.get(r),r,this)}))},get(e){var t,n;const r=V(this),i=_(r).get(e),o=(null===(n=(t=r.options).mark)||void 0===n?void 0:n.call(t,i,P))===P.mutable;if(r.options.strict&&he(i,r.options,o),o)return i;if(r.finalized||!F(i,r.options))return i;if(i!==r.original.get(e))return i;const s=z.createDraft({original:i,parentDraft:r,key:e,finalities:r.finalities,options:r.options});return Q(r),r.copy.set(e,s),s},keys(){return _(V(this)).keys()},values(){const e=this.keys();return{[A]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[A]:()=>this.entries(),next:()=>{const t=e.next();if(t.done)return t;const n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[A](){return this.entries()}},de=Reflect.ownKeys(fe),ye=(e,t,{isValuesIterator:n})=>()=>{var r,i;const o=t.next();if(o.done)return o;const s=o.value;let a=e.setMap.get(s);const l=V(a),c=(null===(i=(r=e.options).mark)||void 0===i?void 0:i.call(r,a,P))===P.mutable;if(e.options.strict&&he(s,e.options,c),c||l||!F(s,e.options)||e.finalized||!e.original.has(s))l&&(a=l.proxy);else{const t=z.createDraft({original:s,parentDraft:e,key:s,finalities:e.finalities,options:e.options});e.setMap.set(s,t),a=t}return{done:!1,value:n?a:[a,a]}},ge={get size(){return V(this).setMap.size},has(e){const t=V(this);if(t.setMap.has(e))return!0;Q(t);const n=V(e);return!(!n||!t.setMap.has(n.original))},add(e){const t=V(this);return this.has(e)||(Q(t),ne(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),ue(t,e,e,pe)),this},delete(e){if(!this.has(e))return!1;const t=V(this);Q(t),ne(t);const n=V(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;const e=V(this);Q(e),ne(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=V(this);Q(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:ye(e,t,{isValuesIterator:!0})}},entries(){const e=V(this);Q(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:ye(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[A](){return this.values()},forEach(e,t){const n=this.values();let r=n.next();for(;!r.done;)e.call(t,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(ge,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const ve=Reflect.ownKeys(ge),me=new WeakSet,be={get(e,t,n){var r,i;const o=null===(r=e.copy)||void 0===r?void 0:r[t];if(o&&me.has(o))return o;if(t===C)return e;let s;if(e.options.mark){const r="size"===t&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(s=e.options.mark(r,P),s===P.mutable)return e.options.strict&&he(r,e.options,!0),r}const a=_(e);if(a instanceof Map&&de.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(fe,"size").get.call(e.proxy);const n=fe[t];if(n)return n.bind(e.proxy)}if(a instanceof Set&&ve.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(ge,"size").get.call(e.proxy);const n=ge[t];if(n)return n.bind(e.proxy)}if(!D(a,t)){const n=I(a,t);return n?"value"in n?n.value:null===(i=n.get)||void 0===i?void 0:i.call(e.proxy):void 0}const l=a[t];if(e.options.strict&&he(l,e.options),e.finalized||!F(l,e.options))return l;if(l===X(e.original,t)){if(Q(e),e.copy[t]=we({original:e.original[t],parentDraft:e,key:1===e.type?Number(t):t,finalities:e.finalities,options:e.options}),"function"==typeof s){const n=V(e.copy[t]);return Q(n),ne(n),n.copy}return e.copy[t]}return l},set(e,t,n){var r;if(3===e.type||2===e.type)throw new Error("Map/Set draft does not support any property assignment.");let i;if(1===e.type&&"length"!==t&&(!(Number.isInteger(i=Number(t))&&i>=0)||0!==t&&0!==i&&String(i)!==String(t)))throw new Error("Only supports setting array indices and the 'length' property.");const o=I(_(e),t);if(null==o?void 0:o.set)return o.set.call(e.proxy,n),!0;const s=X(_(e),t),a=V(s);return a&&K(a.original,n)?(e.copy[t]=n,e.assignedMap=null!==(r=e.assignedMap)&&void 0!==r?r:new Map,e.assignedMap.set(t,!1),!0):(K(n,s)&&(void 0!==n||D(e.original,t))||(Q(e),ne(e),D(e.original,t)&&K(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,ue(e,t,n,pe)),!0)},has:(e,t)=>t in _(e),ownKeys:e=>Reflect.ownKeys(_(e)),getOwnPropertyDescriptor(e,t){const n=_(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{writable:!0,configurable:1!==e.type||"length"!==t,enumerable:r.enumerable,value:n[t]}:r},getPrototypeOf:e=>Reflect.getPrototypeOf(e.original),setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(e,t){var n;return 1===e.type?be.set.call(this,e,t,void 0,e.proxy):(void 0!==X(e.original,t)||t in e.original?(Q(e),ne(e),e.assignedMap.set(t,!1)):(e.assignedMap=null!==(n=e.assignedMap)&&void 0!==n?n:new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function we(e){const{original:t,parentDraft:n,key:r,finalities:i,options:o}=e,s=$(t),a={type:s,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:i,options:o,setMap:3===s?new Map(t.entries()):void 0};(r||"key"in e)&&(a.key=r);const{proxy:l,revoke:c}=Proxy.revocable(1===s?Object.assign([],a):a,be);if(i.revoke.push(c),me.add(l),a.proxy=l,n){const e=n;e.finalities.draft.push(((t,n)=>{var i,o;const s=V(l);let a=3===e.type?e.setMap:e.copy;const c=B(a,r),u=V(c);if(u){let o=u.original;u.operated&&(o=U(c)),le(u),ce(u,pe,t,n),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(i=e.options.updatedValues)&&void 0!==i?i:new WeakMap,e.options.updatedValues.set(o,u.original)),W(a,r,o)}null===(o=s.callbacks)||void 0===o||o.forEach((e=>{e(t,n)}))}))}else{const e=V(l);e.finalities.draft.push(((t,n)=>{le(e),ce(e,pe,t,n)}))}return l}function Oe(e,t,n,r,i){var o;const s=V(e),a=null!==(o=null==s?void 0:s.original)&&void 0!==o?o:e,l=!!t.length;if(null==s?void 0:s.operated)for(;s.finalities.draft.length>0;)s.finalities.draft.pop()(n,r);const c=l?t[0]:s?s.operated?s.copy:s.original:e;return s&&Y(s),i&&ie(c,c,null==s?void 0:s.options.updatedValues),[c,n&&l?[{op:S,path:[],value:t[0]}]:n,r&&l?[{op:S,path:[],value:a}]:r]}function ke(e){const{rootDraft:t,value:n,useRawReturn:r=!1,isRoot:i=!0}=e;oe(n,((n,r,i)=>{const o=V(r);if(o&&t&&o.finalities===t.finalities){e.isContainDraft=!0;const t=o.original;if(i instanceof Set){const e=Array.from(i);i.clear(),e.forEach((e=>i.add(n===e?t:e)))}else W(i,n,t)}else"object"==typeof r&&null!==r&&(e.value=r,e.isRoot=!1,ke(e))})),i&&e.isContainDraft}function Ee(e){var t;const n=V(e);if(!F(e,null==n?void 0:n.options))return e;const r=$(e);if(n&&!n.operated)return n.original;let i;function o(){i=2===r?N(e)?new Map(e):new(Object.getPrototypeOf(e).constructor)(e):3===r?Array.from(n.setMap.values()):J(e,null==n?void 0:n.options)}if(n){n.finalized=!0;try{o()}finally{n.finalized=!1}}else i=e;if(oe(i,((t,r)=>{if(n&&K(B(n.original,t),r))return;const s=Ee(r);s!==r&&(i===e&&o(),W(i,t,s))})),3===r){const e=null!==(t=null==n?void 0:n.original)&&void 0!==t?t:i;return L(e)?new Set(i):new(Object.getPrototypeOf(e).constructor)(i)}return i}function Me(e){if(!q(e))throw new Error(`current() is only used for Draft, parameter: ${e}`);return Ee(e)}z.createDraft=we;const Re=function e(t,n,r){var i,o,s;if("function"==typeof t&&"function"!=typeof n)return function(r,...i){return e(r,(e=>t.call(this,e,...i)),n)};const a=t,l=n;let c=r;if("function"!=typeof n&&(c=n),void 0!==c&&"[object Object]"!==Object.prototype.toString.call(c))throw new Error(`Invalid options: ${c}, 'options' should be an object.`);c=Object.assign(Object.assign({},void 0),c);const u=q(a)?Me(a):a,p=Array.isArray(c.mark)?(e,t)=>{for(const n of c.mark){if("function"!=typeof n)throw new Error(`Invalid mark: ${n}, 'mark' should be a function.`);const r=n(e,t);if(r)return r}}:c.mark,h=null!==(i=c.enablePatches)&&void 0!==i&&i,f=null!==(o=c.strict)&&void 0!==o&&o,d={enableAutoFreeze:null!==(s=c.enableAutoFreeze)&&void 0!==s&&s,mark:p,strict:f,enablePatches:h};if(!F(u,d)&&"object"==typeof u&&null!==u)throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");const[y,g]=function(e,t){var n;const r={draft:[],revoke:[],handledSet:new WeakSet};let i,o;t.enablePatches&&(i=[],o=[]);const s=(null===(n=t.mark)||void 0===n?void 0:n.call(t,e,P))!==P.mutable&&F(e,t)?we({original:e,parentDraft:null,finalities:r,options:t}):e;return[s,(e=[])=>{const[n,r,a]=Oe(s,e,i,o,t.enableAutoFreeze);return t.enablePatches?[n,r,a]:n}]}(u,d);if("function"!=typeof n){if(!F(u,d))throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");return[y,g]}let v;try{v=l(y)}catch(e){throw Y(V(y)),e}const m=e=>{const t=V(y);if(!q(e)){if(void 0!==e&&!K(e,y)&&(null==t?void 0:t.operated))throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");const n=null==e?void 0:e[T];if(n){const r=n[0];return d.strict&&"object"==typeof e&&null!==e&&ke({rootDraft:t,value:e,useRawReturn:!0}),g([r])}if(void 0!==e)return"object"==typeof e&&null!==e&&ke({rootDraft:t,value:e}),g([e])}if(e===y||void 0===e)return g([]);const n=V(e);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return g([Me(e)])}return g([e])};return v instanceof Promise?v.then(m,(e=>{throw Y(V(y)),e})):m(v)};function je(e,t){e.set(Re(e.get(),t))}Object.prototype.constructor.toString();class Se{constructor(e,t=null){this.value=e,this.reactor=t??new M(this,[])}produce(e){return je(this,e)}reducer(...e){let t;return t=1===e.length?new R(this,"",e[0]):new R(this,e[0],e[1]),t.trigger.bind(t)}setObjectByPath(e="",t){if(0===e.length)return void(this.value=t);if("string"!=typeof e||!e)throw new Error("Invalid path");let n=e.split("."),r=this.value;for(let e=0;e<n.length-1;e++){let t=n[e];t in r||(r[t]={}),r=r[t]}r[n[n.length-1]]=t}set(...e){if(1===e.length)this.value=e[0];else{let t=e[0],n=e[1];this.setObjectByPath(t,n)}this.reactor.react()}get(){return this.value}}function xe(e){return new Se(e)}class Ce{constructor(e){this.target=e}set html(e){this.target.innerHTML=e}query(e){return this.target.querySelectorAll(e)}set text(e){this.target.textContent=e}on(e,t){this.target.addEventListener(e,t)}off(e,t){this.target.removeEventListener(e,t)}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}class Te{constructor(e){this.target=e}query(e){return this.target.querySelectorAll(e)}index(e){return Array.from(this.target.children)[e]}list(){return Array.from(this.target.children)}get parent(){return this.target}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}class Ae{constructor(e){this.target=e}set(e){this.target=e.forwardRefs}}window.RUMIOUS_CONTEXTS||(window.RUMIOUS_CONTEXTS={});class Pe{constructor(e={}){this.data=e,this.events={}}on(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)))}emit(e,...t){this.events[e]&&this.events[e].forEach((e=>e(...t)))}set(e,t){let n=xe(t);return this.data[e]=n,n}get(e){return this.data[e]}}class ze{constructor(e,t={}){this.hasExecuted=!1,this.result=null,this.callback=e,this.dependents=[],this.options=t}onLoad(e){this.hasExecuted?e(this.result):this.dependents.push(e)}execute(){return new Promise(((e,t)=>{if(this.hasExecuted)return e(this.result);this.hasExecuted=!0;const n=async()=>{try{this.result=await this.callback(),e(this.result),this.dependents.forEach((e=>e(this.result)))}catch(e){t(e)}};this.options.idle&&"requestIdleCallback"in window?requestIdleCallback(n):n()}))}}const De=new Map;return e.Pending=class extends n{static tag="r-pending";constructor(){super(),this.asynchronousRender=!0}async setLoader(e){this.loader=e;try{this.result=await this.loader.execute(),this.renderResult()}catch(e){this.error=e,this.renderError()}}renderResult(){if(!this.result)throw"Rumious Render: Cannot find component when lazy loading!";this.element.before(this.render(y(this.result,{}))),this.element.remove()}renderError(){this.element.appendChild(this.render(this.props.errorComponent??this.error))}onRender(){let{loader:e}=this.props;this.setLoader(e)}template(){return this.props.fallback}},e.RumiousApp=class{constructor(e=document.createElement("span"),n={}){this.root=e,this.app=this,this.modules=[],this.configs=n,this.renderContext=new t(this)}render(e){this.renderContext.runHooks("onBeforeRender",this.renderContext),E(e,this.root,this.renderContext),this.renderContext.runHooks("onRendered",this.renderContext)}addModule(e,t={}){return e.init(this,t)}},e.RumiousChildrensRef=Te,e.RumiousComponent=n,e.RumiousComponentElement=w,e.RumiousComponentRef=Ae,e.RumiousContext=Pe,e.RumiousDymanicInjector=k,e.RumiousElementRef=Ce,e.RumiousLazyLoader=ze,e.RumiousReactor=M,e.RumiousReducer=R,e.RumiousState=Se,e.createChildrensRef=function(e){return new Te(e)},e.createComponent=v,e.createComponentElement=O,e.createComponentRef=function(e){return new Ae(e)},e.createContext=function(e="",t={}){if(!t||"object"!=typeof t)throw"Rumious context: Initial value must be object !";return window.RUMIOUS_CONTEXTS[e]||(window.RUMIOUS_CONTEXTS[e]=new Pe(t)),window.RUMIOUS_CONTEXTS[e]},e.createDirective=d,e.createElement=y,e.createElementRef=function(e){return new Ce(e)},e.createState=xe,e.createTextElement=g,e.denounce=function(e,t){let n;return function(...r){clearTimeout(n),n=setTimeout((()=>e.apply(this,r)),t)}},e.injectHTML=function(e){let t=new k;return t.commit([{type:"html",value:e}]),t},e.injectText=function(e){let t=new k;return t.commit([{type:"text",value:e}]),t},e.isComponent=r,e.isState=function(e){return e instanceof Se},e.lazyLoad=function(e,t={}){const n=t.key||e.toString();return De.has(n)||De.set(n,new ze(e,t)),De.get(n)},e.leadingTrailingDebounce=function(e,t){let n,r=!0;return function(...i){r&&(e.apply(this,i),r=!1),clearTimeout(n),n=setTimeout((()=>{e.apply(this,i),r=!0}),t)}},e.produceState=je,e.rafThrottle=function(e){let t=!1;return function(...n){t||(t=!0,requestAnimationFrame((()=>{e.apply(this,n),t=!1})))}},e.styleHelper=function(e){let t="";for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){t+=`${n} {`;const r=e[n];for(const e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t+=`${e.replace(/[A-Z]/g,(e=>`-${e.toLowerCase()}`))}: ${r[e]};`);t+="} "}return t.trim()},e.tholle=function(e,t){let n=0;return function(...r){const i=Date.now();i-n>=t&&(n=i,e.apply(this,r))}},e.trailingThrottle=function(e,t){let n=0,r=null,i=null;function o(){n=Date.now(),e.apply(this,r),r=null}return function(...e){const s=Date.now();r=e,s-n>=t?o():i||(i=setTimeout((()=>{i=null,o()}),t-(s-n)))}},e.unwatch=function(e,t){e.reactor.removeBinding(t)},e.watch=function(e,t){e.reactor.addBinding(t)},e}({});
1
+ var Rumious=function(e){"use strict";class t{constructor(e){this.target=e,this.app=e.app,this.hooks={onRendered:[],onBeforeRender:[]}}find(e){return this.target[e]}get(e){return this.target[e]}addHook(e,t){if(!this.hooks[e])throw new Error(`Hook type "${e}" is not defined!`);this.hooks[e].push(t)}async runHooks(e,...t){if(this.hooks[e])for(const n of this.hooks[e])await n(...t)}}class n{constructor(){this.renderOptions={mode:"linear"},this.element=null,this.app=null,this.props={},this.forwardRefs={},this.renderContext=new t(this),this.renderer=null,this.wrapped=null}prepare(e,t,n={},r=null){this.element=e,this.props=t,this.renderer=r,this.wrapped=n,this.renderContext.app=this.app}template(){return{}}render(e){return this.renderer(e,document.createDocumentFragment(),this.renderContext)}async requestRender(){await this.onBeforeRender();let e=this.template(),t=this.renderer(e,document.createDocumentFragment(),this.renderContext);this.element.appendChild(t),this.onRender()}async requestCleanUp(){if(this.element){let e=this.element.cloneNode(!0);for(this.element.replaceWith(e),this.element=e;this.element.firstChild;)this.element.removeChild(this.element.firstChild)}}onInit(){}onCreate(){}async onBeforeRender(){}onRender(){}onUpdate(){}onDestroy(){}}function r(e){return Object.getPrototypeOf(e)===n}class i{constructor(e,t,n=[]){this.type=e,this.props=t,this.children=n}}class s{constructor(e){this.type="ELEMENT_LIST",this.children=e}forEach(e){this.children.forEach(e)}}function o(e){return"function"==typeof e}class a{constructor(e,t,n){this.type=e,this.name=t,this.value=n}init(){}}class l extends a{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return null;const n=t.get(e);if(!o(n))throw new Error(`${e} is not a function!`);return n.bind(t.target)};if("string"===this.value.type)n=r(this.value.value);else if("expression"===this.value.type){if(n=this.value.value,!o(n))throw new Error("Event handler requires a function!")}else"dynamic_value"===this.value.type&&(n=r(this.value.value.objectName));n&&e.addEventListener(this.name,n)}}class c extends a{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");t.reactor.addBinding((()=>{let n=t.get();this.bindAttr(e,n)})),this.bindAttr(e,t.get())}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target),r=t.find(this.value.value.objectName);if(!r)throw new Error("Invalid props value: Directive bind requires a RumiousState Object!");r.reactor.addBinding((()=>{let n=this.value.evaluator?.(t.target);this.bindAttr(e,n)})),this.bindAttr(e,n)}}normalizeValue(e){return"object"==typeof e?e.toString?.()??"":e}async bindAttr(e,t){switch(this.name){case"html":e.innerHTML=this.normalizeValue(t);break;case"text":e.textContent=this.normalizeValue(t);break;case"show":e.style.display=this.normalizeValue(t)?"block":"none";break;case"hide":e.style.display=this.normalizeValue(t)?"none":"block";break;case"className":e.className=this.normalizeValue(t);break;case"style":Object.assign(e.style,t);break;case"disabled":e.disabled=!!this.normalizeValue(t);break;case"visible":e.style.visibility=this.normalizeValue(t)?"visible":"hidden";break;case"value":e.value=this.normalizeValue(t);break;case"checked":e.checked=this.normalizeValue(t);break;default:e.setAttribute(this.name,this.normalizeValue(t))}}}class u extends a{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive ref requires a RumiousRef Object!");n.set(e)}}}class h extends a{async init(e,t){let n;"expression"===this.value.type?n=this.value.value:"dynamic_value"===this.value.type&&(n=t.find(this.value.value.objectName));const r=()=>{"checkbox"===e.type?n.set(e.checked):"radio"===e.type?e.checked&&n.set(e.value):n.set(e.value)};e.addEventListener("input",r),e.addEventListener("change",r)}}class p extends a{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");t.set(e)}else if("dynamic_value"===this.value.type){let n=t.find(this.value.value.objectName);if(!n)throw new Error("Invalid props value: Directive childsRef requires a RumiousChildRef Object!");n.set(e)}}}const f={on:(e,t)=>new l("on",e,t),bind:(e,t)=>new c("bind",e,t),ref:(e,t)=>new u("ref",e,t),childsRef:(e,t)=>new p("childsRef",e,t),model:(e,t)=>new h("model",e,t)};function d(e,t,n){return function(e,t,n){return f[e]?.(t,n)}(e,t,n)}function y(e,t,...n){return r(e)?g(e,t,n):e===m?m(...n):new i(e,t||{},b(n))}function v(e){return new i("TEXT_ELEMENT",{nodeValue:e},[])}function g(e,t,n){let r=new i("COMPONENT",{...t},new s(b(n)));return r.component=e,r}function m(...e){return new i("FRAGMENT",{},b(e))}function b(e){return e.map((e=>"object"==typeof e?e:v(e)))}window.RUMIOUS_JSX_SUPPORT={createElement:y,createFragment:m,createDirective:d};class w extends HTMLElement{constructor(){super(),this.instance=null,this.ref=null}cleanUp(){Object.setPrototypeOf(this,HTMLUnknownElement.prototype),this.remove()}init(e,t,n={},r,i){this.instance=new e,this.instance.element=this,this.instance.app=i,this.instance.prepare(this,t,n,r),this.instance.onInit()}connectedCallback(){switch(this.instance.renderOptions.mode){case"linear":this.instance.onCreate(),this.instance.requestRender();break;case"async":(async()=>{this.instance.onCreate(),this.instance.requestRender()})();break;case"animate":requestAnimationFrame((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"idle":requestIdleCallback((async()=>{this.instance.onCreate(),this.instance.requestRender()}));break;case"defer":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),0);break;case"delay":setTimeout((async()=>{this.instance.onCreate(),this.instance.requestRender()}),this.instance.renderOptions.time);break;case"visible":new IntersectionObserver(((e,t)=>{for(const n of e)n.isIntersecting&&(t.disconnect(),this.instance.onCreate(),this.instance.requestRender())})).observe(this)}}disconnectedCallback(){this.instance.onDestroy(),this.instance.requestCleanUp(),this.cleanUp()}}function E(e="r-component"){return window.customElements.get(e)||window.customElements.define(e,class extends w{static tag=e}),document.createElement(e)}class O{constructor(){this.contents=[],this.targets=[],this.observers=new WeakMap}commit(e=[]){this.contents=e}setTarget(e,t,n){this.targets.push({element:e,context:n,renderer:t}),this.observeTarget(e)}observeTarget(e){if(this.observers.has(e))return;const t=new MutationObserver((()=>{e.parentNode||this.removeTarget(e)}));t.observe(document.body,{childList:!0}),this.observers.set(e,t)}removeTarget(e){const t=this.observers.get(e);t&&(t.disconnect(),this.observers.delete(e)),this.targets=this.targets.filter((t=>t.element!==e))}inject(e=!1){for(let t of this.targets)e&&(t.element.textContent=""),this.contents.forEach((e=>{"html"===e.type?t.element.innerHTML=e.value:"text"===e.type?t.element.textContent=e.value:"component"===e.type&&t.renderer(y(e.value,e.props??{},e.child??{}),t.element,t.context)}))}}class k{constructor(e,t){this.state=e,this.template=t,this.target=null}setTarget(e,t,n){this.target={element:e,context:n,renderer:t}}sync(){this.target&&(this.renderAll(),this.state.reactor.addBinding((e=>this.onChange(e))))}renderAll(){this.target.element.textContent="",this.state.value.forEach(((e,t)=>this.appendElement(e,t)))}appendElement(e,t){let n=this.template(e,t),r=this.target.renderer(n,document.createDocumentFragment(),this.target.context);this.target.element.appendChild(r)}onChange(e){if(this.target)switch(e.type){case"REMOVE_ELEMENT":{let t=this.target.element.children[e.index];t&&this.target.element.removeChild(t);break}case"SET_VALUE":this.renderAll();break;case"ADD_ELEMENT":this.appendElement(e.value,e.index);break;case"SET_ELEMENT":{let t=this.template(e.value,e.index),n=this.target.renderer(t,document.createDocumentFragment(),this.target.context);!function(e,t,n){let r=e.children;t>=0&&t<r.length?e.replaceChild(n,r[t]):e.appendChild(n)}(this.target.element,e.index,n);break}case"INSERT_ELEMENT":{let t=this.template(e.value,e.index),n=this.target.renderer(t,document.createDocumentFragment(),this.target.context),r=this.target.element.children;e.index>=r.length?this.target.element.appendChild(n):this.target.element.insertBefore(n.children[0],r[e.index]);break}}}}function M(e,t,n={}){if(!e)return t;if(null===(r=e)||"object"!=typeof r&&"function"!=typeof r)return M(v(e),t,n);var r;if(Array.isArray(e)){for(const r of e)M(r,t,n);return t}if(e instanceof i){let r;switch(e.type){case"COMPONENT":return function(e,t,n,r){const i=function(e,t,n,r,i=null){const s=E(e.tag??"r-component");return s.init(e,t,n,r,i?.app),s}(e.component,e.props,e.children,n,r);return t.appendChild(i),t}(e,t,M,n);case"FRAGMENT":case"ELEMENT_LIST":for(const r of e.children)M(r,t,n);return t;case"TEXT_ELEMENT":r=function(e){return document.createTextNode(e.props.nodeValue)}(e);break;default:r=function(e,t){const n=document.createElement(e.type);!function(e,t,n){for(const[r,i]of Object.entries(t||{}))i instanceof a?i.init(e,n):r.startsWith("on")&&/^[a-zA-Z]+([A-Z][a-z]*)*$/.test(r)?e.addEventListener(r.substring(2).toLowerCase(),i):e.setAttribute(r,i)}(n,e.props,t);for(const r of e.children)M(r,n,t);return n}(e,n)}return t.appendChild(r),t}if(e instanceof HTMLElement)return t.appendChild(e),t;if(e instanceof O){if(t instanceof HTMLDocument)throw"Rumious Render: Unsupported inject content in HTMLDocument!";return e.setTarget(t,M,n),e.inject(!0),t}if(e instanceof k){if(t instanceof HTMLDocument)throw"Rumious Render: Unsupported sync data of array in HTMLDocument!";return e.setTarget(t,M,n),e.sync(),t}return M(v(JSON.stringify(e)),t,n)}class R{constructor(e=null,t=[]){this.target=e,this.bindings=t}react(e){this.bindings.forEach((t=>t(e)))}removeBinding(e){for(let t=this.bindings.length-1;t>=0;t--)this.bindings[t]===e&&this.bindings.splice(t,1)}addBinding(e){this.bindings.push(e)}}class j{constructor(e,t="",n){this.state=e,this.path=t,this.fn=n}trigger(...e){let t=this.fn(...e);this.state.set(this.path,t)}}const S="remove",x="replace",T="add",C=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),A=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),P=Symbol.iterator,D={mutable:"mutable",immutable:"immutable"},z={};function L(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function _(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const e=Reflect.getOwnPropertyDescriptor(n,t);if(e)return e;n=Reflect.getPrototypeOf(n)}}}function N(e){return Object.getPrototypeOf(e)===Set.prototype}function I(e){return Object.getPrototypeOf(e)===Map.prototype}function V(e){var t;return null!==(t=e.copy)&&void 0!==t?t:e.original}function U(e){return!!q(e)}function q(e){return"object"!=typeof e?null:null==e?void 0:e[C]}function F(e){var t;const n=q(e);return n?null!==(t=n.copy)&&void 0!==t?t:n.original:e}function H(e,t){if(!e||"object"!=typeof e)return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!(null==t?void 0:t.mark)&&((n=t.mark(e,D))===D.immutable||"function"==typeof n)}function B(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,r=q(W(n,e.key));if(null!==r&&(null==r?void 0:r.original)!==e.original)return null;const i=3===e.parent.type,s=i?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(i&&n.size>s||L(n,s)))return null;t.push(s)}if(e.parent)return B(e.parent,t);t.reverse();try{!function(e,t){for(let n=0;n<t.length-1;n+=1){const r=t[n];if("object"!=typeof(e=W(3===$(e)?Array.from(e):e,r)))throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}}(e.copy,t)}catch(e){return null}return t}function $(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function W(e,t){return 2===$(e)?e.get(t):e[t]}function X(e,t,n){2===$(e)?e.set(t,n):e[t]=n}function K(e,t){const n=q(e);return(n?V(n):e)[t]}function G(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function Y(e){if(e)for(;e.finalities.revoke.length>0;)e.finalities.revoke.pop()()}function Z(e,t){return t?e:[""].concat(e).map((e=>{const t=`${e}`;return-1===t.indexOf("/")&&-1===t.indexOf("~")?t:t.replace(/~/g,"~0").replace(/\//g,"~1")})).join("/")}const J=Object.prototype.propertyIsEnumerable;function Q(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set)return N(e)?Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values()):new(0,Object.getPrototypeOf(e).constructor)(e.values());if(e instanceof Map)return I(e)?new Map(e):new(0,Object.getPrototypeOf(e).constructor)(e);if((null==t?void 0:t.mark)&&(n=t.mark(e,D),void 0!==n)&&n!==D.mutable){if(n===D.immutable)return function(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((n=>{let r=Reflect.getOwnPropertyDescriptor(e,n);r.enumerable&&r.configurable&&r.writable?t[n]=e[n]:(r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:e[n]}),Reflect.defineProperty(t,n,r))})),t}(e);if("function"==typeof n){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return n()}throw new Error(`Unsupported mark result: ${n}`)}if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype){const t={};return Object.keys(e).forEach((n=>{t[n]=e[n]})),Object.getOwnPropertySymbols(e).forEach((n=>{J.call(e,n)&&(t[n]=e[n])})),t}throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function ee(e){e.copy||(e.copy=Q(e.original,e.options))}function te(e){if(!H(e))return F(e);if(Array.isArray(e))return e.map(te);if(e instanceof Map){const t=Array.from(e.entries()).map((([e,t])=>[e,te(t)]));return I(e)?new Map(t):new(0,Object.getPrototypeOf(e).constructor)(t)}if(e instanceof Set){const t=Array.from(e).map(te);return N(e)?new Set(t):new(0,Object.getPrototypeOf(e).constructor)(t)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=te(e[n]);return t}function ne(e){return U(e)?te(e):e}function re(e){var t;e.assignedMap=null!==(t=e.assignedMap)&&void 0!==t?t:new Map,e.operated||(e.operated=!0,e.parent&&re(e.parent))}function ie(){throw new Error("Cannot modify frozen object")}function se(e,t,n,r,i){{n=null!=n?n:new WeakMap,r=null!=r?r:[],i=null!=i?i:[];const s=n.has(e)?n.get(e):e;if(r.length>0){const e=r.indexOf(s);if(s&&"object"==typeof s&&-1!==e){if(r[0]===s)throw new Error("Forbids circular reference");throw new Error(`Forbids circular reference: ~/${i.slice(0,e).map(((e,t)=>{if("symbol"==typeof e)return`[${e.toString()}]`;const n=r[t];return"object"==typeof e&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(e):e})).join("/")}`)}r.push(s),i.push(t)}else r.push(s)}if(Object.isFrozen(e)||U(e))return r.pop(),void i.pop();switch($(e)){case 2:for(const[t,s]of e)se(t,t,n,r,i),se(s,t,n,r,i);e.set=e.clear=e.delete=ie;break;case 3:for(const t of e)se(t,t,n,r,i);e.add=e.clear=e.delete=ie;break;case 1:Object.freeze(e);let t=0;for(const s of e)se(s,t,n,r,i),t+=1;break;default:Object.freeze(e),Object.keys(e).forEach((t=>{se(e[t],t,n,r,i)}))}r.pop(),i.pop()}function oe(e,t){const n=$(e);if(0===n)Reflect.ownKeys(e).forEach((n=>{t(n,e[n],e)}));else if(1===n){let n=0;for(const r of e)t(n,r,e),n+=1}else e.forEach(((n,r)=>t(r,n,e)))}function ae(e,t,n){if(U(e)||!H(e,n)||t.has(e)||Object.isFrozen(e))return;const r=e instanceof Set,i=r?new Map:void 0;if(t.add(e),oe(e,((s,o)=>{var a;if(U(o)){const t=q(o);ee(t);const n=(null===(a=t.assignedMap)||void 0===a?void 0:a.size)||t.operated?t.copy:t.original;X(r?i:e,s,n)}else ae(o,t,n)})),i){const t=e,n=Array.from(t);t.clear(),n.forEach((e=>{t.add(i.has(e)?i.get(e):e)}))}}function le(e,t){const n=3===e.type?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&ae(W(n,t),e.finalities.handledSet,e.options)}function ce(e){3===e.type&&e.copy&&(e.copy.clear(),e.setMap.forEach((t=>{e.copy.add(F(t))})))}function ue(e,t,n,r){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&r){const i=B(e);i&&t(e,i,n,r)}e.finalized=!0}}function he(e,t,n,r){const i=q(n);i&&(i.callbacks||(i.callbacks=[]),i.callbacks.push(((s,o)=>{var a;const l=3===e.type?e.setMap:e.copy;if(G(W(l,t),n)){let n=i.original;i.copy&&(n=i.copy),ce(e),ue(e,r,s,o),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(a=e.options.updatedValues)&&void 0!==a?a:new WeakMap,e.options.updatedValues.set(n,i.original)),X(l,t,n)}})),e.options.enableAutoFreeze&&i.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),H(n,e.options)&&e.finalities.draft.push((()=>{G(W(3===e.type?e.setMap:e.copy,t),n)&&le(e,t)}))}function pe(e,t,n,r){const{pathAsArray:i=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return function({original:e,copy:t,assignedMap:n},r,i,s,o){n.forEach(((n,a)=>{const l=W(e,a),c=ne(W(t,a)),u=n?L(e,a)?x:T:S;if(G(l,c)&&u===x)return;const h=Z(r.concat(a),o);i.push(u===S?{op:u,path:h}:{op:u,path:h,value:c}),s.push(u===T?{op:S,path:h}:u===S?{op:T,path:h,value:l}:{op:x,path:h,value:l})}))}(e,t,n,r,i);case 1:return function(e,t,n,r,i){let{original:s,assignedMap:o,options:a}=e,l=e.copy;l.length<s.length&&([s,l]=[l,s],[n,r]=[r,n]);for(let e=0;e<s.length;e+=1)if(o.get(e.toString())&&l[e]!==s[e]){const o=Z(t.concat([e]),i);n.push({op:x,path:o,value:ne(l[e])}),r.push({op:x,path:o,value:ne(s[e])})}for(let e=s.length;e<l.length;e+=1){const r=Z(t.concat([e]),i);n.push({op:T,path:r,value:ne(l[e])})}if(s.length<l.length){const{arrayLengthAssignment:e=!0}=a.enablePatches;if(e){const e=Z(t.concat(["length"]),i);r.push({op:x,path:e,value:s.length})}else for(let e=l.length;s.length<e;e-=1){const n=Z(t.concat([e-1]),i);r.push({op:S,path:n})}}}(e,t,n,r,i);case 3:return function({original:e,copy:t},n,r,i,s){let o=0;e.forEach((e=>{if(!t.has(e)){const t=Z(n.concat([o]),s);r.push({op:S,path:t,value:e}),i.unshift({op:T,path:t,value:e})}o+=1})),o=0,t.forEach((t=>{if(!e.has(t)){const e=Z(n.concat([o]),s);r.push({op:T,path:e,value:t}),i.unshift({op:S,path:e,value:t})}o+=1}))}(e,t,n,r,i)}}const fe=(e,t,n=!1)=>{if("object"==typeof e&&null!==e&&(!H(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},de={get size(){return V(q(this)).size},has(e){return V(q(this)).has(e)},set(e,t){const n=q(this),r=V(n);return r.has(e)&&G(r.get(e),t)||(ee(n),re(n),n.assignedMap.set(e,!0),n.copy.set(e,t),he(n,e,t,pe)),this},delete(e){if(!this.has(e))return!1;const t=q(this);return ee(t),re(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=q(this);if(this.size){ee(e),re(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){V(q(this)).forEach(((n,r)=>{e.call(t,this.get(r),r,this)}))},get(e){var t,n;const r=q(this),i=V(r).get(e),s=(null===(n=(t=r.options).mark)||void 0===n?void 0:n.call(t,i,D))===D.mutable;if(r.options.strict&&fe(i,r.options,s),s)return i;if(r.finalized||!H(i,r.options))return i;if(i!==r.original.get(e))return i;const o=z.createDraft({original:i,parentDraft:r,key:e,finalities:r.finalities,options:r.options});return ee(r),r.copy.set(e,o),o},keys(){return V(q(this)).keys()},values(){const e=this.keys();return{[P]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[P]:()=>this.entries(),next:()=>{const t=e.next();if(t.done)return t;const n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[P](){return this.entries()}},ye=Reflect.ownKeys(de),ve=(e,t,{isValuesIterator:n})=>()=>{var r,i;const s=t.next();if(s.done)return s;const o=s.value;let a=e.setMap.get(o);const l=q(a),c=(null===(i=(r=e.options).mark)||void 0===i?void 0:i.call(r,a,D))===D.mutable;if(e.options.strict&&fe(o,e.options,c),c||l||!H(o,e.options)||e.finalized||!e.original.has(o))l&&(a=l.proxy);else{const t=z.createDraft({original:o,parentDraft:e,key:o,finalities:e.finalities,options:e.options});e.setMap.set(o,t),a=t}return{done:!1,value:n?a:[a,a]}},ge={get size(){return q(this).setMap.size},has(e){const t=q(this);if(t.setMap.has(e))return!0;ee(t);const n=q(e);return!(!n||!t.setMap.has(n.original))},add(e){const t=q(this);return this.has(e)||(ee(t),re(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),he(t,e,e,pe)),this},delete(e){if(!this.has(e))return!1;const t=q(this);ee(t),re(t);const n=q(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;const e=q(this);ee(e),re(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=q(this);ee(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:ve(e,t,{isValuesIterator:!0})}},entries(){const e=q(this);ee(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:ve(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[P](){return this.values()},forEach(e,t){const n=this.values();let r=n.next();for(;!r.done;)e.call(t,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(ge,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const me=Reflect.ownKeys(ge),be=new WeakSet,we={get(e,t,n){var r,i;const s=null===(r=e.copy)||void 0===r?void 0:r[t];if(s&&be.has(s))return s;if(t===C)return e;let o;if(e.options.mark){const r="size"===t&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(o=e.options.mark(r,D),o===D.mutable)return e.options.strict&&fe(r,e.options,!0),r}const a=V(e);if(a instanceof Map&&ye.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(de,"size").get.call(e.proxy);const n=de[t];if(n)return n.bind(e.proxy)}if(a instanceof Set&&me.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(ge,"size").get.call(e.proxy);const n=ge[t];if(n)return n.bind(e.proxy)}if(!L(a,t)){const n=_(a,t);return n?"value"in n?n.value:null===(i=n.get)||void 0===i?void 0:i.call(e.proxy):void 0}const l=a[t];if(e.options.strict&&fe(l,e.options),e.finalized||!H(l,e.options))return l;if(l===K(e.original,t)){if(ee(e),e.copy[t]=Ee({original:e.original[t],parentDraft:e,key:1===e.type?Number(t):t,finalities:e.finalities,options:e.options}),"function"==typeof o){const n=q(e.copy[t]);return ee(n),re(n),n.copy}return e.copy[t]}return l},set(e,t,n){var r;if(3===e.type||2===e.type)throw new Error("Map/Set draft does not support any property assignment.");let i;if(1===e.type&&"length"!==t&&(!(Number.isInteger(i=Number(t))&&i>=0)||0!==t&&0!==i&&String(i)!==String(t)))throw new Error("Only supports setting array indices and the 'length' property.");const s=_(V(e),t);if(null==s?void 0:s.set)return s.set.call(e.proxy,n),!0;const o=K(V(e),t),a=q(o);return a&&G(a.original,n)?(e.copy[t]=n,e.assignedMap=null!==(r=e.assignedMap)&&void 0!==r?r:new Map,e.assignedMap.set(t,!1),!0):(G(n,o)&&(void 0!==n||L(e.original,t))||(ee(e),re(e),L(e.original,t)&&G(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,he(e,t,n,pe)),!0)},has:(e,t)=>t in V(e),ownKeys:e=>Reflect.ownKeys(V(e)),getOwnPropertyDescriptor(e,t){const n=V(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{writable:!0,configurable:1!==e.type||"length"!==t,enumerable:r.enumerable,value:n[t]}:r},getPrototypeOf:e=>Reflect.getPrototypeOf(e.original),setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(e,t){var n;return 1===e.type?we.set.call(this,e,t,void 0,e.proxy):(void 0!==K(e.original,t)||t in e.original?(ee(e),re(e),e.assignedMap.set(t,!1)):(e.assignedMap=null!==(n=e.assignedMap)&&void 0!==n?n:new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function Ee(e){const{original:t,parentDraft:n,key:r,finalities:i,options:s}=e,o=$(t),a={type:o,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:i,options:s,setMap:3===o?new Map(t.entries()):void 0};(r||"key"in e)&&(a.key=r);const{proxy:l,revoke:c}=Proxy.revocable(1===o?Object.assign([],a):a,we);if(i.revoke.push(c),be.add(l),a.proxy=l,n){const e=n;e.finalities.draft.push(((t,n)=>{var i,s;const o=q(l);let a=3===e.type?e.setMap:e.copy;const c=W(a,r),u=q(c);if(u){let s=u.original;u.operated&&(s=F(c)),ce(u),ue(u,pe,t,n),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(i=e.options.updatedValues)&&void 0!==i?i:new WeakMap,e.options.updatedValues.set(s,u.original)),X(a,r,s)}null===(s=o.callbacks)||void 0===s||s.forEach((e=>{e(t,n)}))}))}else{const e=q(l);e.finalities.draft.push(((t,n)=>{ce(e),ue(e,pe,t,n)}))}return l}function Oe(e,t,n,r,i){var s;const o=q(e),a=null!==(s=null==o?void 0:o.original)&&void 0!==s?s:e,l=!!t.length;if(null==o?void 0:o.operated)for(;o.finalities.draft.length>0;)o.finalities.draft.pop()(n,r);const c=l?t[0]:o?o.operated?o.copy:o.original:e;return o&&Y(o),i&&se(c,c,null==o?void 0:o.options.updatedValues),[c,n&&l?[{op:x,path:[],value:t[0]}]:n,r&&l?[{op:x,path:[],value:a}]:r]}function ke(e){const{rootDraft:t,value:n,useRawReturn:r=!1,isRoot:i=!0}=e;oe(n,((n,r,i)=>{const s=q(r);if(s&&t&&s.finalities===t.finalities){e.isContainDraft=!0;const t=s.original;if(i instanceof Set){const e=Array.from(i);i.clear(),e.forEach((e=>i.add(n===e?t:e)))}else X(i,n,t)}else"object"==typeof r&&null!==r&&(e.value=r,e.isRoot=!1,ke(e))})),i&&e.isContainDraft}function Me(e){var t;const n=q(e);if(!H(e,null==n?void 0:n.options))return e;const r=$(e);if(n&&!n.operated)return n.original;let i;function s(){i=2===r?I(e)?new Map(e):new(Object.getPrototypeOf(e).constructor)(e):3===r?Array.from(n.setMap.values()):Q(e,null==n?void 0:n.options)}if(n){n.finalized=!0;try{s()}finally{n.finalized=!1}}else i=e;if(oe(i,((t,r)=>{if(n&&G(W(n.original,t),r))return;const o=Me(r);o!==r&&(i===e&&s(),X(i,t,o))})),3===r){const e=null!==(t=null==n?void 0:n.original)&&void 0!==t?t:i;return N(e)?new Set(i):new(Object.getPrototypeOf(e).constructor)(i)}return i}function Re(e){if(!U(e))throw new Error(`current() is only used for Draft, parameter: ${e}`);return Me(e)}z.createDraft=Ee;const je=function e(t,n,r){var i,s,o;if("function"==typeof t&&"function"!=typeof n)return function(r,...i){return e(r,(e=>t.call(this,e,...i)),n)};const a=t,l=n;let c=r;if("function"!=typeof n&&(c=n),void 0!==c&&"[object Object]"!==Object.prototype.toString.call(c))throw new Error(`Invalid options: ${c}, 'options' should be an object.`);c=Object.assign(Object.assign({},void 0),c);const u=U(a)?Re(a):a,h=Array.isArray(c.mark)?(e,t)=>{for(const n of c.mark){if("function"!=typeof n)throw new Error(`Invalid mark: ${n}, 'mark' should be a function.`);const r=n(e,t);if(r)return r}}:c.mark,p=null!==(i=c.enablePatches)&&void 0!==i&&i,f=null!==(s=c.strict)&&void 0!==s&&s,d={enableAutoFreeze:null!==(o=c.enableAutoFreeze)&&void 0!==o&&o,mark:h,strict:f,enablePatches:p};if(!H(u,d)&&"object"==typeof u&&null!==u)throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");const[y,v]=function(e,t){var n;const r={draft:[],revoke:[],handledSet:new WeakSet};let i,s;t.enablePatches&&(i=[],s=[]);const o=(null===(n=t.mark)||void 0===n?void 0:n.call(t,e,D))!==D.mutable&&H(e,t)?Ee({original:e,parentDraft:null,finalities:r,options:t}):e;return[o,(e=[])=>{const[n,r,a]=Oe(o,e,i,s,t.enableAutoFreeze);return t.enablePatches?[n,r,a]:n}]}(u,d);if("function"!=typeof n){if(!H(u,d))throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");return[y,v]}let g;try{g=l(y)}catch(e){throw Y(q(y)),e}const m=e=>{const t=q(y);if(!U(e)){if(void 0!==e&&!G(e,y)&&(null==t?void 0:t.operated))throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");const n=null==e?void 0:e[A];if(n){const r=n[0];return d.strict&&"object"==typeof e&&null!==e&&ke({rootDraft:t,value:e,useRawReturn:!0}),v([r])}if(void 0!==e)return"object"==typeof e&&null!==e&&ke({rootDraft:t,value:e}),v([e])}if(e===y||void 0===e)return v([]);const n=q(e);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return v([Re(e)])}return v([e])};return g instanceof Promise?g.then(m,(e=>{throw Y(q(y)),e})):m(g)};function Se(e,t){e.set(je(e.get(),t))}Object.prototype.constructor.toString();class xe{constructor(e,t=null){this.value=e,this.reactor=t??new R(this,[])}produce(e){return Se(this,e)}reducer(...e){let t;return t=1===e.length?new j(this,"",e[0]):new j(this,e[0],e[1]),t.trigger.bind(t)}setObjectByPath(e="",t){if(0===e.length)return void(this.value=t);if("string"!=typeof e||!e)throw new Error("Invalid path");let n=e.split("."),r=this.value;for(let e=0;e<n.length-1;e++){let t=n[e];t in r||(r[t]={}),r=r[t]}r[n[n.length-1]]=t}set(...e){if(1===e.length)this.value=e[0],this.reactor.react({type:"SET_VALUE",value:e[0]});else{let t=e[0],n=e[1];this.setObjectByPath(t,n),this.reactor.react({type:"SET_VALUE",path:t,value:n})}}get(){return this.value}}class Te extends xe{constructor(e,t=null){if(!(e instanceof Array))throw Error("RumiousArrayState: The initial value must be an array.");super(e,t)}set(...e){if(1===e.length)this.value=e[0],this.reactor.react({type:"SET_VALUE",value:e[0]});else{let t=e[0],n=e[1];this.value[t]=n,this.reactor.react({type:"SET_ELEMENT",index:t,value:n})}}append(e){this.value.push(e),this.reactor.react({type:"ADD_ELEMENT",value:e,index:this.value.length-1})}index(e){return this.value[e]}remove(e){e>=0&&e<this.value.length&&(this.value.splice(e,1),this.reactor.react({type:"REMOVE_ELEMENT",index:e}))}insert(e,t){e>=0&&e<=this.value.length&&(this.value.splice(e,0,t),this.reactor.react({type:"INSERT_ELEMENT",index:e,value:t}))}find(e){return this.value.find(e)}}class Ce extends xe{constructor(e,t=null){if(!(e instanceof Object))throw Error("RumiousObjectState: The initial value must be an object.");super(e,t)}set(...e){if(1===e.length)this.value=e[0],this.reactor.react({type:"SET_VALUE",value:e[0]});else{let t=e[0],n=e[1];this.value[t]=n,this.reactor.react({type:"SET_VALUE",index:t,value:n})}}keys(){return Object.keys(this.value)}values(){return Object.values(this.value)}each(e){for(let[t,n]of Object.entries(this.value))e(n,t)}has(e){return void 0!==this.value[e]}remove(e){delete this.value[e]}entries(){return Object.entries(this.value)}clear(){this.value={},this.reactor.react({type:"CLEAR"})}merge(e){e instanceof Object&&(Object.assign(this.value,e),this.reactor.react({type:"MERGE",value:e}))}map(e){return Object.entries(this.value).map((([t,n],r)=>e(n,t,r)))}}class Ae{constructor(e){this.target=e}set html(e){this.target.innerHTML=e}query(e){return this.target.querySelectorAll(e)}set text(e){this.target.textContent=e}on(e,t){this.target.addEventListener(e,t)}off(e,t){this.target.removeEventListener(e,t)}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}class Pe{constructor(e){this.target=e}query(e){return this.target.querySelectorAll(e)}index(e){return Array.from(this.target.children)[e]}list(){return Array.from(this.target.children)}get parent(){return this.target}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}class De{constructor(e){this.target=e}set(e){this.target=e.forwardRefs}}window.RUMIOUS_CONTEXTS||(window.RUMIOUS_CONTEXTS={});class ze{constructor(e={}){this.data=e,this.events={}}on(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)))}emit(e,...t){this.events[e]&&this.events[e].forEach((e=>e(...t)))}set(e,t){return this.data[e]=t,t}get(e){return this.data[e]}}class Le{constructor(e,t={}){this.hasExecuted=!1,this.result=null,this.callback=e,this.dependents=[],this.options=t}onLoad(e){this.hasExecuted?e(this.result):this.dependents.push(e)}execute(){return new Promise(((e,t)=>{if(this.hasExecuted)return e(this.result);this.hasExecuted=!0;const n=async()=>{try{this.result=await this.callback(),e(this.result),this.dependents.forEach((e=>e(this.result)))}catch(e){t(e)}};this.options.idle&&"requestIdleCallback"in window?requestIdleCallback(n):n()}))}}const _e=new Map;return e.Pending=class extends n{static tag="r-pending";constructor(){super(),this.asynchronousRender=!0}async setLoader(e){this.loader=e;try{this.result=await this.loader.execute(),this.renderResult()}catch(e){this.error=e,this.renderError()}}renderResult(){if(!this.result)throw"Rumious Render: Cannot find component when lazy loading!";this.element.before(this.render(y(this.result,{}))),this.element.remove()}renderError(){this.element.appendChild(this.render(this.props.errorComponent??this.error))}onRender(){let{loader:e}=this.props;this.setLoader(e)}template(){return this.props.fallback}},e.RumiousApp=class{constructor(e=document.createElement("span"),n={}){this.root=e,this.app=this,this.modules=[],this.configs=n,this.renderContext=new t(this)}render(e){this.renderContext.runHooks("onBeforeRender",this.renderContext),M(e,this.root,this.renderContext),this.renderContext.runHooks("onRendered",this.renderContext)}addModule(e,t={}){return e.init(this,t)}},e.RumiousArraySync=k,e.RumiousChildrensRef=Pe,e.RumiousComponent=n,e.RumiousComponentElement=w,e.RumiousComponentRef=De,e.RumiousContext=ze,e.RumiousDymanicInjector=O,e.RumiousElementRef=Ae,e.RumiousLazyLoader=Le,e.RumiousReactor=R,e.RumiousReducer=j,e.RumiousState=xe,e.createArrayState=function(e=[]){return new Te(e)},e.createChildrensRef=function(e){return new Pe(e)},e.createComponent=g,e.createComponentElement=E,e.createComponentRef=function(e){return new De(e)},e.createContext=function(e="",t={}){if(!t||"object"!=typeof t)throw new Error("Rumious context: Initial value must be an object!");return window.RUMIOUS_CONTEXTS[e]||(window.RUMIOUS_CONTEXTS[e]=new ze(t)),window.RUMIOUS_CONTEXTS[e]},e.createDirective=d,e.createElement=y,e.createElementRef=function(e){return new Ae(e)},e.createObjectState=function(e={}){return new Ce(e)},e.createState=function(e){return new xe(e)},e.createTextElement=v,e.denounce=function(e,t){let n;return function(...r){clearTimeout(n),n=setTimeout((()=>e.apply(this,r)),t)}},e.injectHTML=function(e){let t=new O;return t.commit([{type:"html",value:e}]),t},e.injectText=function(e){let t=new O;return t.commit([{type:"text",value:e}]),t},e.isComponent=r,e.isState=function(e){return e instanceof xe},e.lazyLoad=function(e,t={}){const n=t.key||e.toString();return _e.has(n)||_e.set(n,new Le(e,t)),_e.get(n)},e.leadingTrailingDebounce=function(e,t){let n,r=!0;return function(...i){r&&(e.apply(this,i),r=!1),clearTimeout(n),n=setTimeout((()=>{e.apply(this,i),r=!0}),t)}},e.produceState=Se,e.rafThrottle=function(e){let t=!1;return function(...n){t||(t=!0,requestAnimationFrame((()=>{e.apply(this,n),t=!1})))}},e.styleHelper=function(e){let t="";for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){t+=`${n} {`;const r=e[n];for(const e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t+=`${e.replace(/[A-Z]/g,(e=>`-${e.toLowerCase()}`))}: ${r[e]};`);t+="} "}return t.trim()},e.syncArray=function(e,t){return new k(e,t)},e.tholle=function(e,t){let n=0;return function(...r){const i=Date.now();i-n>=t&&(n=i,e.apply(this,r))}},e.trailingThrottle=function(e,t){let n=0,r=null,i=null;function s(){n=Date.now(),e.apply(this,r),r=null}return function(...e){const o=Date.now();r=e,o-n>=t?s():i||(i=setTimeout((()=>{i=null,s()}),t-(o-n)))}},e.unwatch=function(e,t){e.reactor.removeBinding(t)},e.watch=function(e,t){e.reactor.addBinding(t)},e}({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rumious",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "The simple library for build UI",
5
5
  "keywords": [
6
6
  "rumious",