From 45b1551760c2e87828460e09831f4175973f8f4a Mon Sep 17 00:00:00 2001 From: "A.Lepe" Date: Mon, 7 Mar 2022 13:16:59 +0900 Subject: [PATCH 01/27] 2.1.2 next() and prev() became posterior() and anterior() as "next" and "prev" are very common. --- dist/m2d2.alert.min.js | 4 ++-- dist/m2d2.bundle.min.js | 6 +++--- dist/m2d2.bundle.ws.min.js | 6 +++--- dist/m2d2.bundle.xhr.min.js | 6 +++--- dist/m2d2.lang.min.js | 4 ++-- dist/m2d2.min.js | 6 +++--- dist/m2d2.storage.min.js | 4 ++-- dist/m2d2.upload.min.js | 4 ++-- dist/m2d2.ws.min.js | 4 ++-- dist/m2d2.xhr.min.js | 4 ++-- dist/src/m2d2.alert.src.js | 4 ++-- dist/src/m2d2.all.src.js | 20 ++++++++------------ dist/src/m2d2.lang.src.js | 4 ++-- dist/src/m2d2.src.js | 20 ++++++++------------ dist/src/m2d2.storage.src.js | 4 ++-- dist/src/m2d2.upload.src.js | 4 ++-- dist/src/m2d2.ws.src.js | 4 ++-- dist/src/m2d2.xhr.src.js | 4 ++-- documentation/m2d2.md | 12 ++++++------ js/m2d2.src.js | 16 ++++++---------- package.json | 2 +- test/07_test_items.js | 8 ++++---- 22 files changed, 69 insertions(+), 81 deletions(-) diff --git a/dist/m2d2.alert.min.js b/dist/m2d2.alert.min.js index 71a0c17..7c75151 100644 --- a/dist/m2d2.alert.min.js +++ b/dist/m2d2.alert.min.js @@ -1,8 +1,8 @@ /** * Author : A.Lepe (dev@alepe.com) - intellisrc.com * License: MIT - * Version: 2.1.1 - * Updated: 2022-02-24 + * Version: 2.1.2 + * Updated: 2022-03-07 * Content: Extension */ diff --git a/dist/m2d2.bundle.min.js b/dist/m2d2.bundle.min.js index 089d57b..34be4d8 100644 --- a/dist/m2d2.bundle.min.js +++ b/dist/m2d2.bundle.min.js @@ -1,9 +1,9 @@ /** * Author : A.Lepe (dev@alepe.com) - intellisrc.com * License: MIT - * Version: 2.1.1 - * Updated: 2022-02-24 + * Version: 2.1.2 + * Updated: 2022-03-07 * Content: Full Bundle */ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.m2d2=t()}(this,(function(){"use strict";class e{isString(e){return"string"==typeof e}isBool(e){return"boolean"==typeof e}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isSelectorID(e){return 0===(e+"").trim().indexOf("#")}isPlainObject(e){return"Object"===e.constructor.name}isObject(e){return"object"==typeof e}isArray(e){return Array.isArray(e)}isFunction(e){return"function"==typeof e}isElement(e){return e instanceof HTMLElement}isNode(e){return e instanceof Node||e instanceof DocumentFragment}isHtml(e){return-1!==(e+"").trim().indexOf("<")}isEmpty(e){return void 0===e||this.isObject(e)&&0===Object.keys(e).length||""===e}isVisible(e){if(!this.isElement(e))return console.log("(isVisible) Not an element: "),console.log(e),!1;const t="none"!==e.style.display,s="hidden"!==e.style.visibility;return t&&s}inView(e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)&&t.width>0&&t.height>0}cleanArray(e){return e.filter((function(e){return 0===e||e}))}isValidElement(e){const t=this.newElement(e);return"template"!==e&&"HTMLUnknownElement"!==t.constructor.name}exists(e){return null!==document.querySelector(e)}getAttrOrProp(e,t){let s="";return this.hasAttrOrProp(e,t)&&(s=this.hasAttr(e,t)?e.getAttribute(t):e[t]),s}hasAttrOrProp(e,t){return this.hasAttr(e,t)||this.hasProp(e,t)}hasAttr(e,t){let s=!1;if(e&&!this.isNumeric(t))switch(t){case"checked":s=void 0!==e.type&&("radio"===e.type||"checkbox"===e.type);break;default:s=void 0!==e.hasAttribute&&e.hasAttribute(t)}return s}hasProp(e,t){let s=!1;if(e&&!this.isNumeric(t)){let n=void 0!==e[t];n&&null===e[t]&&"value"===t&&(n=!1),s=n&&!(e[t]instanceof Node)&&!e.hasAttribute(t)}return s}setPropOrAttr(e,t,s){if(this.hasProp(e,t))try{e[t]=s}catch(n){this.setAttr(e,t,s)}else this.setAttr(e,t,s)}setAttr(e,t,s){s?e.setAttribute(t,s):e.removeAttribute(t)}defineProp(e,t,s){this.isObject(e)&&void 0===e[t]&&(Object.defineProperty(e,t,{enumerable:!1,writable:!0}),e[t]=s)}htmlElement(e){const t=this.newElement("template");return t.innerHTML=e.trim(),t.content.firstChild}newElement(e){return document.createElement(e)}newEmptyNode(){return new DocumentFragment}getMethods(e){const t=Reflect.getPrototypeOf(e),s=Reflect.getPrototypeOf(t);return Reflect.ownKeys(t).filter(e=>Reflect.ownKeys(s).indexOf(e)<0)}appendAllChild(e,t){for(;e.firstChild;)t.append(e.firstChild)}prependAllChild(e,t){for(;e.firstChild;)t.prepend(e.firstChild)}}class t{"use strict";_stored={events:[],datasetNodes:[],datasets:[],styleNodes:[],styles:[]};static storedEventsTimeout=50;static short=!0;static updates=!0;static utils=new e;constructor(){}static instance=new t;static extensions={};static main=(()=>{const e=(e,s)=>{const n=this.instance.getProxyNode(e,s);return n&&n.onready&&t.utils.isFunction(n.onready)&&(n.addEventListener("ready",n.onready,{once:!0}),setTimeout(()=>{n.dispatchEvent(new CustomEvent("ready"))},10)),["dataset","style"].forEach(e=>{n&&n[e]&&(this.instance._stored[e+"s"].push(n[e]),this.instance._stored[e+"Nodes"].push(n))}),n};return t.utils.getMethods(t.utils).forEach(s=>{e[s]=t.utils[s]}),e})();static ready(e){document.addEventListener("DOMContentLoaded",()=>{e(t.main)})}static load(e){if(void 0!==e){const s=e(t.main);t.utils.isObject(s)&&!t.utils.isEmpty(s)&&Object.keys(s).forEach(e=>{if(t.utils.isValidElement(e)){void 0===t.extensions[e]&&(t.extensions[e]={});const n=t.utils.newElement(e);Object.keys(s[e]).forEach(s=>{t.utils.hasProp(n,s)&&console.log("Warning: property ["+s+"] already exists in node: ["+e+"] while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions[e],s[e])}else{void 0===t.extensions["*"]&&(t.extensions["*"]={});const n=t.utils.newElement("div");Object.keys(s[e]).forEach(e=>{t.utils.hasProp(n,e)&&console.log("Warning: property ["+e+"] already exists in Node while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions["*"],s[e])}})}return t.main}extDom(e,s){if(!e)return console.error("Selector was empty"),null;void 0===s&&(s=document);const n=t.utils.isNode(e)?e:s.querySelector(e);if(!n)return t.utils.isString(e)?(console.error("Selector: "+e+" didn't match any element in node:"),console.log(s)):console.error("Node was null"),null;if(void 0===n._m2d2){n._m2d2=!0,["parent","sibling","next","prev","find","findAll","onupdate","onready","show","onshow","inView","css","text","html","getData","index"].forEach(e=>{n.hasOwnProperty(e)&&(console.log("Node already had ["+e+"] property. It might cause unexpected behaviour."),console.log("You may need to update the M2D2 version or report it to: github.com/intellisrc/m2d2/"))}),Object.defineProperty(n,"text",{get(){return this.childNodes.length?this.innerText:this.textContent},set(e){if(this.childNodes.length){let t=!1;this.childNodes.forEach(s=>{"Text"===s.constructor.name&&(s.nodeValue=e,t=!0)}),t||this.prepend(document.createTextNode(e))}else this.textContent=e}}),Object.defineProperty(n,"html",{get(){return this.innerHTML},set(e){this.innerHTML=e}}),Object.defineProperty(n,"css",{get(){return this.classList},set(e){t.utils.isArray(e)?this.className=e.join(" "):t.utils.isString(e)?this.className=e:t.utils.isPlainObject(e)?Object.keys(e).forEach(t=>{e[t]?this.classList.add(t):this.classList.remove(t)}):console.error("Trying to assign a wrong value to css : "+e)}}),Object.defineProperty(n,"show",{get(){return t.utils.isVisible(this)},set(e){const s=()=>getComputedStyle(this,null).display,n=()=>{const e=document.getElementsByTagName("body")[0],t=document.createElement("template"),s=document.createElement(this.tagName);t.append(s),e.append(t);const n=getComputedStyle(s,null).display;return t.remove(),n};if(e){if("none"===s()){if(this._m2d2_display)this.style.display=this._m2d2_display;else if(this.style.removeProperty("display"),"none"===s()){const e=n();this.style.display=this.dataset.display||("none"!==e?e:"block")}void 0!==this.onshow&&t.utils.isFunction(this.onshow)&&this.onshow(this)}}else{const e="none"!==this.style.display?this.style.display:s();"none"!==e&&(this._m2d2_display=e),this.style.display="none"}}});let e={};return void 0!==t.extensions["*"]&&Object.assign(e,t.extensions["*"]),void 0!==t.extensions[n.tagName]&&Object.assign(e,t.extensions[n.tagName]),Object.assign(n,{inView:()=>t.utils.inView(n),next:()=>n.nextElementSibling,prev:()=>n.previousElementSibling,parent:()=>this.extDom(n.parentElement),sibling:e=>n.parentElement.find(e),find:e=>{const t=n.querySelector(e);return t?this.extDom(t):null},findAll:e=>{const t=void 0===e?Array.from(n.children):n.querySelectorAll(e);return t.forEach(e=>{this.extDom(e)}),t}},e),void 0===n.index&&(n.index=()=>Array.from(n.parentNode.children).indexOf(n)),["INPUT","TEXTAREA","SELECT"].indexOf(n.tagName)>=0&&t.utils.hasAttrOrProp(n,"value")&&(n.oninput=function(){this.setAttribute("value",this.value)}),"FORM"===n.tagName&&(n.getData=function(e){const t={},s=new FormData(this),o=e||!1;for(let e of s.entries()){const s=n.find("[name='"+e[0]+"']");(o||"hidden"===s.type||s.show)&&(t[e[0]]="file"===s.type?s.files:e[1])}return t}),n}return n}doDom(e,s){if(t.utils.isObject(e)&&void 0===s&&(s=e,e=t.utils.newEmptyNode(),void 0===s.warn&&(s.warn=!1)),!(t.utils.isString(e)||t.utils.isElement(e)||t.utils.isNode(e)))return console.error("Selector is not a string or a Node:"),console.log(e),null;if(t.utils.isString(e)&&!document.querySelector(e))return console.log("Selected element doesn't exists: "+e),null;const n=this.extDom(e);if(void 0===s)return n;if(s=this.plainToObject(n,s),Object.keys(s).filter(e=>!["tagName"].includes(e)).forEach(e=>{let o=s[e];null==o&&(console.log("Value was not set for key: "+e+", 'empty' was used in object: "),console.log(s),console.log("In node:"),console.log(n),o="");let i=this.updateValue(n,e,o),l=t.utils.hasProp(n,e),a=!1;if(t.utils.hasAttr(n,e)||l)switch(!0){case"value"===e&&t.utils.hasProp(n,"valueAsDate")&&i instanceof Date:e="valueAsDate";case"css"===e:case typeof i==typeof n[e]:case t.utils.isString(n[e])&&t.utils.isNumeric(i):case t.utils.isFunction(i)&&t.utils.isObject(n[e]):case t.utils.isBool(i)&&t.utils.isString(n[e]):case"object"==typeof n[e]&&"INPUT"===n.tagName:a=!0}if(a){let s=!1;switch(e){case"classList":t.utils.isArray(i)?i.forEach(t=>{n[e].add(t)}):t.utils.isString(i)?n[e].add(i):s=!0;break;case"style":case"dataset":t.utils.isPlainObject(i)?Object.keys(i).forEach(t=>{n[e][t]=this.updateValue(n[e],t,i[t])}):s=!0;break;default:switch(!0){case t.utils.isBool(i):case t.utils.hasAttrOrProp(n,e):t.utils.setPropOrAttr(n,e,i);break;default:n[e]=i}}s&&(console.error("Invalid value passed to '"+e+"': "),console.log(i),console.log("Into Node:"),console.log(n))}else{const l=[];try{if("template"!==e&&!t.utils.isFunction(i)){if(e&&e.match(/^\w/)){let t=n.find("#"+e);t&&-1===l.indexOf(t)&&l.push(t),t=n.find("[name='"+e+"']"),t&&-1===l.indexOf(t)&&l.push(t);const s=Array.from(n.findAll("."+e)).filter(e=>l.indexOf(e)<0);s.length>0&&s.forEach(e=>l.push(e))}const t=Array.from(n.findAll(e)).filter(e=>l.indexOf(e)<0);t.length>0&&t.forEach(e=>l.push(e))}}catch(t){return console.error("Invalid selector: "+e),void console.log(t)}if(l.length>1){const t=[];l.forEach(s=>{t.push(this.render(s,e,i))}),this.linkNode(n,e,t),void 0!==i.warn&&!1===i.warn||(console.log("Multiple elements were assigned with key: ["+e+"] under node: "),console.log(n),console.log("It might be what we expect, but if it is not expected it could result on some elements mistakenly rendered. You can specify 'warn : false' under that element to hide this message."))}else if(1===l.length){const a=l[0];if(t.utils.isElement(a)){const l=this.plainToObject(a,i),r=t.utils.isPlainObject(l)&&Object.keys(l).length>=1?Object.keys(l)[0]:null;if(r&&(i=this.updateValue(a,r,o)),t.utils.isArray(i)){const t=s.template;this.doItems(a,i,t),this.linkNode(n,e,a)}else this.renderAndLink(n,a,e,i)}else console.error("BUG: It should have been a node but got: "),console.log(a),console.log("Parent node:"),console.log(n)}else if(0===l.length){"template"===e&&void 0===s.items&&(e="items",i=[]);const o=t.utils.isFunction(i);if(void 0!==i.tagName){const t=this.appendElement(n,i.tagName);this.renderAndLink(n,t,e,i)}else if(t.utils.isValidElement(e)&&!o){const t=this.appendElement(n,e);this.renderAndLink(n,t,e,i)}else if("items"===e){const e=s.template;if(t.utils.isPlainObject(i)){const e=[];Object.keys(i).forEach(s=>{let o;"DL"===n.tagName?o={dt:s,dd:i[s]}:(o={text:i[s]},t.utils.hasAttrOrProp(n,"value")?o.value=s:o.dataset={id:s}),e.push(o)}),i=e}t.utils.isArray(i)?this.doItems(n,i,e):(console.log("Warning: 'items' specified but value is not and array, in element: "),console.log(n),console.log("Passed values are: "),console.log(i))}else o?(t.updates&&"onupdate"===e&&n.addEventListener("update",i,!0),n[e]=i):"template"!==e&&"warn"!==e&&!1!==i&&(void 0!==s.warn&&!1===s.warn||(console.error("Not sure what you want to do with key: "+e+" under element: "),console.log(n),console.log("And object:"),console.log(s),console.log("Most likely the element's property or child no longer exists or the value passed to it is incorrect."),console.log("You can set 'warn : false' property to the element to dismiss this message.")),n[e]=i)}}}),n.onload){const e=["BODY","FRAME","IFRAME","IMG","LINK","SCRIPT","STYLE"].indexOf(n.tagName)>=0,t="INPUT"===n.tagName&&"image"===n.type;e||t||n.dispatchEvent(new CustomEvent("load"))}return n}isUpdateLink(e){let s=!1;if(t.utils.isArray(e)&&(2===e.length||3===e.length)){const n=2===e.length,o=t.utils.isNode(e[0])||e[0]instanceof DOMStringMap||e[0]instanceof CSSStyleDeclaration,i=n?t.utils.isString(e[1]):t.utils.isString(e[1])&&t.utils.isFunction(e[2]);s=o&&i,s&&n&&e.push(e=>e)}return s}plainToObject(e,s){if(!t.utils.isPlainObject(s)&&!t.utils.isFunction(s)&&!t.utils.isElement(s))if(t.utils.isHtml(s))s={html:s};else if(this.isUpdateLink(s)){const n=s[0],o=s[1],i=s[2];let l=this.plainToObject(e,i(n[o]));if(t.utils.isPlainObject(l)){const e={};Object.keys(l).forEach(t=>{e[t]=s}),s=e}}else t.utils.isArray(s)?s={items:s}:t.utils.hasAttrOrProp(e,"value")?s="SELECT"===e.tagName?{value:s,text:s}:"BUTTON"===e.tagName?{text:s}:{value:s}:t.utils.isString(s)&&"IMG"===e.tagName?s={src:s}:(t.utils.isString(s)||t.utils.isNumeric(s))&&(s={text:s});return s}renderAndLink(e,t,s,n){const o=this.render(t,s,n);this.linkNode(e,s,o)}render(e,t,s){return s=this.plainToObject(e,s),this.doDom(e,s)}linkNode(e,s,n){if(e[s]===n){const t=this.proxy(n);try{e[s]=t}catch(e){}e["$"+s]=t}else t.utils.hasAttrOrProp(e,s)?(e["$"+s]=n,console.log("Property : "+s+" existed in node: "+e.tagName+". Using $"+s+" instead for node: "+n.tagName+".")):e[s]=this.proxy(n)}appendElement(e,s){const n=t.utils.newElement(s);return e.append(n),n}getItem(e,t,s,n){n||(n=this.getTemplate(e));const o=n.cloneNode(!0);this.addTemplatesToItem(n,o),o.dataset.id=t,this.setUniqueAttrib(o,"selected");let i=this.doDom(o,s);return this.getItemWithEvents(e,i)}addTemplatesToItem(e,t){["_template","__template"].forEach(s=>{void 0!==e[s]&&(t[s]=e[s])})}getItemWithEvents(e,s){if(void 0!==e.__template){const n=(e,s)=>(s=s||{},Object.keys(e).forEach(o=>{t.utils.isPlainObject(e[o])?s[o]=n(e[o]):t.utils.isFunction(e[o])&&(s[o]=e[o])}),s);let o=n(e.__template);t.utils.isEmpty(o)||(o=o[Object.keys(o)[0]],s=this.doDom(s,o))}return s}doItems(e,t,s){const n=this.getTemplate(e,s);if(void 0===n)return console.error("Template not found. Probably an array is being used where it is not expected. Node:"),console.log(e),console.log("Value (mistaken?):"),void console.log(t);let o=0;t.forEach(t=>{t=this.plainToObject(e,t);const s=this.getItem(e,o++,t,n);s&&e.append(s)});const i=e.find("template");i&&e.removeChild(i),e.items=e.children,this.extendItems(e)}getTemplate(e,s){if(void 0!==e._template&&""!==e._template)return e._template;{let n;const o=e.querySelector("template");if(o)n=t.utils.htmlElement(o.innerHTML.trim());else switch(e.tagName){case"SELECT":case"DATALIST":n=t.utils.newElement("option");break;case"UL":case"OL":n=t.utils.newElement("li");break;case"NAV":n=t.utils.newElement("a");break;case"DL":n=t.utils.newElement("dd");break;default:if(s){const o=Object.keys(s).length;if(o){if(o>1)if(void 0!==s.tagName){let e={};e[s.tagName]=s,s=e}else console.log("Template has more than one top elements. Using the first one. In: "),console.log(s),console.log("Node: "),console.log(e);const i=Object.keys(s)[0],l=s[i];t.utils.isValidElement(i)?n=t.utils.newElement(i):void 0!==l.tagName?(n=t.utils.newElement(l.tagName),s[l.tagName]=l,delete s[i]):(console.error("Template defined an element which can not be identified: ["+i+"], using in:"),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span"))}else console.error("Template has no definition, and it can not be guessed. Using . Template: "),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span")}else e.childElementCount>0&&(n=t.utils.htmlElement(e.innerHTML.trim()))}if(s)if(t.utils.isPlainObject(s)){const o=t.utils.newEmptyNode();o.append(n),n=this.doDom(o,s).children[0],t.utils.defineProp(e,"__template",s)}else n=t.utils.isHtml(s)?t.utils.htmlElement(s):t.utils.isSelectorID(s)?t.utils.htmlElement(document.querySelector(s).innerHTML):t.utils.newElement(s);if(n.childrenElementCount>1){console.log("Templates only supports a single child. Multiple children were detected, wrapping them with . Template:"),console.log(n);const e=t.utils.newElement("span");e.append(n),n=e}return n&&t.utils.defineProp(e,"_template",n),n}}setUniqueAttrib(e,s){e.hasOwnProperty(s)||Object.defineProperty(e,s,{get:function(){return this.hasAttribute(s)},set:function(e){const n=this.parentNode?this.parentNode.find("["+s+"]"):null;n&&n.removeAttribute(s),t.utils.setAttr(this,s,e)}})}updateValue(e,s,n){if(this.isUpdateLink(n)){const o=this,i=n[0],l=n[1],a=n[2];if(n=i[l],i instanceof CSSStyleDeclaration&&this._stored.styles.includes(i)){const n=this._stored.styleNodes[this._stored.styles.indexOf(i)];t.updates&&(n.onupdate=function(t){t.detail&&"style"===t.detail.property&&t.detail.newValue.startsWith(l+":")&&o.setShortValue(e,s,a(this.style[l]))})}else if(i instanceof DOMStringMap&&this._stored.datasets.includes(i)){const n=this._stored.datasetNodes[this._stored.datasets.indexOf(i)];t.updates&&(n.onupdate=t=>{t.detail&&t.detail.property==="data-"+l&&o.setShortValue(e,s,a(t.detail.newValue))})}else t.updates&&(i.onupdate=n=>{n.detail&&n.detail.property===l&&(t.utils.isObject(e[s])||o.setShortValue(e,s,a(n.detail.newValue)))})}return n}setShortValue(e,s,n){if(t.utils.isNode(e[s]))if(t.short){const o=this.plainToObject(e[s],n),i=t.utils.isPlainObject(o)&&Object.keys(o).length>=1?Object.keys(o)[0]:null;i&&(e[s][i]=n)}else console.log("Short is disabled. Trying to set a value ("+n+") in a node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else e[s]=n}getShortValue(e,s,n){let o=null;if(t.utils.isNode(e[s]))if(t.short){const i=this.plainToObject(e[s],n||""),l=t.utils.isPlainObject(i)&&Object.keys(i).length>=1?Object.keys(i)[0]:null;l&&(o=e[s][l])}else console.log("Short is disabled. Trying to get a value from node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else o=e[s];return o}proxy(e,s){return!t.short||null===e||void 0!==e._proxy&&void 0===s?e:(e._proxy=e,new Proxy(e,{get:(e,s)=>{const n=e[s];switch(!0){case null==n:return null;case t.utils.isFunction(n):return n.bind(e);case n._proxy&&void 0!==e["$"+s]:return e["$"+s];case void 0===n._proxy&&t.utils.isElement(n):return this.proxy(n);default:return n}},set:(e,s,n)=>{let o="";return t.utils.isElement(e[s])?(o=this.getShortValue(e,s,n),this.setShortValue(e,s,n)):"onupdate"===s?t.updates?t.utils.isFunction(n)?(e.addEventListener("update",n,!0),o=e[s],e[s]=n):(console.error("Value passed to 'onupdate' is incorrect, in node:"),console.log(e),console.log("Value: (not a function)"),console.log(n)):(console.log("Updates are not available when `m2d2.updates == false`:"),console.log(e)):"items"===s?(e.items.clear(),this.doItems(e,n)):(o=e[s],n=this.updateValue(e,s,n),e[s]=n),t.updates&&void 0!==e.onupdate&&n!==o&&e.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:s,newValue:n,oldValue:o}})),!0}}))}onObserve(e,s){e.forEach(e=>{const s=e.target;if(!(this._stored.events.indexOf(e)>=0)&&(this._stored.events.push(e),setTimeout(()=>{const t=this._stored.events.indexOf(e);t>=0&&this._stored.events.splice(t,1)},t.storedEventsTimeout),void 0!==s.onupdate))if("attributes"===e.type){const n=t.utils.getAttrOrProp(s,e.attributeName);n!==e.oldValue&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:e.attributeName,newValue:n,oldValue:e.oldValue}}))}else if("childList"===e.type)if("#text"===(e.addedNodes[0]||e.removedNodes[0]).nodeName){const t=e.addedNodes[0].textContent,n=e.removedNodes.length?e.removedNodes[0].textContent:null;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"text",newValue:t,oldValue:n}}))}else if(void 0!==s.items){const t=e.addedNodes,n=e.removedNodes;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"items",newValue:t,oldValue:n}}))}})}observe(e){if(t.updates){const t=new MutationObserver(this.onObserve.bind(this)),s={attributeOldValue:!0,subtree:!0,childList:!0},n=e._proxy||e;t.observe(n,s)}}getProxyNode(e,t){const s=this.doDom(e,t);if(s)return this.observe(s),this.proxy(s)}extendItems(e){function s(t){t.forEach(t=>{const s=t.parentNode.removeChild(t);e.append(s)})}const n=e.items;Object.getOwnPropertyNames(Array.prototype).concat(["clear","get","remove","selected","first","last","findAll"]).forEach(o=>{if(void 0===n[o]){let i=null;const l=this;switch(o){case"copyWithin":case"fill":case"splice":i=function(){console.log("Not available yet: "+o)};break;case"reverse":i=function(...e){if(this.items.length){const t=Array.from(this.items),n=t[o](...e);return s(t),n}};break;case"clear":i=function(){for(;this.items[0];)this.items[0].remove()};break;case"get":i=function(e){let s=null;return this.items.length&&this.items.some(n=>{const o=t.utils.isNumeric(e)?1*n.dataset.id==1*e:n.dataset.id===e;if(n.dataset&&o)return s=n,!0}),s};break;case"selected":i=function(){return l.proxy(this.find(":scope > [selected]"))};break;case"first":i=function(){return l.proxy(this.items[0])};break;case"last":i=function(){return l.proxy(this.items[this.items.length-1])};break;case"pop":i=function(){if(this.items.length){const e=this[0].parentNode;return l.proxy(e.removeChild(this.items[this.items.length-1]))}};break;case"push":i=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.append(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.appendChild(s)}else console.log("Trying to push an unknown value into a list:"),console.log(e)};break;case"remove":i=function(e){if(this.items.length){const t=this.items.get(e);1===t.length&&t.remove()}};break;case"shift":i=function(){if(this.items.length){const e=this.items[0].parentNode;return l.proxy(e.removeChild(this.items[0]))}};break;case"sort":i=function(e){if(this.items.length){const t=Array.from(this.items);t.sort(e||((e,t)=>e.text.localeCompare(t.text))),s(t)}};break;case"unshift":i=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.prepend(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.prepend(s)}else console.log("Trying to unshift an unknown value into a list:"),console.log(e)};break;default:let n=o;switch(!0){case"findAll"===o:n="filter";case t.utils.isFunction(Array.prototype[o]):const s=function(...t){const s=[];return Array.from(e.items).forEach(e=>{s.push(l.proxy(e))}),Array.from(s)[n](...t)};switch(o){case"find":i=function(...e){return t.utils.isString(e[0])?this.find(e[0]):s(...e)};break;case"findAll":i=function(...e){return 0===e.length?this.findAll():t.utils.isString(e[0])?this.findAll(e[0]):s(...e)};break;case"concat":i=function(...e){for(let s=0;s{function t(t){e.exists("#m2d2-alert .m2d2-alert-front")?(e("#m2d2-alert .m2d2-alert-front").css.add("vanish"),setTimeout(()=>{e.exists("#m2d2-alert .m2d2-alert-front")&&e("#m2d2-alert").remove(),t&&t()},400)):t&&t()}const s={wrap:!1,question:["fa","fa-question-circle"],info:["fa","fa-exclamation-circle"],error:["fa","fa-exclamation-triangle"],ok:["fa","fa-check"],input:["fa","fa-edit"],wait:["fa","fa-cog","fa-spin"]},n={wrap:"material-icons",question:"help",info:"info",error:"error",ok:"done",input:"edit",wait:"pending"},o={wrap:!1,question:"icon_question",info:"icon_info",error:"icon_error",ok:"icon_ok",input:"icon_input",wait:"icon_wait"};e.message=function(i){let l=o;switch(e.messageIcons){case"fa":l=s;break;case"material":l=n;break;default:e.isObject(e.messageIcons)&&(l=e.messageIcons)}i&&(e.isFunction(i.callback)||(i.callback&&!i.text&&(i.text=i.callback),i.callback=()=>{}),i.text||(i.text="")),t(()=>{e("body",{m2d2Alert:{tagName:"div",id:"m2d2-alert",back:{tagName:"div",css:"m2d2-alert-back",style:{position:"absolute",left:0,right:0,top:0,bottom:0,backgroundColor:"#0005",display:"flex",justifyContent:"center",alignItems:"center"},front:Object.assign({tagName:"form",css:(i.css?e.isArray(i.css)?i.css:[i.css]:[]).concat(["m2d2-alert-front","popup",i.icon]),style:{zIndex:100},icon:{tagName:"span",css:["icon",i.icon].concat(l.wrap?[l.wrap]:l[i.icon]).concat("wait"===i.icon?"spin":""),text:l.wrap?l[i.icon]:""},message:{tagName:"div",css:"m2d2-alert-title",span:i.title},submsg:(()=>{let t;return t="input"!==i.icon||i.text?e.isPlainObject(i.text)?{fieldset:Object.assign({css:"m2d2-alert-field"},i.text)}:{span:i.text.replace("\n","
")}:{fieldset:{css:"m2d2-alert-field",input:{type:"text",name:"answer",onload:function(){this.focus()}}}},Object.assign({tagName:"div",css:"m2d2-alert-text"},t)})(i.icon),onsubmit:function(){const e=this.getData();let s;switch(e.button){case"ok":case"yes":s=()=>{i.callback(!0,e)};break;case"no":s=()=>{i.callback(!1,e)};break;case"cancel":s=()=>{i.callback(null,e)};break;case"send":s=1===Object.keys(e).length?()=>{i.callback(e[Object.keys(e)[0]],e)}:2===Object.keys(e).length?()=>{i.callback(e[Object.keys(e).find(e=>"button"!==e)],e)}:()=>{i.callback(e,e)};break;default:s=()=>{i.callback(e,e)}}return t(s),!1},onload:function(){const e=this.find("[autofocus]");e&&e.focus()}},function(t){let s={};return t.length&&(s={buttons:{tagName:"div",css:"m2d2-alert-buttons"}},t.forEach(t=>{const n=t.toLowerCase().replace(/[^a-z ]/g,"").replace(" ","_");s.buttons[n]={tagName:"button",type:"submit",value:n,css:["color",n],text:void 0!==e.dict?e.dict(t):t,autofocus:["ok","yes"].includes(t),formNoValidate:["cancel"].includes(t),onclick:function(){e(this.closest("form"),{hide:{tagName:"input",type:"hidden",name:"button",value:this.value}})}}})),s}(i.buttons))}}})});let a=1;return e("#m2d2-alert .m2d2-alert-front").findAll("input, select, textarea").forEach(e=>{""===e.name&&(e.name="field_"+a++)}),{close:t}},e.wait=(t,s,n)=>e.message({icon:"wait",title:t,buttons:[],text:void 0===n?null:s,callback:void 0===n?s:n}),e.alert=(t,s,n)=>e.message({icon:"info",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.success=(t,s,n)=>e.message({icon:"ok",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.failure=(t,s,n)=>e.message({icon:"error",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.confirm=(t,s,n)=>e.message({icon:"question",title:t,buttons:["yes","no"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.prompt=(t,s,n)=>e.message({icon:"input",title:t,buttons:["cancel","send"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.closeAll=()=>{t()}}),t.load(e=>{let t=localStorage.getItem("m2d2.lang")||navigator.language;e.dict=new function(t){const s=function(e,t){if(void 0===e)return"";let n=s.val(e,!0);if(void 0!==t){if("string"==typeof t&&""!==t){const e=(t=t.replace(/;$/,"")).split(";");t={},e.forEach(s=>{const n=e[s].split(":");t[n[0]]=n[1]})}"object"==typeof t&&t.forEach(e=>{let o=t[e]+"";o=s.val(o,!1),n=n.replace(e,o)})}return n};return s.lang=t||"en",s.data={},s.set=function(e){return this.data=e,this},s.has=function(e,t){return void 0===t?void 0!==this.data[e]:void 0!==this.data[e][t]},s.val=function(t,n){if(e.isEmpty(s.data))return console.error("Dictionary is empty. You need to add a dictionary, for example: `$.dict.set({\nsave : { en : 'Save', es : 'Guardar' },\ncancel : { en : 'Cancel', es : 'Cancelar' }\nyes : { en : 'Yes', es : 'Si' },\nno : { en : 'No', es : 'No' }\n})`"),"";if(!t)return console.error("No keyword specified."),"";let o=t;if(void 0===n&&(n=!1),t=t.toLowerCase(),this.has(t)){const e=this.lang.split("-")[0];this.has(t,this.lang)?o=this.data[t][this.lang]:this.has(t,e)?o=this.data[t][e]:n&&console.log("Missing translation for lang ["+this.lang+"]: "+t)}else n&&console.log("Missing keyword: "+t);return o},s}(t);const s=[];e.lang=function(t){t&&(e.dict.lang=t,localStorage.setItem("m2d2.lang",e.dict.lang)),e("body").findAll("[lang]").forEach(t=>{let s=t.text;if(s&&!t.classList.contains("notxt")){void 0===t.dataset.kw&&(t.dataset.kw=e.lang.getKeyword(s)),t.text=e.dict(t.dataset.kw);const n=t.dataset.kw+"_title";let o=e.dict.has(n)?e.dict(n):"";o&&(t.title=o)}else if(t.title){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.title)),s=e.dict(t.dataset.kw),s&&(t.title=s)}else if(t.placeholder){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.placeholder)),s=e.dict(t.dataset.kw),s&&(t.placeholder=s)}else if(t.value){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.value)),s=e.dict(t.dataset.kw),s&&(t.value=s)}}),s.forEach(e=>{e(t)})},e.lang.getKeyword=function(e){return e.toLowerCase().trim().replace(/ /g,"_").replace(/[^\w]/g,"").replace(/_$/,"")},Object.defineProperty(e.lang,"onchange",{get(){return this},set(t){e.isFunction(t)?s.push(t):(console.log("Unable to set lang.onchange, because it is not a function: "),console.log(t))}})}),t.ready(e=>{const t=localStorage.getItem("m2d2.lang")||"",s=e("body").find("[lang]"),n=e("html").lang||(s?s.lang:null)||"en";(t?n!==t:n!==navigator.language.split("-")[0])&&e.lang()}),t.load(e=>{function t(e){switch(e){case"local":window.localStorage&&(this.store=localStorage);break;case"session":window.sessionStorage&&(this.store=sessionStorage)}null==this.store&&(this.store=localStorage),this.set=function(e,t){"string"==typeof t&&(t={$:t}),this.store.setItem(e,JSON.stringify(t))},this.get=function(e){let t;try{t=JSON.parse(this.store.getItem(e))||{}}catch(s){t=this.store.getItem(e)}return void 0!==t.$?t=t.$:0===Object.keys(t).length&&t.constructor===Object&&(t=null),t},this.del=function(e){this.store.removeItem(e)},this.keys=function(){return Object.keys(this.store).sort()},this.clear=function(){this.store.clear()},this.exists=function(e){return this.store.hasOwnProperty(e)},this.log=function(e,t,s){null==s&&(s=10);const n=this.get(e)||[];for(n.push(t);n.length>s;)n.shift();this.set(e,n)}}e.local=new t("local"),e.session=new t("session")}),t.load(e=>{function t(e,t,s){const n=[];return e=e||{},t.forEach(o=>{const i="Array"==typeof e?e.length==t.length?e[s]:e:void 0!==e[o.name]?e[o.name]:e;n.push({file:o,data:i,index:s++})}),n}function s(e,t,s,n,o){const i=new XMLHttpRequest;t=Array.from(t),i.upload.addEventListener("progress",(function(e){if(e.lengthComputable)if(n.oneByOne){const o=Math.round(100*e.loaded/e.total);n.onUpdate(o,t[0],s)}else{let s=0,o=0;t.some(t=>{s+=t.size;const i=e.loaded>=s?100:100-Math.round(100*(s-e.loaded)/t.size);return n.onUpdate(i,t,o++),s>=e.loaded})}}),!1),i.addEventListener("load",(function(e){let l={};try{l=i.responseText?JSON.parse(i.responseText):{error:{type:"Unknown",reason:"Unknown Error"}}}catch(e){l.error={type:"Parse Error",reason:e.message}}i.status>=200&&i.status<400?o(n.onResponse(l),t,s):("string"==typeof l.error&&(l.error={type:"Exception",reason:l.error}),n.onError(l.error))}),!1),i.open("POST",n.upload);const l=Array(t.length).fill(!1),a=function(e,t){const s=new FormData;return t.forEach(t=>{s.append(e,t,t.name)}),s}(e,t);let r=0;t.forEach(e=>{const t=new FileReader;t.onload=function(e){l[r++]=!0,-1===l.indexOf(!1)&&i.send(a)},t.readAsBinaryString(e)})}e.upload=function(e,n){const o=Object.assign({},{accept:"*/*",parallel:!1,field:"file",multiple:!0,maxFiles:0,maxSizeMb:0},n);n=null;let i=window._protected_reference=document.createElement("INPUT");i.name=o.field,i.type="file",1==o.multiple&&(i.multiple="multiple"),o.upload||(console.log("Upload not specified. Using current page."),o.upload=""),null==o.onDone&&(o.onDone=(e,t)=>{console.log(e)}),null==o.onError&&(o.onError=e=>{console.log("Error : "),console.log(e)}),null==o.onUpdate&&(o.onUpdate=(e,t,s)=>{console.log("Uploading : "+e+"% "+(o.oneByOne?"[ "+t.name+" ]":""))}),null==o.onResponse&&(o.onResponse=e=>e),i.addEventListener("change",()=>{if(i.files.length){if(!(0===o.maxFiles|i.files.length<=o.maxFiles))return o.onError("Max file limit exceeded. Maximum files: "+o.maxFiles),!1;if(o.onSelect){const e=[];let t=0;Array.from(i.files).forEach(s=>{e.push(URL.createObjectURL(s)),t+=s.size});const s=t/1048576;if(o.maxSizeMb&&s>o.maxSizeMb)return o.onError("Maximum size exceeded: "+Math.ceil(s)+"MB > "+o.maxSizeMb+"MB"),!1;o.onSelect(i.files,e)}new Promise(e=>{if(o.oneByOne){let n=0;const l=Array(i.files.length).fill(!1);Array.from(i.files).forEach(a=>{new s(i.name,[a],n++,o,(s,n,i)=>{l[i]=!0;const a=-1===l.indexOf(!1);o.onDone(t(s,n,i),a),a&&e()})})}else new s(i.name,i.files,0,o,(s,n,i)=>{o.onDone(t(s,n,i),!0),e()})}).then(()=>{i=window._protected_reference=void 0})}}),i.click()}}),t.load(e=>{e.ws=new class{request(e){if(e)try{this.webSocket.send(JSON.stringify(e))}catch(e){this.webSocket.onerror(e)}}getSocket(e,t,s){const n=new WebSocket(this.path);return n.onopen=t,n.onclose=s,n.onmessage=t=>{if(t.data)try{e(JSON.parse(t.data))}catch(e){n.onerror(e)}},n.onerror=e=>{console.error("Socket encountered error: ",e?e.message:"Unknown","Closing socket");const t=n||this;1===t.readyState&&t.close()},n}connect(e,t){this.initRequest=e.request||null,this.onConnect=e.connected||(()=>{}),this.onDisconnect=e.disconnected||(()=>{}),this.reconnect=!1!==e.reconnect,this.host=e.host||window.location.hostname,this.secure=!0===e.secure,this.port=e.port||(this.secure?443:80),this.path="ws"+(this.secure?"s":"")+"://"+this.host+":"+this.port+"/"+(e.path||""),this.connected=!1,this.interval=null;const s=e=>{this.connected=!0,this.request(this.initRequest),this.onConnect()},n=e=>{this.connected=!1,this.onDisconnect(),!this.interval&&this.reconnect&&(this.interval=setInterval(()=>{if(this.connected)console.log("Reconnected..."),clearInterval(this.interval),this.interval=null;else try{this.webSocket.close(),console.log("Reconnecting..."),this.webSocket=this.getSocket(t,s,n)}catch(e){}},2e3))};this.webSocket=this.getSocket(t,s,n)}disconnect(){this.reconnect=!1,this.webSocket.close()}}}),t.load(e=>{const t=function(e,t,s,n,o,i){const l=new XMLHttpRequest;if(void 0===i&&(i=!1),void 0===o&&(o=function(e){console.log(e)}),s&&0===Object.entries(s).length&&(s=""),s)if(i)s=JSON.stringify(s);else switch(e.toUpperCase()){case"GET":t+=(-1!==t.indexOf("?")?"&":"?")+Object.keys(s).map(e=>e+"="+s[e]).join("&"),s="";break;default:s=Object.keys(s).map(e=>e+"="+s[e]).join("&")}return l.open(e,t,!0),i?l.setRequestHeader("Content-Type","application/json"):l.setRequestHeader("Content-type","application/x-www-form-urlencoded"),l.onerror=function(e){o({type:"Connection",reason:"Connection Refused"})},l.onload=function(){let e={};try{e=l.responseText?JSON.parse(l.responseText):{error:{type:"Unknown",reason:"Unknown Error"}}}catch(t){e.error={type:"Parse Error",reason:t.message}}l.status>=200&&l.status<400?void 0!==n&&n(e):void 0!==o&&("string"==typeof e.error&&(e.error={type:"Exception",reason:e.error}),o(e.error))},l.send(s),l},s={};["get","post","put","delete","connect","options","trace","patch"].forEach((function(e){s[e]=function(){let s,n,o,i,l;switch(arguments.length){case 5:"boolean"==typeof arguments[4]?l=arguments[4]:console.log("Passed JSON argument: "+arguments[4]+" is not boolean.");case 4:"function"==typeof arguments[3]?i=arguments[3]:4===arguments.length&&"boolean"==typeof arguments[3]?l=arguments[3]:console.log("Passed argument 4: "+arguments[3]+" is mistaken");case 3:"function"==typeof arguments[2]?"function"==typeof arguments[1]&&arguments.length<5?i=arguments[2]:o=arguments[2]:3===arguments.length&&"boolean"==typeof arguments[2]?l=arguments[2]:console.log("Passed argument 3: "+arguments[2]+" is mistaken");case 2:"object"==typeof arguments[1]||"string"==typeof arguments[1]?n=arguments[1]:"function"==typeof arguments[1]?o=arguments[1]:console.log("Passed argument 2: "+arguments[1]+" is mistaken");case 1:"string"==typeof arguments[0]?s=arguments[0]:Array.isArray(arguments[0])?s=arguments[0].join("/"):console.log("Passed URL: "+arguments[0]+" was not a string.");break;default:console.log("Incorrect number of arguments passed to xhr")}return void 0===n&&(n={}),t(e.toUpperCase(),s,n,o,i,l)}})),Object.assign(e,s)}),t})); \ No newline at end of file +!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.m2d2=t()}(this,(function(){"use strict";class e{isString(e){return"string"==typeof e}isBool(e){return"boolean"==typeof e}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isSelectorID(e){return 0===(e+"").trim().indexOf("#")}isPlainObject(e){return"Object"===e.constructor.name}isObject(e){return"object"==typeof e}isArray(e){return Array.isArray(e)}isFunction(e){return"function"==typeof e}isElement(e){return e instanceof HTMLElement}isNode(e){return e instanceof Node||e instanceof DocumentFragment}isHtml(e){return-1!==(e+"").trim().indexOf("<")}isEmpty(e){return void 0===e||this.isObject(e)&&0===Object.keys(e).length||""===e}isVisible(e){if(!this.isElement(e))return console.log("(isVisible) Not an element: "),console.log(e),!1;const t="none"!==e.style.display,s="hidden"!==e.style.visibility;return t&&s}inView(e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)&&t.width>0&&t.height>0}cleanArray(e){return e.filter((function(e){return 0===e||e}))}isValidElement(e){const t=this.newElement(e);return"template"!==e&&"HTMLUnknownElement"!==t.constructor.name}exists(e){return null!==document.querySelector(e)}getAttrOrProp(e,t){let s="";return this.hasAttrOrProp(e,t)&&(s=this.hasAttr(e,t)?e.getAttribute(t):e[t]),s}hasAttrOrProp(e,t){return this.hasAttr(e,t)||this.hasProp(e,t)}hasAttr(e,t){let s=!1;if(e&&!this.isNumeric(t))switch(t){case"checked":s=void 0!==e.type&&("radio"===e.type||"checkbox"===e.type);break;default:s=void 0!==e.hasAttribute&&e.hasAttribute(t)}return s}hasProp(e,t){let s=!1;if(e&&!this.isNumeric(t)){let n=void 0!==e[t];n&&null===e[t]&&"value"===t&&(n=!1),s=n&&!(e[t]instanceof Node)&&!e.hasAttribute(t)}return s}setPropOrAttr(e,t,s){if(this.hasProp(e,t))try{e[t]=s}catch(n){this.setAttr(e,t,s)}else this.setAttr(e,t,s)}setAttr(e,t,s){s?e.setAttribute(t,s):e.removeAttribute(t)}defineProp(e,t,s){this.isObject(e)&&void 0===e[t]&&(Object.defineProperty(e,t,{enumerable:!1,writable:!0}),e[t]=s)}htmlElement(e){const t=this.newElement("template");return t.innerHTML=e.trim(),t.content.firstChild}newElement(e){return document.createElement(e)}newEmptyNode(){return new DocumentFragment}getMethods(e){const t=Reflect.getPrototypeOf(e),s=Reflect.getPrototypeOf(t);return Reflect.ownKeys(t).filter(e=>Reflect.ownKeys(s).indexOf(e)<0)}appendAllChild(e,t){for(;e.firstChild;)t.append(e.firstChild)}prependAllChild(e,t){for(;e.firstChild;)t.prepend(e.firstChild)}}class t{"use strict";_stored={events:[],datasetNodes:[],datasets:[],styleNodes:[],styles:[]};static storedEventsTimeout=50;static short=!0;static updates=!0;static utils=new e;constructor(){}static instance=new t;static extensions={};static main=(()=>{const e=(e,s)=>{const n=this.instance.getProxyNode(e,s);return n&&n.onready&&t.utils.isFunction(n.onready)&&(n.addEventListener("ready",n.onready,{once:!0}),setTimeout(()=>{n.dispatchEvent(new CustomEvent("ready"))},10)),["dataset","style"].forEach(e=>{n&&n[e]&&(this.instance._stored[e+"s"].push(n[e]),this.instance._stored[e+"Nodes"].push(n))}),n};return t.utils.getMethods(t.utils).forEach(s=>{e[s]=t.utils[s]}),e})();static ready(e){document.addEventListener("DOMContentLoaded",()=>{e(t.main)})}static load(e){if(void 0!==e){const s=e(t.main);t.utils.isObject(s)&&!t.utils.isEmpty(s)&&Object.keys(s).forEach(e=>{if(t.utils.isValidElement(e)){void 0===t.extensions[e]&&(t.extensions[e]={});const n=t.utils.newElement(e);Object.keys(s[e]).forEach(s=>{t.utils.hasProp(n,s)&&console.log("Warning: property ["+s+"] already exists in node: ["+e+"] while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions[e],s[e])}else{void 0===t.extensions["*"]&&(t.extensions["*"]={});const n=t.utils.newElement("div");Object.keys(s[e]).forEach(e=>{t.utils.hasProp(n,e)&&console.log("Warning: property ["+e+"] already exists in Node while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions["*"],s[e])}})}return t.main}extDom(e,s){if(!e)return console.error("Selector was empty"),null;void 0===s&&(s=document);const n=t.utils.isNode(e)?e:s.querySelector(e);if(!n)return t.utils.isString(e)?(console.error("Selector: "+e+" didn't match any element in node:"),console.log(s)):console.error("Node was null"),null;if(void 0===n._m2d2){n._m2d2=!0,["parent","sibling","posterior","anterior","find","findAll","onupdate","onready","show","onshow","inView","css","text","html","getData","index"].forEach(e=>{n.hasOwnProperty(e)&&(console.log("Node already had ["+e+"] property. It might cause unexpected behaviour."),console.log("You may need to update the M2D2 version or report it to: github.com/intellisrc/m2d2/"))}),Object.defineProperty(n,"text",{get(){return this.childNodes.length?this.innerText:this.textContent},set(e){if(this.childNodes.length){let t=!1;this.childNodes.forEach(s=>{"Text"===s.constructor.name&&(s.nodeValue=e,t=!0)}),t||this.prepend(document.createTextNode(e))}else this.textContent=e}}),Object.defineProperty(n,"html",{get(){return this.innerHTML},set(e){this.innerHTML=e}}),Object.defineProperty(n,"css",{get(){return this.classList},set(e){t.utils.isArray(e)?this.className=e.join(" "):t.utils.isString(e)?this.className=e:t.utils.isPlainObject(e)?Object.keys(e).forEach(t=>{e[t]?this.classList.add(t):this.classList.remove(t)}):console.error("Trying to assign a wrong value to css : "+e)}}),Object.defineProperty(n,"show",{get(){return t.utils.isVisible(this)},set(e){const s=()=>getComputedStyle(this,null).display,n=()=>{const e=document.getElementsByTagName("body")[0],t=document.createElement("template"),s=document.createElement(this.tagName);t.append(s),e.append(t);const n=getComputedStyle(s,null).display;return t.remove(),n};if(e){if("none"===s()){if(this._m2d2_display)this.style.display=this._m2d2_display;else if(this.style.removeProperty("display"),"none"===s()){const e=n();this.style.display=this.dataset.display||("none"!==e?e:"block")}void 0!==this.onshow&&t.utils.isFunction(this.onshow)&&this.onshow(this)}}else{const e="none"!==this.style.display?this.style.display:s();"none"!==e&&(this._m2d2_display=e),this.style.display="none"}}});let e={};return void 0!==t.extensions["*"]&&Object.assign(e,t.extensions["*"]),void 0!==t.extensions[n.tagName]&&Object.assign(e,t.extensions[n.tagName]),Object.assign(n,{inView:()=>t.utils.inView(n),posterior:()=>n.nextElementSibling,anterior:()=>n.previousElementSibling,parent:()=>this.extDom(n.parentElement),sibling:e=>n.parentElement.find(e),find:e=>{const t=n.querySelector(e);return t?this.extDom(t):null},findAll:e=>{const t=void 0===e?Array.from(n.children):n.querySelectorAll(e);return t.forEach(e=>{this.extDom(e)}),t}},e),void 0===n.index&&(n.index=()=>Array.from(n.parentNode.children).indexOf(n)),["INPUT","TEXTAREA","SELECT"].indexOf(n.tagName)>=0&&t.utils.hasAttrOrProp(n,"value")&&(n.oninput=function(){this.setAttribute("value",this.value)}),"FORM"===n.tagName&&(n.getData=function(e){const t={},s=new FormData(this),o=e||!1;for(let e of s.entries()){const s=n.find("[name='"+e[0]+"']");(o||"hidden"===s.type||s.show)&&(t[e[0]]="file"===s.type?s.files:e[1])}return t}),n}return n}doDom(e,s){if(t.utils.isObject(e)&&void 0===s&&(s=e,e=t.utils.newEmptyNode(),void 0===s.warn&&(s.warn=!1)),!(t.utils.isString(e)||t.utils.isElement(e)||t.utils.isNode(e)))return console.error("Selector is not a string or a Node:"),console.log(e),null;if(t.utils.isString(e)&&!document.querySelector(e))return console.log("Selected element doesn't exists: "+e),null;const n=this.extDom(e);if(void 0===s)return n;if(s=this.plainToObject(n,s),Object.keys(s).filter(e=>!["tagName"].includes(e)).forEach(e=>{let o=s[e];null==o&&(console.log("Value was not set for key: "+e+", 'empty' was used in object: "),console.log(s),console.log("In node:"),console.log(n),o="");let i=this.updateValue(n,e,o),l=t.utils.hasProp(n,e),r=!1;if(t.utils.hasAttr(n,e)||l)switch(!0){case"value"===e&&t.utils.hasProp(n,"valueAsDate")&&i instanceof Date:e="valueAsDate";case"css"===e:case typeof i==typeof n[e]:case t.utils.isString(n[e])&&t.utils.isNumeric(i):case t.utils.isFunction(i)&&t.utils.isObject(n[e]):case t.utils.isBool(i)&&t.utils.isString(n[e]):case"object"==typeof n[e]&&"INPUT"===n.tagName:r=!0}if(r){let s=!1;switch(e){case"classList":t.utils.isArray(i)?i.forEach(t=>{n[e].add(t)}):t.utils.isString(i)?n[e].add(i):s=!0;break;case"style":case"dataset":t.utils.isPlainObject(i)?Object.keys(i).forEach(t=>{n[e][t]=this.updateValue(n[e],t,i[t])}):s=!0;break;default:switch(!0){case t.utils.isBool(i):case t.utils.hasAttrOrProp(n,e):t.utils.setPropOrAttr(n,e,i);break;default:n[e]=i}}s&&(console.error("Invalid value passed to '"+e+"': "),console.log(i),console.log("Into Node:"),console.log(n))}else{const l=[];try{if("template"!==e&&!t.utils.isFunction(i)){if(e&&e.match(/^\w/)){let t=n.find("#"+e);t&&-1===l.indexOf(t)&&l.push(t),t=n.find("[name='"+e+"']"),t&&-1===l.indexOf(t)&&l.push(t);const s=Array.from(n.findAll("."+e)).filter(e=>l.indexOf(e)<0);s.length>0&&s.forEach(e=>l.push(e))}const t=Array.from(n.findAll(e)).filter(e=>l.indexOf(e)<0);t.length>0&&t.forEach(e=>l.push(e))}}catch(t){return console.error("Invalid selector: "+e),void console.log(t)}if(l.length>1){const t=[];l.forEach(s=>{t.push(this.render(s,e,i))}),this.linkNode(n,e,t),void 0!==i.warn&&!1===i.warn||(console.log("Multiple elements were assigned with key: ["+e+"] under node: "),console.log(n),console.log("It might be what we expect, but if it is not expected it could result on some elements mistakenly rendered. You can specify 'warn : false' under that element to hide this message."))}else if(1===l.length){const r=l[0];if(t.utils.isElement(r)){const l=this.plainToObject(r,i),a=t.utils.isPlainObject(l)&&Object.keys(l).length>=1?Object.keys(l)[0]:null;if(a&&(i=this.updateValue(r,a,o)),t.utils.isArray(i)){const t=s.template;this.doItems(r,i,t),this.linkNode(n,e,r)}else this.renderAndLink(n,r,e,i)}else console.error("BUG: It should have been a node but got: "),console.log(r),console.log("Parent node:"),console.log(n)}else if(0===l.length){"template"===e&&void 0===s.items&&(e="items",i=[]);const o=t.utils.isFunction(i);if(void 0!==i.tagName){const t=this.appendElement(n,i.tagName);this.renderAndLink(n,t,e,i)}else if(t.utils.isValidElement(e)&&!o){const t=this.appendElement(n,e);this.renderAndLink(n,t,e,i)}else if("items"===e){const e=s.template;if(t.utils.isPlainObject(i)){const e=[];Object.keys(i).forEach(s=>{let o;"DL"===n.tagName?o={dt:s,dd:i[s]}:(o={text:i[s]},t.utils.hasAttrOrProp(n,"value")?o.value=s:o.dataset={id:s}),e.push(o)}),i=e}t.utils.isArray(i)?this.doItems(n,i,e):(console.log("Warning: 'items' specified but value is not and array, in element: "),console.log(n),console.log("Passed values are: "),console.log(i))}else o?(t.updates&&"onupdate"===e&&n.addEventListener("update",i,!0),n[e]=i):"template"!==e&&"warn"!==e&&!1!==i&&(void 0!==s.warn&&!1===s.warn||(console.error("Not sure what you want to do with key: "+e+" under element: "),console.log(n),console.log("And object:"),console.log(s),console.log("Most likely the element's property or child no longer exists or the value passed to it is incorrect."),console.log("You can set 'warn : false' property to the element to dismiss this message.")),n[e]=i)}}}),n.onload){const e=["BODY","FRAME","IFRAME","IMG","LINK","SCRIPT","STYLE"].indexOf(n.tagName)>=0,t="INPUT"===n.tagName&&"image"===n.type;e||t||n.dispatchEvent(new CustomEvent("load"))}return n}isUpdateLink(e){let s=!1;if(t.utils.isArray(e)&&(2===e.length||3===e.length)){const n=2===e.length,o=t.utils.isNode(e[0])||e[0]instanceof DOMStringMap||e[0]instanceof CSSStyleDeclaration,i=n?t.utils.isString(e[1]):t.utils.isString(e[1])&&t.utils.isFunction(e[2]);s=o&&i,s&&n&&e.push(e=>e)}return s}plainToObject(e,s){if(!t.utils.isPlainObject(s)&&!t.utils.isFunction(s)&&!t.utils.isElement(s))if(t.utils.isHtml(s))s={html:s};else if(this.isUpdateLink(s)){const n=s[0],o=s[1],i=s[2];let l=this.plainToObject(e,i(n[o]));if(t.utils.isPlainObject(l)){const e={};Object.keys(l).forEach(t=>{e[t]=s}),s=e}}else t.utils.isArray(s)?s={items:s}:t.utils.hasAttrOrProp(e,"value")?s="SELECT"===e.tagName?{value:s,text:s}:"BUTTON"===e.tagName?{text:s}:{value:s}:t.utils.isString(s)&&"IMG"===e.tagName?s={src:s}:(t.utils.isString(s)||t.utils.isNumeric(s))&&(s={text:s});return s}renderAndLink(e,t,s,n){const o=this.render(t,s,n);this.linkNode(e,s,o)}render(e,t,s){return s=this.plainToObject(e,s),this.doDom(e,s)}linkNode(e,s,n){if(e[s]===n){const t=this.proxy(n);try{e[s]=t}catch(e){}e["$"+s]=t}else t.utils.hasAttrOrProp(e,s)?(e["$"+s]=n,console.log("Property : "+s+" existed in node: "+e.tagName+". Using $"+s+" instead for node: "+n.tagName+".")):e[s]=this.proxy(n)}appendElement(e,s){const n=t.utils.newElement(s);return e.append(n),n}getItem(e,t,s,n){n||(n=this.getTemplate(e));const o=n.cloneNode(!0);this.addTemplatesToItem(n,o),o.dataset.id=t,this.setUniqueAttrib(o,"selected");let i=this.doDom(o,s);return this.getItemWithEvents(e,i)}addTemplatesToItem(e,t){["_template","__template"].forEach(s=>{void 0!==e[s]&&(t[s]=e[s])})}getItemWithEvents(e,s){if(void 0!==e.__template){const n=(e,s)=>(s=s||{},Object.keys(e).forEach(o=>{t.utils.isPlainObject(e[o])?s[o]=n(e[o]):t.utils.isFunction(e[o])&&(s[o]=e[o])}),s);let o=n(e.__template);t.utils.isEmpty(o)||(o=o[Object.keys(o)[0]],s=this.doDom(s,o))}return s}doItems(e,t,s){const n=this.getTemplate(e,s);if(void 0===n)return console.error("Template not found. Probably an array is being used where it is not expected. Node:"),console.log(e),console.log("Value (mistaken?):"),void console.log(t);let o=0;t.forEach(t=>{t=this.plainToObject(e,t);const s=this.getItem(e,o++,t,n);s&&e.append(s)});const i=e.find("template");i&&e.removeChild(i),e.items=e.children,this.extendItems(e)}getTemplate(e,s){if(void 0!==e._template&&""!==e._template)return e._template;{let n;const o=e.querySelector("template");if(o)n=t.utils.htmlElement(o.innerHTML.trim());else switch(e.tagName){case"SELECT":case"DATALIST":n=t.utils.newElement("option");break;case"UL":case"OL":n=t.utils.newElement("li");break;case"NAV":n=t.utils.newElement("a");break;case"DL":n=t.utils.newElement("dd");break;default:if(s){const o=Object.keys(s).length;if(o){if(o>1)if(void 0!==s.tagName){let e={};e[s.tagName]=s,s=e}else console.log("Template has more than one top elements. Using the first one. In: "),console.log(s),console.log("Node: "),console.log(e);const i=Object.keys(s)[0],l=s[i];t.utils.isValidElement(i)?n=t.utils.newElement(i):void 0!==l.tagName?(n=t.utils.newElement(l.tagName),s[l.tagName]=l,delete s[i]):(console.error("Template defined an element which can not be identified: ["+i+"], using in:"),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span"))}else console.error("Template has no definition, and it can not be guessed. Using . Template: "),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span")}else e.childElementCount>0&&(n=t.utils.htmlElement(e.innerHTML.trim()))}if(s)if(t.utils.isPlainObject(s)){const o=t.utils.newEmptyNode();o.append(n),n=this.doDom(o,s).children[0],t.utils.defineProp(e,"__template",s)}else n=t.utils.isHtml(s)?t.utils.htmlElement(s):t.utils.isSelectorID(s)?t.utils.htmlElement(document.querySelector(s).innerHTML):t.utils.newElement(s);if(n.childrenElementCount>1){console.log("Templates only supports a single child. Multiple children were detected, wrapping them with . Template:"),console.log(n);const e=t.utils.newElement("span");e.append(n),n=e}return n&&t.utils.defineProp(e,"_template",n),n}}setUniqueAttrib(e,s){e.hasOwnProperty(s)||Object.defineProperty(e,s,{get:function(){return this.hasAttribute(s)},set:function(e){const n=this.parentNode?this.parentNode.find("["+s+"]"):null;n&&n.removeAttribute(s),t.utils.setAttr(this,s,e)}})}updateValue(e,s,n){if(this.isUpdateLink(n)){const o=this,i=n[0],l=n[1],r=n[2];if(n=i[l],i instanceof CSSStyleDeclaration&&this._stored.styles.includes(i)){const n=this._stored.styleNodes[this._stored.styles.indexOf(i)];t.updates&&(n.onupdate=function(t){t.detail&&"style"===t.detail.property&&t.detail.newValue.startsWith(l+":")&&o.setShortValue(e,s,r(this.style[l]))})}else if(i instanceof DOMStringMap&&this._stored.datasets.includes(i)){const n=this._stored.datasetNodes[this._stored.datasets.indexOf(i)];t.updates&&(n.onupdate=t=>{t.detail&&t.detail.property==="data-"+l&&o.setShortValue(e,s,r(t.detail.newValue))})}else t.updates&&(i.onupdate=n=>{n.detail&&n.detail.property===l&&(t.utils.isObject(e[s])||o.setShortValue(e,s,r(n.detail.newValue)))})}return n}setShortValue(e,s,n){if(t.utils.isNode(e[s]))if(t.short){const o=this.plainToObject(e[s],n),i=t.utils.isPlainObject(o)&&Object.keys(o).length>=1?Object.keys(o)[0]:null;i&&(e[s][i]=n)}else console.log("Short is disabled. Trying to set a value ("+n+") in a node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else e[s]=n}getShortValue(e,s,n){let o=null;if(t.utils.isNode(e[s]))if(t.short){const i=this.plainToObject(e[s],n||""),l=t.utils.isPlainObject(i)&&Object.keys(i).length>=1?Object.keys(i)[0]:null;l&&(o=e[s][l])}else console.log("Short is disabled. Trying to get a value from node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else o=e[s];return o}proxy(e,s){return!t.short||null===e||void 0!==e._proxy&&void 0===s?e:(e._proxy=e,new Proxy(e,{get:(e,s)=>{const n=e[s];switch(!0){case null==n:return null;case t.utils.isFunction(n):return n.bind(e);case n._proxy&&void 0!==e["$"+s]:return e["$"+s];case void 0===n._proxy&&t.utils.isElement(n):return this.proxy(n);default:return n}},set:(e,s,n)=>{let o="";return t.utils.isElement(e[s])?(o=this.getShortValue(e,s,n),this.setShortValue(e,s,n)):"onupdate"===s?t.updates?t.utils.isFunction(n)?(e.addEventListener("update",n,!0),o=e[s],e[s]=n):(console.error("Value passed to 'onupdate' is incorrect, in node:"),console.log(e),console.log("Value: (not a function)"),console.log(n)):(console.log("Updates are not available when `m2d2.updates == false`:"),console.log(e)):"items"===s?(e.items.clear(),this.doItems(e,n)):(o=e[s],n=this.updateValue(e,s,n),e[s]=n),t.updates&&void 0!==e.onupdate&&n!==o&&e.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:s,newValue:n,oldValue:o}})),!0}}))}onObserve(e,s){e.forEach(e=>{const s=e.target;if(!(this._stored.events.indexOf(e)>=0)&&(this._stored.events.push(e),setTimeout(()=>{const t=this._stored.events.indexOf(e);t>=0&&this._stored.events.splice(t,1)},t.storedEventsTimeout),void 0!==s.onupdate))if("attributes"===e.type){const n=t.utils.getAttrOrProp(s,e.attributeName);n!==e.oldValue&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:e.attributeName,newValue:n,oldValue:e.oldValue}}))}else if("childList"===e.type)if("#text"===(e.addedNodes[0]||e.removedNodes[0]).nodeName){const t=e.addedNodes[0].textContent,n=e.removedNodes.length?e.removedNodes[0].textContent:null;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"text",newValue:t,oldValue:n}}))}else if(void 0!==s.items){const t=e.addedNodes,n=e.removedNodes;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"items",newValue:t,oldValue:n}}))}})}observe(e){if(t.updates){const t=new MutationObserver(this.onObserve.bind(this)),s={attributeOldValue:!0,subtree:!0,childList:!0},n=e._proxy||e;t.observe(n,s)}}getProxyNode(e,t){const s=this.doDom(e,t);if(s)return this.observe(s),this.proxy(s)}extendItems(e){function s(t){t.forEach(t=>{const s=t.parentNode.removeChild(t);e.append(s)})}const n=e.items;Object.getOwnPropertyNames(Array.prototype).concat(["clear","get","remove","selected","first","last","findAll"]).forEach(o=>{if(void 0===n[o]){let i=null;const l=this;switch(o){case"copyWithin":case"fill":case"splice":i=function(){console.log("Not available yet: "+o)};break;case"reverse":i=function(...e){if(this.items.length){const t=Array.from(this.items),n=t[o](...e);return s(t),n}};break;case"clear":i=function(){for(;this.items[0];)this.items[0].remove()};break;case"get":i=function(e){let s=null;return this.items.length&&this.items.some(n=>{const o=t.utils.isNumeric(e)?1*n.dataset.id==1*e:n.dataset.id===e;if(n.dataset&&o)return s=n,!0}),s};break;case"selected":i=function(){return l.proxy(this.find(":scope > [selected]"))};break;case"first":i=function(){return l.proxy(this.items[0])};break;case"last":i=function(){return l.proxy(this.items[this.items.length-1])};break;case"pop":i=function(){if(this.items.length){const e=this[0].parentNode;return l.proxy(e.removeChild(this.items[this.items.length-1]))}};break;case"push":i=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.append(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.appendChild(s)}else console.log("Trying to push an unknown value into a list:"),console.log(e)};break;case"remove":i=function(e){if(this.items.length){const t=this.items.get(e);1===t.length&&t.remove()}};break;case"shift":i=function(){if(this.items.length){const e=this.items[0].parentNode;return l.proxy(e.removeChild(this.items[0]))}};break;case"sort":i=function(e){if(this.items.length){const t=Array.from(this.items);t.sort(e||((e,t)=>e.text.localeCompare(t.text))),s(t)}};break;case"unshift":i=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.prepend(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.prepend(s)}else console.log("Trying to unshift an unknown value into a list:"),console.log(e)};break;default:let n=o;switch(!0){case"findAll"===o:n="filter";case t.utils.isFunction(Array.prototype[o]):const s=function(...t){const s=[];return Array.from(e.items).forEach(e=>{s.push(l.proxy(e))}),Array.from(s)[n](...t)};switch(o){case"find":i=function(...e){return t.utils.isString(e[0])?this.find(e[0]):s(...e)};break;case"findAll":i=function(...e){return 0===e.length?this.findAll():t.utils.isString(e[0])?this.findAll(e[0]):s(...e)};break;case"concat":i=function(...e){for(let s=0;s{function t(t){e.exists("#m2d2-alert .m2d2-alert-front")?(e("#m2d2-alert .m2d2-alert-front").css.add("vanish"),setTimeout(()=>{e.exists("#m2d2-alert .m2d2-alert-front")&&e("#m2d2-alert").remove(),t&&t()},400)):t&&t()}const s={wrap:!1,question:["fa","fa-question-circle"],info:["fa","fa-exclamation-circle"],error:["fa","fa-exclamation-triangle"],ok:["fa","fa-check"],input:["fa","fa-edit"],wait:["fa","fa-cog","fa-spin"]},n={wrap:"material-icons",question:"help",info:"info",error:"error",ok:"done",input:"edit",wait:"pending"},o={wrap:!1,question:"icon_question",info:"icon_info",error:"icon_error",ok:"icon_ok",input:"icon_input",wait:"icon_wait"};e.message=function(i){let l=o;switch(e.messageIcons){case"fa":l=s;break;case"material":l=n;break;default:e.isObject(e.messageIcons)&&(l=e.messageIcons)}i&&(e.isFunction(i.callback)||(i.callback&&!i.text&&(i.text=i.callback),i.callback=()=>{}),i.text||(i.text="")),t(()=>{e("body",{m2d2Alert:{tagName:"div",id:"m2d2-alert",back:{tagName:"div",css:"m2d2-alert-back",style:{position:"absolute",left:0,right:0,top:0,bottom:0,backgroundColor:"#0005",display:"flex",justifyContent:"center",alignItems:"center"},front:Object.assign({tagName:"form",css:(i.css?e.isArray(i.css)?i.css:[i.css]:[]).concat(["m2d2-alert-front","popup",i.icon]),style:{zIndex:100},icon:{tagName:"span",css:["icon",i.icon].concat(l.wrap?[l.wrap]:l[i.icon]).concat("wait"===i.icon?"spin":""),text:l.wrap?l[i.icon]:""},message:{tagName:"div",css:"m2d2-alert-title",span:i.title},submsg:(()=>{let t;return t="input"!==i.icon||i.text?e.isPlainObject(i.text)?{fieldset:Object.assign({css:"m2d2-alert-field"},i.text)}:{span:i.text.replace("\n","
")}:{fieldset:{css:"m2d2-alert-field",input:{type:"text",name:"answer",onload:function(){this.focus()}}}},Object.assign({tagName:"div",css:"m2d2-alert-text"},t)})(i.icon),onsubmit:function(){const e=this.getData();let s;switch(e.button){case"ok":case"yes":s=()=>{i.callback(!0,e)};break;case"no":s=()=>{i.callback(!1,e)};break;case"cancel":s=()=>{i.callback(null,e)};break;case"send":s=1===Object.keys(e).length?()=>{i.callback(e[Object.keys(e)[0]],e)}:2===Object.keys(e).length?()=>{i.callback(e[Object.keys(e).find(e=>"button"!==e)],e)}:()=>{i.callback(e,e)};break;default:s=()=>{i.callback(e,e)}}return t(s),!1},onload:function(){const e=this.find("[autofocus]");e&&e.focus()}},function(t){let s={};return t.length&&(s={buttons:{tagName:"div",css:"m2d2-alert-buttons"}},t.forEach(t=>{const n=t.toLowerCase().replace(/[^a-z ]/g,"").replace(" ","_");s.buttons[n]={tagName:"button",type:"submit",value:n,css:["color",n],text:void 0!==e.dict?e.dict(t):t,autofocus:["ok","yes"].includes(t),formNoValidate:["cancel"].includes(t),onclick:function(){e(this.closest("form"),{hide:{tagName:"input",type:"hidden",name:"button",value:this.value}})}}})),s}(i.buttons))}}})});let r=1;return e("#m2d2-alert .m2d2-alert-front").findAll("input, select, textarea").forEach(e=>{""===e.name&&(e.name="field_"+r++)}),{close:t}},e.wait=(t,s,n)=>e.message({icon:"wait",title:t,buttons:[],text:void 0===n?null:s,callback:void 0===n?s:n}),e.alert=(t,s,n)=>e.message({icon:"info",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.success=(t,s,n)=>e.message({icon:"ok",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.failure=(t,s,n)=>e.message({icon:"error",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.confirm=(t,s,n)=>e.message({icon:"question",title:t,buttons:["yes","no"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.prompt=(t,s,n)=>e.message({icon:"input",title:t,buttons:["cancel","send"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.closeAll=()=>{t()}}),t.load(e=>{let t=localStorage.getItem("m2d2.lang")||navigator.language;e.dict=new function(t){const s=function(e,t){if(void 0===e)return"";let n=s.val(e,!0);if(void 0!==t){if("string"==typeof t&&""!==t){const e=(t=t.replace(/;$/,"")).split(";");t={},e.forEach(s=>{const n=e[s].split(":");t[n[0]]=n[1]})}"object"==typeof t&&t.forEach(e=>{let o=t[e]+"";o=s.val(o,!1),n=n.replace(e,o)})}return n};return s.lang=t||"en",s.data={},s.set=function(e){return this.data=e,this},s.has=function(e,t){return void 0===t?void 0!==this.data[e]:void 0!==this.data[e][t]},s.val=function(t,n){if(e.isEmpty(s.data))return console.error("Dictionary is empty. You need to add a dictionary, for example: `$.dict.set({\nsave : { en : 'Save', es : 'Guardar' },\ncancel : { en : 'Cancel', es : 'Cancelar' }\nyes : { en : 'Yes', es : 'Si' },\nno : { en : 'No', es : 'No' }\n})`"),"";if(!t)return console.error("No keyword specified."),"";let o=t;if(void 0===n&&(n=!1),t=t.toLowerCase(),this.has(t)){const e=this.lang.split("-")[0];this.has(t,this.lang)?o=this.data[t][this.lang]:this.has(t,e)?o=this.data[t][e]:n&&console.log("Missing translation for lang ["+this.lang+"]: "+t)}else n&&console.log("Missing keyword: "+t);return o},s}(t);const s=[];e.lang=function(t){t&&(e.dict.lang=t,localStorage.setItem("m2d2.lang",e.dict.lang)),e("body").findAll("[lang]").forEach(t=>{let s=t.text;if(s&&!t.classList.contains("notxt")){void 0===t.dataset.kw&&(t.dataset.kw=e.lang.getKeyword(s)),t.text=e.dict(t.dataset.kw);const n=t.dataset.kw+"_title";let o=e.dict.has(n)?e.dict(n):"";o&&(t.title=o)}else if(t.title){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.title)),s=e.dict(t.dataset.kw),s&&(t.title=s)}else if(t.placeholder){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.placeholder)),s=e.dict(t.dataset.kw),s&&(t.placeholder=s)}else if(t.value){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.value)),s=e.dict(t.dataset.kw),s&&(t.value=s)}}),s.forEach(e=>{e(t)})},e.lang.getKeyword=function(e){return e.toLowerCase().trim().replace(/ /g,"_").replace(/[^\w]/g,"").replace(/_$/,"")},Object.defineProperty(e.lang,"onchange",{get(){return this},set(t){e.isFunction(t)?s.push(t):(console.log("Unable to set lang.onchange, because it is not a function: "),console.log(t))}})}),t.ready(e=>{const t=localStorage.getItem("m2d2.lang")||"",s=e("body").find("[lang]"),n=e("html").lang||(s?s.lang:null)||"en";(t?n!==t:n!==navigator.language.split("-")[0])&&e.lang()}),t.load(e=>{function t(e){switch(e){case"local":window.localStorage&&(this.store=localStorage);break;case"session":window.sessionStorage&&(this.store=sessionStorage)}null==this.store&&(this.store=localStorage),this.set=function(e,t){"string"==typeof t&&(t={$:t}),this.store.setItem(e,JSON.stringify(t))},this.get=function(e){let t;try{t=JSON.parse(this.store.getItem(e))||{}}catch(s){t=this.store.getItem(e)}return void 0!==t.$?t=t.$:0===Object.keys(t).length&&t.constructor===Object&&(t=null),t},this.del=function(e){this.store.removeItem(e)},this.keys=function(){return Object.keys(this.store).sort()},this.clear=function(){this.store.clear()},this.exists=function(e){return this.store.hasOwnProperty(e)},this.log=function(e,t,s){null==s&&(s=10);const n=this.get(e)||[];for(n.push(t);n.length>s;)n.shift();this.set(e,n)}}e.local=new t("local"),e.session=new t("session")}),t.load(e=>{function t(e,t,s){const n=[];return e=e||{},t.forEach(o=>{const i="Array"==typeof e?e.length==t.length?e[s]:e:void 0!==e[o.name]?e[o.name]:e;n.push({file:o,data:i,index:s++})}),n}function s(e,t,s,n,o){const i=new XMLHttpRequest;t=Array.from(t),i.upload.addEventListener("progress",(function(e){if(e.lengthComputable)if(n.oneByOne){const o=Math.round(100*e.loaded/e.total);n.onUpdate(o,t[0],s)}else{let s=0,o=0;t.some(t=>{s+=t.size;const i=e.loaded>=s?100:100-Math.round(100*(s-e.loaded)/t.size);return n.onUpdate(i,t,o++),s>=e.loaded})}}),!1),i.addEventListener("load",(function(e){let l={};try{l=i.responseText?JSON.parse(i.responseText):{error:{type:"Unknown",reason:"Unknown Error"}}}catch(e){l.error={type:"Parse Error",reason:e.message}}i.status>=200&&i.status<400?o(n.onResponse(l),t,s):("string"==typeof l.error&&(l.error={type:"Exception",reason:l.error}),n.onError(l.error))}),!1),i.open("POST",n.upload);const l=Array(t.length).fill(!1),r=function(e,t){const s=new FormData;return t.forEach(t=>{s.append(e,t,t.name)}),s}(e,t);let a=0;t.forEach(e=>{const t=new FileReader;t.onload=function(e){l[a++]=!0,-1===l.indexOf(!1)&&i.send(r)},t.readAsBinaryString(e)})}e.upload=function(e,n){const o=Object.assign({},{accept:"*/*",parallel:!1,field:"file",multiple:!0,maxFiles:0,maxSizeMb:0},n);n=null;let i=window._protected_reference=document.createElement("INPUT");i.name=o.field,i.type="file",1==o.multiple&&(i.multiple="multiple"),o.upload||(console.log("Upload not specified. Using current page."),o.upload=""),null==o.onDone&&(o.onDone=(e,t)=>{console.log(e)}),null==o.onError&&(o.onError=e=>{console.log("Error : "),console.log(e)}),null==o.onUpdate&&(o.onUpdate=(e,t,s)=>{console.log("Uploading : "+e+"% "+(o.oneByOne?"[ "+t.name+" ]":""))}),null==o.onResponse&&(o.onResponse=e=>e),i.addEventListener("change",()=>{if(i.files.length){if(!(0===o.maxFiles|i.files.length<=o.maxFiles))return o.onError("Max file limit exceeded. Maximum files: "+o.maxFiles),!1;if(o.onSelect){const e=[];let t=0;Array.from(i.files).forEach(s=>{e.push(URL.createObjectURL(s)),t+=s.size});const s=t/1048576;if(o.maxSizeMb&&s>o.maxSizeMb)return o.onError("Maximum size exceeded: "+Math.ceil(s)+"MB > "+o.maxSizeMb+"MB"),!1;o.onSelect(i.files,e)}new Promise(e=>{if(o.oneByOne){let n=0;const l=Array(i.files.length).fill(!1);Array.from(i.files).forEach(r=>{new s(i.name,[r],n++,o,(s,n,i)=>{l[i]=!0;const r=-1===l.indexOf(!1);o.onDone(t(s,n,i),r),r&&e()})})}else new s(i.name,i.files,0,o,(s,n,i)=>{o.onDone(t(s,n,i),!0),e()})}).then(()=>{i=window._protected_reference=void 0})}}),i.click()}}),t.load(e=>{e.ws=new class{request(e){if(e)try{this.webSocket.send(JSON.stringify(e))}catch(e){this.webSocket.onerror(e)}}getSocket(e,t,s){const n=new WebSocket(this.path);return n.onopen=t,n.onclose=s,n.onmessage=t=>{if(t.data)try{e(JSON.parse(t.data))}catch(e){n.onerror(e)}},n.onerror=e=>{console.error("Socket encountered error: ",e?e.message:"Unknown","Closing socket");const t=n||this;1===t.readyState&&t.close()},n}connect(e,t){this.initRequest=e.request||null,this.onConnect=e.connected||(()=>{}),this.onDisconnect=e.disconnected||(()=>{}),this.reconnect=!1!==e.reconnect,this.host=e.host||window.location.hostname,this.secure=!0===e.secure,this.port=e.port||(this.secure?443:80),this.path="ws"+(this.secure?"s":"")+"://"+this.host+":"+this.port+"/"+(e.path||""),this.connected=!1,this.interval=null;const s=e=>{this.connected=!0,this.request(this.initRequest),this.onConnect()},n=e=>{this.connected=!1,this.onDisconnect(),!this.interval&&this.reconnect&&(this.interval=setInterval(()=>{if(this.connected)console.log("Reconnected..."),clearInterval(this.interval),this.interval=null;else try{this.webSocket.close(),console.log("Reconnecting..."),this.webSocket=this.getSocket(t,s,n)}catch(e){}},2e3))};this.webSocket=this.getSocket(t,s,n)}disconnect(){this.reconnect=!1,this.webSocket.close()}}}),t.load(e=>{const t=function(e,t,s,n,o,i){const l=new XMLHttpRequest;if(void 0===i&&(i=!1),void 0===o&&(o=function(e){console.log(e)}),s&&0===Object.entries(s).length&&(s=""),s)if(i)s=JSON.stringify(s);else switch(e.toUpperCase()){case"GET":t+=(-1!==t.indexOf("?")?"&":"?")+Object.keys(s).map(e=>e+"="+s[e]).join("&"),s="";break;default:s=Object.keys(s).map(e=>e+"="+s[e]).join("&")}return l.open(e,t,!0),i?l.setRequestHeader("Content-Type","application/json"):l.setRequestHeader("Content-type","application/x-www-form-urlencoded"),l.onerror=function(e){o({type:"Connection",reason:"Connection Refused"})},l.onload=function(){let e={};try{e=l.responseText?JSON.parse(l.responseText):{error:{type:"Unknown",reason:"Unknown Error"}}}catch(t){e.error={type:"Parse Error",reason:t.message}}l.status>=200&&l.status<400?void 0!==n&&n(e):void 0!==o&&("string"==typeof e.error&&(e.error={type:"Exception",reason:e.error}),o(e.error))},l.send(s),l},s={};["get","post","put","delete","connect","options","trace","patch"].forEach((function(e){s[e]=function(){let s,n,o,i,l;switch(arguments.length){case 5:"boolean"==typeof arguments[4]?l=arguments[4]:console.log("Passed JSON argument: "+arguments[4]+" is not boolean.");case 4:"function"==typeof arguments[3]?i=arguments[3]:4===arguments.length&&"boolean"==typeof arguments[3]?l=arguments[3]:console.log("Passed argument 4: "+arguments[3]+" is mistaken");case 3:"function"==typeof arguments[2]?"function"==typeof arguments[1]&&arguments.length<5?i=arguments[2]:o=arguments[2]:3===arguments.length&&"boolean"==typeof arguments[2]?l=arguments[2]:console.log("Passed argument 3: "+arguments[2]+" is mistaken");case 2:"object"==typeof arguments[1]||"string"==typeof arguments[1]?n=arguments[1]:"function"==typeof arguments[1]?o=arguments[1]:console.log("Passed argument 2: "+arguments[1]+" is mistaken");case 1:"string"==typeof arguments[0]?s=arguments[0]:Array.isArray(arguments[0])?s=arguments[0].join("/"):console.log("Passed URL: "+arguments[0]+" was not a string.");break;default:console.log("Incorrect number of arguments passed to xhr")}return void 0===n&&(n={}),t(e.toUpperCase(),s,n,o,i,l)}})),Object.assign(e,s)}),t})); \ No newline at end of file diff --git a/dist/m2d2.bundle.ws.min.js b/dist/m2d2.bundle.ws.min.js index 9734406..92e1836 100644 --- a/dist/m2d2.bundle.ws.min.js +++ b/dist/m2d2.bundle.ws.min.js @@ -1,9 +1,9 @@ /** * Author : A.Lepe (dev@alepe.com) - intellisrc.com * License: MIT - * Version: 2.1.1 - * Updated: 2022-02-24 + * Version: 2.1.2 + * Updated: 2022-03-07 * Content: WebSocket Bundle */ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.m2d2=t()}(this,(function(){"use strict";class e{isString(e){return"string"==typeof e}isBool(e){return"boolean"==typeof e}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isSelectorID(e){return 0===(e+"").trim().indexOf("#")}isPlainObject(e){return"Object"===e.constructor.name}isObject(e){return"object"==typeof e}isArray(e){return Array.isArray(e)}isFunction(e){return"function"==typeof e}isElement(e){return e instanceof HTMLElement}isNode(e){return e instanceof Node||e instanceof DocumentFragment}isHtml(e){return-1!==(e+"").trim().indexOf("<")}isEmpty(e){return void 0===e||this.isObject(e)&&0===Object.keys(e).length||""===e}isVisible(e){if(!this.isElement(e))return console.log("(isVisible) Not an element: "),console.log(e),!1;const t="none"!==e.style.display,s="hidden"!==e.style.visibility;return t&&s}inView(e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)&&t.width>0&&t.height>0}cleanArray(e){return e.filter((function(e){return 0===e||e}))}isValidElement(e){const t=this.newElement(e);return"template"!==e&&"HTMLUnknownElement"!==t.constructor.name}exists(e){return null!==document.querySelector(e)}getAttrOrProp(e,t){let s="";return this.hasAttrOrProp(e,t)&&(s=this.hasAttr(e,t)?e.getAttribute(t):e[t]),s}hasAttrOrProp(e,t){return this.hasAttr(e,t)||this.hasProp(e,t)}hasAttr(e,t){let s=!1;if(e&&!this.isNumeric(t))switch(t){case"checked":s=void 0!==e.type&&("radio"===e.type||"checkbox"===e.type);break;default:s=void 0!==e.hasAttribute&&e.hasAttribute(t)}return s}hasProp(e,t){let s=!1;if(e&&!this.isNumeric(t)){let n=void 0!==e[t];n&&null===e[t]&&"value"===t&&(n=!1),s=n&&!(e[t]instanceof Node)&&!e.hasAttribute(t)}return s}setPropOrAttr(e,t,s){if(this.hasProp(e,t))try{e[t]=s}catch(n){this.setAttr(e,t,s)}else this.setAttr(e,t,s)}setAttr(e,t,s){s?e.setAttribute(t,s):e.removeAttribute(t)}defineProp(e,t,s){this.isObject(e)&&void 0===e[t]&&(Object.defineProperty(e,t,{enumerable:!1,writable:!0}),e[t]=s)}htmlElement(e){const t=this.newElement("template");return t.innerHTML=e.trim(),t.content.firstChild}newElement(e){return document.createElement(e)}newEmptyNode(){return new DocumentFragment}getMethods(e){const t=Reflect.getPrototypeOf(e),s=Reflect.getPrototypeOf(t);return Reflect.ownKeys(t).filter(e=>Reflect.ownKeys(s).indexOf(e)<0)}appendAllChild(e,t){for(;e.firstChild;)t.append(e.firstChild)}prependAllChild(e,t){for(;e.firstChild;)t.prepend(e.firstChild)}}class t{"use strict";_stored={events:[],datasetNodes:[],datasets:[],styleNodes:[],styles:[]};static storedEventsTimeout=50;static short=!0;static updates=!0;static utils=new e;constructor(){}static instance=new t;static extensions={};static main=(()=>{const e=(e,s)=>{const n=this.instance.getProxyNode(e,s);return n&&n.onready&&t.utils.isFunction(n.onready)&&(n.addEventListener("ready",n.onready,{once:!0}),setTimeout(()=>{n.dispatchEvent(new CustomEvent("ready"))},10)),["dataset","style"].forEach(e=>{n&&n[e]&&(this.instance._stored[e+"s"].push(n[e]),this.instance._stored[e+"Nodes"].push(n))}),n};return t.utils.getMethods(t.utils).forEach(s=>{e[s]=t.utils[s]}),e})();static ready(e){document.addEventListener("DOMContentLoaded",()=>{e(t.main)})}static load(e){if(void 0!==e){const s=e(t.main);t.utils.isObject(s)&&!t.utils.isEmpty(s)&&Object.keys(s).forEach(e=>{if(t.utils.isValidElement(e)){void 0===t.extensions[e]&&(t.extensions[e]={});const n=t.utils.newElement(e);Object.keys(s[e]).forEach(s=>{t.utils.hasProp(n,s)&&console.log("Warning: property ["+s+"] already exists in node: ["+e+"] while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions[e],s[e])}else{void 0===t.extensions["*"]&&(t.extensions["*"]={});const n=t.utils.newElement("div");Object.keys(s[e]).forEach(e=>{t.utils.hasProp(n,e)&&console.log("Warning: property ["+e+"] already exists in Node while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions["*"],s[e])}})}return t.main}extDom(e,s){if(!e)return console.error("Selector was empty"),null;void 0===s&&(s=document);const n=t.utils.isNode(e)?e:s.querySelector(e);if(!n)return t.utils.isString(e)?(console.error("Selector: "+e+" didn't match any element in node:"),console.log(s)):console.error("Node was null"),null;if(void 0===n._m2d2){n._m2d2=!0,["parent","sibling","next","prev","find","findAll","onupdate","onready","show","onshow","inView","css","text","html","getData","index"].forEach(e=>{n.hasOwnProperty(e)&&(console.log("Node already had ["+e+"] property. It might cause unexpected behaviour."),console.log("You may need to update the M2D2 version or report it to: github.com/intellisrc/m2d2/"))}),Object.defineProperty(n,"text",{get(){return this.childNodes.length?this.innerText:this.textContent},set(e){if(this.childNodes.length){let t=!1;this.childNodes.forEach(s=>{"Text"===s.constructor.name&&(s.nodeValue=e,t=!0)}),t||this.prepend(document.createTextNode(e))}else this.textContent=e}}),Object.defineProperty(n,"html",{get(){return this.innerHTML},set(e){this.innerHTML=e}}),Object.defineProperty(n,"css",{get(){return this.classList},set(e){t.utils.isArray(e)?this.className=e.join(" "):t.utils.isString(e)?this.className=e:t.utils.isPlainObject(e)?Object.keys(e).forEach(t=>{e[t]?this.classList.add(t):this.classList.remove(t)}):console.error("Trying to assign a wrong value to css : "+e)}}),Object.defineProperty(n,"show",{get(){return t.utils.isVisible(this)},set(e){const s=()=>getComputedStyle(this,null).display,n=()=>{const e=document.getElementsByTagName("body")[0],t=document.createElement("template"),s=document.createElement(this.tagName);t.append(s),e.append(t);const n=getComputedStyle(s,null).display;return t.remove(),n};if(e){if("none"===s()){if(this._m2d2_display)this.style.display=this._m2d2_display;else if(this.style.removeProperty("display"),"none"===s()){const e=n();this.style.display=this.dataset.display||("none"!==e?e:"block")}void 0!==this.onshow&&t.utils.isFunction(this.onshow)&&this.onshow(this)}}else{const e="none"!==this.style.display?this.style.display:s();"none"!==e&&(this._m2d2_display=e),this.style.display="none"}}});let e={};return void 0!==t.extensions["*"]&&Object.assign(e,t.extensions["*"]),void 0!==t.extensions[n.tagName]&&Object.assign(e,t.extensions[n.tagName]),Object.assign(n,{inView:()=>t.utils.inView(n),next:()=>n.nextElementSibling,prev:()=>n.previousElementSibling,parent:()=>this.extDom(n.parentElement),sibling:e=>n.parentElement.find(e),find:e=>{const t=n.querySelector(e);return t?this.extDom(t):null},findAll:e=>{const t=void 0===e?Array.from(n.children):n.querySelectorAll(e);return t.forEach(e=>{this.extDom(e)}),t}},e),void 0===n.index&&(n.index=()=>Array.from(n.parentNode.children).indexOf(n)),["INPUT","TEXTAREA","SELECT"].indexOf(n.tagName)>=0&&t.utils.hasAttrOrProp(n,"value")&&(n.oninput=function(){this.setAttribute("value",this.value)}),"FORM"===n.tagName&&(n.getData=function(e){const t={},s=new FormData(this),i=e||!1;for(let e of s.entries()){const s=n.find("[name='"+e[0]+"']");(i||"hidden"===s.type||s.show)&&(t[e[0]]="file"===s.type?s.files:e[1])}return t}),n}return n}doDom(e,s){if(t.utils.isObject(e)&&void 0===s&&(s=e,e=t.utils.newEmptyNode(),void 0===s.warn&&(s.warn=!1)),!(t.utils.isString(e)||t.utils.isElement(e)||t.utils.isNode(e)))return console.error("Selector is not a string or a Node:"),console.log(e),null;if(t.utils.isString(e)&&!document.querySelector(e))return console.log("Selected element doesn't exists: "+e),null;const n=this.extDom(e);if(void 0===s)return n;if(s=this.plainToObject(n,s),Object.keys(s).filter(e=>!["tagName"].includes(e)).forEach(e=>{let i=s[e];null==i&&(console.log("Value was not set for key: "+e+", 'empty' was used in object: "),console.log(s),console.log("In node:"),console.log(n),i="");let o=this.updateValue(n,e,i),l=t.utils.hasProp(n,e),a=!1;if(t.utils.hasAttr(n,e)||l)switch(!0){case"value"===e&&t.utils.hasProp(n,"valueAsDate")&&o instanceof Date:e="valueAsDate";case"css"===e:case typeof o==typeof n[e]:case t.utils.isString(n[e])&&t.utils.isNumeric(o):case t.utils.isFunction(o)&&t.utils.isObject(n[e]):case t.utils.isBool(o)&&t.utils.isString(n[e]):case"object"==typeof n[e]&&"INPUT"===n.tagName:a=!0}if(a){let s=!1;switch(e){case"classList":t.utils.isArray(o)?o.forEach(t=>{n[e].add(t)}):t.utils.isString(o)?n[e].add(o):s=!0;break;case"style":case"dataset":t.utils.isPlainObject(o)?Object.keys(o).forEach(t=>{n[e][t]=this.updateValue(n[e],t,o[t])}):s=!0;break;default:switch(!0){case t.utils.isBool(o):case t.utils.hasAttrOrProp(n,e):t.utils.setPropOrAttr(n,e,o);break;default:n[e]=o}}s&&(console.error("Invalid value passed to '"+e+"': "),console.log(o),console.log("Into Node:"),console.log(n))}else{const l=[];try{if("template"!==e&&!t.utils.isFunction(o)){if(e&&e.match(/^\w/)){let t=n.find("#"+e);t&&-1===l.indexOf(t)&&l.push(t),t=n.find("[name='"+e+"']"),t&&-1===l.indexOf(t)&&l.push(t);const s=Array.from(n.findAll("."+e)).filter(e=>l.indexOf(e)<0);s.length>0&&s.forEach(e=>l.push(e))}const t=Array.from(n.findAll(e)).filter(e=>l.indexOf(e)<0);t.length>0&&t.forEach(e=>l.push(e))}}catch(t){return console.error("Invalid selector: "+e),void console.log(t)}if(l.length>1){const t=[];l.forEach(s=>{t.push(this.render(s,e,o))}),this.linkNode(n,e,t),void 0!==o.warn&&!1===o.warn||(console.log("Multiple elements were assigned with key: ["+e+"] under node: "),console.log(n),console.log("It might be what we expect, but if it is not expected it could result on some elements mistakenly rendered. You can specify 'warn : false' under that element to hide this message."))}else if(1===l.length){const a=l[0];if(t.utils.isElement(a)){const l=this.plainToObject(a,o),r=t.utils.isPlainObject(l)&&Object.keys(l).length>=1?Object.keys(l)[0]:null;if(r&&(o=this.updateValue(a,r,i)),t.utils.isArray(o)){const t=s.template;this.doItems(a,o,t),this.linkNode(n,e,a)}else this.renderAndLink(n,a,e,o)}else console.error("BUG: It should have been a node but got: "),console.log(a),console.log("Parent node:"),console.log(n)}else if(0===l.length){"template"===e&&void 0===s.items&&(e="items",o=[]);const i=t.utils.isFunction(o);if(void 0!==o.tagName){const t=this.appendElement(n,o.tagName);this.renderAndLink(n,t,e,o)}else if(t.utils.isValidElement(e)&&!i){const t=this.appendElement(n,e);this.renderAndLink(n,t,e,o)}else if("items"===e){const e=s.template;if(t.utils.isPlainObject(o)){const e=[];Object.keys(o).forEach(s=>{let i;"DL"===n.tagName?i={dt:s,dd:o[s]}:(i={text:o[s]},t.utils.hasAttrOrProp(n,"value")?i.value=s:i.dataset={id:s}),e.push(i)}),o=e}t.utils.isArray(o)?this.doItems(n,o,e):(console.log("Warning: 'items' specified but value is not and array, in element: "),console.log(n),console.log("Passed values are: "),console.log(o))}else i?(t.updates&&"onupdate"===e&&n.addEventListener("update",o,!0),n[e]=o):"template"!==e&&"warn"!==e&&!1!==o&&(void 0!==s.warn&&!1===s.warn||(console.error("Not sure what you want to do with key: "+e+" under element: "),console.log(n),console.log("And object:"),console.log(s),console.log("Most likely the element's property or child no longer exists or the value passed to it is incorrect."),console.log("You can set 'warn : false' property to the element to dismiss this message.")),n[e]=o)}}}),n.onload){const e=["BODY","FRAME","IFRAME","IMG","LINK","SCRIPT","STYLE"].indexOf(n.tagName)>=0,t="INPUT"===n.tagName&&"image"===n.type;e||t||n.dispatchEvent(new CustomEvent("load"))}return n}isUpdateLink(e){let s=!1;if(t.utils.isArray(e)&&(2===e.length||3===e.length)){const n=2===e.length,i=t.utils.isNode(e[0])||e[0]instanceof DOMStringMap||e[0]instanceof CSSStyleDeclaration,o=n?t.utils.isString(e[1]):t.utils.isString(e[1])&&t.utils.isFunction(e[2]);s=i&&o,s&&n&&e.push(e=>e)}return s}plainToObject(e,s){if(!t.utils.isPlainObject(s)&&!t.utils.isFunction(s)&&!t.utils.isElement(s))if(t.utils.isHtml(s))s={html:s};else if(this.isUpdateLink(s)){const n=s[0],i=s[1],o=s[2];let l=this.plainToObject(e,o(n[i]));if(t.utils.isPlainObject(l)){const e={};Object.keys(l).forEach(t=>{e[t]=s}),s=e}}else t.utils.isArray(s)?s={items:s}:t.utils.hasAttrOrProp(e,"value")?s="SELECT"===e.tagName?{value:s,text:s}:"BUTTON"===e.tagName?{text:s}:{value:s}:t.utils.isString(s)&&"IMG"===e.tagName?s={src:s}:(t.utils.isString(s)||t.utils.isNumeric(s))&&(s={text:s});return s}renderAndLink(e,t,s,n){const i=this.render(t,s,n);this.linkNode(e,s,i)}render(e,t,s){return s=this.plainToObject(e,s),this.doDom(e,s)}linkNode(e,s,n){if(e[s]===n){const t=this.proxy(n);try{e[s]=t}catch(e){}e["$"+s]=t}else t.utils.hasAttrOrProp(e,s)?(e["$"+s]=n,console.log("Property : "+s+" existed in node: "+e.tagName+". Using $"+s+" instead for node: "+n.tagName+".")):e[s]=this.proxy(n)}appendElement(e,s){const n=t.utils.newElement(s);return e.append(n),n}getItem(e,t,s,n){n||(n=this.getTemplate(e));const i=n.cloneNode(!0);this.addTemplatesToItem(n,i),i.dataset.id=t,this.setUniqueAttrib(i,"selected");let o=this.doDom(i,s);return this.getItemWithEvents(e,o)}addTemplatesToItem(e,t){["_template","__template"].forEach(s=>{void 0!==e[s]&&(t[s]=e[s])})}getItemWithEvents(e,s){if(void 0!==e.__template){const n=(e,s)=>(s=s||{},Object.keys(e).forEach(i=>{t.utils.isPlainObject(e[i])?s[i]=n(e[i]):t.utils.isFunction(e[i])&&(s[i]=e[i])}),s);let i=n(e.__template);t.utils.isEmpty(i)||(i=i[Object.keys(i)[0]],s=this.doDom(s,i))}return s}doItems(e,t,s){const n=this.getTemplate(e,s);if(void 0===n)return console.error("Template not found. Probably an array is being used where it is not expected. Node:"),console.log(e),console.log("Value (mistaken?):"),void console.log(t);let i=0;t.forEach(t=>{t=this.plainToObject(e,t);const s=this.getItem(e,i++,t,n);s&&e.append(s)});const o=e.find("template");o&&e.removeChild(o),e.items=e.children,this.extendItems(e)}getTemplate(e,s){if(void 0!==e._template&&""!==e._template)return e._template;{let n;const i=e.querySelector("template");if(i)n=t.utils.htmlElement(i.innerHTML.trim());else switch(e.tagName){case"SELECT":case"DATALIST":n=t.utils.newElement("option");break;case"UL":case"OL":n=t.utils.newElement("li");break;case"NAV":n=t.utils.newElement("a");break;case"DL":n=t.utils.newElement("dd");break;default:if(s){const i=Object.keys(s).length;if(i){if(i>1)if(void 0!==s.tagName){let e={};e[s.tagName]=s,s=e}else console.log("Template has more than one top elements. Using the first one. In: "),console.log(s),console.log("Node: "),console.log(e);const o=Object.keys(s)[0],l=s[o];t.utils.isValidElement(o)?n=t.utils.newElement(o):void 0!==l.tagName?(n=t.utils.newElement(l.tagName),s[l.tagName]=l,delete s[o]):(console.error("Template defined an element which can not be identified: ["+o+"], using in:"),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span"))}else console.error("Template has no definition, and it can not be guessed. Using . Template: "),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span")}else e.childElementCount>0&&(n=t.utils.htmlElement(e.innerHTML.trim()))}if(s)if(t.utils.isPlainObject(s)){const i=t.utils.newEmptyNode();i.append(n),n=this.doDom(i,s).children[0],t.utils.defineProp(e,"__template",s)}else n=t.utils.isHtml(s)?t.utils.htmlElement(s):t.utils.isSelectorID(s)?t.utils.htmlElement(document.querySelector(s).innerHTML):t.utils.newElement(s);if(n.childrenElementCount>1){console.log("Templates only supports a single child. Multiple children were detected, wrapping them with . Template:"),console.log(n);const e=t.utils.newElement("span");e.append(n),n=e}return n&&t.utils.defineProp(e,"_template",n),n}}setUniqueAttrib(e,s){e.hasOwnProperty(s)||Object.defineProperty(e,s,{get:function(){return this.hasAttribute(s)},set:function(e){const n=this.parentNode?this.parentNode.find("["+s+"]"):null;n&&n.removeAttribute(s),t.utils.setAttr(this,s,e)}})}updateValue(e,s,n){if(this.isUpdateLink(n)){const i=this,o=n[0],l=n[1],a=n[2];if(n=o[l],o instanceof CSSStyleDeclaration&&this._stored.styles.includes(o)){const n=this._stored.styleNodes[this._stored.styles.indexOf(o)];t.updates&&(n.onupdate=function(t){t.detail&&"style"===t.detail.property&&t.detail.newValue.startsWith(l+":")&&i.setShortValue(e,s,a(this.style[l]))})}else if(o instanceof DOMStringMap&&this._stored.datasets.includes(o)){const n=this._stored.datasetNodes[this._stored.datasets.indexOf(o)];t.updates&&(n.onupdate=t=>{t.detail&&t.detail.property==="data-"+l&&i.setShortValue(e,s,a(t.detail.newValue))})}else t.updates&&(o.onupdate=n=>{n.detail&&n.detail.property===l&&(t.utils.isObject(e[s])||i.setShortValue(e,s,a(n.detail.newValue)))})}return n}setShortValue(e,s,n){if(t.utils.isNode(e[s]))if(t.short){const i=this.plainToObject(e[s],n),o=t.utils.isPlainObject(i)&&Object.keys(i).length>=1?Object.keys(i)[0]:null;o&&(e[s][o]=n)}else console.log("Short is disabled. Trying to set a value ("+n+") in a node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else e[s]=n}getShortValue(e,s,n){let i=null;if(t.utils.isNode(e[s]))if(t.short){const o=this.plainToObject(e[s],n||""),l=t.utils.isPlainObject(o)&&Object.keys(o).length>=1?Object.keys(o)[0]:null;l&&(i=e[s][l])}else console.log("Short is disabled. Trying to get a value from node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else i=e[s];return i}proxy(e,s){return!t.short||null===e||void 0!==e._proxy&&void 0===s?e:(e._proxy=e,new Proxy(e,{get:(e,s)=>{const n=e[s];switch(!0){case null==n:return null;case t.utils.isFunction(n):return n.bind(e);case n._proxy&&void 0!==e["$"+s]:return e["$"+s];case void 0===n._proxy&&t.utils.isElement(n):return this.proxy(n);default:return n}},set:(e,s,n)=>{let i="";return t.utils.isElement(e[s])?(i=this.getShortValue(e,s,n),this.setShortValue(e,s,n)):"onupdate"===s?t.updates?t.utils.isFunction(n)?(e.addEventListener("update",n,!0),i=e[s],e[s]=n):(console.error("Value passed to 'onupdate' is incorrect, in node:"),console.log(e),console.log("Value: (not a function)"),console.log(n)):(console.log("Updates are not available when `m2d2.updates == false`:"),console.log(e)):"items"===s?(e.items.clear(),this.doItems(e,n)):(i=e[s],n=this.updateValue(e,s,n),e[s]=n),t.updates&&void 0!==e.onupdate&&n!==i&&e.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:s,newValue:n,oldValue:i}})),!0}}))}onObserve(e,s){e.forEach(e=>{const s=e.target;if(!(this._stored.events.indexOf(e)>=0)&&(this._stored.events.push(e),setTimeout(()=>{const t=this._stored.events.indexOf(e);t>=0&&this._stored.events.splice(t,1)},t.storedEventsTimeout),void 0!==s.onupdate))if("attributes"===e.type){const n=t.utils.getAttrOrProp(s,e.attributeName);n!==e.oldValue&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:e.attributeName,newValue:n,oldValue:e.oldValue}}))}else if("childList"===e.type)if("#text"===(e.addedNodes[0]||e.removedNodes[0]).nodeName){const t=e.addedNodes[0].textContent,n=e.removedNodes.length?e.removedNodes[0].textContent:null;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"text",newValue:t,oldValue:n}}))}else if(void 0!==s.items){const t=e.addedNodes,n=e.removedNodes;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"items",newValue:t,oldValue:n}}))}})}observe(e){if(t.updates){const t=new MutationObserver(this.onObserve.bind(this)),s={attributeOldValue:!0,subtree:!0,childList:!0},n=e._proxy||e;t.observe(n,s)}}getProxyNode(e,t){const s=this.doDom(e,t);if(s)return this.observe(s),this.proxy(s)}extendItems(e){function s(t){t.forEach(t=>{const s=t.parentNode.removeChild(t);e.append(s)})}const n=e.items;Object.getOwnPropertyNames(Array.prototype).concat(["clear","get","remove","selected","first","last","findAll"]).forEach(i=>{if(void 0===n[i]){let o=null;const l=this;switch(i){case"copyWithin":case"fill":case"splice":o=function(){console.log("Not available yet: "+i)};break;case"reverse":o=function(...e){if(this.items.length){const t=Array.from(this.items),n=t[i](...e);return s(t),n}};break;case"clear":o=function(){for(;this.items[0];)this.items[0].remove()};break;case"get":o=function(e){let s=null;return this.items.length&&this.items.some(n=>{const i=t.utils.isNumeric(e)?1*n.dataset.id==1*e:n.dataset.id===e;if(n.dataset&&i)return s=n,!0}),s};break;case"selected":o=function(){return l.proxy(this.find(":scope > [selected]"))};break;case"first":o=function(){return l.proxy(this.items[0])};break;case"last":o=function(){return l.proxy(this.items[this.items.length-1])};break;case"pop":o=function(){if(this.items.length){const e=this[0].parentNode;return l.proxy(e.removeChild(this.items[this.items.length-1]))}};break;case"push":o=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.append(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.appendChild(s)}else console.log("Trying to push an unknown value into a list:"),console.log(e)};break;case"remove":o=function(e){if(this.items.length){const t=this.items.get(e);1===t.length&&t.remove()}};break;case"shift":o=function(){if(this.items.length){const e=this.items[0].parentNode;return l.proxy(e.removeChild(this.items[0]))}};break;case"sort":o=function(e){if(this.items.length){const t=Array.from(this.items);t.sort(e||((e,t)=>e.text.localeCompare(t.text))),s(t)}};break;case"unshift":o=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.prepend(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.prepend(s)}else console.log("Trying to unshift an unknown value into a list:"),console.log(e)};break;default:let n=i;switch(!0){case"findAll"===i:n="filter";case t.utils.isFunction(Array.prototype[i]):const s=function(...t){const s=[];return Array.from(e.items).forEach(e=>{s.push(l.proxy(e))}),Array.from(s)[n](...t)};switch(i){case"find":o=function(...e){return t.utils.isString(e[0])?this.find(e[0]):s(...e)};break;case"findAll":o=function(...e){return 0===e.length?this.findAll():t.utils.isString(e[0])?this.findAll(e[0]):s(...e)};break;case"concat":o=function(...e){for(let s=0;s{function t(t){e.exists("#m2d2-alert .m2d2-alert-front")?(e("#m2d2-alert .m2d2-alert-front").css.add("vanish"),setTimeout(()=>{e.exists("#m2d2-alert .m2d2-alert-front")&&e("#m2d2-alert").remove(),t&&t()},400)):t&&t()}const s={wrap:!1,question:["fa","fa-question-circle"],info:["fa","fa-exclamation-circle"],error:["fa","fa-exclamation-triangle"],ok:["fa","fa-check"],input:["fa","fa-edit"],wait:["fa","fa-cog","fa-spin"]},n={wrap:"material-icons",question:"help",info:"info",error:"error",ok:"done",input:"edit",wait:"pending"},i={wrap:!1,question:"icon_question",info:"icon_info",error:"icon_error",ok:"icon_ok",input:"icon_input",wait:"icon_wait"};e.message=function(o){let l=i;switch(e.messageIcons){case"fa":l=s;break;case"material":l=n;break;default:e.isObject(e.messageIcons)&&(l=e.messageIcons)}o&&(e.isFunction(o.callback)||(o.callback&&!o.text&&(o.text=o.callback),o.callback=()=>{}),o.text||(o.text="")),t(()=>{e("body",{m2d2Alert:{tagName:"div",id:"m2d2-alert",back:{tagName:"div",css:"m2d2-alert-back",style:{position:"absolute",left:0,right:0,top:0,bottom:0,backgroundColor:"#0005",display:"flex",justifyContent:"center",alignItems:"center"},front:Object.assign({tagName:"form",css:(o.css?e.isArray(o.css)?o.css:[o.css]:[]).concat(["m2d2-alert-front","popup",o.icon]),style:{zIndex:100},icon:{tagName:"span",css:["icon",o.icon].concat(l.wrap?[l.wrap]:l[o.icon]).concat("wait"===o.icon?"spin":""),text:l.wrap?l[o.icon]:""},message:{tagName:"div",css:"m2d2-alert-title",span:o.title},submsg:(()=>{let t;return t="input"!==o.icon||o.text?e.isPlainObject(o.text)?{fieldset:Object.assign({css:"m2d2-alert-field"},o.text)}:{span:o.text.replace("\n","
")}:{fieldset:{css:"m2d2-alert-field",input:{type:"text",name:"answer",onload:function(){this.focus()}}}},Object.assign({tagName:"div",css:"m2d2-alert-text"},t)})(o.icon),onsubmit:function(){const e=this.getData();let s;switch(e.button){case"ok":case"yes":s=()=>{o.callback(!0,e)};break;case"no":s=()=>{o.callback(!1,e)};break;case"cancel":s=()=>{o.callback(null,e)};break;case"send":s=1===Object.keys(e).length?()=>{o.callback(e[Object.keys(e)[0]],e)}:2===Object.keys(e).length?()=>{o.callback(e[Object.keys(e).find(e=>"button"!==e)],e)}:()=>{o.callback(e,e)};break;default:s=()=>{o.callback(e,e)}}return t(s),!1},onload:function(){const e=this.find("[autofocus]");e&&e.focus()}},function(t){let s={};return t.length&&(s={buttons:{tagName:"div",css:"m2d2-alert-buttons"}},t.forEach(t=>{const n=t.toLowerCase().replace(/[^a-z ]/g,"").replace(" ","_");s.buttons[n]={tagName:"button",type:"submit",value:n,css:["color",n],text:void 0!==e.dict?e.dict(t):t,autofocus:["ok","yes"].includes(t),formNoValidate:["cancel"].includes(t),onclick:function(){e(this.closest("form"),{hide:{tagName:"input",type:"hidden",name:"button",value:this.value}})}}})),s}(o.buttons))}}})});let a=1;return e("#m2d2-alert .m2d2-alert-front").findAll("input, select, textarea").forEach(e=>{""===e.name&&(e.name="field_"+a++)}),{close:t}},e.wait=(t,s,n)=>e.message({icon:"wait",title:t,buttons:[],text:void 0===n?null:s,callback:void 0===n?s:n}),e.alert=(t,s,n)=>e.message({icon:"info",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.success=(t,s,n)=>e.message({icon:"ok",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.failure=(t,s,n)=>e.message({icon:"error",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.confirm=(t,s,n)=>e.message({icon:"question",title:t,buttons:["yes","no"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.prompt=(t,s,n)=>e.message({icon:"input",title:t,buttons:["cancel","send"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.closeAll=()=>{t()}}),t.load(e=>{let t=localStorage.getItem("m2d2.lang")||navigator.language;e.dict=new function(t){const s=function(e,t){if(void 0===e)return"";let n=s.val(e,!0);if(void 0!==t){if("string"==typeof t&&""!==t){const e=(t=t.replace(/;$/,"")).split(";");t={},e.forEach(s=>{const n=e[s].split(":");t[n[0]]=n[1]})}"object"==typeof t&&t.forEach(e=>{let i=t[e]+"";i=s.val(i,!1),n=n.replace(e,i)})}return n};return s.lang=t||"en",s.data={},s.set=function(e){return this.data=e,this},s.has=function(e,t){return void 0===t?void 0!==this.data[e]:void 0!==this.data[e][t]},s.val=function(t,n){if(e.isEmpty(s.data))return console.error("Dictionary is empty. You need to add a dictionary, for example: `$.dict.set({\nsave : { en : 'Save', es : 'Guardar' },\ncancel : { en : 'Cancel', es : 'Cancelar' }\nyes : { en : 'Yes', es : 'Si' },\nno : { en : 'No', es : 'No' }\n})`"),"";if(!t)return console.error("No keyword specified."),"";let i=t;if(void 0===n&&(n=!1),t=t.toLowerCase(),this.has(t)){const e=this.lang.split("-")[0];this.has(t,this.lang)?i=this.data[t][this.lang]:this.has(t,e)?i=this.data[t][e]:n&&console.log("Missing translation for lang ["+this.lang+"]: "+t)}else n&&console.log("Missing keyword: "+t);return i},s}(t);const s=[];e.lang=function(t){t&&(e.dict.lang=t,localStorage.setItem("m2d2.lang",e.dict.lang)),e("body").findAll("[lang]").forEach(t=>{let s=t.text;if(s&&!t.classList.contains("notxt")){void 0===t.dataset.kw&&(t.dataset.kw=e.lang.getKeyword(s)),t.text=e.dict(t.dataset.kw);const n=t.dataset.kw+"_title";let i=e.dict.has(n)?e.dict(n):"";i&&(t.title=i)}else if(t.title){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.title)),s=e.dict(t.dataset.kw),s&&(t.title=s)}else if(t.placeholder){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.placeholder)),s=e.dict(t.dataset.kw),s&&(t.placeholder=s)}else if(t.value){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.value)),s=e.dict(t.dataset.kw),s&&(t.value=s)}}),s.forEach(e=>{e(t)})},e.lang.getKeyword=function(e){return e.toLowerCase().trim().replace(/ /g,"_").replace(/[^\w]/g,"").replace(/_$/,"")},Object.defineProperty(e.lang,"onchange",{get(){return this},set(t){e.isFunction(t)?s.push(t):(console.log("Unable to set lang.onchange, because it is not a function: "),console.log(t))}})}),t.ready(e=>{const t=localStorage.getItem("m2d2.lang")||"",s=e("body").find("[lang]"),n=e("html").lang||(s?s.lang:null)||"en";(t?n!==t:n!==navigator.language.split("-")[0])&&e.lang()}),t.load(e=>{function t(e){switch(e){case"local":window.localStorage&&(this.store=localStorage);break;case"session":window.sessionStorage&&(this.store=sessionStorage)}null==this.store&&(this.store=localStorage),this.set=function(e,t){"string"==typeof t&&(t={$:t}),this.store.setItem(e,JSON.stringify(t))},this.get=function(e){let t;try{t=JSON.parse(this.store.getItem(e))||{}}catch(s){t=this.store.getItem(e)}return void 0!==t.$?t=t.$:0===Object.keys(t).length&&t.constructor===Object&&(t=null),t},this.del=function(e){this.store.removeItem(e)},this.keys=function(){return Object.keys(this.store).sort()},this.clear=function(){this.store.clear()},this.exists=function(e){return this.store.hasOwnProperty(e)},this.log=function(e,t,s){null==s&&(s=10);const n=this.get(e)||[];for(n.push(t);n.length>s;)n.shift();this.set(e,n)}}e.local=new t("local"),e.session=new t("session")}),t.load(e=>{function t(e,t,s){const n=[];return e=e||{},t.forEach(i=>{const o="Array"==typeof e?e.length==t.length?e[s]:e:void 0!==e[i.name]?e[i.name]:e;n.push({file:i,data:o,index:s++})}),n}function s(e,t,s,n,i){const o=new XMLHttpRequest;t=Array.from(t),o.upload.addEventListener("progress",(function(e){if(e.lengthComputable)if(n.oneByOne){const i=Math.round(100*e.loaded/e.total);n.onUpdate(i,t[0],s)}else{let s=0,i=0;t.some(t=>{s+=t.size;const o=e.loaded>=s?100:100-Math.round(100*(s-e.loaded)/t.size);return n.onUpdate(o,t,i++),s>=e.loaded})}}),!1),o.addEventListener("load",(function(e){let l={};try{l=o.responseText?JSON.parse(o.responseText):{error:{type:"Unknown",reason:"Unknown Error"}}}catch(e){l.error={type:"Parse Error",reason:e.message}}o.status>=200&&o.status<400?i(n.onResponse(l),t,s):("string"==typeof l.error&&(l.error={type:"Exception",reason:l.error}),n.onError(l.error))}),!1),o.open("POST",n.upload);const l=Array(t.length).fill(!1),a=function(e,t){const s=new FormData;return t.forEach(t=>{s.append(e,t,t.name)}),s}(e,t);let r=0;t.forEach(e=>{const t=new FileReader;t.onload=function(e){l[r++]=!0,-1===l.indexOf(!1)&&o.send(a)},t.readAsBinaryString(e)})}e.upload=function(e,n){const i=Object.assign({},{accept:"*/*",parallel:!1,field:"file",multiple:!0,maxFiles:0,maxSizeMb:0},n);n=null;let o=window._protected_reference=document.createElement("INPUT");o.name=i.field,o.type="file",1==i.multiple&&(o.multiple="multiple"),i.upload||(console.log("Upload not specified. Using current page."),i.upload=""),null==i.onDone&&(i.onDone=(e,t)=>{console.log(e)}),null==i.onError&&(i.onError=e=>{console.log("Error : "),console.log(e)}),null==i.onUpdate&&(i.onUpdate=(e,t,s)=>{console.log("Uploading : "+e+"% "+(i.oneByOne?"[ "+t.name+" ]":""))}),null==i.onResponse&&(i.onResponse=e=>e),o.addEventListener("change",()=>{if(o.files.length){if(!(0===i.maxFiles|o.files.length<=i.maxFiles))return i.onError("Max file limit exceeded. Maximum files: "+i.maxFiles),!1;if(i.onSelect){const e=[];let t=0;Array.from(o.files).forEach(s=>{e.push(URL.createObjectURL(s)),t+=s.size});const s=t/1048576;if(i.maxSizeMb&&s>i.maxSizeMb)return i.onError("Maximum size exceeded: "+Math.ceil(s)+"MB > "+i.maxSizeMb+"MB"),!1;i.onSelect(o.files,e)}new Promise(e=>{if(i.oneByOne){let n=0;const l=Array(o.files.length).fill(!1);Array.from(o.files).forEach(a=>{new s(o.name,[a],n++,i,(s,n,o)=>{l[o]=!0;const a=-1===l.indexOf(!1);i.onDone(t(s,n,o),a),a&&e()})})}else new s(o.name,o.files,0,i,(s,n,o)=>{i.onDone(t(s,n,o),!0),e()})}).then(()=>{o=window._protected_reference=void 0})}}),o.click()}}),t.load(e=>{e.ws=new class{request(e){if(e)try{this.webSocket.send(JSON.stringify(e))}catch(e){this.webSocket.onerror(e)}}getSocket(e,t,s){const n=new WebSocket(this.path);return n.onopen=t,n.onclose=s,n.onmessage=t=>{if(t.data)try{e(JSON.parse(t.data))}catch(e){n.onerror(e)}},n.onerror=e=>{console.error("Socket encountered error: ",e?e.message:"Unknown","Closing socket");const t=n||this;1===t.readyState&&t.close()},n}connect(e,t){this.initRequest=e.request||null,this.onConnect=e.connected||(()=>{}),this.onDisconnect=e.disconnected||(()=>{}),this.reconnect=!1!==e.reconnect,this.host=e.host||window.location.hostname,this.secure=!0===e.secure,this.port=e.port||(this.secure?443:80),this.path="ws"+(this.secure?"s":"")+"://"+this.host+":"+this.port+"/"+(e.path||""),this.connected=!1,this.interval=null;const s=e=>{this.connected=!0,this.request(this.initRequest),this.onConnect()},n=e=>{this.connected=!1,this.onDisconnect(),!this.interval&&this.reconnect&&(this.interval=setInterval(()=>{if(this.connected)console.log("Reconnected..."),clearInterval(this.interval),this.interval=null;else try{this.webSocket.close(),console.log("Reconnecting..."),this.webSocket=this.getSocket(t,s,n)}catch(e){}},2e3))};this.webSocket=this.getSocket(t,s,n)}disconnect(){this.reconnect=!1,this.webSocket.close()}}}),t})); \ No newline at end of file +!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.m2d2=t()}(this,(function(){"use strict";class e{isString(e){return"string"==typeof e}isBool(e){return"boolean"==typeof e}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isSelectorID(e){return 0===(e+"").trim().indexOf("#")}isPlainObject(e){return"Object"===e.constructor.name}isObject(e){return"object"==typeof e}isArray(e){return Array.isArray(e)}isFunction(e){return"function"==typeof e}isElement(e){return e instanceof HTMLElement}isNode(e){return e instanceof Node||e instanceof DocumentFragment}isHtml(e){return-1!==(e+"").trim().indexOf("<")}isEmpty(e){return void 0===e||this.isObject(e)&&0===Object.keys(e).length||""===e}isVisible(e){if(!this.isElement(e))return console.log("(isVisible) Not an element: "),console.log(e),!1;const t="none"!==e.style.display,s="hidden"!==e.style.visibility;return t&&s}inView(e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)&&t.width>0&&t.height>0}cleanArray(e){return e.filter((function(e){return 0===e||e}))}isValidElement(e){const t=this.newElement(e);return"template"!==e&&"HTMLUnknownElement"!==t.constructor.name}exists(e){return null!==document.querySelector(e)}getAttrOrProp(e,t){let s="";return this.hasAttrOrProp(e,t)&&(s=this.hasAttr(e,t)?e.getAttribute(t):e[t]),s}hasAttrOrProp(e,t){return this.hasAttr(e,t)||this.hasProp(e,t)}hasAttr(e,t){let s=!1;if(e&&!this.isNumeric(t))switch(t){case"checked":s=void 0!==e.type&&("radio"===e.type||"checkbox"===e.type);break;default:s=void 0!==e.hasAttribute&&e.hasAttribute(t)}return s}hasProp(e,t){let s=!1;if(e&&!this.isNumeric(t)){let n=void 0!==e[t];n&&null===e[t]&&"value"===t&&(n=!1),s=n&&!(e[t]instanceof Node)&&!e.hasAttribute(t)}return s}setPropOrAttr(e,t,s){if(this.hasProp(e,t))try{e[t]=s}catch(n){this.setAttr(e,t,s)}else this.setAttr(e,t,s)}setAttr(e,t,s){s?e.setAttribute(t,s):e.removeAttribute(t)}defineProp(e,t,s){this.isObject(e)&&void 0===e[t]&&(Object.defineProperty(e,t,{enumerable:!1,writable:!0}),e[t]=s)}htmlElement(e){const t=this.newElement("template");return t.innerHTML=e.trim(),t.content.firstChild}newElement(e){return document.createElement(e)}newEmptyNode(){return new DocumentFragment}getMethods(e){const t=Reflect.getPrototypeOf(e),s=Reflect.getPrototypeOf(t);return Reflect.ownKeys(t).filter(e=>Reflect.ownKeys(s).indexOf(e)<0)}appendAllChild(e,t){for(;e.firstChild;)t.append(e.firstChild)}prependAllChild(e,t){for(;e.firstChild;)t.prepend(e.firstChild)}}class t{"use strict";_stored={events:[],datasetNodes:[],datasets:[],styleNodes:[],styles:[]};static storedEventsTimeout=50;static short=!0;static updates=!0;static utils=new e;constructor(){}static instance=new t;static extensions={};static main=(()=>{const e=(e,s)=>{const n=this.instance.getProxyNode(e,s);return n&&n.onready&&t.utils.isFunction(n.onready)&&(n.addEventListener("ready",n.onready,{once:!0}),setTimeout(()=>{n.dispatchEvent(new CustomEvent("ready"))},10)),["dataset","style"].forEach(e=>{n&&n[e]&&(this.instance._stored[e+"s"].push(n[e]),this.instance._stored[e+"Nodes"].push(n))}),n};return t.utils.getMethods(t.utils).forEach(s=>{e[s]=t.utils[s]}),e})();static ready(e){document.addEventListener("DOMContentLoaded",()=>{e(t.main)})}static load(e){if(void 0!==e){const s=e(t.main);t.utils.isObject(s)&&!t.utils.isEmpty(s)&&Object.keys(s).forEach(e=>{if(t.utils.isValidElement(e)){void 0===t.extensions[e]&&(t.extensions[e]={});const n=t.utils.newElement(e);Object.keys(s[e]).forEach(s=>{t.utils.hasProp(n,s)&&console.log("Warning: property ["+s+"] already exists in node: ["+e+"] while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions[e],s[e])}else{void 0===t.extensions["*"]&&(t.extensions["*"]={});const n=t.utils.newElement("div");Object.keys(s[e]).forEach(e=>{t.utils.hasProp(n,e)&&console.log("Warning: property ["+e+"] already exists in Node while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions["*"],s[e])}})}return t.main}extDom(e,s){if(!e)return console.error("Selector was empty"),null;void 0===s&&(s=document);const n=t.utils.isNode(e)?e:s.querySelector(e);if(!n)return t.utils.isString(e)?(console.error("Selector: "+e+" didn't match any element in node:"),console.log(s)):console.error("Node was null"),null;if(void 0===n._m2d2){n._m2d2=!0,["parent","sibling","posterior","anterior","find","findAll","onupdate","onready","show","onshow","inView","css","text","html","getData","index"].forEach(e=>{n.hasOwnProperty(e)&&(console.log("Node already had ["+e+"] property. It might cause unexpected behaviour."),console.log("You may need to update the M2D2 version or report it to: github.com/intellisrc/m2d2/"))}),Object.defineProperty(n,"text",{get(){return this.childNodes.length?this.innerText:this.textContent},set(e){if(this.childNodes.length){let t=!1;this.childNodes.forEach(s=>{"Text"===s.constructor.name&&(s.nodeValue=e,t=!0)}),t||this.prepend(document.createTextNode(e))}else this.textContent=e}}),Object.defineProperty(n,"html",{get(){return this.innerHTML},set(e){this.innerHTML=e}}),Object.defineProperty(n,"css",{get(){return this.classList},set(e){t.utils.isArray(e)?this.className=e.join(" "):t.utils.isString(e)?this.className=e:t.utils.isPlainObject(e)?Object.keys(e).forEach(t=>{e[t]?this.classList.add(t):this.classList.remove(t)}):console.error("Trying to assign a wrong value to css : "+e)}}),Object.defineProperty(n,"show",{get(){return t.utils.isVisible(this)},set(e){const s=()=>getComputedStyle(this,null).display,n=()=>{const e=document.getElementsByTagName("body")[0],t=document.createElement("template"),s=document.createElement(this.tagName);t.append(s),e.append(t);const n=getComputedStyle(s,null).display;return t.remove(),n};if(e){if("none"===s()){if(this._m2d2_display)this.style.display=this._m2d2_display;else if(this.style.removeProperty("display"),"none"===s()){const e=n();this.style.display=this.dataset.display||("none"!==e?e:"block")}void 0!==this.onshow&&t.utils.isFunction(this.onshow)&&this.onshow(this)}}else{const e="none"!==this.style.display?this.style.display:s();"none"!==e&&(this._m2d2_display=e),this.style.display="none"}}});let e={};return void 0!==t.extensions["*"]&&Object.assign(e,t.extensions["*"]),void 0!==t.extensions[n.tagName]&&Object.assign(e,t.extensions[n.tagName]),Object.assign(n,{inView:()=>t.utils.inView(n),posterior:()=>n.nextElementSibling,anterior:()=>n.previousElementSibling,parent:()=>this.extDom(n.parentElement),sibling:e=>n.parentElement.find(e),find:e=>{const t=n.querySelector(e);return t?this.extDom(t):null},findAll:e=>{const t=void 0===e?Array.from(n.children):n.querySelectorAll(e);return t.forEach(e=>{this.extDom(e)}),t}},e),void 0===n.index&&(n.index=()=>Array.from(n.parentNode.children).indexOf(n)),["INPUT","TEXTAREA","SELECT"].indexOf(n.tagName)>=0&&t.utils.hasAttrOrProp(n,"value")&&(n.oninput=function(){this.setAttribute("value",this.value)}),"FORM"===n.tagName&&(n.getData=function(e){const t={},s=new FormData(this),i=e||!1;for(let e of s.entries()){const s=n.find("[name='"+e[0]+"']");(i||"hidden"===s.type||s.show)&&(t[e[0]]="file"===s.type?s.files:e[1])}return t}),n}return n}doDom(e,s){if(t.utils.isObject(e)&&void 0===s&&(s=e,e=t.utils.newEmptyNode(),void 0===s.warn&&(s.warn=!1)),!(t.utils.isString(e)||t.utils.isElement(e)||t.utils.isNode(e)))return console.error("Selector is not a string or a Node:"),console.log(e),null;if(t.utils.isString(e)&&!document.querySelector(e))return console.log("Selected element doesn't exists: "+e),null;const n=this.extDom(e);if(void 0===s)return n;if(s=this.plainToObject(n,s),Object.keys(s).filter(e=>!["tagName"].includes(e)).forEach(e=>{let i=s[e];null==i&&(console.log("Value was not set for key: "+e+", 'empty' was used in object: "),console.log(s),console.log("In node:"),console.log(n),i="");let o=this.updateValue(n,e,i),l=t.utils.hasProp(n,e),a=!1;if(t.utils.hasAttr(n,e)||l)switch(!0){case"value"===e&&t.utils.hasProp(n,"valueAsDate")&&o instanceof Date:e="valueAsDate";case"css"===e:case typeof o==typeof n[e]:case t.utils.isString(n[e])&&t.utils.isNumeric(o):case t.utils.isFunction(o)&&t.utils.isObject(n[e]):case t.utils.isBool(o)&&t.utils.isString(n[e]):case"object"==typeof n[e]&&"INPUT"===n.tagName:a=!0}if(a){let s=!1;switch(e){case"classList":t.utils.isArray(o)?o.forEach(t=>{n[e].add(t)}):t.utils.isString(o)?n[e].add(o):s=!0;break;case"style":case"dataset":t.utils.isPlainObject(o)?Object.keys(o).forEach(t=>{n[e][t]=this.updateValue(n[e],t,o[t])}):s=!0;break;default:switch(!0){case t.utils.isBool(o):case t.utils.hasAttrOrProp(n,e):t.utils.setPropOrAttr(n,e,o);break;default:n[e]=o}}s&&(console.error("Invalid value passed to '"+e+"': "),console.log(o),console.log("Into Node:"),console.log(n))}else{const l=[];try{if("template"!==e&&!t.utils.isFunction(o)){if(e&&e.match(/^\w/)){let t=n.find("#"+e);t&&-1===l.indexOf(t)&&l.push(t),t=n.find("[name='"+e+"']"),t&&-1===l.indexOf(t)&&l.push(t);const s=Array.from(n.findAll("."+e)).filter(e=>l.indexOf(e)<0);s.length>0&&s.forEach(e=>l.push(e))}const t=Array.from(n.findAll(e)).filter(e=>l.indexOf(e)<0);t.length>0&&t.forEach(e=>l.push(e))}}catch(t){return console.error("Invalid selector: "+e),void console.log(t)}if(l.length>1){const t=[];l.forEach(s=>{t.push(this.render(s,e,o))}),this.linkNode(n,e,t),void 0!==o.warn&&!1===o.warn||(console.log("Multiple elements were assigned with key: ["+e+"] under node: "),console.log(n),console.log("It might be what we expect, but if it is not expected it could result on some elements mistakenly rendered. You can specify 'warn : false' under that element to hide this message."))}else if(1===l.length){const a=l[0];if(t.utils.isElement(a)){const l=this.plainToObject(a,o),r=t.utils.isPlainObject(l)&&Object.keys(l).length>=1?Object.keys(l)[0]:null;if(r&&(o=this.updateValue(a,r,i)),t.utils.isArray(o)){const t=s.template;this.doItems(a,o,t),this.linkNode(n,e,a)}else this.renderAndLink(n,a,e,o)}else console.error("BUG: It should have been a node but got: "),console.log(a),console.log("Parent node:"),console.log(n)}else if(0===l.length){"template"===e&&void 0===s.items&&(e="items",o=[]);const i=t.utils.isFunction(o);if(void 0!==o.tagName){const t=this.appendElement(n,o.tagName);this.renderAndLink(n,t,e,o)}else if(t.utils.isValidElement(e)&&!i){const t=this.appendElement(n,e);this.renderAndLink(n,t,e,o)}else if("items"===e){const e=s.template;if(t.utils.isPlainObject(o)){const e=[];Object.keys(o).forEach(s=>{let i;"DL"===n.tagName?i={dt:s,dd:o[s]}:(i={text:o[s]},t.utils.hasAttrOrProp(n,"value")?i.value=s:i.dataset={id:s}),e.push(i)}),o=e}t.utils.isArray(o)?this.doItems(n,o,e):(console.log("Warning: 'items' specified but value is not and array, in element: "),console.log(n),console.log("Passed values are: "),console.log(o))}else i?(t.updates&&"onupdate"===e&&n.addEventListener("update",o,!0),n[e]=o):"template"!==e&&"warn"!==e&&!1!==o&&(void 0!==s.warn&&!1===s.warn||(console.error("Not sure what you want to do with key: "+e+" under element: "),console.log(n),console.log("And object:"),console.log(s),console.log("Most likely the element's property or child no longer exists or the value passed to it is incorrect."),console.log("You can set 'warn : false' property to the element to dismiss this message.")),n[e]=o)}}}),n.onload){const e=["BODY","FRAME","IFRAME","IMG","LINK","SCRIPT","STYLE"].indexOf(n.tagName)>=0,t="INPUT"===n.tagName&&"image"===n.type;e||t||n.dispatchEvent(new CustomEvent("load"))}return n}isUpdateLink(e){let s=!1;if(t.utils.isArray(e)&&(2===e.length||3===e.length)){const n=2===e.length,i=t.utils.isNode(e[0])||e[0]instanceof DOMStringMap||e[0]instanceof CSSStyleDeclaration,o=n?t.utils.isString(e[1]):t.utils.isString(e[1])&&t.utils.isFunction(e[2]);s=i&&o,s&&n&&e.push(e=>e)}return s}plainToObject(e,s){if(!t.utils.isPlainObject(s)&&!t.utils.isFunction(s)&&!t.utils.isElement(s))if(t.utils.isHtml(s))s={html:s};else if(this.isUpdateLink(s)){const n=s[0],i=s[1],o=s[2];let l=this.plainToObject(e,o(n[i]));if(t.utils.isPlainObject(l)){const e={};Object.keys(l).forEach(t=>{e[t]=s}),s=e}}else t.utils.isArray(s)?s={items:s}:t.utils.hasAttrOrProp(e,"value")?s="SELECT"===e.tagName?{value:s,text:s}:"BUTTON"===e.tagName?{text:s}:{value:s}:t.utils.isString(s)&&"IMG"===e.tagName?s={src:s}:(t.utils.isString(s)||t.utils.isNumeric(s))&&(s={text:s});return s}renderAndLink(e,t,s,n){const i=this.render(t,s,n);this.linkNode(e,s,i)}render(e,t,s){return s=this.plainToObject(e,s),this.doDom(e,s)}linkNode(e,s,n){if(e[s]===n){const t=this.proxy(n);try{e[s]=t}catch(e){}e["$"+s]=t}else t.utils.hasAttrOrProp(e,s)?(e["$"+s]=n,console.log("Property : "+s+" existed in node: "+e.tagName+". Using $"+s+" instead for node: "+n.tagName+".")):e[s]=this.proxy(n)}appendElement(e,s){const n=t.utils.newElement(s);return e.append(n),n}getItem(e,t,s,n){n||(n=this.getTemplate(e));const i=n.cloneNode(!0);this.addTemplatesToItem(n,i),i.dataset.id=t,this.setUniqueAttrib(i,"selected");let o=this.doDom(i,s);return this.getItemWithEvents(e,o)}addTemplatesToItem(e,t){["_template","__template"].forEach(s=>{void 0!==e[s]&&(t[s]=e[s])})}getItemWithEvents(e,s){if(void 0!==e.__template){const n=(e,s)=>(s=s||{},Object.keys(e).forEach(i=>{t.utils.isPlainObject(e[i])?s[i]=n(e[i]):t.utils.isFunction(e[i])&&(s[i]=e[i])}),s);let i=n(e.__template);t.utils.isEmpty(i)||(i=i[Object.keys(i)[0]],s=this.doDom(s,i))}return s}doItems(e,t,s){const n=this.getTemplate(e,s);if(void 0===n)return console.error("Template not found. Probably an array is being used where it is not expected. Node:"),console.log(e),console.log("Value (mistaken?):"),void console.log(t);let i=0;t.forEach(t=>{t=this.plainToObject(e,t);const s=this.getItem(e,i++,t,n);s&&e.append(s)});const o=e.find("template");o&&e.removeChild(o),e.items=e.children,this.extendItems(e)}getTemplate(e,s){if(void 0!==e._template&&""!==e._template)return e._template;{let n;const i=e.querySelector("template");if(i)n=t.utils.htmlElement(i.innerHTML.trim());else switch(e.tagName){case"SELECT":case"DATALIST":n=t.utils.newElement("option");break;case"UL":case"OL":n=t.utils.newElement("li");break;case"NAV":n=t.utils.newElement("a");break;case"DL":n=t.utils.newElement("dd");break;default:if(s){const i=Object.keys(s).length;if(i){if(i>1)if(void 0!==s.tagName){let e={};e[s.tagName]=s,s=e}else console.log("Template has more than one top elements. Using the first one. In: "),console.log(s),console.log("Node: "),console.log(e);const o=Object.keys(s)[0],l=s[o];t.utils.isValidElement(o)?n=t.utils.newElement(o):void 0!==l.tagName?(n=t.utils.newElement(l.tagName),s[l.tagName]=l,delete s[o]):(console.error("Template defined an element which can not be identified: ["+o+"], using in:"),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span"))}else console.error("Template has no definition, and it can not be guessed. Using . Template: "),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span")}else e.childElementCount>0&&(n=t.utils.htmlElement(e.innerHTML.trim()))}if(s)if(t.utils.isPlainObject(s)){const i=t.utils.newEmptyNode();i.append(n),n=this.doDom(i,s).children[0],t.utils.defineProp(e,"__template",s)}else n=t.utils.isHtml(s)?t.utils.htmlElement(s):t.utils.isSelectorID(s)?t.utils.htmlElement(document.querySelector(s).innerHTML):t.utils.newElement(s);if(n.childrenElementCount>1){console.log("Templates only supports a single child. Multiple children were detected, wrapping them with . Template:"),console.log(n);const e=t.utils.newElement("span");e.append(n),n=e}return n&&t.utils.defineProp(e,"_template",n),n}}setUniqueAttrib(e,s){e.hasOwnProperty(s)||Object.defineProperty(e,s,{get:function(){return this.hasAttribute(s)},set:function(e){const n=this.parentNode?this.parentNode.find("["+s+"]"):null;n&&n.removeAttribute(s),t.utils.setAttr(this,s,e)}})}updateValue(e,s,n){if(this.isUpdateLink(n)){const i=this,o=n[0],l=n[1],a=n[2];if(n=o[l],o instanceof CSSStyleDeclaration&&this._stored.styles.includes(o)){const n=this._stored.styleNodes[this._stored.styles.indexOf(o)];t.updates&&(n.onupdate=function(t){t.detail&&"style"===t.detail.property&&t.detail.newValue.startsWith(l+":")&&i.setShortValue(e,s,a(this.style[l]))})}else if(o instanceof DOMStringMap&&this._stored.datasets.includes(o)){const n=this._stored.datasetNodes[this._stored.datasets.indexOf(o)];t.updates&&(n.onupdate=t=>{t.detail&&t.detail.property==="data-"+l&&i.setShortValue(e,s,a(t.detail.newValue))})}else t.updates&&(o.onupdate=n=>{n.detail&&n.detail.property===l&&(t.utils.isObject(e[s])||i.setShortValue(e,s,a(n.detail.newValue)))})}return n}setShortValue(e,s,n){if(t.utils.isNode(e[s]))if(t.short){const i=this.plainToObject(e[s],n),o=t.utils.isPlainObject(i)&&Object.keys(i).length>=1?Object.keys(i)[0]:null;o&&(e[s][o]=n)}else console.log("Short is disabled. Trying to set a value ("+n+") in a node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else e[s]=n}getShortValue(e,s,n){let i=null;if(t.utils.isNode(e[s]))if(t.short){const o=this.plainToObject(e[s],n||""),l=t.utils.isPlainObject(o)&&Object.keys(o).length>=1?Object.keys(o)[0]:null;l&&(i=e[s][l])}else console.log("Short is disabled. Trying to get a value from node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else i=e[s];return i}proxy(e,s){return!t.short||null===e||void 0!==e._proxy&&void 0===s?e:(e._proxy=e,new Proxy(e,{get:(e,s)=>{const n=e[s];switch(!0){case null==n:return null;case t.utils.isFunction(n):return n.bind(e);case n._proxy&&void 0!==e["$"+s]:return e["$"+s];case void 0===n._proxy&&t.utils.isElement(n):return this.proxy(n);default:return n}},set:(e,s,n)=>{let i="";return t.utils.isElement(e[s])?(i=this.getShortValue(e,s,n),this.setShortValue(e,s,n)):"onupdate"===s?t.updates?t.utils.isFunction(n)?(e.addEventListener("update",n,!0),i=e[s],e[s]=n):(console.error("Value passed to 'onupdate' is incorrect, in node:"),console.log(e),console.log("Value: (not a function)"),console.log(n)):(console.log("Updates are not available when `m2d2.updates == false`:"),console.log(e)):"items"===s?(e.items.clear(),this.doItems(e,n)):(i=e[s],n=this.updateValue(e,s,n),e[s]=n),t.updates&&void 0!==e.onupdate&&n!==i&&e.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:s,newValue:n,oldValue:i}})),!0}}))}onObserve(e,s){e.forEach(e=>{const s=e.target;if(!(this._stored.events.indexOf(e)>=0)&&(this._stored.events.push(e),setTimeout(()=>{const t=this._stored.events.indexOf(e);t>=0&&this._stored.events.splice(t,1)},t.storedEventsTimeout),void 0!==s.onupdate))if("attributes"===e.type){const n=t.utils.getAttrOrProp(s,e.attributeName);n!==e.oldValue&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:e.attributeName,newValue:n,oldValue:e.oldValue}}))}else if("childList"===e.type)if("#text"===(e.addedNodes[0]||e.removedNodes[0]).nodeName){const t=e.addedNodes[0].textContent,n=e.removedNodes.length?e.removedNodes[0].textContent:null;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"text",newValue:t,oldValue:n}}))}else if(void 0!==s.items){const t=e.addedNodes,n=e.removedNodes;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"items",newValue:t,oldValue:n}}))}})}observe(e){if(t.updates){const t=new MutationObserver(this.onObserve.bind(this)),s={attributeOldValue:!0,subtree:!0,childList:!0},n=e._proxy||e;t.observe(n,s)}}getProxyNode(e,t){const s=this.doDom(e,t);if(s)return this.observe(s),this.proxy(s)}extendItems(e){function s(t){t.forEach(t=>{const s=t.parentNode.removeChild(t);e.append(s)})}const n=e.items;Object.getOwnPropertyNames(Array.prototype).concat(["clear","get","remove","selected","first","last","findAll"]).forEach(i=>{if(void 0===n[i]){let o=null;const l=this;switch(i){case"copyWithin":case"fill":case"splice":o=function(){console.log("Not available yet: "+i)};break;case"reverse":o=function(...e){if(this.items.length){const t=Array.from(this.items),n=t[i](...e);return s(t),n}};break;case"clear":o=function(){for(;this.items[0];)this.items[0].remove()};break;case"get":o=function(e){let s=null;return this.items.length&&this.items.some(n=>{const i=t.utils.isNumeric(e)?1*n.dataset.id==1*e:n.dataset.id===e;if(n.dataset&&i)return s=n,!0}),s};break;case"selected":o=function(){return l.proxy(this.find(":scope > [selected]"))};break;case"first":o=function(){return l.proxy(this.items[0])};break;case"last":o=function(){return l.proxy(this.items[this.items.length-1])};break;case"pop":o=function(){if(this.items.length){const e=this[0].parentNode;return l.proxy(e.removeChild(this.items[this.items.length-1]))}};break;case"push":o=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.append(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.appendChild(s)}else console.log("Trying to push an unknown value into a list:"),console.log(e)};break;case"remove":o=function(e){if(this.items.length){const t=this.items.get(e);1===t.length&&t.remove()}};break;case"shift":o=function(){if(this.items.length){const e=this.items[0].parentNode;return l.proxy(e.removeChild(this.items[0]))}};break;case"sort":o=function(e){if(this.items.length){const t=Array.from(this.items);t.sort(e||((e,t)=>e.text.localeCompare(t.text))),s(t)}};break;case"unshift":o=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.prepend(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.prepend(s)}else console.log("Trying to unshift an unknown value into a list:"),console.log(e)};break;default:let n=i;switch(!0){case"findAll"===i:n="filter";case t.utils.isFunction(Array.prototype[i]):const s=function(...t){const s=[];return Array.from(e.items).forEach(e=>{s.push(l.proxy(e))}),Array.from(s)[n](...t)};switch(i){case"find":o=function(...e){return t.utils.isString(e[0])?this.find(e[0]):s(...e)};break;case"findAll":o=function(...e){return 0===e.length?this.findAll():t.utils.isString(e[0])?this.findAll(e[0]):s(...e)};break;case"concat":o=function(...e){for(let s=0;s{function t(t){e.exists("#m2d2-alert .m2d2-alert-front")?(e("#m2d2-alert .m2d2-alert-front").css.add("vanish"),setTimeout(()=>{e.exists("#m2d2-alert .m2d2-alert-front")&&e("#m2d2-alert").remove(),t&&t()},400)):t&&t()}const s={wrap:!1,question:["fa","fa-question-circle"],info:["fa","fa-exclamation-circle"],error:["fa","fa-exclamation-triangle"],ok:["fa","fa-check"],input:["fa","fa-edit"],wait:["fa","fa-cog","fa-spin"]},n={wrap:"material-icons",question:"help",info:"info",error:"error",ok:"done",input:"edit",wait:"pending"},i={wrap:!1,question:"icon_question",info:"icon_info",error:"icon_error",ok:"icon_ok",input:"icon_input",wait:"icon_wait"};e.message=function(o){let l=i;switch(e.messageIcons){case"fa":l=s;break;case"material":l=n;break;default:e.isObject(e.messageIcons)&&(l=e.messageIcons)}o&&(e.isFunction(o.callback)||(o.callback&&!o.text&&(o.text=o.callback),o.callback=()=>{}),o.text||(o.text="")),t(()=>{e("body",{m2d2Alert:{tagName:"div",id:"m2d2-alert",back:{tagName:"div",css:"m2d2-alert-back",style:{position:"absolute",left:0,right:0,top:0,bottom:0,backgroundColor:"#0005",display:"flex",justifyContent:"center",alignItems:"center"},front:Object.assign({tagName:"form",css:(o.css?e.isArray(o.css)?o.css:[o.css]:[]).concat(["m2d2-alert-front","popup",o.icon]),style:{zIndex:100},icon:{tagName:"span",css:["icon",o.icon].concat(l.wrap?[l.wrap]:l[o.icon]).concat("wait"===o.icon?"spin":""),text:l.wrap?l[o.icon]:""},message:{tagName:"div",css:"m2d2-alert-title",span:o.title},submsg:(()=>{let t;return t="input"!==o.icon||o.text?e.isPlainObject(o.text)?{fieldset:Object.assign({css:"m2d2-alert-field"},o.text)}:{span:o.text.replace("\n","
")}:{fieldset:{css:"m2d2-alert-field",input:{type:"text",name:"answer",onload:function(){this.focus()}}}},Object.assign({tagName:"div",css:"m2d2-alert-text"},t)})(o.icon),onsubmit:function(){const e=this.getData();let s;switch(e.button){case"ok":case"yes":s=()=>{o.callback(!0,e)};break;case"no":s=()=>{o.callback(!1,e)};break;case"cancel":s=()=>{o.callback(null,e)};break;case"send":s=1===Object.keys(e).length?()=>{o.callback(e[Object.keys(e)[0]],e)}:2===Object.keys(e).length?()=>{o.callback(e[Object.keys(e).find(e=>"button"!==e)],e)}:()=>{o.callback(e,e)};break;default:s=()=>{o.callback(e,e)}}return t(s),!1},onload:function(){const e=this.find("[autofocus]");e&&e.focus()}},function(t){let s={};return t.length&&(s={buttons:{tagName:"div",css:"m2d2-alert-buttons"}},t.forEach(t=>{const n=t.toLowerCase().replace(/[^a-z ]/g,"").replace(" ","_");s.buttons[n]={tagName:"button",type:"submit",value:n,css:["color",n],text:void 0!==e.dict?e.dict(t):t,autofocus:["ok","yes"].includes(t),formNoValidate:["cancel"].includes(t),onclick:function(){e(this.closest("form"),{hide:{tagName:"input",type:"hidden",name:"button",value:this.value}})}}})),s}(o.buttons))}}})});let a=1;return e("#m2d2-alert .m2d2-alert-front").findAll("input, select, textarea").forEach(e=>{""===e.name&&(e.name="field_"+a++)}),{close:t}},e.wait=(t,s,n)=>e.message({icon:"wait",title:t,buttons:[],text:void 0===n?null:s,callback:void 0===n?s:n}),e.alert=(t,s,n)=>e.message({icon:"info",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.success=(t,s,n)=>e.message({icon:"ok",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.failure=(t,s,n)=>e.message({icon:"error",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.confirm=(t,s,n)=>e.message({icon:"question",title:t,buttons:["yes","no"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.prompt=(t,s,n)=>e.message({icon:"input",title:t,buttons:["cancel","send"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.closeAll=()=>{t()}}),t.load(e=>{let t=localStorage.getItem("m2d2.lang")||navigator.language;e.dict=new function(t){const s=function(e,t){if(void 0===e)return"";let n=s.val(e,!0);if(void 0!==t){if("string"==typeof t&&""!==t){const e=(t=t.replace(/;$/,"")).split(";");t={},e.forEach(s=>{const n=e[s].split(":");t[n[0]]=n[1]})}"object"==typeof t&&t.forEach(e=>{let i=t[e]+"";i=s.val(i,!1),n=n.replace(e,i)})}return n};return s.lang=t||"en",s.data={},s.set=function(e){return this.data=e,this},s.has=function(e,t){return void 0===t?void 0!==this.data[e]:void 0!==this.data[e][t]},s.val=function(t,n){if(e.isEmpty(s.data))return console.error("Dictionary is empty. You need to add a dictionary, for example: `$.dict.set({\nsave : { en : 'Save', es : 'Guardar' },\ncancel : { en : 'Cancel', es : 'Cancelar' }\nyes : { en : 'Yes', es : 'Si' },\nno : { en : 'No', es : 'No' }\n})`"),"";if(!t)return console.error("No keyword specified."),"";let i=t;if(void 0===n&&(n=!1),t=t.toLowerCase(),this.has(t)){const e=this.lang.split("-")[0];this.has(t,this.lang)?i=this.data[t][this.lang]:this.has(t,e)?i=this.data[t][e]:n&&console.log("Missing translation for lang ["+this.lang+"]: "+t)}else n&&console.log("Missing keyword: "+t);return i},s}(t);const s=[];e.lang=function(t){t&&(e.dict.lang=t,localStorage.setItem("m2d2.lang",e.dict.lang)),e("body").findAll("[lang]").forEach(t=>{let s=t.text;if(s&&!t.classList.contains("notxt")){void 0===t.dataset.kw&&(t.dataset.kw=e.lang.getKeyword(s)),t.text=e.dict(t.dataset.kw);const n=t.dataset.kw+"_title";let i=e.dict.has(n)?e.dict(n):"";i&&(t.title=i)}else if(t.title){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.title)),s=e.dict(t.dataset.kw),s&&(t.title=s)}else if(t.placeholder){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.placeholder)),s=e.dict(t.dataset.kw),s&&(t.placeholder=s)}else if(t.value){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.value)),s=e.dict(t.dataset.kw),s&&(t.value=s)}}),s.forEach(e=>{e(t)})},e.lang.getKeyword=function(e){return e.toLowerCase().trim().replace(/ /g,"_").replace(/[^\w]/g,"").replace(/_$/,"")},Object.defineProperty(e.lang,"onchange",{get(){return this},set(t){e.isFunction(t)?s.push(t):(console.log("Unable to set lang.onchange, because it is not a function: "),console.log(t))}})}),t.ready(e=>{const t=localStorage.getItem("m2d2.lang")||"",s=e("body").find("[lang]"),n=e("html").lang||(s?s.lang:null)||"en";(t?n!==t:n!==navigator.language.split("-")[0])&&e.lang()}),t.load(e=>{function t(e){switch(e){case"local":window.localStorage&&(this.store=localStorage);break;case"session":window.sessionStorage&&(this.store=sessionStorage)}null==this.store&&(this.store=localStorage),this.set=function(e,t){"string"==typeof t&&(t={$:t}),this.store.setItem(e,JSON.stringify(t))},this.get=function(e){let t;try{t=JSON.parse(this.store.getItem(e))||{}}catch(s){t=this.store.getItem(e)}return void 0!==t.$?t=t.$:0===Object.keys(t).length&&t.constructor===Object&&(t=null),t},this.del=function(e){this.store.removeItem(e)},this.keys=function(){return Object.keys(this.store).sort()},this.clear=function(){this.store.clear()},this.exists=function(e){return this.store.hasOwnProperty(e)},this.log=function(e,t,s){null==s&&(s=10);const n=this.get(e)||[];for(n.push(t);n.length>s;)n.shift();this.set(e,n)}}e.local=new t("local"),e.session=new t("session")}),t.load(e=>{function t(e,t,s){const n=[];return e=e||{},t.forEach(i=>{const o="Array"==typeof e?e.length==t.length?e[s]:e:void 0!==e[i.name]?e[i.name]:e;n.push({file:i,data:o,index:s++})}),n}function s(e,t,s,n,i){const o=new XMLHttpRequest;t=Array.from(t),o.upload.addEventListener("progress",(function(e){if(e.lengthComputable)if(n.oneByOne){const i=Math.round(100*e.loaded/e.total);n.onUpdate(i,t[0],s)}else{let s=0,i=0;t.some(t=>{s+=t.size;const o=e.loaded>=s?100:100-Math.round(100*(s-e.loaded)/t.size);return n.onUpdate(o,t,i++),s>=e.loaded})}}),!1),o.addEventListener("load",(function(e){let l={};try{l=o.responseText?JSON.parse(o.responseText):{error:{type:"Unknown",reason:"Unknown Error"}}}catch(e){l.error={type:"Parse Error",reason:e.message}}o.status>=200&&o.status<400?i(n.onResponse(l),t,s):("string"==typeof l.error&&(l.error={type:"Exception",reason:l.error}),n.onError(l.error))}),!1),o.open("POST",n.upload);const l=Array(t.length).fill(!1),a=function(e,t){const s=new FormData;return t.forEach(t=>{s.append(e,t,t.name)}),s}(e,t);let r=0;t.forEach(e=>{const t=new FileReader;t.onload=function(e){l[r++]=!0,-1===l.indexOf(!1)&&o.send(a)},t.readAsBinaryString(e)})}e.upload=function(e,n){const i=Object.assign({},{accept:"*/*",parallel:!1,field:"file",multiple:!0,maxFiles:0,maxSizeMb:0},n);n=null;let o=window._protected_reference=document.createElement("INPUT");o.name=i.field,o.type="file",1==i.multiple&&(o.multiple="multiple"),i.upload||(console.log("Upload not specified. Using current page."),i.upload=""),null==i.onDone&&(i.onDone=(e,t)=>{console.log(e)}),null==i.onError&&(i.onError=e=>{console.log("Error : "),console.log(e)}),null==i.onUpdate&&(i.onUpdate=(e,t,s)=>{console.log("Uploading : "+e+"% "+(i.oneByOne?"[ "+t.name+" ]":""))}),null==i.onResponse&&(i.onResponse=e=>e),o.addEventListener("change",()=>{if(o.files.length){if(!(0===i.maxFiles|o.files.length<=i.maxFiles))return i.onError("Max file limit exceeded. Maximum files: "+i.maxFiles),!1;if(i.onSelect){const e=[];let t=0;Array.from(o.files).forEach(s=>{e.push(URL.createObjectURL(s)),t+=s.size});const s=t/1048576;if(i.maxSizeMb&&s>i.maxSizeMb)return i.onError("Maximum size exceeded: "+Math.ceil(s)+"MB > "+i.maxSizeMb+"MB"),!1;i.onSelect(o.files,e)}new Promise(e=>{if(i.oneByOne){let n=0;const l=Array(o.files.length).fill(!1);Array.from(o.files).forEach(a=>{new s(o.name,[a],n++,i,(s,n,o)=>{l[o]=!0;const a=-1===l.indexOf(!1);i.onDone(t(s,n,o),a),a&&e()})})}else new s(o.name,o.files,0,i,(s,n,o)=>{i.onDone(t(s,n,o),!0),e()})}).then(()=>{o=window._protected_reference=void 0})}}),o.click()}}),t.load(e=>{e.ws=new class{request(e){if(e)try{this.webSocket.send(JSON.stringify(e))}catch(e){this.webSocket.onerror(e)}}getSocket(e,t,s){const n=new WebSocket(this.path);return n.onopen=t,n.onclose=s,n.onmessage=t=>{if(t.data)try{e(JSON.parse(t.data))}catch(e){n.onerror(e)}},n.onerror=e=>{console.error("Socket encountered error: ",e?e.message:"Unknown","Closing socket");const t=n||this;1===t.readyState&&t.close()},n}connect(e,t){this.initRequest=e.request||null,this.onConnect=e.connected||(()=>{}),this.onDisconnect=e.disconnected||(()=>{}),this.reconnect=!1!==e.reconnect,this.host=e.host||window.location.hostname,this.secure=!0===e.secure,this.port=e.port||(this.secure?443:80),this.path="ws"+(this.secure?"s":"")+"://"+this.host+":"+this.port+"/"+(e.path||""),this.connected=!1,this.interval=null;const s=e=>{this.connected=!0,this.request(this.initRequest),this.onConnect()},n=e=>{this.connected=!1,this.onDisconnect(),!this.interval&&this.reconnect&&(this.interval=setInterval(()=>{if(this.connected)console.log("Reconnected..."),clearInterval(this.interval),this.interval=null;else try{this.webSocket.close(),console.log("Reconnecting..."),this.webSocket=this.getSocket(t,s,n)}catch(e){}},2e3))};this.webSocket=this.getSocket(t,s,n)}disconnect(){this.reconnect=!1,this.webSocket.close()}}}),t})); \ No newline at end of file diff --git a/dist/m2d2.bundle.xhr.min.js b/dist/m2d2.bundle.xhr.min.js index 1694a6c..f309a41 100644 --- a/dist/m2d2.bundle.xhr.min.js +++ b/dist/m2d2.bundle.xhr.min.js @@ -1,9 +1,9 @@ /** * Author : A.Lepe (dev@alepe.com) - intellisrc.com * License: MIT - * Version: 2.1.1 - * Updated: 2022-02-24 + * Version: 2.1.2 + * Updated: 2022-03-07 * Content: XHR Bundle */ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.m2d2=t()}(this,(function(){"use strict";class e{isString(e){return"string"==typeof e}isBool(e){return"boolean"==typeof e}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isSelectorID(e){return 0===(e+"").trim().indexOf("#")}isPlainObject(e){return"Object"===e.constructor.name}isObject(e){return"object"==typeof e}isArray(e){return Array.isArray(e)}isFunction(e){return"function"==typeof e}isElement(e){return e instanceof HTMLElement}isNode(e){return e instanceof Node||e instanceof DocumentFragment}isHtml(e){return-1!==(e+"").trim().indexOf("<")}isEmpty(e){return void 0===e||this.isObject(e)&&0===Object.keys(e).length||""===e}isVisible(e){if(!this.isElement(e))return console.log("(isVisible) Not an element: "),console.log(e),!1;const t="none"!==e.style.display,s="hidden"!==e.style.visibility;return t&&s}inView(e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)&&t.width>0&&t.height>0}cleanArray(e){return e.filter((function(e){return 0===e||e}))}isValidElement(e){const t=this.newElement(e);return"template"!==e&&"HTMLUnknownElement"!==t.constructor.name}exists(e){return null!==document.querySelector(e)}getAttrOrProp(e,t){let s="";return this.hasAttrOrProp(e,t)&&(s=this.hasAttr(e,t)?e.getAttribute(t):e[t]),s}hasAttrOrProp(e,t){return this.hasAttr(e,t)||this.hasProp(e,t)}hasAttr(e,t){let s=!1;if(e&&!this.isNumeric(t))switch(t){case"checked":s=void 0!==e.type&&("radio"===e.type||"checkbox"===e.type);break;default:s=void 0!==e.hasAttribute&&e.hasAttribute(t)}return s}hasProp(e,t){let s=!1;if(e&&!this.isNumeric(t)){let n=void 0!==e[t];n&&null===e[t]&&"value"===t&&(n=!1),s=n&&!(e[t]instanceof Node)&&!e.hasAttribute(t)}return s}setPropOrAttr(e,t,s){if(this.hasProp(e,t))try{e[t]=s}catch(n){this.setAttr(e,t,s)}else this.setAttr(e,t,s)}setAttr(e,t,s){s?e.setAttribute(t,s):e.removeAttribute(t)}defineProp(e,t,s){this.isObject(e)&&void 0===e[t]&&(Object.defineProperty(e,t,{enumerable:!1,writable:!0}),e[t]=s)}htmlElement(e){const t=this.newElement("template");return t.innerHTML=e.trim(),t.content.firstChild}newElement(e){return document.createElement(e)}newEmptyNode(){return new DocumentFragment}getMethods(e){const t=Reflect.getPrototypeOf(e),s=Reflect.getPrototypeOf(t);return Reflect.ownKeys(t).filter(e=>Reflect.ownKeys(s).indexOf(e)<0)}appendAllChild(e,t){for(;e.firstChild;)t.append(e.firstChild)}prependAllChild(e,t){for(;e.firstChild;)t.prepend(e.firstChild)}}class t{"use strict";_stored={events:[],datasetNodes:[],datasets:[],styleNodes:[],styles:[]};static storedEventsTimeout=50;static short=!0;static updates=!0;static utils=new e;constructor(){}static instance=new t;static extensions={};static main=(()=>{const e=(e,s)=>{const n=this.instance.getProxyNode(e,s);return n&&n.onready&&t.utils.isFunction(n.onready)&&(n.addEventListener("ready",n.onready,{once:!0}),setTimeout(()=>{n.dispatchEvent(new CustomEvent("ready"))},10)),["dataset","style"].forEach(e=>{n&&n[e]&&(this.instance._stored[e+"s"].push(n[e]),this.instance._stored[e+"Nodes"].push(n))}),n};return t.utils.getMethods(t.utils).forEach(s=>{e[s]=t.utils[s]}),e})();static ready(e){document.addEventListener("DOMContentLoaded",()=>{e(t.main)})}static load(e){if(void 0!==e){const s=e(t.main);t.utils.isObject(s)&&!t.utils.isEmpty(s)&&Object.keys(s).forEach(e=>{if(t.utils.isValidElement(e)){void 0===t.extensions[e]&&(t.extensions[e]={});const n=t.utils.newElement(e);Object.keys(s[e]).forEach(s=>{t.utils.hasProp(n,s)&&console.log("Warning: property ["+s+"] already exists in node: ["+e+"] while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions[e],s[e])}else{void 0===t.extensions["*"]&&(t.extensions["*"]={});const n=t.utils.newElement("div");Object.keys(s[e]).forEach(e=>{t.utils.hasProp(n,e)&&console.log("Warning: property ["+e+"] already exists in Node while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions["*"],s[e])}})}return t.main}extDom(e,s){if(!e)return console.error("Selector was empty"),null;void 0===s&&(s=document);const n=t.utils.isNode(e)?e:s.querySelector(e);if(!n)return t.utils.isString(e)?(console.error("Selector: "+e+" didn't match any element in node:"),console.log(s)):console.error("Node was null"),null;if(void 0===n._m2d2){n._m2d2=!0,["parent","sibling","next","prev","find","findAll","onupdate","onready","show","onshow","inView","css","text","html","getData","index"].forEach(e=>{n.hasOwnProperty(e)&&(console.log("Node already had ["+e+"] property. It might cause unexpected behaviour."),console.log("You may need to update the M2D2 version or report it to: github.com/intellisrc/m2d2/"))}),Object.defineProperty(n,"text",{get(){return this.childNodes.length?this.innerText:this.textContent},set(e){if(this.childNodes.length){let t=!1;this.childNodes.forEach(s=>{"Text"===s.constructor.name&&(s.nodeValue=e,t=!0)}),t||this.prepend(document.createTextNode(e))}else this.textContent=e}}),Object.defineProperty(n,"html",{get(){return this.innerHTML},set(e){this.innerHTML=e}}),Object.defineProperty(n,"css",{get(){return this.classList},set(e){t.utils.isArray(e)?this.className=e.join(" "):t.utils.isString(e)?this.className=e:t.utils.isPlainObject(e)?Object.keys(e).forEach(t=>{e[t]?this.classList.add(t):this.classList.remove(t)}):console.error("Trying to assign a wrong value to css : "+e)}}),Object.defineProperty(n,"show",{get(){return t.utils.isVisible(this)},set(e){const s=()=>getComputedStyle(this,null).display,n=()=>{const e=document.getElementsByTagName("body")[0],t=document.createElement("template"),s=document.createElement(this.tagName);t.append(s),e.append(t);const n=getComputedStyle(s,null).display;return t.remove(),n};if(e){if("none"===s()){if(this._m2d2_display)this.style.display=this._m2d2_display;else if(this.style.removeProperty("display"),"none"===s()){const e=n();this.style.display=this.dataset.display||("none"!==e?e:"block")}void 0!==this.onshow&&t.utils.isFunction(this.onshow)&&this.onshow(this)}}else{const e="none"!==this.style.display?this.style.display:s();"none"!==e&&(this._m2d2_display=e),this.style.display="none"}}});let e={};return void 0!==t.extensions["*"]&&Object.assign(e,t.extensions["*"]),void 0!==t.extensions[n.tagName]&&Object.assign(e,t.extensions[n.tagName]),Object.assign(n,{inView:()=>t.utils.inView(n),next:()=>n.nextElementSibling,prev:()=>n.previousElementSibling,parent:()=>this.extDom(n.parentElement),sibling:e=>n.parentElement.find(e),find:e=>{const t=n.querySelector(e);return t?this.extDom(t):null},findAll:e=>{const t=void 0===e?Array.from(n.children):n.querySelectorAll(e);return t.forEach(e=>{this.extDom(e)}),t}},e),void 0===n.index&&(n.index=()=>Array.from(n.parentNode.children).indexOf(n)),["INPUT","TEXTAREA","SELECT"].indexOf(n.tagName)>=0&&t.utils.hasAttrOrProp(n,"value")&&(n.oninput=function(){this.setAttribute("value",this.value)}),"FORM"===n.tagName&&(n.getData=function(e){const t={},s=new FormData(this),o=e||!1;for(let e of s.entries()){const s=n.find("[name='"+e[0]+"']");(o||"hidden"===s.type||s.show)&&(t[e[0]]="file"===s.type?s.files:e[1])}return t}),n}return n}doDom(e,s){if(t.utils.isObject(e)&&void 0===s&&(s=e,e=t.utils.newEmptyNode(),void 0===s.warn&&(s.warn=!1)),!(t.utils.isString(e)||t.utils.isElement(e)||t.utils.isNode(e)))return console.error("Selector is not a string or a Node:"),console.log(e),null;if(t.utils.isString(e)&&!document.querySelector(e))return console.log("Selected element doesn't exists: "+e),null;const n=this.extDom(e);if(void 0===s)return n;if(s=this.plainToObject(n,s),Object.keys(s).filter(e=>!["tagName"].includes(e)).forEach(e=>{let o=s[e];null==o&&(console.log("Value was not set for key: "+e+", 'empty' was used in object: "),console.log(s),console.log("In node:"),console.log(n),o="");let i=this.updateValue(n,e,o),l=t.utils.hasProp(n,e),a=!1;if(t.utils.hasAttr(n,e)||l)switch(!0){case"value"===e&&t.utils.hasProp(n,"valueAsDate")&&i instanceof Date:e="valueAsDate";case"css"===e:case typeof i==typeof n[e]:case t.utils.isString(n[e])&&t.utils.isNumeric(i):case t.utils.isFunction(i)&&t.utils.isObject(n[e]):case t.utils.isBool(i)&&t.utils.isString(n[e]):case"object"==typeof n[e]&&"INPUT"===n.tagName:a=!0}if(a){let s=!1;switch(e){case"classList":t.utils.isArray(i)?i.forEach(t=>{n[e].add(t)}):t.utils.isString(i)?n[e].add(i):s=!0;break;case"style":case"dataset":t.utils.isPlainObject(i)?Object.keys(i).forEach(t=>{n[e][t]=this.updateValue(n[e],t,i[t])}):s=!0;break;default:switch(!0){case t.utils.isBool(i):case t.utils.hasAttrOrProp(n,e):t.utils.setPropOrAttr(n,e,i);break;default:n[e]=i}}s&&(console.error("Invalid value passed to '"+e+"': "),console.log(i),console.log("Into Node:"),console.log(n))}else{const l=[];try{if("template"!==e&&!t.utils.isFunction(i)){if(e&&e.match(/^\w/)){let t=n.find("#"+e);t&&-1===l.indexOf(t)&&l.push(t),t=n.find("[name='"+e+"']"),t&&-1===l.indexOf(t)&&l.push(t);const s=Array.from(n.findAll("."+e)).filter(e=>l.indexOf(e)<0);s.length>0&&s.forEach(e=>l.push(e))}const t=Array.from(n.findAll(e)).filter(e=>l.indexOf(e)<0);t.length>0&&t.forEach(e=>l.push(e))}}catch(t){return console.error("Invalid selector: "+e),void console.log(t)}if(l.length>1){const t=[];l.forEach(s=>{t.push(this.render(s,e,i))}),this.linkNode(n,e,t),void 0!==i.warn&&!1===i.warn||(console.log("Multiple elements were assigned with key: ["+e+"] under node: "),console.log(n),console.log("It might be what we expect, but if it is not expected it could result on some elements mistakenly rendered. You can specify 'warn : false' under that element to hide this message."))}else if(1===l.length){const a=l[0];if(t.utils.isElement(a)){const l=this.plainToObject(a,i),r=t.utils.isPlainObject(l)&&Object.keys(l).length>=1?Object.keys(l)[0]:null;if(r&&(i=this.updateValue(a,r,o)),t.utils.isArray(i)){const t=s.template;this.doItems(a,i,t),this.linkNode(n,e,a)}else this.renderAndLink(n,a,e,i)}else console.error("BUG: It should have been a node but got: "),console.log(a),console.log("Parent node:"),console.log(n)}else if(0===l.length){"template"===e&&void 0===s.items&&(e="items",i=[]);const o=t.utils.isFunction(i);if(void 0!==i.tagName){const t=this.appendElement(n,i.tagName);this.renderAndLink(n,t,e,i)}else if(t.utils.isValidElement(e)&&!o){const t=this.appendElement(n,e);this.renderAndLink(n,t,e,i)}else if("items"===e){const e=s.template;if(t.utils.isPlainObject(i)){const e=[];Object.keys(i).forEach(s=>{let o;"DL"===n.tagName?o={dt:s,dd:i[s]}:(o={text:i[s]},t.utils.hasAttrOrProp(n,"value")?o.value=s:o.dataset={id:s}),e.push(o)}),i=e}t.utils.isArray(i)?this.doItems(n,i,e):(console.log("Warning: 'items' specified but value is not and array, in element: "),console.log(n),console.log("Passed values are: "),console.log(i))}else o?(t.updates&&"onupdate"===e&&n.addEventListener("update",i,!0),n[e]=i):"template"!==e&&"warn"!==e&&!1!==i&&(void 0!==s.warn&&!1===s.warn||(console.error("Not sure what you want to do with key: "+e+" under element: "),console.log(n),console.log("And object:"),console.log(s),console.log("Most likely the element's property or child no longer exists or the value passed to it is incorrect."),console.log("You can set 'warn : false' property to the element to dismiss this message.")),n[e]=i)}}}),n.onload){const e=["BODY","FRAME","IFRAME","IMG","LINK","SCRIPT","STYLE"].indexOf(n.tagName)>=0,t="INPUT"===n.tagName&&"image"===n.type;e||t||n.dispatchEvent(new CustomEvent("load"))}return n}isUpdateLink(e){let s=!1;if(t.utils.isArray(e)&&(2===e.length||3===e.length)){const n=2===e.length,o=t.utils.isNode(e[0])||e[0]instanceof DOMStringMap||e[0]instanceof CSSStyleDeclaration,i=n?t.utils.isString(e[1]):t.utils.isString(e[1])&&t.utils.isFunction(e[2]);s=o&&i,s&&n&&e.push(e=>e)}return s}plainToObject(e,s){if(!t.utils.isPlainObject(s)&&!t.utils.isFunction(s)&&!t.utils.isElement(s))if(t.utils.isHtml(s))s={html:s};else if(this.isUpdateLink(s)){const n=s[0],o=s[1],i=s[2];let l=this.plainToObject(e,i(n[o]));if(t.utils.isPlainObject(l)){const e={};Object.keys(l).forEach(t=>{e[t]=s}),s=e}}else t.utils.isArray(s)?s={items:s}:t.utils.hasAttrOrProp(e,"value")?s="SELECT"===e.tagName?{value:s,text:s}:"BUTTON"===e.tagName?{text:s}:{value:s}:t.utils.isString(s)&&"IMG"===e.tagName?s={src:s}:(t.utils.isString(s)||t.utils.isNumeric(s))&&(s={text:s});return s}renderAndLink(e,t,s,n){const o=this.render(t,s,n);this.linkNode(e,s,o)}render(e,t,s){return s=this.plainToObject(e,s),this.doDom(e,s)}linkNode(e,s,n){if(e[s]===n){const t=this.proxy(n);try{e[s]=t}catch(e){}e["$"+s]=t}else t.utils.hasAttrOrProp(e,s)?(e["$"+s]=n,console.log("Property : "+s+" existed in node: "+e.tagName+". Using $"+s+" instead for node: "+n.tagName+".")):e[s]=this.proxy(n)}appendElement(e,s){const n=t.utils.newElement(s);return e.append(n),n}getItem(e,t,s,n){n||(n=this.getTemplate(e));const o=n.cloneNode(!0);this.addTemplatesToItem(n,o),o.dataset.id=t,this.setUniqueAttrib(o,"selected");let i=this.doDom(o,s);return this.getItemWithEvents(e,i)}addTemplatesToItem(e,t){["_template","__template"].forEach(s=>{void 0!==e[s]&&(t[s]=e[s])})}getItemWithEvents(e,s){if(void 0!==e.__template){const n=(e,s)=>(s=s||{},Object.keys(e).forEach(o=>{t.utils.isPlainObject(e[o])?s[o]=n(e[o]):t.utils.isFunction(e[o])&&(s[o]=e[o])}),s);let o=n(e.__template);t.utils.isEmpty(o)||(o=o[Object.keys(o)[0]],s=this.doDom(s,o))}return s}doItems(e,t,s){const n=this.getTemplate(e,s);if(void 0===n)return console.error("Template not found. Probably an array is being used where it is not expected. Node:"),console.log(e),console.log("Value (mistaken?):"),void console.log(t);let o=0;t.forEach(t=>{t=this.plainToObject(e,t);const s=this.getItem(e,o++,t,n);s&&e.append(s)});const i=e.find("template");i&&e.removeChild(i),e.items=e.children,this.extendItems(e)}getTemplate(e,s){if(void 0!==e._template&&""!==e._template)return e._template;{let n;const o=e.querySelector("template");if(o)n=t.utils.htmlElement(o.innerHTML.trim());else switch(e.tagName){case"SELECT":case"DATALIST":n=t.utils.newElement("option");break;case"UL":case"OL":n=t.utils.newElement("li");break;case"NAV":n=t.utils.newElement("a");break;case"DL":n=t.utils.newElement("dd");break;default:if(s){const o=Object.keys(s).length;if(o){if(o>1)if(void 0!==s.tagName){let e={};e[s.tagName]=s,s=e}else console.log("Template has more than one top elements. Using the first one. In: "),console.log(s),console.log("Node: "),console.log(e);const i=Object.keys(s)[0],l=s[i];t.utils.isValidElement(i)?n=t.utils.newElement(i):void 0!==l.tagName?(n=t.utils.newElement(l.tagName),s[l.tagName]=l,delete s[i]):(console.error("Template defined an element which can not be identified: ["+i+"], using in:"),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span"))}else console.error("Template has no definition, and it can not be guessed. Using . Template: "),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span")}else e.childElementCount>0&&(n=t.utils.htmlElement(e.innerHTML.trim()))}if(s)if(t.utils.isPlainObject(s)){const o=t.utils.newEmptyNode();o.append(n),n=this.doDom(o,s).children[0],t.utils.defineProp(e,"__template",s)}else n=t.utils.isHtml(s)?t.utils.htmlElement(s):t.utils.isSelectorID(s)?t.utils.htmlElement(document.querySelector(s).innerHTML):t.utils.newElement(s);if(n.childrenElementCount>1){console.log("Templates only supports a single child. Multiple children were detected, wrapping them with . Template:"),console.log(n);const e=t.utils.newElement("span");e.append(n),n=e}return n&&t.utils.defineProp(e,"_template",n),n}}setUniqueAttrib(e,s){e.hasOwnProperty(s)||Object.defineProperty(e,s,{get:function(){return this.hasAttribute(s)},set:function(e){const n=this.parentNode?this.parentNode.find("["+s+"]"):null;n&&n.removeAttribute(s),t.utils.setAttr(this,s,e)}})}updateValue(e,s,n){if(this.isUpdateLink(n)){const o=this,i=n[0],l=n[1],a=n[2];if(n=i[l],i instanceof CSSStyleDeclaration&&this._stored.styles.includes(i)){const n=this._stored.styleNodes[this._stored.styles.indexOf(i)];t.updates&&(n.onupdate=function(t){t.detail&&"style"===t.detail.property&&t.detail.newValue.startsWith(l+":")&&o.setShortValue(e,s,a(this.style[l]))})}else if(i instanceof DOMStringMap&&this._stored.datasets.includes(i)){const n=this._stored.datasetNodes[this._stored.datasets.indexOf(i)];t.updates&&(n.onupdate=t=>{t.detail&&t.detail.property==="data-"+l&&o.setShortValue(e,s,a(t.detail.newValue))})}else t.updates&&(i.onupdate=n=>{n.detail&&n.detail.property===l&&(t.utils.isObject(e[s])||o.setShortValue(e,s,a(n.detail.newValue)))})}return n}setShortValue(e,s,n){if(t.utils.isNode(e[s]))if(t.short){const o=this.plainToObject(e[s],n),i=t.utils.isPlainObject(o)&&Object.keys(o).length>=1?Object.keys(o)[0]:null;i&&(e[s][i]=n)}else console.log("Short is disabled. Trying to set a value ("+n+") in a node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else e[s]=n}getShortValue(e,s,n){let o=null;if(t.utils.isNode(e[s]))if(t.short){const i=this.plainToObject(e[s],n||""),l=t.utils.isPlainObject(i)&&Object.keys(i).length>=1?Object.keys(i)[0]:null;l&&(o=e[s][l])}else console.log("Short is disabled. Trying to get a value from node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else o=e[s];return o}proxy(e,s){return!t.short||null===e||void 0!==e._proxy&&void 0===s?e:(e._proxy=e,new Proxy(e,{get:(e,s)=>{const n=e[s];switch(!0){case null==n:return null;case t.utils.isFunction(n):return n.bind(e);case n._proxy&&void 0!==e["$"+s]:return e["$"+s];case void 0===n._proxy&&t.utils.isElement(n):return this.proxy(n);default:return n}},set:(e,s,n)=>{let o="";return t.utils.isElement(e[s])?(o=this.getShortValue(e,s,n),this.setShortValue(e,s,n)):"onupdate"===s?t.updates?t.utils.isFunction(n)?(e.addEventListener("update",n,!0),o=e[s],e[s]=n):(console.error("Value passed to 'onupdate' is incorrect, in node:"),console.log(e),console.log("Value: (not a function)"),console.log(n)):(console.log("Updates are not available when `m2d2.updates == false`:"),console.log(e)):"items"===s?(e.items.clear(),this.doItems(e,n)):(o=e[s],n=this.updateValue(e,s,n),e[s]=n),t.updates&&void 0!==e.onupdate&&n!==o&&e.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:s,newValue:n,oldValue:o}})),!0}}))}onObserve(e,s){e.forEach(e=>{const s=e.target;if(!(this._stored.events.indexOf(e)>=0)&&(this._stored.events.push(e),setTimeout(()=>{const t=this._stored.events.indexOf(e);t>=0&&this._stored.events.splice(t,1)},t.storedEventsTimeout),void 0!==s.onupdate))if("attributes"===e.type){const n=t.utils.getAttrOrProp(s,e.attributeName);n!==e.oldValue&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:e.attributeName,newValue:n,oldValue:e.oldValue}}))}else if("childList"===e.type)if("#text"===(e.addedNodes[0]||e.removedNodes[0]).nodeName){const t=e.addedNodes[0].textContent,n=e.removedNodes.length?e.removedNodes[0].textContent:null;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"text",newValue:t,oldValue:n}}))}else if(void 0!==s.items){const t=e.addedNodes,n=e.removedNodes;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"items",newValue:t,oldValue:n}}))}})}observe(e){if(t.updates){const t=new MutationObserver(this.onObserve.bind(this)),s={attributeOldValue:!0,subtree:!0,childList:!0},n=e._proxy||e;t.observe(n,s)}}getProxyNode(e,t){const s=this.doDom(e,t);if(s)return this.observe(s),this.proxy(s)}extendItems(e){function s(t){t.forEach(t=>{const s=t.parentNode.removeChild(t);e.append(s)})}const n=e.items;Object.getOwnPropertyNames(Array.prototype).concat(["clear","get","remove","selected","first","last","findAll"]).forEach(o=>{if(void 0===n[o]){let i=null;const l=this;switch(o){case"copyWithin":case"fill":case"splice":i=function(){console.log("Not available yet: "+o)};break;case"reverse":i=function(...e){if(this.items.length){const t=Array.from(this.items),n=t[o](...e);return s(t),n}};break;case"clear":i=function(){for(;this.items[0];)this.items[0].remove()};break;case"get":i=function(e){let s=null;return this.items.length&&this.items.some(n=>{const o=t.utils.isNumeric(e)?1*n.dataset.id==1*e:n.dataset.id===e;if(n.dataset&&o)return s=n,!0}),s};break;case"selected":i=function(){return l.proxy(this.find(":scope > [selected]"))};break;case"first":i=function(){return l.proxy(this.items[0])};break;case"last":i=function(){return l.proxy(this.items[this.items.length-1])};break;case"pop":i=function(){if(this.items.length){const e=this[0].parentNode;return l.proxy(e.removeChild(this.items[this.items.length-1]))}};break;case"push":i=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.append(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.appendChild(s)}else console.log("Trying to push an unknown value into a list:"),console.log(e)};break;case"remove":i=function(e){if(this.items.length){const t=this.items.get(e);1===t.length&&t.remove()}};break;case"shift":i=function(){if(this.items.length){const e=this.items[0].parentNode;return l.proxy(e.removeChild(this.items[0]))}};break;case"sort":i=function(e){if(this.items.length){const t=Array.from(this.items);t.sort(e||((e,t)=>e.text.localeCompare(t.text))),s(t)}};break;case"unshift":i=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.prepend(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.prepend(s)}else console.log("Trying to unshift an unknown value into a list:"),console.log(e)};break;default:let n=o;switch(!0){case"findAll"===o:n="filter";case t.utils.isFunction(Array.prototype[o]):const s=function(...t){const s=[];return Array.from(e.items).forEach(e=>{s.push(l.proxy(e))}),Array.from(s)[n](...t)};switch(o){case"find":i=function(...e){return t.utils.isString(e[0])?this.find(e[0]):s(...e)};break;case"findAll":i=function(...e){return 0===e.length?this.findAll():t.utils.isString(e[0])?this.findAll(e[0]):s(...e)};break;case"concat":i=function(...e){for(let s=0;s{function t(t){e.exists("#m2d2-alert .m2d2-alert-front")?(e("#m2d2-alert .m2d2-alert-front").css.add("vanish"),setTimeout(()=>{e.exists("#m2d2-alert .m2d2-alert-front")&&e("#m2d2-alert").remove(),t&&t()},400)):t&&t()}const s={wrap:!1,question:["fa","fa-question-circle"],info:["fa","fa-exclamation-circle"],error:["fa","fa-exclamation-triangle"],ok:["fa","fa-check"],input:["fa","fa-edit"],wait:["fa","fa-cog","fa-spin"]},n={wrap:"material-icons",question:"help",info:"info",error:"error",ok:"done",input:"edit",wait:"pending"},o={wrap:!1,question:"icon_question",info:"icon_info",error:"icon_error",ok:"icon_ok",input:"icon_input",wait:"icon_wait"};e.message=function(i){let l=o;switch(e.messageIcons){case"fa":l=s;break;case"material":l=n;break;default:e.isObject(e.messageIcons)&&(l=e.messageIcons)}i&&(e.isFunction(i.callback)||(i.callback&&!i.text&&(i.text=i.callback),i.callback=()=>{}),i.text||(i.text="")),t(()=>{e("body",{m2d2Alert:{tagName:"div",id:"m2d2-alert",back:{tagName:"div",css:"m2d2-alert-back",style:{position:"absolute",left:0,right:0,top:0,bottom:0,backgroundColor:"#0005",display:"flex",justifyContent:"center",alignItems:"center"},front:Object.assign({tagName:"form",css:(i.css?e.isArray(i.css)?i.css:[i.css]:[]).concat(["m2d2-alert-front","popup",i.icon]),style:{zIndex:100},icon:{tagName:"span",css:["icon",i.icon].concat(l.wrap?[l.wrap]:l[i.icon]).concat("wait"===i.icon?"spin":""),text:l.wrap?l[i.icon]:""},message:{tagName:"div",css:"m2d2-alert-title",span:i.title},submsg:(()=>{let t;return t="input"!==i.icon||i.text?e.isPlainObject(i.text)?{fieldset:Object.assign({css:"m2d2-alert-field"},i.text)}:{span:i.text.replace("\n","
")}:{fieldset:{css:"m2d2-alert-field",input:{type:"text",name:"answer",onload:function(){this.focus()}}}},Object.assign({tagName:"div",css:"m2d2-alert-text"},t)})(i.icon),onsubmit:function(){const e=this.getData();let s;switch(e.button){case"ok":case"yes":s=()=>{i.callback(!0,e)};break;case"no":s=()=>{i.callback(!1,e)};break;case"cancel":s=()=>{i.callback(null,e)};break;case"send":s=1===Object.keys(e).length?()=>{i.callback(e[Object.keys(e)[0]],e)}:2===Object.keys(e).length?()=>{i.callback(e[Object.keys(e).find(e=>"button"!==e)],e)}:()=>{i.callback(e,e)};break;default:s=()=>{i.callback(e,e)}}return t(s),!1},onload:function(){const e=this.find("[autofocus]");e&&e.focus()}},function(t){let s={};return t.length&&(s={buttons:{tagName:"div",css:"m2d2-alert-buttons"}},t.forEach(t=>{const n=t.toLowerCase().replace(/[^a-z ]/g,"").replace(" ","_");s.buttons[n]={tagName:"button",type:"submit",value:n,css:["color",n],text:void 0!==e.dict?e.dict(t):t,autofocus:["ok","yes"].includes(t),formNoValidate:["cancel"].includes(t),onclick:function(){e(this.closest("form"),{hide:{tagName:"input",type:"hidden",name:"button",value:this.value}})}}})),s}(i.buttons))}}})});let a=1;return e("#m2d2-alert .m2d2-alert-front").findAll("input, select, textarea").forEach(e=>{""===e.name&&(e.name="field_"+a++)}),{close:t}},e.wait=(t,s,n)=>e.message({icon:"wait",title:t,buttons:[],text:void 0===n?null:s,callback:void 0===n?s:n}),e.alert=(t,s,n)=>e.message({icon:"info",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.success=(t,s,n)=>e.message({icon:"ok",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.failure=(t,s,n)=>e.message({icon:"error",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.confirm=(t,s,n)=>e.message({icon:"question",title:t,buttons:["yes","no"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.prompt=(t,s,n)=>e.message({icon:"input",title:t,buttons:["cancel","send"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.closeAll=()=>{t()}}),t.load(e=>{let t=localStorage.getItem("m2d2.lang")||navigator.language;e.dict=new function(t){const s=function(e,t){if(void 0===e)return"";let n=s.val(e,!0);if(void 0!==t){if("string"==typeof t&&""!==t){const e=(t=t.replace(/;$/,"")).split(";");t={},e.forEach(s=>{const n=e[s].split(":");t[n[0]]=n[1]})}"object"==typeof t&&t.forEach(e=>{let o=t[e]+"";o=s.val(o,!1),n=n.replace(e,o)})}return n};return s.lang=t||"en",s.data={},s.set=function(e){return this.data=e,this},s.has=function(e,t){return void 0===t?void 0!==this.data[e]:void 0!==this.data[e][t]},s.val=function(t,n){if(e.isEmpty(s.data))return console.error("Dictionary is empty. You need to add a dictionary, for example: `$.dict.set({\nsave : { en : 'Save', es : 'Guardar' },\ncancel : { en : 'Cancel', es : 'Cancelar' }\nyes : { en : 'Yes', es : 'Si' },\nno : { en : 'No', es : 'No' }\n})`"),"";if(!t)return console.error("No keyword specified."),"";let o=t;if(void 0===n&&(n=!1),t=t.toLowerCase(),this.has(t)){const e=this.lang.split("-")[0];this.has(t,this.lang)?o=this.data[t][this.lang]:this.has(t,e)?o=this.data[t][e]:n&&console.log("Missing translation for lang ["+this.lang+"]: "+t)}else n&&console.log("Missing keyword: "+t);return o},s}(t);const s=[];e.lang=function(t){t&&(e.dict.lang=t,localStorage.setItem("m2d2.lang",e.dict.lang)),e("body").findAll("[lang]").forEach(t=>{let s=t.text;if(s&&!t.classList.contains("notxt")){void 0===t.dataset.kw&&(t.dataset.kw=e.lang.getKeyword(s)),t.text=e.dict(t.dataset.kw);const n=t.dataset.kw+"_title";let o=e.dict.has(n)?e.dict(n):"";o&&(t.title=o)}else if(t.title){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.title)),s=e.dict(t.dataset.kw),s&&(t.title=s)}else if(t.placeholder){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.placeholder)),s=e.dict(t.dataset.kw),s&&(t.placeholder=s)}else if(t.value){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.value)),s=e.dict(t.dataset.kw),s&&(t.value=s)}}),s.forEach(e=>{e(t)})},e.lang.getKeyword=function(e){return e.toLowerCase().trim().replace(/ /g,"_").replace(/[^\w]/g,"").replace(/_$/,"")},Object.defineProperty(e.lang,"onchange",{get(){return this},set(t){e.isFunction(t)?s.push(t):(console.log("Unable to set lang.onchange, because it is not a function: "),console.log(t))}})}),t.ready(e=>{const t=localStorage.getItem("m2d2.lang")||"",s=e("body").find("[lang]"),n=e("html").lang||(s?s.lang:null)||"en";(t?n!==t:n!==navigator.language.split("-")[0])&&e.lang()}),t.load(e=>{function t(e){switch(e){case"local":window.localStorage&&(this.store=localStorage);break;case"session":window.sessionStorage&&(this.store=sessionStorage)}null==this.store&&(this.store=localStorage),this.set=function(e,t){"string"==typeof t&&(t={$:t}),this.store.setItem(e,JSON.stringify(t))},this.get=function(e){let t;try{t=JSON.parse(this.store.getItem(e))||{}}catch(s){t=this.store.getItem(e)}return void 0!==t.$?t=t.$:0===Object.keys(t).length&&t.constructor===Object&&(t=null),t},this.del=function(e){this.store.removeItem(e)},this.keys=function(){return Object.keys(this.store).sort()},this.clear=function(){this.store.clear()},this.exists=function(e){return this.store.hasOwnProperty(e)},this.log=function(e,t,s){null==s&&(s=10);const n=this.get(e)||[];for(n.push(t);n.length>s;)n.shift();this.set(e,n)}}e.local=new t("local"),e.session=new t("session")}),t.load(e=>{function t(e,t,s){const n=[];return e=e||{},t.forEach(o=>{const i="Array"==typeof e?e.length==t.length?e[s]:e:void 0!==e[o.name]?e[o.name]:e;n.push({file:o,data:i,index:s++})}),n}function s(e,t,s,n,o){const i=new XMLHttpRequest;t=Array.from(t),i.upload.addEventListener("progress",(function(e){if(e.lengthComputable)if(n.oneByOne){const o=Math.round(100*e.loaded/e.total);n.onUpdate(o,t[0],s)}else{let s=0,o=0;t.some(t=>{s+=t.size;const i=e.loaded>=s?100:100-Math.round(100*(s-e.loaded)/t.size);return n.onUpdate(i,t,o++),s>=e.loaded})}}),!1),i.addEventListener("load",(function(e){let l={};try{l=i.responseText?JSON.parse(i.responseText):{error:{type:"Unknown",reason:"Unknown Error"}}}catch(e){l.error={type:"Parse Error",reason:e.message}}i.status>=200&&i.status<400?o(n.onResponse(l),t,s):("string"==typeof l.error&&(l.error={type:"Exception",reason:l.error}),n.onError(l.error))}),!1),i.open("POST",n.upload);const l=Array(t.length).fill(!1),a=function(e,t){const s=new FormData;return t.forEach(t=>{s.append(e,t,t.name)}),s}(e,t);let r=0;t.forEach(e=>{const t=new FileReader;t.onload=function(e){l[r++]=!0,-1===l.indexOf(!1)&&i.send(a)},t.readAsBinaryString(e)})}e.upload=function(e,n){const o=Object.assign({},{accept:"*/*",parallel:!1,field:"file",multiple:!0,maxFiles:0,maxSizeMb:0},n);n=null;let i=window._protected_reference=document.createElement("INPUT");i.name=o.field,i.type="file",1==o.multiple&&(i.multiple="multiple"),o.upload||(console.log("Upload not specified. Using current page."),o.upload=""),null==o.onDone&&(o.onDone=(e,t)=>{console.log(e)}),null==o.onError&&(o.onError=e=>{console.log("Error : "),console.log(e)}),null==o.onUpdate&&(o.onUpdate=(e,t,s)=>{console.log("Uploading : "+e+"% "+(o.oneByOne?"[ "+t.name+" ]":""))}),null==o.onResponse&&(o.onResponse=e=>e),i.addEventListener("change",()=>{if(i.files.length){if(!(0===o.maxFiles|i.files.length<=o.maxFiles))return o.onError("Max file limit exceeded. Maximum files: "+o.maxFiles),!1;if(o.onSelect){const e=[];let t=0;Array.from(i.files).forEach(s=>{e.push(URL.createObjectURL(s)),t+=s.size});const s=t/1048576;if(o.maxSizeMb&&s>o.maxSizeMb)return o.onError("Maximum size exceeded: "+Math.ceil(s)+"MB > "+o.maxSizeMb+"MB"),!1;o.onSelect(i.files,e)}new Promise(e=>{if(o.oneByOne){let n=0;const l=Array(i.files.length).fill(!1);Array.from(i.files).forEach(a=>{new s(i.name,[a],n++,o,(s,n,i)=>{l[i]=!0;const a=-1===l.indexOf(!1);o.onDone(t(s,n,i),a),a&&e()})})}else new s(i.name,i.files,0,o,(s,n,i)=>{o.onDone(t(s,n,i),!0),e()})}).then(()=>{i=window._protected_reference=void 0})}}),i.click()}}),t.load(e=>{const t=function(e,t,s,n,o,i){const l=new XMLHttpRequest;if(void 0===i&&(i=!1),void 0===o&&(o=function(e){console.log(e)}),s&&0===Object.entries(s).length&&(s=""),s)if(i)s=JSON.stringify(s);else switch(e.toUpperCase()){case"GET":t+=(-1!==t.indexOf("?")?"&":"?")+Object.keys(s).map(e=>e+"="+s[e]).join("&"),s="";break;default:s=Object.keys(s).map(e=>e+"="+s[e]).join("&")}return l.open(e,t,!0),i?l.setRequestHeader("Content-Type","application/json"):l.setRequestHeader("Content-type","application/x-www-form-urlencoded"),l.onerror=function(e){o({type:"Connection",reason:"Connection Refused"})},l.onload=function(){let e={};try{e=l.responseText?JSON.parse(l.responseText):{error:{type:"Unknown",reason:"Unknown Error"}}}catch(t){e.error={type:"Parse Error",reason:t.message}}l.status>=200&&l.status<400?void 0!==n&&n(e):void 0!==o&&("string"==typeof e.error&&(e.error={type:"Exception",reason:e.error}),o(e.error))},l.send(s),l},s={};["get","post","put","delete","connect","options","trace","patch"].forEach((function(e){s[e]=function(){let s,n,o,i,l;switch(arguments.length){case 5:"boolean"==typeof arguments[4]?l=arguments[4]:console.log("Passed JSON argument: "+arguments[4]+" is not boolean.");case 4:"function"==typeof arguments[3]?i=arguments[3]:4===arguments.length&&"boolean"==typeof arguments[3]?l=arguments[3]:console.log("Passed argument 4: "+arguments[3]+" is mistaken");case 3:"function"==typeof arguments[2]?"function"==typeof arguments[1]&&arguments.length<5?i=arguments[2]:o=arguments[2]:3===arguments.length&&"boolean"==typeof arguments[2]?l=arguments[2]:console.log("Passed argument 3: "+arguments[2]+" is mistaken");case 2:"object"==typeof arguments[1]||"string"==typeof arguments[1]?n=arguments[1]:"function"==typeof arguments[1]?o=arguments[1]:console.log("Passed argument 2: "+arguments[1]+" is mistaken");case 1:"string"==typeof arguments[0]?s=arguments[0]:Array.isArray(arguments[0])?s=arguments[0].join("/"):console.log("Passed URL: "+arguments[0]+" was not a string.");break;default:console.log("Incorrect number of arguments passed to xhr")}return void 0===n&&(n={}),t(e.toUpperCase(),s,n,o,i,l)}})),Object.assign(e,s)}),t})); \ No newline at end of file +!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.m2d2=t()}(this,(function(){"use strict";class e{isString(e){return"string"==typeof e}isBool(e){return"boolean"==typeof e}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isSelectorID(e){return 0===(e+"").trim().indexOf("#")}isPlainObject(e){return"Object"===e.constructor.name}isObject(e){return"object"==typeof e}isArray(e){return Array.isArray(e)}isFunction(e){return"function"==typeof e}isElement(e){return e instanceof HTMLElement}isNode(e){return e instanceof Node||e instanceof DocumentFragment}isHtml(e){return-1!==(e+"").trim().indexOf("<")}isEmpty(e){return void 0===e||this.isObject(e)&&0===Object.keys(e).length||""===e}isVisible(e){if(!this.isElement(e))return console.log("(isVisible) Not an element: "),console.log(e),!1;const t="none"!==e.style.display,s="hidden"!==e.style.visibility;return t&&s}inView(e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)&&t.width>0&&t.height>0}cleanArray(e){return e.filter((function(e){return 0===e||e}))}isValidElement(e){const t=this.newElement(e);return"template"!==e&&"HTMLUnknownElement"!==t.constructor.name}exists(e){return null!==document.querySelector(e)}getAttrOrProp(e,t){let s="";return this.hasAttrOrProp(e,t)&&(s=this.hasAttr(e,t)?e.getAttribute(t):e[t]),s}hasAttrOrProp(e,t){return this.hasAttr(e,t)||this.hasProp(e,t)}hasAttr(e,t){let s=!1;if(e&&!this.isNumeric(t))switch(t){case"checked":s=void 0!==e.type&&("radio"===e.type||"checkbox"===e.type);break;default:s=void 0!==e.hasAttribute&&e.hasAttribute(t)}return s}hasProp(e,t){let s=!1;if(e&&!this.isNumeric(t)){let n=void 0!==e[t];n&&null===e[t]&&"value"===t&&(n=!1),s=n&&!(e[t]instanceof Node)&&!e.hasAttribute(t)}return s}setPropOrAttr(e,t,s){if(this.hasProp(e,t))try{e[t]=s}catch(n){this.setAttr(e,t,s)}else this.setAttr(e,t,s)}setAttr(e,t,s){s?e.setAttribute(t,s):e.removeAttribute(t)}defineProp(e,t,s){this.isObject(e)&&void 0===e[t]&&(Object.defineProperty(e,t,{enumerable:!1,writable:!0}),e[t]=s)}htmlElement(e){const t=this.newElement("template");return t.innerHTML=e.trim(),t.content.firstChild}newElement(e){return document.createElement(e)}newEmptyNode(){return new DocumentFragment}getMethods(e){const t=Reflect.getPrototypeOf(e),s=Reflect.getPrototypeOf(t);return Reflect.ownKeys(t).filter(e=>Reflect.ownKeys(s).indexOf(e)<0)}appendAllChild(e,t){for(;e.firstChild;)t.append(e.firstChild)}prependAllChild(e,t){for(;e.firstChild;)t.prepend(e.firstChild)}}class t{"use strict";_stored={events:[],datasetNodes:[],datasets:[],styleNodes:[],styles:[]};static storedEventsTimeout=50;static short=!0;static updates=!0;static utils=new e;constructor(){}static instance=new t;static extensions={};static main=(()=>{const e=(e,s)=>{const n=this.instance.getProxyNode(e,s);return n&&n.onready&&t.utils.isFunction(n.onready)&&(n.addEventListener("ready",n.onready,{once:!0}),setTimeout(()=>{n.dispatchEvent(new CustomEvent("ready"))},10)),["dataset","style"].forEach(e=>{n&&n[e]&&(this.instance._stored[e+"s"].push(n[e]),this.instance._stored[e+"Nodes"].push(n))}),n};return t.utils.getMethods(t.utils).forEach(s=>{e[s]=t.utils[s]}),e})();static ready(e){document.addEventListener("DOMContentLoaded",()=>{e(t.main)})}static load(e){if(void 0!==e){const s=e(t.main);t.utils.isObject(s)&&!t.utils.isEmpty(s)&&Object.keys(s).forEach(e=>{if(t.utils.isValidElement(e)){void 0===t.extensions[e]&&(t.extensions[e]={});const n=t.utils.newElement(e);Object.keys(s[e]).forEach(s=>{t.utils.hasProp(n,s)&&console.log("Warning: property ["+s+"] already exists in node: ["+e+"] while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions[e],s[e])}else{void 0===t.extensions["*"]&&(t.extensions["*"]={});const n=t.utils.newElement("div");Object.keys(s[e]).forEach(e=>{t.utils.hasProp(n,e)&&console.log("Warning: property ["+e+"] already exists in Node while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions["*"],s[e])}})}return t.main}extDom(e,s){if(!e)return console.error("Selector was empty"),null;void 0===s&&(s=document);const n=t.utils.isNode(e)?e:s.querySelector(e);if(!n)return t.utils.isString(e)?(console.error("Selector: "+e+" didn't match any element in node:"),console.log(s)):console.error("Node was null"),null;if(void 0===n._m2d2){n._m2d2=!0,["parent","sibling","posterior","anterior","find","findAll","onupdate","onready","show","onshow","inView","css","text","html","getData","index"].forEach(e=>{n.hasOwnProperty(e)&&(console.log("Node already had ["+e+"] property. It might cause unexpected behaviour."),console.log("You may need to update the M2D2 version or report it to: github.com/intellisrc/m2d2/"))}),Object.defineProperty(n,"text",{get(){return this.childNodes.length?this.innerText:this.textContent},set(e){if(this.childNodes.length){let t=!1;this.childNodes.forEach(s=>{"Text"===s.constructor.name&&(s.nodeValue=e,t=!0)}),t||this.prepend(document.createTextNode(e))}else this.textContent=e}}),Object.defineProperty(n,"html",{get(){return this.innerHTML},set(e){this.innerHTML=e}}),Object.defineProperty(n,"css",{get(){return this.classList},set(e){t.utils.isArray(e)?this.className=e.join(" "):t.utils.isString(e)?this.className=e:t.utils.isPlainObject(e)?Object.keys(e).forEach(t=>{e[t]?this.classList.add(t):this.classList.remove(t)}):console.error("Trying to assign a wrong value to css : "+e)}}),Object.defineProperty(n,"show",{get(){return t.utils.isVisible(this)},set(e){const s=()=>getComputedStyle(this,null).display,n=()=>{const e=document.getElementsByTagName("body")[0],t=document.createElement("template"),s=document.createElement(this.tagName);t.append(s),e.append(t);const n=getComputedStyle(s,null).display;return t.remove(),n};if(e){if("none"===s()){if(this._m2d2_display)this.style.display=this._m2d2_display;else if(this.style.removeProperty("display"),"none"===s()){const e=n();this.style.display=this.dataset.display||("none"!==e?e:"block")}void 0!==this.onshow&&t.utils.isFunction(this.onshow)&&this.onshow(this)}}else{const e="none"!==this.style.display?this.style.display:s();"none"!==e&&(this._m2d2_display=e),this.style.display="none"}}});let e={};return void 0!==t.extensions["*"]&&Object.assign(e,t.extensions["*"]),void 0!==t.extensions[n.tagName]&&Object.assign(e,t.extensions[n.tagName]),Object.assign(n,{inView:()=>t.utils.inView(n),posterior:()=>n.nextElementSibling,anterior:()=>n.previousElementSibling,parent:()=>this.extDom(n.parentElement),sibling:e=>n.parentElement.find(e),find:e=>{const t=n.querySelector(e);return t?this.extDom(t):null},findAll:e=>{const t=void 0===e?Array.from(n.children):n.querySelectorAll(e);return t.forEach(e=>{this.extDom(e)}),t}},e),void 0===n.index&&(n.index=()=>Array.from(n.parentNode.children).indexOf(n)),["INPUT","TEXTAREA","SELECT"].indexOf(n.tagName)>=0&&t.utils.hasAttrOrProp(n,"value")&&(n.oninput=function(){this.setAttribute("value",this.value)}),"FORM"===n.tagName&&(n.getData=function(e){const t={},s=new FormData(this),o=e||!1;for(let e of s.entries()){const s=n.find("[name='"+e[0]+"']");(o||"hidden"===s.type||s.show)&&(t[e[0]]="file"===s.type?s.files:e[1])}return t}),n}return n}doDom(e,s){if(t.utils.isObject(e)&&void 0===s&&(s=e,e=t.utils.newEmptyNode(),void 0===s.warn&&(s.warn=!1)),!(t.utils.isString(e)||t.utils.isElement(e)||t.utils.isNode(e)))return console.error("Selector is not a string or a Node:"),console.log(e),null;if(t.utils.isString(e)&&!document.querySelector(e))return console.log("Selected element doesn't exists: "+e),null;const n=this.extDom(e);if(void 0===s)return n;if(s=this.plainToObject(n,s),Object.keys(s).filter(e=>!["tagName"].includes(e)).forEach(e=>{let o=s[e];null==o&&(console.log("Value was not set for key: "+e+", 'empty' was used in object: "),console.log(s),console.log("In node:"),console.log(n),o="");let i=this.updateValue(n,e,o),l=t.utils.hasProp(n,e),a=!1;if(t.utils.hasAttr(n,e)||l)switch(!0){case"value"===e&&t.utils.hasProp(n,"valueAsDate")&&i instanceof Date:e="valueAsDate";case"css"===e:case typeof i==typeof n[e]:case t.utils.isString(n[e])&&t.utils.isNumeric(i):case t.utils.isFunction(i)&&t.utils.isObject(n[e]):case t.utils.isBool(i)&&t.utils.isString(n[e]):case"object"==typeof n[e]&&"INPUT"===n.tagName:a=!0}if(a){let s=!1;switch(e){case"classList":t.utils.isArray(i)?i.forEach(t=>{n[e].add(t)}):t.utils.isString(i)?n[e].add(i):s=!0;break;case"style":case"dataset":t.utils.isPlainObject(i)?Object.keys(i).forEach(t=>{n[e][t]=this.updateValue(n[e],t,i[t])}):s=!0;break;default:switch(!0){case t.utils.isBool(i):case t.utils.hasAttrOrProp(n,e):t.utils.setPropOrAttr(n,e,i);break;default:n[e]=i}}s&&(console.error("Invalid value passed to '"+e+"': "),console.log(i),console.log("Into Node:"),console.log(n))}else{const l=[];try{if("template"!==e&&!t.utils.isFunction(i)){if(e&&e.match(/^\w/)){let t=n.find("#"+e);t&&-1===l.indexOf(t)&&l.push(t),t=n.find("[name='"+e+"']"),t&&-1===l.indexOf(t)&&l.push(t);const s=Array.from(n.findAll("."+e)).filter(e=>l.indexOf(e)<0);s.length>0&&s.forEach(e=>l.push(e))}const t=Array.from(n.findAll(e)).filter(e=>l.indexOf(e)<0);t.length>0&&t.forEach(e=>l.push(e))}}catch(t){return console.error("Invalid selector: "+e),void console.log(t)}if(l.length>1){const t=[];l.forEach(s=>{t.push(this.render(s,e,i))}),this.linkNode(n,e,t),void 0!==i.warn&&!1===i.warn||(console.log("Multiple elements were assigned with key: ["+e+"] under node: "),console.log(n),console.log("It might be what we expect, but if it is not expected it could result on some elements mistakenly rendered. You can specify 'warn : false' under that element to hide this message."))}else if(1===l.length){const a=l[0];if(t.utils.isElement(a)){const l=this.plainToObject(a,i),r=t.utils.isPlainObject(l)&&Object.keys(l).length>=1?Object.keys(l)[0]:null;if(r&&(i=this.updateValue(a,r,o)),t.utils.isArray(i)){const t=s.template;this.doItems(a,i,t),this.linkNode(n,e,a)}else this.renderAndLink(n,a,e,i)}else console.error("BUG: It should have been a node but got: "),console.log(a),console.log("Parent node:"),console.log(n)}else if(0===l.length){"template"===e&&void 0===s.items&&(e="items",i=[]);const o=t.utils.isFunction(i);if(void 0!==i.tagName){const t=this.appendElement(n,i.tagName);this.renderAndLink(n,t,e,i)}else if(t.utils.isValidElement(e)&&!o){const t=this.appendElement(n,e);this.renderAndLink(n,t,e,i)}else if("items"===e){const e=s.template;if(t.utils.isPlainObject(i)){const e=[];Object.keys(i).forEach(s=>{let o;"DL"===n.tagName?o={dt:s,dd:i[s]}:(o={text:i[s]},t.utils.hasAttrOrProp(n,"value")?o.value=s:o.dataset={id:s}),e.push(o)}),i=e}t.utils.isArray(i)?this.doItems(n,i,e):(console.log("Warning: 'items' specified but value is not and array, in element: "),console.log(n),console.log("Passed values are: "),console.log(i))}else o?(t.updates&&"onupdate"===e&&n.addEventListener("update",i,!0),n[e]=i):"template"!==e&&"warn"!==e&&!1!==i&&(void 0!==s.warn&&!1===s.warn||(console.error("Not sure what you want to do with key: "+e+" under element: "),console.log(n),console.log("And object:"),console.log(s),console.log("Most likely the element's property or child no longer exists or the value passed to it is incorrect."),console.log("You can set 'warn : false' property to the element to dismiss this message.")),n[e]=i)}}}),n.onload){const e=["BODY","FRAME","IFRAME","IMG","LINK","SCRIPT","STYLE"].indexOf(n.tagName)>=0,t="INPUT"===n.tagName&&"image"===n.type;e||t||n.dispatchEvent(new CustomEvent("load"))}return n}isUpdateLink(e){let s=!1;if(t.utils.isArray(e)&&(2===e.length||3===e.length)){const n=2===e.length,o=t.utils.isNode(e[0])||e[0]instanceof DOMStringMap||e[0]instanceof CSSStyleDeclaration,i=n?t.utils.isString(e[1]):t.utils.isString(e[1])&&t.utils.isFunction(e[2]);s=o&&i,s&&n&&e.push(e=>e)}return s}plainToObject(e,s){if(!t.utils.isPlainObject(s)&&!t.utils.isFunction(s)&&!t.utils.isElement(s))if(t.utils.isHtml(s))s={html:s};else if(this.isUpdateLink(s)){const n=s[0],o=s[1],i=s[2];let l=this.plainToObject(e,i(n[o]));if(t.utils.isPlainObject(l)){const e={};Object.keys(l).forEach(t=>{e[t]=s}),s=e}}else t.utils.isArray(s)?s={items:s}:t.utils.hasAttrOrProp(e,"value")?s="SELECT"===e.tagName?{value:s,text:s}:"BUTTON"===e.tagName?{text:s}:{value:s}:t.utils.isString(s)&&"IMG"===e.tagName?s={src:s}:(t.utils.isString(s)||t.utils.isNumeric(s))&&(s={text:s});return s}renderAndLink(e,t,s,n){const o=this.render(t,s,n);this.linkNode(e,s,o)}render(e,t,s){return s=this.plainToObject(e,s),this.doDom(e,s)}linkNode(e,s,n){if(e[s]===n){const t=this.proxy(n);try{e[s]=t}catch(e){}e["$"+s]=t}else t.utils.hasAttrOrProp(e,s)?(e["$"+s]=n,console.log("Property : "+s+" existed in node: "+e.tagName+". Using $"+s+" instead for node: "+n.tagName+".")):e[s]=this.proxy(n)}appendElement(e,s){const n=t.utils.newElement(s);return e.append(n),n}getItem(e,t,s,n){n||(n=this.getTemplate(e));const o=n.cloneNode(!0);this.addTemplatesToItem(n,o),o.dataset.id=t,this.setUniqueAttrib(o,"selected");let i=this.doDom(o,s);return this.getItemWithEvents(e,i)}addTemplatesToItem(e,t){["_template","__template"].forEach(s=>{void 0!==e[s]&&(t[s]=e[s])})}getItemWithEvents(e,s){if(void 0!==e.__template){const n=(e,s)=>(s=s||{},Object.keys(e).forEach(o=>{t.utils.isPlainObject(e[o])?s[o]=n(e[o]):t.utils.isFunction(e[o])&&(s[o]=e[o])}),s);let o=n(e.__template);t.utils.isEmpty(o)||(o=o[Object.keys(o)[0]],s=this.doDom(s,o))}return s}doItems(e,t,s){const n=this.getTemplate(e,s);if(void 0===n)return console.error("Template not found. Probably an array is being used where it is not expected. Node:"),console.log(e),console.log("Value (mistaken?):"),void console.log(t);let o=0;t.forEach(t=>{t=this.plainToObject(e,t);const s=this.getItem(e,o++,t,n);s&&e.append(s)});const i=e.find("template");i&&e.removeChild(i),e.items=e.children,this.extendItems(e)}getTemplate(e,s){if(void 0!==e._template&&""!==e._template)return e._template;{let n;const o=e.querySelector("template");if(o)n=t.utils.htmlElement(o.innerHTML.trim());else switch(e.tagName){case"SELECT":case"DATALIST":n=t.utils.newElement("option");break;case"UL":case"OL":n=t.utils.newElement("li");break;case"NAV":n=t.utils.newElement("a");break;case"DL":n=t.utils.newElement("dd");break;default:if(s){const o=Object.keys(s).length;if(o){if(o>1)if(void 0!==s.tagName){let e={};e[s.tagName]=s,s=e}else console.log("Template has more than one top elements. Using the first one. In: "),console.log(s),console.log("Node: "),console.log(e);const i=Object.keys(s)[0],l=s[i];t.utils.isValidElement(i)?n=t.utils.newElement(i):void 0!==l.tagName?(n=t.utils.newElement(l.tagName),s[l.tagName]=l,delete s[i]):(console.error("Template defined an element which can not be identified: ["+i+"], using in:"),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span"))}else console.error("Template has no definition, and it can not be guessed. Using . Template: "),console.log(s),console.log("Node: "),console.log(e),n=t.utils.newElement("span")}else e.childElementCount>0&&(n=t.utils.htmlElement(e.innerHTML.trim()))}if(s)if(t.utils.isPlainObject(s)){const o=t.utils.newEmptyNode();o.append(n),n=this.doDom(o,s).children[0],t.utils.defineProp(e,"__template",s)}else n=t.utils.isHtml(s)?t.utils.htmlElement(s):t.utils.isSelectorID(s)?t.utils.htmlElement(document.querySelector(s).innerHTML):t.utils.newElement(s);if(n.childrenElementCount>1){console.log("Templates only supports a single child. Multiple children were detected, wrapping them with . Template:"),console.log(n);const e=t.utils.newElement("span");e.append(n),n=e}return n&&t.utils.defineProp(e,"_template",n),n}}setUniqueAttrib(e,s){e.hasOwnProperty(s)||Object.defineProperty(e,s,{get:function(){return this.hasAttribute(s)},set:function(e){const n=this.parentNode?this.parentNode.find("["+s+"]"):null;n&&n.removeAttribute(s),t.utils.setAttr(this,s,e)}})}updateValue(e,s,n){if(this.isUpdateLink(n)){const o=this,i=n[0],l=n[1],a=n[2];if(n=i[l],i instanceof CSSStyleDeclaration&&this._stored.styles.includes(i)){const n=this._stored.styleNodes[this._stored.styles.indexOf(i)];t.updates&&(n.onupdate=function(t){t.detail&&"style"===t.detail.property&&t.detail.newValue.startsWith(l+":")&&o.setShortValue(e,s,a(this.style[l]))})}else if(i instanceof DOMStringMap&&this._stored.datasets.includes(i)){const n=this._stored.datasetNodes[this._stored.datasets.indexOf(i)];t.updates&&(n.onupdate=t=>{t.detail&&t.detail.property==="data-"+l&&o.setShortValue(e,s,a(t.detail.newValue))})}else t.updates&&(i.onupdate=n=>{n.detail&&n.detail.property===l&&(t.utils.isObject(e[s])||o.setShortValue(e,s,a(n.detail.newValue)))})}return n}setShortValue(e,s,n){if(t.utils.isNode(e[s]))if(t.short){const o=this.plainToObject(e[s],n),i=t.utils.isPlainObject(o)&&Object.keys(o).length>=1?Object.keys(o)[0]:null;i&&(e[s][i]=n)}else console.log("Short is disabled. Trying to set a value ("+n+") in a node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else e[s]=n}getShortValue(e,s,n){let o=null;if(t.utils.isNode(e[s]))if(t.short){const i=this.plainToObject(e[s],n||""),l=t.utils.isPlainObject(i)&&Object.keys(i).length>=1?Object.keys(i)[0]:null;l&&(o=e[s][l])}else console.log("Short is disabled. Trying to get a value from node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else o=e[s];return o}proxy(e,s){return!t.short||null===e||void 0!==e._proxy&&void 0===s?e:(e._proxy=e,new Proxy(e,{get:(e,s)=>{const n=e[s];switch(!0){case null==n:return null;case t.utils.isFunction(n):return n.bind(e);case n._proxy&&void 0!==e["$"+s]:return e["$"+s];case void 0===n._proxy&&t.utils.isElement(n):return this.proxy(n);default:return n}},set:(e,s,n)=>{let o="";return t.utils.isElement(e[s])?(o=this.getShortValue(e,s,n),this.setShortValue(e,s,n)):"onupdate"===s?t.updates?t.utils.isFunction(n)?(e.addEventListener("update",n,!0),o=e[s],e[s]=n):(console.error("Value passed to 'onupdate' is incorrect, in node:"),console.log(e),console.log("Value: (not a function)"),console.log(n)):(console.log("Updates are not available when `m2d2.updates == false`:"),console.log(e)):"items"===s?(e.items.clear(),this.doItems(e,n)):(o=e[s],n=this.updateValue(e,s,n),e[s]=n),t.updates&&void 0!==e.onupdate&&n!==o&&e.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:s,newValue:n,oldValue:o}})),!0}}))}onObserve(e,s){e.forEach(e=>{const s=e.target;if(!(this._stored.events.indexOf(e)>=0)&&(this._stored.events.push(e),setTimeout(()=>{const t=this._stored.events.indexOf(e);t>=0&&this._stored.events.splice(t,1)},t.storedEventsTimeout),void 0!==s.onupdate))if("attributes"===e.type){const n=t.utils.getAttrOrProp(s,e.attributeName);n!==e.oldValue&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof n,property:e.attributeName,newValue:n,oldValue:e.oldValue}}))}else if("childList"===e.type)if("#text"===(e.addedNodes[0]||e.removedNodes[0]).nodeName){const t=e.addedNodes[0].textContent,n=e.removedNodes.length?e.removedNodes[0].textContent:null;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"text",newValue:t,oldValue:n}}))}else if(void 0!==s.items){const t=e.addedNodes,n=e.removedNodes;t!==n&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"items",newValue:t,oldValue:n}}))}})}observe(e){if(t.updates){const t=new MutationObserver(this.onObserve.bind(this)),s={attributeOldValue:!0,subtree:!0,childList:!0},n=e._proxy||e;t.observe(n,s)}}getProxyNode(e,t){const s=this.doDom(e,t);if(s)return this.observe(s),this.proxy(s)}extendItems(e){function s(t){t.forEach(t=>{const s=t.parentNode.removeChild(t);e.append(s)})}const n=e.items;Object.getOwnPropertyNames(Array.prototype).concat(["clear","get","remove","selected","first","last","findAll"]).forEach(o=>{if(void 0===n[o]){let i=null;const l=this;switch(o){case"copyWithin":case"fill":case"splice":i=function(){console.log("Not available yet: "+o)};break;case"reverse":i=function(...e){if(this.items.length){const t=Array.from(this.items),n=t[o](...e);return s(t),n}};break;case"clear":i=function(){for(;this.items[0];)this.items[0].remove()};break;case"get":i=function(e){let s=null;return this.items.length&&this.items.some(n=>{const o=t.utils.isNumeric(e)?1*n.dataset.id==1*e:n.dataset.id===e;if(n.dataset&&o)return s=n,!0}),s};break;case"selected":i=function(){return l.proxy(this.find(":scope > [selected]"))};break;case"first":i=function(){return l.proxy(this.items[0])};break;case"last":i=function(){return l.proxy(this.items[this.items.length-1])};break;case"pop":i=function(){if(this.items.length){const e=this[0].parentNode;return l.proxy(e.removeChild(this.items[this.items.length-1]))}};break;case"push":i=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.append(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.appendChild(s)}else console.log("Trying to push an unknown value into a list:"),console.log(e)};break;case"remove":i=function(e){if(this.items.length){const t=this.items.get(e);1===t.length&&t.remove()}};break;case"shift":i=function(){if(this.items.length){const e=this.items[0].parentNode;return l.proxy(e.removeChild(this.items[0]))}};break;case"sort":i=function(e){if(this.items.length){const t=Array.from(this.items);t.sort(e||((e,t)=>e.text.localeCompare(t.text))),s(t)}};break;case"unshift":i=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.prepend(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.prepend(s)}else console.log("Trying to unshift an unknown value into a list:"),console.log(e)};break;default:let n=o;switch(!0){case"findAll"===o:n="filter";case t.utils.isFunction(Array.prototype[o]):const s=function(...t){const s=[];return Array.from(e.items).forEach(e=>{s.push(l.proxy(e))}),Array.from(s)[n](...t)};switch(o){case"find":i=function(...e){return t.utils.isString(e[0])?this.find(e[0]):s(...e)};break;case"findAll":i=function(...e){return 0===e.length?this.findAll():t.utils.isString(e[0])?this.findAll(e[0]):s(...e)};break;case"concat":i=function(...e){for(let s=0;s{function t(t){e.exists("#m2d2-alert .m2d2-alert-front")?(e("#m2d2-alert .m2d2-alert-front").css.add("vanish"),setTimeout(()=>{e.exists("#m2d2-alert .m2d2-alert-front")&&e("#m2d2-alert").remove(),t&&t()},400)):t&&t()}const s={wrap:!1,question:["fa","fa-question-circle"],info:["fa","fa-exclamation-circle"],error:["fa","fa-exclamation-triangle"],ok:["fa","fa-check"],input:["fa","fa-edit"],wait:["fa","fa-cog","fa-spin"]},n={wrap:"material-icons",question:"help",info:"info",error:"error",ok:"done",input:"edit",wait:"pending"},o={wrap:!1,question:"icon_question",info:"icon_info",error:"icon_error",ok:"icon_ok",input:"icon_input",wait:"icon_wait"};e.message=function(i){let l=o;switch(e.messageIcons){case"fa":l=s;break;case"material":l=n;break;default:e.isObject(e.messageIcons)&&(l=e.messageIcons)}i&&(e.isFunction(i.callback)||(i.callback&&!i.text&&(i.text=i.callback),i.callback=()=>{}),i.text||(i.text="")),t(()=>{e("body",{m2d2Alert:{tagName:"div",id:"m2d2-alert",back:{tagName:"div",css:"m2d2-alert-back",style:{position:"absolute",left:0,right:0,top:0,bottom:0,backgroundColor:"#0005",display:"flex",justifyContent:"center",alignItems:"center"},front:Object.assign({tagName:"form",css:(i.css?e.isArray(i.css)?i.css:[i.css]:[]).concat(["m2d2-alert-front","popup",i.icon]),style:{zIndex:100},icon:{tagName:"span",css:["icon",i.icon].concat(l.wrap?[l.wrap]:l[i.icon]).concat("wait"===i.icon?"spin":""),text:l.wrap?l[i.icon]:""},message:{tagName:"div",css:"m2d2-alert-title",span:i.title},submsg:(()=>{let t;return t="input"!==i.icon||i.text?e.isPlainObject(i.text)?{fieldset:Object.assign({css:"m2d2-alert-field"},i.text)}:{span:i.text.replace("\n","
")}:{fieldset:{css:"m2d2-alert-field",input:{type:"text",name:"answer",onload:function(){this.focus()}}}},Object.assign({tagName:"div",css:"m2d2-alert-text"},t)})(i.icon),onsubmit:function(){const e=this.getData();let s;switch(e.button){case"ok":case"yes":s=()=>{i.callback(!0,e)};break;case"no":s=()=>{i.callback(!1,e)};break;case"cancel":s=()=>{i.callback(null,e)};break;case"send":s=1===Object.keys(e).length?()=>{i.callback(e[Object.keys(e)[0]],e)}:2===Object.keys(e).length?()=>{i.callback(e[Object.keys(e).find(e=>"button"!==e)],e)}:()=>{i.callback(e,e)};break;default:s=()=>{i.callback(e,e)}}return t(s),!1},onload:function(){const e=this.find("[autofocus]");e&&e.focus()}},function(t){let s={};return t.length&&(s={buttons:{tagName:"div",css:"m2d2-alert-buttons"}},t.forEach(t=>{const n=t.toLowerCase().replace(/[^a-z ]/g,"").replace(" ","_");s.buttons[n]={tagName:"button",type:"submit",value:n,css:["color",n],text:void 0!==e.dict?e.dict(t):t,autofocus:["ok","yes"].includes(t),formNoValidate:["cancel"].includes(t),onclick:function(){e(this.closest("form"),{hide:{tagName:"input",type:"hidden",name:"button",value:this.value}})}}})),s}(i.buttons))}}})});let a=1;return e("#m2d2-alert .m2d2-alert-front").findAll("input, select, textarea").forEach(e=>{""===e.name&&(e.name="field_"+a++)}),{close:t}},e.wait=(t,s,n)=>e.message({icon:"wait",title:t,buttons:[],text:void 0===n?null:s,callback:void 0===n?s:n}),e.alert=(t,s,n)=>e.message({icon:"info",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.success=(t,s,n)=>e.message({icon:"ok",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.failure=(t,s,n)=>e.message({icon:"error",title:t,buttons:["ok"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.confirm=(t,s,n)=>e.message({icon:"question",title:t,buttons:["yes","no"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.prompt=(t,s,n)=>e.message({icon:"input",title:t,buttons:["cancel","send"],text:void 0===n?null:s,callback:void 0===n?s:n}),e.closeAll=()=>{t()}}),t.load(e=>{let t=localStorage.getItem("m2d2.lang")||navigator.language;e.dict=new function(t){const s=function(e,t){if(void 0===e)return"";let n=s.val(e,!0);if(void 0!==t){if("string"==typeof t&&""!==t){const e=(t=t.replace(/;$/,"")).split(";");t={},e.forEach(s=>{const n=e[s].split(":");t[n[0]]=n[1]})}"object"==typeof t&&t.forEach(e=>{let o=t[e]+"";o=s.val(o,!1),n=n.replace(e,o)})}return n};return s.lang=t||"en",s.data={},s.set=function(e){return this.data=e,this},s.has=function(e,t){return void 0===t?void 0!==this.data[e]:void 0!==this.data[e][t]},s.val=function(t,n){if(e.isEmpty(s.data))return console.error("Dictionary is empty. You need to add a dictionary, for example: `$.dict.set({\nsave : { en : 'Save', es : 'Guardar' },\ncancel : { en : 'Cancel', es : 'Cancelar' }\nyes : { en : 'Yes', es : 'Si' },\nno : { en : 'No', es : 'No' }\n})`"),"";if(!t)return console.error("No keyword specified."),"";let o=t;if(void 0===n&&(n=!1),t=t.toLowerCase(),this.has(t)){const e=this.lang.split("-")[0];this.has(t,this.lang)?o=this.data[t][this.lang]:this.has(t,e)?o=this.data[t][e]:n&&console.log("Missing translation for lang ["+this.lang+"]: "+t)}else n&&console.log("Missing keyword: "+t);return o},s}(t);const s=[];e.lang=function(t){t&&(e.dict.lang=t,localStorage.setItem("m2d2.lang",e.dict.lang)),e("body").findAll("[lang]").forEach(t=>{let s=t.text;if(s&&!t.classList.contains("notxt")){void 0===t.dataset.kw&&(t.dataset.kw=e.lang.getKeyword(s)),t.text=e.dict(t.dataset.kw);const n=t.dataset.kw+"_title";let o=e.dict.has(n)?e.dict(n):"";o&&(t.title=o)}else if(t.title){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.title)),s=e.dict(t.dataset.kw),s&&(t.title=s)}else if(t.placeholder){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.placeholder)),s=e.dict(t.dataset.kw),s&&(t.placeholder=s)}else if(t.value){let s="";t.dataset.kw||(t.dataset.kw=e.lang.getKeyword(t.value)),s=e.dict(t.dataset.kw),s&&(t.value=s)}}),s.forEach(e=>{e(t)})},e.lang.getKeyword=function(e){return e.toLowerCase().trim().replace(/ /g,"_").replace(/[^\w]/g,"").replace(/_$/,"")},Object.defineProperty(e.lang,"onchange",{get(){return this},set(t){e.isFunction(t)?s.push(t):(console.log("Unable to set lang.onchange, because it is not a function: "),console.log(t))}})}),t.ready(e=>{const t=localStorage.getItem("m2d2.lang")||"",s=e("body").find("[lang]"),n=e("html").lang||(s?s.lang:null)||"en";(t?n!==t:n!==navigator.language.split("-")[0])&&e.lang()}),t.load(e=>{function t(e){switch(e){case"local":window.localStorage&&(this.store=localStorage);break;case"session":window.sessionStorage&&(this.store=sessionStorage)}null==this.store&&(this.store=localStorage),this.set=function(e,t){"string"==typeof t&&(t={$:t}),this.store.setItem(e,JSON.stringify(t))},this.get=function(e){let t;try{t=JSON.parse(this.store.getItem(e))||{}}catch(s){t=this.store.getItem(e)}return void 0!==t.$?t=t.$:0===Object.keys(t).length&&t.constructor===Object&&(t=null),t},this.del=function(e){this.store.removeItem(e)},this.keys=function(){return Object.keys(this.store).sort()},this.clear=function(){this.store.clear()},this.exists=function(e){return this.store.hasOwnProperty(e)},this.log=function(e,t,s){null==s&&(s=10);const n=this.get(e)||[];for(n.push(t);n.length>s;)n.shift();this.set(e,n)}}e.local=new t("local"),e.session=new t("session")}),t.load(e=>{function t(e,t,s){const n=[];return e=e||{},t.forEach(o=>{const i="Array"==typeof e?e.length==t.length?e[s]:e:void 0!==e[o.name]?e[o.name]:e;n.push({file:o,data:i,index:s++})}),n}function s(e,t,s,n,o){const i=new XMLHttpRequest;t=Array.from(t),i.upload.addEventListener("progress",(function(e){if(e.lengthComputable)if(n.oneByOne){const o=Math.round(100*e.loaded/e.total);n.onUpdate(o,t[0],s)}else{let s=0,o=0;t.some(t=>{s+=t.size;const i=e.loaded>=s?100:100-Math.round(100*(s-e.loaded)/t.size);return n.onUpdate(i,t,o++),s>=e.loaded})}}),!1),i.addEventListener("load",(function(e){let l={};try{l=i.responseText?JSON.parse(i.responseText):{error:{type:"Unknown",reason:"Unknown Error"}}}catch(e){l.error={type:"Parse Error",reason:e.message}}i.status>=200&&i.status<400?o(n.onResponse(l),t,s):("string"==typeof l.error&&(l.error={type:"Exception",reason:l.error}),n.onError(l.error))}),!1),i.open("POST",n.upload);const l=Array(t.length).fill(!1),a=function(e,t){const s=new FormData;return t.forEach(t=>{s.append(e,t,t.name)}),s}(e,t);let r=0;t.forEach(e=>{const t=new FileReader;t.onload=function(e){l[r++]=!0,-1===l.indexOf(!1)&&i.send(a)},t.readAsBinaryString(e)})}e.upload=function(e,n){const o=Object.assign({},{accept:"*/*",parallel:!1,field:"file",multiple:!0,maxFiles:0,maxSizeMb:0},n);n=null;let i=window._protected_reference=document.createElement("INPUT");i.name=o.field,i.type="file",1==o.multiple&&(i.multiple="multiple"),o.upload||(console.log("Upload not specified. Using current page."),o.upload=""),null==o.onDone&&(o.onDone=(e,t)=>{console.log(e)}),null==o.onError&&(o.onError=e=>{console.log("Error : "),console.log(e)}),null==o.onUpdate&&(o.onUpdate=(e,t,s)=>{console.log("Uploading : "+e+"% "+(o.oneByOne?"[ "+t.name+" ]":""))}),null==o.onResponse&&(o.onResponse=e=>e),i.addEventListener("change",()=>{if(i.files.length){if(!(0===o.maxFiles|i.files.length<=o.maxFiles))return o.onError("Max file limit exceeded. Maximum files: "+o.maxFiles),!1;if(o.onSelect){const e=[];let t=0;Array.from(i.files).forEach(s=>{e.push(URL.createObjectURL(s)),t+=s.size});const s=t/1048576;if(o.maxSizeMb&&s>o.maxSizeMb)return o.onError("Maximum size exceeded: "+Math.ceil(s)+"MB > "+o.maxSizeMb+"MB"),!1;o.onSelect(i.files,e)}new Promise(e=>{if(o.oneByOne){let n=0;const l=Array(i.files.length).fill(!1);Array.from(i.files).forEach(a=>{new s(i.name,[a],n++,o,(s,n,i)=>{l[i]=!0;const a=-1===l.indexOf(!1);o.onDone(t(s,n,i),a),a&&e()})})}else new s(i.name,i.files,0,o,(s,n,i)=>{o.onDone(t(s,n,i),!0),e()})}).then(()=>{i=window._protected_reference=void 0})}}),i.click()}}),t.load(e=>{const t=function(e,t,s,n,o,i){const l=new XMLHttpRequest;if(void 0===i&&(i=!1),void 0===o&&(o=function(e){console.log(e)}),s&&0===Object.entries(s).length&&(s=""),s)if(i)s=JSON.stringify(s);else switch(e.toUpperCase()){case"GET":t+=(-1!==t.indexOf("?")?"&":"?")+Object.keys(s).map(e=>e+"="+s[e]).join("&"),s="";break;default:s=Object.keys(s).map(e=>e+"="+s[e]).join("&")}return l.open(e,t,!0),i?l.setRequestHeader("Content-Type","application/json"):l.setRequestHeader("Content-type","application/x-www-form-urlencoded"),l.onerror=function(e){o({type:"Connection",reason:"Connection Refused"})},l.onload=function(){let e={};try{e=l.responseText?JSON.parse(l.responseText):{error:{type:"Unknown",reason:"Unknown Error"}}}catch(t){e.error={type:"Parse Error",reason:t.message}}l.status>=200&&l.status<400?void 0!==n&&n(e):void 0!==o&&("string"==typeof e.error&&(e.error={type:"Exception",reason:e.error}),o(e.error))},l.send(s),l},s={};["get","post","put","delete","connect","options","trace","patch"].forEach((function(e){s[e]=function(){let s,n,o,i,l;switch(arguments.length){case 5:"boolean"==typeof arguments[4]?l=arguments[4]:console.log("Passed JSON argument: "+arguments[4]+" is not boolean.");case 4:"function"==typeof arguments[3]?i=arguments[3]:4===arguments.length&&"boolean"==typeof arguments[3]?l=arguments[3]:console.log("Passed argument 4: "+arguments[3]+" is mistaken");case 3:"function"==typeof arguments[2]?"function"==typeof arguments[1]&&arguments.length<5?i=arguments[2]:o=arguments[2]:3===arguments.length&&"boolean"==typeof arguments[2]?l=arguments[2]:console.log("Passed argument 3: "+arguments[2]+" is mistaken");case 2:"object"==typeof arguments[1]||"string"==typeof arguments[1]?n=arguments[1]:"function"==typeof arguments[1]?o=arguments[1]:console.log("Passed argument 2: "+arguments[1]+" is mistaken");case 1:"string"==typeof arguments[0]?s=arguments[0]:Array.isArray(arguments[0])?s=arguments[0].join("/"):console.log("Passed URL: "+arguments[0]+" was not a string.");break;default:console.log("Incorrect number of arguments passed to xhr")}return void 0===n&&(n={}),t(e.toUpperCase(),s,n,o,i,l)}})),Object.assign(e,s)}),t})); \ No newline at end of file diff --git a/dist/m2d2.lang.min.js b/dist/m2d2.lang.min.js index 45c8789..26b80d9 100644 --- a/dist/m2d2.lang.min.js +++ b/dist/m2d2.lang.min.js @@ -1,8 +1,8 @@ /** * Author : A.Lepe (dev@alepe.com) - intellisrc.com * License: MIT - * Version: 2.1.1 - * Updated: 2022-02-24 + * Version: 2.1.2 + * Updated: 2022-03-07 * Content: Extension */ diff --git a/dist/m2d2.min.js b/dist/m2d2.min.js index d63206d..0a16d9c 100644 --- a/dist/m2d2.min.js +++ b/dist/m2d2.min.js @@ -1,9 +1,9 @@ /** * Author : A.Lepe (dev@alepe.com) - intellisrc.com * License: MIT - * Version: 2.1.1 - * Updated: 2022-02-24 + * Version: 2.1.2 + * Updated: 2022-03-07 * Content: Core */ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.m2d2=t()}(this,(function(){"use strict";class e{isString(e){return"string"==typeof e}isBool(e){return"boolean"==typeof e}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isSelectorID(e){return 0===(e+"").trim().indexOf("#")}isPlainObject(e){return"Object"===e.constructor.name}isObject(e){return"object"==typeof e}isArray(e){return Array.isArray(e)}isFunction(e){return"function"==typeof e}isElement(e){return e instanceof HTMLElement}isNode(e){return e instanceof Node||e instanceof DocumentFragment}isHtml(e){return-1!==(e+"").trim().indexOf("<")}isEmpty(e){return void 0===e||this.isObject(e)&&0===Object.keys(e).length||""===e}isVisible(e){if(!this.isElement(e))return console.log("(isVisible) Not an element: "),console.log(e),!1;const t="none"!==e.style.display,s="hidden"!==e.style.visibility;return t&&s}inView(e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)&&t.width>0&&t.height>0}cleanArray(e){return e.filter((function(e){return 0===e||e}))}isValidElement(e){const t=this.newElement(e);return"template"!==e&&"HTMLUnknownElement"!==t.constructor.name}exists(e){return null!==document.querySelector(e)}getAttrOrProp(e,t){let s="";return this.hasAttrOrProp(e,t)&&(s=this.hasAttr(e,t)?e.getAttribute(t):e[t]),s}hasAttrOrProp(e,t){return this.hasAttr(e,t)||this.hasProp(e,t)}hasAttr(e,t){let s=!1;if(e&&!this.isNumeric(t))switch(t){case"checked":s=void 0!==e.type&&("radio"===e.type||"checkbox"===e.type);break;default:s=void 0!==e.hasAttribute&&e.hasAttribute(t)}return s}hasProp(e,t){let s=!1;if(e&&!this.isNumeric(t)){let i=void 0!==e[t];i&&null===e[t]&&"value"===t&&(i=!1),s=i&&!(e[t]instanceof Node)&&!e.hasAttribute(t)}return s}setPropOrAttr(e,t,s){if(this.hasProp(e,t))try{e[t]=s}catch(i){this.setAttr(e,t,s)}else this.setAttr(e,t,s)}setAttr(e,t,s){s?e.setAttribute(t,s):e.removeAttribute(t)}defineProp(e,t,s){this.isObject(e)&&void 0===e[t]&&(Object.defineProperty(e,t,{enumerable:!1,writable:!0}),e[t]=s)}htmlElement(e){const t=this.newElement("template");return t.innerHTML=e.trim(),t.content.firstChild}newElement(e){return document.createElement(e)}newEmptyNode(){return new DocumentFragment}getMethods(e){const t=Reflect.getPrototypeOf(e),s=Reflect.getPrototypeOf(t);return Reflect.ownKeys(t).filter(e=>Reflect.ownKeys(s).indexOf(e)<0)}appendAllChild(e,t){for(;e.firstChild;)t.append(e.firstChild)}prependAllChild(e,t){for(;e.firstChild;)t.prepend(e.firstChild)}}class t{"use strict";_stored={events:[],datasetNodes:[],datasets:[],styleNodes:[],styles:[]};static storedEventsTimeout=50;static short=!0;static updates=!0;static utils=new e;constructor(){}static instance=new t;static extensions={};static main=(()=>{const e=(e,s)=>{const i=this.instance.getProxyNode(e,s);return i&&i.onready&&t.utils.isFunction(i.onready)&&(i.addEventListener("ready",i.onready,{once:!0}),setTimeout(()=>{i.dispatchEvent(new CustomEvent("ready"))},10)),["dataset","style"].forEach(e=>{i&&i[e]&&(this.instance._stored[e+"s"].push(i[e]),this.instance._stored[e+"Nodes"].push(i))}),i};return t.utils.getMethods(t.utils).forEach(s=>{e[s]=t.utils[s]}),e})();static ready(e){document.addEventListener("DOMContentLoaded",()=>{e(t.main)})}static load(e){if(void 0!==e){const s=e(t.main);t.utils.isObject(s)&&!t.utils.isEmpty(s)&&Object.keys(s).forEach(e=>{if(t.utils.isValidElement(e)){void 0===t.extensions[e]&&(t.extensions[e]={});const i=t.utils.newElement(e);Object.keys(s[e]).forEach(s=>{t.utils.hasProp(i,s)&&console.log("Warning: property ["+s+"] already exists in node: ["+e+"] while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions[e],s[e])}else{void 0===t.extensions["*"]&&(t.extensions["*"]={});const i=t.utils.newElement("div");Object.keys(s[e]).forEach(e=>{t.utils.hasProp(i,e)&&console.log("Warning: property ["+e+"] already exists in Node while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions["*"],s[e])}})}return t.main}extDom(e,s){if(!e)return console.error("Selector was empty"),null;void 0===s&&(s=document);const i=t.utils.isNode(e)?e:s.querySelector(e);if(!i)return t.utils.isString(e)?(console.error("Selector: "+e+" didn't match any element in node:"),console.log(s)):console.error("Node was null"),null;if(void 0===i._m2d2){i._m2d2=!0,["parent","sibling","next","prev","find","findAll","onupdate","onready","show","onshow","inView","css","text","html","getData","index"].forEach(e=>{i.hasOwnProperty(e)&&(console.log("Node already had ["+e+"] property. It might cause unexpected behaviour."),console.log("You may need to update the M2D2 version or report it to: github.com/intellisrc/m2d2/"))}),Object.defineProperty(i,"text",{get(){return this.childNodes.length?this.innerText:this.textContent},set(e){if(this.childNodes.length){let t=!1;this.childNodes.forEach(s=>{"Text"===s.constructor.name&&(s.nodeValue=e,t=!0)}),t||this.prepend(document.createTextNode(e))}else this.textContent=e}}),Object.defineProperty(i,"html",{get(){return this.innerHTML},set(e){this.innerHTML=e}}),Object.defineProperty(i,"css",{get(){return this.classList},set(e){t.utils.isArray(e)?this.className=e.join(" "):t.utils.isString(e)?this.className=e:t.utils.isPlainObject(e)?Object.keys(e).forEach(t=>{e[t]?this.classList.add(t):this.classList.remove(t)}):console.error("Trying to assign a wrong value to css : "+e)}}),Object.defineProperty(i,"show",{get(){return t.utils.isVisible(this)},set(e){const s=()=>getComputedStyle(this,null).display,i=()=>{const e=document.getElementsByTagName("body")[0],t=document.createElement("template"),s=document.createElement(this.tagName);t.append(s),e.append(t);const i=getComputedStyle(s,null).display;return t.remove(),i};if(e){if("none"===s()){if(this._m2d2_display)this.style.display=this._m2d2_display;else if(this.style.removeProperty("display"),"none"===s()){const e=i();this.style.display=this.dataset.display||("none"!==e?e:"block")}void 0!==this.onshow&&t.utils.isFunction(this.onshow)&&this.onshow(this)}}else{const e="none"!==this.style.display?this.style.display:s();"none"!==e&&(this._m2d2_display=e),this.style.display="none"}}});let e={};return void 0!==t.extensions["*"]&&Object.assign(e,t.extensions["*"]),void 0!==t.extensions[i.tagName]&&Object.assign(e,t.extensions[i.tagName]),Object.assign(i,{inView:()=>t.utils.inView(i),next:()=>i.nextElementSibling,prev:()=>i.previousElementSibling,parent:()=>this.extDom(i.parentElement),sibling:e=>i.parentElement.find(e),find:e=>{const t=i.querySelector(e);return t?this.extDom(t):null},findAll:e=>{const t=void 0===e?Array.from(i.children):i.querySelectorAll(e);return t.forEach(e=>{this.extDom(e)}),t}},e),void 0===i.index&&(i.index=()=>Array.from(i.parentNode.children).indexOf(i)),["INPUT","TEXTAREA","SELECT"].indexOf(i.tagName)>=0&&t.utils.hasAttrOrProp(i,"value")&&(i.oninput=function(){this.setAttribute("value",this.value)}),"FORM"===i.tagName&&(i.getData=function(e){const t={},s=new FormData(this),n=e||!1;for(let e of s.entries()){const s=i.find("[name='"+e[0]+"']");(n||"hidden"===s.type||s.show)&&(t[e[0]]="file"===s.type?s.files:e[1])}return t}),i}return i}doDom(e,s){if(t.utils.isObject(e)&&void 0===s&&(s=e,e=t.utils.newEmptyNode(),void 0===s.warn&&(s.warn=!1)),!(t.utils.isString(e)||t.utils.isElement(e)||t.utils.isNode(e)))return console.error("Selector is not a string or a Node:"),console.log(e),null;if(t.utils.isString(e)&&!document.querySelector(e))return console.log("Selected element doesn't exists: "+e),null;const i=this.extDom(e);if(void 0===s)return i;if(s=this.plainToObject(i,s),Object.keys(s).filter(e=>!["tagName"].includes(e)).forEach(e=>{let n=s[e];null==n&&(console.log("Value was not set for key: "+e+", 'empty' was used in object: "),console.log(s),console.log("In node:"),console.log(i),n="");let o=this.updateValue(i,e,n),l=t.utils.hasProp(i,e),r=!1;if(t.utils.hasAttr(i,e)||l)switch(!0){case"value"===e&&t.utils.hasProp(i,"valueAsDate")&&o instanceof Date:e="valueAsDate";case"css"===e:case typeof o==typeof i[e]:case t.utils.isString(i[e])&&t.utils.isNumeric(o):case t.utils.isFunction(o)&&t.utils.isObject(i[e]):case t.utils.isBool(o)&&t.utils.isString(i[e]):case"object"==typeof i[e]&&"INPUT"===i.tagName:r=!0}if(r){let s=!1;switch(e){case"classList":t.utils.isArray(o)?o.forEach(t=>{i[e].add(t)}):t.utils.isString(o)?i[e].add(o):s=!0;break;case"style":case"dataset":t.utils.isPlainObject(o)?Object.keys(o).forEach(t=>{i[e][t]=this.updateValue(i[e],t,o[t])}):s=!0;break;default:switch(!0){case t.utils.isBool(o):case t.utils.hasAttrOrProp(i,e):t.utils.setPropOrAttr(i,e,o);break;default:i[e]=o}}s&&(console.error("Invalid value passed to '"+e+"': "),console.log(o),console.log("Into Node:"),console.log(i))}else{const l=[];try{if("template"!==e&&!t.utils.isFunction(o)){if(e&&e.match(/^\w/)){let t=i.find("#"+e);t&&-1===l.indexOf(t)&&l.push(t),t=i.find("[name='"+e+"']"),t&&-1===l.indexOf(t)&&l.push(t);const s=Array.from(i.findAll("."+e)).filter(e=>l.indexOf(e)<0);s.length>0&&s.forEach(e=>l.push(e))}const t=Array.from(i.findAll(e)).filter(e=>l.indexOf(e)<0);t.length>0&&t.forEach(e=>l.push(e))}}catch(t){return console.error("Invalid selector: "+e),void console.log(t)}if(l.length>1){const t=[];l.forEach(s=>{t.push(this.render(s,e,o))}),this.linkNode(i,e,t),void 0!==o.warn&&!1===o.warn||(console.log("Multiple elements were assigned with key: ["+e+"] under node: "),console.log(i),console.log("It might be what we expect, but if it is not expected it could result on some elements mistakenly rendered. You can specify 'warn : false' under that element to hide this message."))}else if(1===l.length){const r=l[0];if(t.utils.isElement(r)){const l=this.plainToObject(r,o),a=t.utils.isPlainObject(l)&&Object.keys(l).length>=1?Object.keys(l)[0]:null;if(a&&(o=this.updateValue(r,a,n)),t.utils.isArray(o)){const t=s.template;this.doItems(r,o,t),this.linkNode(i,e,r)}else this.renderAndLink(i,r,e,o)}else console.error("BUG: It should have been a node but got: "),console.log(r),console.log("Parent node:"),console.log(i)}else if(0===l.length){"template"===e&&void 0===s.items&&(e="items",o=[]);const n=t.utils.isFunction(o);if(void 0!==o.tagName){const t=this.appendElement(i,o.tagName);this.renderAndLink(i,t,e,o)}else if(t.utils.isValidElement(e)&&!n){const t=this.appendElement(i,e);this.renderAndLink(i,t,e,o)}else if("items"===e){const e=s.template;if(t.utils.isPlainObject(o)){const e=[];Object.keys(o).forEach(s=>{let n;"DL"===i.tagName?n={dt:s,dd:o[s]}:(n={text:o[s]},t.utils.hasAttrOrProp(i,"value")?n.value=s:n.dataset={id:s}),e.push(n)}),o=e}t.utils.isArray(o)?this.doItems(i,o,e):(console.log("Warning: 'items' specified but value is not and array, in element: "),console.log(i),console.log("Passed values are: "),console.log(o))}else n?(t.updates&&"onupdate"===e&&i.addEventListener("update",o,!0),i[e]=o):"template"!==e&&"warn"!==e&&!1!==o&&(void 0!==s.warn&&!1===s.warn||(console.error("Not sure what you want to do with key: "+e+" under element: "),console.log(i),console.log("And object:"),console.log(s),console.log("Most likely the element's property or child no longer exists or the value passed to it is incorrect."),console.log("You can set 'warn : false' property to the element to dismiss this message.")),i[e]=o)}}}),i.onload){const e=["BODY","FRAME","IFRAME","IMG","LINK","SCRIPT","STYLE"].indexOf(i.tagName)>=0,t="INPUT"===i.tagName&&"image"===i.type;e||t||i.dispatchEvent(new CustomEvent("load"))}return i}isUpdateLink(e){let s=!1;if(t.utils.isArray(e)&&(2===e.length||3===e.length)){const i=2===e.length,n=t.utils.isNode(e[0])||e[0]instanceof DOMStringMap||e[0]instanceof CSSStyleDeclaration,o=i?t.utils.isString(e[1]):t.utils.isString(e[1])&&t.utils.isFunction(e[2]);s=n&&o,s&&i&&e.push(e=>e)}return s}plainToObject(e,s){if(!t.utils.isPlainObject(s)&&!t.utils.isFunction(s)&&!t.utils.isElement(s))if(t.utils.isHtml(s))s={html:s};else if(this.isUpdateLink(s)){const i=s[0],n=s[1],o=s[2];let l=this.plainToObject(e,o(i[n]));if(t.utils.isPlainObject(l)){const e={};Object.keys(l).forEach(t=>{e[t]=s}),s=e}}else t.utils.isArray(s)?s={items:s}:t.utils.hasAttrOrProp(e,"value")?s="SELECT"===e.tagName?{value:s,text:s}:"BUTTON"===e.tagName?{text:s}:{value:s}:t.utils.isString(s)&&"IMG"===e.tagName?s={src:s}:(t.utils.isString(s)||t.utils.isNumeric(s))&&(s={text:s});return s}renderAndLink(e,t,s,i){const n=this.render(t,s,i);this.linkNode(e,s,n)}render(e,t,s){return s=this.plainToObject(e,s),this.doDom(e,s)}linkNode(e,s,i){if(e[s]===i){const t=this.proxy(i);try{e[s]=t}catch(e){}e["$"+s]=t}else t.utils.hasAttrOrProp(e,s)?(e["$"+s]=i,console.log("Property : "+s+" existed in node: "+e.tagName+". Using $"+s+" instead for node: "+i.tagName+".")):e[s]=this.proxy(i)}appendElement(e,s){const i=t.utils.newElement(s);return e.append(i),i}getItem(e,t,s,i){i||(i=this.getTemplate(e));const n=i.cloneNode(!0);this.addTemplatesToItem(i,n),n.dataset.id=t,this.setUniqueAttrib(n,"selected");let o=this.doDom(n,s);return this.getItemWithEvents(e,o)}addTemplatesToItem(e,t){["_template","__template"].forEach(s=>{void 0!==e[s]&&(t[s]=e[s])})}getItemWithEvents(e,s){if(void 0!==e.__template){const i=(e,s)=>(s=s||{},Object.keys(e).forEach(n=>{t.utils.isPlainObject(e[n])?s[n]=i(e[n]):t.utils.isFunction(e[n])&&(s[n]=e[n])}),s);let n=i(e.__template);t.utils.isEmpty(n)||(n=n[Object.keys(n)[0]],s=this.doDom(s,n))}return s}doItems(e,t,s){const i=this.getTemplate(e,s);if(void 0===i)return console.error("Template not found. Probably an array is being used where it is not expected. Node:"),console.log(e),console.log("Value (mistaken?):"),void console.log(t);let n=0;t.forEach(t=>{t=this.plainToObject(e,t);const s=this.getItem(e,n++,t,i);s&&e.append(s)});const o=e.find("template");o&&e.removeChild(o),e.items=e.children,this.extendItems(e)}getTemplate(e,s){if(void 0!==e._template&&""!==e._template)return e._template;{let i;const n=e.querySelector("template");if(n)i=t.utils.htmlElement(n.innerHTML.trim());else switch(e.tagName){case"SELECT":case"DATALIST":i=t.utils.newElement("option");break;case"UL":case"OL":i=t.utils.newElement("li");break;case"NAV":i=t.utils.newElement("a");break;case"DL":i=t.utils.newElement("dd");break;default:if(s){const n=Object.keys(s).length;if(n){if(n>1)if(void 0!==s.tagName){let e={};e[s.tagName]=s,s=e}else console.log("Template has more than one top elements. Using the first one. In: "),console.log(s),console.log("Node: "),console.log(e);const o=Object.keys(s)[0],l=s[o];t.utils.isValidElement(o)?i=t.utils.newElement(o):void 0!==l.tagName?(i=t.utils.newElement(l.tagName),s[l.tagName]=l,delete s[o]):(console.error("Template defined an element which can not be identified: ["+o+"], using in:"),console.log(s),console.log("Node: "),console.log(e),i=t.utils.newElement("span"))}else console.error("Template has no definition, and it can not be guessed. Using . Template: "),console.log(s),console.log("Node: "),console.log(e),i=t.utils.newElement("span")}else e.childElementCount>0&&(i=t.utils.htmlElement(e.innerHTML.trim()))}if(s)if(t.utils.isPlainObject(s)){const n=t.utils.newEmptyNode();n.append(i),i=this.doDom(n,s).children[0],t.utils.defineProp(e,"__template",s)}else i=t.utils.isHtml(s)?t.utils.htmlElement(s):t.utils.isSelectorID(s)?t.utils.htmlElement(document.querySelector(s).innerHTML):t.utils.newElement(s);if(i.childrenElementCount>1){console.log("Templates only supports a single child. Multiple children were detected, wrapping them with . Template:"),console.log(i);const e=t.utils.newElement("span");e.append(i),i=e}return i&&t.utils.defineProp(e,"_template",i),i}}setUniqueAttrib(e,s){e.hasOwnProperty(s)||Object.defineProperty(e,s,{get:function(){return this.hasAttribute(s)},set:function(e){const i=this.parentNode?this.parentNode.find("["+s+"]"):null;i&&i.removeAttribute(s),t.utils.setAttr(this,s,e)}})}updateValue(e,s,i){if(this.isUpdateLink(i)){const n=this,o=i[0],l=i[1],r=i[2];if(i=o[l],o instanceof CSSStyleDeclaration&&this._stored.styles.includes(o)){const i=this._stored.styleNodes[this._stored.styles.indexOf(o)];t.updates&&(i.onupdate=function(t){t.detail&&"style"===t.detail.property&&t.detail.newValue.startsWith(l+":")&&n.setShortValue(e,s,r(this.style[l]))})}else if(o instanceof DOMStringMap&&this._stored.datasets.includes(o)){const i=this._stored.datasetNodes[this._stored.datasets.indexOf(o)];t.updates&&(i.onupdate=t=>{t.detail&&t.detail.property==="data-"+l&&n.setShortValue(e,s,r(t.detail.newValue))})}else t.updates&&(o.onupdate=i=>{i.detail&&i.detail.property===l&&(t.utils.isObject(e[s])||n.setShortValue(e,s,r(i.detail.newValue)))})}return i}setShortValue(e,s,i){if(t.utils.isNode(e[s]))if(t.short){const n=this.plainToObject(e[s],i),o=t.utils.isPlainObject(n)&&Object.keys(n).length>=1?Object.keys(n)[0]:null;o&&(e[s][o]=i)}else console.log("Short is disabled. Trying to set a value ("+i+") in a node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else e[s]=i}getShortValue(e,s,i){let n=null;if(t.utils.isNode(e[s]))if(t.short){const o=this.plainToObject(e[s],i||""),l=t.utils.isPlainObject(o)&&Object.keys(o).length>=1?Object.keys(o)[0]:null;l&&(n=e[s][l])}else console.log("Short is disabled. Trying to get a value from node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else n=e[s];return n}proxy(e,s){return!t.short||null===e||void 0!==e._proxy&&void 0===s?e:(e._proxy=e,new Proxy(e,{get:(e,s)=>{const i=e[s];switch(!0){case null==i:return null;case t.utils.isFunction(i):return i.bind(e);case i._proxy&&void 0!==e["$"+s]:return e["$"+s];case void 0===i._proxy&&t.utils.isElement(i):return this.proxy(i);default:return i}},set:(e,s,i)=>{let n="";return t.utils.isElement(e[s])?(n=this.getShortValue(e,s,i),this.setShortValue(e,s,i)):"onupdate"===s?t.updates?t.utils.isFunction(i)?(e.addEventListener("update",i,!0),n=e[s],e[s]=i):(console.error("Value passed to 'onupdate' is incorrect, in node:"),console.log(e),console.log("Value: (not a function)"),console.log(i)):(console.log("Updates are not available when `m2d2.updates == false`:"),console.log(e)):"items"===s?(e.items.clear(),this.doItems(e,i)):(n=e[s],i=this.updateValue(e,s,i),e[s]=i),t.updates&&void 0!==e.onupdate&&i!==n&&e.dispatchEvent(new CustomEvent("update",{detail:{type:typeof i,property:s,newValue:i,oldValue:n}})),!0}}))}onObserve(e,s){e.forEach(e=>{const s=e.target;if(!(this._stored.events.indexOf(e)>=0)&&(this._stored.events.push(e),setTimeout(()=>{const t=this._stored.events.indexOf(e);t>=0&&this._stored.events.splice(t,1)},t.storedEventsTimeout),void 0!==s.onupdate))if("attributes"===e.type){const i=t.utils.getAttrOrProp(s,e.attributeName);i!==e.oldValue&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof i,property:e.attributeName,newValue:i,oldValue:e.oldValue}}))}else if("childList"===e.type)if("#text"===(e.addedNodes[0]||e.removedNodes[0]).nodeName){const t=e.addedNodes[0].textContent,i=e.removedNodes.length?e.removedNodes[0].textContent:null;t!==i&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"text",newValue:t,oldValue:i}}))}else if(void 0!==s.items){const t=e.addedNodes,i=e.removedNodes;t!==i&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"items",newValue:t,oldValue:i}}))}})}observe(e){if(t.updates){const t=new MutationObserver(this.onObserve.bind(this)),s={attributeOldValue:!0,subtree:!0,childList:!0},i=e._proxy||e;t.observe(i,s)}}getProxyNode(e,t){const s=this.doDom(e,t);if(s)return this.observe(s),this.proxy(s)}extendItems(e){function s(t){t.forEach(t=>{const s=t.parentNode.removeChild(t);e.append(s)})}const i=e.items;Object.getOwnPropertyNames(Array.prototype).concat(["clear","get","remove","selected","first","last","findAll"]).forEach(n=>{if(void 0===i[n]){let o=null;const l=this;switch(n){case"copyWithin":case"fill":case"splice":o=function(){console.log("Not available yet: "+n)};break;case"reverse":o=function(...e){if(this.items.length){const t=Array.from(this.items),i=t[n](...e);return s(t),i}};break;case"clear":o=function(){for(;this.items[0];)this.items[0].remove()};break;case"get":o=function(e){let s=null;return this.items.length&&this.items.some(i=>{const n=t.utils.isNumeric(e)?1*i.dataset.id==1*e:i.dataset.id===e;if(i.dataset&&n)return s=i,!0}),s};break;case"selected":o=function(){return l.proxy(this.find(":scope > [selected]"))};break;case"first":o=function(){return l.proxy(this.items[0])};break;case"last":o=function(){return l.proxy(this.items[this.items.length-1])};break;case"pop":o=function(){if(this.items.length){const e=this[0].parentNode;return l.proxy(e.removeChild(this.items[this.items.length-1]))}};break;case"push":o=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.append(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.appendChild(s)}else console.log("Trying to push an unknown value into a list:"),console.log(e)};break;case"remove":o=function(e){if(this.items.length){const t=this.items.get(e);1===t.length&&t.remove()}};break;case"shift":o=function(){if(this.items.length){const e=this.items[0].parentNode;return l.proxy(e.removeChild(this.items[0]))}};break;case"sort":o=function(e){if(this.items.length){const t=Array.from(this.items);t.sort(e||((e,t)=>e.text.localeCompare(t.text))),s(t)}};break;case"unshift":o=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.prepend(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.prepend(s)}else console.log("Trying to unshift an unknown value into a list:"),console.log(e)};break;default:let i=n;switch(!0){case"findAll"===n:i="filter";case t.utils.isFunction(Array.prototype[n]):const s=function(...t){const s=[];return Array.from(e.items).forEach(e=>{s.push(l.proxy(e))}),Array.from(s)[i](...t)};switch(n){case"find":o=function(...e){return t.utils.isString(e[0])?this.find(e[0]):s(...e)};break;case"findAll":o=function(...e){return 0===e.length?this.findAll():t.utils.isString(e[0])?this.findAll(e[0]):s(...e)};break;case"concat":o=function(...e){for(let s=0;s=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)&&t.width>0&&t.height>0}cleanArray(e){return e.filter((function(e){return 0===e||e}))}isValidElement(e){const t=this.newElement(e);return"template"!==e&&"HTMLUnknownElement"!==t.constructor.name}exists(e){return null!==document.querySelector(e)}getAttrOrProp(e,t){let s="";return this.hasAttrOrProp(e,t)&&(s=this.hasAttr(e,t)?e.getAttribute(t):e[t]),s}hasAttrOrProp(e,t){return this.hasAttr(e,t)||this.hasProp(e,t)}hasAttr(e,t){let s=!1;if(e&&!this.isNumeric(t))switch(t){case"checked":s=void 0!==e.type&&("radio"===e.type||"checkbox"===e.type);break;default:s=void 0!==e.hasAttribute&&e.hasAttribute(t)}return s}hasProp(e,t){let s=!1;if(e&&!this.isNumeric(t)){let i=void 0!==e[t];i&&null===e[t]&&"value"===t&&(i=!1),s=i&&!(e[t]instanceof Node)&&!e.hasAttribute(t)}return s}setPropOrAttr(e,t,s){if(this.hasProp(e,t))try{e[t]=s}catch(i){this.setAttr(e,t,s)}else this.setAttr(e,t,s)}setAttr(e,t,s){s?e.setAttribute(t,s):e.removeAttribute(t)}defineProp(e,t,s){this.isObject(e)&&void 0===e[t]&&(Object.defineProperty(e,t,{enumerable:!1,writable:!0}),e[t]=s)}htmlElement(e){const t=this.newElement("template");return t.innerHTML=e.trim(),t.content.firstChild}newElement(e){return document.createElement(e)}newEmptyNode(){return new DocumentFragment}getMethods(e){const t=Reflect.getPrototypeOf(e),s=Reflect.getPrototypeOf(t);return Reflect.ownKeys(t).filter(e=>Reflect.ownKeys(s).indexOf(e)<0)}appendAllChild(e,t){for(;e.firstChild;)t.append(e.firstChild)}prependAllChild(e,t){for(;e.firstChild;)t.prepend(e.firstChild)}}class t{"use strict";_stored={events:[],datasetNodes:[],datasets:[],styleNodes:[],styles:[]};static storedEventsTimeout=50;static short=!0;static updates=!0;static utils=new e;constructor(){}static instance=new t;static extensions={};static main=(()=>{const e=(e,s)=>{const i=this.instance.getProxyNode(e,s);return i&&i.onready&&t.utils.isFunction(i.onready)&&(i.addEventListener("ready",i.onready,{once:!0}),setTimeout(()=>{i.dispatchEvent(new CustomEvent("ready"))},10)),["dataset","style"].forEach(e=>{i&&i[e]&&(this.instance._stored[e+"s"].push(i[e]),this.instance._stored[e+"Nodes"].push(i))}),i};return t.utils.getMethods(t.utils).forEach(s=>{e[s]=t.utils[s]}),e})();static ready(e){document.addEventListener("DOMContentLoaded",()=>{e(t.main)})}static load(e){if(void 0!==e){const s=e(t.main);t.utils.isObject(s)&&!t.utils.isEmpty(s)&&Object.keys(s).forEach(e=>{if(t.utils.isValidElement(e)){void 0===t.extensions[e]&&(t.extensions[e]={});const i=t.utils.newElement(e);Object.keys(s[e]).forEach(s=>{t.utils.hasProp(i,s)&&console.log("Warning: property ["+s+"] already exists in node: ["+e+"] while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions[e],s[e])}else{void 0===t.extensions["*"]&&(t.extensions["*"]={});const i=t.utils.newElement("div");Object.keys(s[e]).forEach(e=>{t.utils.hasProp(i,e)&&console.log("Warning: property ["+e+"] already exists in Node while trying to extend it. Unexpected behaviour may happen.")}),Object.assign(t.extensions["*"],s[e])}})}return t.main}extDom(e,s){if(!e)return console.error("Selector was empty"),null;void 0===s&&(s=document);const i=t.utils.isNode(e)?e:s.querySelector(e);if(!i)return t.utils.isString(e)?(console.error("Selector: "+e+" didn't match any element in node:"),console.log(s)):console.error("Node was null"),null;if(void 0===i._m2d2){i._m2d2=!0,["parent","sibling","posterior","anterior","find","findAll","onupdate","onready","show","onshow","inView","css","text","html","getData","index"].forEach(e=>{i.hasOwnProperty(e)&&(console.log("Node already had ["+e+"] property. It might cause unexpected behaviour."),console.log("You may need to update the M2D2 version or report it to: github.com/intellisrc/m2d2/"))}),Object.defineProperty(i,"text",{get(){return this.childNodes.length?this.innerText:this.textContent},set(e){if(this.childNodes.length){let t=!1;this.childNodes.forEach(s=>{"Text"===s.constructor.name&&(s.nodeValue=e,t=!0)}),t||this.prepend(document.createTextNode(e))}else this.textContent=e}}),Object.defineProperty(i,"html",{get(){return this.innerHTML},set(e){this.innerHTML=e}}),Object.defineProperty(i,"css",{get(){return this.classList},set(e){t.utils.isArray(e)?this.className=e.join(" "):t.utils.isString(e)?this.className=e:t.utils.isPlainObject(e)?Object.keys(e).forEach(t=>{e[t]?this.classList.add(t):this.classList.remove(t)}):console.error("Trying to assign a wrong value to css : "+e)}}),Object.defineProperty(i,"show",{get(){return t.utils.isVisible(this)},set(e){const s=()=>getComputedStyle(this,null).display,i=()=>{const e=document.getElementsByTagName("body")[0],t=document.createElement("template"),s=document.createElement(this.tagName);t.append(s),e.append(t);const i=getComputedStyle(s,null).display;return t.remove(),i};if(e){if("none"===s()){if(this._m2d2_display)this.style.display=this._m2d2_display;else if(this.style.removeProperty("display"),"none"===s()){const e=i();this.style.display=this.dataset.display||("none"!==e?e:"block")}void 0!==this.onshow&&t.utils.isFunction(this.onshow)&&this.onshow(this)}}else{const e="none"!==this.style.display?this.style.display:s();"none"!==e&&(this._m2d2_display=e),this.style.display="none"}}});let e={};return void 0!==t.extensions["*"]&&Object.assign(e,t.extensions["*"]),void 0!==t.extensions[i.tagName]&&Object.assign(e,t.extensions[i.tagName]),Object.assign(i,{inView:()=>t.utils.inView(i),posterior:()=>i.nextElementSibling,anterior:()=>i.previousElementSibling,parent:()=>this.extDom(i.parentElement),sibling:e=>i.parentElement.find(e),find:e=>{const t=i.querySelector(e);return t?this.extDom(t):null},findAll:e=>{const t=void 0===e?Array.from(i.children):i.querySelectorAll(e);return t.forEach(e=>{this.extDom(e)}),t}},e),void 0===i.index&&(i.index=()=>Array.from(i.parentNode.children).indexOf(i)),["INPUT","TEXTAREA","SELECT"].indexOf(i.tagName)>=0&&t.utils.hasAttrOrProp(i,"value")&&(i.oninput=function(){this.setAttribute("value",this.value)}),"FORM"===i.tagName&&(i.getData=function(e){const t={},s=new FormData(this),n=e||!1;for(let e of s.entries()){const s=i.find("[name='"+e[0]+"']");(n||"hidden"===s.type||s.show)&&(t[e[0]]="file"===s.type?s.files:e[1])}return t}),i}return i}doDom(e,s){if(t.utils.isObject(e)&&void 0===s&&(s=e,e=t.utils.newEmptyNode(),void 0===s.warn&&(s.warn=!1)),!(t.utils.isString(e)||t.utils.isElement(e)||t.utils.isNode(e)))return console.error("Selector is not a string or a Node:"),console.log(e),null;if(t.utils.isString(e)&&!document.querySelector(e))return console.log("Selected element doesn't exists: "+e),null;const i=this.extDom(e);if(void 0===s)return i;if(s=this.plainToObject(i,s),Object.keys(s).filter(e=>!["tagName"].includes(e)).forEach(e=>{let n=s[e];null==n&&(console.log("Value was not set for key: "+e+", 'empty' was used in object: "),console.log(s),console.log("In node:"),console.log(i),n="");let o=this.updateValue(i,e,n),l=t.utils.hasProp(i,e),r=!1;if(t.utils.hasAttr(i,e)||l)switch(!0){case"value"===e&&t.utils.hasProp(i,"valueAsDate")&&o instanceof Date:e="valueAsDate";case"css"===e:case typeof o==typeof i[e]:case t.utils.isString(i[e])&&t.utils.isNumeric(o):case t.utils.isFunction(o)&&t.utils.isObject(i[e]):case t.utils.isBool(o)&&t.utils.isString(i[e]):case"object"==typeof i[e]&&"INPUT"===i.tagName:r=!0}if(r){let s=!1;switch(e){case"classList":t.utils.isArray(o)?o.forEach(t=>{i[e].add(t)}):t.utils.isString(o)?i[e].add(o):s=!0;break;case"style":case"dataset":t.utils.isPlainObject(o)?Object.keys(o).forEach(t=>{i[e][t]=this.updateValue(i[e],t,o[t])}):s=!0;break;default:switch(!0){case t.utils.isBool(o):case t.utils.hasAttrOrProp(i,e):t.utils.setPropOrAttr(i,e,o);break;default:i[e]=o}}s&&(console.error("Invalid value passed to '"+e+"': "),console.log(o),console.log("Into Node:"),console.log(i))}else{const l=[];try{if("template"!==e&&!t.utils.isFunction(o)){if(e&&e.match(/^\w/)){let t=i.find("#"+e);t&&-1===l.indexOf(t)&&l.push(t),t=i.find("[name='"+e+"']"),t&&-1===l.indexOf(t)&&l.push(t);const s=Array.from(i.findAll("."+e)).filter(e=>l.indexOf(e)<0);s.length>0&&s.forEach(e=>l.push(e))}const t=Array.from(i.findAll(e)).filter(e=>l.indexOf(e)<0);t.length>0&&t.forEach(e=>l.push(e))}}catch(t){return console.error("Invalid selector: "+e),void console.log(t)}if(l.length>1){const t=[];l.forEach(s=>{t.push(this.render(s,e,o))}),this.linkNode(i,e,t),void 0!==o.warn&&!1===o.warn||(console.log("Multiple elements were assigned with key: ["+e+"] under node: "),console.log(i),console.log("It might be what we expect, but if it is not expected it could result on some elements mistakenly rendered. You can specify 'warn : false' under that element to hide this message."))}else if(1===l.length){const r=l[0];if(t.utils.isElement(r)){const l=this.plainToObject(r,o),a=t.utils.isPlainObject(l)&&Object.keys(l).length>=1?Object.keys(l)[0]:null;if(a&&(o=this.updateValue(r,a,n)),t.utils.isArray(o)){const t=s.template;this.doItems(r,o,t),this.linkNode(i,e,r)}else this.renderAndLink(i,r,e,o)}else console.error("BUG: It should have been a node but got: "),console.log(r),console.log("Parent node:"),console.log(i)}else if(0===l.length){"template"===e&&void 0===s.items&&(e="items",o=[]);const n=t.utils.isFunction(o);if(void 0!==o.tagName){const t=this.appendElement(i,o.tagName);this.renderAndLink(i,t,e,o)}else if(t.utils.isValidElement(e)&&!n){const t=this.appendElement(i,e);this.renderAndLink(i,t,e,o)}else if("items"===e){const e=s.template;if(t.utils.isPlainObject(o)){const e=[];Object.keys(o).forEach(s=>{let n;"DL"===i.tagName?n={dt:s,dd:o[s]}:(n={text:o[s]},t.utils.hasAttrOrProp(i,"value")?n.value=s:n.dataset={id:s}),e.push(n)}),o=e}t.utils.isArray(o)?this.doItems(i,o,e):(console.log("Warning: 'items' specified but value is not and array, in element: "),console.log(i),console.log("Passed values are: "),console.log(o))}else n?(t.updates&&"onupdate"===e&&i.addEventListener("update",o,!0),i[e]=o):"template"!==e&&"warn"!==e&&!1!==o&&(void 0!==s.warn&&!1===s.warn||(console.error("Not sure what you want to do with key: "+e+" under element: "),console.log(i),console.log("And object:"),console.log(s),console.log("Most likely the element's property or child no longer exists or the value passed to it is incorrect."),console.log("You can set 'warn : false' property to the element to dismiss this message.")),i[e]=o)}}}),i.onload){const e=["BODY","FRAME","IFRAME","IMG","LINK","SCRIPT","STYLE"].indexOf(i.tagName)>=0,t="INPUT"===i.tagName&&"image"===i.type;e||t||i.dispatchEvent(new CustomEvent("load"))}return i}isUpdateLink(e){let s=!1;if(t.utils.isArray(e)&&(2===e.length||3===e.length)){const i=2===e.length,n=t.utils.isNode(e[0])||e[0]instanceof DOMStringMap||e[0]instanceof CSSStyleDeclaration,o=i?t.utils.isString(e[1]):t.utils.isString(e[1])&&t.utils.isFunction(e[2]);s=n&&o,s&&i&&e.push(e=>e)}return s}plainToObject(e,s){if(!t.utils.isPlainObject(s)&&!t.utils.isFunction(s)&&!t.utils.isElement(s))if(t.utils.isHtml(s))s={html:s};else if(this.isUpdateLink(s)){const i=s[0],n=s[1],o=s[2];let l=this.plainToObject(e,o(i[n]));if(t.utils.isPlainObject(l)){const e={};Object.keys(l).forEach(t=>{e[t]=s}),s=e}}else t.utils.isArray(s)?s={items:s}:t.utils.hasAttrOrProp(e,"value")?s="SELECT"===e.tagName?{value:s,text:s}:"BUTTON"===e.tagName?{text:s}:{value:s}:t.utils.isString(s)&&"IMG"===e.tagName?s={src:s}:(t.utils.isString(s)||t.utils.isNumeric(s))&&(s={text:s});return s}renderAndLink(e,t,s,i){const n=this.render(t,s,i);this.linkNode(e,s,n)}render(e,t,s){return s=this.plainToObject(e,s),this.doDom(e,s)}linkNode(e,s,i){if(e[s]===i){const t=this.proxy(i);try{e[s]=t}catch(e){}e["$"+s]=t}else t.utils.hasAttrOrProp(e,s)?(e["$"+s]=i,console.log("Property : "+s+" existed in node: "+e.tagName+". Using $"+s+" instead for node: "+i.tagName+".")):e[s]=this.proxy(i)}appendElement(e,s){const i=t.utils.newElement(s);return e.append(i),i}getItem(e,t,s,i){i||(i=this.getTemplate(e));const n=i.cloneNode(!0);this.addTemplatesToItem(i,n),n.dataset.id=t,this.setUniqueAttrib(n,"selected");let o=this.doDom(n,s);return this.getItemWithEvents(e,o)}addTemplatesToItem(e,t){["_template","__template"].forEach(s=>{void 0!==e[s]&&(t[s]=e[s])})}getItemWithEvents(e,s){if(void 0!==e.__template){const i=(e,s)=>(s=s||{},Object.keys(e).forEach(n=>{t.utils.isPlainObject(e[n])?s[n]=i(e[n]):t.utils.isFunction(e[n])&&(s[n]=e[n])}),s);let n=i(e.__template);t.utils.isEmpty(n)||(n=n[Object.keys(n)[0]],s=this.doDom(s,n))}return s}doItems(e,t,s){const i=this.getTemplate(e,s);if(void 0===i)return console.error("Template not found. Probably an array is being used where it is not expected. Node:"),console.log(e),console.log("Value (mistaken?):"),void console.log(t);let n=0;t.forEach(t=>{t=this.plainToObject(e,t);const s=this.getItem(e,n++,t,i);s&&e.append(s)});const o=e.find("template");o&&e.removeChild(o),e.items=e.children,this.extendItems(e)}getTemplate(e,s){if(void 0!==e._template&&""!==e._template)return e._template;{let i;const n=e.querySelector("template");if(n)i=t.utils.htmlElement(n.innerHTML.trim());else switch(e.tagName){case"SELECT":case"DATALIST":i=t.utils.newElement("option");break;case"UL":case"OL":i=t.utils.newElement("li");break;case"NAV":i=t.utils.newElement("a");break;case"DL":i=t.utils.newElement("dd");break;default:if(s){const n=Object.keys(s).length;if(n){if(n>1)if(void 0!==s.tagName){let e={};e[s.tagName]=s,s=e}else console.log("Template has more than one top elements. Using the first one. In: "),console.log(s),console.log("Node: "),console.log(e);const o=Object.keys(s)[0],l=s[o];t.utils.isValidElement(o)?i=t.utils.newElement(o):void 0!==l.tagName?(i=t.utils.newElement(l.tagName),s[l.tagName]=l,delete s[o]):(console.error("Template defined an element which can not be identified: ["+o+"], using in:"),console.log(s),console.log("Node: "),console.log(e),i=t.utils.newElement("span"))}else console.error("Template has no definition, and it can not be guessed. Using . Template: "),console.log(s),console.log("Node: "),console.log(e),i=t.utils.newElement("span")}else e.childElementCount>0&&(i=t.utils.htmlElement(e.innerHTML.trim()))}if(s)if(t.utils.isPlainObject(s)){const n=t.utils.newEmptyNode();n.append(i),i=this.doDom(n,s).children[0],t.utils.defineProp(e,"__template",s)}else i=t.utils.isHtml(s)?t.utils.htmlElement(s):t.utils.isSelectorID(s)?t.utils.htmlElement(document.querySelector(s).innerHTML):t.utils.newElement(s);if(i.childrenElementCount>1){console.log("Templates only supports a single child. Multiple children were detected, wrapping them with . Template:"),console.log(i);const e=t.utils.newElement("span");e.append(i),i=e}return i&&t.utils.defineProp(e,"_template",i),i}}setUniqueAttrib(e,s){e.hasOwnProperty(s)||Object.defineProperty(e,s,{get:function(){return this.hasAttribute(s)},set:function(e){const i=this.parentNode?this.parentNode.find("["+s+"]"):null;i&&i.removeAttribute(s),t.utils.setAttr(this,s,e)}})}updateValue(e,s,i){if(this.isUpdateLink(i)){const n=this,o=i[0],l=i[1],r=i[2];if(i=o[l],o instanceof CSSStyleDeclaration&&this._stored.styles.includes(o)){const i=this._stored.styleNodes[this._stored.styles.indexOf(o)];t.updates&&(i.onupdate=function(t){t.detail&&"style"===t.detail.property&&t.detail.newValue.startsWith(l+":")&&n.setShortValue(e,s,r(this.style[l]))})}else if(o instanceof DOMStringMap&&this._stored.datasets.includes(o)){const i=this._stored.datasetNodes[this._stored.datasets.indexOf(o)];t.updates&&(i.onupdate=t=>{t.detail&&t.detail.property==="data-"+l&&n.setShortValue(e,s,r(t.detail.newValue))})}else t.updates&&(o.onupdate=i=>{i.detail&&i.detail.property===l&&(t.utils.isObject(e[s])||n.setShortValue(e,s,r(i.detail.newValue)))})}return i}setShortValue(e,s,i){if(t.utils.isNode(e[s]))if(t.short){const n=this.plainToObject(e[s],i),o=t.utils.isPlainObject(n)&&Object.keys(n).length>=1?Object.keys(n)[0]:null;o&&(e[s][o]=i)}else console.log("Short is disabled. Trying to set a value ("+i+") in a node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else e[s]=i}getShortValue(e,s,i){let n=null;if(t.utils.isNode(e[s]))if(t.short){const o=this.plainToObject(e[s],i||""),l=t.utils.isPlainObject(o)&&Object.keys(o).length>=1?Object.keys(o)[0]:null;l&&(n=e[s][l])}else console.log("Short is disabled. Trying to get a value from node:"),console.log(e[s]),console.log("Either turn on 'short' functionality, or be sure you specify the property, like: 'node.text'");else n=e[s];return n}proxy(e,s){return!t.short||null===e||void 0!==e._proxy&&void 0===s?e:(e._proxy=e,new Proxy(e,{get:(e,s)=>{const i=e[s];switch(!0){case null==i:return null;case t.utils.isFunction(i):return i.bind(e);case i._proxy&&void 0!==e["$"+s]:return e["$"+s];case void 0===i._proxy&&t.utils.isElement(i):return this.proxy(i);default:return i}},set:(e,s,i)=>{let n="";return t.utils.isElement(e[s])?(n=this.getShortValue(e,s,i),this.setShortValue(e,s,i)):"onupdate"===s?t.updates?t.utils.isFunction(i)?(e.addEventListener("update",i,!0),n=e[s],e[s]=i):(console.error("Value passed to 'onupdate' is incorrect, in node:"),console.log(e),console.log("Value: (not a function)"),console.log(i)):(console.log("Updates are not available when `m2d2.updates == false`:"),console.log(e)):"items"===s?(e.items.clear(),this.doItems(e,i)):(n=e[s],i=this.updateValue(e,s,i),e[s]=i),t.updates&&void 0!==e.onupdate&&i!==n&&e.dispatchEvent(new CustomEvent("update",{detail:{type:typeof i,property:s,newValue:i,oldValue:n}})),!0}}))}onObserve(e,s){e.forEach(e=>{const s=e.target;if(!(this._stored.events.indexOf(e)>=0)&&(this._stored.events.push(e),setTimeout(()=>{const t=this._stored.events.indexOf(e);t>=0&&this._stored.events.splice(t,1)},t.storedEventsTimeout),void 0!==s.onupdate))if("attributes"===e.type){const i=t.utils.getAttrOrProp(s,e.attributeName);i!==e.oldValue&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof i,property:e.attributeName,newValue:i,oldValue:e.oldValue}}))}else if("childList"===e.type)if("#text"===(e.addedNodes[0]||e.removedNodes[0]).nodeName){const t=e.addedNodes[0].textContent,i=e.removedNodes.length?e.removedNodes[0].textContent:null;t!==i&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"text",newValue:t,oldValue:i}}))}else if(void 0!==s.items){const t=e.addedNodes,i=e.removedNodes;t!==i&&s.dispatchEvent(new CustomEvent("update",{detail:{type:typeof t,property:"items",newValue:t,oldValue:i}}))}})}observe(e){if(t.updates){const t=new MutationObserver(this.onObserve.bind(this)),s={attributeOldValue:!0,subtree:!0,childList:!0},i=e._proxy||e;t.observe(i,s)}}getProxyNode(e,t){const s=this.doDom(e,t);if(s)return this.observe(s),this.proxy(s)}extendItems(e){function s(t){t.forEach(t=>{const s=t.parentNode.removeChild(t);e.append(s)})}const i=e.items;Object.getOwnPropertyNames(Array.prototype).concat(["clear","get","remove","selected","first","last","findAll"]).forEach(n=>{if(void 0===i[n]){let o=null;const l=this;switch(n){case"copyWithin":case"fill":case"splice":o=function(){console.log("Not available yet: "+n)};break;case"reverse":o=function(...e){if(this.items.length){const t=Array.from(this.items),i=t[n](...e);return s(t),i}};break;case"clear":o=function(){for(;this.items[0];)this.items[0].remove()};break;case"get":o=function(e){let s=null;return this.items.length&&this.items.some(i=>{const n=t.utils.isNumeric(e)?1*i.dataset.id==1*e:i.dataset.id===e;if(i.dataset&&n)return s=i,!0}),s};break;case"selected":o=function(){return l.proxy(this.find(":scope > [selected]"))};break;case"first":o=function(){return l.proxy(this.items[0])};break;case"last":o=function(){return l.proxy(this.items[this.items.length-1])};break;case"pop":o=function(){if(this.items.length){const e=this[0].parentNode;return l.proxy(e.removeChild(this.items[this.items.length-1]))}};break;case"push":o=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.append(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.appendChild(s)}else console.log("Trying to push an unknown value into a list:"),console.log(e)};break;case"remove":o=function(e){if(this.items.length){const t=this.items.get(e);1===t.length&&t.remove()}};break;case"shift":o=function(){if(this.items.length){const e=this.items[0].parentNode;return l.proxy(e.removeChild(this.items[0]))}};break;case"sort":o=function(e){if(this.items.length){const t=Array.from(this.items);t.sort(e||((e,t)=>e.text.localeCompare(t.text))),s(t)}};break;case"unshift":o=function(e){if(e=l.plainToObject(this,e),t.utils.isElement(e))this.prepend(e);else if(t.utils.isPlainObject(e)){const t=this.items.length,s=l.getItem(this,t,e);this.prepend(s)}else console.log("Trying to unshift an unknown value into a list:"),console.log(e)};break;default:let i=n;switch(!0){case"findAll"===n:i="filter";case t.utils.isFunction(Array.prototype[n]):const s=function(...t){const s=[];return Array.from(e.items).forEach(e=>{s.push(l.proxy(e))}),Array.from(s)[i](...t)};switch(n){case"find":o=function(...e){return t.utils.isString(e[0])?this.find(e[0]):s(...e)};break;case"findAll":o=function(...e){return 0===e.length?this.findAll():t.utils.isString(e[0])?this.findAll(e[0]):s(...e)};break;case"concat":o=function(...e){for(let s=0;s { + ["parent","sibling","posterior","anterior","find","findAll","onupdate","onready","show","onshow","inView","css","text","html","getData","index"].forEach(f => { if($node.hasOwnProperty(f)) { console.log("Node already had ["+f+"] property. It might cause unexpected behaviour.") console.log("You may need to update the M2D2 version or report it to: github.com/intellisrc/m2d2/") @@ -624,10 +621,9 @@ class m2d2 { inView: () => { //TODO: document return m2d2.utils.inView($node); }, - next: () => { //TEST: 07 - return $node.nextElementSibling; - }, - prev: () => { //TEST: 07 + posterior: () => { //TEST: 07 + return $node.nextElementSibling; }, + anterior: () => { //TEST: 07 return $node.previousElementSibling; }, parent: () => { //TODO: test @@ -646,10 +642,10 @@ class m2d2 { return nodeList; }, }, extend); - // Some elements like