var cx_libtranslate=(()=>{var i=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var b=i(j=>{var g=class{#e;#t;constructor(e,t=!0){if(typeof e!="string")throw new TypeError("Translated content must be string.");if(typeof t!="boolean")throw new TypeError("Result of translation must be boolean.");this.#e=e,this.#t=t,Object.freeze(this)}toString(){return this.#e}get text(){return this.#e}get valid(){return this.translated}format(e){if(typeof e!="object")throw new TypeError("Content to format from must be object.");return this.#t?this.#r(e):this.#e}#r(e){let t=this.#e.split("#{"),r=t[0];for(let s=1;s{var f=b().translation,w=class n{#e;#t;constructor(e,t=null){if(!(e instanceof Map))throw new TypeError("Phrases must an map.");if(t!==null&&typeof t!="object")throw new TypeError("Objects must be null or object.");this.#e=e,this.#t=t}translate(e){if(typeof e!="string")throw new TypeError("Phrase to translate must be an string.");return this.#r(e)?this.#s(e):this.#n(e)}get(e){return this.translate(e)}#r(e){return e.indexOf(".")!==-1}#s(e){if(this.#t===null)return this.#n(e);let t=e.trim().split("."),r=this.#t;for(let s in t){let a=t[s];if(!(a in r))return new f(e,!1);r=r[a]}return typeof r!="string"?new f(e,!1):new f(r,!0)}set_as_default(){let e=t=>this.translate(t);window._=e,window.translate=e}#n(e){let t=n.prepare(e),r=this.#e.has(t),s=r?this.#e.get(t):e;return new f(s,r)}static prepare(e){if(typeof e!="string")throw new TypeError("Content to prepare must be an string.");return e.trim().replaceAll(" ","_").replaceAll(".","_").toLowerCase()}};S.phrasebook=w});var h=i(L=>{var m=l().phrasebook,y=class{#e;#t;constructor(e,t=!1){if(typeof e!="string")throw new TypeError("Path of the file must be string.");if(typeof t!="boolean")throw new TypeError("Local must be bool variable.");this.#e=e,this.#t=t}async#r(){let t=await(await fetch(this.#e)).json();return this.#n(t)}async#s(){let e=null;if(e===null)throw new Error("Could not use ndoe:fs in browser.");let t=await e.readFile(this.#e,{encoding:"utf8"}),r=JSON.parse(t);return this.#n(r)}load(){return this.#t?this.#s():this.#r()}#n(e){let t="objects"in e&&typeof e.objects=="object",r="phrases"in e&&typeof e.phrases=="object";if(t||r){let a=r?e.phrases:{},u=t?e.objects:{};return new m(this.#o(a),u)}return new m(this.#o(e))}#o(e){let t=new Map;return Object.keys(e).forEach(r=>{let s=m.prepare(r),a=e[r];t.set(s,a)}),t}};L.loader=y});var c=i(N=>{var M=h().loader,J=l().phrasebook,E=class n{#e;#t;#r;constructor(e,t=!1){if(typeof e!="string")throw new TypeError("Path to the phrasebooks must be string.");if(typeof t!="boolean")throw new TypeError("Local must be bool variable.");this.#r=t,this.#e=e,this.#t=new Map}add(e,t){if(typeof e!="string")throw new TypeError("Name of the language must be sting.");if(typeof t!="string")throw new TypeError("File on in the directory must be string.");return this.#t.has(e)?(console.error('Language "'+e+'" already loaded.'),console.error("It could not being loaded twice."),this):this.#o(e)?(this.#t.set(e,t),this):(console.error('Language name "'+e+'" invalid formated.'),console.error("It could not being loaded."),this)}async load(e){if(typeof e!="string")throw new TypeError("Name of index file is not string.");let t=await this.#s(e),r=new n(this.#e,this.#r);return Object.keys(t).forEach(s=>{if(typeof s!="string"){console.error("Name of the language must be string."),console.error("Check languages index."),console.error("Skipping it.");return}if(typeof t[s]!="string"){console.error("Name of phrasebook file must be string."),console.error("Check languages index."),console.error("Skipping it.");return}r.add(s,t[s])}),r}async#s(e){let t=this.#n(e);if(this.#r){let s=null;if(s===null)throw new Error("Could not use ndoe:fs in browser.");return JSON.parse(await s.readFile(t,{encoding:"utf-8"}))}return await(await fetch(t)).json()}has(e){return this.#t.has(e)}get avairable(){let e=new Array;return this.#t.keys().forEach(t=>{e.push(t)}),e}get default(){let e=this.avairable;if(e.length===0)throw new Error("Languages list is empty. Can not load default.");return e[0]}select(e){if(typeof e!="string")throw new TypeError("Name of the language must be string.");if(!this.has(e))return new J(new Map);let t=this.#t.get(e),r=this.#n(t);return new M(r,this.#r).load()}#n(e){let t="/";return this.#e[this.#e.length-1]===t&&(t=""),this.#e+t+e}#o(e){let t=e.split("_");if(t.length!==2)return!1;let r=t[0],s=t[1];return!(r.toLowerCase()!==r||r.length!==2||s.toUpperCase()!==s||s.length!==2)}};N.languages=E});var p=i(O=>{var B=c().languages,q=class{#e;#t;#r;#s;constructor(e){this.#t=null,this.#e=e,this.#s=new Array,this.#r=this.#a()}get is_inserted(){return this.#t!==null}insert(e=null){return this.is_inserted?this:(e===null&&(e=document.querySelector("body")),this.#t=this.#o(),e.appendChild(this.#t),this)}#n(){this.#s.forEach(e=>{e(this.current)})}remove(){return this.is_inserted?(this.#t.remove(),this.#t=null,this):this}#o(){let e=document.createElement("div");return e.classList.add(this.class_name),e.appendChild(this.#r),e}add_listener(e){return this.#s.push(e),this}get class_name(){return"cx-libtranslate-language-selector"}#i(e){let t=e.split("_").pop(),r=document.createElement("option");return r.innerText=t,r.value=e,r}get current(){return this.#r.value}set_selection(e){return this.#e.has(e),this.#r.value=e,this}reload(){for(;this.#r.lastChild;)this.#r.lastChild.remove();return this.#e.avairable.forEach(e=>{this.#r.appendChild(this.#i(e))}),this}#a(){let e=document.createElement("select");return e.addEventListener("change",()=>{this.#n()}),this.#e.avairable.forEach(t=>{e.appendChild(this.#i(t))}),e}};O.selector=q});var d=i(A=>{var{phrasebook:K}=l(),k=class n{#e;#t;constructor(e=null){this.#t=null,this.#e=e}static get_class_name(){return"translate"}get#r(){return"."+n.get_class_name()}static get_attribute_name(){return"phrase"}get is_connected(){return this.#t!==null}#s(e=null){return e===null&&(e=document),Array.from(e.querySelectorAll(this.#r))}#n(e){return this.#e!==null?this.#e.translate(e):_===void 0?e:_(e)}connect(){if(this.is_connected)return this;let e=document.querySelector("body"),t=s=>{this.#o(s)},r={childList:!0,attributes:!0,characterData:!1,subtree:!0,attributeFilter:[n.get_attribute_name()],attributeOldValue:!1,characterDataOldValue:!1};return this.#t=new MutationObserver(t),this.#t.observe(e,r),this}#o(e){e.forEach(t=>{if(t.type==="attributes"){this.#i(t.target);return}this.#s(t.target).forEach(r=>{this.#i(r)})})}disconnect(){return this.is_connected?(this.#t.disconnect(),this.#t=null,this):this}#i(e){let t=n.get_attribute_name(),r=e.getAttribute(t),s=this.#n(r);if(e instanceof HTMLInputElement){if(e.type==="button"||e.type==="submit"){e.value=s;return}e.placeholder=s;return}if(e instanceof HTMLTextAreaElement){e.placeholder=s;return}e.innerText=s}update(){return this.#s().forEach(e=>{this.#i(e)}),this}};A.autotranslate=k});var T=i(I=>{var W=c().languages,X=l().phrasebook,F=p().selector,P=d().autotranslate,v=class{#e;#t;#r;constructor(e){this.#t=null,this.#r=null,this.#e=e}get#s(){return"cx_libtranslate_lang"}get#n(){return localStorage.getItem(this.#s)}get selector(){return this.#t!==null?this.#t:(this.#t=new F(this.#e).set_selection(this.current).add_listener(e=>{this.update(e)}).add_listener(async e=>{this.#r!==null&&this.#o()}),this.#t)}async#o(){let e=this.#r.is_connected;e&&this.#r.disconnect(),this.#r=null;let t=await this.get_autotranslate();e&&t.connect()}async get_autotranslate(){if(this.#r!==null)return this.#r;let e=await this.load_choosen_phrasebook();return this.#r=new P(e),this.#r.update(),this.#r}set#n(e){if(e===null){localStorage.removeItem(this.#s);return}localStorage.setItem(this.#s,e)}get current(){let e=this.#n;return e===null?this.#e.default:this.#e.has(e)?e:this.#e.default}async load_choosen_phrasebook(){return await this.#e.select(this.current)}get languages(){return this.#e}update(e){return this.#n=e,this}};I.preferences=v});var R=i((Z,o)=>{typeof o<"u"&&o.exports?(o.exports.phrasebook=l().phrasebook,o.exports.loader=h().loader,o.exports.languages=c().languages,o.exports.loader=h().loader,o.exports.preferences=T().preferences,o.exports.selector=p().selector,o.exports.autotranslate=d().autotranslate):window.cx_libtranslate={phrasebook:l().phrasebook,loader:h().loader,languages:c().languages,translation:b().translation,preferences:T().preferences,selector:p().selector,autotranslate:d().autotranslate}});return R();})(); //# sourceMappingURL=cx-libtranslate.min.js.map