rumious 0.0.13-beta.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/app/app.d.ts +14 -0
- package/dist/app/index.d.ts +2 -0
- package/dist/app/module.d.ts +6 -0
- package/dist/component/component.d.ts +29 -0
- package/dist/component/element.d.ts +17 -0
- package/dist/component/index.d.ts +2 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.esm.js +1 -0
- package/dist/index.min.js +1 -1
- package/dist/jsx/index.d.ts +3 -0
- package/dist/ref/children.d.ts +23 -0
- package/dist/ref/element.d.ts +49 -0
- package/dist/ref/index.d.ts +2 -0
- package/dist/render/array.d.ts +20 -0
- package/dist/render/context.d.ts +11 -0
- package/dist/render/directives.d.ts +1 -0
- package/dist/render/dynamic.d.ts +2 -0
- package/dist/render/index.d.ts +3 -0
- package/dist/render/injector.d.ts +14 -0
- package/dist/render/render.d.ts +3 -0
- package/dist/render/template.d.ts +5 -0
- package/dist/state/array.d.ts +21 -0
- package/dist/state/index.d.ts +3 -0
- package/dist/state/object.d.ts +31 -0
- package/dist/state/reactor.d.ts +19 -0
- package/dist/state/state.d.ts +15 -0
- package/dist/types/render.d.ts +5 -0
- package/dist/types/utils.d.ts +1 -0
- package/dist/utils/checkers.d.ts +1 -0
- package/dist/utils/name.d.ts +1 -0
- package/dist/utils/oberve.d.ts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -3
- package/package.json +44 -31
- package/dist/index.cjs.min.js +0 -1
- package/dist/index.esm.min.js +0 -1
package/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
import { RumiousModule, RumiousModuleInstance } from './module.js';
|
2
|
+
interface RumiousAppOptions {
|
3
|
+
}
|
4
|
+
export declare class RumiousApp {
|
5
|
+
private root;
|
6
|
+
options: RumiousAppOptions;
|
7
|
+
modules: RumiousModuleInstance[];
|
8
|
+
private context;
|
9
|
+
constructor(root: HTMLElement, options?: RumiousAppOptions);
|
10
|
+
addModule(module: RumiousModule, options: any): RumiousModuleInstance;
|
11
|
+
render(template: JSX.Element): void;
|
12
|
+
}
|
13
|
+
export declare function createApp(root: HTMLElement, options?: RumiousAppOptions): RumiousApp;
|
14
|
+
export {};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { RumiousApp } from '../app/app.js';
|
2
|
+
import { RumiousRenderContext } from '../render/context.js';
|
3
|
+
import { RumiousRenderTemplate } from '../render/template.js';
|
4
|
+
import { RumiousRenderMode } from "../types/render.js";
|
5
|
+
export interface RumiousEmptyProps {
|
6
|
+
}
|
7
|
+
interface RumiousComponentRenderOptions {
|
8
|
+
mode: RumiousRenderMode;
|
9
|
+
time?: number;
|
10
|
+
}
|
11
|
+
export declare abstract class RumiousComponent<T = unknown> {
|
12
|
+
static classNames: string;
|
13
|
+
static tagName: string;
|
14
|
+
app: RumiousApp;
|
15
|
+
props: T;
|
16
|
+
element: HTMLElement;
|
17
|
+
context: RumiousRenderContext;
|
18
|
+
renderOptions: RumiousComponentRenderOptions;
|
19
|
+
constructor();
|
20
|
+
onCreate(): void;
|
21
|
+
onRender(): void;
|
22
|
+
onDestroy(): void;
|
23
|
+
onBeforeRender(): Promise<void>;
|
24
|
+
abstract template(): RumiousRenderTemplate;
|
25
|
+
prepare(currentContext: RumiousRenderContext, props: T): void;
|
26
|
+
requestRender(): Promise<void>;
|
27
|
+
requestCleanup(): void;
|
28
|
+
}
|
29
|
+
export {};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { RumiousComponent } from "./component.js";
|
2
|
+
import { RumiousRenderContext } from "../render/context.js";
|
3
|
+
import { Constructor } from '../types/utils.js';
|
4
|
+
export type RumiousComponentConstructor = Constructor<RumiousComponent> & {
|
5
|
+
classNames?: string;
|
6
|
+
tagName?: string;
|
7
|
+
};
|
8
|
+
export declare class RumiousComponentElement extends HTMLElement {
|
9
|
+
componentConstructor: RumiousComponentConstructor;
|
10
|
+
private componentInstance;
|
11
|
+
private context;
|
12
|
+
props: Record<string, any>;
|
13
|
+
constructor();
|
14
|
+
setup(context: RumiousRenderContext, componentConstructor: RumiousComponentConstructor): void;
|
15
|
+
connectedCallback(): void;
|
16
|
+
disconnectedCallback(): void;
|
17
|
+
}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import { RumiousRenderTemplate } from "./render/template.js";
|
2
|
+
interface RumiousJSXFactory {
|
3
|
+
template(...args: any[]): RumiousRenderTemplate;
|
4
|
+
createElement(...args: any[]): RumiousRenderTemplate;
|
5
|
+
addDirective(...args: any[]): void;
|
6
|
+
dynamicValue(...args: any[]): void;
|
7
|
+
createComponent(...args: any[]): HTMLElement;
|
8
|
+
}
|
9
|
+
declare global {
|
10
|
+
interface Window {
|
11
|
+
RUMIOUS_JSX: RumiousJSXFactory;
|
12
|
+
}
|
13
|
+
namespace JSX {
|
14
|
+
interface ElementClass {
|
15
|
+
template: () => RumiousRenderTemplate;
|
16
|
+
}
|
17
|
+
interface ElementAttributesProperty {
|
18
|
+
props: {};
|
19
|
+
}
|
20
|
+
type Element = RumiousRenderTemplate;
|
21
|
+
interface IntrinsicElements {
|
22
|
+
[elemName: string]: any;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
export * from "./component/index.js";
|
27
|
+
export * from "./app/index.js";
|
28
|
+
export * from "./jsx/index.js";
|
29
|
+
export * from "./render/index.js";
|
30
|
+
export * from "./ref/index.js";
|
31
|
+
export * from "./state/index.js";
|
@@ -0,0 +1 @@
|
|
1
|
+
class t{constructor(t,e){this.target=t,this.app=e,this.onRenderFinished=[]}findName(t){return this.target[t]}}function e(t,n,r){let i=n.generator.bind(t.target);t.renderHelper=e,i(r,t),setTimeout((async()=>{const e=[...t.onRenderFinished];t.onRenderFinished=[];for(const t of e)await t()}),0)}class n{static classNames="";static tagName="rumious-component";constructor(){this.renderOptions={mode:"idle"}}onCreate(){}onRender(){}onDestroy(){}async onBeforeRender(){}prepare(e,n){this.props=n,this.context=new t(this,e.app)}async requestRender(){await this.onBeforeRender();let t=this.template();e(this.context,t,this.element),this.onRender()}requestCleanup(){}}class r extends HTMLElement{constructor(){super(),this.props={}}setup(t,e){this.context=t,this.componentConstructor=e}connectedCallback(){this.componentConstructor?(this.componentInstance=new this.componentConstructor,this.componentInstance.element=this,this.componentConstructor.classNames&&(this.className=this.componentConstructor.classNames),this.componentInstance.prepare(this.context,this.props),this.componentInstance.onCreate(),this.componentInstance.requestRender()):console.warn("Rumious: Cannot find matching component constructor.")}disconnectedCallback(){this.componentInstance?.onDestroy()}}class i{constructor(e,n={}){this.root=e,this.options=n,this.modules=[],this.context=new t(this,this)}addModule(t,e){let n=t.init(this,e);return this.modules.push(n),n}render(t){e(this.context,t,this.root)}}function s(t,e){return new i(t,e)}class o{constructor(t){this.generator=t}}class a{constructor(t){if(this.contents=t,this.targets=new Map,!t||0===t.length)throw new Error("Injector must be initialized with non-empty content");const e=t[0];this.type="string"==typeof e?"string":"element"}addTarget(t){this.targets.set(t,1)}inject(t){if(this.targets.has(t)&&this.contents)if(t.innerHTML="","string"===this.type)for(const e of this.contents)t.insertAdjacentHTML("beforeend",e);else for(const e of this.contents)t.appendChild(e)}injectAll(){for(const t of this.targets.keys())this.inject(t)}removeTarget(t){this.targets.delete(t)}clear(){this.targets.clear()}}function l(t){return new a([t])}class c{constructor(t){this.target=t}getElement(){return this.target}remove(){this.target.remove()}addChild(t){this.target.appendChild(t)}listChild(){return this.target.childNodes}querySelector(t){return this.target.querySelector(t)}querySelectorAll(t){return this.target.querySelectorAll(t)}set text(t){this.target.textContent=t}get text(){return this.target.textContent}set value(t){(this.target instanceof HTMLInputElement||this.target instanceof HTMLTextAreaElement)&&(this.target.value=t)}get value(){if(this.target instanceof HTMLInputElement||this.target instanceof HTMLTextAreaElement)return this.target.value}addClassName(t){this.target.classList.add(t)}removeClassName(t){this.target.classList.remove(t)}hasClassName(t){return this.target.classList.contains(t)}toggleClass(t,e){return this.target.classList.toggle(t,e)}setStyle(t){Object.assign(this.target.style,t)}getStyle(t){return getComputedStyle(this.target).getPropertyValue(t)}setAttribute(t,e){this.target.setAttribute(t,e)}getAttribute(t){return this.target.getAttribute(t)}removeAttribute(t){this.target.removeAttribute(t)}on(t,e,n){this.target.addEventListener(t,e,n)}off(t,e,n){this.target.removeEventListener(t,e,n)}set html(t){this.target.innerHTML=t}get html(){return this.target.innerHTML}getBoundingRect(){return this.target.getBoundingClientRect()}isInViewport(){const t=this.target.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}prependChild(t){this.target.prepend(t)}setDisabled(t){(this.target instanceof HTMLButtonElement||this.target instanceof HTMLInputElement||this.target instanceof HTMLTextAreaElement)&&(this.target.disabled=t)}addClasses(...t){this.target.classList.add(...t)}removeClasses(...t){this.target.classList.remove(...t)}replaceClass(t,e){this.target.classList.replace(t,e)}moveTo(t){t.appendChild(this.target)}getParent(){return this.target.parentElement}getNextSibling(){return this.target.nextElementSibling}getPreviousSibling(){return this.target.previousElementSibling}hide(){this.target.style.display="none"}show(){this.target.style.removeProperty("display")}isHidden(){return"none"===window.getComputedStyle(this.target).display}scrollIntoView(t={behavior:"smooth"}){this.target.scrollIntoView(t)}matches(t){return this.target.matches(t)}getChildren(){return Array.from(this.target.children)}insertAfter(t){this.target.parentNode&&this.target.parentNode.insertBefore(t,this.target.nextSibling)}insertBefore(t){this.target.parentNode&&this.target.parentNode.insertBefore(t,this.target)}clearChildren(){for(;this.target.firstChild;)this.target.removeChild(this.target.firstChild)}animate(t,e){return this.target.animate(t,e)}}function u(){return new c(document.createElement("span"))}function h(t){const e=t.indexOf("$");return-1!==e?t.slice(e+1):""}class p{constructor(t){this.target=t,this.bindings=[]}addBinding(t){this.bindings.push(t)}removeBinding(t){this.bindings=this.bindings.filter((e=>e!==t))}async emit(t){await Promise.allSettled(this.bindings.map((e=>{try{const n=e(t);return n instanceof Promise?n:Promise.resolve(n)}catch(t){return Promise.reject(t)}})))}}const f="remove",d="replace",g="add",y=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),m=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),v=Symbol.iterator,b={mutable:"mutable",immutable:"immutable"},w={};function E(t,e){return t instanceof Map?t.has(e):Object.prototype.hasOwnProperty.call(t,e)}function k(t,e){if(e in t){let n=Reflect.getPrototypeOf(t);for(;n;){const t=Reflect.getOwnPropertyDescriptor(n,e);if(t)return t;n=Reflect.getPrototypeOf(n)}}}function M(t){return Object.getPrototypeOf(t)===Set.prototype}function S(t){return Object.getPrototypeOf(t)===Map.prototype}function O(t){var e;return null!==(e=t.copy)&&void 0!==e?e:t.original}function j(t){return!!C(t)}function C(t){return"object"!=typeof t?null:null==t?void 0:t[y]}function x(t){var e;const n=C(t);return n?null!==(e=n.copy)&&void 0!==e?e:n.original:t}function A(t,e){if(!t||"object"!=typeof t)return!1;let n;return Object.getPrototypeOf(t)===Object.prototype||Array.isArray(t)||t instanceof Map||t instanceof Set||!!(null==e?void 0:e.mark)&&((n=e.mark(t,b))===b.immutable||"function"==typeof n)}function R(t,e=[]){if(Object.hasOwnProperty.call(t,"key")){const n=t.parent.copy,r=C(T(n,t.key));if(null!==r&&(null==r?void 0:r.original)!==t.original)return null;const i=3===t.parent.type,s=i?Array.from(t.parent.setMap.keys()).indexOf(t.key):t.key;if(!(i&&n.size>s||E(n,s)))return null;e.push(s)}if(t.parent)return R(t.parent,e);e.reverse();try{!function(t,e){for(let n=0;n<e.length-1;n+=1){const r=e[n];if("object"!=typeof(t=T(3===P(t)?Array.from(t):t,r)))throw new Error(`Cannot resolve patch at '${e.join("/")}'.`)}}(t.copy,e)}catch(t){return null}return e}function P(t){return Array.isArray(t)?1:t instanceof Map?2:t instanceof Set?3:0}function T(t,e){return 2===P(t)?t.get(e):t[e]}function z(t,e,n){2===P(t)?t.set(e,n):t[e]=n}function N(t,e){const n=C(t);return(n?O(n):t)[e]}function L(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}function D(t){if(t)for(;t.finalities.revoke.length>0;){t.finalities.revoke.pop()()}}function I(t,e){return e?t:[""].concat(t).map((t=>{const e=`${t}`;return-1===e.indexOf("/")&&-1===e.indexOf("~")?e:e.replace(/~/g,"~0").replace(/\//g,"~1")})).join("/")}const F=Object.prototype.propertyIsEnumerable;function _(t,e){let n;if(Array.isArray(t))return Array.prototype.concat.call(t);if(t instanceof Set){if(!M(t)){return new(0,Object.getPrototypeOf(t).constructor)(t.values())}return Set.prototype.difference?Set.prototype.difference.call(t,new Set):new Set(t.values())}if(t instanceof Map){if(!S(t)){return new(0,Object.getPrototypeOf(t).constructor)(t)}return new Map(t)}if((null==e?void 0:e.mark)&&(n=e.mark(t,b),void 0!==n)&&n!==b.mutable){if(n===b.immutable)return function(t){const e=Object.create(Object.getPrototypeOf(t));return Reflect.ownKeys(t).forEach((n=>{let r=Reflect.getOwnPropertyDescriptor(t,n);r.enumerable&&r.configurable&&r.writable?e[n]=t[n]:(r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:t[n]}),Reflect.defineProperty(e,n,r))})),e}(t);if("function"==typeof n){if(e.enablePatches||e.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 t&&Object.getPrototypeOf(t)===Object.prototype){const e={};return Object.keys(t).forEach((n=>{e[n]=t[n]})),Object.getOwnPropertySymbols(t).forEach((n=>{F.call(t,n)&&(e[n]=t[n])})),e}throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function B(t){t.copy||(t.copy=_(t.original,t.options))}function H(t){if(!A(t))return x(t);if(Array.isArray(t))return t.map(H);if(t instanceof Map){const e=Array.from(t.entries()).map((([t,e])=>[t,H(e)]));if(!S(t)){return new(0,Object.getPrototypeOf(t).constructor)(e)}return new Map(e)}if(t instanceof Set){const e=Array.from(t).map(H);if(!M(t)){return new(0,Object.getPrototypeOf(t).constructor)(e)}return new Set(e)}const e=Object.create(Object.getPrototypeOf(t));for(const n in t)e[n]=H(t[n]);return e}function Y(t){return j(t)?H(t):t}function V(t){var e;t.assignedMap=null!==(e=t.assignedMap)&&void 0!==e?e:new Map,t.operated||(t.operated=!0,t.parent&&V(t.parent))}function q(){throw new Error("Cannot modify frozen object")}function K(t,e,n,r,i){{n=null!=n?n:new WeakMap,r=null!=r?r:[],i=null!=i?i:[];const s=n.has(t)?n.get(t):t;if(r.length>0){const t=r.indexOf(s);if(s&&"object"==typeof s&&-1!==t){if(r[0]===s)throw new Error("Forbids circular reference");throw new Error(`Forbids circular reference: ~/${i.slice(0,t).map(((t,e)=>{if("symbol"==typeof t)return`[${t.toString()}]`;const n=r[e];return"object"==typeof t&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(t):t})).join("/")}`)}r.push(s),i.push(e)}else r.push(s)}if(Object.isFrozen(t)||j(t))return r.pop(),void i.pop();switch(P(t)){case 2:for(const[e,s]of t)K(e,e,n,r,i),K(s,e,n,r,i);t.set=t.clear=t.delete=q;break;case 3:for(const e of t)K(e,e,n,r,i);t.add=t.clear=t.delete=q;break;case 1:Object.freeze(t);let e=0;for(const s of t)K(s,e,n,r,i),e+=1;break;default:Object.freeze(t),Object.keys(t).forEach((e=>{K(t[e],e,n,r,i)}))}r.pop(),i.pop()}function W(t,e){const n=P(t);if(0===n)Reflect.ownKeys(t).forEach((n=>{e(n,t[n],t)}));else if(1===n){let n=0;for(const r of t)e(n,r,t),n+=1}else t.forEach(((n,r)=>e(r,n,t)))}function $(t,e,n){if(j(t)||!A(t,n)||e.has(t)||Object.isFrozen(t))return;const r=t instanceof Set,i=r?new Map:void 0;if(e.add(t),W(t,((s,o)=>{var a;if(j(o)){const e=C(o);B(e);const n=(null===(a=e.assignedMap)||void 0===a?void 0:a.size)||e.operated?e.copy:e.original;z(r?i:t,s,n)}else $(o,e,n)})),i){const e=t,n=Array.from(e);e.clear(),n.forEach((t=>{e.add(i.has(t)?i.get(t):t)}))}}function J(t,e){const n=3===t.type?t.setMap:t.copy;t.finalities.revoke.length>1&&t.assignedMap.get(e)&&n&&$(T(n,e),t.finalities.handledSet,t.options)}function U(t){3===t.type&&t.copy&&(t.copy.clear(),t.setMap.forEach((e=>{t.copy.add(x(e))})))}function X(t,e,n,r){if(t.operated&&t.assignedMap&&t.assignedMap.size>0&&!t.finalized){if(n&&r){const i=R(t);i&&e(t,i,n,r)}t.finalized=!0}}function G(t,e,n,r){const i=C(n);i&&(i.callbacks||(i.callbacks=[]),i.callbacks.push(((s,o)=>{var a;const l=3===t.type?t.setMap:t.copy;if(L(T(l,e),n)){let n=i.original;i.copy&&(n=i.copy),U(t),X(t,r,s,o),t.options.enableAutoFreeze&&(t.options.updatedValues=null!==(a=t.options.updatedValues)&&void 0!==a?a:new WeakMap,t.options.updatedValues.set(n,i.original)),z(l,e,n)}})),t.options.enableAutoFreeze&&i.finalities!==t.finalities&&(t.options.enableAutoFreeze=!1)),A(n,t.options)&&t.finalities.draft.push((()=>{L(T(3===t.type?t.setMap:t.copy,e),n)&&J(t,e)}))}function Q(t,e,n,r){const{pathAsArray:i=!0}=t.options.enablePatches;switch(t.type){case 0:case 2:return function({original:t,copy:e,assignedMap:n},r,i,s,o){n.forEach(((n,a)=>{const l=T(t,a),c=Y(T(e,a)),u=n?E(t,a)?d:g:f;if(L(l,c)&&u===d)return;const h=I(r.concat(a),o);i.push(u===f?{op:u,path:h}:{op:u,path:h,value:c}),s.push(u===g?{op:f,path:h}:u===f?{op:g,path:h,value:l}:{op:d,path:h,value:l})}))}(t,e,n,r,i);case 1:return function(t,e,n,r,i){let{original:s,assignedMap:o,options:a}=t,l=t.copy;l.length<s.length&&([s,l]=[l,s],[n,r]=[r,n]);for(let t=0;t<s.length;t+=1)if(o.get(t.toString())&&l[t]!==s[t]){const o=I(e.concat([t]),i);n.push({op:d,path:o,value:Y(l[t])}),r.push({op:d,path:o,value:Y(s[t])})}for(let t=s.length;t<l.length;t+=1){const r=I(e.concat([t]),i);n.push({op:g,path:r,value:Y(l[t])})}if(s.length<l.length){const{arrayLengthAssignment:t=!0}=a.enablePatches;if(t){const t=I(e.concat(["length"]),i);r.push({op:d,path:t,value:s.length})}else for(let t=l.length;s.length<t;t-=1){const n=I(e.concat([t-1]),i);r.push({op:f,path:n})}}}(t,e,n,r,i);case 3:return function({original:t,copy:e},n,r,i,s){let o=0;t.forEach((t=>{if(!e.has(t)){const e=I(n.concat([o]),s);r.push({op:f,path:e,value:t}),i.unshift({op:g,path:e,value:t})}o+=1})),o=0,e.forEach((e=>{if(!t.has(e)){const t=I(n.concat([o]),s);r.push({op:g,path:t,value:e}),i.unshift({op:f,path:t,value:e})}o+=1}))}(t,e,n,r,i)}}const Z=(t,e,n=!1)=>{if("object"==typeof t&&null!==t&&(!A(t,e)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},tt={get size(){return O(C(this)).size},has(t){return O(C(this)).has(t)},set(t,e){const n=C(this),r=O(n);return r.has(t)&&L(r.get(t),e)||(B(n),V(n),n.assignedMap.set(t,!0),n.copy.set(t,e),G(n,t,e,Q)),this},delete(t){if(!this.has(t))return!1;const e=C(this);return B(e),V(e),e.original.has(t)?e.assignedMap.set(t,!1):e.assignedMap.delete(t),e.copy.delete(t),!0},clear(){const t=C(this);if(this.size){B(t),V(t),t.assignedMap=new Map;for(const[e]of t.original)t.assignedMap.set(e,!1);t.copy.clear()}},forEach(t,e){O(C(this)).forEach(((n,r)=>{t.call(e,this.get(r),r,this)}))},get(t){var e,n;const r=C(this),i=O(r).get(t),s=(null===(n=(e=r.options).mark)||void 0===n?void 0:n.call(e,i,b))===b.mutable;if(r.options.strict&&Z(i,r.options,s),s)return i;if(r.finalized||!A(i,r.options))return i;if(i!==r.original.get(t))return i;const o=w.createDraft({original:i,parentDraft:r,key:t,finalities:r.finalities,options:r.options});return B(r),r.copy.set(t,o),o},keys(){return O(C(this)).keys()},values(){const t=this.keys();return{[v]:()=>this.values(),next:()=>{const e=t.next();if(e.done)return e;return{done:!1,value:this.get(e.value)}}}},entries(){const t=this.keys();return{[v]:()=>this.entries(),next:()=>{const e=t.next();if(e.done)return e;const n=this.get(e.value);return{done:!1,value:[e.value,n]}}}},[v](){return this.entries()}},et=Reflect.ownKeys(tt),nt=(t,e,{isValuesIterator:n})=>()=>{var r,i;const s=e.next();if(s.done)return s;const o=s.value;let a=t.setMap.get(o);const l=C(a),c=(null===(i=(r=t.options).mark)||void 0===i?void 0:i.call(r,a,b))===b.mutable;if(t.options.strict&&Z(o,t.options,c),c||l||!A(o,t.options)||t.finalized||!t.original.has(o))l&&(a=l.proxy);else{const e=w.createDraft({original:o,parentDraft:t,key:o,finalities:t.finalities,options:t.options});t.setMap.set(o,e),a=e}return{done:!1,value:n?a:[a,a]}},rt={get size(){return C(this).setMap.size},has(t){const e=C(this);if(e.setMap.has(t))return!0;B(e);const n=C(t);return!(!n||!e.setMap.has(n.original))},add(t){const e=C(this);return this.has(t)||(B(e),V(e),e.assignedMap.set(t,!0),e.setMap.set(t,t),G(e,t,t,Q)),this},delete(t){if(!this.has(t))return!1;const e=C(this);B(e),V(e);const n=C(t);return n&&e.setMap.has(n.original)?(e.assignedMap.set(n.original,!1),e.setMap.delete(n.original)):(!n&&e.setMap.has(t)?e.assignedMap.set(t,!1):e.assignedMap.delete(t),e.setMap.delete(t))},clear(){if(!this.size)return;const t=C(this);B(t),V(t);for(const e of t.original)t.assignedMap.set(e,!1);t.setMap.clear()},values(){const t=C(this);B(t);const e=t.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:nt(t,e,{isValuesIterator:!0})}},entries(){const t=C(this);B(t);const e=t.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:nt(t,e,{isValuesIterator:!1})}},keys(){return this.values()},[v](){return this.values()},forEach(t,e){const n=this.values();let r=n.next();for(;!r.done;)t.call(e,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(rt,{intersection(t){return Set.prototype.intersection.call(new Set(this.values()),t)},union(t){return Set.prototype.union.call(new Set(this.values()),t)},difference(t){return Set.prototype.difference.call(new Set(this.values()),t)},symmetricDifference(t){return Set.prototype.symmetricDifference.call(new Set(this.values()),t)},isSubsetOf(t){return Set.prototype.isSubsetOf.call(new Set(this.values()),t)},isSupersetOf(t){return Set.prototype.isSupersetOf.call(new Set(this.values()),t)},isDisjointFrom(t){return Set.prototype.isDisjointFrom.call(new Set(this.values()),t)}});const it=Reflect.ownKeys(rt),st=new WeakSet,ot={get(t,e,n){var r,i;const s=null===(r=t.copy)||void 0===r?void 0:r[e];if(s&&st.has(s))return s;if(e===y)return t;let o;if(t.options.mark){const r="size"===e&&(t.original instanceof Map||t.original instanceof Set)?Reflect.get(t.original,e):Reflect.get(t.original,e,n);if(o=t.options.mark(r,b),o===b.mutable)return t.options.strict&&Z(r,t.options,!0),r}const a=O(t);if(a instanceof Map&&et.includes(e)){if("size"===e)return Object.getOwnPropertyDescriptor(tt,"size").get.call(t.proxy);const n=tt[e];if(n)return n.bind(t.proxy)}if(a instanceof Set&&it.includes(e)){if("size"===e)return Object.getOwnPropertyDescriptor(rt,"size").get.call(t.proxy);const n=rt[e];if(n)return n.bind(t.proxy)}if(!E(a,e)){const n=k(a,e);return n?"value"in n?n.value:null===(i=n.get)||void 0===i?void 0:i.call(t.proxy):void 0}const l=a[e];if(t.options.strict&&Z(l,t.options),t.finalized||!A(l,t.options))return l;if(l===N(t.original,e)){if(B(t),t.copy[e]=at({original:t.original[e],parentDraft:t,key:1===t.type?Number(e):e,finalities:t.finalities,options:t.options}),"function"==typeof o){const n=C(t.copy[e]);return B(n),V(n),n.copy}return t.copy[e]}return l},set(t,e,n){var r;if(3===t.type||2===t.type)throw new Error("Map/Set draft does not support any property assignment.");let i;if(1===t.type&&"length"!==e&&(!(Number.isInteger(i=Number(e))&&i>=0)||0!==e&&0!==i&&String(i)!==String(e)))throw new Error("Only supports setting array indices and the 'length' property.");const s=k(O(t),e);if(null==s?void 0:s.set)return s.set.call(t.proxy,n),!0;const o=N(O(t),e),a=C(o);return a&&L(a.original,n)?(t.copy[e]=n,t.assignedMap=null!==(r=t.assignedMap)&&void 0!==r?r:new Map,t.assignedMap.set(e,!1),!0):(L(n,o)&&(void 0!==n||E(t.original,e))||(B(t),V(t),E(t.original,e)&&L(n,t.original[e])?t.assignedMap.delete(e):t.assignedMap.set(e,!0),t.copy[e]=n,G(t,e,n,Q)),!0)},has:(t,e)=>e in O(t),ownKeys:t=>Reflect.ownKeys(O(t)),getOwnPropertyDescriptor(t,e){const n=O(t),r=Reflect.getOwnPropertyDescriptor(n,e);return r?{writable:!0,configurable:1!==t.type||"length"!==e,enumerable:r.enumerable,value:n[e]}:r},getPrototypeOf:t=>Reflect.getPrototypeOf(t.original),setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(t,e){var n;return 1===t.type?ot.set.call(this,t,e,void 0,t.proxy):(void 0!==N(t.original,e)||e in t.original?(B(t),V(t),t.assignedMap.set(e,!1)):(t.assignedMap=null!==(n=t.assignedMap)&&void 0!==n?n:new Map,t.assignedMap.delete(e)),t.copy&&delete t.copy[e],!0)}};function at(t){const{original:e,parentDraft:n,key:r,finalities:i,options:s}=t,o=P(e),a={type:o,finalized:!1,parent:n,original:e,copy:null,proxy:null,finalities:i,options:s,setMap:3===o?new Map(e.entries()):void 0};(r||"key"in t)&&(a.key=r);const{proxy:l,revoke:c}=Proxy.revocable(1===o?Object.assign([],a):a,ot);if(i.revoke.push(c),st.add(l),a.proxy=l,n){const t=n;t.finalities.draft.push(((e,n)=>{var i,s;const o=C(l);let a=3===t.type?t.setMap:t.copy;const c=T(a,r),u=C(c);if(u){let s=u.original;u.operated&&(s=x(c)),U(u),X(u,Q,e,n),t.options.enableAutoFreeze&&(t.options.updatedValues=null!==(i=t.options.updatedValues)&&void 0!==i?i:new WeakMap,t.options.updatedValues.set(s,u.original)),z(a,r,s)}null===(s=o.callbacks)||void 0===s||s.forEach((t=>{t(e,n)}))}))}else{const t=C(l);t.finalities.draft.push(((e,n)=>{U(t),X(t,Q,e,n)}))}return l}function lt(t,e,n,r,i){var s;const o=C(t),a=null!==(s=null==o?void 0:o.original)&&void 0!==s?s:t,l=!!e.length;if(null==o?void 0:o.operated)for(;o.finalities.draft.length>0;){o.finalities.draft.pop()(n,r)}const c=l?e[0]:o?o.operated?o.copy:o.original:t;return o&&D(o),i&&K(c,c,null==o?void 0:o.options.updatedValues),[c,n&&l?[{op:d,path:[],value:e[0]}]:n,r&&l?[{op:d,path:[],value:a}]:r]}function ct(t){const{rootDraft:e,value:n,useRawReturn:r=!1,isRoot:i=!0}=t;W(n,((n,r,i)=>{const s=C(r);if(s&&e&&s.finalities===e.finalities){t.isContainDraft=!0;const e=s.original;if(i instanceof Set){const t=Array.from(i);i.clear(),t.forEach((t=>i.add(n===t?e:t)))}else z(i,n,e)}else"object"==typeof r&&null!==r&&(t.value=r,t.isRoot=!1,ct(t))})),i&&(t.isContainDraft||console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance."),r&&console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value."))}function ut(t){var e;const n=C(t);if(!A(t,null==n?void 0:n.options))return t;const r=P(t);if(n&&!n.operated)return n.original;let i;function s(){i=2===r?S(t)?new Map(t):new(Object.getPrototypeOf(t).constructor)(t):3===r?Array.from(n.setMap.values()):_(t,null==n?void 0:n.options)}if(n){n.finalized=!0;try{s()}finally{n.finalized=!1}}else i=t;if(W(i,((e,r)=>{if(n&&L(T(n.original,e),r))return;const o=ut(r);o!==r&&(i===t&&s(),z(i,e,o))})),3===r){const t=null!==(e=null==n?void 0:n.original)&&void 0!==e?e:i;return M(t)?new Set(i):new(Object.getPrototypeOf(t).constructor)(i)}return i}function ht(t){if(!j(t))throw new Error(`current() is only used for Draft, parameter: ${t}`);return ut(t)}w.createDraft=at;const pt=function t(e,n,r){var i,s,o;if("function"==typeof e&&"function"!=typeof n)return function(r,...i){return t(r,(t=>e.call(this,t,...i)),n)};const a=e,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({},ft),c);const u=j(a)?ht(a):a,h=Array.isArray(c.mark)?(t,e)=>{for(const n of c.mark){if("function"!=typeof n)throw new Error(`Invalid mark: ${n}, 'mark' should be a function.`);const r=n(t,e);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(!A(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[g,y]=function(t,e){var n;const r={draft:[],revoke:[],handledSet:new WeakSet};let i,s;e.enablePatches&&(i=[],s=[]);const o=(null===(n=e.mark)||void 0===n?void 0:n.call(e,t,b))!==b.mutable&&A(t,e)?at({original:t,parentDraft:null,finalities:r,options:e}):t;return[o,(t=[])=>{const[n,r,a]=lt(o,t,i,s,e.enableAutoFreeze);return e.enablePatches?[n,r,a]:n}]}(u,d);if("function"!=typeof n){if(!A(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[g,y]}let v;try{v=l(g)}catch(t){throw D(C(g)),t}const w=t=>{const e=C(g);if(!j(t)){if(void 0!==t&&!L(t,g)&&(null==e?void 0:e.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==t?void 0:t[m];if(n){const r=n[0];return d.strict&&"object"==typeof t&&null!==t&&ct({rootDraft:e,value:t,useRawReturn:!0}),y([r])}if(void 0!==t)return"object"==typeof t&&null!==t&&ct({rootDraft:e,value:t}),y([t])}if(t===g||void 0===t)return y([]);const n=C(t);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return y([ht(t)])}return y([t])};return v instanceof Promise?v.then(w,(t=>{throw D(C(g)),t})):w(v)};var ft;Object.prototype.constructor.toString();class dt{constructor(t,e){this.value=t,this.reactor=e??new p(this)}set(t){this.value=t,this.reactor.emit({type:"SET",target:this,value:t})}get(){return this.value}increase(t=1){"number"==typeof this.value&&this.set(this.value+t)}produce(t){const[e,n]=pt(this.value);t(e),this.set(n())}}function gt(t,e){t.reactor.addBinding(e)}function yt(t,e){t.reactor.removeBinding(e)}function mt(t){return new dt(t)}const vt={on:function(t,e,n,r){"string"==typeof r&&(r=t.findName(h(r))),e.addEventListener(n,r)},ref:function(t,e,n,r){if("string"==typeof r&&(r=t.findName(h(r))),!(r instanceof c))throw Error("Rumious: ref directive required RumiousElementRef !");r.target=e},inject:function(t,e,n,r){if("string"==typeof r&&(r=t.findName(h(r))),!(r instanceof a))throw Error("Rumious: inject directive required RumiousInjector !");r.addTarget(e),r.inject(e)},bind:function(t,e,n,r){if("string"==typeof r&&(r=t.findName(h(r))),!(r instanceof dt))throw Error("Rumious: bind directive required RumiousState !");e.setAttribute(n,r.value),r.reactor.addBinding((({})=>{e.setAttribute(n,r.value)}))},model:function(t,e,n,r){if("string"==typeof r&&(r=t.findName(h(r))),!(r instanceof dt&&(e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)))throw Error("Rumious: model directive requires RumiousState and a valid form element!");{const t=e.type;e.addEventListener("input",(()=>{if(e instanceof HTMLInputElement)switch(t){case"checkbox":r.set(e.checked);break;case"radio":e.checked&&r.set(e.value);break;default:r.set(e.value)}else(e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&r.set(e.value)}))}}};class bt{domMap=new Map;constructor(t,e,n){this.state=t,this.callback=e,this.keyFn=n??((t,e)=>e)}prepare(t,e){this.anchorElement=t,this.context=e}async render(){await this.reconcile(this.state.value),this.state.reactor.addBinding(this.onStateChange.bind(this))}async onStateChange(t){if("APPEND"===t.type){const e=this.keyFn(t.item,t.key);if(!this.domMap.has(e)){const n=await this.callback(t.item,t.key),r=document.createDocumentFragment();this.context.renderHelper(this.context,n,r),this.anchorElement.appendChild(r),this.domMap.set(e,r)}}else if("SET_BY_KEY"===t.type){const e=this.keyFn(t.item,t.key),n=this.anchorElement.childNodes[t.key];if(n){const r=await this.callback(t.item,t.key),i=document.createDocumentFragment();this.context.renderHelper(this.context,r,i),this.anchorElement.replaceChild(i,n),this.domMap.set(e,i)}}else if("REMOVE_BY_KEY"===t.type){const e=this.anchorElement.childNodes[t.key];if(e){this.anchorElement.removeChild(e);const t=[...this.domMap.entries()].find((([,t])=>t===e));t&&this.domMap.delete(t[0])}}else if("INSERT_BY_KEY"===t.type){const e=this.keyFn(t.item,t.key);if(!this.domMap.has(e)){const n=await this.callback(t.item,t.key),r=document.createDocumentFragment();this.context.renderHelper(this.context,n,r);const i=this.anchorElement.childNodes[t.key]??null;this.anchorElement.insertBefore(r,i),this.domMap.set(e,r)}}else await this.reconcile(this.state.value)}async reconcile(t){const e=this.domMap,n=new Map,r=[];for(let i=0;i<t.length;i++){const s=t[i],o=this.keyFn(s,i);let a=e.get(o);if(!a){const t=await this.callback(s,i),e=document.createDocumentFragment();this.context.renderHelper(this.context,t,e),a=e}n.set(o,a),r.push(a)}this.anchorElement.textContent="";for(const t of r)this.anchorElement.appendChild(t);this.domMap=n}}function wt(t,e){return new bt(t,e)}async function Et(t,e,n,r){if(e.parentNode)if(function(t){return t!==Object(t)}(n))e.textContent=String(n);else if(n&&n instanceof dt){function i({}){document.contains(e)?e.textContent=n.value:n.reactor.removeBinding(i)}e.textContent=n.value,n.reactor.addBinding(i)}else if(Array.isArray(n))e.textContent=n.map(String).join("");else if(n instanceof bt)n.prepare(e.parentElement,r),n.render();else if(n instanceof HTMLElement)e.replaceWith(n);else if(n instanceof o){let s=document.createDocumentFragment();r.renderHelper?.(r,n,s),e.replaceWith(s)}else if(n instanceof NodeList||n instanceof HTMLCollection){if(0===n.length)return void e.remove();const a=document.createDocumentFragment();for(const l of Array.from(n))a.appendChild(l.cloneNode(!0));e.replaceWith(a),e.remove()}else if(n&&"function"==typeof n.toString)try{e.textContent=n.toString()}catch{e.textContent=""}else e.textContent=""}function kt(t){return new o(t)}window.RUMIOUS_JSX={template:kt,createElement:function(...t){throw Error("Rumious doesn't use createElement !")},addDirective:function(t,e,n,r="",i){let s=vt[n];if(!s)throw Error("Rumious: Cannot solve directive !");s(e,t,r,i)},dynamicValue:function(t,e,n,r){Et(0,e,n,r)},createComponent:function(t){let e=t.tagName;return window.customElements.get(e)||window.customElements.define(e,class extends r{static tag=e}),document.createElement(e)}};class Mt{constructor(t){this.target=t}list(){return Array.from(this.target.children)}getChild(t){return this.list()[t]}remove(t){this.list()[t]?.remove()}add(t){this.target.appendChild(t)}querySelector(t){return this.target.querySelector(t)}querySelectorAll(t){return this.target.querySelectorAll(t)}clear(){this.target.innerHTML=""}replaceChild(t,e){const n=this.getChild(t);n&&this.target.replaceChild(e,n)}insertBefore(t,e){const n=this.getChild(e);n?this.target.insertBefore(t,n):this.add(t)}prepend(t){this.target.prepend(t)}getFirstChild(){return this.list()[0]}getLastChild(){return this.list()[this.list().length-1]}hasChildren(){return this.target.hasChildNodes()}count(){return this.target.children.length}find(t){return this.list().find(t)}forEach(t){this.list().forEach(t)}removeAllMatching(t){this.querySelectorAll(t).forEach((t=>t.remove()))}toggleClass(t){this.list().forEach((e=>e.classList.toggle(t)))}setAttribute(t,e){this.list().forEach((n=>n.setAttribute(t,e)))}}class St extends dt{constructor(t,e){super(t,e)}set(t,e){if("number"==typeof t&&void 0!==e){const n=t,r=e;this.value[n]=r,this.reactor.emit({type:"SET_BY_KEY",value:[...this.value],target:this,key:n,item:r})}else{if(!Array.isArray(t))throw new Error("Invalid arguments passed to set()");super.set(t)}}get(t){return"number"==typeof t?this.value[t]:this.value}insert(t,e){return this.value.splice(t,0,e),this.reactor.emit({type:"INSERT_BY_KEY",value:this.value,target:this,key:t,item:e}),this}remove(t){return this.value.splice(t,1),this.reactor.emit({type:"REMOVE_BY_KEY",value:this.value,target:this,key:t}),this}append(t){return this.value.push(t),this.reactor.emit({type:"APPEND",value:this.value,target:this,item:t}),this}clear(){return this.value.length=0,this.reactor.emit({type:"SET",value:[],target:this}),this}replace(t,e){if(t<0||t>=this.value.length)throw new Error("Index out of bounds");return this.value[t]=e,this.reactor.emit({type:"SET_BY_KEY",value:[...this.value],target:this,key:t,item:e}),this}filter(t){return this.value=this.value.filter(t),this.reactor.emit({type:"SET",value:this.value,target:this}),this}map(t){return this.value=this.value.map(t),this.reactor.emit({type:"SET",value:this.value,target:this}),this}sort(t){return this.value.sort(t),this.reactor.emit({type:"SET",value:this.value,target:this}),this}reverse(){return this.value.reverse(),this.reactor.emit({type:"SET",value:this.value,target:this}),this}get length(){return this.value.length}forEach(t){this.value.forEach(t)}}function Ot(t){return new St(t)}class jt extends dt{#t=!1;constructor(t,e){super(t,e)}set(t,e){if(this.#t)throw new Error("Object is locked");if("string"==typeof t){const n=t,r=e;return this.value[n]=r,this.reactor.emit({type:"SET_BY_KEY",value:{...this.value},target:this,key:n,item:r}),this}if("object"!=typeof t)throw new Error("Invalid arguments passed to set()");super.set(t)}remove(t){if(this.#t)throw new Error("Object is locked");return t in this.value&&(delete this.value[t],this.reactor.emit({type:"REMOVE_BY_KEY",value:{...this.value},target:this,key:t})),this}merge(t){if(this.#t)throw new Error("Object is locked");return Object.assign(this.value,t),this.reactor.emit({type:"SET",value:{...this.value},target:this}),this}assign(t){if(this.#t)throw new Error("Object is locked");return this.value={...this.value,...t},this.reactor.emit({type:"SET",value:{...this.value},target:this}),this}clear(){if(this.#t)throw new Error("Object is locked");for(const t in this.value)delete this.value[t];return this.reactor.emit({type:"SET",value:{},target:this}),this}get(t){return"string"==typeof t?this.value[t]:this.value}keys(){return Object.keys(this.value)}values(){return Object.values(this.value)}entries(){return Object.entries(this.value)}has(t){return t in this.value}get size(){return Object.keys(this.value).length}forEach(t){Object.entries(this.value).forEach((([e,n])=>{t(n,e,this.value)}))}map(t){const e={};return Object.entries(this.value).forEach((([n,r])=>{e[n]=t(r,n,this.value)})),e}clone(){return JSON.parse(JSON.stringify(this.value))}toJSON(){return JSON.parse(JSON.stringify(this.value))}toObject(){return this.get()}lock(){return this.#t=!0,this}unlock(){return this.#t=!1,this}get isLocked(){return this.#t}freeze(){return Object.freeze(this.value),this}unfreeze(){return this.value=JSON.parse(JSON.stringify(this.value)),this}get isFrozen(){return Object.isFrozen(this.value)}}function Ct(t){return new jt(t)}export{i as RumiousApp,St as RumiousArrayState,Mt as RumiousChildrenRef,n as RumiousComponent,r as RumiousComponentElement,a as RumiousDymanicInjector,c as RumiousElementRef,jt as RumiousObjectState,o as RumiousRenderTemplate,dt as RumiousState,s as createApp,Ot as createArrayState,u as createElementRef,l as createHTMLInjector,Ct as createObjectState,mt as createState,wt as renderDynamicArray,kt as template,yt as unwatch,gt 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.cleans=[],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.renderContext.cleans.forEach((e=>e())),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(){console.warn("Directive haven't handler !")}}class l extends a{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return console.warn(`Missing event handler for event: ${this.name}`),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,this._id=Date.now()}setTarget(e,t,n){this.target={element:e,context:n,renderer:t}}clean(){this.target&&delete this.state.reactor.priorityBinding[this._id]}sync(){this.target&&(this.renderAll(),this.state.reactor.priorityBinding[this._id]=this.onChange.bind(this))}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 n.cleans.push((()=>{e.clean()})),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,this.priorityBinding={}}react(e){Object.keys(this.priorityBinding).forEach((t=>this.priorityBinding[t]?.(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__"),D=Symbol.iterator,P={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 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,P))===P.immutable||"function"==typeof n)}function H(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 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=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,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=>{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(!B(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)||!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),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=H(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)),B(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&&(!B(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,P))===P.mutable;if(r.options.strict&&fe(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=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{[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()}},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,P))===P.mutable;if(e.options.strict&&fe(o,e.options,c),c||l||!B(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()},[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(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,P),o===P.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||!B(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||console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance."),r&&console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value."))}function Me(e){var t;const n=q(e);if(!B(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(!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,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&&B(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(!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,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 De{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 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=De,e.RumiousComponent=n,e.RumiousComponentElement=w,e.RumiousComponentRef=Pe,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 De(e)},e.createComponent=g,e.createComponentElement=E,e.createComponentRef=function(e){return new Pe(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}({});
|
1
|
+
!function(){class t{constructor(t,e){this.target=t,this.app=e,this.onRenderFinished=[]}findName(t){return this.target[t]}}function e(t,n,r){let i=n.generator.bind(t.target);t.renderHelper=e,i(r,t),setTimeout((async()=>{const e=[...t.onRenderFinished];t.onRenderFinished=[];for(const t of e)await t()}),0)}class n extends HTMLElement{constructor(){super(),this.props={}}setup(t,e){this.context=t,this.componentConstructor=e}connectedCallback(){this.componentConstructor?(this.componentInstance=new this.componentConstructor,this.componentInstance.element=this,this.componentConstructor.classNames&&(this.className=this.componentConstructor.classNames),this.componentInstance.prepare(this.context,this.props),this.componentInstance.onCreate(),this.componentInstance.requestRender()):console.warn("Rumious: Cannot find matching component constructor.")}disconnectedCallback(){this.componentInstance?.onDestroy()}}var r=Object.freeze({__proto__:null,RumiousComponent:class{static classNames="";static tagName="rumious-component";constructor(){this.renderOptions={mode:"idle"}}onCreate(){}onRender(){}onDestroy(){}async onBeforeRender(){}prepare(e,n){this.props=n,this.context=new t(this,e.app)}async requestRender(){await this.onBeforeRender();let t=this.template();e(this.context,t,this.element),this.onRender()}requestCleanup(){}},RumiousComponentElement:n});class i{constructor(e,n={}){this.root=e,this.options=n,this.modules=[],this.context=new t(this,this)}addModule(t,e){let n=t.init(this,e);return this.modules.push(n),n}render(t){e(this.context,t,this.root)}}var o=Object.freeze({__proto__:null,RumiousApp:i,createApp:function(t,e){return new i(t,e)}});class s{constructor(t){this.generator=t}}class a{constructor(t){if(this.contents=t,this.targets=new Map,!t||0===t.length)throw new Error("Injector must be initialized with non-empty content");const e=t[0];this.type="string"==typeof e?"string":"element"}addTarget(t){this.targets.set(t,1)}inject(t){if(this.targets.has(t)&&this.contents)if(t.innerHTML="","string"===this.type)for(const e of this.contents)t.insertAdjacentHTML("beforeend",e);else for(const e of this.contents)t.appendChild(e)}injectAll(){for(const t of this.targets.keys())this.inject(t)}removeTarget(t){this.targets.delete(t)}clear(){this.targets.clear()}}class c{constructor(t){this.target=t}getElement(){return this.target}remove(){this.target.remove()}addChild(t){this.target.appendChild(t)}listChild(){return this.target.childNodes}querySelector(t){return this.target.querySelector(t)}querySelectorAll(t){return this.target.querySelectorAll(t)}set text(t){this.target.textContent=t}get text(){return this.target.textContent}set value(t){(this.target instanceof HTMLInputElement||this.target instanceof HTMLTextAreaElement)&&(this.target.value=t)}get value(){if(this.target instanceof HTMLInputElement||this.target instanceof HTMLTextAreaElement)return this.target.value}addClassName(t){this.target.classList.add(t)}removeClassName(t){this.target.classList.remove(t)}hasClassName(t){return this.target.classList.contains(t)}toggleClass(t,e){return this.target.classList.toggle(t,e)}setStyle(t){Object.assign(this.target.style,t)}getStyle(t){return getComputedStyle(this.target).getPropertyValue(t)}setAttribute(t,e){this.target.setAttribute(t,e)}getAttribute(t){return this.target.getAttribute(t)}removeAttribute(t){this.target.removeAttribute(t)}on(t,e,n){this.target.addEventListener(t,e,n)}off(t,e,n){this.target.removeEventListener(t,e,n)}set html(t){this.target.innerHTML=t}get html(){return this.target.innerHTML}getBoundingRect(){return this.target.getBoundingClientRect()}isInViewport(){const t=this.target.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}prependChild(t){this.target.prepend(t)}setDisabled(t){(this.target instanceof HTMLButtonElement||this.target instanceof HTMLInputElement||this.target instanceof HTMLTextAreaElement)&&(this.target.disabled=t)}addClasses(...t){this.target.classList.add(...t)}removeClasses(...t){this.target.classList.remove(...t)}replaceClass(t,e){this.target.classList.replace(t,e)}moveTo(t){t.appendChild(this.target)}getParent(){return this.target.parentElement}getNextSibling(){return this.target.nextElementSibling}getPreviousSibling(){return this.target.previousElementSibling}hide(){this.target.style.display="none"}show(){this.target.style.removeProperty("display")}isHidden(){return"none"===window.getComputedStyle(this.target).display}scrollIntoView(t={behavior:"smooth"}){this.target.scrollIntoView(t)}matches(t){return this.target.matches(t)}getChildren(){return Array.from(this.target.children)}insertAfter(t){this.target.parentNode&&this.target.parentNode.insertBefore(t,this.target.nextSibling)}insertBefore(t){this.target.parentNode&&this.target.parentNode.insertBefore(t,this.target)}clearChildren(){for(;this.target.firstChild;)this.target.removeChild(this.target.firstChild)}animate(t,e){return this.target.animate(t,e)}}function l(t){const e=t.indexOf("$");return-1!==e?t.slice(e+1):""}class u{constructor(t){this.target=t,this.bindings=[]}addBinding(t){this.bindings.push(t)}removeBinding(t){this.bindings=this.bindings.filter((e=>e!==t))}async emit(t){await Promise.allSettled(this.bindings.map((e=>{try{const n=e(t);return n instanceof Promise?n:Promise.resolve(n)}catch(t){return Promise.reject(t)}})))}}const h="remove",p="replace",f="add",d=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),g=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),m=Symbol.iterator,y={mutable:"mutable",immutable:"immutable"},v={};function b(t,e){return t instanceof Map?t.has(e):Object.prototype.hasOwnProperty.call(t,e)}function w(t,e){if(e in t){let n=Reflect.getPrototypeOf(t);for(;n;){const t=Reflect.getOwnPropertyDescriptor(n,e);if(t)return t;n=Reflect.getPrototypeOf(n)}}}function E(t){return Object.getPrototypeOf(t)===Set.prototype}function k(t){return Object.getPrototypeOf(t)===Map.prototype}function M(t){var e;return null!==(e=t.copy)&&void 0!==e?e:t.original}function S(t){return!!O(t)}function O(t){return"object"!=typeof t?null:null==t?void 0:t[d]}function j(t){var e;const n=O(t);return n?null!==(e=n.copy)&&void 0!==e?e:n.original:t}function C(t,e){if(!t||"object"!=typeof t)return!1;let n;return Object.getPrototypeOf(t)===Object.prototype||Array.isArray(t)||t instanceof Map||t instanceof Set||!!(null==e?void 0:e.mark)&&((n=e.mark(t,y))===y.immutable||"function"==typeof n)}function A(t,e=[]){if(Object.hasOwnProperty.call(t,"key")){const n=t.parent.copy,r=O(x(n,t.key));if(null!==r&&(null==r?void 0:r.original)!==t.original)return null;const i=3===t.parent.type,o=i?Array.from(t.parent.setMap.keys()).indexOf(t.key):t.key;if(!(i&&n.size>o||b(n,o)))return null;e.push(o)}if(t.parent)return A(t.parent,e);e.reverse();try{!function(t,e){for(let n=0;n<e.length-1;n+=1){const r=e[n];if("object"!=typeof(t=x(3===R(t)?Array.from(t):t,r)))throw new Error(`Cannot resolve patch at '${e.join("/")}'.`)}}(t.copy,e)}catch(t){return null}return e}function R(t){return Array.isArray(t)?1:t instanceof Map?2:t instanceof Set?3:0}function x(t,e){return 2===R(t)?t.get(e):t[e]}function T(t,e,n){2===R(t)?t.set(e,n):t[e]=n}function _(t,e){const n=O(t);return(n?M(n):t)[e]}function P(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}function z(t){if(t)for(;t.finalities.revoke.length>0;){t.finalities.revoke.pop()()}}function N(t,e){return e?t:[""].concat(t).map((t=>{const e=`${t}`;return-1===e.indexOf("/")&&-1===e.indexOf("~")?e:e.replace(/~/g,"~0").replace(/\//g,"~1")})).join("/")}const D=Object.prototype.propertyIsEnumerable;function L(t,e){let n;if(Array.isArray(t))return Array.prototype.concat.call(t);if(t instanceof Set){if(!E(t)){return new(0,Object.getPrototypeOf(t).constructor)(t.values())}return Set.prototype.difference?Set.prototype.difference.call(t,new Set):new Set(t.values())}if(t instanceof Map){if(!k(t)){return new(0,Object.getPrototypeOf(t).constructor)(t)}return new Map(t)}if((null==e?void 0:e.mark)&&(n=e.mark(t,y),void 0!==n)&&n!==y.mutable){if(n===y.immutable)return function(t){const e=Object.create(Object.getPrototypeOf(t));return Reflect.ownKeys(t).forEach((n=>{let r=Reflect.getOwnPropertyDescriptor(t,n);r.enumerable&&r.configurable&&r.writable?e[n]=t[n]:(r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:t[n]}),Reflect.defineProperty(e,n,r))})),e}(t);if("function"==typeof n){if(e.enablePatches||e.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 t&&Object.getPrototypeOf(t)===Object.prototype){const e={};return Object.keys(t).forEach((n=>{e[n]=t[n]})),Object.getOwnPropertySymbols(t).forEach((n=>{D.call(t,n)&&(e[n]=t[n])})),e}throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function I(t){t.copy||(t.copy=L(t.original,t.options))}function F(t){if(!C(t))return j(t);if(Array.isArray(t))return t.map(F);if(t instanceof Map){const e=Array.from(t.entries()).map((([t,e])=>[t,F(e)]));if(!k(t)){return new(0,Object.getPrototypeOf(t).constructor)(e)}return new Map(e)}if(t instanceof Set){const e=Array.from(t).map(F);if(!E(t)){return new(0,Object.getPrototypeOf(t).constructor)(e)}return new Set(e)}const e=Object.create(Object.getPrototypeOf(t));for(const n in t)e[n]=F(t[n]);return e}function H(t){return S(t)?F(t):t}function B(t){var e;t.assignedMap=null!==(e=t.assignedMap)&&void 0!==e?e:new Map,t.operated||(t.operated=!0,t.parent&&B(t.parent))}function Y(){throw new Error("Cannot modify frozen object")}function V(t,e,n,r,i){{n=null!=n?n:new WeakMap,r=null!=r?r:[],i=null!=i?i:[];const o=n.has(t)?n.get(t):t;if(r.length>0){const t=r.indexOf(o);if(o&&"object"==typeof o&&-1!==t){if(r[0]===o)throw new Error("Forbids circular reference");throw new Error(`Forbids circular reference: ~/${i.slice(0,t).map(((t,e)=>{if("symbol"==typeof t)return`[${t.toString()}]`;const n=r[e];return"object"==typeof t&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(t):t})).join("/")}`)}r.push(o),i.push(e)}else r.push(o)}if(Object.isFrozen(t)||S(t))return r.pop(),void i.pop();switch(R(t)){case 2:for(const[e,o]of t)V(e,e,n,r,i),V(o,e,n,r,i);t.set=t.clear=t.delete=Y;break;case 3:for(const e of t)V(e,e,n,r,i);t.add=t.clear=t.delete=Y;break;case 1:Object.freeze(t);let e=0;for(const o of t)V(o,e,n,r,i),e+=1;break;default:Object.freeze(t),Object.keys(t).forEach((e=>{V(t[e],e,n,r,i)}))}r.pop(),i.pop()}function q(t,e){const n=R(t);if(0===n)Reflect.ownKeys(t).forEach((n=>{e(n,t[n],t)}));else if(1===n){let n=0;for(const r of t)e(n,r,t),n+=1}else t.forEach(((n,r)=>e(r,n,t)))}function K(t,e,n){if(S(t)||!C(t,n)||e.has(t)||Object.isFrozen(t))return;const r=t instanceof Set,i=r?new Map:void 0;if(e.add(t),q(t,((o,s)=>{var a;if(S(s)){const e=O(s);I(e);const n=(null===(a=e.assignedMap)||void 0===a?void 0:a.size)||e.operated?e.copy:e.original;T(r?i:t,o,n)}else K(s,e,n)})),i){const e=t,n=Array.from(e);e.clear(),n.forEach((t=>{e.add(i.has(t)?i.get(t):t)}))}}function W(t,e){const n=3===t.type?t.setMap:t.copy;t.finalities.revoke.length>1&&t.assignedMap.get(e)&&n&&K(x(n,e),t.finalities.handledSet,t.options)}function $(t){3===t.type&&t.copy&&(t.copy.clear(),t.setMap.forEach((e=>{t.copy.add(j(e))})))}function J(t,e,n,r){if(t.operated&&t.assignedMap&&t.assignedMap.size>0&&!t.finalized){if(n&&r){const i=A(t);i&&e(t,i,n,r)}t.finalized=!0}}function U(t,e,n,r){const i=O(n);i&&(i.callbacks||(i.callbacks=[]),i.callbacks.push(((o,s)=>{var a;const c=3===t.type?t.setMap:t.copy;if(P(x(c,e),n)){let n=i.original;i.copy&&(n=i.copy),$(t),J(t,r,o,s),t.options.enableAutoFreeze&&(t.options.updatedValues=null!==(a=t.options.updatedValues)&&void 0!==a?a:new WeakMap,t.options.updatedValues.set(n,i.original)),T(c,e,n)}})),t.options.enableAutoFreeze&&i.finalities!==t.finalities&&(t.options.enableAutoFreeze=!1)),C(n,t.options)&&t.finalities.draft.push((()=>{P(x(3===t.type?t.setMap:t.copy,e),n)&&W(t,e)}))}function X(t,e,n,r){const{pathAsArray:i=!0}=t.options.enablePatches;switch(t.type){case 0:case 2:return function({original:t,copy:e,assignedMap:n},r,i,o,s){n.forEach(((n,a)=>{const c=x(t,a),l=H(x(e,a)),u=n?b(t,a)?p:f:h;if(P(c,l)&&u===p)return;const d=N(r.concat(a),s);i.push(u===h?{op:u,path:d}:{op:u,path:d,value:l}),o.push(u===f?{op:h,path:d}:u===h?{op:f,path:d,value:c}:{op:p,path:d,value:c})}))}(t,e,n,r,i);case 1:return function(t,e,n,r,i){let{original:o,assignedMap:s,options:a}=t,c=t.copy;c.length<o.length&&([o,c]=[c,o],[n,r]=[r,n]);for(let t=0;t<o.length;t+=1)if(s.get(t.toString())&&c[t]!==o[t]){const s=N(e.concat([t]),i);n.push({op:p,path:s,value:H(c[t])}),r.push({op:p,path:s,value:H(o[t])})}for(let t=o.length;t<c.length;t+=1){const r=N(e.concat([t]),i);n.push({op:f,path:r,value:H(c[t])})}if(o.length<c.length){const{arrayLengthAssignment:t=!0}=a.enablePatches;if(t){const t=N(e.concat(["length"]),i);r.push({op:p,path:t,value:o.length})}else for(let t=c.length;o.length<t;t-=1){const n=N(e.concat([t-1]),i);r.push({op:h,path:n})}}}(t,e,n,r,i);case 3:return function({original:t,copy:e},n,r,i,o){let s=0;t.forEach((t=>{if(!e.has(t)){const e=N(n.concat([s]),o);r.push({op:h,path:e,value:t}),i.unshift({op:f,path:e,value:t})}s+=1})),s=0,e.forEach((e=>{if(!t.has(e)){const t=N(n.concat([s]),o);r.push({op:f,path:t,value:e}),i.unshift({op:h,path:t,value:e})}s+=1}))}(t,e,n,r,i)}}const G=(t,e,n=!1)=>{if("object"==typeof t&&null!==t&&(!C(t,e)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},Q={get size(){return M(O(this)).size},has(t){return M(O(this)).has(t)},set(t,e){const n=O(this),r=M(n);return r.has(t)&&P(r.get(t),e)||(I(n),B(n),n.assignedMap.set(t,!0),n.copy.set(t,e),U(n,t,e,X)),this},delete(t){if(!this.has(t))return!1;const e=O(this);return I(e),B(e),e.original.has(t)?e.assignedMap.set(t,!1):e.assignedMap.delete(t),e.copy.delete(t),!0},clear(){const t=O(this);if(this.size){I(t),B(t),t.assignedMap=new Map;for(const[e]of t.original)t.assignedMap.set(e,!1);t.copy.clear()}},forEach(t,e){M(O(this)).forEach(((n,r)=>{t.call(e,this.get(r),r,this)}))},get(t){var e,n;const r=O(this),i=M(r).get(t),o=(null===(n=(e=r.options).mark)||void 0===n?void 0:n.call(e,i,y))===y.mutable;if(r.options.strict&&G(i,r.options,o),o)return i;if(r.finalized||!C(i,r.options))return i;if(i!==r.original.get(t))return i;const s=v.createDraft({original:i,parentDraft:r,key:t,finalities:r.finalities,options:r.options});return I(r),r.copy.set(t,s),s},keys(){return M(O(this)).keys()},values(){const t=this.keys();return{[m]:()=>this.values(),next:()=>{const e=t.next();if(e.done)return e;return{done:!1,value:this.get(e.value)}}}},entries(){const t=this.keys();return{[m]:()=>this.entries(),next:()=>{const e=t.next();if(e.done)return e;const n=this.get(e.value);return{done:!1,value:[e.value,n]}}}},[m](){return this.entries()}},Z=Reflect.ownKeys(Q),tt=(t,e,{isValuesIterator:n})=>()=>{var r,i;const o=e.next();if(o.done)return o;const s=o.value;let a=t.setMap.get(s);const c=O(a),l=(null===(i=(r=t.options).mark)||void 0===i?void 0:i.call(r,a,y))===y.mutable;if(t.options.strict&&G(s,t.options,l),l||c||!C(s,t.options)||t.finalized||!t.original.has(s))c&&(a=c.proxy);else{const e=v.createDraft({original:s,parentDraft:t,key:s,finalities:t.finalities,options:t.options});t.setMap.set(s,e),a=e}return{done:!1,value:n?a:[a,a]}},et={get size(){return O(this).setMap.size},has(t){const e=O(this);if(e.setMap.has(t))return!0;I(e);const n=O(t);return!(!n||!e.setMap.has(n.original))},add(t){const e=O(this);return this.has(t)||(I(e),B(e),e.assignedMap.set(t,!0),e.setMap.set(t,t),U(e,t,t,X)),this},delete(t){if(!this.has(t))return!1;const e=O(this);I(e),B(e);const n=O(t);return n&&e.setMap.has(n.original)?(e.assignedMap.set(n.original,!1),e.setMap.delete(n.original)):(!n&&e.setMap.has(t)?e.assignedMap.set(t,!1):e.assignedMap.delete(t),e.setMap.delete(t))},clear(){if(!this.size)return;const t=O(this);I(t),B(t);for(const e of t.original)t.assignedMap.set(e,!1);t.setMap.clear()},values(){const t=O(this);I(t);const e=t.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:tt(t,e,{isValuesIterator:!0})}},entries(){const t=O(this);I(t);const e=t.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:tt(t,e,{isValuesIterator:!1})}},keys(){return this.values()},[m](){return this.values()},forEach(t,e){const n=this.values();let r=n.next();for(;!r.done;)t.call(e,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(et,{intersection(t){return Set.prototype.intersection.call(new Set(this.values()),t)},union(t){return Set.prototype.union.call(new Set(this.values()),t)},difference(t){return Set.prototype.difference.call(new Set(this.values()),t)},symmetricDifference(t){return Set.prototype.symmetricDifference.call(new Set(this.values()),t)},isSubsetOf(t){return Set.prototype.isSubsetOf.call(new Set(this.values()),t)},isSupersetOf(t){return Set.prototype.isSupersetOf.call(new Set(this.values()),t)},isDisjointFrom(t){return Set.prototype.isDisjointFrom.call(new Set(this.values()),t)}});const nt=Reflect.ownKeys(et),rt=new WeakSet,it={get(t,e,n){var r,i;const o=null===(r=t.copy)||void 0===r?void 0:r[e];if(o&&rt.has(o))return o;if(e===d)return t;let s;if(t.options.mark){const r="size"===e&&(t.original instanceof Map||t.original instanceof Set)?Reflect.get(t.original,e):Reflect.get(t.original,e,n);if(s=t.options.mark(r,y),s===y.mutable)return t.options.strict&&G(r,t.options,!0),r}const a=M(t);if(a instanceof Map&&Z.includes(e)){if("size"===e)return Object.getOwnPropertyDescriptor(Q,"size").get.call(t.proxy);const n=Q[e];if(n)return n.bind(t.proxy)}if(a instanceof Set&&nt.includes(e)){if("size"===e)return Object.getOwnPropertyDescriptor(et,"size").get.call(t.proxy);const n=et[e];if(n)return n.bind(t.proxy)}if(!b(a,e)){const n=w(a,e);return n?"value"in n?n.value:null===(i=n.get)||void 0===i?void 0:i.call(t.proxy):void 0}const c=a[e];if(t.options.strict&&G(c,t.options),t.finalized||!C(c,t.options))return c;if(c===_(t.original,e)){if(I(t),t.copy[e]=ot({original:t.original[e],parentDraft:t,key:1===t.type?Number(e):e,finalities:t.finalities,options:t.options}),"function"==typeof s){const n=O(t.copy[e]);return I(n),B(n),n.copy}return t.copy[e]}return c},set(t,e,n){var r;if(3===t.type||2===t.type)throw new Error("Map/Set draft does not support any property assignment.");let i;if(1===t.type&&"length"!==e&&(!(Number.isInteger(i=Number(e))&&i>=0)||0!==e&&0!==i&&String(i)!==String(e)))throw new Error("Only supports setting array indices and the 'length' property.");const o=w(M(t),e);if(null==o?void 0:o.set)return o.set.call(t.proxy,n),!0;const s=_(M(t),e),a=O(s);return a&&P(a.original,n)?(t.copy[e]=n,t.assignedMap=null!==(r=t.assignedMap)&&void 0!==r?r:new Map,t.assignedMap.set(e,!1),!0):(P(n,s)&&(void 0!==n||b(t.original,e))||(I(t),B(t),b(t.original,e)&&P(n,t.original[e])?t.assignedMap.delete(e):t.assignedMap.set(e,!0),t.copy[e]=n,U(t,e,n,X)),!0)},has:(t,e)=>e in M(t),ownKeys:t=>Reflect.ownKeys(M(t)),getOwnPropertyDescriptor(t,e){const n=M(t),r=Reflect.getOwnPropertyDescriptor(n,e);return r?{writable:!0,configurable:1!==t.type||"length"!==e,enumerable:r.enumerable,value:n[e]}:r},getPrototypeOf:t=>Reflect.getPrototypeOf(t.original),setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(t,e){var n;return 1===t.type?it.set.call(this,t,e,void 0,t.proxy):(void 0!==_(t.original,e)||e in t.original?(I(t),B(t),t.assignedMap.set(e,!1)):(t.assignedMap=null!==(n=t.assignedMap)&&void 0!==n?n:new Map,t.assignedMap.delete(e)),t.copy&&delete t.copy[e],!0)}};function ot(t){const{original:e,parentDraft:n,key:r,finalities:i,options:o}=t,s=R(e),a={type:s,finalized:!1,parent:n,original:e,copy:null,proxy:null,finalities:i,options:o,setMap:3===s?new Map(e.entries()):void 0};(r||"key"in t)&&(a.key=r);const{proxy:c,revoke:l}=Proxy.revocable(1===s?Object.assign([],a):a,it);if(i.revoke.push(l),rt.add(c),a.proxy=c,n){const t=n;t.finalities.draft.push(((e,n)=>{var i,o;const s=O(c);let a=3===t.type?t.setMap:t.copy;const l=x(a,r),u=O(l);if(u){let o=u.original;u.operated&&(o=j(l)),$(u),J(u,X,e,n),t.options.enableAutoFreeze&&(t.options.updatedValues=null!==(i=t.options.updatedValues)&&void 0!==i?i:new WeakMap,t.options.updatedValues.set(o,u.original)),T(a,r,o)}null===(o=s.callbacks)||void 0===o||o.forEach((t=>{t(e,n)}))}))}else{const t=O(c);t.finalities.draft.push(((e,n)=>{$(t),J(t,X,e,n)}))}return c}function st(t,e,n,r,i){var o;const s=O(t),a=null!==(o=null==s?void 0:s.original)&&void 0!==o?o:t,c=!!e.length;if(null==s?void 0:s.operated)for(;s.finalities.draft.length>0;){s.finalities.draft.pop()(n,r)}const l=c?e[0]:s?s.operated?s.copy:s.original:t;return s&&z(s),i&&V(l,l,null==s?void 0:s.options.updatedValues),[l,n&&c?[{op:p,path:[],value:e[0]}]:n,r&&c?[{op:p,path:[],value:a}]:r]}function at(t){const{rootDraft:e,value:n,useRawReturn:r=!1,isRoot:i=!0}=t;q(n,((n,r,i)=>{const o=O(r);if(o&&e&&o.finalities===e.finalities){t.isContainDraft=!0;const e=o.original;if(i instanceof Set){const t=Array.from(i);i.clear(),t.forEach((t=>i.add(n===t?e:t)))}else T(i,n,e)}else"object"==typeof r&&null!==r&&(t.value=r,t.isRoot=!1,at(t))})),i&&(t.isContainDraft||console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance."),r&&console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value."))}function ct(t){var e;const n=O(t);if(!C(t,null==n?void 0:n.options))return t;const r=R(t);if(n&&!n.operated)return n.original;let i;function o(){i=2===r?k(t)?new Map(t):new(Object.getPrototypeOf(t).constructor)(t):3===r?Array.from(n.setMap.values()):L(t,null==n?void 0:n.options)}if(n){n.finalized=!0;try{o()}finally{n.finalized=!1}}else i=t;if(q(i,((e,r)=>{if(n&&P(x(n.original,e),r))return;const s=ct(r);s!==r&&(i===t&&o(),T(i,e,s))})),3===r){const t=null!==(e=null==n?void 0:n.original)&&void 0!==e?e:i;return E(t)?new Set(i):new(Object.getPrototypeOf(t).constructor)(i)}return i}function lt(t){if(!S(t))throw new Error(`current() is only used for Draft, parameter: ${t}`);return ct(t)}v.createDraft=ot;const ut=function t(e,n,r){var i,o,s;if("function"==typeof e&&"function"!=typeof n)return function(r,...i){return t(r,(t=>e.call(this,t,...i)),n)};const a=e,c=n;let l=r;if("function"!=typeof n&&(l=n),void 0!==l&&"[object Object]"!==Object.prototype.toString.call(l))throw new Error(`Invalid options: ${l}, 'options' should be an object.`);l=Object.assign(Object.assign({},ht),l);const u=S(a)?lt(a):a,h=Array.isArray(l.mark)?(t,e)=>{for(const n of l.mark){if("function"!=typeof n)throw new Error(`Invalid mark: ${n}, 'mark' should be a function.`);const r=n(t,e);if(r)return r}}:l.mark,p=null!==(i=l.enablePatches)&&void 0!==i&&i,f=null!==(o=l.strict)&&void 0!==o&&o,d={enableAutoFreeze:null!==(s=l.enableAutoFreeze)&&void 0!==s&&s,mark:h,strict:f,enablePatches:p};if(!C(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[m,v]=function(t,e){var n;const r={draft:[],revoke:[],handledSet:new WeakSet};let i,o;e.enablePatches&&(i=[],o=[]);const s=(null===(n=e.mark)||void 0===n?void 0:n.call(e,t,y))!==y.mutable&&C(t,e)?ot({original:t,parentDraft:null,finalities:r,options:e}):t;return[s,(t=[])=>{const[n,r,a]=st(s,t,i,o,e.enableAutoFreeze);return e.enablePatches?[n,r,a]:n}]}(u,d);if("function"!=typeof n){if(!C(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[m,v]}let b;try{b=c(m)}catch(t){throw z(O(m)),t}const w=t=>{const e=O(m);if(!S(t)){if(void 0!==t&&!P(t,m)&&(null==e?void 0:e.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==t?void 0:t[g];if(n){const r=n[0];return d.strict&&"object"==typeof t&&null!==t&&at({rootDraft:e,value:t,useRawReturn:!0}),v([r])}if(void 0!==t)return"object"==typeof t&&null!==t&&at({rootDraft:e,value:t}),v([t])}if(t===m||void 0===t)return v([]);const n=O(t);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return v([lt(t)])}return v([t])};return b instanceof Promise?b.then(w,(t=>{throw z(O(m)),t})):w(b)};var ht;Object.prototype.constructor.toString();class pt{constructor(t,e){this.value=t,this.reactor=e??new u(this)}set(t){this.value=t,this.reactor.emit({type:"SET",target:this,value:t})}get(){return this.value}increase(t=1){"number"==typeof this.value&&this.set(this.value+t)}produce(t){const[e,n]=ut(this.value);t(e),this.set(n())}}const ft={on:function(t,e,n,r){"string"==typeof r&&(r=t.findName(l(r))),e.addEventListener(n,r)},ref:function(t,e,n,r){if("string"==typeof r&&(r=t.findName(l(r))),!(r instanceof c))throw Error("Rumious: ref directive required RumiousElementRef !");r.target=e},inject:function(t,e,n,r){if("string"==typeof r&&(r=t.findName(l(r))),!(r instanceof a))throw Error("Rumious: inject directive required RumiousInjector !");r.addTarget(e),r.inject(e)},bind:function(t,e,n,r){if("string"==typeof r&&(r=t.findName(l(r))),!(r instanceof pt))throw Error("Rumious: bind directive required RumiousState !");e.setAttribute(n,r.value),r.reactor.addBinding((({})=>{e.setAttribute(n,r.value)}))},model:function(t,e,n,r){if("string"==typeof r&&(r=t.findName(l(r))),!(r instanceof pt&&(e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)))throw Error("Rumious: model directive requires RumiousState and a valid form element!");{const t=e.type;e.addEventListener("input",(()=>{if(e instanceof HTMLInputElement)switch(t){case"checkbox":r.set(e.checked);break;case"radio":e.checked&&r.set(e.value);break;default:r.set(e.value)}else(e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&r.set(e.value)}))}}};class dt{domMap=new Map;constructor(t,e,n){this.state=t,this.callback=e,this.keyFn=n??((t,e)=>e)}prepare(t,e){this.anchorElement=t,this.context=e}async render(){await this.reconcile(this.state.value),this.state.reactor.addBinding(this.onStateChange.bind(this))}async onStateChange(t){if("APPEND"===t.type){const e=this.keyFn(t.item,t.key);if(!this.domMap.has(e)){const n=await this.callback(t.item,t.key),r=document.createDocumentFragment();this.context.renderHelper(this.context,n,r),this.anchorElement.appendChild(r),this.domMap.set(e,r)}}else if("SET_BY_KEY"===t.type){const e=this.keyFn(t.item,t.key),n=this.anchorElement.childNodes[t.key];if(n){const r=await this.callback(t.item,t.key),i=document.createDocumentFragment();this.context.renderHelper(this.context,r,i),this.anchorElement.replaceChild(i,n),this.domMap.set(e,i)}}else if("REMOVE_BY_KEY"===t.type){const e=this.anchorElement.childNodes[t.key];if(e){this.anchorElement.removeChild(e);const t=[...this.domMap.entries()].find((([,t])=>t===e));t&&this.domMap.delete(t[0])}}else if("INSERT_BY_KEY"===t.type){const e=this.keyFn(t.item,t.key);if(!this.domMap.has(e)){const n=await this.callback(t.item,t.key),r=document.createDocumentFragment();this.context.renderHelper(this.context,n,r);const i=this.anchorElement.childNodes[t.key]??null;this.anchorElement.insertBefore(r,i),this.domMap.set(e,r)}}else await this.reconcile(this.state.value)}async reconcile(t){const e=this.domMap,n=new Map,r=[];for(let i=0;i<t.length;i++){const o=t[i],s=this.keyFn(o,i);let a=e.get(s);if(!a){const t=await this.callback(o,i),e=document.createDocumentFragment();this.context.renderHelper(this.context,t,e),a=e}n.set(s,a),r.push(a)}this.anchorElement.textContent="";for(const t of r)this.anchorElement.appendChild(t);this.domMap=n}}async function gt(t,e,n,r){if(e.parentNode)if(function(t){return t!==Object(t)}(n))e.textContent=String(n);else if(n&&n instanceof pt){function i({}){document.contains(e)?e.textContent=n.value:n.reactor.removeBinding(i)}e.textContent=n.value,n.reactor.addBinding(i)}else if(Array.isArray(n))e.textContent=n.map(String).join("");else if(n instanceof dt)n.prepare(e.parentElement,r),n.render();else if(n instanceof HTMLElement)e.replaceWith(n);else if(n instanceof s){let o=document.createDocumentFragment();r.renderHelper?.(r,n,o),e.replaceWith(o)}else if(n instanceof NodeList||n instanceof HTMLCollection){if(0===n.length)return void e.remove();const a=document.createDocumentFragment();for(const c of Array.from(n))a.appendChild(c.cloneNode(!0));e.replaceWith(a),e.remove()}else if(n&&"function"==typeof n.toString)try{e.textContent=n.toString()}catch{e.textContent=""}else e.textContent=""}function mt(t){return new s(t)}window.RUMIOUS_JSX={template:mt,createElement:function(...t){throw Error("Rumious doesn't use createElement !")},addDirective:function(t,e,n,r="",i){let o=ft[n];if(!o)throw Error("Rumious: Cannot solve directive !");o(e,t,r,i)},dynamicValue:function(t,e,n,r){gt(0,e,n,r)},createComponent:function(t){let e=t.tagName;return window.customElements.get(e)||window.customElements.define(e,class extends n{static tag=e}),document.createElement(e)}};var yt=Object.freeze({__proto__:null,template:mt}),vt=Object.freeze({__proto__:null,RumiousDymanicInjector:a,RumiousRenderTemplate:s,createHTMLInjector:function(t){return new a([t])},renderDynamicArray:function(t,e){return new dt(t,e)}});var bt=Object.freeze({__proto__:null,RumiousChildrenRef:class{constructor(t){this.target=t}list(){return Array.from(this.target.children)}getChild(t){return this.list()[t]}remove(t){this.list()[t]?.remove()}add(t){this.target.appendChild(t)}querySelector(t){return this.target.querySelector(t)}querySelectorAll(t){return this.target.querySelectorAll(t)}clear(){this.target.innerHTML=""}replaceChild(t,e){const n=this.getChild(t);n&&this.target.replaceChild(e,n)}insertBefore(t,e){const n=this.getChild(e);n?this.target.insertBefore(t,n):this.add(t)}prepend(t){this.target.prepend(t)}getFirstChild(){return this.list()[0]}getLastChild(){return this.list()[this.list().length-1]}hasChildren(){return this.target.hasChildNodes()}count(){return this.target.children.length}find(t){return this.list().find(t)}forEach(t){this.list().forEach(t)}removeAllMatching(t){this.querySelectorAll(t).forEach((t=>t.remove()))}toggleClass(t){this.list().forEach((e=>e.classList.toggle(t)))}setAttribute(t,e){this.list().forEach((n=>n.setAttribute(t,e)))}},RumiousElementRef:c,createElementRef:function(){return new c(document.createElement("span"))}});class wt extends pt{constructor(t,e){super(t,e)}set(t,e){if("number"==typeof t&&void 0!==e){const n=t,r=e;this.value[n]=r,this.reactor.emit({type:"SET_BY_KEY",value:[...this.value],target:this,key:n,item:r})}else{if(!Array.isArray(t))throw new Error("Invalid arguments passed to set()");super.set(t)}}get(t){return"number"==typeof t?this.value[t]:this.value}insert(t,e){return this.value.splice(t,0,e),this.reactor.emit({type:"INSERT_BY_KEY",value:this.value,target:this,key:t,item:e}),this}remove(t){return this.value.splice(t,1),this.reactor.emit({type:"REMOVE_BY_KEY",value:this.value,target:this,key:t}),this}append(t){return this.value.push(t),this.reactor.emit({type:"APPEND",value:this.value,target:this,item:t}),this}clear(){return this.value.length=0,this.reactor.emit({type:"SET",value:[],target:this}),this}replace(t,e){if(t<0||t>=this.value.length)throw new Error("Index out of bounds");return this.value[t]=e,this.reactor.emit({type:"SET_BY_KEY",value:[...this.value],target:this,key:t,item:e}),this}filter(t){return this.value=this.value.filter(t),this.reactor.emit({type:"SET",value:this.value,target:this}),this}map(t){return this.value=this.value.map(t),this.reactor.emit({type:"SET",value:this.value,target:this}),this}sort(t){return this.value.sort(t),this.reactor.emit({type:"SET",value:this.value,target:this}),this}reverse(){return this.value.reverse(),this.reactor.emit({type:"SET",value:this.value,target:this}),this}get length(){return this.value.length}forEach(t){this.value.forEach(t)}}class Et extends pt{#t=!1;constructor(t,e){super(t,e)}set(t,e){if(this.#t)throw new Error("Object is locked");if("string"==typeof t){const n=t,r=e;return this.value[n]=r,this.reactor.emit({type:"SET_BY_KEY",value:{...this.value},target:this,key:n,item:r}),this}if("object"!=typeof t)throw new Error("Invalid arguments passed to set()");super.set(t)}remove(t){if(this.#t)throw new Error("Object is locked");return t in this.value&&(delete this.value[t],this.reactor.emit({type:"REMOVE_BY_KEY",value:{...this.value},target:this,key:t})),this}merge(t){if(this.#t)throw new Error("Object is locked");return Object.assign(this.value,t),this.reactor.emit({type:"SET",value:{...this.value},target:this}),this}assign(t){if(this.#t)throw new Error("Object is locked");return this.value={...this.value,...t},this.reactor.emit({type:"SET",value:{...this.value},target:this}),this}clear(){if(this.#t)throw new Error("Object is locked");for(const t in this.value)delete this.value[t];return this.reactor.emit({type:"SET",value:{},target:this}),this}get(t){return"string"==typeof t?this.value[t]:this.value}keys(){return Object.keys(this.value)}values(){return Object.values(this.value)}entries(){return Object.entries(this.value)}has(t){return t in this.value}get size(){return Object.keys(this.value).length}forEach(t){Object.entries(this.value).forEach((([e,n])=>{t(n,e,this.value)}))}map(t){const e={};return Object.entries(this.value).forEach((([n,r])=>{e[n]=t(r,n,this.value)})),e}clone(){return JSON.parse(JSON.stringify(this.value))}toJSON(){return JSON.parse(JSON.stringify(this.value))}toObject(){return this.get()}lock(){return this.#t=!0,this}unlock(){return this.#t=!1,this}get isLocked(){return this.#t}freeze(){return Object.freeze(this.value),this}unfreeze(){return this.value=JSON.parse(JSON.stringify(this.value)),this}get isFrozen(){return Object.isFrozen(this.value)}}const kt={...r,...o,...yt,...vt,...bt,...Object.freeze({__proto__:null,RumiousArrayState:wt,RumiousObjectState:Et,RumiousState:pt,createArrayState:function(t){return new wt(t)},createObjectState:function(t){return new Et(t)},createState:function(t){return new pt(t)},unwatch:function(t,e){t.reactor.removeBinding(e)},watch:function(t,e){t.reactor.addBinding(e)}})};window.Rumious=kt}();
|
@@ -0,0 +1,23 @@
|
|
1
|
+
export declare class RumiousChildrenRef {
|
2
|
+
target: HTMLElement;
|
3
|
+
constructor(target: HTMLElement);
|
4
|
+
list(): HTMLElement[];
|
5
|
+
getChild(index: number): HTMLElement | undefined;
|
6
|
+
remove(index: number): void;
|
7
|
+
add(child: HTMLElement): void;
|
8
|
+
querySelector(query: string): HTMLElement | null;
|
9
|
+
querySelectorAll(query: string): NodeListOf<HTMLElement>;
|
10
|
+
clear(): void;
|
11
|
+
replaceChild(index: number, newChild: HTMLElement): void;
|
12
|
+
insertBefore(newChild: HTMLElement, index: number): void;
|
13
|
+
prepend(child: HTMLElement): void;
|
14
|
+
getFirstChild(): HTMLElement | undefined;
|
15
|
+
getLastChild(): HTMLElement | undefined;
|
16
|
+
hasChildren(): boolean;
|
17
|
+
count(): number;
|
18
|
+
find(predicate: (child: HTMLElement, index: number) => boolean): HTMLElement | undefined;
|
19
|
+
forEach(callback: (child: HTMLElement, index: number) => void): void;
|
20
|
+
removeAllMatching(query: string): void;
|
21
|
+
toggleClass(className: string): void;
|
22
|
+
setAttribute(key: string, value: string): void;
|
23
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
export declare class RumiousElementRef {
|
2
|
+
target: HTMLElement;
|
3
|
+
constructor(target: HTMLElement);
|
4
|
+
getElement(): HTMLElement;
|
5
|
+
remove(): void;
|
6
|
+
addChild(child: Node): void;
|
7
|
+
listChild(): NodeList;
|
8
|
+
querySelector(query: string): Node | null;
|
9
|
+
querySelectorAll(query: string): NodeList;
|
10
|
+
set text(t: string);
|
11
|
+
get text(): string | null;
|
12
|
+
set value(v: string);
|
13
|
+
get value(): string | undefined;
|
14
|
+
addClassName(className: string): void;
|
15
|
+
removeClassName(className: string): void;
|
16
|
+
hasClassName(className: string): boolean;
|
17
|
+
toggleClass(className: string, force?: boolean): boolean;
|
18
|
+
setStyle(styles: Partial<CSSStyleDeclaration>): void;
|
19
|
+
getStyle(property: string): string;
|
20
|
+
setAttribute(key: string, value: string): void;
|
21
|
+
getAttribute(key: string): string | null;
|
22
|
+
removeAttribute(key: string): void;
|
23
|
+
on(event: string, callback: EventListener, options?: AddEventListenerOptions): void;
|
24
|
+
off(event: string, callback: EventListener, options?: EventListenerOptions): void;
|
25
|
+
set html(t: string);
|
26
|
+
get html(): string | null;
|
27
|
+
getBoundingRect(): DOMRect;
|
28
|
+
isInViewport(): boolean;
|
29
|
+
prependChild(child: Node): void;
|
30
|
+
setDisabled(disabled: boolean): void;
|
31
|
+
addClasses(...classNames: string[]): void;
|
32
|
+
removeClasses(...classNames: string[]): void;
|
33
|
+
replaceClass(oldClass: string, newClass: string): void;
|
34
|
+
moveTo(newParent: HTMLElement): void;
|
35
|
+
getParent(): HTMLElement | null;
|
36
|
+
getNextSibling(): HTMLElement | null;
|
37
|
+
getPreviousSibling(): HTMLElement | null;
|
38
|
+
hide(): void;
|
39
|
+
show(): void;
|
40
|
+
isHidden(): boolean;
|
41
|
+
scrollIntoView(options?: ScrollIntoViewOptions): void;
|
42
|
+
matches(selector: string): boolean;
|
43
|
+
getChildren(): HTMLElement[];
|
44
|
+
insertAfter(newNode: Node): void;
|
45
|
+
insertBefore(newNode: Node): void;
|
46
|
+
clearChildren(): void;
|
47
|
+
animate(keyframes: Keyframe[], options: KeyframeAnimationOptions | number): Animation;
|
48
|
+
}
|
49
|
+
export declare function createElementRef(): RumiousElementRef;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { RumiousRenderTemplate } from "./template.js";
|
2
|
+
import { RumiousArrayState } from "../state/array.js";
|
3
|
+
import { RumiousRenderContext } from "./context.js";
|
4
|
+
import { RumiousStateCommit } from "../state/reactor.js";
|
5
|
+
type RumiousDynamicArrayRenderFn<T> = (item: any, index: any) => RumiousRenderTemplate;
|
6
|
+
export declare class RumiousDynamicArrayRenderer<T> {
|
7
|
+
state: RumiousArrayState<T>;
|
8
|
+
callback: RumiousDynamicArrayRenderFn<T>;
|
9
|
+
anchorElement: HTMLElement;
|
10
|
+
context: RumiousRenderContext;
|
11
|
+
private domMap;
|
12
|
+
private keyFn;
|
13
|
+
constructor(state: RumiousArrayState<T>, callback: RumiousDynamicArrayRenderFn<T>, keyFn?: (item: any, index: any) => any);
|
14
|
+
prepare(anchor: HTMLElement, context: RumiousRenderContext): void;
|
15
|
+
render(): Promise<void>;
|
16
|
+
onStateChange(commit: RumiousStateCommit<typeof this.state.value>): Promise<void>;
|
17
|
+
private reconcile;
|
18
|
+
}
|
19
|
+
export declare function renderDynamicArray<T>(state: RumiousArrayState<T>, callback: RumiousDynamicArrayRenderFn<T>): RumiousDynamicArrayRenderer<T>;
|
20
|
+
export {};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { RumiousRenderable } from '../types/render.js';
|
2
|
+
import type { RumiousApp } from '../app/app.js';
|
3
|
+
import type { RumiousRenderTemplate } from "./template.js";
|
4
|
+
export declare class RumiousRenderContext {
|
5
|
+
target: RumiousRenderable;
|
6
|
+
app?: RumiousApp;
|
7
|
+
renderHelper: (context: RumiousRenderContext, template: RumiousRenderTemplate, target: HTMLElement | HTMLDocument | DocumentFragment) => void;
|
8
|
+
onRenderFinished: Array<Function>;
|
9
|
+
constructor(target: RumiousRenderable, app?: RumiousApp);
|
10
|
+
findName(name: string): unknown;
|
11
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const directives: Record<string, Function>;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
type RumiousDymanicInjectorContentTypes = HTMLElement | string;
|
2
|
+
export declare class RumiousDymanicInjector<T extends RumiousDymanicInjectorContentTypes> {
|
3
|
+
contents?: T[] | undefined;
|
4
|
+
private targets;
|
5
|
+
private type;
|
6
|
+
constructor(contents?: T[] | undefined);
|
7
|
+
addTarget(element: HTMLElement): void;
|
8
|
+
inject(element: HTMLElement): void;
|
9
|
+
injectAll(): void;
|
10
|
+
removeTarget(element: HTMLElement): void;
|
11
|
+
clear(): void;
|
12
|
+
}
|
13
|
+
export declare function createHTMLInjector(html: string): RumiousDymanicInjector<string>;
|
14
|
+
export {};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { RumiousState } from "./state.js";
|
2
|
+
import { RumiousReactor } from "./reactor.js";
|
3
|
+
export declare class RumiousArrayState<T> extends RumiousState<T[]> {
|
4
|
+
constructor(value: T[], reactor?: RumiousReactor<T[]>);
|
5
|
+
set(value: T[]): void;
|
6
|
+
set(index: number, value: T): void;
|
7
|
+
get(index: number): T;
|
8
|
+
get(): T[];
|
9
|
+
insert(index: number, newItem: T): this;
|
10
|
+
remove(index: number): this;
|
11
|
+
append(value: T): this;
|
12
|
+
clear(): this;
|
13
|
+
replace(index: number, newItem: T): this;
|
14
|
+
filter(callback: (item: T, index: number, array: T[]) => boolean): this;
|
15
|
+
map(callback: (item: T, index: number, array: T[]) => T): this;
|
16
|
+
sort(compareFn?: (a: T, b: T) => number): this;
|
17
|
+
reverse(): this;
|
18
|
+
get length(): number;
|
19
|
+
forEach(callback: (value: T, index: number) => void): void;
|
20
|
+
}
|
21
|
+
export declare function createArrayState<T>(value: T[]): RumiousArrayState<T>;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { RumiousState } from "./state.js";
|
2
|
+
import { RumiousReactor } from "./reactor.js";
|
3
|
+
export declare class RumiousObjectState<T extends Record<string, any>> extends RumiousState<T> {
|
4
|
+
#private;
|
5
|
+
constructor(value: T, reactor?: RumiousReactor<T>);
|
6
|
+
set<K extends string>(key: K, newValue: any): this;
|
7
|
+
set(newObject: T): void;
|
8
|
+
remove<K extends string>(key: K): this;
|
9
|
+
merge(partial: Partial<T>): this;
|
10
|
+
assign(obj: Partial<T>): this;
|
11
|
+
clear(): this;
|
12
|
+
get<K extends string>(key: K): any;
|
13
|
+
get(): T;
|
14
|
+
keys(): string[];
|
15
|
+
values(): any[];
|
16
|
+
entries(): [string, any][];
|
17
|
+
has(key: string): boolean;
|
18
|
+
get size(): number;
|
19
|
+
forEach(callback: (value: any, key: string, obj: T) => void): void;
|
20
|
+
map(callback: (value: any, key: string, obj: T) => any): Record<string, any>;
|
21
|
+
clone(): T;
|
22
|
+
toJSON(): Record<string, any>;
|
23
|
+
toObject(): T;
|
24
|
+
lock(): this;
|
25
|
+
unlock(): this;
|
26
|
+
get isLocked(): boolean;
|
27
|
+
freeze(): this;
|
28
|
+
unfreeze(): this;
|
29
|
+
get isFrozen(): boolean;
|
30
|
+
}
|
31
|
+
export declare function createObjectState<T extends Record<string, any>>(value: T): RumiousObjectState<T>;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import type { RumiousState } from './state.js';
|
2
|
+
type RumiousStateCommitTypes = "SET" | "GET" | "SET_BY_KEY" | "REMOVE_BY_KEY" | "APPEND" | "INSERT_BY_KEY";
|
3
|
+
export interface RumiousStateCommit<T> {
|
4
|
+
type: RumiousStateCommitTypes;
|
5
|
+
target: RumiousState<T>;
|
6
|
+
value: T;
|
7
|
+
key?: string | number;
|
8
|
+
item?: T extends Array<infer A> ? A : T extends object ? keyof T : unknown;
|
9
|
+
}
|
10
|
+
export type RumiousBinding<T> = (commit: RumiousStateCommit<T>) => void;
|
11
|
+
export declare class RumiousReactor<T> {
|
12
|
+
target: RumiousState<T>;
|
13
|
+
private bindings;
|
14
|
+
constructor(target: RumiousState<T>);
|
15
|
+
addBinding(bind: RumiousBinding<T>): void;
|
16
|
+
removeBinding(bind: RumiousBinding<T>): void;
|
17
|
+
emit(commit: RumiousStateCommit<T>): Promise<void>;
|
18
|
+
}
|
19
|
+
export {};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { RumiousReactor, RumiousBinding } from './reactor.js';
|
2
|
+
type RumiousStateProduceCallback<T> = (draft: T) => void;
|
3
|
+
export declare class RumiousState<T> {
|
4
|
+
value: T;
|
5
|
+
reactor: RumiousReactor<T>;
|
6
|
+
constructor(value: T, reactor?: RumiousReactor<T>);
|
7
|
+
set(value: T): void;
|
8
|
+
get(): T;
|
9
|
+
increase(count?: number): void;
|
10
|
+
produce(callback: RumiousStateProduceCallback<T>): void;
|
11
|
+
}
|
12
|
+
export declare function watch<T>(state: RumiousState<T>, fn: RumiousBinding<T>): void;
|
13
|
+
export declare function unwatch<T>(state: RumiousState<T>, fn: RumiousBinding<T>): void;
|
14
|
+
export declare function createState<T>(value: T): RumiousState<T>;
|
15
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import type { RumiousApp } from '../app/index.js';
|
2
|
+
import type { RumiousComponent } from '../component/component.js';
|
3
|
+
export type RumiousRenderMode = "idle" | "async" | "linear" | "animate";
|
4
|
+
export type RumiousRenderable = RumiousComponent | RumiousApp;
|
5
|
+
export type RumiousTemplateGenerator = (root: HTMLElement | HTMLDocument | DocumentFragment, context: Record<any, any>) => HTMLElement | DocumentFragment | HTMLDocument | Node;
|
@@ -0,0 +1 @@
|
|
1
|
+
export type Constructor<T> = new (...args: any[]) => T;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function isPrimitive(value: any): boolean;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function extractName(str: string): string;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function observeUnmount(targetNode: Node, onRemoved: () => void): () => void;
|
package/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./dist/index.js";
|
package/index.js
CHANGED
package/package.json
CHANGED
@@ -1,33 +1,46 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
2
|
+
"name": "rumious",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "Simple framework for building UI ",
|
5
|
+
"main": "./index.js",
|
6
|
+
"types": "./index.d.ts",
|
7
|
+
"keywords": [
|
8
|
+
"rumious",
|
9
|
+
"core",
|
10
|
+
"framework",
|
11
|
+
"typescript",
|
12
|
+
"webcomponents",
|
13
|
+
"ui"
|
14
|
+
],
|
15
|
+
"scripts": {
|
16
|
+
"dec": "tsc --declaration --allowJs --emitDeclarationOnly",
|
17
|
+
"type": "tsc --noEmit",
|
18
|
+
"build": "rollup -c --environment MINIFY:true",
|
19
|
+
"build:dev": "rollup -c ",
|
20
|
+
"start": "node dist/index.js",
|
21
|
+
"test": "echo \"No tests yet\"",
|
22
|
+
"prepublish":"npm run dec && npm run build"
|
23
|
+
},
|
24
|
+
"author": "smtdfc",
|
25
|
+
"license": "MIT",
|
26
|
+
"repository": {
|
27
|
+
"type": "git",
|
28
|
+
"url": "https://github.com/smtdfc/rumious"
|
29
|
+
},
|
30
|
+
"bugs": {
|
31
|
+
"url": "https://github.com/smtdfc/rumious/issues"
|
32
|
+
},
|
33
|
+
"homepage": "https://github.com/smtdfc/rumious#readme",
|
34
|
+
"files": [
|
35
|
+
"dist/**",
|
36
|
+
"README.md",
|
37
|
+
"index.js",
|
38
|
+
"index.d.ts"
|
39
|
+
],
|
40
|
+
"engines": {
|
41
|
+
"node": ">=16"
|
42
|
+
},
|
43
|
+
"dependencies": {
|
44
|
+
"mutative": "^1.1.0"
|
45
|
+
}
|
33
46
|
}
|
package/dist/index.cjs.min.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
"use strict";class e{constructor(e){this.target=e,this.app=e.app,this.cleans=[],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.renderContext.cleans.forEach((e=>e())),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(){console.warn("Directive haven't handler !")}}class a extends o{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return console.warn(`Missing event handler for event: ${this.name}`),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,this._id=Date.now()}setTarget(e,t,n){this.target={element:e,context:n,renderer:t}}clean(){this.target&&delete this.state.reactor.priorityBinding[this._id]}sync(){this.target&&(this.renderAll(),this.state.reactor.priorityBinding[this._id]=this.onChange.bind(this))}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 n.cleans.push((()=>{e.clean()})),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,this.priorityBinding={}}react(e){Object.keys(this.priorityBinding).forEach((t=>this.priorityBinding[t]?.(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,D={mutable:"mutable",immutable:"immutable"},P={};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,D))===D.immutable||"function"==typeof n)}function B(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 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=$(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 W(e,t,n){2===H(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,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=>{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(H(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=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 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=B(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,D))===D.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=P.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,D))===D.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=P.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,D),o===D.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=H(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||console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance."),r&&console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value."))}function Oe(e){var t;const n=U(e);if(!F(e,null==n?void 0:n.options))return e;const r=H(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)}P.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,D))!==D.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 De{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){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=De,exports.RumiousContext=Pe,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 De(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 Pe(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)};
|
package/dist/index.esm.min.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
class e{constructor(e){this.target=e,this.app=e.app,this.cleans=[],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.renderContext.cleans.forEach((e=>e())),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(){console.warn("Directive haven't handler !")}}class a extends o{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return console.warn(`Missing event handler for event: ${this.name}`),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,this._id=Date.now()}setTarget(e,t,n){this.target={element:e,context:n,renderer:t}}clean(){this.target&&delete this.state.reactor.priorityBinding[this._id]}sync(){this.target&&(this.renderAll(),this.state.reactor.priorityBinding[this._id]=this.onChange.bind(this))}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 n.cleans.push((()=>{e.clean()})),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,this.priorityBinding={}}react(e){Object.keys(this.priorityBinding).forEach((t=>this.priorityBinding[t]?.(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",D="add",z=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),_=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),L=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 $(e){return!!H(e)}function H(e){return"object"!=typeof e?null:null==e?void 0:e[z]}function W(e){var t;const n=H(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=H(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=H(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 $(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)||$(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($(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($(o)){const t=H(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=H(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:D: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===D?{op:A,path:h}:u===A?{op:D,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:D,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:D,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:D,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(H(this)).size},has(e){return B(H(this)).has(e)},set(e,t){const n=H(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=H(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=H(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(H(this)).forEach(((n,r)=>{e.call(t,this.get(r),r,this)}))},get(e){var t,n;const r=H(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(H(this)).keys()},values(){const e=this.keys();return{[L]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[L]:()=>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]}}}},[L](){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=H(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 H(this).setMap.size},has(e){const t=H(this);if(t.setMap.has(e))return!0;ie(t);const n=H(e);return!(!n||!t.setMap.has(n.original))},add(e){const t=H(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=H(this);ie(t),ae(t);const n=H(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=H(this);ie(e),ae(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=H(this);ie(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:we(e,t,{isValuesIterator:!0})}},entries(){const e=H(this);ie(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:we(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[L](){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===z)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=H(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=H(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=H(l);let a=3===e.type?e.setMap:e.copy;const c=Y(a,r),u=H(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=H(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=H(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=H(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||console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance."),r&&console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value."))}function Re(e){var t;const n=H(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(!$(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=$(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(H(y)),e}const m=e=>{const t=H(y);if(!$(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[_];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=H(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(H(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 De(e){return new Pe(e)}function ze(e){return e instanceof Pe}class _e 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 Le(e=[]){return new _e(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 $e(e){return new Be(e)}class He{constructor(e){this.target=e}set(e){this.target=e.forwardRefs}}function We(e){return new He(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,He as RumiousComponentRef,Xe as RumiousContext,E as RumiousDymanicInjector,qe as RumiousElementRef,Ye as RumiousLazyLoader,T as RumiousReactor,C as RumiousReducer,Pe as RumiousState,Le as createArrayState,$e 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,De as createState,y as createTextElement,et as denounce,O as injectHTML,k as injectText,n as isComponent,ze 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};
|