text: (()=>{const components={};const Datastore=function(){const callbacks=[];let that;let user;this.init=(async()=>{that=this;await prepareDB();await prepareRealtime();delete that.init;async function prepareDB(){if(!that.name||that.url)return;await openDB();await createStore();function openDB(){return new Promise(resolve=>db?resolve():indexedDB.open("ccm").onsuccess=function(){db=this.result;resolve()})}function createStore(){return new Promise(resolve=>{if(db.objectStoreNames.contains(that.name))return resolve();let version=parseInt(localStorage.getItem("ccm"));if(!version)version=1;db.close();const request=indexedDB.open("ccm",version+1);request.onupgradeneeded=function(){db=this.result;localStorage.setItem("ccm",db.version);db.createObjectStore(that.name,{keyPath:"key"})};request.onsuccess=resolve})}}function prepareRealtime(){return new Promise(resolve=>{if(!that.url||that.url.indexOf("ws")!==0)return resolve();if(!that.onchange&&that.parent)that.onchange=that.parent.start;let message=[that.db,that.name];if(that.dataset){if(!Array.isArray(that.dataset))that.dataset=[that.dataset];message=message.concat(that.dataset)}that.socket=new WebSocket(that.url,"ccm-cloud");that.socket.onmessage=(message=>{const{callback:callback,data:data}=self.helper.parse(message.data);if(callback){callbacks[callback](data);delete callbacks[callback]}else that.onchange&&that.onchange(data)});that.socket.onopen=(()=>{that.socket.send(message);resolve()})})}});this.clear=(()=>that.local={});this.source=(()=>{return{name:that.name,url:that.url,db:that.db}});this.get=((key_or_query={})=>new Promise((resolve,reject)=>{key_or_query=self.helper.clone(key_or_query);if(!self.helper.isObject(key_or_query)&&!self.helper.isKey(key_or_query))reject(new Error("invalid dataset key: "+key_or_query));that.url?serverDB():that.name?clientDB():localCache();function localCache(){resolve(self.helper.clone(self.helper.isObject(key_or_query)?runQuery(key_or_query):that.local[key_or_query]));function runQuery(query){const results=[];for(const key in that.local)self.helper.isSubset(query,that.local[key])&&results.push(that.local[key]);return results}}function clientDB(){const store=getStore();const request=self.helper.isObject(key_or_query)?store.getAll():store.get(key_or_query);request.onsuccess=(event=>resolve(event.target.result||null));request.onerror=(event=>reject(event.target.errorCode))}function serverDB(){(that.socket?useWebsocket:useHttp)(prepareParams({get:key_or_query})).then(resolve).catch(error=>checkError(error,reject))}}));this.set=(priodata=>new Promise((resolve,reject)=>{priodata=self.helper.toJSON(priodata);if(!priodata.key)priodata.key=self.helper.generateKey();if(!self.helper.isKey(priodata.key))reject(new Error("invalid dataset key: "+priodata.key));that.url?serverDB():that.name?clientDB():localCache();async function localCache(){if(that.local[priodata.key])that.local[priodata.key]=await self.helper.integrate(priodata,that.local[priodata.key]);else that.local[priodata.key]=priodata;resolve(priodata.key)}function clientDB(){const request=getStore().put(priodata);request.onsuccess=(event=>event.target.result.toString()===priodata.key.toString()?resolve(event.target.result):reject(event.target.result));request.onerror=(event=>reject(event.target.errorCode))}function serverDB(){(that.socket?useWebsocket:useHttp)(prepareParams({set:priodata})).then(response=>(response.toString()===priodata.key.toString()?resolve:reject)(response)).catch(error=>checkError(error,reject))}}));this.del=(key=>new Promise((resolve,reject)=>{if(!self.helper.isKey(key))reject(new Error("invalid dataset key: "+key));that.url?serverDB():that.name?clientDB():localCache();function localCache(){delete that.local[key];resolve(true)}function clientDB(){const request=getStore().delete(key);request.onsuccess=(event=>event.target.result===undefined?resolve(true):reject(event.target.result));request.onerror=(event=>reject(event.target.errorCode))}function serverDB(){(that.socket?useWebsocket:useHttp)(prepareParams({del:key})).then(response=>(response===true?resolve:reject)(response)).catch(error=>checkError(error,reject))}}));this.count=(query=>new Promise((resolve,reject)=>{that.url?serverDB():that.name?clientDB():localCache();function localCache(){resolve(query?that.get(query).then(datasets=>datasets.length):Object.keys(that.local).length)}function clientDB(){const request=getStore().count();request.onsuccess=(event=>(!isNaN(event.target.result)?resolve:reject)(event.target.result));request.onerror=(event=>reject(event.target.errorCode))}function serverDB(){(that.socket?useWebsocket:useHttp)(prepareParams(query?{count:query}:{})).then(response=>!isNaN(response)?resolve(parseInt(response)):reject(response)).catch(error=>checkError(error,reject))}}));function getStore(){return db.transaction([that.name],"readwrite").objectStore(that.name)}function prepareParams(params={}){if(that.db)params.db=that.db;params.store=that.name;user=self.context.find(that,"user");if(user&&user.isLoggedIn()){params.realm=user.getRealm();params.token=user.data().token}return params}async function checkError(error,reject){if(error&&(error===401||error.data&&error.data.status===401)&&user){try{await user.logout();await user.login();await self.context.root(user).start()}catch(e){await self.context.root(user).start()}}else reject(error)}function useWebsocket(params){return new Promise(resolve=>{const key=self.helper.generateKey();callbacks[key]=(result=>Number.isInteger(result)?checkError(result,reject):resolve(result));params.callback=key;that.socket.send(self.helper.stringify(params))})}function useHttp(params){return self.load({url:that.url,params:params,method:that.method})}};let db;if(!window.ccm)ccm={callbacks:{},files:{}};const self={version:()=>"25.1.0",components:{},load:function(){const args=[...arguments];const call=args.slice(0);call.unshift(self.load);let results=[];let counter=1;let failed=false;return new Promise((resolve,reject)=>{args.forEach((resource,i)=>{counter++;resource=self.helper.clone(resource);if(Array.isArray(resource)){results[i]=[];serial(null);return}if(!self.helper.isObject(resource))resource={url:resource};const suffix=resource.url.split(".").pop().split("?").shift().split("#").shift().toLowerCase();if(resource.method)resource.method=resource.method.toLowerCase();if(!resource.context||resource.context==="head")resource.context=document.head;if(self.helper.isInstance(resource.context))resource.context=resource.context.element.parentNode;const operation=getOperation();let timeout;self.load.timeout&&window.setTimeout(()=>timeout===undefined&&(timeout=true)&&error("timeout"),self.load.timeout);operation();function serial(result){if(result!==null)results[i].push(result);if(resource.length===0)return check();let next=resource.shift();if(!Array.isArray(next))next=[next];self.load.apply(null,next).then(serial).catch(serial)}function getOperation(){switch(resource.type){case"html":return loadHTML;case"image":return loadImage;case"css":return loadCSS;case"js":return loadJS;case"module":return loadModule;case"xml":return loadXML;case"data":return loadData}switch(suffix){case"html":return loadHTML;case"jpg":case"jpeg":case"gif":case"png":case"svg":case"bmp":return loadImage;case"css":return loadCSS;case"js":return loadJS;case"mjs":return loadModule;case"xml":return loadXML;default:return loadData}}function loadHTML(){resource.type="html";resource.method="get";loadData()}function loadImage(){const image=new Image;image.onload=success;image.onerror=(event=>error(image,event));image.src=resource.url}function loadCSS(){if(resource.context.querySelector('link[rel="stylesheet"][type="text/css"][href="'+resource.url+'"]'))return success();let element={tag:"link",rel:"stylesheet",type:"text/css",href:resource.url};if(resource.attr)element=Object.assign(element,resource.attr);element=self.helper.html(element);element.onload=success;element.onerror=(event=>{element.parentNode.removeChild(element);error(element,event)});resource.context.appendChild(element)}function loadJS(){const filename=resource.url.split("/").pop().split("?").shift().replace(".min.",".");ccm.files[filename]=null;ccm.files["#"+filename]=ccm.files["#"+filename]?ccm.files["#"+filename]+1:1;let element={tag:"script",src:resource.url};if(resource.attr)element=Object.assign(element,resource.attr);element=self.helper.html(element);element.onload=(()=>{const data=ccm.files[filename];if(!--ccm.files["#"+filename]){delete ccm.files[filename];delete ccm.files["#"+filename]}element.parentNode.removeChild(element);data!==null?successData(data):success()});element.onerror=(event=>{element.parentNode.removeChild(element);error(element,event)});resource.context.appendChild(element)}function loadModule(){const callback="callback"+self.helper.generateKey();ccm.callbacks[callback]=function(result){element.parentNode.removeChild(element);delete ccm.callbacks[callback];successData(result)};const element=self.helper.html({tag:"script",type:"module"});element.onerror=(event=>{element.parentNode.removeChild(element);error(element,event)});const split=resource.url.split("#");if(!resource.import&&split.length>1)resource.import=split[1];element.text="import * as alias from '"+split[0]+"'; ccm.callbacks['"+callback+"']( alias"+(resource.import?"."+resource.import:"")+" )";document.head.appendChild(element)}function loadXML(){if(!resource.method)resource.method="post";const request=new XMLHttpRequest;request.onreadystatechange=(()=>{if(request.readyState===4)request.status===200?successData(request.responseXML):error(request)});request.open(resource.method,resource.url,true);request.send()}function loadData(){switch(resource.method){case"jsonp":jsonp();break;case"get":case"post":case"put":case"delete":ajax();break;case"fetch":fetchAPI();break;default:resource.method="post";ajax()}function jsonp(){const callback="callback"+self.helper.generateKey();if(!resource.params)resource.params={};resource.params.callback="ccm.callbacks."+callback;ccm.callbacks[callback]=(data=>{element.parentNode.removeChild(element);delete ccm.callbacks[callback];successData(data)});let element={tag:"script",src:buildURL(resource.url,resource.params)};if(resource.attr)element=Object.assign(element,resource.attr);element=self.helper.html(element);element.onerror=(event=>{element.parentNode.removeChild(element);error(element,event)});element.src=element.src.replace(/&amp;/g,"&");resource.context.appendChild(element)}function ajax(){const request=new XMLHttpRequest;request.open(resource.method,resource.method==="get"&&resource.params?buildURL(resource.url,resource.params):resource.url,true);if(resource.headers)for(const key in resource.headers){request.setRequestHeader(key,resource.headers[key]);if(key.toLowerCase()==="authorization")request.withCredentials=true}(resource.method==="post"||resource.method==="put")&&request.setRequestHeader("Content-Type","application/json");request.onreadystatechange=(()=>{if(request.readyState===4)request.status>=200&&request.status<300?successData(request.responseText):error(request)});request.send(resource.method==="post"||resource.method==="put"?self.helper.stringify(resource.params):undefined)}function fetchAPI(){if(!resource.init)resource.init={};if(resource.params)resource.init.method.toLowerCase()==="post"?resource.init.body=self.helper.stringify(resource.params):resource.url=buildURL(resource.url,resource.params);fetch(resource.url,resource.init).then(response=>response.text()).then(successData).catch(error)}function buildURL(url,data){if(self.helper.isObject(data.json))data.json=self.helper.stringify(data.json);return data?url+"?"+params(data).slice(0,-1):url;function params(obj,prefix){let result="";for(const i in obj){const key=prefix?prefix+"["+encodeURIComponent(i)+"]":encodeURIComponent(i);if(typeof obj[i]==="object")result+=params(obj[i],key);else result+=key+"="+encodeURIComponent(obj[i])+"&"}return result}}}function successData(data){if(checkTimeout())return;if(typeof data==="string"&&self.helper.regex("json").test(data))try{data=self.helper.parse(data)}catch(e){}if(resource.type==="html")data=self.helper.html2json(data);results[i]=data;success()}function success(){if(checkTimeout())return;if(results[i]===undefined)results[i]=resource.url;check()}function checkTimeout(){return timeout?self.helper.log("loading of "+resource.url+" succeeded after timeout ("+self.load.timeout+"ms)")||true:timeout=false}function error(){failed=true;results[i]={error:new Error("loading of "+resource.url+" failed"),resource:resource,data:[...arguments],call:call};if(results[i].data.length<=1)results[i].data=results[i].data[0];check()}});check();function check(){if(--counter)return;if(results.length===1)results=results[0];(failed?reject:resolve)(results)}})},component:async(component,config)=>{component=await getComponentObject();if(!self.helper.isComponent(component))throw new Error("invalid component object");await changeFrameworkVersion(component,config);const version=(self.helper.isFramework(component.ccm)?component.ccm:await self.helper.loadFramework(component.ccm)).version();if(version!==self.version())return new Promise(async resolve=>{const result=await ccm[version].component(component,config,resolve);result&&resolve(result)});component.index=component.name+(component.version?"-"+component.version.join("-"):"");if(!components[component.index]){components[component.index]=component;self.components[component.index]={};component.instances=0;component.ccm=ccm[version];component.ready&&await component.ready.call(component);delete component.ready;await defineCustomElement(component.index)}else component=components[component.index];component=self.helper.clone(component);component.config=await prepareConfig(config,component.config);component.instance=(async config=>await self.instance(component,await prepareConfig(config,component.config)));component.start=(async config=>await self.start(component,await prepareConfig(config,component.config)));return component;async function getComponentObject(){if(typeof component==="string"){const index=component.endsWith(".js")?self.helper.convertComponentURL(component).index:component;if(components[index])return self.helper.clone(components[index]);if(self.helper.regex("filename").test(component.split("/").pop())){const response=await self.load(component);response.url=component;return response}return new Error("invalid component index or URL: "+component)}return component}},instance:async(component,config)=>{component=await self.component(component,{ccm:config&&config.ccm});config&&delete config.ccm;config=await prepareConfig(config,component.config);config.beforeCreation&&await config.beforeCreation(config,self.helper.clone(component));delete config.beforeCreation;if(!self.helper.isComponent(component))return component;if(component.ccm.version()!==self.version())return new Promise(async resolve=>{const result=await ccm[component.ccm.version()].instance(component,config,resolve);result&&resolve(result)});let instance=createInstance();config.afterCreation&&await config.afterCreation(config,self.helper.clone(component));delete config.afterCreation;instance.config=self.helper.stringify(config);if(!document.contains(instance.root)){instance.root.position=document.createElement("div");if(instance.root.parentNode)instance.root.parentNode.replaceChild(instance.root.position,instance.root);document.head.appendChild(instance.root)}config=await self.helper.solveDependencies(config,instance);if(document.head.contains(instance.root)){document.head.removeChild(instance.root);if(instance.root.position.parentNode)instance.root.position.parentNode.replaceChild(instance.root,instance.root.position);delete instance.root.placeholder}config.inner=self.helper.html(config.inner,undefined,{no_evaluation:true});Object.assign(instance,config);if(!instance.parent||!instance.parent.init)await initialize();instance.onReady&&await instance.onReady(instance);delete instance.onReady;return instance;function createInstance(){const instance=new component.Instance;instance.ccm=component.ccm;instance.component=component;instance.parent=config.parent;delete config.parent;instance.root=config.root;delete config.root;instance.id=++components[component.index].instances;instance.index=component.index+"-"+instance.id;setElement();if(!instance.init)instance.init=(async()=>{});if(instance.root.id===instance.index&&instance.root.parentNode&&instance.root.parentNode.tagName.indexOf("CCM-")===0)watchAttributes();return instance;function setElement(){if(instance.root==="parent"&&instance.parent){instance.root=instance.parent.root;instance.element=instance.parent.element;return}if(typeof instance.root==="string")instance.root=instance.parent.element.querySelector("#"+(instance.root==="name"&&instance.parent?component.name:instance.root));const root=self.helper.html({id:instance.index});if(instance.root){instance.root.innerHTML="";instance.root.appendChild(root);instance.root=root}if(!config.shadow)config.shadow="closed";if(typeof config.shadow==="string"&&config.shadow!=="none"){instance.shadow=root.shadowRoot||root.attachShadow({mode:config.shadow});delete config.shadow}(instance.shadow||root).appendChild(instance.element=self.helper.html({id:"element"}));if(!instance.root)instance.root=root}function watchAttributes(){if(!instance.update)instance.update=((key,value)=>{switch(key){case"ccm":case"component":case"config":case"element":case"id":case"index":case"init":case"onfinish":case"parent":case"ready":case"root":case"start":case"update":break;case"key":if(self.helper.regex("json").test(value))value=self.helper.parse(value);if(self.helper.isObject(value))for(const key in value)if(value.hasOwnProperty(key))switch(key){case"ccm":case"component":case"dependency":case"parent":case"id":case"index":case"element":case"root":case"init":case"ready":case"start":case"update":case"key":break;default:instance[key]=value[key]}instance.start();break;default:instance[key]=value;instance.start()}});const MutationObserver=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;const observer=new MutationObserver(mutations=>mutations.forEach(mutation=>{if(mutation.type!=="attributes")return;const key=mutation.attributeName;const value=instance.root.parentNode.getAttribute(key);instance.update(key,value)}));observer.observe(instance.root.parentNode,{attributes:true})}}function initialize(){return new Promise(resolve=>{const instances=[instance];find(instance);let i=0;init();function find(obj){const relevant=[];for(const key in obj)if(obj.hasOwnProperty&&obj.hasOwnProperty(key)){const value=obj[key];if(self.helper.isInstance(value)&&key!=="parent"&&!self.helper.isProxy(value)){instances.push(value);relevant.push(value)}else if(Array.isArray(value)||self.helper.isObject(value)){if(self.helper.isSpecialObject(value))continue;relevant.push(value)}}relevant.map(find)}function init(){if(i===instances.length)return ready();const next=instances[i++];next.init?next.init().then(()=>{delete next.init;init()}):init()}function ready(){if(!instances.length)return resolve();const next=instances.pop();next.ready?next.ready().then(()=>{delete next.ready;ready()}):ready();if(next._start){delete next._start;next.start()}}})}},proxy:async(component,config)=>{const obj={ccm:true,component:{Instance:true}};obj.start=(async cfg=>await Object.assign(obj,await self.instance(component,await self.helper.integrate(cfg,config))).start());return obj},start:async(component,config)=>{const instance=await self.instance(component,config);if(!self.helper.isInstance(instance))return instance;instance.init?instance._start=true:await instance.start();return instance},store:(config={})=>new Promise((resolve,reject)=>{config=self.helper.clone(config);if(typeof config==="string")config=config.split("?").shift().endsWith(".js")?{local:["ccm.load",config]}:{name:config};if(!self.helper.isObject(config)||!config.local&&!config.name){config={local:config,parent:config.parent};delete config.local.parent}if(!config.local&&!config.name)config.local={};self.helper.solveDependency(config.local).then(result=>{config.local=result;if(Array.isArray(config.local))config.local=self.helper.arrToStore(config.local);let store=new Datastore;Object.assign(store,config);store.init().then(()=>resolve(store))}).catch(reject)}),get:(settings,key_or_query)=>self.store(settings).then(store=>{let property;if(typeof key_or_query==="string"){property=key_or_query.split(".");key_or_query=property.shift();property=property.join(".")}return store.get(key_or_query).then(result=>property?self.helper.deepValue(result,property):result)}),set:(settings,priodata)=>self.store(settings).then(store=>store.set(priodata)),del:(settings,key)=>self.store(settings).then(store=>store.del(key)),context:{find:(instance,property,not_me)=>{const start=instance;if(not_me)instance=instance.parent;do{if(self.helper.isObject(instance)&&instance[property]!==undefined&&instance[property]!==start)return instance[property]}while(instance=instance.parent)},highestByProperty:(instance,property,not_me)=>{const start=instance;let result=null;if(not_me)instance=instance.parent;do{if(self.helper.isObject(instance)&&instance[property]!==undefined&&instance[property]!==start)result=instance}while(instance=instance.parent);return result},nearestByProperty:(instance,property,not_me)=>{const start=instance;if(not_me)instance=instance.parent;do{if(self.helper.isObject(instance)&&instance[property]!==undefined&&instance[property]!==start)return instance}while(instance=instance.parent);return null},root:function(instance){while(instance.parent)instance=instance.parent;return instance}},helper:{arrToStore:arr=>{if(!Array.isArray(arr))return;const obj={};arr.forEach(value=>{if(self.helper.isDataset(value))obj[value.key]=value});return obj},clone:function(value){return recursive(value,true);function recursive(value,first){if(self.helper.isSpecialObject(value)&&!first)return value;if(Array.isArray(value)||self.helper.isObject(value)){var copy=Array.isArray(value)?[]:{};for(var i in value)copy[i]=recursive(value[i]);return copy}return value}},compareVersions:(a,b)=>{if(a===b)return 0;const a_arr=a.split(".");const b_arr=b.split(".");for(let i=0;i<3;i++){const x=parseInt(a_arr[i]);const y=parseInt(b_arr[i]);if(x<y)return-1;else if(x>y)return 1}return 0},convertComponentURL:url=>{const filename=url.split("/").pop();if(!self.helper.regex("filename").test(filename))throw new Error("invalid component filename: "+filename);const data={url:url};let tmp=filename.substring(4,filename.length-3);if(tmp.endsWith(".min")){data.minified=true;tmp=tmp.substr(0,tmp.length-4)}tmp=tmp.split("-");data.name=tmp.shift();if(tmp.length)data.version=tmp[0];data.index=data.name+(data.version?"-"+data.version.replace(/\./g,"-"):"");return data},deepValue:function(obj,key,value){return recursive(obj,key.split("."),value);function recursive(obj,key,value){if(!obj)return;var next=key.shift();if(key.length===0)return value!==undefined?obj[next]=value:obj[next];if(!obj[next]&&value!==undefined)obj[next]=isNaN(key[0])?{}:[];return recursive(obj[next],key,value)}},format:function(data,values){const temp=[[],[],{}];const obj_mode=self.helper.isObject(data);values=self.helper.clone([...arguments]);values.shift();data=self.helper.stringify(data,(key,val)=>{if(typeof val==="function"){temp[0].push(val);return"%$0%"}return val});for(let i=0;i<values.length;i++){if(typeof values[i]==="object"){for(const key in values[i])if(values[i].hasOwnProperty(key)){if(typeof values[i][key]!=="string"&&obj_mode){temp[2][key]=values[i][key];values[i][key]=`%$2%${key}%`}if(typeof values[i][key]!=="string")continue;data=data.replace(new RegExp(`%${key}%`,"g"),values[i][key].replace(/"/g,'\\"'))}}else{if(typeof values[i]!=="string"&&obj_mode){temp[1].push(values[i]);values[i]="%$1%"}data=data.replace(/%%/,values[i].replace(/"/g,'\\"'))}}return self.helper.parse(data,(key,val)=>{if(val==="%$0%")return temp[0].shift();if(val==="%$1%")return temp[1].shift();if(typeof val==="string"){if(val.indexOf("%$2%")===0&&val.split("%")[3]==="")return temp[2][val.split("%")[2]];else for(const key in temp[2])val=val.replace(new RegExp(`%\\$2%${key}%`,"g"),temp[2][key])}return val})},generateConfig:element=>{element=self.helper.html(element,undefined,{no_evaluation:true});if(self.helper.regex("json").test(element.innerHTML)){element.setAttribute("inner",element.innerHTML);element.innerHTML=""}const config={};catchAttributes(element,config);catchInnerTags(element);return config;function catchAttributes(element,obj){if(!element.attributes)return;[...element.attributes].forEach(attr=>{if(attr.name!=="src"||element.tagName.indexOf("CCM-COMPONENT")!==0&&element.tagName.indexOf("CCM-INSTANCE")!==0&&element.tagName.indexOf("CCM-PROXY")!==0)try{obj[attr.name]=attr.value.charAt(0)==="{"||attr.value.charAt(0)==="["?self.helper.parse(attr.value):prepareValue(attr.value)}catch(err){}})}function catchInnerTags(element){if(!element.childNodes)return;config.childNodes=[];[...element.childNodes].forEach(child=>{if(child.tagName&&child.tagName.indexOf("CCM-")===0){const split=child.tagName.toLowerCase().split("-");if(split.length<3)split[2]=split[1];switch(split[1]){case"load":self.helper.deepValue(config,split[2],interpretLoadTag(child,split[2]));break;case"component":case"instance":case"proxy":self.helper.deepValue(config,split[2],["ccm."+split[1],child.getAttribute("src")||split[2],self.helper.generateConfig(child)]);break;case"store":case"get":const settings={};catchAttributes(child,settings);const key=settings.key;delete settings.key;self.helper.deepValue(config,split[2],["ccm."+split[1],settings,key]);break;case"list":let list=null;[...child.children].forEach(entry=>{if(entry.tagName&&entry.tagName.indexOf("CCM-ENTRY")===0){const value=prepareValue(entry.getAttribute("value"));const split=entry.tagName.toLowerCase().split("-");if(!list)list=split.length<3?[]:{};if(split.length<3)list.push(value);else self.helper.deepValue(list,split[2],value)}});if(!list)list={};catchAttributes(child,list);if(list)self.helper.deepValue(config,split[2],list);break;default:config.childNodes.push(child);element.removeChild(child)}}else{config.childNodes.push(child);element.removeChild(child)}});if(config.inner)return;config.inner=self.helper.html({});config.childNodes.forEach(child=>config.inner.appendChild(child));delete config.childNodes;if(!config.inner.hasChildNodes())delete config.inner;function interpretLoadTag(node){let params=generateParameters(node);if(!Array.isArray(params))params=[params];params.unshift("ccm.load");if(node.hasAttribute("head"))params.push(true);return params;function generateParameters(node){if(node.hasAttribute("src")){if(node.children.length===0)return node.getAttribute("src");const data={};[...node.children].forEach(child=>{if(child.tagName&&child.tagName.indexOf("CCM-DATA-")===0)data[child.tagName.toLowerCase().split("-")[2]]=child.getAttribute("value")});return[node.getAttribute("src"),data]}const params=[];[...node.children].forEach(child=>{if(child.tagName==="CCM-SERIAL"&&(node.tagName==="CCM-PARALLEL"||node.tagName.indexOf("CCM-LOAD")===0)||child.tagName==="CCM-PARALLEL"&&node.tagName==="CCM-SERIAL")params.push(generateParameters(child))});return params}}}function prepareValue(value){if(value==="true")return true;if(value==="false")return false;if(value==="null")return null;if(value==="undefined")return undefined;if(value==="")return true;if(!isNaN(value))return parseInt(value);return value}},generateKey:function(){return Date.now()+"X"+Math.random().toString().substr(2)},html2json:html=>{const json={inner:[]};if(typeof html==="string"){const template=document.createElement("template");template.innerHTML=html;html=template.content}if(window.jQuery&&html instanceof jQuery){html=html.get();const fragment=document.createDocumentFragment();html.forEach(elem=>fragment.appendChild(elem));html=fragment}if(html instanceof DocumentFragment){if(!html.children.length)return html.textContent;[...html.childNodes].forEach(child=>{if(child.nodeValue){child.nodeValue=child.nodeValue.trim();if(!child.nodeValue||child.nodeType===Node.COMMENT_NODE)child.parentNode.removeChild(child)}});if(html.firstChild.tagName==="CCM-TEMPLATE"){const result=html.firstChild.getAttribute("key")?{}:[];[...html.childNodes].forEach((child,i)=>{if(child.tagName!=="CCM-TEMPLATE")return;const key=child.getAttribute("key");result[key||i]=child=self.helper.html2json(child);delete child.key;delete child.tag;if(!Array.isArray(child.inner))result[key||i]=child.inner});return result}if(html.childNodes.length===1)html=html.firstChild}if(!self.helper.isElement(html))return html;if(html.tagName)json.tag=html.tagName.toLowerCase();if(json.tag==="div")delete json.tag;html.attributes&&[...html.attributes].forEach(attr=>json[attr.name]=attr.value===""&&attr.name!=="value"?true:attr.value);[...html.childNodes].forEach(child=>{if(child.nodeType===Node.COMMENT_NODE)return child.parentNode.removeChild(child);if(child.nodeValue)child.nodeValue=child.nodeValue.replace(/\s+/g," ");if(self.helper.isElement(child)||child.nodeValue.trim())json.inner.push(self.helper.isElement(child)?self.helper.html2json(child):child.textContent)});if(!json.inner.length)delete json.inner;else if(json.inner.length===1)json.inner=json.inner[0];return json},html:function(html,values,settings){if(!html)return html;if(self.helper.isElement(html)&&values===undefined)return html;let advanced={};if(self.helper.isObject(settings)){advanced=settings;settings=undefined}html=self.helper.html2json(html);html=self.helper.clone(html);if(values!==undefined)html=self.helper.format.apply(this,arguments);if(Array.isArray(html)){const result=[];for(let i=0;i<html.length;i++)result.push(self.helper.html(html[i],undefined,advanced));return result}if(typeof html!=="object"||html===null)html={tag:"span",inner:html};if(html.tag==="svg")advanced.namespace_uri="http://www.w3.org/2000/svg";const element=advanced.namespace_uri?document.createElementNS(advanced.namespace_uri,html.tag||"div"):document.createElement(html.tag||"div");delete html.tag;if(!self.helper.regex("json").test(html.key))delete html.key;for(const key in html){const value=html[key];switch(key){case"async":case"autofocus":case"checked":case"defer":case"disabled":case"ismap":case"multiple":case"required":case"selected":if(value)element[key]=true;break;case"readonly":if(value)element.readOnly=true;break;case"inner":if(typeof value==="string"||typeof value==="number"){element.innerHTML=value;break}let children=Array.isArray(value)?value:[value];children.forEach(child=>element.appendChild(this.html(child,undefined,advanced)));break;default:if(key.indexOf("on")===0&&typeof value==="function")element.addEventListener(key.substr(2),value);else element.setAttribute(key,value)}}if(element.tagName.startsWith("CCM-")&&!advanced.no_evaluation){const config=self.helper.generateConfig(element);config.root=element;self.start(element.tagName==="CCM-APP"?element.getAttribute("component"):element.tagName.substr(4).toLowerCase(),config)}return element},integrate:async(priodata,dataset,as_defaults)=>{dataset=self.helper.clone(dataset);if(!self.helper.isObject(priodata))return dataset;if(!self.helper.isObject(dataset))return self.helper.clone(priodata);for(let key in priodata){const split=key.split(".");let obj=dataset;for(let i=0;i<split.length;i++){const prop=split[i];if(self.helper.isDependency(obj[prop])&&obj[prop][0]==="ccm.get")obj[prop]=await self.helper.solveDependency(obj[prop]);obj=obj[prop];if(!obj)break}if(!as_defaults||self.helper.deepValue(dataset,key)===undefined)self.helper.deepValue(dataset,key,priodata[key])}return dataset},isComponent:function(value){return self.helper.isObject(value)&&value.Instance&&true},isDataset:value=>self.helper.isObject(value)&&self.helper.isKey(value.key),isDatastore:value=>self.helper.isObject(value)&&value.get&&value.set&&value.del&&value.source&&value.clear&&true,isDependency:function(value){if(Array.isArray(value))if(value.length>0)switch(value[0]){case"ccm.load":case"ccm.component":case"ccm.instance":case"ccm.proxy":case"ccm.start":case"ccm.store":case"ccm.get":case"ccm.set":case"ccm.del":return true}return false},isElement:function(value){return value instanceof Element||value instanceof DocumentFragment},isFramework:value=>self.helper.isObject(value)&&value.components&&value.version&&true,isInstance:value=>self.helper.isObject(value)&&self.helper.isComponent(value.component)&&value.ccm&&true,isKey:value=>{if(typeof value==="string")return self.helper.regex("key").test(value);if(Array.isArray(value)){for(let i=0;i<value.length;i++)if(!self.helper.regex("key").test(value[i]))return false;return true}return false},isNode:function(value){return value instanceof Node},isObject:function(value){return typeof value==="object"&&value!==null&&!Array.isArray(value)},isProxy:function(value){return self.helper.isInstance(value)&&value.component===true},isSpecialObject:value=>{return!!(value===window||self.helper.isNode(value)||self.helper.isFramework(value)||self.helper.isInstance(value)||self.helper.isComponent(value)||self.helper.isDatastore(value)||window.jQuery&&value instanceof jQuery)},isSubset:function(obj,other){other=self.helper.toDotNotation(other,true);for(const key in obj)if(typeof obj[key]==="object"&&typeof other[key]==="object"){if(JSON.stringify(obj[key])!==JSON.stringify(other[key]))return false}else if(obj[key]!==other[key])return false;return true},loadFramework:async url=>{let resource={};if(self.helper.isObject(url)){url=self.helper.clone(url);resource.url=url.url;delete url.url;resource.attr=url}else resource={url:url};const version=(resource.url.match(/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/)||["latest"])[0];!ccm[version]&&await self.load(resource);return ccm[version]},log:message=>console.log("[ccm]",message),parse:(string,reviver)=>JSON.parse(string.replace(/\\n/g,"\\n").replace(/\\'/g,"\\'").replace(/\\"/g,'\\"').replace(/\\&/g,"\\&").replace(/\\r/g,"\\r").replace(/\\t/g,"\\t").replace(/\\b/g,"\\b").replace(/\\f/g,"\\f").replace(/[\u0000-\u0019]+/g,""),reviver),regex:function(index){switch(index){case"filename":return/^ccm\.([a-z][a-z0-9_]*)(-(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*))?(\.min)?(\.js)$/;case"key":return/^[a-zA-Z0-9_-]+$/;case"json":return/^(({(.|\n)*})|(\[(.|\n)*])|true|false|null)$/}},solveDependencies:(obj,instance)=>new Promise((resolve,reject)=>{obj=self.helper.clone(obj);if(!self.helper.isObject(obj)&&!Array.isArray(obj))return resolve(obj);let failed=false;let counter=1;search(obj);check();function search(obj){if(self.helper.isSpecialObject(obj))return;for(const key in obj)if(obj.hasOwnProperty(key))if(key!=="ignore"){const value=obj[key];if(self.helper.isDependency(value)){counter++;self.helper.solveDependency(obj[key],instance).then(result=>{obj[key]=result;check()}).catch(result=>{failed=true;obj[key]=result;check()})}else if(self.helper.isObject(value)||Array.isArray(value))search(value)}}function check(){!--counter&&(failed?reject:resolve)(obj)}}),solveDependency:async(dependency,instance)=>{if(!self.helper.isDependency(dependency))return dependency;dependency=self.helper.clone(dependency);const operation=dependency.shift().substr("ccm.".length);switch(operation){case"load":instance&&setContext(dependency);return await self.load.apply(null,dependency);case"component":case"instance":case"proxy":case"start":case"set":case"del":dependency[1]=await self.helper.solveDependency(dependency[1],instance);if(!dependency[operation==="store"?0:1])dependency[operation==="store"?0:1]={};if(instance)dependency[operation==="store"?0:1].parent=instance;return await self[operation].apply(null,dependency);case"store":case"get":if(!dependency[0])dependency[0]={};if(instance)dependency[0].parent=instance;return await self[operation].apply(null,dependency)}function setContext(resources){for(let i=0;i<resources.length;i++){if(Array.isArray(resources[i])){setContext(resources[i]);continue}if(!self.helper.isObject(resources[i]))resources[i]={url:resources[i]};if(!resources[i].context)resources[i].context=instance.element.parentNode}}},solveDotNotation:function(obj){obj=self.helper.clone(obj);for(const key in obj)if(key.indexOf(".")!==-1){self.helper.deepValue(obj,key,obj[key]);delete obj[key]}return obj},stringify:(value,replacer,space)=>JSON.stringify(value,(key,value)=>{if(typeof value==="function"||self.helper.isSpecialObject(value))value=null;return replacer?replacer(key,value):value},space),toDotNotation:function(obj,all_levels){const result={};recursive(obj,"");return result;function recursive(obj,prefix){for(const key in obj){if(typeof obj[key]==="object"&&!self.helper.isSpecialObject(obj[key])){if(all_levels)result[prefix+key]=obj[key];recursive(obj[key],prefix+key+".")}else result[prefix+key]=obj[key]}}},toJSON:value=>self.helper.parse(self.helper.stringify(value))}};self.load.timeout=0;if(self.version&&!ccm[self.version()])ccm[self.version()]=self;if(!ccm.version||self.helper.compareVersions(self.version(),ccm.version())>0){ccm.latest=self;Object.assign(ccm,self.helper.clone(self))}defineCustomElement("app");async function defineCustomElement(name){if(!("customElements"in window))await self.load({url:"https://ccmjs.github.io/ccm/polyfills/webcomponents-lite.js",attr:{integrity:"sha384-yEuTKRGFLhOAfHNxaZiiI23KhMelYudrPUNSUK6T5u1+deGEEKsQ89cS0sPIHjyj",crossorigin:"anonymous"}});if(customElements.get("ccm-"+name))return;window.customElements.define("ccm-"+name,class extends HTMLElement{async connectedCallback(){if(!document.body.contains(this))return;let node=this;while(node=node.parentNode)if(node.tagName&&node.tagName.indexOf("CCM-")===0)return;const config=self.helper.generateConfig(this);this.removeAttribute("key");config.root=this;await self.start(this.tagName==="CCM-APP"?this.getAttribute("component"):name,config)}})}async function prepareConfig(config={},defaults={}){config=await self.helper.solveDependency(config);let result=defaults;result=await self.helper.integrate(await self.helper.solveDependency(config.key),result);result=await self.helper.integrate(config,result);delete result.key;delete result.component;return result}async function changeFrameworkVersion(component,config){const source=config&&config.ccm||component.config&&component.config.ccm;if(source){component.ccm=ccm[(await self.helper.loadFramework(source)).version()];component.ccm.url=self.helper.isObject(source)?source.url:source;config&&delete config.ccm;component.config&&delete component.config.ccm}}})();