Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 1.31
  • master
  • 1.10.0
  • 1.30.1
  • 1.31.0
  • 1.8.0
  • 1.9.0
  • 3.100.0
  • 3.100.1
  • 3.100.10
  • 3.100.11
  • 3.100.12
  • 3.100.13
  • 3.100.14
  • 3.100.15
  • 3.100.16
  • 3.100.17
  • 3.100.18
  • 3.100.19
  • 3.100.2
  • 3.100.20
  • 3.100.3
  • 3.100.4
  • 3.100.5
  • 3.100.6
  • 3.100.7
  • 3.100.8
  • 3.100.9
  • 3.101.0
  • 3.101.1
  • 3.101.2
  • 3.101.3
  • 3.102.0
  • 3.102.1
  • 3.102.2
  • 3.102.3
  • 3.102.4
  • 3.102.5
  • 3.102.6
  • 3.103.0
  • 3.103.1
  • 3.104.0
  • 3.104.1
  • 3.105.0
  • 3.105.1
  • 3.105.2
  • 3.106.0
  • 3.106.1
  • 3.107.0
  • 3.108.0
  • 3.108.1
  • 3.108.2
  • 3.108.3
  • 3.108.4
  • 3.108.5
  • 3.109.0
  • 3.110.0
  • 3.110.1
  • 3.110.2
  • 3.110.3
  • 3.110.4
  • 3.111.0
  • 3.112.0
  • 3.112.1
  • 3.112.2
  • 3.112.3
  • 3.112.4
  • 3.113.0
  • 3.114.0
  • 3.114.1
  • 3.114.2
  • 3.114.3
  • 3.114.4
  • 3.114.5
  • 3.114.6
  • 3.114.7
  • 3.115.0
  • 3.115.1
  • 3.115.2
  • 3.115.3
  • 3.115.4
  • 3.116.0
  • 3.116.1
  • 3.117.0
  • 3.117.1
  • 3.117.2
  • 3.117.3
  • 3.118.0
  • 3.118.1
  • 3.119.0
  • 3.120.0
  • 3.121.0
  • 3.51.5
  • 3.52.0
  • 3.52.1
  • 3.53.0
  • 3.54.0
  • 3.55.0
  • 3.55.1
  • 3.55.2
  • 3.55.3
  • 3.55.4
102 results

Target

Select target project
  • oss/libraries/javascript/monster
1 result
Select Git revision
  • 1.31
  • master
  • 1.10.0
  • 1.30.1
  • 1.31.0
  • 1.8.0
  • 1.9.0
  • 3.100.0
  • 3.100.1
  • 3.100.10
  • 3.100.11
  • 3.100.12
  • 3.100.13
  • 3.100.14
  • 3.100.15
  • 3.100.16
  • 3.100.17
  • 3.100.18
  • 3.100.19
  • 3.100.2
  • 3.100.20
  • 3.100.3
  • 3.100.4
  • 3.100.5
  • 3.100.6
  • 3.100.7
  • 3.100.8
  • 3.100.9
  • 3.101.0
  • 3.101.1
  • 3.101.2
  • 3.101.3
  • 3.102.0
  • 3.102.1
  • 3.102.2
  • 3.102.3
  • 3.102.4
  • 3.102.5
  • 3.102.6
  • 3.103.0
  • 3.103.1
  • 3.104.0
  • 3.104.1
  • 3.105.0
  • 3.105.1
  • 3.105.2
  • 3.106.0
  • 3.106.1
  • 3.107.0
  • 3.108.0
  • 3.108.1
  • 3.108.2
  • 3.108.3
  • 3.108.4
  • 3.108.5
  • 3.109.0
  • 3.110.0
  • 3.110.1
  • 3.110.2
  • 3.110.3
  • 3.110.4
  • 3.111.0
  • 3.112.0
  • 3.112.1
  • 3.112.2
  • 3.112.3
  • 3.112.4
  • 3.113.0
  • 3.114.0
  • 3.114.1
  • 3.114.2
  • 3.114.3
  • 3.114.4
  • 3.114.5
  • 3.114.6
  • 3.114.7
  • 3.115.0
  • 3.115.1
  • 3.115.2
  • 3.115.3
  • 3.115.4
  • 3.116.0
  • 3.116.1
  • 3.117.0
  • 3.117.1
  • 3.117.2
  • 3.117.3
  • 3.118.0
  • 3.118.1
  • 3.119.0
  • 3.120.0
  • 3.121.0
  • 3.51.5
  • 3.52.0
  • 3.52.1
  • 3.53.0
  • 3.54.0
  • 3.55.0
  • 3.55.1
  • 3.55.2
  • 3.55.3
  • 3.55.4
