Skip to content
Snippets Groups Projects
Verified Commit 81bf2d6f authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

#116

parent c3049ee8
No related branches found
No related tags found
No related merge requests found
Showing
with 20 additions and 20 deletions
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{extend}from"../../../data/extend.js";import{assignToNamespace,Monster}from"../../../namespace.js";import{Link}from"../link.js";class Stylesheet extends Link{get defaults(){return extend({},super.defaults,{rel:"stylesheet"})}}assignToNamespace("Monster.DOM.Resource.Link",Stylesheet);export{Monster,Stylesheet};
\ No newline at end of file
'use strict';import{extend}from"../../../data/extend.js";import{assignToNamespace,Monster}from"../../../namespace.js";import{Link}from"../link.js";class Stylesheet extends Link{get defaults(){return extend({},super.defaults,{rel:"stylesheet"})}}assignToNamespace("Monster.DOM.Resource.Link",Stylesheet);export{Monster,Stylesheet};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{extend}from"../../data/extend.js";import{assignToNamespace,Monster}from"../../namespace.js";import{ATTRIBUTE_CLASS,ATTRIBUTE_ID,ATTRIBUTE_NONCE,ATTRIBUTE_SRC,ATTRIBUTE_TITLE,ATTRIBUTE_TYPE,TAG_SCRIPT}from"../constants.js";import{KEY_DOCUMENT,referenceSymbol,Resource}from"../resource.js";class Script extends Resource{get defaults(){return extend({},super.defaults,{async:!0,crossOrigin:"anonymous",defer:!1,integrity:void 0,nomodule:!1,nonce:void 0,referrerpolicy:void 0,type:"text/javascript"})}create(){return createElement.call(this),this}static getURLAttribute(){return ATTRIBUTE_SRC}}function createElement(){var e,r=this;const t=r.getOption(KEY_DOCUMENT);r[referenceSymbol]=t.createElement(TAG_SCRIPT);for(e of["crossOrigin","defer","async","integrity","nomodule",ATTRIBUTE_NONCE,"referrerpolicy",ATTRIBUTE_TYPE,ATTRIBUTE_SRC,ATTRIBUTE_ID,ATTRIBUTE_CLASS,ATTRIBUTE_TITLE])void 0!==r.getOption(e)&&(r[referenceSymbol][e]=r.getOption(e));return r}assignToNamespace("Monster.DOM.Resource",Script);export{Monster,Script};
\ No newline at end of file
'use strict';import{extend}from"../../data/extend.js";import{assignToNamespace,Monster}from"../../namespace.js";import{ATTRIBUTE_CLASS,ATTRIBUTE_ID,ATTRIBUTE_NONCE,ATTRIBUTE_SRC,ATTRIBUTE_TITLE,ATTRIBUTE_TYPE,TAG_SCRIPT}from"../constants.js";import{KEY_DOCUMENT,referenceSymbol,Resource}from"../resource.js";class Script extends Resource{get defaults(){return extend({},super.defaults,{async:true,crossOrigin:"anonymous",defer:false,integrity:undefined,nomodule:false,nonce:undefined,referrerpolicy:undefined,type:"text/javascript"})}create(){createElement.call(this);return this}static getURLAttribute(){return ATTRIBUTE_SRC}}function createElement(){const self=this;const document=self.getOption(KEY_DOCUMENT);self[referenceSymbol]=document.createElement(TAG_SCRIPT);for(let key of["crossOrigin","defer","async","integrity","nomodule",ATTRIBUTE_NONCE,"referrerpolicy",ATTRIBUTE_TYPE,ATTRIBUTE_SRC,ATTRIBUTE_ID,ATTRIBUTE_CLASS,ATTRIBUTE_TITLE]){if(self.getOption(key)!==undefined){self[referenceSymbol][key]=self.getOption(key)}}return self}assignToNamespace("Monster.DOM.Resource",Script);export{Monster,Script};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{extend}from"../data/extend.js";import{assignToNamespace,Monster}from"../namespace.js";import{BaseWithOptions}from"../types/basewithoptions.js";import{getGlobalObject}from"../types/global.js";import{isArray}from"../types/is.js";import{ATTRIBUTE_HREF,ATTRIBUTE_SRC}from"./constants.js";import{Resource}from"./resource.js";import{Data}from"./resource/data.js";import{Stylesheet}from"./resource/link/stylesheet.js";import{Script}from"./resource/script.js";class ResourceManager extends BaseWithOptions{constructor(e){if(super(e),!(this.getOption("document")instanceof Document))throw new Error("unsupported document type")}getBaseURL(){this.getOption("document")?.baseURL}get defaults(){return Object.assign({},super.defaults,{document:getGlobalObject("document"),resources:{scripts:[],stylesheets:[],data:[]}})}connect(){return runResourceMethod.call(this,"connect"),this}available(){return Promise.all(runResourceMethod.call(this,"available"))}addScript(e,t){return addResource.call(this,"scripts",e,t)}addStylesheet(e,t){return addResource.call(this,"stylesheets",e,t)}addData(e,t){return addResource.call(this,"data",e,t)}}function runResourceMethod(e){const t=[];for(const r of["scripts","stylesheets","data"]){var s=this.getOption("resources."+r);if(isArray(s))for(const o of s){if(!(o instanceof Resource))throw new Error("unsupported resource definition");t.push(o[e]())}}return t}function addResource(e,t,s){t instanceof URL&&(t=t.toString()),s=s||{};let r;switch(e){case"scripts":r=new Script(extend({},s,{[ATTRIBUTE_SRC]:t}));break;case"stylesheets":r=new Stylesheet(extend({},s,{[ATTRIBUTE_HREF]:t}));break;case"data":r=new Data(extend({},s,{[ATTRIBUTE_SRC]:t}));break;default:throw new Error("unsupported type "+e)}return(this.getOption("resources")?.[e]).push(r),this}assignToNamespace("Monster.DOM",ResourceManager);export{Monster,ResourceManager};
\ No newline at end of file
'use strict';import{extend}from"../data/extend.js";import{assignToNamespace,Monster}from"../namespace.js";import{BaseWithOptions}from"../types/basewithoptions.js";import{getGlobalObject}from"../types/global.js";import{isArray}from"../types/is.js";import{ATTRIBUTE_HREF,ATTRIBUTE_SRC}from"./constants.js";import{Resource}from"./resource.js";import{Data}from"./resource/data.js";import{Stylesheet}from"./resource/link/stylesheet.js";import{Script}from"./resource/script.js";class ResourceManager extends BaseWithOptions{constructor(options){super(options);if(!(this.getOption("document")instanceof Document)){throw new Error("unsupported document type")}}getBaseURL(){this.getOption("document")?.baseURL}get defaults(){return Object.assign({},super.defaults,{document:getGlobalObject("document"),resources:{scripts:[],stylesheets:[],data:[]}})}connect(){runResourceMethod.call(this,"connect");return this}available(){return Promise.all(runResourceMethod.call(this,"available"))}addScript(url,options){return addResource.call(this,"scripts",url,options)}addStylesheet(url,options){return addResource.call(this,"stylesheets",url,options)}addData(url,options){return addResource.call(this,"data",url,options)}}function runResourceMethod(method){const self=this;const result=[];for(const type of["scripts","stylesheets","data"]){const resources=self.getOption("resources."+type);if(!isArray(resources)){continue}for(const resource of resources){if(!(resource instanceof Resource)){throw new Error("unsupported resource definition")}result.push(resource[method]())}}return result}function addResource(type,url,options){const self=this;if(url instanceof URL){url=url.toString()}options=options||{};let resource;switch(type){case"scripts":resource=new Script(extend({},options,{[ATTRIBUTE_SRC]:url}));break;case"stylesheets":resource=new Stylesheet(extend({},options,{[ATTRIBUTE_HREF]:url}));break;case"data":resource=new Data(extend({},options,{[ATTRIBUTE_SRC]:url}));break;default:throw new Error("unsupported type "+type);}(self.getOption("resources")?.[type]).push(resource);return self}assignToNamespace("Monster.DOM",ResourceManager);export{Monster,ResourceManager};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{getGlobalFunction,getGlobalObject}from"../types/global.js";import{validateInstance,validateString}from"../types/validate.js";import{ATTRIBUTE_TEMPLATE_PREFIX}from"./constants.js";import{getDocumentTheme}from"./theme.js";class Template extends Base{constructor(e){super();var t=getGlobalFunction("HTMLTemplateElement");validateInstance(e,t),this.template=e}getTemplateElement(){return this.template}createDocumentFragment(){return this.template.content.cloneNode(!0)}}function findDocumentTemplate(e,t){validateString(e);const n=getGlobalObject("document");var a=getGlobalFunction("HTMLTemplateElement"),o=getGlobalFunction("DocumentFragment"),m=getGlobalFunction("Document");let l;t instanceof m||t instanceof o||(t instanceof Node&&(t.hasAttribute(ATTRIBUTE_TEMPLATE_PREFIX)&&(l=t.getAttribute(ATTRIBUTE_TEMPLATE_PREFIX)),(t=t.getRootNode())instanceof m||t instanceof o||(t=t.ownerDocument)),t instanceof m||t instanceof o||(t=n));let s,i=getDocumentTheme();if(l){m=l+"-"+e+"-"+i.getName();if(s=t.getElementById(m),s instanceof a)return new Template(s);if(s=n.getElementById(m),s instanceof a)return new Template(s)}o=e+"-"+i.getName();if(s=t.getElementById(o),s instanceof a)return new Template(s);if(s=n.getElementById(o),s instanceof a)return new Template(s);if(s=t.getElementById(e),s instanceof a)return new Template(s);if(s=n.getElementById(e),s instanceof a)return new Template(s);throw new Error("template "+e+" not found.")}assignToNamespace("Monster.DOM",Template,findDocumentTemplate);export{Monster,Template,findDocumentTemplate};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{getGlobalFunction,getGlobalObject}from"../types/global.js";import{validateInstance,validateString}from"../types/validate.js";import{ATTRIBUTE_TEMPLATE_PREFIX}from"./constants.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,currentNode){validateString(id);const document=getGlobalObject("document");const HTMLTemplateElement=getGlobalFunction("HTMLTemplateElement");const DocumentFragment=getGlobalFunction("DocumentFragment");const Document=getGlobalFunction("Document");let prefixID;if(!(currentNode instanceof Document||currentNode instanceof DocumentFragment)){if(currentNode instanceof Node){if(currentNode.hasAttribute(ATTRIBUTE_TEMPLATE_PREFIX)){prefixID=currentNode.getAttribute(ATTRIBUTE_TEMPLATE_PREFIX)}currentNode=currentNode.getRootNode();if(!(currentNode instanceof Document||currentNode instanceof DocumentFragment)){currentNode=currentNode.ownerDocument}}if(!(currentNode instanceof Document||currentNode instanceof DocumentFragment)){currentNode=document}}let template;let theme=getDocumentTheme();if(prefixID){let themedPrefixID=prefixID+"-"+id+"-"+theme.getName();template=currentNode.getElementById(themedPrefixID);if(template instanceof HTMLTemplateElement){return new Template(template)}template=document.getElementById(themedPrefixID);if(template instanceof HTMLTemplateElement){return new Template(template)}}let themedID=id+"-"+theme.getName();template=currentNode.getElementById(themedID);if(template instanceof HTMLTemplateElement){return new Template(template)}template=document.getElementById(themedID);if(template instanceof HTMLTemplateElement){return new Template(template)}template=currentNode.getElementById(id);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.")}assignToNamespace("Monster.DOM",Template,findDocumentTemplate);export{Monster,Template,findDocumentTemplate};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{getGlobalObject}from"../types/global.js";import{validateString}from"../types/validate.js";import{ATTRIBUTE_THEME_NAME,DEFAULT_THEME}from"./constants.js";class Theme extends Base{constructor(e){super(),validateString(e),this.name=e}getName(){return this.name}}function getDocumentTheme(){let e=getGlobalObject("document"),t=DEFAULT_THEME,s=e.querySelector("html");var m;return s instanceof HTMLElement&&((m=s.getAttribute(ATTRIBUTE_THEME_NAME))&&(t=m)),new Theme(t)}assignToNamespace("Monster.DOM",Theme,getDocumentTheme);export{Monster,Theme,getDocumentTheme};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{getGlobalObject}from"../types/global.js";import{validateString}from"../types/validate.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)}assignToNamespace("Monster.DOM",Theme,getDocumentTheme);export{Monster,Theme,getDocumentTheme};
This diff is collapsed.
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{getGlobal}from"../types/global.js";import{validateString}from"../types/validate.js";function getDocument(){var t=getGlobal()?.document;if("object"!=typeof t)throw new Error("not supported environment");return t}function getWindow(){var t=getGlobal()?.window;if("object"!=typeof t)throw new Error("not supported environment");return t}function getDocumentFragmentFromString(t){validateString(t);const e=getDocument(),n=e.createElement("template");return n.innerHTML=t,n.content}assignToNamespace("Monster.DOM",getWindow,getDocument,getDocumentFragmentFromString);export{Monster,getWindow,getDocument,getDocumentFragmentFromString};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{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}assignToNamespace("Monster.DOM",getWindow,getDocument,getDocumentFragmentFromString);export{Monster,getWindow,getDocument,getDocumentFragmentFromString};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{internalSymbol}from"../../constants.js";import{assignToNamespace,Monster}from"../../namespace.js";import{Base}from"../../types/base.js";import{getGlobal,getGlobalFunction}from"../../types/global.js";import{isFunction}from"../../types/is.js";import{validateInstance,validateString}from"../../types/validate.js";class Factory extends Base{constructor(){super(),this[internalSymbol]={worker:new WeakMap}}createFromURL=function(t,e,r){t instanceof URL&&(t=t.toString());const o=getGlobalFunction("Worker");var n=new o(validateString(t));return isFunction(e)&&(n.onmessage=t=>{e.call(n,t)}),isFunction(r)&&(n.onerror=t=>{r.call(n,t)}),n};createFromScript=function(t,e,r){const o=new getGlobalFunction("Blob");t=new o([validateString(t)],{type:"script/javascript"}),t=getGlobalFunction("URL").createObjectURL(t),e=this.createFromURL(t,e,r);return this[internalSymbol].worker.set(e,t),e};terminate(t){var e=getGlobalFunction("Worker");return validateInstance(t,e),t.terminate(),this[internalSymbol].worker.has(t)&&(e=this[internalSymbol].worker.get(t),URL.revokeObjectURL(e)),this}}assignToNamespace("Monster.DOM.Worker",Factory);export{Monster,Factory};
\ No newline at end of file
'use strict';import{internalSymbol}from"../../constants.js";import{assignToNamespace,Monster}from"../../namespace.js";import{Base}from"../../types/base.js";import{getGlobal,getGlobalFunction}from"../../types/global.js";import{isFunction}from"../../types/is.js";import{validateInstance,validateString}from"../../types/validate.js";class Factory extends Base{constructor(){super();this[internalSymbol]={worker:new WeakMap}}createFromURL=function(url,messageHandler,errorHandler){if(url instanceof URL){url=url.toString()}const workerClass=getGlobalFunction("Worker");var worker=new workerClass(validateString(url));if(isFunction(messageHandler)){worker.onmessage=event=>{messageHandler.call(worker,event)}}if(isFunction(errorHandler)){worker.onerror=event=>{errorHandler.call(worker,event)}}return worker};createFromScript=function(content,messageHandler,errorHandler){const blobFunction=new getGlobalFunction("Blob");const blob=new blobFunction([validateString(content)],{type:"script/javascript"});const url=getGlobalFunction("URL").createObjectURL(blob);const worker=this.createFromURL(url,messageHandler,errorHandler);this[internalSymbol]["worker"].set(worker,url);return worker};terminate(worker){const workerClass=getGlobalFunction("Worker");validateInstance(worker,workerClass);worker.terminate();if(this[internalSymbol]["worker"].has(worker)){const url=this[internalSymbol]["worker"].get(worker);URL.revokeObjectURL(url)}return this}}assignToNamespace("Monster.DOM.Worker",Factory);export{Monster,Factory};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{internalSymbol}from"../constants.js";import{extend}from"../data/extend.js";import{assignToNamespace,Monster}from"../namespace.js";import{Formatter as TextFormatter}from"../text/formatter.js";import{validateInstance,validateString}from"../types/validate.js";import{Translations}from"./translations.js";const internalTranslationSymbol=Symbol("internalTranslation");class Formatter extends TextFormatter{constructor(t,r,e){super(t,e),this[internalTranslationSymbol]=validateInstance(r,Translations)}get defaults(){const r=this;return extend({},super.defaults,{callbacks:{i18n:t=>r[internalTranslationSymbol].getText(validateString(t))},marker:{open:["i18n{","${"],close:["}"]}})}format(t){validateString(t);var r=this[internalSymbol].marker.open?.[0],e=this[internalSymbol].marker.close?.[0];if(0===t.indexOf(r)){if((t=t.substring(r.length)).indexOf(e)!==t.length-e.length)throw new Error("the closing marker is missing");t=t.substring(0,t.length-e.length)}const n=validateString(t).split("::");var t=n.shift().trim(),a=n.join("::").trim();let s=r+"static:"+t+" | call:i18n";return 0<a.length&&(s+="::"+a),s+=e,super.format(s)}}assignToNamespace("Monster.I18n",Formatter);export{Monster,Formatter};
\ No newline at end of file
'use strict';import{internalSymbol}from"../constants.js";import{extend}from"../data/extend.js";import{assignToNamespace,Monster}from"../namespace.js";import{Formatter as TextFormatter}from"../text/formatter.js";import{validateInstance,validateString}from"../types/validate.js";import{Translations}from"./translations.js";const internalTranslationSymbol=Symbol("internalTranslation");class Formatter extends TextFormatter{constructor(object,translation,options){super(object,options);this[internalTranslationSymbol]=validateInstance(translation,Translations)}get defaults(){const self=this;return extend({},super.defaults,{callbacks:{i18n:value=>{return self[internalTranslationSymbol].getText(validateString(value))}},marker:{open:["i18n{","${"],close:["}"]}})}format(text){validateString(text);const openMarker=this[internalSymbol]["marker"]["open"]?.[0];const closeMarker=this[internalSymbol]["marker"]["close"]?.[0];if(text.indexOf(openMarker)===0){text=text.substring(openMarker.length);if(text.indexOf(closeMarker)===text.length-closeMarker.length){text=text.substring(0,text.length-closeMarker.length)}else{throw new Error("the closing marker is missing")}}const parts=validateString(text).split("::");const translationKey=parts.shift().trim();const parameter=parts.join("::").trim();let assembledText=openMarker+"static:"+translationKey+" | call:i18n";if(parameter.length>0){assembledText+="::"+parameter}assembledText+=closeMarker;return super.format(assembledText)}}assignToNamespace("Monster.I18n",Formatter);export{Monster,Formatter};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateString}from"../types/validate.js";import{clone}from"../util/clone.js";const propertiesSymbol=Symbol("properties"),localeStringSymbol=Symbol("localeString");class Locale extends Base{constructor(e,i,t,o,a,r){super(),this[propertiesSymbol]={language:void 0===e?void 0:validateString(e),script:void 0===t?void 0:validateString(t),region:void 0===i?void 0:validateString(i),variants:void 0===o?void 0:validateString(o),extlang:void 0===a?void 0:validateString(a),privateUse:void 0===r?void 0:validateString(r)};let n=[];if(void 0!==e&&n.push(e),void 0!==t&&n.push(t),void 0!==i&&n.push(i),void 0!==o&&n.push(o),void 0!==a&&n.push(a),void 0!==r&&n.push(r),0===n.length)throw new Error("unsupported locale");this[localeStringSymbol]=n.join("-")}get localeString(){return this[localeStringSymbol]}get language(){return this[propertiesSymbol].language}get region(){return this[propertiesSymbol].region}get script(){return this[propertiesSymbol].script}get variants(){return this[propertiesSymbol].variants}get extlang(){return this[propertiesSymbol].extlang}get privateUse(){return this[propertiesSymbol].privateValue}toString(){return""+this.localeString}getMap(){return clone(this[propertiesSymbol])}}function parseLocale(e){e=validateString(e).replace(/_/g,"-");let i,t,o,a,r,n,l=new RegExp("^(((en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((([A-Za-z]{2,3}(-([A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-([A-Za-z]{4}))?(-([A-Za-z]{2}|[0-9]{3}))?(-([A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-([0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(x(-[A-Za-z0-9]{1,8})+))?)|(x(-[A-Za-z0-9]{1,8})+))$"),s;if(null!==(s=l.exec(e))&&s.index===l.lastIndex&&l.lastIndex++,null==s)throw new Error("unsupported locale");return void 0!==s[6]&&(i=s[6],1<(a=i.split("-")).length&&(i=a[0],n=a[1])),void 0!==s[14]&&(t=s[14]),void 0!==s[12]&&(r=s[12]),void 0!==s[16]&&(o=s[16]),new Locale(i,t,r,o,n)}assignToNamespace("Monster.I18n",Locale,parseLocale);export{Monster,Locale,parseLocale};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateString}from"../types/validate.js";import{clone}from"../util/clone.js";const propertiesSymbol=Symbol("properties");const localeStringSymbol=Symbol("localeString");class Locale extends Base{constructor(language,region,script,variants,extlang,privateUse){super();this[propertiesSymbol]={language:language===undefined?undefined:validateString(language),script:script===undefined?undefined:validateString(script),region:region===undefined?undefined:validateString(region),variants:variants===undefined?undefined:validateString(variants),extlang:extlang===undefined?undefined:validateString(extlang),privateUse:privateUse===undefined?undefined:validateString(privateUse)};let s=[];if(language!==undefined)s.push(language);if(script!==undefined)s.push(script);if(region!==undefined)s.push(region);if(variants!==undefined)s.push(variants);if(extlang!==undefined)s.push(extlang);if(privateUse!==undefined)s.push(privateUse);if(s.length===0){throw new Error("unsupported locale")}this[localeStringSymbol]=s.join("-")}get localeString(){return this[localeStringSymbol]}get language(){return this[propertiesSymbol].language}get region(){return this[propertiesSymbol].region}get script(){return this[propertiesSymbol].script}get variants(){return this[propertiesSymbol].variants}get extlang(){return this[propertiesSymbol].extlang}get privateUse(){return this[propertiesSymbol].privateValue}toString(){return""+this.localeString}getMap(){return clone(this[propertiesSymbol])}}function parseLocale(locale){locale=validateString(locale).replace(/_/g,"-");let language,region,variants,parts,script,extlang,regexRegular="(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)",regexIrregular="(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)",regexGrandfathered="("+regexIrregular+"|"+regexRegular+")",regexPrivateUse="(x(-[A-Za-z0-9]{1,8})+)",regexSingleton="[0-9A-WY-Za-wy-z]",regexExtension="("+regexSingleton+"(-[A-Za-z0-9]{2,8})+)",regexVariant="([A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3})",regexRegion="([A-Za-z]{2}|[0-9]{3})",regexScript="([A-Za-z]{4})",regexExtlang="([A-Za-z]{3}(-[A-Za-z]{3}){0,2})",regexLanguage="(([A-Za-z]{2,3}(-"+regexExtlang+")?)|[A-Za-z]{4}|[A-Za-z]{5,8})",regexLangtag="("+regexLanguage+"(-"+regexScript+")?"+"(-"+regexRegion+")?"+"(-"+regexVariant+")*"+"(-"+regexExtension+")*"+"(-"+regexPrivateUse+")?"+")",regexLanguageTag="^("+regexGrandfathered+"|"+regexLangtag+"|"+regexPrivateUse+")$",regex=new RegExp(regexLanguageTag),match;if((match=regex.exec(locale))!==null){if(match.index===regex.lastIndex){regex.lastIndex++}}if(match===undefined||match===null){throw new Error("unsupported locale")}if(match[6]!==undefined){language=match[6];parts=language.split("-");if(parts.length>1){language=parts[0];extlang=parts[1]}}if(match[14]!==undefined){region=match[14]}if(match[12]!==undefined){script=match[12]}if(match[16]!==undefined){variants=match[16]}return new Locale(language,region,script,variants,extlang)}assignToNamespace("Monster.I18n",Locale,parseLocale);export{Monster,Locale,parseLocale};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";const namespace="Monster.I18n";export{namespace};
\ No newline at end of file
'use strict';export const namespace="Monster.I18n";
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{BaseWithOptions}from"../types/basewithoptions.js";import{Locale}from"./locale.js";import{Translations}from"./translations.js";class Provider extends BaseWithOptions{getTranslations(e){return new Promise((s,o)=>{try{s(new Translations(e))}catch(s){o(s)}})}}assignToNamespace("Monster.I18n",Provider);export{Monster,Provider};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{BaseWithOptions}from"../types/basewithoptions.js";import{Locale}from"./locale.js";import{Translations}from"./translations.js";class Provider extends BaseWithOptions{getTranslations(locale){return new Promise((resolve,reject)=>{try{resolve(new Translations(locale))}catch(e){reject(e)}})}}assignToNamespace("Monster.I18n",Provider);export{Monster,Provider};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{internalSymbol}from"../../constants.js";import{extend}from"../../data/extend.js";import{assignToNamespace,Monster}from"../../namespace.js";import{Formatter}from"../../text/formatter.js";import{getGlobalFunction}from"../../types/global.js";import{isInstance,isString}from"../../types/is.js";import{validateObject,validateString}from"../../types/validate.js";import{parseLocale}from"../locale.js";import{Provider}from"../provider.js";import{Translations}from"../translations.js";class Fetch extends Provider{constructor(t,e){super(e),isInstance(t,URL)&&(t=t.toString()),void 0===e&&(e={}),validateString(t),this.url=t,this[internalSymbol]=extend({},super.defaults,this.defaults,validateObject(e))}get defaults(){return{fetch:{method:"GET",mode:"cors",cache:"no-cache",credentials:"omit",redirect:"follow",referrerPolicy:"no-referrer"}}}getTranslations(e){isString(e)&&(e=parseLocale(e));let t=new Formatter(e.getMap());return getGlobalFunction("fetch")(t.format(this.url),this.getOption("fetch",{})).then(t=>t.json()).then(t=>new Translations(e).assignTranslations(t))}}assignToNamespace("Monster.I18n.Providers",Fetch);export{Monster,Fetch};
\ No newline at end of file
'use strict';import{internalSymbol}from"../../constants.js";import{extend}from"../../data/extend.js";import{assignToNamespace,Monster}from"../../namespace.js";import{Formatter}from"../../text/formatter.js";import{getGlobalFunction}from"../../types/global.js";import{isInstance,isString}from"../../types/is.js";import{validateObject,validateString}from"../../types/validate.js";import{parseLocale}from"../locale.js";import{Provider}from"../provider.js";import{Translations}from"../translations.js";class Fetch extends Provider{constructor(url,options){super(options);if(isInstance(url,URL)){url=url.toString()}if(options===undefined){options={}}validateString(url);this.url=url;this[internalSymbol]=extend({},super.defaults,this.defaults,validateObject(options))}get defaults(){return{fetch:{method:"GET",mode:"cors",cache:"no-cache",credentials:"omit",redirect:"follow",referrerPolicy:"no-referrer"}}}getTranslations(locale){if(isString(locale)){locale=parseLocale(locale)}let formatter=new Formatter(locale.getMap());return getGlobalFunction("fetch")(formatter.format(this.url),this.getOption("fetch",{})).then(response=>response.json()).then(data=>{return new Translations(locale).assignTranslations(data)})}}assignToNamespace("Monster.I18n.Providers",Fetch);export{Monster,Fetch};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";const namespace="Monster.I18n.Providers";export{namespace};
\ No newline at end of file
'use strict';export const namespace="Monster.I18n.Providers";
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{isObject,isString}from"../types/is.js";import{validateInstance,validateInteger,validateObject,validateString}from"../types/validate.js";import{Locale,parseLocale}from"./locale.js";class Translations extends Base{constructor(t){super(),isString(t)&&(t=parseLocale(t)),this.locale=validateInstance(t,Locale),this.storage=new Map}getText(t,e){if(!this.storage.has(t)){if(void 0===e)throw new Error("key "+t+" not found");return validateString(e)}var r=this.storage.get(t);return isObject(r)?this.getPluralRuleText(t,"other",e):this.storage.get(t)}getPluralRuleText(t,e,r){if(!this.storage.has(t))return validateString(r);let a=validateObject(this.storage.get(t)),s;if(isString(e))s=e.toLocaleString();else{if(0===(e=validateInteger(e))&&a.hasOwnProperty("zero"))return validateString(a.zero);s=new Intl.PluralRules(this.locale.toString()).select(validateInteger(e))}return a.hasOwnProperty(s)?validateString(a[s]):a.hasOwnProperty(DEFAULT_KEY)?validateString(a[DEFAULT_KEY]):validateString(r)}setText(t,e){if(isString(e)||isObject(e))return this.storage.set(validateString(t),e),this;throw new TypeError("value is not a string or object")}assignTranslations(t){validateObject(t);for(var[e,r]of Object.entries(t))this.setText(e,r);return this}}assignToNamespace("Monster.I18n",Translations);export{Monster,Translations};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{isObject,isString}from"../types/is.js";import{validateInstance,validateInteger,validateObject,validateString}from"../types/validate.js";import{Locale,parseLocale}from"./locale.js";class Translations extends Base{constructor(locale){super();if(isString(locale)){locale=parseLocale(locale)}this.locale=validateInstance(locale,Locale);this.storage=new Map}getText(key,defaultText){if(!this.storage.has(key)){if(defaultText===undefined){throw new Error("key "+key+" not found")}return validateString(defaultText)}let r=this.storage.get(key);if(isObject(r)){return this.getPluralRuleText(key,"other",defaultText)}return this.storage.get(key)}getPluralRuleText(key,count,defaultText){if(!this.storage.has(key)){return validateString(defaultText)}let r=validateObject(this.storage.get(key));let keyword;if(isString(count)){keyword=count.toLocaleString()}else{count=validateInteger(count);if(count===0){if(r.hasOwnProperty("zero")){return validateString(r["zero"])}}keyword=new Intl.PluralRules(this.locale.toString()).select(validateInteger(count))}if(r.hasOwnProperty(keyword)){return validateString(r[keyword])}if(r.hasOwnProperty(DEFAULT_KEY)){return validateString(r[DEFAULT_KEY])}return validateString(defaultText)}setText(key,text){if(isString(text)||isObject(text)){this.storage.set(validateString(key),text);return this}throw new TypeError("value is not a string or object")}assignTranslations(translations){validateObject(translations);for(const[k,v]of Object.entries(translations)){this.setText(k,v)}return this}}assignToNamespace("Monster.I18n",Translations);export{Monster,Translations};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateInstance,validateInteger}from"../types/validate.js";import{LogEntry}from"./logentry.js";import{ALL,DEBUG,ERROR,FATAL,INFO,OFF,TRACE,WARN}from"./logger.js";class Handler extends Base{constructor(){super(),this.loglevel=OFF}log(e){return validateInstance(e,LogEntry),!(this.loglevel<e.getLogLevel())}setLogLevel(e){return validateInteger(e),this.loglevel=e,this}getLogLevel(){return this.loglevel}setAll(){return this.setLogLevel(ALL),this}setTrace(){return this.setLogLevel(TRACE),this}setDebug(){return this.setLogLevel(DEBUG),this}setInfo(){return this.setLogLevel(INFO),this}setWarn(){return this.setLogLevel(WARN),this}setError(){return this.setLogLevel(ERROR),this}setFatal(){return this.setLogLevel(FATAL),this}setOff(){return this.setLogLevel(OFF),this}}assignToNamespace("Monster.Logging",Handler);export{Monster,Handler};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateInstance,validateInteger}from"../types/validate.js";import{LogEntry}from"./logentry.js";import{ALL,DEBUG,ERROR,FATAL,INFO,OFF,TRACE,WARN}from"./logger.js";class Handler extends Base{constructor(){super();this.loglevel=OFF}log(entry){validateInstance(entry,LogEntry);if(this.loglevel<entry.getLogLevel()){return false}return true}setLogLevel(loglevel){validateInteger(loglevel);this.loglevel=loglevel;return this}getLogLevel(){return this.loglevel}setAll(){this.setLogLevel(ALL);return this}setTrace(){this.setLogLevel(TRACE);return this}setDebug(){this.setLogLevel(DEBUG);return this}setInfo(){this.setLogLevel(INFO);return this}setWarn(){this.setLogLevel(WARN);return this}setError(){this.setLogLevel(ERROR);return this}setFatal(){this.setLogLevel(FATAL);return this}setOff(){this.setLogLevel(OFF);return this}}assignToNamespace("Monster.Logging",Handler);export{Monster,Handler};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../../namespace.js";import{Base}from"../../types/base.js";import{getGlobalObject}from"../../types/global.js";import{Handler}from"../handler.js";import{LogEntry}from"../logentry.js";class ConsoleHandler extends Handler{constructor(){super()}log(o){if(super.log(o)){let e=getGlobalObject("console");return e?(e.log(o.toString()),!0):!1}return!1}}assignToNamespace("Monster.Logging.Handler",ConsoleHandler);export{Monster,ConsoleHandler};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../../namespace.js";import{Base}from"../../types/base.js";import{getGlobalObject}from"../../types/global.js";import{Handler}from"../handler.js";import{LogEntry}from"../logentry.js";class ConsoleHandler extends Handler{constructor(){super()}log(entry){if(super.log(entry)){let console=getGlobalObject("console");if(!console)return false;console.log(entry.toString());return true}return false}}assignToNamespace("Monster.Logging.Handler",ConsoleHandler);export{Monster,ConsoleHandler};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";const namespace="Monster.Logging.Handler";export{namespace};
\ No newline at end of file
'use strict';export const namespace="Monster.Logging.Handler";
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateInteger}from"../types/validate.js";class LogEntry extends Base{constructor(e,...t){super(),validateInteger(e),this.loglevel=e,this.arguments=t}getLogLevel(){return this.loglevel}getArguments(){return this.arguments}}assignToNamespace("Monster.Logging",LogEntry);export{Monster,LogEntry};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateInteger}from"../types/validate.js";class LogEntry extends Base{constructor(loglevel,...args){super();validateInteger(loglevel);this.loglevel=loglevel;this.arguments=args}getLogLevel(){return this.loglevel}getArguments(){return this.arguments}}assignToNamespace("Monster.Logging",LogEntry);export{Monster,LogEntry};
/** Monster 1.30.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{Handler}from"../logging/handler.js";import{LogEntry}from"../logging/logentry.js";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateInteger,validateObject,validateString}from"../types/validate.js";const ALL=255,TRACE=64,DEBUG=32,INFO=16,WARN=8,ERROR=4,FATAL=2,OFF=0;class Logger extends Base{constructor(){super(),this.handler=new Set}addHandler(e){if(validateObject(e),!(e instanceof Handler))throw new Error("the handler must be an instance of Handler");return this.handler.add(e),this}removeHandler(e){if(validateObject(e),!(e instanceof Handler))throw new Error("the handler must be an instance of Handler");return this.handler.delete(e),this}logTrace(){return triggerLog.apply(this,[TRACE,...arguments]),this}logDebug(){return triggerLog.apply(this,[DEBUG,...arguments]),this}logInfo(){return triggerLog.apply(this,[INFO,...arguments]),this}logWarn(){return triggerLog.apply(this,[WARN,...arguments]),this}logError(){return triggerLog.apply(this,[ERROR,...arguments]),this}logFatal(){return triggerLog.apply(this,[FATAL,...arguments]),this}getLabel(e){return validateInteger(e),e===ALL?"ALL":e===TRACE?"TRACE":e===DEBUG?"DEBUG":e===INFO?"INFO":e===WARN?"WARN":e===ERROR?"ERROR":e===FATAL?"FATAL":e===OFF?"OFF":"unknown"}getLevel(e){return validateString(e),"ALL"===e?ALL:"TRACE"===e?TRACE:"DEBUG"===e?DEBUG:"INFO"===e?INFO:"WARN"===e?WARN:"ERROR"===e?ERROR:"FATAL"===e?FATAL:"OFF"===e?OFF:0}}function triggerLog(e,...r){var t;for(t of this.handler)t.log(new LogEntry(e,r));return this}assignToNamespace("Monster.Logging",Logger);export{Monster,Logger,ALL,TRACE,DEBUG,INFO,WARN,ERROR,FATAL,OFF};
\ No newline at end of file
'use strict';import{Handler}from"../logging/handler.js";import{LogEntry}from"../logging/logentry.js";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateInteger,validateObject,validateString}from"../types/validate.js";const ALL=255;const TRACE=64;const DEBUG=32;const INFO=16;const WARN=8;const ERROR=4;const FATAL=2;const OFF=0;class Logger extends Base{constructor(){super();this.handler=new Set}addHandler(handler){validateObject(handler);if(!(handler instanceof Handler)){throw new Error("the handler must be an instance of Handler")}this.handler.add(handler);return this}removeHandler(handler){validateObject(handler);if(!(handler instanceof Handler)){throw new Error("the handler must be an instance of Handler")}this.handler.delete(handler);return this}logTrace(){triggerLog.apply(this,[TRACE,...arguments]);return this}logDebug(){triggerLog.apply(this,[DEBUG,...arguments]);return this}logInfo(){triggerLog.apply(this,[INFO,...arguments]);return this}logWarn(){triggerLog.apply(this,[WARN,...arguments]);return this}logError(){triggerLog.apply(this,[ERROR,...arguments]);return this}logFatal(){triggerLog.apply(this,[FATAL,...arguments]);return this}getLabel(level){validateInteger(level);if(level===ALL)return"ALL";if(level===TRACE)return"TRACE";if(level===DEBUG)return"DEBUG";if(level===INFO)return"INFO";if(level===WARN)return"WARN";if(level===ERROR)return"ERROR";if(level===FATAL)return"FATAL";if(level===OFF)return"OFF";return"unknown"}getLevel(label){validateString(label);if(label==="ALL")return ALL;if(label==="TRACE")return TRACE;if(label==="DEBUG")return DEBUG;if(label==="INFO")return INFO;if(label==="WARN")return WARN;if(label==="ERROR")return ERROR;if(label==="FATAL")return FATAL;if(label==="OFF")return OFF;return 0}}assignToNamespace("Monster.Logging",Logger);export{Monster,Logger,ALL,TRACE,DEBUG,INFO,WARN,ERROR,FATAL,OFF};function triggerLog(loglevel,...args){var logger=this;for(let handler of logger.handler){handler.log(new LogEntry(loglevel,args))}return logger}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment