rumious 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/app.d.ts +1 -2
- package/dist/app/index.d.ts +2 -2
- package/dist/component/component.d.ts +1 -1
- package/dist/component/element.d.ts +2 -2
- package/dist/component/index.d.ts +2 -2
- package/dist/context/context.d.ts +12 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +14 -15
- package/dist/index.esm.js +1 -1
- package/dist/index.global.d.ts +41 -0
- package/dist/index.min.js +1 -1
- package/dist/jsx/index.d.ts +2 -2
- package/dist/performance/index.d.ts +5 -0
- package/dist/render/array.d.ts +8 -8
- package/dist/render/context.d.ts +1 -1
- package/dist/render/dynamic.d.ts +2 -2
- package/dist/render/index.d.ts +3 -3
- package/dist/render/render.d.ts +2 -2
- package/dist/render/template.d.ts +1 -1
- package/dist/state/array.d.ts +2 -2
- package/dist/state/index.d.ts +3 -3
- package/dist/state/object.d.ts +2 -2
- package/dist/state/reactor.d.ts +1 -1
- package/dist/types/jsx.d.ts +8 -0
- package/dist/types/render.d.ts +1 -1
- package/dist/utils/name.d.ts +1 -0
- package/package.json +16 -5
- package/index.d.ts +0 -1
- package/index.js +0 -1
package/dist/app/app.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { RumiousModule, RumiousModuleInstance } from './module.js';
|
2
|
-
interface RumiousAppOptions {
|
2
|
+
export interface RumiousAppOptions {
|
3
3
|
}
|
4
4
|
export declare class RumiousApp {
|
5
5
|
private root;
|
@@ -11,4 +11,3 @@ export declare class RumiousApp {
|
|
11
11
|
render(template: JSX.Element): void;
|
12
12
|
}
|
13
13
|
export declare function createApp(root: HTMLElement, options?: RumiousAppOptions): RumiousApp;
|
14
|
-
export {};
|
package/dist/app/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
1
|
+
export * from './app.js';
|
2
|
+
export * from './module.js';
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { RumiousApp } from '../app/app.js';
|
2
2
|
import { RumiousRenderContext } from '../render/context.js';
|
3
3
|
import { RumiousRenderTemplate } from '../render/template.js';
|
4
|
-
import { RumiousRenderMode } from
|
4
|
+
import { RumiousRenderMode } from '../types/render.js';
|
5
5
|
export interface RumiousEmptyProps {
|
6
6
|
}
|
7
7
|
interface RumiousComponentRenderOptions {
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import type { RumiousComponent } from
|
2
|
-
import { RumiousRenderContext } from
|
1
|
+
import type { RumiousComponent } from './component.js';
|
2
|
+
import { RumiousRenderContext } from '../render/context.js';
|
3
3
|
import { Constructor } from '../types/utils.js';
|
4
4
|
export type RumiousComponentConstructor = Constructor<RumiousComponent> & {
|
5
5
|
classNames?: string;
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
1
|
+
export * from './component.js';
|
2
|
+
export * from './element.js';
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export declare class RumiousContext<T extends object> {
|
2
|
+
events: Record<string, Function[]>;
|
3
|
+
values: Partial<T>;
|
4
|
+
constructor(initialValues?: Partial<T>);
|
5
|
+
has<K extends keyof T>(key: K): boolean;
|
6
|
+
set<K extends keyof T>(key: K, value: T[K]): void;
|
7
|
+
get<K extends keyof T>(key: K): T[K] | undefined;
|
8
|
+
on(event: string, callback: Function): void;
|
9
|
+
off(event: string, callback: Function): void;
|
10
|
+
emit(event: string, payload: any): void;
|
11
|
+
}
|
12
|
+
export declare function createContext<T extends object>(values: T, name?: string): RumiousContext<T>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './context.js';
|
package/dist/index.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
var t=require("mutative");class e{constructor(t,e){this.target=t,this.app=e,this.onRenderFinished=[]}findName(t){return this.target[t]}}function r(t,e,s){let i=e.generator.bind(t.target);t.renderHelper=r,i(s,t),setTimeout((async()=>{const e=[...t.onRenderFinished];t.onRenderFinished=[];for(const t of e)await t()}),0)}class s 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(t,r={}){this.root=t,this.options=r,this.modules=[],this.context=new e(this,this)}addModule(t,e){let r=t.init(this,e);return this.modules.push(r),r}render(t){r(this.context,t,this.root)}}class n{constructor(t){this.generator=t}}class o{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 a{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,r){this.target.addEventListener(t,e,r)}off(t,e,r){this.target.removeEventListener(t,e,r)}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 h(t){const e=t.indexOf("$");return-1!==e?t.slice(e+1):""}class c{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 r=e(t);return r instanceof Promise?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}})))}}class l{constructor(t,e){this.value=t,this.reactor=e??new c(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(e){const[r,s]=t.create(this.value);e(r),this.set(s())}}const u={on:function(t,e,r,s){"string"==typeof s&&(s=t.findName(h(s))),e.addEventListener(r,s)},ref:function(t,e,r,s){if("string"==typeof s&&(s=t.findName(h(s))),!(s instanceof a))throw Error("Rumious: ref directive required RumiousElementRef !");s.target=e},inject:function(t,e,r,s){if("string"==typeof s&&(s=t.findName(h(s))),!(s instanceof o))throw Error("Rumious: inject directive required RumiousInjector !");s.addTarget(e),s.inject(e)},bind:function(t,e,r,s){if("string"==typeof s&&(s=t.findName(h(s))),!(s instanceof l))throw Error("Rumious: bind directive required RumiousState !");e.setAttribute(r,s.value),s.reactor.addBinding((({})=>{e.setAttribute(r,s.value)}))},model:function(t,e,r,s){if("string"==typeof s&&(s=t.findName(h(s))),!(s instanceof l&&(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":s.set(e.checked);break;case"radio":e.checked&&s.set(e.value);break;default:s.set(e.value)}else(e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&s.set(e.value)}))}}};class d{domMap=new Map;constructor(t,e,r){this.state=t,this.callback=e,this.keyFn=r??((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 r=await this.callback(t.item,t.key),s=document.createDocumentFragment();this.context.renderHelper(this.context,r,s),this.anchorElement.appendChild(s),this.domMap.set(e,s)}}else if("SET_BY_KEY"===t.type){const e=this.keyFn(t.item,t.key),r=this.anchorElement.childNodes[t.key];if(r){const s=await this.callback(t.item,t.key),i=document.createDocumentFragment();this.context.renderHelper(this.context,s,i),this.anchorElement.replaceChild(i,r),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 r=await this.callback(t.item,t.key),s=document.createDocumentFragment();this.context.renderHelper(this.context,r,s);const i=this.anchorElement.childNodes[t.key]??null;this.anchorElement.insertBefore(s,i),this.domMap.set(e,s)}}else await this.reconcile(this.state.value)}async reconcile(t){const e=this.domMap,r=new Map,s=[];for(let i=0;i<t.length;i++){const n=t[i],o=this.keyFn(n,i);let a=e.get(o);if(!a){const t=await this.callback(n,i),e=document.createDocumentFragment();this.context.renderHelper(this.context,t,e),a=e}r.set(o,a),s.push(a)}this.anchorElement.textContent="";for(const t of s)this.anchorElement.appendChild(t);this.domMap=r}}async function m(t,e,r,s){if(e.parentNode)if(function(t){return t!==Object(t)}(r))e.textContent=String(r);else if(r&&r instanceof l){function i({}){document.contains(e)?e.textContent=r.value:r.reactor.removeBinding(i)}e.textContent=r.value,r.reactor.addBinding(i)}else if(Array.isArray(r))e.textContent=r.map(String).join("");else if(r instanceof d)r.prepare(e.parentElement,s),r.render();else if(r instanceof HTMLElement)e.replaceWith(r);else if(r instanceof n){let o=document.createDocumentFragment();s.renderHelper?.(s,r,o),e.replaceWith(o)}else if(r instanceof NodeList||r instanceof HTMLCollection){if(0===r.length)return void e.remove();const a=document.createDocumentFragment();for(const h of Array.from(r))a.appendChild(h.cloneNode(!0));e.replaceWith(a),e.remove()}else if(r&&"function"==typeof r.toString)try{e.textContent=r.toString()}catch{e.textContent=""}else e.textContent=""}function p(t){return new n(t)}window.RUMIOUS_JSX={template:p,createElement:function(...t){throw console.log(t),Error("Rumious doesn't use createElement !")},addDirective:function(t,e,r,s="",i){let n=u[r];if(!n)throw Error("Rumious: Cannot solve directive !");n(e,t,s,i)},dynamicValue:function(t,e,r,s){m(0,e,r,s)},createComponent:function(t){let e=t.tagName;return window.customElements.get(e)||window.customElements.define(e,class extends s{static tag=e}),document.createElement(e)}};class g extends l{constructor(t,e){super(t,e)}set(t,e){if("number"==typeof t&&void 0!==e){const r=t,s=e;this.value[r]=s,this.reactor.emit({type:"SET_BY_KEY",value:[...this.value],target:this,key:r,item:s})}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 f extends l{#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 r=t,s=e;return this.value[r]=s,this.reactor.emit({type:"SET_BY_KEY",value:{...this.value},target:this,key:r,item:s}),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,r])=>{t(r,e,this.value)}))}map(t){const e={};return Object.entries(this.value).forEach((([r,s])=>{e[r]=t(s,r,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)}}window.RUMIOUS_CONTEXTS={};class v{constructor(t={}){this.events={},this.values=t}has(t){return t in this.values}set(t,e){this.values[t]=e}get(t){return this.values[t]}on(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}off(t,e){this.events[t]&&(this.events[t]=this.events[t].filter((t=>t!==e)))}emit(t,e){this.events[t]&&this.events[t].forEach((t=>t(e)))}}exports.RumiousApp=i,exports.RumiousArrayState=g,exports.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 r=this.getChild(t);r&&this.target.replaceChild(e,r)}insertBefore(t,e){const r=this.getChild(e);r?this.target.insertBefore(t,r):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((r=>r.setAttribute(t,e)))}},exports.RumiousComponent=class{static classNames="";static tagName="rumious-component";constructor(){this.renderOptions={mode:"idle"}}onCreate(){}onRender(){}onDestroy(){}async onBeforeRender(){}prepare(t,r){this.props=r,this.context=new e(this,t.app)}async requestRender(){await this.onBeforeRender();let t=this.template();r(this.context,t,this.element),this.onRender()}requestCleanup(){}},exports.RumiousComponentElement=s,exports.RumiousContext=v,exports.RumiousDymanicInjector=o,exports.RumiousElementRef=a,exports.RumiousObjectState=f,exports.RumiousRenderTemplate=n,exports.RumiousState=l,exports.createApp=function(t,e){return new i(t,e)},exports.createArrayState=function(t){return new g(t)},exports.createContext=function(t,e=function(t="_"){return`${t}${(Math.floor(9999*Math.random())*Date.now()).toString(32)}`}("rctx_")){if(window.RUMIOUS_CONTEXTS[e])return window.RUMIOUS_CONTEXTS[e];{let r=new v(t);return window.RUMIOUS_CONTEXTS[e]=r,r}},exports.createElementRef=function(){return new a(document.createElement("span"))},exports.createHTMLInjector=function(t){return new o([t])},exports.createObjectState=function(t){return new f(t)},exports.createState=function(t){return new l(t)},exports.denounce=function(t,e){let r;return function(...s){clearTimeout(r),r=setTimeout((()=>t.apply(this,s)),e)}},exports.leadingTrailingDebounce=function(t,e){let r,s=!0;return function(...i){s&&(t.apply(this,i),s=!1),clearTimeout(r),r=setTimeout((()=>{t.apply(this,i),s=!0}),e)}},exports.rafThrottle=function(t){let e=!1;return function(...r){e||(e=!0,requestAnimationFrame((()=>{t.apply(this,r),e=!1})))}},exports.renderDynamicArray=function(t,e){return new d(t,e)},exports.template=p,exports.tholle=function(t,e){let r=0;return function(...s){const i=Date.now();i-r>=e&&(r=i,t.apply(this,s))}},exports.trailingThrottle=function(t,e){let r=0,s=null,i=null;function n(){r=Date.now(),t.apply(this,s),s=null}return function(...t){const o=Date.now();s=t,o-r>=e?n.call(this):i||(i=setTimeout((()=>{i=null,n.call(this)}),e-(o-r)))}},exports.unwatch=function(t,e){t.reactor.removeBinding(e)},exports.watch=function(t,e){t.reactor.addBinding(e)};
|
package/dist/index.d.ts
CHANGED
@@ -1,31 +1,30 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
createElement(...args: any[]): RumiousRenderTemplate;
|
5
|
-
addDirective(...args: any[]): void;
|
6
|
-
dynamicValue(...args: any[]): void;
|
7
|
-
createComponent(...args: any[]): HTMLElement;
|
8
|
-
}
|
1
|
+
import { RumiousJSXFactory } from './types/jsx.js';
|
2
|
+
import type { RumiousContext } from './context/context.js';
|
3
|
+
import type { RumiousRenderTemplate } from './render/template.js';
|
9
4
|
declare global {
|
10
5
|
interface Window {
|
11
6
|
RUMIOUS_JSX: RumiousJSXFactory;
|
7
|
+
RUMIOUS_CONTEXTS: Record<string, RumiousContext<any>>;
|
12
8
|
}
|
13
9
|
namespace JSX {
|
10
|
+
type Element = RumiousRenderTemplate;
|
14
11
|
interface ElementClass {
|
15
12
|
template: () => RumiousRenderTemplate;
|
16
13
|
}
|
17
14
|
interface ElementAttributesProperty {
|
18
15
|
props: {};
|
19
16
|
}
|
20
|
-
type Element = RumiousRenderTemplate;
|
21
17
|
interface IntrinsicElements {
|
22
18
|
[elemName: string]: any;
|
23
19
|
}
|
20
|
+
type Fragment = 'RUMIOUS_INTERNAL_FRAGMENT';
|
24
21
|
}
|
25
22
|
}
|
26
|
-
export * from
|
27
|
-
export * from
|
28
|
-
export * from
|
29
|
-
export * from
|
30
|
-
export * from
|
31
|
-
export * from
|
23
|
+
export * from './component/index.js';
|
24
|
+
export * from './app/index.js';
|
25
|
+
export * from './jsx/index.js';
|
26
|
+
export * from './render/index.js';
|
27
|
+
export * from './ref/index.js';
|
28
|
+
export * from './state/index.js';
|
29
|
+
export * from './context/index.js';
|
30
|
+
export * from './performance/index.js';
|
package/dist/index.esm.js
CHANGED
@@ -1 +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};
|
1
|
+
import{create as t}from"mutative";class e{constructor(t,e){this.target=t,this.app=e,this.onRenderFinished=[]}findName(t){return this.target[t]}}function i(t,e,s){let n=e.generator.bind(t.target);t.renderHelper=i,n(s,t),setTimeout((async()=>{const e=[...t.onRenderFinished];t.onRenderFinished=[];for(const t of e)await t()}),0)}class s{static classNames="";static tagName="rumious-component";constructor(){this.renderOptions={mode:"idle"}}onCreate(){}onRender(){}onDestroy(){}async onBeforeRender(){}prepare(t,i){this.props=i,this.context=new e(this,t.app)}async requestRender(){await this.onBeforeRender();let t=this.template();i(this.context,t,this.element),this.onRender()}requestCleanup(){}}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()}}class r{constructor(t,i={}){this.root=t,this.options=i,this.modules=[],this.context=new e(this,this)}addModule(t,e){let i=t.init(this,e);return this.modules.push(i),i}render(t){i(this.context,t,this.root)}}function a(t,e){return new r(t,e)}class o{constructor(t){this.generator=t}}class h{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 c(t){return new h([t])}class l{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,i){this.target.addEventListener(t,e,i)}off(t,e,i){this.target.removeEventListener(t,e,i)}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 l(document.createElement("span"))}function d(t){const e=t.indexOf("$");return-1!==e?t.slice(e+1):""}class m{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 i=e(t);return i instanceof Promise?i:Promise.resolve(i)}catch(t){return Promise.reject(t)}})))}}class g{constructor(t,e){this.value=t,this.reactor=e??new m(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(e){const[i,s]=t(this.value);e(i),this.set(s())}}function f(t,e){t.reactor.addBinding(e)}function p(t,e){t.reactor.removeBinding(e)}function v(t){return new g(t)}const y={on:function(t,e,i,s){"string"==typeof s&&(s=t.findName(d(s))),e.addEventListener(i,s)},ref:function(t,e,i,s){if("string"==typeof s&&(s=t.findName(d(s))),!(s instanceof l))throw Error("Rumious: ref directive required RumiousElementRef !");s.target=e},inject:function(t,e,i,s){if("string"==typeof s&&(s=t.findName(d(s))),!(s instanceof h))throw Error("Rumious: inject directive required RumiousInjector !");s.addTarget(e),s.inject(e)},bind:function(t,e,i,s){if("string"==typeof s&&(s=t.findName(d(s))),!(s instanceof g))throw Error("Rumious: bind directive required RumiousState !");e.setAttribute(i,s.value),s.reactor.addBinding((({})=>{e.setAttribute(i,s.value)}))},model:function(t,e,i,s){if("string"==typeof s&&(s=t.findName(d(s))),!(s instanceof g&&(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":s.set(e.checked);break;case"radio":e.checked&&s.set(e.value);break;default:s.set(e.value)}else(e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&s.set(e.value)}))}}};class E{domMap=new Map;constructor(t,e,i){this.state=t,this.callback=e,this.keyFn=i??((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 i=await this.callback(t.item,t.key),s=document.createDocumentFragment();this.context.renderHelper(this.context,i,s),this.anchorElement.appendChild(s),this.domMap.set(e,s)}}else if("SET_BY_KEY"===t.type){const e=this.keyFn(t.item,t.key),i=this.anchorElement.childNodes[t.key];if(i){const s=await this.callback(t.item,t.key),n=document.createDocumentFragment();this.context.renderHelper(this.context,s,n),this.anchorElement.replaceChild(n,i),this.domMap.set(e,n)}}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 i=await this.callback(t.item,t.key),s=document.createDocumentFragment();this.context.renderHelper(this.context,i,s);const n=this.anchorElement.childNodes[t.key]??null;this.anchorElement.insertBefore(s,n),this.domMap.set(e,s)}}else await this.reconcile(this.state.value)}async reconcile(t){const e=this.domMap,i=new Map,s=[];for(let n=0;n<t.length;n++){const r=t[n],a=this.keyFn(r,n);let o=e.get(a);if(!o){const t=await this.callback(r,n),e=document.createDocumentFragment();this.context.renderHelper(this.context,t,e),o=e}i.set(a,o),s.push(o)}this.anchorElement.textContent="";for(const t of s)this.anchorElement.appendChild(t);this.domMap=i}}function w(t,e){return new E(t,e)}async function C(t,e,i,s){if(e.parentNode)if(function(t){return t!==Object(t)}(i))e.textContent=String(i);else if(i&&i instanceof g){function n({}){document.contains(e)?e.textContent=i.value:i.reactor.removeBinding(n)}e.textContent=i.value,i.reactor.addBinding(n)}else if(Array.isArray(i))e.textContent=i.map(String).join("");else if(i instanceof E)i.prepare(e.parentElement,s),i.render();else if(i instanceof HTMLElement)e.replaceWith(i);else if(i instanceof o){let r=document.createDocumentFragment();s.renderHelper?.(s,i,r),e.replaceWith(r)}else if(i instanceof NodeList||i instanceof HTMLCollection){if(0===i.length)return void e.remove();const a=document.createDocumentFragment();for(const h of Array.from(i))a.appendChild(h.cloneNode(!0));e.replaceWith(a),e.remove()}else if(i&&"function"==typeof i.toString)try{e.textContent=i.toString()}catch{e.textContent=""}else e.textContent=""}function b(t){return new o(t)}window.RUMIOUS_JSX={template:b,createElement:function(...t){throw console.log(t),Error("Rumious doesn't use createElement !")},addDirective:function(t,e,i,s="",n){let r=y[i];if(!r)throw Error("Rumious: Cannot solve directive !");r(e,t,s,n)},dynamicValue:function(t,e,i,s){C(0,e,i,s)},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)}};class S{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 i=this.getChild(t);i&&this.target.replaceChild(e,i)}insertBefore(t,e){const i=this.getChild(e);i?this.target.insertBefore(t,i):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((i=>i.setAttribute(t,e)))}}class T extends g{constructor(t,e){super(t,e)}set(t,e){if("number"==typeof t&&void 0!==e){const i=t,s=e;this.value[i]=s,this.reactor.emit({type:"SET_BY_KEY",value:[...this.value],target:this,key:i,item:s})}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 k(t){return new T(t)}class M extends g{#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 i=t,s=e;return this.value[i]=s,this.reactor.emit({type:"SET_BY_KEY",value:{...this.value},target:this,key:i,item:s}),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,i])=>{t(i,e,this.value)}))}map(t){const e={};return Object.entries(this.value).forEach((([i,s])=>{e[i]=t(s,i,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 x(t){return new M(t)}window.RUMIOUS_CONTEXTS={};class N{constructor(t={}){this.events={},this.values=t}has(t){return t in this.values}set(t,e){this.values[t]=e}get(t){return this.values[t]}on(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}off(t,e){this.events[t]&&(this.events[t]=this.events[t].filter((t=>t!==e)))}emit(t,e){this.events[t]&&this.events[t].forEach((t=>t(e)))}}function O(t,e=function(t="_"){return`${t}${(Math.floor(9999*Math.random())*Date.now()).toString(32)}`}("rctx_")){if(window.RUMIOUS_CONTEXTS[e])return window.RUMIOUS_CONTEXTS[e];{let i=new N(t);return window.RUMIOUS_CONTEXTS[e]=i,i}}function L(t,e){let i=0;return function(...s){const n=Date.now();n-i>=e&&(i=n,t.apply(this,s))}}function A(t,e){let i;return function(...s){clearTimeout(i),i=setTimeout((()=>t.apply(this,s)),e)}}function R(t,e){let i=0,s=null,n=null;function r(){i=Date.now(),t.apply(this,s),s=null}return function(...t){const a=Date.now();s=t,a-i>=e?r.call(this):n||(n=setTimeout((()=>{n=null,r.call(this)}),e-(a-i)))}}function H(t,e){let i,s=!0;return function(...n){s&&(t.apply(this,n),s=!1),clearTimeout(i),i=setTimeout((()=>{t.apply(this,n),s=!0}),e)}}function j(t){let e=!1;return function(...i){e||(e=!0,requestAnimationFrame((()=>{t.apply(this,i),e=!1})))}}export{r as RumiousApp,T as RumiousArrayState,S as RumiousChildrenRef,s as RumiousComponent,n as RumiousComponentElement,N as RumiousContext,h as RumiousDymanicInjector,l as RumiousElementRef,M as RumiousObjectState,o as RumiousRenderTemplate,g as RumiousState,a as createApp,k as createArrayState,O as createContext,u as createElementRef,c as createHTMLInjector,x as createObjectState,v as createState,A as denounce,H as leadingTrailingDebounce,j as rafThrottle,w as renderDynamicArray,b as template,L as tholle,R as trailingThrottle,p as unwatch,f as watch};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import * as Component from './component/index.js';
|
2
|
+
import * as App from './app/index.js';
|
3
|
+
import * as Render from './render/index.js';
|
4
|
+
import * as Ref from './ref/index.js';
|
5
|
+
import * as State from './state/index.js';
|
6
|
+
import * as Context from './context/index.js';
|
7
|
+
declare global {
|
8
|
+
interface Window {
|
9
|
+
Rumious: Record<string, any>;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
declare const Rumious: {
|
13
|
+
tholle<T extends (...args: any[]) => any>(func: T, limit: number): T;
|
14
|
+
denounce<T extends (...args: any[]) => any>(func: T, delay: number): T;
|
15
|
+
trailingThrottle<T extends (...args: any[]) => any>(func: T, limit: number): T;
|
16
|
+
leadingTrailingDebounce<T extends (...args: any[]) => any>(func: T, delay: number): T;
|
17
|
+
rafThrottle<T extends (...args: any[]) => any>(func: T): T;
|
18
|
+
createContext<T extends object>(values: T, name?: string): Context.RumiousContext<T>;
|
19
|
+
RumiousContext: typeof Context.RumiousContext;
|
20
|
+
watch<T>(state: State.RumiousState<T>, fn: import("./state/reactor.js").RumiousBinding<T>): void;
|
21
|
+
unwatch<T>(state: State.RumiousState<T>, fn: import("./state/reactor.js").RumiousBinding<T>): void;
|
22
|
+
createState<T>(value: T): State.RumiousState<T>;
|
23
|
+
RumiousState: typeof State.RumiousState;
|
24
|
+
createArrayState<T>(value: T[]): State.RumiousArrayState<T>;
|
25
|
+
RumiousArrayState: typeof State.RumiousArrayState;
|
26
|
+
createObjectState<T extends Record<string, any>>(value: T): State.RumiousObjectState<T>;
|
27
|
+
RumiousObjectState: typeof State.RumiousObjectState;
|
28
|
+
createElementRef(): Ref.RumiousElementRef;
|
29
|
+
RumiousElementRef: typeof Ref.RumiousElementRef;
|
30
|
+
RumiousChildrenRef: typeof Ref.RumiousChildrenRef;
|
31
|
+
renderDynamicArray: typeof Render.renderDynamicArray;
|
32
|
+
RumiousRenderTemplate: typeof Render.RumiousRenderTemplate;
|
33
|
+
createHTMLInjector(html: string): Render.RumiousDymanicInjector<string>;
|
34
|
+
RumiousDymanicInjector: typeof Render.RumiousDymanicInjector;
|
35
|
+
template(generator: import("./types/render.js").RumiousTemplateGenerator): Render.RumiousRenderTemplate;
|
36
|
+
createApp(root: HTMLElement, options?: App.RumiousAppOptions): App.RumiousApp;
|
37
|
+
RumiousApp: typeof App.RumiousApp;
|
38
|
+
RumiousComponent: typeof Component.RumiousComponent;
|
39
|
+
RumiousComponentElement: typeof Component.RumiousComponentElement;
|
40
|
+
};
|
41
|
+
export default Rumious;
|
package/dist/index.min.js
CHANGED
@@ -1 +1 @@
|
|
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}();
|
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 l{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 c(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 S(t){return Object.getPrototypeOf(t)===Map.prototype}function M(t){var e;return null!==(e=t.copy)&&void 0!==e?e:t.original}function O(t){return!!k(t)}function k(t){return"object"!=typeof t?null:null==t?void 0:t[d]}function j(t){var e;const n=k(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 R(t,e=[]){if(Object.hasOwnProperty.call(t,"key")){const n=t.parent.copy,r=k(T(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 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===A(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 A(t){return Array.isArray(t)?1:t instanceof Map?2:t instanceof Set?3:0}function T(t,e){return 2===A(t)?t.get(e):t[e]}function x(t,e,n){2===A(t)?t.set(e,n):t[e]=n}function _(t,e){const n=k(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 I(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(!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,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 L(t){t.copy||(t.copy=I(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(!S(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 O(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)||O(t))return r.pop(),void i.pop();switch(A(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=A(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(O(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(O(s)){const e=k(s);L(e);const n=(null===(a=e.assignedMap)||void 0===a?void 0:a.size)||e.operated?e.copy:e.original;x(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 U(t,e){const n=3===t.type?t.setMap:t.copy;t.finalities.revoke.length>1&&t.assignedMap.get(e)&&n&&K(T(n,e),t.finalities.handledSet,t.options)}function W(t){3===t.type&&t.copy&&(t.copy.clear(),t.setMap.forEach((e=>{t.copy.add(j(e))})))}function $(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 J(t,e,n,r){const i=k(n);i&&(i.callbacks||(i.callbacks=[]),i.callbacks.push(((o,s)=>{var a;const l=3===t.type?t.setMap:t.copy;if(P(T(l,e),n)){let n=i.original;i.copy&&(n=i.copy),W(t),$(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)),x(l,e,n)}})),t.options.enableAutoFreeze&&i.finalities!==t.finalities&&(t.options.enableAutoFreeze=!1)),C(n,t.options)&&t.finalities.draft.push((()=>{P(T(3===t.type?t.setMap:t.copy,e),n)&&U(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 l=T(t,a),c=H(T(e,a)),u=n?b(t,a)?p:f:h;if(P(l,c)&&u===p)return;const d=N(r.concat(a),s);i.push(u===h?{op:u,path:d}:{op:u,path:d,value:c}),o.push(u===f?{op:h,path:d}:u===h?{op:f,path:d,value:l}:{op:p,path:d,value:l})}))}(t,e,n,r,i);case 1:return function(t,e,n,r,i){let{original:o,assignedMap:s,options:a}=t,l=t.copy;l.length<o.length&&([o,l]=[l,o],[n,r]=[r,n]);for(let t=0;t<o.length;t+=1)if(s.get(t.toString())&&l[t]!==o[t]){const s=N(e.concat([t]),i);n.push({op:p,path:s,value:H(l[t])}),r.push({op:p,path:s,value:H(o[t])})}for(let t=o.length;t<l.length;t+=1){const r=N(e.concat([t]),i);n.push({op:f,path:r,value:H(l[t])})}if(o.length<l.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=l.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(k(this)).size},has(t){return M(k(this)).has(t)},set(t,e){const n=k(this),r=M(n);return r.has(t)&&P(r.get(t),e)||(L(n),B(n),n.assignedMap.set(t,!0),n.copy.set(t,e),J(n,t,e,X)),this},delete(t){if(!this.has(t))return!1;const e=k(this);return L(e),B(e),e.original.has(t)?e.assignedMap.set(t,!1):e.assignedMap.delete(t),e.copy.delete(t),!0},clear(){const t=k(this);if(this.size){L(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(k(this)).forEach(((n,r)=>{t.call(e,this.get(r),r,this)}))},get(t){var e,n;const r=k(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 L(r),r.copy.set(t,s),s},keys(){return M(k(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 l=k(a),c=(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,c),c||l||!C(s,t.options)||t.finalized||!t.original.has(s))l&&(a=l.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 k(this).setMap.size},has(t){const e=k(this);if(e.setMap.has(t))return!0;L(e);const n=k(t);return!(!n||!e.setMap.has(n.original))},add(t){const e=k(this);return this.has(t)||(L(e),B(e),e.assignedMap.set(t,!0),e.setMap.set(t,t),J(e,t,t,X)),this},delete(t){if(!this.has(t))return!1;const e=k(this);L(e),B(e);const n=k(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=k(this);L(t),B(t);for(const e of t.original)t.assignedMap.set(e,!1);t.setMap.clear()},values(){const t=k(this);L(t);const e=t.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:tt(t,e,{isValuesIterator:!0})}},entries(){const t=k(this);L(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 l=a[e];if(t.options.strict&&G(l,t.options),t.finalized||!C(l,t.options))return l;if(l===_(t.original,e)){if(L(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=k(t.copy[e]);return L(n),B(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 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=k(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))||(L(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,J(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?(L(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=A(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:l,revoke:c}=Proxy.revocable(1===s?Object.assign([],a):a,it);if(i.revoke.push(c),rt.add(l),a.proxy=l,n){const t=n;t.finalities.draft.push(((e,n)=>{var i,o;const s=k(l);let a=3===t.type?t.setMap:t.copy;const c=T(a,r),u=k(c);if(u){let o=u.original;u.operated&&(o=j(c)),W(u),$(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)),x(a,r,o)}null===(o=s.callbacks)||void 0===o||o.forEach((t=>{t(e,n)}))}))}else{const t=k(l);t.finalities.draft.push(((e,n)=>{W(t),$(t,X,e,n)}))}return l}function st(t,e,n,r,i){var o;const s=k(t),a=null!==(o=null==s?void 0:s.original)&&void 0!==o?o:t,l=!!e.length;if(null==s?void 0:s.operated)for(;s.finalities.draft.length>0;){s.finalities.draft.pop()(n,r)}const c=l?e[0]:s?s.operated?s.copy:s.original:t;return s&&z(s),i&&V(c,c,null==s?void 0:s.options.updatedValues),[c,n&&l?[{op:p,path:[],value:e[0]}]:n,r&&l?[{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=k(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 x(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 lt(t){var e;const n=k(t);if(!C(t,null==n?void 0:n.options))return t;const r=A(t);if(n&&!n.operated)return n.original;let i;function o(){i=2===r?S(t)?new Map(t):new(Object.getPrototypeOf(t).constructor)(t):3===r?Array.from(n.setMap.values()):I(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(T(n.original,e),r))return;const s=lt(r);s!==r&&(i===t&&o(),x(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 ct(t){if(!O(t))throw new Error(`current() is only used for Draft, parameter: ${t}`);return lt(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,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({},ht),c);const u=O(a)?ct(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!==(o=c.strict)&&void 0!==o&&o,d={enableAutoFreeze:null!==(s=c.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=l(m)}catch(t){throw z(k(m)),t}const w=t=>{const e=k(m);if(!O(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=k(t);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return v([ct(t)])}return v([t])};return b instanceof Promise?b.then(w,(t=>{throw z(k(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(c(r))),e.addEventListener(n,r)},ref:function(t,e,n,r){if("string"==typeof r&&(r=t.findName(c(r))),!(r instanceof l))throw Error("Rumious: ref directive required RumiousElementRef !");r.target=e},inject:function(t,e,n,r){if("string"==typeof r&&(r=t.findName(c(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(c(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(c(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 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 mt(t){return new s(t)}window.RUMIOUS_JSX={template:mt,createElement:function(...t){throw console.log(t),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:l,createElementRef:function(){return new l(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)}}var St=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_CONTEXTS={};class Mt{constructor(t={}){this.events={},this.values=t}has(t){return t in this.values}set(t,e){this.values[t]=e}get(t){return this.values[t]}on(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}off(t,e){this.events[t]&&(this.events[t]=this.events[t].filter((t=>t!==e)))}emit(t,e){this.events[t]&&this.events[t].forEach((t=>t(e)))}}const Ot={...r,...o,...yt,...vt,...bt,...St,...Object.freeze({__proto__:null,RumiousContext:Mt,createContext:function(t,e=function(t="_"){return`${t}${(Math.floor(9999*Math.random())*Date.now()).toString(32)}`}("rctx_")){if(window.RUMIOUS_CONTEXTS[e])return window.RUMIOUS_CONTEXTS[e];{let n=new Mt(t);return window.RUMIOUS_CONTEXTS[e]=n,n}}}),...Object.freeze({__proto__:null,denounce:function(t,e){let n;return function(...r){clearTimeout(n),n=setTimeout((()=>t.apply(this,r)),e)}},leadingTrailingDebounce:function(t,e){let n,r=!0;return function(...i){r&&(t.apply(this,i),r=!1),clearTimeout(n),n=setTimeout((()=>{t.apply(this,i),r=!0}),e)}},rafThrottle:function(t){let e=!1;return function(...n){e||(e=!0,requestAnimationFrame((()=>{t.apply(this,n),e=!1})))}},tholle:function(t,e){let n=0;return function(...r){const i=Date.now();i-n>=e&&(n=i,t.apply(this,r))}},trailingThrottle:function(t,e){let n=0,r=null,i=null;function o(){n=Date.now(),t.apply(this,r),r=null}return function(...t){const s=Date.now();r=t,s-n>=e?o.call(this):i||(i=setTimeout((()=>{i=null,o.call(this)}),e-(s-n)))}}})};window.Rumious=Ot}();
|
package/dist/jsx/index.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import { RumiousTemplateGenerator } from
|
2
|
-
import { RumiousRenderTemplate } from
|
1
|
+
import { RumiousTemplateGenerator } from '../types/render.js';
|
2
|
+
import { RumiousRenderTemplate } from '../render/template.js';
|
3
3
|
export declare function template(generator: RumiousTemplateGenerator): RumiousRenderTemplate;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
export declare function tholle<T extends (...args: any[]) => any>(func: T, limit: number): T;
|
2
|
+
export declare function denounce<T extends (...args: any[]) => any>(func: T, delay: number): T;
|
3
|
+
export declare function trailingThrottle<T extends (...args: any[]) => any>(func: T, limit: number): T;
|
4
|
+
export declare function leadingTrailingDebounce<T extends (...args: any[]) => any>(func: T, delay: number): T;
|
5
|
+
export declare function rafThrottle<T extends (...args: any[]) => any>(func: T): T;
|
package/dist/render/array.d.ts
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
import { RumiousRenderTemplate } from
|
2
|
-
import { RumiousArrayState } from
|
3
|
-
import { RumiousRenderContext } from
|
4
|
-
import { RumiousStateCommit } from
|
5
|
-
type RumiousDynamicArrayRenderFn
|
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 = (item: any, index: any) => RumiousRenderTemplate;
|
6
6
|
export declare class RumiousDynamicArrayRenderer<T> {
|
7
7
|
state: RumiousArrayState<T>;
|
8
|
-
callback: RumiousDynamicArrayRenderFn
|
8
|
+
callback: RumiousDynamicArrayRenderFn;
|
9
9
|
anchorElement: HTMLElement;
|
10
10
|
context: RumiousRenderContext;
|
11
11
|
private domMap;
|
12
12
|
private keyFn;
|
13
|
-
constructor(state: RumiousArrayState<T>, callback: RumiousDynamicArrayRenderFn
|
13
|
+
constructor(state: RumiousArrayState<T>, callback: RumiousDynamicArrayRenderFn, keyFn?: (item: any, index: any) => any);
|
14
14
|
prepare(anchor: HTMLElement, context: RumiousRenderContext): void;
|
15
15
|
render(): Promise<void>;
|
16
16
|
onStateChange(commit: RumiousStateCommit<typeof this.state.value>): Promise<void>;
|
17
17
|
private reconcile;
|
18
18
|
}
|
19
|
-
export declare function renderDynamicArray<T>(state: RumiousArrayState<T>, callback: RumiousDynamicArrayRenderFn
|
19
|
+
export declare function renderDynamicArray<T>(state: RumiousArrayState<T>, callback: RumiousDynamicArrayRenderFn): RumiousDynamicArrayRenderer<T>;
|
20
20
|
export {};
|
package/dist/render/context.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { RumiousRenderable } from '../types/render.js';
|
2
2
|
import type { RumiousApp } from '../app/app.js';
|
3
|
-
import type { RumiousRenderTemplate } from
|
3
|
+
import type { RumiousRenderTemplate } from './template.js';
|
4
4
|
export declare class RumiousRenderContext {
|
5
5
|
target: RumiousRenderable;
|
6
6
|
app?: RumiousApp;
|
package/dist/render/dynamic.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import { RumiousRenderContext } from
|
2
|
-
export declare function dynamicValue(target: HTMLElement, textNode: Text, value: any, context: RumiousRenderContext): void
|
1
|
+
import { RumiousRenderContext } from './context.js';
|
2
|
+
export declare function dynamicValue(target: HTMLElement, textNode: Text, value: any, context: RumiousRenderContext): Promise<void>;
|
package/dist/render/index.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
3
|
-
export { renderDynamicArray } from
|
1
|
+
export * from './template.js';
|
2
|
+
export * from './injector.js';
|
3
|
+
export { renderDynamicArray } from './array.js';
|
package/dist/render/render.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import { RumiousRenderContext } from
|
2
|
-
import { RumiousRenderTemplate } from
|
1
|
+
import { RumiousRenderContext } from './context.js';
|
2
|
+
import { RumiousRenderTemplate } from './template.js';
|
3
3
|
export declare function render(context: RumiousRenderContext, template: RumiousRenderTemplate, target: HTMLElement | HTMLDocument | DocumentFragment): void;
|
package/dist/state/array.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { RumiousState } from
|
2
|
-
import { RumiousReactor } from
|
1
|
+
import { RumiousState } from './state.js';
|
2
|
+
import { RumiousReactor } from './reactor.js';
|
3
3
|
export declare class RumiousArrayState<T> extends RumiousState<T[]> {
|
4
4
|
constructor(value: T[], reactor?: RumiousReactor<T[]>);
|
5
5
|
set(value: T[]): void;
|
package/dist/state/index.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
3
|
-
export * from
|
1
|
+
export * from './state.js';
|
2
|
+
export * from './array.js';
|
3
|
+
export * from './object.js';
|
package/dist/state/object.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { RumiousState } from
|
2
|
-
import { RumiousReactor } from
|
1
|
+
import { RumiousState } from './state.js';
|
2
|
+
import { RumiousReactor } from './reactor.js';
|
3
3
|
export declare class RumiousObjectState<T extends Record<string, any>> extends RumiousState<T> {
|
4
4
|
#private;
|
5
5
|
constructor(value: T, reactor?: RumiousReactor<T>);
|
package/dist/state/reactor.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { RumiousState } from './state.js';
|
2
|
-
type RumiousStateCommitTypes =
|
2
|
+
type RumiousStateCommitTypes = 'SET' | 'GET' | 'SET_BY_KEY' | 'REMOVE_BY_KEY' | 'APPEND' | 'INSERT_BY_KEY';
|
3
3
|
export interface RumiousStateCommit<T> {
|
4
4
|
type: RumiousStateCommitTypes;
|
5
5
|
target: RumiousState<T>;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { RumiousRenderTemplate } from '../render/template.js';
|
2
|
+
export 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
|
+
}
|
package/dist/types/render.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { RumiousApp } from '../app/index.js';
|
2
2
|
import type { RumiousComponent } from '../component/component.js';
|
3
|
-
export type RumiousRenderMode =
|
3
|
+
export type RumiousRenderMode = 'idle' | 'async' | 'linear' | 'animate';
|
4
4
|
export type RumiousRenderable = RumiousComponent | RumiousApp;
|
5
5
|
export type RumiousTemplateGenerator = (root: HTMLElement | HTMLDocument | DocumentFragment, context: Record<any, any>) => HTMLElement | DocumentFragment | HTMLDocument | Node;
|
package/dist/utils/name.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
{
|
2
2
|
"name": "rumious",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.2",
|
4
4
|
"description": "Simple framework for building UI ",
|
5
|
-
"main": "./index.
|
6
|
-
"
|
5
|
+
"main": "./dist/index.cjs",
|
6
|
+
"module": "./dist/index.esm.js",
|
7
|
+
"exports": {
|
8
|
+
"import": "./dist/index.esm.js",
|
9
|
+
"require": "./dist/index.cjs",
|
10
|
+
"types": "./dist/index.d.ts",
|
11
|
+
".": {
|
12
|
+
"import": "./dist/index.esm.js",
|
13
|
+
"require": "./dist/index.cjs",
|
14
|
+
"types": "./dist/index.d.ts"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
"types": "./dist/index.d.ts",
|
7
18
|
"keywords": [
|
8
19
|
"rumious",
|
9
20
|
"core",
|
@@ -19,7 +30,7 @@
|
|
19
30
|
"build:dev": "rollup -c ",
|
20
31
|
"start": "node dist/index.js",
|
21
32
|
"test": "echo \"No tests yet\"",
|
22
|
-
"
|
33
|
+
"prepublishOnly": "npm run dec && npm run build"
|
23
34
|
},
|
24
35
|
"author": "smtdfc",
|
25
36
|
"license": "MIT",
|
@@ -43,4 +54,4 @@
|
|
43
54
|
"dependencies": {
|
44
55
|
"mutative": "^1.1.0"
|
45
56
|
}
|
46
|
-
}
|
57
|
+
}
|
package/index.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from "./dist/index.js";
|
package/index.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from "./dist/index.min.js";
|