102 results
Show changes
Showing
with 25 additions and 23 deletions
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,AbstractConstraint}from"./abstract.js";import{isObject}from"../types/is.js";class IsObject extends AbstractConstraint{isValid(value){if(isObject(value)){return Promise.resolve(value)}return Promise.reject(value)}}Monster.assignToNamespace("Monster.Constraints",IsObject);export{Monster,IsObject};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';const namespace="Monster.Constraints";
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,AbstractOperator}from"./abstractoperator.js";class OrOperator extends AbstractOperator{isValid(value){var self=this;return new Promise(function(resolve,reject){let a,b;self.operantA.isValid(value).then(function(){resolve()}).catch(function(){a=false;if(b===false){reject()}});self.operantB.isValid(value).then(function(){resolve()}).catch(function(){b=false;if(a===false){reject()}})})}}Monster.assignToNamespace("Monster.Constraints",OrOperator);export{Monster,OrOperator};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,AbstractConstraint}from"./abstract.js";class Valid extends AbstractConstraint{isValid(value){return Promise.resolve(value)}}Monster.assignToNamespace("Monster.Constraints",Valid);export{Monster,Valid};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{isFunction}from"../types/is.js";import{validateString}from"../types/validate.js";import{Pathfinder}from"./pathfinder.js";function buildMap(subject,selector,valuePath,keyPath,filter){validateString(selector);const result=new Map;let finder=new Pathfinder(subject);let map=finder.getVia(selector);if(!(map instanceof Map)){return result}map.forEach((v,k,m)=>{if(isFunction(filter)){if(filter.call(m,v,k)!==true)return}k=build(v,keyPath,k);v=build(v,valuePath);result.set(k,v)});return result}function build(subject,definition,defaultValue){if(definition===undefined)return defaultValue?defaultValue:subject;validateString(definition);const regexp=/(?<placeholder>\$\{(?<path>[a-z.-]*)\})/gm;const array=[...definition.matchAll(regexp)];let finder=new Pathfinder(subject);if(array.length===0){return finder.getVia(definition)}array.forEach(a=>{let groups=a?.["groups"];let placeholder=groups?.["placeholder"];if(placeholder===undefined)return;let path=groups?.["path"];let v=finder.getVia(path);definition=definition.replaceAll(placeholder,v)});return definition}Monster.assignToNamespace("Monster.Data",buildMap);export{Monster,buildMap};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,isArray,isObject}from"../types/is.js";function Diff(first,second){return doDiff(first,second)}function getKeys(a,b,type){if(isArray(type)){const keys=a.length>b.length?new Array(a.length):new Array(b.length);keys.fill(0);return new Set(keys.map((_,i)=>i))}return new Set(Object.keys(a).concat(Object.keys(b)))}function doDiff(a,b,path,diff){let typeA=typeof a;let typeB=typeof b;const currPath=path||[];const currDiff=diff||[];if(typeA===typeB&&typeA==="object"){getKeys(a,b,typeA).forEach(v=>{if(!Object.prototype.hasOwnProperty.call(a,v)){currDiff.push(buildResult(a[v],b[v],"add",currPath.concat(v)))}else if(!Object.prototype.hasOwnProperty.call(b,v)){currDiff.push(buildResult(a[v],b[v],"delete",currPath.concat(v)))}else{doDiff(a[v],b[v],currPath.concat(v),currDiff)}})}else{const o=getOperator(a,b,typeA,typeB);if(o!==undefined){currDiff.push(buildResult(a,b,o,path))}}return currDiff}function buildResult(a,b,operator,path){const result={operator,path};if(operator!=="add"){result.first={value:a,type:typeof a};if(isObject(a)){const name=Object.getPrototypeOf(a)?.constructor?.name;if(name!==undefined){result.first.instance=name}}}if(operator==="add"||operator==="update"){result.second={value:b,type:typeof b};if(isObject(b)){const name=Object.getPrototypeOf(b)?.constructor?.name;if(name!==undefined){result.second.instance=name}}}return result}function isNotEqual(a,b){if(typeof a!==typeof b){return true}if(a instanceof Date&&b instanceof Date){return a.getTime()!==b.getTime()}return a!==b}function getOperator(a,b){let operator;let typeA=typeof a;let typeB=typeof b;if(typeA==="undefined"&&typeB!=="undefined"){operator="add"}else if(typeA!=="undefined"&&typeB==="undefined"){operator="delete"}else if(isNotEqual(a,b)){operator="update"}return operator}Monster.assignToNamespace("Monster.Data",Diff);export{Monster,Diff};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';const namespace="Monster.Data";
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{isObject,isArray,isInteger}from"../types/is.js";import{validateString,validateInteger}from"../types/validate.js";import{Base}from"../types/base.js";import{Stack}from"../types/stack.js";const DELIMITER=".";const WILDCARD="*";class Pathfinder extends Base{constructor(object){super();this.object=object;this.wildCard=WILDCARD}setWildCard(wildcard){validateString(wildcard);this.wildCard=wildcard;return this}getVia(path){validateString(path);return getValueViaPath.call(this,this.object,path)}setVia(path,value){validateString(path);setValueViaPath.call(this,this.object,path,value);return this}deleteVia(path){validateString(path);deleteValueViaPath.call(this,this.object,path);return this}exists(path){validateString(path);try{getValueViaPath.call(this,this.object,path,true);return true}catch(e){}return false}}Monster.assignToNamespace("Monster.Data",Pathfinder);export{Monster,Pathfinder};function iterate(subject,path,check){const result=new Map;if(isObject(subject)||isArray(subject)){for(const[key,value]of Object.entries(subject)){result.set(key,getValueViaPath.call(this,value,path,check))}}else{let key=path.split(DELIMITER).shift();result.set(key,getValueViaPath.call(this,subject,path,check))}return result}function getValueViaPath(subject,path,check){if(path===""){return subject}let parts=path.split(DELIMITER);let current=parts.shift();if(current===this.wildCard){return iterate.call(this,subject,parts.join(DELIMITER),check)}if(isObject(subject)||isArray(subject)){let anchor;if(subject instanceof Map||subject instanceof WeakMap){anchor=subject.get(current)}else if(subject instanceof Set||subject instanceof WeakSet){current=parseInt(current);validateInteger(current);anchor=[...subject]?.[current]}else if(subject instanceof WeakRef){throw Error("unsupported action for this data type")}else if(isArray(subject)){current=parseInt(current);validateInteger(current);anchor=subject?.[current]}else{anchor=subject?.[current]}if(isObject(anchor)||isArray(anchor)){return getValueViaPath.call(this,anchor,parts.join(DELIMITER),check)}if(parts.length>0){throw Error("the journey is not at its end ("+parts.join(DELIMITER)+")")}if(check===true&&!subject.hasOwnProperty(current)){throw Error("unknown value")}return anchor}throw TypeError("unsupported type "+typeof subject)}function setValueViaPath(object,path,value){validateString(path);let parts=path.split(DELIMITER);let last=parts.pop();let subpath=parts.join(DELIMITER);let stack=new Stack;let current=subpath;while(true){try{getValueViaPath.call(this,object,current,true);break}catch(e){}stack.push(current);parts.pop();current=parts.join(DELIMITER);if(current==="")break}while(!stack.isEmpty()){current=stack.pop();let obj={};if(!stack.isEmpty()){let n=stack.peek().split(DELIMITER).pop();if(isInteger(parseInt(n))){obj=[]}}setValueViaPath.call(this,object,current,obj)}let anchor=getValueViaPath.call(this,object,subpath);if(!isObject(object)&&!isArray(object)){throw TypeError("unsupported type: "+typeof object)}if(anchor instanceof Map||anchor instanceof WeakMap){anchor.set(last,value)}else if(anchor instanceof Set||anchor instanceof WeakSet){anchor.append(value)}else if(anchor instanceof WeakRef){throw Error("unsupported action for this data type")}else if(isArray(anchor)){last=parseInt(last);validateInteger(last);anchor[last]=value}else{anchor[last]=value}return}function deleteValueViaPath(object,path){const parts=path.split(DELIMITER);let last=parts.pop();const subpath=parts.join(DELIMITER);const anchor=getValueViaPath.call(this,object,subpath);if(anchor instanceof Map){anchor.delete(last)}else if(anchor instanceof Set||anchor instanceof WeakMap||anchor instanceof WeakSet||anchor instanceof WeakRef){throw Error("unsupported action for this data type")}else if(isArray(anchor)){last=parseInt(last);validateInteger(last);delete anchor[last]}else{delete anchor[last]}return}
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{Transformer}from"./transformer.js";import{Base}from"../types/base.js";import{validateFunction,validateString}from"../types/validate.js";const DELIMITER="|";class Pipe extends Base{constructor(pipe){super();validateString(pipe);this.pipe=pipe.split(DELIMITER).map(v=>{return new Transformer(v)})}setCallback(name,callback){for(const[,t]of Object.entries(this.pipe)){t.setCallback(name,callback)}return this}run(value){return this.pipe.reduce((accumulator,transformer,currentIndex,array)=>{return transformer.run(accumulator)},value)}}Monster.assignToNamespace("Monster.Data",Pipe);export{Monster,Pipe};
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{Transformer}from"./transformer.js";import{Base}from"../types/base.js";import{validateFunction,validateString}from"../types/validate.js";const DELIMITER="|";class Pipe extends Base{constructor(pipe){super();validateString(pipe);this.pipe=pipe.split(DELIMITER).map(v=>{return new Transformer(v)})}setCallback(name,callback,context){for(const[,t]of Object.entries(this.pipe)){t.setCallback(name,callback,context)}return this}run(value){return this.pipe.reduce((accumulator,transformer,currentIndex,array)=>{return transformer.run(accumulator)},value)}}Monster.assignToNamespace("Monster.Data",Pipe);export{Monster,Pipe};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateString,validatePrimitive,validateFunction,validateInteger}from"../types/validate.js";import{isObject,isString,isArray}from"../types/is.js";import{ID}from"../types/id.js";import{clone}from"../util/clone.js";import{Pathfinder}from"./pathfinder.js";class Transformer extends Base{constructor(definition){super();validateString(definition);this.args=disassemble(definition);this.command=this.args.shift();this.callbacks=new Map}setCallback(name,callback){validateString(name);validateFunction(callback);this.callbacks.set(name,callback);return this}run(value){return transform.apply(this,[value])}}Monster.assignToNamespace("Monster.Data",Transformer);export{Monster,Transformer};function disassemble(command){validateString(command);let placeholder=new Map;const regex=/((?<pattern>\\(?<char>.)){1})/mig;let result=command.matchAll(regex);for(let m of result){let g=m?.["groups"];if(!isObject(g)){continue}let p=g?.["pattern"];let c=g?.["char"];if(p&&c){let r="__"+new ID().toString()+"__";placeholder.set(r,c);command=command.replace(p,r)}}let parts=command.split(":");parts=parts.map(function(value){let v=value.trim();for(let k of placeholder){v=v.replace(k[0],k[1])}return v});return parts}function convertToString(value){if(isObject(value)&&value.hasOwnProperty("toString")){value=value.toString()}validateString(value);return value}function transform(value){let args=clone(this.args);let key;switch(this.command){case"static":return this.args.join(":");case"tolower":case"strtolower":case"tolowercase":validateString(value);return value.toLowerCase();case"toupper":case"strtoupper":case"touppercase":validateString(value);return value.toUpperCase();case"tostring":return""+value;case"tointeger":let n=parseInt(value);validateInteger(n);return n;case"tojson":return JSON.stringify(value);case"trim":validateString(value);return value.trim();case"rawurlencode":validateString(value);return encodeURIComponent(value).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A");case"call":let callback;let callbackName=args.shift();if(isObject(value)&&value.hasOwnProperty(callbackName)){callback=value[callbackName]}else if(this.callbacks.has(callbackName)){callback=this.callbacks.get(callbackName)}else if(typeof window==="object"&&window.hasOwnProperty(callbackName)){callback=window[callbackName]}validateFunction(callback);args.unshift(value);return callback(...args);case"plain":case"plaintext":validateString(value);let doc=new DOMParser().parseFromString(value,"text/html");return doc.body.textContent||"";case"if":case"?":validatePrimitive(value);let trueStatement=args.shift()||undefined;let falseStatement=args.shift()||undefined;if(trueStatement==="value"){trueStatement=value}if(trueStatement==="\\value"){trueStatement="value"}if(falseStatement==="value"){falseStatement=value}if(falseStatement==="\\value"){falseStatement="value"}let condition=value!==undefined&&value!==""&&value!=="off"&&value!=="false"&&value!==false||value==="on"||value==="true"||value===true;return condition?trueStatement:falseStatement;case"ucfirst":validateString(value);let firstchar=value.charAt(0).toUpperCase();return firstchar+value.substr(1);case"ucwords":validateString(value);return value.replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g,function(v){return v.toUpperCase()});case"count":case"length":if((isString(value)||isObject(value)||isArray(value))&&value.hasOwnProperty("length")){return value.length}throw new TypeError("unsupported type");case"base64":convertToString(value);return btoa(value);case"empty":return"";case"undefined":return undefined;case"prefix":validateString(value);let prefix=args?.[0];return prefix+value;case"suffix":validateString(value);let suffix=args?.[0];return value+suffix;case"uniqid":return new ID().toString();case"key":case"property":case"index":key=args.shift()||"undefined";let defaultValue=args.shift()||"";if(value instanceof Map){if(!value.has(key)){return defaultValue}return value.get(key)}if(isObject(value)||isArray(value)){if(value?.[key]){return value?.[key]}return defaultValue}throw new Error("type not supported");case"path":key=args.shift()||"undefined";return new Pathfinder(value).getVia(key);case"substring":validateString(value);let start=parseInt(args[0])||0;let end=(parseInt(args[1])||0)+start;return value.substring(start,end);case"nop":return value;default:throw new Error("unknown command "+this.command);}return value}
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{Base}from"../types/base.js";import{getGlobal}from"../types/global.js";import{validateString,validatePrimitive,validateFunction,validateInteger,validateObject}from"../types/validate.js";import{isObject,isString,isArray}from"../types/is.js";import{ID}from"../types/id.js";import{clone}from"../util/clone.js";import{Pathfinder}from"./pathfinder.js";class Transformer extends Base{constructor(definition){super();validateString(definition);this.args=disassemble(definition);this.command=this.args.shift();this.callbacks=new Map}setCallback(name,callback,context){validateString(name);validateFunction(callback);if(context!==undefined){validateObject(context)}this.callbacks.set(name,{callback:callback,context:context});return this}run(value){return transform.apply(this,[value])}}Monster.assignToNamespace("Monster.Data",Transformer);export{Monster,Transformer};function disassemble(command){validateString(command);let placeholder=new Map;const regex=/((?<pattern>\\(?<char>.)){1})/mig;let result=command.matchAll(regex);for(let m of result){let g=m?.["groups"];if(!isObject(g)){continue}let p=g?.["pattern"];let c=g?.["char"];if(p&&c){let r="__"+new ID().toString()+"__";placeholder.set(r,c);command=command.replace(p,r)}}let parts=command.split(":");parts=parts.map(function(value){let v=value.trim();for(let k of placeholder){v=v.replace(k[0],k[1])}return v});return parts}function convertToString(value){if(isObject(value)&&value.hasOwnProperty("toString")){value=value.toString()}validateString(value);return value}function transform(value){let args=clone(this.args);let key;switch(this.command){case"static":return this.args.join(":");case"tolower":case"strtolower":case"tolowercase":validateString(value);return value.toLowerCase();case"toupper":case"strtoupper":case"touppercase":validateString(value);return value.toUpperCase();case"tostring":return""+value;case"tointeger":let n=parseInt(value);validateInteger(n);return n;case"tojson":return JSON.stringify(value);case"trim":validateString(value);return value.trim();case"rawurlencode":validateString(value);return encodeURIComponent(value).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A");case"call":let callback;let callbackName=args.shift();let context=getGlobal();if(isObject(value)&&value.hasOwnProperty(callbackName)){callback=value[callbackName]}else if(this.callbacks.has(callbackName)){let s=this.callbacks.get(callbackName);callback=s?.["callback"];context=s?.["context"]}else if(typeof window==="object"&&window.hasOwnProperty(callbackName)){callback=window[callbackName]}validateFunction(callback);args.unshift(value);return callback.call(context,...args);case"plain":case"plaintext":validateString(value);let doc=new DOMParser().parseFromString(value,"text/html");return doc.body.textContent||"";case"if":case"?":validatePrimitive(value);let trueStatement=args.shift()||undefined;let falseStatement=args.shift()||undefined;if(trueStatement==="value"){trueStatement=value}if(trueStatement==="\\value"){trueStatement="value"}if(falseStatement==="value"){falseStatement=value}if(falseStatement==="\\value"){falseStatement="value"}let condition=value!==undefined&&value!==""&&value!=="off"&&value!=="false"&&value!==false||value==="on"||value==="true"||value===true;return condition?trueStatement:falseStatement;case"ucfirst":validateString(value);let firstchar=value.charAt(0).toUpperCase();return firstchar+value.substr(1);case"ucwords":validateString(value);return value.replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g,function(v){return v.toUpperCase()});case"count":case"length":if((isString(value)||isObject(value)||isArray(value))&&value.hasOwnProperty("length")){return value.length}throw new TypeError("unsupported type");case"base64":convertToString(value);return btoa(value);case"empty":return"";case"undefined":return undefined;case"prefix":validateString(value);let prefix=args?.[0];return prefix+value;case"suffix":validateString(value);let suffix=args?.[0];return value+suffix;case"uniqid":return new ID().toString();case"key":case"property":case"index":key=args.shift()||"undefined";let defaultValue=args.shift()||"";if(value instanceof Map){if(!value.has(key)){return defaultValue}return value.get(key)}if(isObject(value)||isArray(value)){if(value?.[key]){return value?.[key]}return defaultValue}throw new Error("type not supported");case"path":key=args.shift()||"undefined";return new Pathfinder(value).getVia(key);case"substring":validateString(value);let start=parseInt(args[0])||0;let end=(parseInt(args[1])||0)+start;return value.substring(start,end);case"nop":return value;default:throw new Error("unknown command "+this.command);}return value}
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,Base}from"../types/base.js";import{validateInstance,validateString}from"../types/validate.js";import{getGlobalFunction}from"../types/global.js";import{ProxyObserver}from"../types/proxyobserver.js";const ATTRIBUTEPREFIX="data-monster-";class Assembler extends Base{constructor(fragment){super();this.attributePrefix=ATTRIBUTEPREFIX;validateInstance(fragment,getGlobalFunction("DocumentFragment"));this.fragment=fragment}setAttributePrefix(prefix){validateString(prefix);this.attributePrefix=prefix;return this}getAttributePrefix(){return this.attributePrefix}createDocumentFragment(data){if(data===undefined){data=new ProxyObserver({})}validateInstance(data,ProxyObserver);let fragment=this.fragment.cloneNode(true);return fragment}}Monster.assignToNamespace("Monster.DOM",Assembler);export{Monster,ATTRIBUTEPREFIX,Assembler};
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{TokenList}from"../types/tokenlist.js";import{validateInstance,validateString,validateSymbol}from"../types/validate.js";import{ATTRIBUTE_OBJECTLINK}from"./constants.js";function addToObjectLink(element,symbol,object){validateInstance(element,HTMLElement);validateSymbol(symbol);if(element?.[symbol]===undefined){element[symbol]=new Set}addAttributeToken(element,ATTRIBUTE_OBJECTLINK,symbol.toString());element[symbol].add(object);return element}function removeObjectLink(element,symbol){validateInstance(element,HTMLElement);validateSymbol(symbol);if(element?.[symbol]===undefined){return element}removeAttributeToken(element,ATTRIBUTE_OBJECTLINK,symbol.toString());delete element[symbol];return element}function hasObjectLink(element,symbol){validateInstance(element,HTMLElement);validateSymbol(symbol);if(element?.[symbol]===undefined){return false}return containsAttributeToken(element,ATTRIBUTE_OBJECTLINK,symbol.toString())}function getLinkedObjects(element,symbol){validateInstance(element,HTMLElement);validateSymbol(symbol);if(element?.[symbol]===undefined){throw new Error("there is no object link for "+symbol.toString())}return element?.[symbol][Symbol.iterator]()}function toggleAttributeToken(element,key,token){validateInstance(element,HTMLElement);validateString(token);validateString(key);if(!element.hasAttribute(key)){element.setAttribute(key,token);return element}element.setAttribute(key,new TokenList(element.getAttribute(key)).toggle(token).toString());return element}function addAttributeToken(element,key,token){validateInstance(element,HTMLElement);validateString(token);validateString(key);if(!element.hasAttribute(key)){element.setAttribute(key,token);return element}element.setAttribute(key,new TokenList(element.getAttribute(key)).add(token).toString());return element}function removeAttributeToken(element,key,token){validateInstance(element,HTMLElement);validateString(token);validateString(key);if(!element.hasAttribute(key)){return element}element.setAttribute(key,new TokenList(element.getAttribute(key)).remove(token).toString());return element}function containsAttributeToken(element,key,token){validateInstance(element,HTMLElement);validateString(token);validateString(key);if(!element.hasAttribute(key)){return false}return new TokenList(element.getAttribute(key)).contains(token)}function replaceAttributeToken(element,key,from,to){validateInstance(element,HTMLElement);validateString(from);validateString(to);validateString(key);if(!element.hasAttribute(key)){return element}element.setAttribute(key,new TokenList(element.getAttribute(key)).replace(from,to).toString());return element}function clearAttributeTokens(element,key){validateInstance(element,HTMLElement);validateString(key);if(!element.hasAttribute(key)){return element}element.setAttribute(key,"");return element}Monster.assignToNamespace("Monster.DOM",getLinkedObjects,addToObjectLink,removeObjectLink,hasObjectLink,clearAttributeTokens,replaceAttributeToken,containsAttributeToken,removeAttributeToken,addAttributeToken,toggleAttributeToken);export{Monster,addToObjectLink,removeObjectLink,hasObjectLink,clearAttributeTokens,replaceAttributeToken,containsAttributeToken,removeAttributeToken,addAttributeToken,toggleAttributeToken,getLinkedObjects};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";const ATTRIBUTE_PREFIX="data-monster-";const ATTRIBUTE_OPTIONS=ATTRIBUTE_PREFIX+"options";const DEFAULT_THEME="monster";const ATTRIBUTE_THEME_PREFIX=ATTRIBUTE_PREFIX+"theme-";const ATTRIBUTE_THEME_NAME=ATTRIBUTE_THEME_PREFIX+"name";const ATTRIBUTE_UPDATER_ATTRIBUTES=ATTRIBUTE_PREFIX+"attributes";const ATTRIBUTE_UPDATER_REPLACE=ATTRIBUTE_PREFIX+"replace";const ATTRIBUTE_UPDATER_INSERT=ATTRIBUTE_PREFIX+"insert";const ATTRIBUTE_UPDATER_INSERT_REFERENCE=ATTRIBUTE_PREFIX+"insert-reference";const ATTRIBUTE_UPDATER_REMOVE=ATTRIBUTE_PREFIX+"remove";export{Monster,ATTRIBUTE_PREFIX,ATTRIBUTE_OPTIONS,DEFAULT_THEME,ATTRIBUTE_THEME_PREFIX,ATTRIBUTE_THEME_NAME,ATTRIBUTE_UPDATER_ATTRIBUTES,ATTRIBUTE_UPDATER_REPLACE,ATTRIBUTE_UPDATER_INSERT,ATTRIBUTE_UPDATER_INSERT_REFERENCE,ATTRIBUTE_UPDATER_REMOVE};
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";const ATTRIBUTE_PREFIX="data-monster-";const ATTRIBUTE_OPTIONS=ATTRIBUTE_PREFIX+"options";const DEFAULT_THEME="monster";const ATTRIBUTE_THEME_PREFIX=ATTRIBUTE_PREFIX+"theme-";const ATTRIBUTE_THEME_NAME=ATTRIBUTE_THEME_PREFIX+"name";const ATTRIBUTE_UPDATER_ATTRIBUTES=ATTRIBUTE_PREFIX+"attributes";const ATTRIBUTE_UPDATER_REPLACE=ATTRIBUTE_PREFIX+"replace";const ATTRIBUTE_UPDATER_INSERT=ATTRIBUTE_PREFIX+"insert";const ATTRIBUTE_UPDATER_INSERT_REFERENCE=ATTRIBUTE_PREFIX+"insert-reference";const ATTRIBUTE_UPDATER_REMOVE=ATTRIBUTE_PREFIX+"remove";const ATTRIBUTE_UPDATER_BIND=ATTRIBUTE_PREFIX+"bind";const ATTRIBUTE_OBJECTLINK=ATTRIBUTE_PREFIX+"objectlink";export{Monster,ATTRIBUTE_PREFIX,ATTRIBUTE_OPTIONS,DEFAULT_THEME,ATTRIBUTE_THEME_PREFIX,ATTRIBUTE_THEME_NAME,ATTRIBUTE_UPDATER_ATTRIBUTES,ATTRIBUTE_UPDATER_REPLACE,ATTRIBUTE_UPDATER_INSERT,ATTRIBUTE_UPDATER_INSERT_REFERENCE,ATTRIBUTE_UPDATER_REMOVE,ATTRIBUTE_UPDATER_BIND,ATTRIBUTE_OBJECTLINK};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{ATTRIBUTE_OPTIONS}from"./constants.js";import{findDocumentTemplate}from"./template.js";import{getGlobalObject}from"../types/global.js";import{Monster,validateFunction,validateObject,validateString}from"../types/validate.js";class CustomElement extends HTMLElement{constructor(){super();this._options=Object.assign({},this.defaults,getOptionsFromAttributes.call(this));this.init()}get defaults(){return{shadowMode:"open",delegatesFocus:true}}getOption(key,defaultValue){validateString(key);let v=this._options?.[key];if(v===undefined)return defaultValue;return v}init(){initShadowRoot.call(this);return this}assemble(){return this}disassemble(){return this}connectedCallback(){this.assemble()}disconnectedCallback(){this.disassemble()}adoptedCallback(){}attributeChangedCallback(attrName,oldVal,newVal){this.assemble()}static getTemplate(){throw new Error("the method getTemplate must be overwritten by the derived class.")}static getTag(){throw new Error("the method getTag must be overwritten by the derived class.")}static getCSSStyleSheet(){return new CSSStyleSheet}}function getOptionsFromAttributes(){if(this.hasAttribute(ATTRIBUTE_OPTIONS)){try{let obj=JSON.parse(this.getAttribute(ATTRIBUTE_OPTIONS));validateObject(obj);return obj}catch(e){throw new Error("the options attribute "+ATTRIBUTE_OPTIONS+" does not contain a valid json definition (actual: "+this.getAttribute(ATTRIBUTE_OPTIONS)+").")}}return{}}function initShadowRoot(){this.attachShadow({mode:this.getOption("shadowMode","open"),delegatesFocus:this.getOption("delegatesFocus",true)});const styleSheet=this.constructor.getCSSStyleSheet();if(styleSheet instanceof CSSStyleSheet){this.shadowRoot.adoptedStyleSheets=[styleSheet]}try{let template=findDocumentTemplate(this.constructor.getTag());this.shadowRoot.appendChild(template.createDocumentFragment())}catch(e){this.shadowRoot.innerHTML=this.constructor.getTemplate()}return this}function registerCustomElement(element){validateFunction(element);let tag=element.getTag();getGlobalObject("customElements").define(element.getTag(),element);return}Monster.assignToNamespace("Monster.DOM",CustomElement,registerCustomElement);export{Monster,registerCustomElement,CustomElement};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,Base}from"../types/base.js";import{Stack}from"../types/stack.js";import{validateInstance}from"../types/validate.js";import{ProxyObserver}from"../types/proxyobserver.js";import{Observer}from"../types/observer.js";import{getGlobalFunction,getGlobalObject}from"../types/global.js";import{isInstance}from"../types/is.js";import{ATTRIBUTEPREFIX}from"./assembler.js";import{ID}from"../types/id.js";const MONSTERDOMHANDLE=Symbol("MonsterHandle");class Handle extends Base{constructor(data){super();let self=this;self.id=new ID;validateInstance(data,ProxyObserver);this.data=data;this.mutationObserver=createMutationObserver.call(this);this.dataObserver=createDataObserver.call(this);this.data.attachObserver(this.dataObserver);this.nodes=new WeakSet;this.updates=new Stack}update(){return}remove(node){if(isInstance(node,getGlobalFunction("Document"))){node=node.firstElementChild}validateInstance(node,getGlobalFunction("HTMLElement"));if(!this.nodes.has(node)){return this}this.mutationObserver.disconnect(node);delete node.dataset[MONSTERDOMHANDLE];node.removeAttribute(ATTRIBUTEPREFIX+"handler");return this}append(node){if(isInstance(node,getGlobalFunction("Document"))){node=node.firstElementChild}validateInstance(node,getGlobalFunction("HTMLElement"));if(this.nodes.has(node)){return this}node.dataset[MONSTERDOMHANDLE]=this;node.setAttribute(ATTRIBUTEPREFIX+"handler",true);this.mutationObserver.observe(node,{attributes:true,childList:true,subtree:true,characterData:true,characterDataOldValue:true,attributeOldValue:true});this.nodes.add(node);return this}}function createDataObserver(){const self=this;return new Observer(()=>{self.update()})}function createMutationObserver(){const self=this;const MutationObserver=getGlobalFunction("MutationObserver");return new MutationObserver((mutationsList,observer)=>{for(const mutation of mutationsList){self.updates.push(mutation)}self.update()})}function getHandleFromNode(node){validateInstance(node,getGlobalFunction("Node"));let handle=node.dataset?.[MONSTERDOMHANDLE];if(handle===undefined){let parentNode=node?.["parentNode"];if(isInstance(parentNode,getGlobalFunction("Node"))){return getHandleFromNode(parentNode)}}return handle}Monster.assignToNamespace("Monster.DOM",getHandleFromNode,Handle);export{Monster,getHandleFromNode,Handle};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';const namespace="Monster.DOM";
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,Base}from"../types/base.js";import{validateString}from"../types/validate.js";import{getGlobalFunction,getGlobalObject}from"../types/global.js";import{validateInstance}from"../types/validate.js";import{getDocumentTheme}from"./theme.js";class Template extends Base{constructor(template){super();const HTMLTemplateElement=getGlobalFunction("HTMLTemplateElement");validateInstance(template,HTMLTemplateElement);this.template=template}getTemplateElement(){return this.template}createDocumentFragment(){return this.template.content.cloneNode(true)}}function findDocumentTemplate(id){validateString(id);const document=getGlobalObject("document");const HTMLTemplateElement=getGlobalFunction("HTMLTemplateElement");let theme=getDocumentTheme();let themedID=id+"-"+theme.getName();let template=document.getElementById(themedID);if(template instanceof HTMLTemplateElement){return new Template(template)}template=document.getElementById(id);if(template instanceof HTMLTemplateElement){return new Template(template)}throw new Error("template "+id+" not found.")}Monster.assignToNamespace("Monster.DOM",Template,findDocumentTemplate);export{Monster,Template,findDocumentTemplate};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,Base}from"../types/base.js";import{validateString}from"../types/validate.js";import{getGlobalObject}from"../types/global.js";import{ATTRIBUTE_THEME_NAME,DEFAULT_THEME}from"./constants.js";class Theme extends Base{constructor(name){super();validateString(name);this.name=name}getName(){return this.name}}function getDocumentTheme(){let document=getGlobalObject("document");let name=DEFAULT_THEME;let element=document.querySelector("html");if(element instanceof HTMLElement){let theme=element.getAttribute(ATTRIBUTE_THEME_NAME);if(theme){name=theme}}return new Theme(name)}Monster.assignToNamespace("Monster.DOM",Theme,getDocumentTheme);export{Monster,Theme,getDocumentTheme};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Pipe}from"../data/pipe.js";import{Base,Monster}from"../types/base.js";import{isInstance,isArray}from"../types/is.js";import{Observer}from"../types/observer.js";import{ProxyObserver}from"../types/proxyobserver.js";import{validateInstance}from"../types/validate.js";import{clone}from"../util/clone.js";import{Diff}from"../data/diff.js";import{ATTRIBUTE_UPDATER_REPLACE,ATTRIBUTE_UPDATER_ATTRIBUTES,ATTRIBUTE_UPDATER_INSERT,ATTRIBUTE_UPDATER_REMOVE,ATTRIBUTE_UPDATER_INSERT_REFERENCE}from"../dom/constants.js";import{getDocument}from"./util.js";class Updater extends Base{constructor(element,subject){super();this.element=validateInstance(element,HTMLElement);if(!isInstance(subject,ProxyObserver)){subject=new ProxyObserver(subject)}this.last={};this.callbacks=new Map;this.subject=subject.attachObserver(new Observer(()=>{const s=this.subject.getRealSubject();const diff=Diff(this.last,s);this.last=clone(s);for(const[,change]of Object.entries(diff)){removeElement.call(this,change);insertElement.call(this,change);updateContent.call(this,change);updateAttributes.call(this,change)}}))}run(){this.last={};return this.subject.notifyObservers()}getSubject(){return this.subject.getSubject()}setCallback(name,callback){this.callbacks.set(name,callback);return this}}function removeElement(change){for(const[,element]of this.element.querySelectorAll(":scope ["+ATTRIBUTE_UPDATER_REMOVE+"]").entries()){element.parentNode.removeChild(element)}return this}function insertElement(change){const self=this;const subject=self.subject.getRealSubject();const document=getDocument();let mem=new WeakSet;let wd=0;while(true){let found=false;wd++;let p=clone(change?.["path"]);if(!isArray(p))return this;while(p.length>0){const current=p.join(".");const list=this.element.querySelectorAll(":scope ["+ATTRIBUTE_UPDATER_INSERT+"*=\"path:"+current+"\"]").entries();for(const[,containerElement]of list){if(mem.has(containerElement))continue;mem.add(containerElement);found=true;const attributes=containerElement.getAttribute(ATTRIBUTE_UPDATER_INSERT);let def=attributes.trim();let i=def.indexOf(" ");let key=def.substr(0,i).trim();let refPrefix=key+"-";let cmd=def.substr(i).trim();if(cmd.indexOf("|")>0){throw new Error("pipes are not allowed when cloning a node.")}let pipe=new Pipe(cmd);this.callbacks.forEach((f,n)=>{pipe.setCallback(n,f)});let value=pipe.run(subject);let dataPath=cmd.split(":").pop();let insertPoint;if(containerElement.hasChildNodes()){insertPoint=containerElement.lastChild}if(!isArray(value)){throw new Error("the value is not iterable")}let available=new Set;for(const[_i,obj]of Object.entries(value)){let ref=refPrefix+_i;let currentPath=dataPath+"."+_i;available.add(ref);let refElement=containerElement.querySelector("["+ATTRIBUTE_UPDATER_INSERT_REFERENCE+"=\""+ref+"\"]");if(refElement instanceof HTMLElement){insertPoint=refElement;continue}appendNewDocumentFragment(containerElement,key,ref,currentPath)}let nodes=containerElement.querySelectorAll("["+ATTRIBUTE_UPDATER_INSERT_REFERENCE+"*=\""+refPrefix+"\"]");for(const[,node]of Object.entries(nodes)){if(!available.has(node.getAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE))){containerElement.removeChild(node)}}}p.pop()}if(found===false)break;if(wd++>200){throw new Error("the maximum depth for the recursion is reached.")};}}function appendNewDocumentFragment(container,key,ref,path){let template=getDocument().querySelector("template#"+key);if(!(template instanceof HTMLTemplateElement)){throw new Error("no template was found with the specified key "+key)}let nodes=template.content.cloneNode(true);for(const[,node]of Object.entries(nodes.childNodes)){if(node instanceof HTMLElement){node.setAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE,ref);if(node.hasAttribute(ATTRIBUTE_UPDATER_REPLACE)){let value=node.getAttribute(ATTRIBUTE_UPDATER_REPLACE);node.setAttribute(ATTRIBUTE_UPDATER_REPLACE,value.replace("path:"+key,"path:"+path))}}container.appendChild(node)}}function updateContent(change){const self=this;const subject=self.subject.getRealSubject();let p=clone(change?.["path"]);runUpdateContent.call(this,this.element,p,subject);return this}function runUpdateContent(container,parts,subject){if(!isArray(parts))return;parts=clone(parts);let mem=new WeakSet;while(parts.length>0){const current=parts.join(".");parts.pop();for(const[,element]of container.querySelectorAll(":scope ["+ATTRIBUTE_UPDATER_REPLACE+"^=\"path:"+current+"\"], ["+ATTRIBUTE_UPDATER_REPLACE+"^=\"static:\"]").entries()){if(mem.has(element))continue;mem.add(element);const attributes=element.getAttribute(ATTRIBUTE_UPDATER_REPLACE);let cmd=attributes.trim();let pipe=new Pipe(cmd);this.callbacks.forEach((f,n)=>{pipe.setCallback(n,f)});let value=pipe.run(subject);if(value instanceof HTMLElement){while(element.firstChild){element.removeChild(element.firstChild)}element.addNode(value)}else{element.innerHTML=value}}}}function updateAttributes(change){const self=this;const subject=self.subject.getRealSubject();let p=clone(change?.["path"]);runUpdateAttributes(this.element,p,subject);return this}function runUpdateAttributes(container,parts,subject){if(!isArray(parts))return;parts=clone(parts);let mem=new WeakSet;while(parts.length>0){const current=parts.join(".");parts.pop();for(const[,element]of container.querySelectorAll(":scope ["+ATTRIBUTE_UPDATER_ATTRIBUTES+"*=\"path:"+current+"\"]").entries()){if(mem.has(element))continue;mem.add(element);const attributes=element.getAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES);for(let[,def]of Object.entries(attributes.split(","))){def=def.trim();let i=def.indexOf(" ");let name=def.substr(0,i).trim();let cmd=def.substr(i).trim();let value=new Pipe(cmd).run(subject);if(element.getAttribute(name)!==value){element.setAttribute(name,value)}}}}}Monster.assignToNamespace("Monster.DOM",Updater);export{Monster,Updater};
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Pathfinder}from"../data/pathfinder.js";import{Pipe}from"../data/pipe.js";import{Base,Monster}from"../types/base.js";import{getGlobalFunction}from"../types/global.js";import{isInstance,isArray}from"../types/is.js";import{Observer}from"../types/observer.js";import{ProxyObserver}from"../types/proxyobserver.js";import{validateInstance}from"../types/validate.js";import{clone}from"../util/clone.js";import{Diff}from"../data/diff.js";import{ATTRIBUTE_UPDATER_REPLACE,ATTRIBUTE_UPDATER_ATTRIBUTES,ATTRIBUTE_UPDATER_INSERT,ATTRIBUTE_UPDATER_REMOVE,ATTRIBUTE_UPDATER_INSERT_REFERENCE,ATTRIBUTE_UPDATER_BIND}from"../dom/constants.js";import{getDocument}from"./util.js";class Updater extends Base{constructor(element,subject){super();this.element=validateInstance(element,HTMLElement);if(subject===undefined)subject={};if(!isInstance(subject,ProxyObserver)){subject=new ProxyObserver(subject)}this.last={};this.callbacks=new Map;this.callbacks.set("checkstate",getCheckStateCallback.call(this));this.subject=subject.attachObserver(new Observer(()=>{const s=this.subject.getRealSubject();const diff=Diff(this.last,s);this.last=clone(s);for(const[,change]of Object.entries(diff)){removeElement.call(this,change);insertElement.call(this,change);updateContent.call(this,change);updateAttributes.call(this,change)}}));this.eventTypes=["keyup","click","change","drop","touchend"]}setEventTypes(types){this.eventTypes=validateArray(types);return this}enableEventProcessing(){this.disableEventProcessing();for(const type of this.eventTypes){this.element.addEventListener(type,getControlEventHandler.call(this))}return this}disableEventProcessing(){for(const type of this.eventTypes){this.element.removeEventListener(type,getControlEventHandler.call(this))}return this}run(){this.last={"__init__":true};return this.subject.notifyObservers()}getSubject(){return this.subject.getSubject()}setCallback(name,callback){this.callbacks.set(name,callback);return this}}function getCheckStateCallback(){const self=this;return function(current){if(this instanceof HTMLInputElement){if(["radio","checkbox"].indexOf(this.type)!==-1){return this.value+""===current+""?"true":undefined}}else if(this instanceof HTMLOptionElement){if(isArray(current)&&current.indexOf(this.value)!==-1){return"true"}return undefined}}}const symbol=Symbol("EventHandler");function getControlEventHandler(){const self=this;if(self[symbol]){return self[symbol]}const pathfinder=new Pathfinder(this.subject.getSubject());self[symbol]=event=>{const element=event.target;if(!element.hasAttribute(ATTRIBUTE_UPDATER_BIND)){return}let path=element.getAttribute(ATTRIBUTE_UPDATER_BIND);if(path.indexOf("path:")!==0){throw new Error}path=path.substr(5);let value;if(element instanceof HTMLInputElement){switch(element.type){case"checkbox":value=element.checked?element.value:undefined;break;default:value=element.value;break;}}else if(element instanceof HTMLSelectElement){switch(element.type){case"select-one":value=element.value;break;case"select-multiple":value=element.value;let options=element.querySelectorAll(":scope option:checked");value=Array.from(options).map(({value})=>value);break;}}else{throw new Error}const copy=clone(self.subject.getRealSubject());const pf=new Pathfinder(copy);pf.setVia(path,value);const diff=new Diff(copy,self.subject.getRealSubject());if(diff.length>0){pathfinder.setVia(path,value)}};return self[symbol]}function removeElement(change){for(const[,element]of this.element.querySelectorAll(":scope ["+ATTRIBUTE_UPDATER_REMOVE+"]").entries()){element.parentNode.removeChild(element)}return this}function insertElement(change){const self=this;const subject=self.subject.getRealSubject();const document=getDocument();let mem=new WeakSet;let wd=0;while(true){let found=false;wd++;let p=clone(change?.["path"]);if(!isArray(p))return this;while(p.length>0){const current=p.join(".");const list=this.element.querySelectorAll(":scope ["+ATTRIBUTE_UPDATER_INSERT+"*=\"path:"+current+"\"]").entries();for(const[,containerElement]of list){if(mem.has(containerElement))continue;mem.add(containerElement);found=true;const attributes=containerElement.getAttribute(ATTRIBUTE_UPDATER_INSERT);let def=attributes.trim();let i=def.indexOf(" ");let key=def.substr(0,i).trim();let refPrefix=key+"-";let cmd=def.substr(i).trim();if(cmd.indexOf("|")>0){throw new Error("pipes are not allowed when cloning a node.")}let pipe=new Pipe(cmd);this.callbacks.forEach((f,n)=>{pipe.setCallback(n,f)});let value=pipe.run(subject);let dataPath=cmd.split(":").pop();let insertPoint;if(containerElement.hasChildNodes()){insertPoint=containerElement.lastChild}if(!isArray(value)){throw new Error("the value is not iterable")}let available=new Set;for(const[_i,obj]of Object.entries(value)){let ref=refPrefix+_i;let currentPath=dataPath+"."+_i;available.add(ref);let refElement=containerElement.querySelector("["+ATTRIBUTE_UPDATER_INSERT_REFERENCE+"=\""+ref+"\"]");if(refElement instanceof HTMLElement){insertPoint=refElement;continue}appendNewDocumentFragment(containerElement,key,ref,currentPath)}let nodes=containerElement.querySelectorAll("["+ATTRIBUTE_UPDATER_INSERT_REFERENCE+"*=\""+refPrefix+"\"]");for(const[,node]of Object.entries(nodes)){if(!available.has(node.getAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE))){containerElement.removeChild(node)}}}p.pop()}if(found===false)break;if(wd++>200){throw new Error("the maximum depth for the recursion is reached.")}}}function appendNewDocumentFragment(container,key,ref,path){let template=getDocument().querySelector("template#"+key);if(!(template instanceof HTMLTemplateElement)){throw new Error("no template was found with the specified key "+key)}let nodes=template.content.cloneNode(true);for(const[,node]of Object.entries(nodes.childNodes)){if(node instanceof HTMLElement){node.setAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE,ref);if(node.hasAttribute(ATTRIBUTE_UPDATER_REPLACE)){let value=node.getAttribute(ATTRIBUTE_UPDATER_REPLACE);node.setAttribute(ATTRIBUTE_UPDATER_REPLACE,value.replace("path:"+key,"path:"+path))}}container.appendChild(node)}}function updateContent(change){const self=this;const subject=self.subject.getRealSubject();let p=clone(change?.["path"]);runUpdateContent.call(this,this.element,p,subject);return this}function runUpdateContent(container,parts,subject){if(!isArray(parts))return;parts=clone(parts);let mem=new WeakSet;while(parts.length>0){const current=parts.join(".");parts.pop();for(const[,element]of container.querySelectorAll(":scope ["+ATTRIBUTE_UPDATER_REPLACE+"^=\"path:"+current+"\"], ["+ATTRIBUTE_UPDATER_REPLACE+"^=\"static:\"]").entries()){if(mem.has(element))continue;mem.add(element);const attributes=element.getAttribute(ATTRIBUTE_UPDATER_REPLACE);let cmd=attributes.trim();let pipe=new Pipe(cmd);this.callbacks.forEach((f,n)=>{pipe.setCallback(n,f)});let value=pipe.run(subject);if(value instanceof HTMLElement){while(element.firstChild){element.removeChild(element.firstChild)}element.addNode(value)}else{element.innerHTML=value}}}}function updateAttributes(change){const subject=this.subject.getRealSubject();let p=clone(change?.["path"]);runUpdateAttributes.call(this,this.element,p,subject);return this}function runUpdateAttributes(container,parts,subject){const self=this;if(!isArray(parts))return;parts=clone(parts);let mem=new WeakSet;while(parts.length>0){const current=parts.join(".");parts.pop();for(const[,element]of container.querySelectorAll(":scope ["+ATTRIBUTE_UPDATER_ATTRIBUTES+"*=\"path:"+current+"\"]").entries()){if(mem.has(element))continue;mem.add(element);const attributes=element.getAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES);for(let[,def]of Object.entries(attributes.split(","))){def=def.trim();let i=def.indexOf(" ");let name=def.substr(0,i).trim();let cmd=def.substr(i).trim();let pipe=new Pipe(cmd);self.callbacks.forEach((f,n)=>{pipe.setCallback(n,f,element)});let value=pipe.run(subject);if(value===undefined){element.removeAttribute(name)}else if(element.getAttribute(name)!==value){element.setAttribute(name,value)}handleInputControlAttributeUpdate.call(this,element,name,value)}}}}function handleInputControlAttributeUpdate(element,name,value){const self=this;if(element instanceof HTMLElement){switch(element.type){case"text":if(name==="value"){element.value=value===undefined?"":value}break;case"radio":if(name==="checked"&&value!==undefined){element.checked=true}else{element.checked=false}break;case"checkbox":break;default:if(name==="value"&&value!==undefined){element.value=value}break;}}}Monster.assignToNamespace("Monster.DOM",Updater);export{Monster,Updater};
/** Monster 1.8.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.9.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,getGlobal}from"../types/global.js";import{validateString}from"../types/validate.js";function getDocument(){let document=getGlobal()?.["document"];if(typeof document!=="object"){throw new Error("not supported environment")}return document}function getWindow(){let window=getGlobal()?.["window"];if(typeof window!=="object"){throw new Error("not supported environment")}return window}function getDocumentFragmentFromString(html){validateString(html);const document=getDocument();const template=document.createElement("template");template.innerHTML=html;return template.content}Monster.assignToNamespace("Monster.DOM",getWindow,getDocument,getDocumentFragmentFromString);export{Monster,getWindow,getDocument,getDocumentFragmentFromString};