forked from rahatool/runtime-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
light-framework.js
1 lines (1 loc) · 17.9 KB
/
light-framework.js
1
"use strict";{(()=>{let e=new Function("object","property","delete object[property]"),t=function(t,s,n){for(let r of Object.getOwnPropertyNames(s).concat(Object.getOwnPropertySymbols(s))){let i=Object.getOwnPropertyDescriptor(s,r);null==i.value&&(i.set||e(i,"set"),i.get||e(i,"get")),i.configurable=!1,n.has(r)||Object.defineProperty(t,r,i)}}.bind(this),n=new Set(Array.of("name","length","prototype")),r=new Set(Array.of("constructor"));Function.prototype.implements=function(e){return t(this,e,n),t(this.prototype,e.prototype,r),this};let i=function(){return this},l=Object.prototype.hasOwnProperty,o=Symbol.for("to");Symbol.implements((()=>{class e{}return e.set=Symbol(),e.get=Symbol(),e.add=Symbol(),e.clone=Symbol(),e.objectModel=Symbol(),e})());class a{get to(){if(l.call(this,o))return this[o];{let e=Symbol(`to${this.name}`);return this.prototype[e]=i,this[o]=e,e}}get empty(){return new this}isObjectModelOf(e){{let t=this.prototype;for(;e;)if((e=e[Symbol.objectModel])==t)return!0}return!1}[Symbol.clone](){return this}schedule(e,t){null==e&&(e=0),null==t&&(t=1);let s,n=this,r=function(){s=setTimeout(function(){(t-=1)&&r(),n()}.bind(this),e)}.bind(this);return r(),(new Object).fillWith({stop(){clearTimeout(s)}})}}Function.implements(a),Object.implements((()=>{let t;class n{static*getElementsOf(e){for(let t of Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e)))yield new s(t,e[t])}static set removeElementOf(e){t=e}static get removeElementOf(){return t}static setBaseOf(e,t){e[Symbol.objectModel]=t,e.prototype[Symbol.objectModel]=t.prototype}[Symbol.iterator](){return Object.getElementsOf(this)}set[Symbol.objectModel](e){Object.setPrototypeOf(this,e)}get[Symbol.objectModel](){return Object.getPrototypeOf(this)}[Symbol.clone](e){e=null!=e?e[Boolean.to]():Boolean.empty;let t=new(0,this.constructor);for(let s of Object.getElementsOf(this)){Sequence.isObjectModelOf(s)&&(s=s[List.to]());let n=s[Symbol.get]("name"),r=s[Symbol.get]("value");t[n]=e&&null!=r?r[Symbol.clone](e):r}return t}[Symbol.get](e){return this[e]}fillWith(e,t,s){let n=this;if(Object.assign(n,e),t){let e=0;for(let r of s?t.call(s):t)n[Symbol.add](r,e),e+=1}return n.whenObjectStateChanged&&n.whenObjectStateChanged(),n}}return n.removeElementOf=e,n})())})(),(()=>{let e;class t{static set empty(t){e=t}static get empty(){return e}static[Symbol.hasInstance](e){return null!=e&&e.constructor==this}[Symbol.clone](){return this}}t.empty=!1,Boolean.implements(t)})(),(()=>{let e;class t{static set to(t){e=t}static get to(){return e}static*empty(){}*filter(e){null==e&&(e=function(e){return null!=e}.bind(this));for(let t of this)e(t)&&(yield t)}*map(e){for(let t of this)yield e(t)}forEach(e){for(let t of this)e(t)}forAllExists(e){for(let t of this)if(!e(t))return!1;return!0}forAnyExists(e){for(let t of this)if(e(t))return!0;return!1}includes(e){return this.forAnyExists(function(t){return e==t}.bind(this))}find(e){for(let t of this)if(e(t))return t}}t.to=Symbol.iterator,this.Sequence=function*(){}.bind(this)[Symbol.objectModel],Sequence.implements(t)})(),(()=>{class e{}this.AsyncSequence=e})();let e=(()=>{let e;class t{static set empty(t){e=t}static get empty(){return e}static*range(e,t,s){if(null==t&&(t=0),null==s&&(s=1),e>t&&!t)for(;e;)yield e-=s;else for(s*=Math.sign(t-e);e<t;)yield e,e+=s}}return t.empty=0,this.Integer=t,t})(),t=((()=>{let t;class s{static set empty(e){t=e}static get empty(){return t}[Sequence.to](){return e.range(this)}[e.to](){return this>>>0}static[Symbol.hasInstance](e){return null!=e&&e.constructor==this}[Symbol.clone](){return this}}s.empty=0,this.RealNumber=Number,RealNumber.implements(s)})(),(()=>{let t,s;class n{static set to(e){t=e}static get to(){return t}static set empty(e){s=e}static get empty(){return s}static[Symbol.hasInstance](e){return null!=e&&e.constructor==this}[Symbol.clone](){return this}[e.to](e){null==e&&(e=10);let t=Number.parseInt(this,e);if(Number.isNaN(t))throw Number.NaN;return t}[RealNumber.to](){let e=Number.parseFloat(this);if(Number.isNaN(e))throw Number.NaN;return e}clean(){return this.replace(RegExp.from`\x20{2,}`," ").replace(RegExp.from`[\r\n|\r]`,"\n").trim()}get size(){return this.length}trimStart(){return this.trimLeft()}trimEnd(){return this.trimRight()}}n.empty="",n.to="toString",String.implements(n)})(),(()=>{class e{[Symbol.clone](e){return(new(0,this.constructor)).fillWith({},function*(){for(let t of this)yield e&&null!=t?t[Symbol.clone](e):t},this)}[Symbol.add](e){this.add(e)}addAll(e){e=null!=e?e[Sequence.to]():Sequence.empty;for(let t of e)this.add(t);return this}includes(e,t){{let s=0;for(let n of this){if(n==e&&s>=t)return!0;s+=1}}return!1}excludes(e,t){return!this.includes(e,t)}get isEmpty(){return 0==this.size}get size(){return this.length}set size(e){this.length=e}}return this.Collection=e,e})()),s=((()=>{class s{addAll(e,t){e=null!=e?e[Sequence.to]():Sequence.empty,null!=t?this.splice(t,0,...e):this.push(...e)}add(e,t){return null!=t?this.splice(t,0,e):this.push(e),this}clear(){return this.size=0,this}trim(e){this.size=e}remove(e){let t=this.indexOf(e);return t>-1&&(this.splice(t,1),!0)}replaceWith(t,s,n){return t=null!=t?t[e.to]():e.empty,s=null!=s?s[e.to]():e.empty,null==n&&(n=new List),n=null!=n?n[Sequence.to]():Sequence.empty,this.splice(t,s,...n)}orderBy(e){return this.sort(e)}*[Sequence.to](){for(let t of e.range(0,this.size))yield this[t]}}this.List=Array,List.implements(s),Object.setBaseOf(List,t),Sequence.implements(class{[List.to](){return(new List).fillWith({},function*(){for(let e of this)yield e},this)}})})(),(()=>{class e{remove(e){return this.delete(e)}includes(e){return this.has(e)}}Set.implements(e),Object.setBaseOf(Set,t)})(),(()=>{class e{remove(e){return this.delete(e)}includes(e){return this.has(e)}[Symbol.get](e){return this.get(e)}add(e){this.set(e[0],e[1])}}Map.implements(e),Object.setBaseOf(Map,t)})(),(()=>{return List.implements(class{get name(){return this[0]}get value(){return this[1]}}),class{constructor(){this.name=arguments[0],this.value=arguments[1]}get 0(){return this.name}get 1(){return this.value}*[Sequence.to](){yield this.name,yield this.value}}})());(()=>{class e{static from(e,...t){return new RegExp(`${e.raw[0]}${t.map(function(t,s){return`${t}${e.raw[s+1]}`}.bind(this)).join("")}`,"g")}hasMatch(e){return this.test(e)}*findAllMatches(e,t){null==t&&(t=0),this.lastIndex=t;{let t;for(;t=this.exec(e);)t.start=t.position,t.pattern=this,yield t}}[Symbol.clone](){return new RegExp(this.source,this.flags)}}RegExp.implements(e)})();Math.fillWith({modulo:(e,t)=>e-t*Math.floor(e/t)}),JSON.fillWith({decode(e){return JSON.parse(e,function(e,t){return null==t?new Reference:(t.constructor==Object&&(t=new Map(t)),t)}.bind(this))},encode:e=>JSON.stringify(e),to:"toJSON"});(()=>{class e{set getter(e){this.get=e}set setter(e){this.set=e}}this.Accessor=e})()}{let e=(()=>{let e=Symbol(),t=Symbol(),s=Symbol(),n=Symbol(),r=Symbol();class i{constructor(){this.name=null,this.resolver=null,this.phase="bottom-up",this.once=null,this.passive=null}set name(t){t=null!=t?t[String.to]():String.empty,this[e]=t}get name(){return this[e]}set resolver(e){e=null!=e?e[Function.to]():Function.empty,this[t]=e}get resolver(){return this[t]}set phase(e){this[s]=e}get phase(){return this[s]}set once(e){e=null!=e?e[Boolean.to]():Boolean.empty,this[n]=e}get once(){return this[n]}set passive(e){e=null!=e?e[Boolean.to]():Boolean.empty,this[r]=e}get passive(){return this[r]}addTo(e){e.addEventListener(this.name,this.resolver,{capture:"top-down"==this.phase,once:this.once,passive:this.passive})}removeFrom(e){e.removeEventListener(this.name,this.resolver,{capture:"top-down"==this.phase})}toJSON(){let e={};return e.name=this.name,e.resolver=this.resolver,e.phase=this.phase,e.once=this.once,e.passive=this.passive,e}}return this.When=i,i})();Node.implements(class{addTo(e){e.append(this)}removeFrom(e){this.remove()}}),String.implements(class{addTo(e){e.append(new Text(this))}removeFrom(e){throw new Error(`String#removeFrom ${this}`)}}),DOMTokenList.implements(class{includes(e){return this.contains(e)}clear(){return this.remove(...this),this}}),NamedNodeMap.implements(class{set(e,t,s){null==s&&(s=null);let n=document.createAttributeNS(s,e);return n.value=t,this.setNamedItemNS(n),this}get(e,t){null==t&&(t=null);let s=this.getNamedItemNS(t,e);if(s)return s.value}includes(e,t){return null==t&&(t=null),null!=this.get(e,t)}remove(e,t){return null==t&&(t=null),this.removeNamedItemNS(t,e),this}}),HTMLElement.implements(class{static create(e){return document.createElementNS("http://www.w3.org/1999/xhtml",e)}}),SVGElement.implements(class{static create(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}}),EventTarget.implements(class{[Symbol.add](e){e.addTo(this)}});{Object.setBaseOf(NodeList,Collection);let e=Symbol();NodeList.implements(class{add(t,s){return t=null!=t?t[Node.to]():Node.empty,null==s&&(s=this.size),this.size>s?this[s].before(t):this[e].append(t),this}clear(){for(let e of this)e.remove();return this}*[Sequence.to](){if(this[e]){let e,t=this[0];for(;t;)yield t,t=e=t.nextSibling}else for(let e of Integer.range(0,this.size))yield this[e]}}),Element.implements(class{set classes(e){String.isObjectModelOf(e)?this.classList.add(e):this.classList.add(...e)}get classes(){return this.classList}set nodes(e){e=null!=e?e[Node.to]():Node.empty,this.innerHTML="",this.append(e)}get nodes(){return this.childNodes[e]=this,this.childNodes}find(e){let t=this.querySelector(e);if(t)return t;throw new Fault.Miss}findAll(e){return this.querySelectorAll(e)}get path(){return function*(){{let e=this;for(;e;)yield e,e=e.parentNode}}.bind(this)()}});(()=>{class e{}Node.implements(class{[e.to](){return this}set parentNode(e){e&&e.append(this)}}),String.implements(class{[Node.to](){return new Text(this)}});let t=class{[Node.to](){let e=new DocumentFragment;for(let t of this)e.append(t[Node.to]());return e}};List.implements(t),Sequence.implements(t)})()}HTMLElement.implements(class{set style(e){for(let t of e){Sequence.isObjectModelOf(t)&&(t=t[List.to]());let e=t[Symbol.get]("name"),s=t[Symbol.get]("value");this.style.setProperty(e,s)}}set dataset(e){for(let t of e){Sequence.isObjectModelOf(t)&&(t=t[List.to]());let e=t[Symbol.get]("name"),s=t[Symbol.get]("value");this.dataset[e]=s}}set _focus(e){this.focus()}}),HTMLDocument.implements((()=>{return document.scripts.fillWith({add(e){return new Promise(function(t,s){HTMLElement.create("script").fillWith({source:e,load:t,error:s,parentNode:document.head})}.bind(this))}}),class{set icons(e){HTMLElement.create("link").fillWith({rel:"icon",source:e.source,type:e.type,sizes:e.sizes,parentNode:document.head})}get icons(){return document.head.findAll("link[rel~=icon]")}set baseAddress(e){HTMLElement.create("base").fillWith({href:e,parentNode:document.head})}get baseAddress(){return this.baseURI}}})());{let e=class{set source(e){e=null!=e?e[WebAddress.to]():WebAddress.empty,this.src=e}get source(){return this.src}};for(let t of(new List).fillWith({},[HTMLScriptElement,HTMLIFrameElement,HTMLImageElement,HTMLAudioElement,HTMLVideoElement]))t.implements(e);HTMLStyleElement.implements(class{set source(e){e=null!=e?e[WebAddress.to]():WebAddress.empty,this.attributes.set("src",e),this.textContent=`@import url("${e}");`}get source(){return this.attributes.get("src")}}),HTMLLinkElement.implements(class{set source(e){e=null!=e?e[WebAddress.to]():WebAddress.empty,this.href=e}get source(){return this.href}}),HTMLAnchorElement.implements(class{set destination(e){e=null!=e?e[WebAddress.to]():WebAddress.empty,this.href=e}get destination(){return this.href}})}URL.implements((()=>{let e=new URL("scheme:");return this.WebAddress=URL,String.implements(class{[WebAddress.to](e){return null==e&&(e=document.baseAddress),new URL(this,e)}}),class{get scheme(){return this.protocol.slice(0,-1)}revoke(){WebAddress.revokeObjectURL(this)}static get empty(){return e}}})()),Request.implements(class{fetch(){return fetch(this)}}),Headers.implements(class{[Symbol.add](e){this.set(e[0],e[1])}});(()=>{this.ObjectImage=Blob;class t{get body(){return new Promise(function(t,s){let n=(new FileReader).fillWith({},[(new e).fillWith({name:"load",resolver(){t(n.result)}}),(new e).fillWith({name:"error",resolver(){s(n.error)}})]);n.readAsArrayBuffer(this)}.bind(this))}saveAs(e){let t=HTMLElement.create("a").fillWith({download:e,href:this[WebAddress.to](),parentNode:document.head});t.click(),t.remove()}[WebAddress.to](){return new WebAddress(WebAddress.createObjectURL(this))}[ObjectImage.to](e){return e?new Blob(Array.of(this),{type:e}):this}}Blob.implements(t),Object.implements(class{[ObjectImage.to](e){return new Blob(Array.of(JSON.encode(this)),{type:e?`${e}+json`:"application/json"})}}),HTMLTemplateElement.implements(class{[ObjectImage.to](e){return new Blob(Array.of(this.innerHTML),{type:e})}})})();HTMLTemplateElement.implements(class{static from(e){(function(){}).bind(this)}resolve(e){}});let t=class{},s=class{};HTMLCanvasElement.implements(class{[t.to](e){return new Promise(function(t){this.toBlob(t,"image/jpeg",e)}.bind(this))}[s.to](){return new Promise(function(e){this.toBlob(e,"image/png")}.bind(this))}}),ArrayBuffer.implements((()=>{return class{[String.to](e,t,s){return e=null!=e?e[Integer.to]():Integer.empty,null==t&&(t=this.byteLength),null==s&&(s="utf-8"),new TextDecoder(s).decode(new Uint8Array(this,e,t))}}})()),Event.implements(class{get source(){return this.target}sendTo(e){return e.dispatchEvent(this)}stop(){this.preventDefault(),this.stopImmediatePropagation()}}),MessageEvent.implements(class{sendTo(e,t){null==t&&(t="*"),e.postMessage(this.data,t)}respondWith(e){this.source.postMessage(e.data,this.origin)}});{let e=function(){new Event("AnimationFrame").sendTo(document),requestAnimationFrame(e)}.bind(this);e()}this.DataTransferItemList&&this.BroadcastChannel&&(DataTransferItemList.implements((()=>{let t=new Set,s=function(e){"clear"==e.data?t.clear():t.add(e.data)}.bind(this),n=function(e){e.sendTo(r),s(e)}.bind(this),r=new BroadcastChannel("DragDrop#items").fillWith({message:s});window.fillWith({},[(new e).fillWith({name:"dragstart",resolver(e){let t=e.dataTransfer;Sequence.isObjectModelOf(t)&&(t=t[List.to]());let s=t[Symbol.get]("items");for(let e of Integer.range(s.length)){let t=s[e];"file"==t.kind&&(n(new MessageEvent("message",{data:t.getAsFile()})),s.remove(e))}}}),(new e).fillWith({name:"dragend",resolver(e){n(new MessageEvent("message",{data:"clear"}))}})]);return class{*[Sequence.to](){for(let e of Integer.range(0,this.length))yield this[e];for(let e of t)yield(new Object).fillWith({type:e.type,get:()=>e,kind:"file",getAsFile:()=>e})}}})()),DataTransferItem.implements((()=>{let e=(()=>{let e=Symbol();return class{constructor(){this.source=null}set source(t){this[e]=t}get source(){return this[e]}get type(){return"directory"}get name(){return this.source.name}toJSON(){let e={};return e.source=this.source,e}}})();return class{get(){try{let t=this.webkitGetAsEntry();return t.isFile?this.getAsFile():(new e).fillWith({source:t})}catch(e){return this.getAsFile()}}}})()));(()=>{let t=Symbol();class s{constructor(){this.rules=null}set rules(e){e=null!=e?e[List.to]():List.empty,this[t]=e}get rules(){return this[t]}addTo(t){let s=this;t.fillWith({},[(new e).fillWith({name:"dragover",resolver(e){if(!e.defaultPrevented)for(let t of e.dataTransfer.items)try{return e.dataTransfer.dropEffect=s.rules.find(function(e){return e.type==t.type}.bind(this)).effect,void e.preventDefault()}catch(e){}}}),(new e).fillWith({name:"drop",resolver(e){for(let t of e.dataTransfer.items)try{s.rules.find(function(e){return e.type==t.type}.bind(this)).action(t.getAsFile()),e.preventDefault()}catch(e){}}})])}toJSON(){let e={};return e.rules=this.rules,e}}this.DropZone=s})();if(Selection.implements((()=>{return HTMLDocument.implements(class{get selection(){return this.getSelection()}}),class{get size(){return this.rangeCount}add(e){return this.addRange(e)}[Symbol.add](e){this.add(e)}[Symbol.get](e){return this.getRangeAt(e)}remove(e){return this.removeRange(e)}clear(){return this.removeAllRanges(),this}*[Sequence.to](){for(let e of Integer.range(0,this.size))yield this.getRangeAt(e)}}})()),Range.implements(class{[Symbol.clone](){return this.cloneRange()}includes(e){return this.intersectsNode(e)}removeContents(){return this.extractContents()}replaceWith(e){this.removeContents();let t=this;Sequence.isObjectModelOf(t)&&(t=t[List.to]());let s=t[Symbol.get]("startContainer"),n=t[Symbol.get]("startOffset");Text.isObjectModelOf(s)?s.splitText(n).before(e):s.nodes[n].before(e)}addNode(e,t){}set startContainer(e){this.setStart(e,this.startPosition)}set startPosition(e){let t=this;Sequence.isObjectModelOf(t)&&(t=t[List.to]());let s=t[Symbol.get]("startContainer");-1==e&&(e=Text.isObjectModelOf(s)?s.data.size:s.nodes.size),this.setStart(s,e)}get startPosition(){return this.startOffset}set endContainer(e){this.setEnd(e,this.endPosition)}set endPosition(e){let t=this;Sequence.isObjectModelOf(t)&&(t=t[List.to]());let s=t[Symbol.get]("endContainer");-1==e&&(e=Text.isObjectModelOf(s)?s.data.size:s.nodes.size),this.setEnd(s,e)}get endPosition(){return this.endOffset}get isCollapsed(){return this.collapsed}set collapsePosition(e){this.startPosition=e,this.endPosition=e}set collapseContainer(e){this.startContainer=e,this.endContainer=e}}),Element.implements(class{get disabled(){return this.classes.includes("disabled")}set disabled(e){this.classes.toggle("disabled",e)}get active(){return this.classes.includes("active")}set active(e){this.classes.toggle("active",e)}}),Function.implements(class{throttle(e){null==e&&(e=250);let t,s=this;return function(){t&&t.stop(),t=s.bind(this,...arguments).schedule(e)}.bind(this)}}),RealNumber.implements(class{format(e,t){null==e&&(e=1e3),null==t&&(t=1e3);let s=this;return`${Math.round(s/Math.pow(t,s=(Math.log(s)/Math.log(t))[Integer.to]())*e)/e}${"\ufeffKMGTPEZY"[s]}`}toBytes(){return`${this.format(1e3,1024)}iB`}}),!this.visualViewport){let e=class{[Symbol.add](e){e.addTo(this)}get width(){return document.documentElement.offsetWidth}get height(){return document.documentElement.offsetHeight}addEventListener(){window.addEventListener(...arguments)}removeEventListener(){window.removeEventListener(...arguments)}};this.visualViewport=new e}}