rumious 1.0.0 → 1.0.1

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/index.esm.js CHANGED
@@ -1 +1,1072 @@
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 } from 'mutative';
2
+
3
+ class RumiousRenderContext {
4
+ constructor(target, app) {
5
+ this.target = target;
6
+ this.app = app;
7
+ this.onRenderFinished = [];
8
+ }
9
+ findName(name) {
10
+ return this.target[name];
11
+ }
12
+ }
13
+
14
+ function render(context, template, target) {
15
+ let generator = template.generator.bind(context.target);
16
+ context.renderHelper = render;
17
+ generator(target, context);
18
+ setTimeout(async () => {
19
+ const callbacks = [...context.onRenderFinished];
20
+ context.onRenderFinished = [];
21
+ for (const callback of callbacks) {
22
+ await callback();
23
+ }
24
+ }, 0);
25
+ }
26
+
27
+ class RumiousComponent {
28
+ static classNames = "";
29
+ static tagName = "rumious-component";
30
+ constructor() {
31
+ this.renderOptions = {
32
+ mode: "idle"
33
+ };
34
+ }
35
+ onCreate() {}
36
+ onRender() {}
37
+ onDestroy() {}
38
+ async onBeforeRender() {}
39
+ prepare(currentContext, props) {
40
+ this.props = props;
41
+ this.context = new RumiousRenderContext(this, currentContext.app);
42
+ }
43
+ async requestRender() {
44
+ await this.onBeforeRender();
45
+ let template = this.template();
46
+ render(this.context, template, this.element);
47
+ this.onRender();
48
+ }
49
+ requestCleanup() {}
50
+ }
51
+
52
+ class RumiousComponentElement extends HTMLElement {
53
+ constructor() {
54
+ super();
55
+ this.props = {};
56
+ }
57
+ setup(context, componentConstructor) {
58
+ this.context = context;
59
+ this.componentConstructor = componentConstructor;
60
+ }
61
+ connectedCallback() {
62
+ if (!this.componentConstructor) {
63
+ console.warn("Rumious: Cannot find matching component constructor.");
64
+ return;
65
+ }
66
+ this.componentInstance = new this.componentConstructor();
67
+ this.componentInstance.element = this;
68
+ if (this.componentConstructor.classNames) {
69
+ this.className = this.componentConstructor.classNames;
70
+ }
71
+ this.componentInstance.prepare(this.context, this.props);
72
+ this.componentInstance.onCreate();
73
+ this.componentInstance.requestRender();
74
+ }
75
+ disconnectedCallback() {
76
+ this.componentInstance?.onDestroy();
77
+ }
78
+ }
79
+
80
+ class RumiousApp {
81
+ constructor(root, options = {}) {
82
+ this.root = root;
83
+ this.options = options;
84
+ this.modules = [];
85
+ this.context = new RumiousRenderContext(this, this);
86
+ }
87
+ addModule(module, options) {
88
+ let instance = module.init(this, options);
89
+ this.modules.push(instance);
90
+ return instance;
91
+ }
92
+ render(template) {
93
+ render(this.context, template, this.root);
94
+ }
95
+ }
96
+ function createApp(root, options) {
97
+ return new RumiousApp(root, options);
98
+ }
99
+
100
+ class RumiousRenderTemplate {
101
+ constructor(generator) {
102
+ this.generator = generator;
103
+ }
104
+ }
105
+
106
+ class RumiousDymanicInjector {
107
+ constructor(contents) {
108
+ this.contents = contents;
109
+ this.targets = new Map();
110
+ if (!contents || contents.length === 0) {
111
+ throw new Error("Injector must be initialized with non-empty content");
112
+ }
113
+ const first = contents[0];
114
+ this.type = typeof first === "string" ? "string" : "element";
115
+ }
116
+ addTarget(element) {
117
+ this.targets.set(element, 1);
118
+ }
119
+ inject(element) {
120
+ if (!this.targets.has(element)) return;
121
+ if (!this.contents) return;
122
+ element.innerHTML = "";
123
+ if (this.type === "string") {
124
+ for (const content of this.contents) {
125
+ element.insertAdjacentHTML("beforeend", content);
126
+ }
127
+ } else {
128
+ for (const content of this.contents) {
129
+ element.appendChild(content);
130
+ }
131
+ }
132
+ }
133
+ injectAll() {
134
+ for (const target of this.targets.keys()) {
135
+ this.inject(target);
136
+ }
137
+ }
138
+ removeTarget(element) {
139
+ this.targets.delete(element);
140
+ }
141
+ clear() {
142
+ this.targets.clear();
143
+ }
144
+ }
145
+ function createHTMLInjector(html) {
146
+ return new RumiousDymanicInjector([html]);
147
+ }
148
+
149
+ class RumiousElementRef {
150
+ constructor(target) {
151
+ this.target = target;
152
+ }
153
+ getElement() {
154
+ return this.target;
155
+ }
156
+ remove() {
157
+ this.target.remove();
158
+ }
159
+ addChild(child) {
160
+ this.target.appendChild(child);
161
+ }
162
+ listChild() {
163
+ return this.target.childNodes;
164
+ }
165
+ querySelector(query) {
166
+ return this.target.querySelector(query);
167
+ }
168
+ querySelectorAll(query) {
169
+ return this.target.querySelectorAll(query);
170
+ }
171
+ set text(t) {
172
+ this.target.textContent = t;
173
+ }
174
+ get text() {
175
+ return this.target.textContent;
176
+ }
177
+ set value(v) {
178
+ if (this.target instanceof HTMLInputElement || this.target instanceof HTMLTextAreaElement) {
179
+ this.target.value = v;
180
+ }
181
+ }
182
+ get value() {
183
+ if (this.target instanceof HTMLInputElement || this.target instanceof HTMLTextAreaElement) {
184
+ return this.target.value;
185
+ }
186
+ return undefined;
187
+ }
188
+ addClassName(className) {
189
+ this.target.classList.add(className);
190
+ }
191
+ removeClassName(className) {
192
+ this.target.classList.remove(className);
193
+ }
194
+ hasClassName(className) {
195
+ return this.target.classList.contains(className);
196
+ }
197
+ toggleClass(className, force) {
198
+ return this.target.classList.toggle(className, force);
199
+ }
200
+ setStyle(styles) {
201
+ Object.assign(this.target.style, styles);
202
+ }
203
+ getStyle(property) {
204
+ return getComputedStyle(this.target).getPropertyValue(property);
205
+ }
206
+ setAttribute(key, value) {
207
+ this.target.setAttribute(key, value);
208
+ }
209
+ getAttribute(key) {
210
+ return this.target.getAttribute(key);
211
+ }
212
+ removeAttribute(key) {
213
+ this.target.removeAttribute(key);
214
+ }
215
+ on(event, callback, options) {
216
+ this.target.addEventListener(event, callback, options);
217
+ }
218
+ off(event, callback, options) {
219
+ this.target.removeEventListener(event, callback, options);
220
+ }
221
+ set html(t) {
222
+ this.target.innerHTML = t;
223
+ }
224
+ get html() {
225
+ return this.target.innerHTML;
226
+ }
227
+ getBoundingRect() {
228
+ return this.target.getBoundingClientRect();
229
+ }
230
+ isInViewport() {
231
+ const rect = this.target.getBoundingClientRect();
232
+ return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
233
+ }
234
+ prependChild(child) {
235
+ this.target.prepend(child);
236
+ }
237
+ setDisabled(disabled) {
238
+ if (this.target instanceof HTMLButtonElement || this.target instanceof HTMLInputElement || this.target instanceof HTMLTextAreaElement) {
239
+ this.target.disabled = disabled;
240
+ }
241
+ }
242
+ addClasses(...classNames) {
243
+ this.target.classList.add(...classNames);
244
+ }
245
+ removeClasses(...classNames) {
246
+ this.target.classList.remove(...classNames);
247
+ }
248
+ replaceClass(oldClass, newClass) {
249
+ this.target.classList.replace(oldClass, newClass);
250
+ }
251
+ moveTo(newParent) {
252
+ newParent.appendChild(this.target);
253
+ }
254
+ getParent() {
255
+ return this.target.parentElement;
256
+ }
257
+ getNextSibling() {
258
+ return this.target.nextElementSibling;
259
+ }
260
+ getPreviousSibling() {
261
+ return this.target.previousElementSibling;
262
+ }
263
+ hide() {
264
+ this.target.style.display = 'none';
265
+ }
266
+ show() {
267
+ this.target.style.removeProperty('display');
268
+ }
269
+ isHidden() {
270
+ return window.getComputedStyle(this.target).display === 'none';
271
+ }
272
+ scrollIntoView(options = {
273
+ behavior: 'smooth'
274
+ }) {
275
+ this.target.scrollIntoView(options);
276
+ }
277
+ matches(selector) {
278
+ return this.target.matches(selector);
279
+ }
280
+ getChildren() {
281
+ return Array.from(this.target.children);
282
+ }
283
+ insertAfter(newNode) {
284
+ if (this.target.parentNode) {
285
+ this.target.parentNode.insertBefore(newNode, this.target.nextSibling);
286
+ }
287
+ }
288
+ insertBefore(newNode) {
289
+ if (this.target.parentNode) {
290
+ this.target.parentNode.insertBefore(newNode, this.target);
291
+ }
292
+ }
293
+ clearChildren() {
294
+ while (this.target.firstChild) {
295
+ this.target.removeChild(this.target.firstChild);
296
+ }
297
+ }
298
+ animate(keyframes, options) {
299
+ return this.target.animate(keyframes, options);
300
+ }
301
+ }
302
+ function createElementRef() {
303
+ return new RumiousElementRef(document.createElement("span"));
304
+ }
305
+
306
+ function extractName(str) {
307
+ const index = str.indexOf('$');
308
+ if (index !== -1) {
309
+ return str.slice(index + 1);
310
+ }
311
+ return '';
312
+ }
313
+ function generateName(prefix = "_") {
314
+ return `${prefix}${(Math.floor(Math.random() * 9999) * Date.now()).toString(32)}`;
315
+ }
316
+
317
+ class RumiousReactor {
318
+ constructor(target) {
319
+ this.target = target;
320
+ this.bindings = [];
321
+ }
322
+ addBinding(bind) {
323
+ this.bindings.push(bind);
324
+ }
325
+ removeBinding(bind) {
326
+ this.bindings = this.bindings.filter(_ => _ !== bind);
327
+ }
328
+ async emit(commit) {
329
+ await Promise.allSettled(this.bindings.map(bind => {
330
+ try {
331
+ const result = bind(commit);
332
+ return result instanceof Promise ? result : Promise.resolve(result);
333
+ } catch (err) {
334
+ return Promise.reject(err);
335
+ }
336
+ }));
337
+ }
338
+ }
339
+
340
+ class RumiousState {
341
+ constructor(value, reactor) {
342
+ this.value = value;
343
+ this.reactor = reactor ?? new RumiousReactor(this);
344
+ }
345
+ set(value) {
346
+ this.value = value;
347
+ this.reactor.emit({
348
+ type: "SET",
349
+ target: this,
350
+ value: value
351
+ });
352
+ }
353
+ get() {
354
+ return this.value;
355
+ }
356
+ increase(count = 1) {
357
+ if (typeof this.value === "number") {
358
+ this.set(this.value + count);
359
+ }
360
+ }
361
+ produce(callback) {
362
+ const [draft, finalize] = create(this.value);
363
+ callback(draft);
364
+ this.set(finalize());
365
+ }
366
+ }
367
+ function watch(state, fn) {
368
+ state.reactor.addBinding(fn);
369
+ }
370
+ function unwatch(state, fn) {
371
+ state.reactor.removeBinding(fn);
372
+ }
373
+ function createState(value) {
374
+ return new RumiousState(value);
375
+ }
376
+
377
+ function eventBindingDirective(context, target, modifier, data) {
378
+ if (typeof data === "string") {
379
+ data = context.findName(extractName(data));
380
+ }
381
+ target.addEventListener(modifier, data);
382
+ }
383
+ function refBindingDirective(context, target, modifier, data) {
384
+ if (typeof data === "string") {
385
+ data = context.findName(extractName(data));
386
+ }
387
+ if (data instanceof RumiousElementRef) {
388
+ data.target = target;
389
+ } else {
390
+ throw Error("Rumious: ref directive required RumiousElementRef !");
391
+ }
392
+ }
393
+ function injectDirective(context, target, modifier, data) {
394
+ if (typeof data === "string") {
395
+ data = context.findName(extractName(data));
396
+ }
397
+ if (data instanceof RumiousDymanicInjector) {
398
+ data.addTarget(target);
399
+ data.inject(target);
400
+ } else {
401
+ throw Error("Rumious: inject directive required RumiousInjector !");
402
+ }
403
+ }
404
+ function bindDirective(context, target, modifier, data) {
405
+ if (typeof data === "string") {
406
+ data = context.findName(extractName(data));
407
+ }
408
+ if (data instanceof RumiousState) {
409
+ target.setAttribute(modifier, data.value);
410
+ data.reactor.addBinding(({}) => {
411
+ target.setAttribute(modifier, data.value);
412
+ });
413
+ } else {
414
+ throw Error("Rumious: bind directive required RumiousState !");
415
+ }
416
+ }
417
+ function modelDirective(context, target, modifier, data) {
418
+ if (typeof data === "string") {
419
+ data = context.findName(extractName(data));
420
+ }
421
+ if (data instanceof RumiousState && (target instanceof HTMLInputElement || target instanceof HTMLSelectElement || target instanceof HTMLTextAreaElement)) {
422
+ const type = target.type;
423
+ target.addEventListener("input", () => {
424
+ if (target instanceof HTMLInputElement) {
425
+ switch (type) {
426
+ case "checkbox":
427
+ data.set(target.checked);
428
+ break;
429
+ case "radio":
430
+ if (target.checked) data.set(target.value);
431
+ break;
432
+ default:
433
+ data.set(target.value);
434
+ }
435
+ } else if (target instanceof HTMLSelectElement || target instanceof HTMLTextAreaElement) {
436
+ data.set(target.value);
437
+ }
438
+ });
439
+ } else {
440
+ throw Error("Rumious: model directive requires RumiousState and a valid form element!");
441
+ }
442
+ }
443
+ const directives = {
444
+ "on": eventBindingDirective,
445
+ "ref": refBindingDirective,
446
+ "inject": injectDirective,
447
+ "bind": bindDirective,
448
+ "model": modelDirective
449
+ };
450
+
451
+ class RumiousDynamicArrayRenderer {
452
+ domMap = new Map();
453
+ constructor(state, callback, keyFn) {
454
+ this.state = state;
455
+ this.callback = callback;
456
+ this.keyFn = keyFn ?? ((_, i) => i);
457
+ }
458
+ prepare(anchor, context) {
459
+ this.anchorElement = anchor;
460
+ this.context = context;
461
+ }
462
+ async render() {
463
+ await this.reconcile(this.state.value);
464
+ this.state.reactor.addBinding(this.onStateChange.bind(this));
465
+ }
466
+ async onStateChange(commit) {
467
+ if (commit.type === "APPEND") {
468
+ const key = this.keyFn(commit.item, commit.key);
469
+ if (!this.domMap.has(key)) {
470
+ const template = await this.callback(commit.item, commit.key);
471
+ const frag = document.createDocumentFragment();
472
+ this.context.renderHelper(this.context, template, frag);
473
+ this.anchorElement.appendChild(frag);
474
+ this.domMap.set(key, frag);
475
+ }
476
+ } else if (commit.type === "SET_BY_KEY") {
477
+ const key = this.keyFn(commit.item, commit.key);
478
+ const oldNode = this.anchorElement.childNodes[commit.key];
479
+ if (oldNode) {
480
+ const template = await this.callback(commit.item, commit.key);
481
+ const frag = document.createDocumentFragment();
482
+ this.context.renderHelper(this.context, template, frag);
483
+ this.anchorElement.replaceChild(frag, oldNode);
484
+ this.domMap.set(key, frag);
485
+ }
486
+ } else if (commit.type === "REMOVE_BY_KEY") {
487
+ const node = this.anchorElement.childNodes[commit.key];
488
+ if (node) {
489
+ this.anchorElement.removeChild(node);
490
+ const entry = [...this.domMap.entries()].find(([, n]) => n === node);
491
+ if (entry) this.domMap.delete(entry[0]);
492
+ }
493
+ } else if (commit.type === "INSERT_BY_KEY") {
494
+ const key = this.keyFn(commit.item, commit.key);
495
+ if (!this.domMap.has(key)) {
496
+ const template = await this.callback(commit.item, commit.key);
497
+ const frag = document.createDocumentFragment();
498
+ this.context.renderHelper(this.context, template, frag);
499
+ const refNode = this.anchorElement.childNodes[commit.key] ?? null;
500
+ this.anchorElement.insertBefore(frag, refNode);
501
+ this.domMap.set(key, frag);
502
+ }
503
+ } else {
504
+ await this.reconcile(this.state.value);
505
+ }
506
+ }
507
+ async reconcile(nextItems) {
508
+ const oldMap = this.domMap;
509
+ const newMap = new Map();
510
+ const newNodes = [];
511
+ for (let i = 0; i < nextItems.length; i++) {
512
+ const item = nextItems[i];
513
+ const key = this.keyFn(item, i);
514
+ let node = oldMap.get(key);
515
+ if (!node) {
516
+ const template = await this.callback(item, i);
517
+ const frag = document.createDocumentFragment();
518
+ this.context.renderHelper(this.context, template, frag);
519
+ node = frag;
520
+ }
521
+ newMap.set(key, node);
522
+ newNodes.push(node);
523
+ }
524
+ this.anchorElement.textContent = "";
525
+ for (const node of newNodes) {
526
+ this.anchorElement.appendChild(node);
527
+ }
528
+ this.domMap = newMap;
529
+ }
530
+ }
531
+ function renderDynamicArray(state, callback) {
532
+ return new RumiousDynamicArrayRenderer(state, callback);
533
+ }
534
+
535
+ function isPrimitive(value) {
536
+ return value !== Object(value);
537
+ }
538
+
539
+ async function dynamicValue$1(target, textNode, value, context) {
540
+ const parent = textNode.parentNode;
541
+ if (!parent) return;
542
+ if (isPrimitive(value)) {
543
+ textNode.textContent = String(value);
544
+ } else if (value && value instanceof RumiousState) {
545
+ textNode.textContent = value.value;
546
+ function onValueChange({}) {
547
+ if (document.contains(textNode)) {
548
+ textNode.textContent = value.value;
549
+ } else {
550
+ value.reactor.removeBinding(onValueChange);
551
+ }
552
+ }
553
+ value.reactor.addBinding(onValueChange);
554
+ } else if (Array.isArray(value)) {
555
+ textNode.textContent = value.map(String).join("");
556
+ } else if (value instanceof RumiousDynamicArrayRenderer) {
557
+ value.prepare(textNode.parentElement, context);
558
+ value.render();
559
+ } else if (value instanceof HTMLElement) {
560
+ textNode.replaceWith(value);
561
+ } else if (value instanceof RumiousRenderTemplate) {
562
+ let fragment = document.createDocumentFragment();
563
+ context.renderHelper?.(context, value, fragment);
564
+ textNode.replaceWith(fragment);
565
+ } else if (value instanceof NodeList || value instanceof HTMLCollection) {
566
+ if (value.length === 0) {
567
+ textNode.remove();
568
+ return;
569
+ }
570
+ const fragment = document.createDocumentFragment();
571
+ for (const node of Array.from(value)) {
572
+ fragment.appendChild(node.cloneNode(true));
573
+ }
574
+ textNode.replaceWith(fragment);
575
+ textNode.remove();
576
+ } else if (value && typeof value.toString === "function") {
577
+ try {
578
+ textNode.textContent = value.toString();
579
+ } catch {
580
+ textNode.textContent = "";
581
+ }
582
+ } else {
583
+ textNode.textContent = "";
584
+ }
585
+ }
586
+
587
+ function template(generator) {
588
+ return new RumiousRenderTemplate(generator);
589
+ }
590
+ function addDirective(element, context, name, modifier = "", data) {
591
+ let callback = directives[name];
592
+ if (callback) {
593
+ callback(context, element, modifier, data);
594
+ } else {
595
+ throw Error("Rumious: Cannot solve directive !");
596
+ }
597
+ }
598
+ function dynamicValue(target, textNode, value, context) {
599
+ dynamicValue$1(target, textNode, value, context);
600
+ }
601
+ function createComponent(componentConstructor) {
602
+ let tagName = componentConstructor.tagName;
603
+ if (!window.customElements.get(tagName)) {
604
+ window.customElements.define(tagName, class extends RumiousComponentElement {
605
+ static tag = tagName;
606
+ });
607
+ }
608
+ return document.createElement(tagName);
609
+ }
610
+
611
+ // This is just to satisfy TypeScript's JSX requirement.
612
+ // Rumious doesn't use createElement — we do things differently.
613
+
614
+ function createElement(...args) {
615
+ throw Error("Rumious doesn't use createElement !");
616
+ }
617
+ window.RUMIOUS_JSX = {
618
+ template,
619
+ createElement,
620
+ addDirective,
621
+ dynamicValue,
622
+ createComponent
623
+ };
624
+
625
+ class RumiousChildrenRef {
626
+ constructor(target) {
627
+ this.target = target;
628
+ }
629
+ list() {
630
+ return Array.from(this.target.children);
631
+ }
632
+ getChild(index) {
633
+ return this.list()[index];
634
+ }
635
+ remove(index) {
636
+ this.list()[index]?.remove();
637
+ }
638
+ add(child) {
639
+ this.target.appendChild(child);
640
+ }
641
+ querySelector(query) {
642
+ return this.target.querySelector(query);
643
+ }
644
+ querySelectorAll(query) {
645
+ return this.target.querySelectorAll(query);
646
+ }
647
+ clear() {
648
+ this.target.innerHTML = '';
649
+ }
650
+ replaceChild(index, newChild) {
651
+ const oldChild = this.getChild(index);
652
+ if (oldChild) {
653
+ this.target.replaceChild(newChild, oldChild);
654
+ }
655
+ }
656
+ insertBefore(newChild, index) {
657
+ const referenceChild = this.getChild(index);
658
+ if (referenceChild) {
659
+ this.target.insertBefore(newChild, referenceChild);
660
+ } else {
661
+ this.add(newChild);
662
+ }
663
+ }
664
+ prepend(child) {
665
+ this.target.prepend(child);
666
+ }
667
+ getFirstChild() {
668
+ return this.list()[0];
669
+ }
670
+ getLastChild() {
671
+ return this.list()[this.list().length - 1];
672
+ }
673
+ hasChildren() {
674
+ return this.target.hasChildNodes();
675
+ }
676
+ count() {
677
+ return this.target.children.length;
678
+ }
679
+ find(predicate) {
680
+ return this.list().find(predicate);
681
+ }
682
+ forEach(callback) {
683
+ this.list().forEach(callback);
684
+ }
685
+ removeAllMatching(query) {
686
+ this.querySelectorAll(query).forEach(element => element.remove());
687
+ }
688
+ toggleClass(className) {
689
+ this.list().forEach(child => child.classList.toggle(className));
690
+ }
691
+ setAttribute(key, value) {
692
+ this.list().forEach(child => child.setAttribute(key, value));
693
+ }
694
+ }
695
+
696
+ class RumiousArrayState extends RumiousState {
697
+ constructor(value, reactor) {
698
+ super(value, reactor);
699
+ }
700
+ set(arg1, arg2) {
701
+ if (typeof arg1 === "number" && arg2 !== undefined) {
702
+ const index = arg1;
703
+ const newValue = arg2;
704
+ this.value[index] = newValue;
705
+ this.reactor.emit({
706
+ type: "SET_BY_KEY",
707
+ value: [...this.value],
708
+ target: this,
709
+ key: index,
710
+ item: newValue
711
+ });
712
+ } else if (Array.isArray(arg1)) {
713
+ super.set(arg1);
714
+ } else {
715
+ throw new Error("Invalid arguments passed to set()");
716
+ }
717
+ }
718
+ get(arg) {
719
+ return typeof arg === "number" ? this.value[arg] : this.value;
720
+ }
721
+ insert(index, newItem) {
722
+ this.value.splice(index, 0, newItem);
723
+ this.reactor.emit({
724
+ type: "INSERT_BY_KEY",
725
+ value: this.value,
726
+ target: this,
727
+ key: index,
728
+ item: newItem
729
+ });
730
+ return this;
731
+ }
732
+ remove(index) {
733
+ this.value.splice(index, 1);
734
+ this.reactor.emit({
735
+ type: "REMOVE_BY_KEY",
736
+ value: this.value,
737
+ target: this,
738
+ key: index
739
+ });
740
+ return this;
741
+ }
742
+ append(value) {
743
+ this.value.push(value);
744
+ this.reactor.emit({
745
+ type: "APPEND",
746
+ value: this.value,
747
+ target: this,
748
+ item: value
749
+ });
750
+ return this;
751
+ }
752
+ clear() {
753
+ this.value.length = 0;
754
+ this.reactor.emit({
755
+ type: "SET",
756
+ value: [],
757
+ target: this
758
+ });
759
+ return this;
760
+ }
761
+ replace(index, newItem) {
762
+ if (index < 0 || index >= this.value.length) {
763
+ throw new Error("Index out of bounds");
764
+ }
765
+ this.value[index] = newItem;
766
+ this.reactor.emit({
767
+ type: "SET_BY_KEY",
768
+ value: [...this.value],
769
+ target: this,
770
+ key: index,
771
+ item: newItem
772
+ });
773
+ return this;
774
+ }
775
+ filter(callback) {
776
+ this.value = this.value.filter(callback);
777
+ this.reactor.emit({
778
+ type: "SET",
779
+ value: this.value,
780
+ target: this
781
+ });
782
+ return this;
783
+ }
784
+ map(callback) {
785
+ this.value = this.value.map(callback);
786
+ this.reactor.emit({
787
+ type: "SET",
788
+ value: this.value,
789
+ target: this
790
+ });
791
+ return this;
792
+ }
793
+ sort(compareFn) {
794
+ this.value.sort(compareFn);
795
+ this.reactor.emit({
796
+ type: "SET",
797
+ value: this.value,
798
+ target: this
799
+ });
800
+ return this;
801
+ }
802
+ reverse() {
803
+ this.value.reverse();
804
+ this.reactor.emit({
805
+ type: "SET",
806
+ value: this.value,
807
+ target: this
808
+ });
809
+ return this;
810
+ }
811
+ get length() {
812
+ return this.value.length;
813
+ }
814
+ forEach(callback) {
815
+ this.value.forEach(callback);
816
+ }
817
+ }
818
+ function createArrayState(value) {
819
+ return new RumiousArrayState(value);
820
+ }
821
+
822
+ class RumiousObjectState extends RumiousState {
823
+ #locked = false;
824
+ constructor(value, reactor) {
825
+ super(value, reactor);
826
+ }
827
+ set(arg1, arg2) {
828
+ if (this.#locked) throw new Error("Object is locked");
829
+ if (typeof arg1 === "string") {
830
+ const key = arg1;
831
+ const newValue = arg2;
832
+ this.value[key] = newValue;
833
+ this.reactor.emit({
834
+ type: "SET_BY_KEY",
835
+ value: {
836
+ ...this.value
837
+ },
838
+ target: this,
839
+ key,
840
+ item: newValue
841
+ });
842
+ return this;
843
+ } else if (typeof arg1 === "object") {
844
+ super.set(arg1);
845
+ } else {
846
+ throw new Error("Invalid arguments passed to set()");
847
+ }
848
+ }
849
+ remove(key) {
850
+ if (this.#locked) throw new Error("Object is locked");
851
+ if (key in this.value) {
852
+ delete this.value[key];
853
+ this.reactor.emit({
854
+ type: "REMOVE_BY_KEY",
855
+ value: {
856
+ ...this.value
857
+ },
858
+ target: this,
859
+ key
860
+ });
861
+ }
862
+ return this;
863
+ }
864
+ merge(partial) {
865
+ if (this.#locked) throw new Error("Object is locked");
866
+ Object.assign(this.value, partial);
867
+ this.reactor.emit({
868
+ type: "SET",
869
+ value: {
870
+ ...this.value
871
+ },
872
+ target: this
873
+ });
874
+ return this;
875
+ }
876
+ assign(obj) {
877
+ if (this.#locked) throw new Error("Object is locked");
878
+ this.value = {
879
+ ...this.value,
880
+ ...obj
881
+ };
882
+ this.reactor.emit({
883
+ type: "SET",
884
+ value: {
885
+ ...this.value
886
+ },
887
+ target: this
888
+ });
889
+ return this;
890
+ }
891
+ clear() {
892
+ if (this.#locked) throw new Error("Object is locked");
893
+ for (const key in this.value) {
894
+ delete this.value[key];
895
+ }
896
+ this.reactor.emit({
897
+ type: "SET",
898
+ value: {},
899
+ target: this
900
+ });
901
+ return this;
902
+ }
903
+ get(arg) {
904
+ return typeof arg === "string" ? this.value[arg] : this.value;
905
+ }
906
+ keys() {
907
+ return Object.keys(this.value);
908
+ }
909
+ values() {
910
+ return Object.values(this.value);
911
+ }
912
+ entries() {
913
+ return Object.entries(this.value);
914
+ }
915
+ has(key) {
916
+ return key in this.value;
917
+ }
918
+ get size() {
919
+ return Object.keys(this.value).length;
920
+ }
921
+ forEach(callback) {
922
+ Object.entries(this.value).forEach(([key, value]) => {
923
+ callback(value, key, this.value);
924
+ });
925
+ }
926
+ map(callback) {
927
+ const result = {};
928
+ Object.entries(this.value).forEach(([key, value]) => {
929
+ result[key] = callback(value, key, this.value);
930
+ });
931
+ return result;
932
+ }
933
+ clone() {
934
+ return JSON.parse(JSON.stringify(this.value));
935
+ }
936
+ toJSON() {
937
+ return JSON.parse(JSON.stringify(this.value));
938
+ }
939
+ toObject() {
940
+ return this.get();
941
+ }
942
+ lock() {
943
+ this.#locked = true;
944
+ return this;
945
+ }
946
+ unlock() {
947
+ this.#locked = false;
948
+ return this;
949
+ }
950
+ get isLocked() {
951
+ return this.#locked;
952
+ }
953
+ freeze() {
954
+ Object.freeze(this.value);
955
+ return this;
956
+ }
957
+ unfreeze() {
958
+ this.value = JSON.parse(JSON.stringify(this.value));
959
+ return this;
960
+ }
961
+ get isFrozen() {
962
+ return Object.isFrozen(this.value);
963
+ }
964
+ }
965
+ function createObjectState(value) {
966
+ return new RumiousObjectState(value);
967
+ }
968
+
969
+ window.RUMIOUS_CONTEXTS = {};
970
+ class RumiousContext {
971
+ constructor(initialValues = {}) {
972
+ this.events = {};
973
+ this.values = initialValues;
974
+ }
975
+ has(key) {
976
+ return key in this.values;
977
+ }
978
+ set(key, value) {
979
+ this.values[key] = value;
980
+ }
981
+ get(key) {
982
+ return this.values[key];
983
+ }
984
+ on(event, callback) {
985
+ if (!this.events[event]) this.events[event] = [];
986
+ this.events[event].push(callback);
987
+ }
988
+ off(event, callback) {
989
+ if (!this.events[event]) return;
990
+ this.events[event] = this.events[event].filter(fn => fn !== callback);
991
+ }
992
+ emit(event, payload) {
993
+ if (!this.events[event]) return;
994
+ this.events[event].forEach(fn => fn(payload));
995
+ }
996
+ }
997
+ function createContext(values, name = generateName("rctx_")) {
998
+ if (window.RUMIOUS_CONTEXTS[name]) return window.RUMIOUS_CONTEXTS[name];else {
999
+ let context = new RumiousContext(values);
1000
+ window.RUMIOUS_CONTEXTS[name] = context;
1001
+ return context;
1002
+ }
1003
+ }
1004
+
1005
+ function tholle(func, limit) {
1006
+ let lastCall = 0;
1007
+ return function (...args) {
1008
+ const now = Date.now();
1009
+ if (now - lastCall >= limit) {
1010
+ lastCall = now;
1011
+ func.apply(this, args);
1012
+ }
1013
+ };
1014
+ }
1015
+ function denounce(func, delay) {
1016
+ let timer;
1017
+ return function (...args) {
1018
+ clearTimeout(timer);
1019
+ timer = setTimeout(() => func.apply(this, args), delay);
1020
+ };
1021
+ }
1022
+ function trailingThrottle(func, limit) {
1023
+ let lastCall = 0;
1024
+ let lastArgs = null;
1025
+ let timeout = null;
1026
+ function invoke() {
1027
+ lastCall = Date.now();
1028
+ func.apply(this, lastArgs);
1029
+ lastArgs = null;
1030
+ }
1031
+ return function (...args) {
1032
+ const now = Date.now();
1033
+ lastArgs = args;
1034
+ if (now - lastCall >= limit) {
1035
+ invoke.call(this);
1036
+ } else if (!timeout) {
1037
+ timeout = setTimeout(() => {
1038
+ timeout = null;
1039
+ invoke.call(this);
1040
+ }, limit - (now - lastCall));
1041
+ }
1042
+ };
1043
+ }
1044
+ function leadingTrailingDebounce(func, delay) {
1045
+ let timer;
1046
+ let isFirstCall = true;
1047
+ return function (...args) {
1048
+ if (isFirstCall) {
1049
+ func.apply(this, args);
1050
+ isFirstCall = false;
1051
+ }
1052
+ clearTimeout(timer);
1053
+ timer = setTimeout(() => {
1054
+ func.apply(this, args);
1055
+ isFirstCall = true;
1056
+ }, delay);
1057
+ };
1058
+ }
1059
+ function rafThrottle(func) {
1060
+ let ticking = false;
1061
+ return function (...args) {
1062
+ if (!ticking) {
1063
+ ticking = true;
1064
+ requestAnimationFrame(() => {
1065
+ func.apply(this, args);
1066
+ ticking = false;
1067
+ });
1068
+ }
1069
+ };
1070
+ }
1071
+
1072
+ export { RumiousApp, RumiousArrayState, RumiousChildrenRef, RumiousComponent, RumiousComponentElement, RumiousContext, RumiousDymanicInjector, RumiousElementRef, RumiousObjectState, RumiousRenderTemplate, RumiousState, createApp, createArrayState, createContext, createElementRef, createHTMLInjector, createObjectState, createState, denounce, leadingTrailingDebounce, rafThrottle, renderDynamicArray, template, tholle, trailingThrottle, unwatch, watch };