@tolgee/core
Advanced tools
Comparing version 5.23.3 to 5.24.0
@@ -81,3 +81,3 @@ 'use strict'; | ||
const createFetchFunction = (fetchFn = defaultFetchFunction) => { | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.23.3" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.24.0" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
}; | ||
@@ -84,0 +84,0 @@ |
@@ -81,3 +81,3 @@ 'use strict'; | ||
const createFetchFunction = (fetchFn = defaultFetchFunction) => { | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.23.3" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.24.0" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
}; | ||
@@ -84,0 +84,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return Boolean(e&&"function"==typeof e.then)}function n(n,t){return e(n)?Promise.resolve(n).then(t):t(n)}function t(n,t,a){function i(e){const a=t(e);throw n.emit(a),console.error(a),a}try{const n=a();return e(n)?n.catch(i):n}catch(e){i(e)}}function a(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function i(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function o(e){return i(e)||[]}function r(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?o(n):o(null==n?void 0:n[e]);var t}function s(e){return Array.from(new Set(e))}function g(e){return e?e.replace(/\/+$/,""):e}Object.defineProperty(exports,"__esModule",{value:!0});const c=(e,n)=>fetch(e,n),l=(e=c)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.23.3"},null==t?void 0:t.headers)}));function u(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function d(e,n,t){const a=new Set,i=new Set;let r=[];function s(){if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(r.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(o(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class p extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class f extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const h=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):h(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},m=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},b=({language:e,namespace:n})=>n?`${e}:${n}`:e;function y(n,t,a,i,r,g,c){const l=new Map,u=new Map;let d={},f=0;function v(e,t,a){const i=b(e);u.set(i,{data:h(t),version:a}),n.onCacheChange.emit(e)}async function y(i,o){let r;if(o)try{r=await a(i)}catch(e){const t=new p(i,e,!0);n.onError.emit(t),console.warn(t)}return r||(r=await async function(a){let i;const o=d[b(a)];return"function"==typeof o&&(i=o()),i||(i=t(a)),e(i)?null==i?void 0:i.catch((e=>{const t=new p(a,e);throw n.onError.emit(t),console.error(t),t})):i}(i)),r}const L=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=m(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),f+=1},addRecord(e,n){v(e,n,f)},exists(e,n=!1){const t=u.get(b(e));return t&&n?t.version===f:Boolean(t)},getRecord(e){var n;return null===(n=u.get(b(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(b(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return s(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(e,t,a){var i;const o=null===(i=u.get(b(e)))||void 0===i?void 0:i.data;null==o||o.set(t,a),n.onCacheChange.emit(Object.assign(Object.assign({},e),{key:t}))},isFetching(e){if(r())return!0;if(void 0===e)return l.size>0;const n=o(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(m(e).namespace))))},isLoading(e,n){const t=o(n);return Boolean(r()||Array.from(l.keys()).find((n=>{const a=m(n);return(!t.length||t.includes(a.namespace))&&!L.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const t=e.map((e=>{const t=i(e),a=b(t),o=l.get(a);if(o)return{new:!1,promise:o,keyObject:t,cacheKey:a};const r=y(t,n)||Promise.resolve(void 0);return l.set(a,r),{new:!0,promise:r,keyObject:t,cacheKey:a}}));g.notify(),c.notify();const a=await Promise.all(t.map((e=>e.promise)));return t.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=a[n];t?L.addRecord(e.keyObject,t):L.getRecord(e.keyObject)||L.addRecord(e.keyObject,{})}})),g.notify(),c.notify(),t.map((e=>L.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},m(e)),{data:n.data})))});return L}function L(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const O="invalid",j={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:O,apiUrl:"https://app.tolgee.io",fetch:l(),onTranslationMissing:({key:e})=>e},k=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function w(e,n){const t=k(j,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=l(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function E(e,a,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,target:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},p=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function h(e){const n=s({key:e.key,ns:e.ns});return C.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:a().fetch}}function b(e){u.observer=null==e?void 0:e()}function y(){return Boolean(u.observer)}function j(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function w(e){l.ui=e}function E(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function D(e){u.languageDetector=e}function F(e){e&&u.backends.push(e)}function N(e){u.devBackend=e}const C=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:j,setObserver:b,hasObserver:y,setUi:w,hasUi:E,setDevBackend:N,addBackend:F,setLanguageDetector:D,setLanguageStorage:R}))},findPositions:p,run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:t,apiUrl:i,projectId:o,highlight:C.highlight,changeTranslation:g,findPositions:p,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(n=u.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:h,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return n(t(c.onError,(e=>new v("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return t(c.onError,(e=>new f("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>t(c.onError,(e=>new v("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:async({language:e,namespace:n})=>{for(const t of u.backends){const a=await t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:async({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=u.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(C.getDevBackend()),formatTranslation(n){var t,{formatEnabled:i}=n,o=L(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:p}=o,f=null!=s?s:g;let v="";null==s&&(v=a().onTranslationMissing(o));let h=null!=f?f:p?"":v;const m=e(),b=i||!(null===(t=u.observer)||void 0===t?void 0:t.outputNotFormattable),y=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=y(h);try{if(f&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&f&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(j=e)?j:"string"==typeof(null==j?void 0:j.message)?j.message:void 0)||O,t=a().onFormatError,i=typeof t;h="string"===i?t:"function"===i?t(n,o):O,h=y(h)}var j;return h}});return C}const R=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const D=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=L(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function F({options:t}){const i=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:u(a),onLanguageChange:u(a),onLoadingChange:u(a),onFetchingChange:u(a),onInitialLoaded:u(a),onRunningChange:u(a),onCacheChange:u(a),onUpdate:d(a,e,n),onPermanentChange:u(a),onError:u(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(b,L),c=R(!1,(()=>v.isFetching()),i.onFetchingChange.emit),l=R(!1,(()=>S.isLoading()),i.onLoadingChange.emit),p=function(e,n,t){let a,i=w();const c=Object.freeze({init(e){i=w(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||c.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>s([...i.initialOptions.ns||[i.initialOptions.defaultNs],...o(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?s([n,...r(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>o(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>m(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?c.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:g(e.apiUrl)}):void 0}});return c}(i.onLanguageChange,i.onPendingLanguageChange,i.onRunningChange),f=E(p.getLanguage,p.getInitialOptions,p.getAvailableLanguages,O,C,P,k,i),v=y(i,f.getBackendRecord,f.getBackendDevRecord,p.withDefaultNs,p.isInitialLoading,c,l);let h;function b(){return p.getFallbackNs()}function L(e){return p.getDefaultNs(e)}function O(e){return[...o(L(e)),...b()]}function j(e){return[...o(null!=e?e:L()),...p.getRequiredNamespaces()]}function k(e,n,t){const a=p.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function F(e){p.init(e),v.addStaticData(p.getInitialOptions().staticData)}function N(e,t){const a=function(e,n){const t=p.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(S.loadRecords(a),(()=>{}))}function C({key:e,ns:n}){const t=p.getFallbackLangs(),a=O(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function P({key:e,ns:n,language:t}){const a=O(null!=n?n:void 0),i=p.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function A(){const t=n(function(){if(p.getLanguage())return;return n(f.getInitialLanguage(),(e=>{const n=e||p.getInitialOptions().defaultLanguage;n&&p.setLanguage(n)}))}(),(()=>N()));if(e(t))return p.setInitialLoading(!0),c.notify(),l.notify(),Promise.resolve(t).then((()=>{p.setInitialLoading(!1),c.notify(),l.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}t&&F(t),i.onUpdate.listen((()=>{p.isRunning()&&f.retranslate()}));const S=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),p),f),v),{init:F,getTranslation:P,changeTranslation:k,getTranslationNs:C,getDefaultAndFallbackNs:O,findPositions:f.findPositions,async changeLanguage(e){p.getPendingLanguage()===e&&p.getLanguage()===e||(p.setPendingLanguage(e),p.isRunning()&&await N(e),e===p.getPendingLanguage()&&(p.setLanguage(e),await f.setStoredLanguage(e)))},async addActiveNs(e,n){n||p.addActiveNs(e),p.isRunning()&&await N(void 0,e)},loadRecords:e=>v.loadRecords(e,S.isDev()),loadRecord:async e=>(await S.loadRecords([e]))[0],isLoading:e=>v.isLoading(p.getLanguage(),e),isLoaded(e){const n=p.getLanguage();if(!n)return!1;const t=p.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=D(...e),t=P(n);return f.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(p.getInitialOptions().apiKey&&p.getInitialOptions().apiUrl),run:()=>(function(){if((f.getLanguageDetector()||f.getLanguageStorage())&&!p.getAvailableLanguages())throw new Error(a("availableLanguages"));if(!p.getLanguage()&&!p.getInitialOptions().defaultLanguage)throw new Error(a(["defaultLanguage","language"]))}(),p.isRunning()||(p.setRunning(!0),f.run(),h=A()),Promise.resolve(h)),stop(){p.isRunning()&&(f.stop(),p.setRunning(!1))}}));return S}const N=0,C=1,P=2;class A extends Error{constructor(e,n,t){let a;a=e===N?"Empty parameter":e===C?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function S(e){return/\s/.test(e)}const T=0,I=1,x=2,U=3,B=4,z=new Set([x,I,T]),K="'",$=new Set(["{","}",K]),M=e=>/[0-9a-zA-Z_]/.test(e);function V(e,n){const[t,a]=function(e){let n=T,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new A(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(N),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case T:i===K?(t+=i,n=I):"{"===i?(c(),n=U):(t+=i,n=T);break;case I:$.has(i)?(t=t.slice(0,-1)+i,n=x):(t+=i,n=T);break;case x:i===K?n=T:(t+=i,n=x);break;case U:"}"===i?(l(),n=T):S(i)?""!==a&&(l(),n=B):(M(i)||g(C),a+=i,n=U);break;case B:"}"==i?n=T:S(i)?n=B:g(C)}return z.has(n)||g(P),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}exports.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>V(e,n)}),e),exports.LanguageDetectorError=f,exports.LanguageStorageError=v,exports.RecordFetchError=p,exports.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=k(e.options,t),n),init(n){const t=function(e){const n=F({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,findPositions:n.findPositions,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(k(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},exports.createFetchFunction=l,exports.getFallback=i,exports.getFallbackArray=o,exports.getTranslateProps=D; | ||
"use strict";function e(e){return Boolean(e&&"function"==typeof e.then)}function n(n,t){return e(n)?Promise.resolve(n).then(t):t(n)}function t(n,t,a){function i(e){const a=t(e);throw n.emit(a),console.error(a),a}try{const n=a();return e(n)?n.catch(i):n}catch(e){i(e)}}function a(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function i(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function o(e){return i(e)||[]}function r(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?o(n):o(null==n?void 0:n[e]);var t}function s(e){return Array.from(new Set(e))}function g(e){return e?e.replace(/\/+$/,""):e}Object.defineProperty(exports,"__esModule",{value:!0});const c=(e,n)=>fetch(e,n),l=(e=c)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.24.0"},null==t?void 0:t.headers)}));function u(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function d(e,n,t){const a=new Set,i=new Set;let r=[];function s(){if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(r.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(o(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class p extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class f extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const h=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):h(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},m=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},b=({language:e,namespace:n})=>n?`${e}:${n}`:e;function y(n,t,a,i,r,g,c){const l=new Map,u=new Map;let d={},f=0;function v(e,t,a){const i=b(e);u.set(i,{data:h(t),version:a}),n.onCacheChange.emit(e)}async function y(i,o){let r;if(o)try{r=await a(i)}catch(e){const t=new p(i,e,!0);n.onError.emit(t),console.warn(t)}return r||(r=await async function(a){let i;const o=d[b(a)];return"function"==typeof o&&(i=o()),i||(i=t(a)),e(i)?null==i?void 0:i.catch((e=>{const t=new p(a,e);throw n.onError.emit(t),console.error(t),t})):i}(i)),r}const L=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=m(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),f+=1},addRecord(e,n){v(e,n,f)},exists(e,n=!1){const t=u.get(b(e));return t&&n?t.version===f:Boolean(t)},getRecord(e){var n;return null===(n=u.get(b(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(b(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return s(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(e,t,a){var i;const o=null===(i=u.get(b(e)))||void 0===i?void 0:i.data;null==o||o.set(t,a),n.onCacheChange.emit(Object.assign(Object.assign({},e),{key:t}))},isFetching(e){if(r())return!0;if(void 0===e)return l.size>0;const n=o(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(m(e).namespace))))},isLoading(e,n){const t=o(n);return Boolean(r()||Array.from(l.keys()).find((n=>{const a=m(n);return(!t.length||t.includes(a.namespace))&&!L.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const t=e.map((e=>{const t=i(e),a=b(t),o=l.get(a);if(o)return{new:!1,promise:o,keyObject:t,cacheKey:a};const r=y(t,n)||Promise.resolve(void 0);return l.set(a,r),{new:!0,promise:r,keyObject:t,cacheKey:a}}));g.notify(),c.notify();const a=await Promise.all(t.map((e=>e.promise)));return t.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=a[n];t?L.addRecord(e.keyObject,t):L.getRecord(e.keyObject)||L.addRecord(e.keyObject,{})}})),g.notify(),c.notify(),t.map((e=>L.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},m(e)),{data:n.data})))});return L}function L(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const O="invalid",j={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:O,apiUrl:"https://app.tolgee.io",fetch:l(),onTranslationMissing:({key:e})=>e},k=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function w(e,n){const t=k(j,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=l(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function E(e,a,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,target:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},p=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function h(e){const n=s({key:e.key,ns:e.ns});return C.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:a().fetch}}function b(e){u.observer=null==e?void 0:e()}function y(){return Boolean(u.observer)}function j(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function w(e){l.ui=e}function E(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function D(e){u.languageDetector=e}function F(e){e&&u.backends.push(e)}function N(e){u.devBackend=e}const C=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:j,setObserver:b,hasObserver:y,setUi:w,hasUi:E,setDevBackend:N,addBackend:F,setLanguageDetector:D,setLanguageStorage:R}))},findPositions:p,run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:t,apiUrl:i,projectId:o,highlight:C.highlight,changeTranslation:g,findPositions:p,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(n=u.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:h,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return n(t(c.onError,(e=>new v("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return t(c.onError,(e=>new f("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>t(c.onError,(e=>new v("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:async({language:e,namespace:n})=>{for(const t of u.backends){const a=await t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:async({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=u.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(C.getDevBackend()),formatTranslation(n){var t,{formatEnabled:i}=n,o=L(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:p}=o,f=null!=s?s:g;let v="";null==s&&(v=a().onTranslationMissing(o));let h=null!=f?f:p?"":v;const m=e(),b=i||!(null===(t=u.observer)||void 0===t?void 0:t.outputNotFormattable),y=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=y(h);try{if(f&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&f&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(j=e)?j:"string"==typeof(null==j?void 0:j.message)?j.message:void 0)||O,t=a().onFormatError,i=typeof t;h="string"===i?t:"function"===i?t(n,o):O,h=y(h)}var j;return h}});return C}const R=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const D=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=L(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function F({options:t}){const i=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:u(a),onLanguageChange:u(a),onLoadingChange:u(a),onFetchingChange:u(a),onInitialLoaded:u(a),onRunningChange:u(a),onCacheChange:u(a),onUpdate:d(a,e,n),onPermanentChange:u(a),onError:u(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(b,L),c=R(!1,(()=>v.isFetching()),i.onFetchingChange.emit),l=R(!1,(()=>S.isLoading()),i.onLoadingChange.emit),p=function(e,n,t){let a,i=w();const c=Object.freeze({init(e){i=w(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||c.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>s([...i.initialOptions.ns||[i.initialOptions.defaultNs],...o(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?s([n,...r(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>o(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>m(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?c.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:g(e.apiUrl)}):void 0}});return c}(i.onLanguageChange,i.onPendingLanguageChange,i.onRunningChange),f=E(p.getLanguage,p.getInitialOptions,p.getAvailableLanguages,O,C,P,k,i),v=y(i,f.getBackendRecord,f.getBackendDevRecord,p.withDefaultNs,p.isInitialLoading,c,l);let h;function b(){return p.getFallbackNs()}function L(e){return p.getDefaultNs(e)}function O(e){return[...o(L(e)),...b()]}function j(e){return[...o(null!=e?e:L()),...p.getRequiredNamespaces()]}function k(e,n,t){const a=p.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function F(e){p.init(e),v.addStaticData(p.getInitialOptions().staticData)}function N(e,t){const a=function(e,n){const t=p.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(S.loadRecords(a),(()=>{}))}function C({key:e,ns:n}){const t=p.getFallbackLangs(),a=O(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function P({key:e,ns:n,language:t}){const a=O(null!=n?n:void 0),i=p.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function A(){const t=n(function(){if(p.getLanguage())return;return n(f.getInitialLanguage(),(e=>{const n=e||p.getInitialOptions().defaultLanguage;n&&p.setLanguage(n)}))}(),(()=>N()));if(e(t))return p.setInitialLoading(!0),c.notify(),l.notify(),Promise.resolve(t).then((()=>{p.setInitialLoading(!1),c.notify(),l.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}t&&F(t),i.onUpdate.listen((()=>{p.isRunning()&&f.retranslate()}));const S=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),p),f),v),{init:F,getTranslation:P,changeTranslation:k,getTranslationNs:C,getDefaultAndFallbackNs:O,findPositions:f.findPositions,async changeLanguage(e){p.getPendingLanguage()===e&&p.getLanguage()===e||(p.setPendingLanguage(e),p.isRunning()&&await N(e),e===p.getPendingLanguage()&&(p.setLanguage(e),await f.setStoredLanguage(e)))},async addActiveNs(e,n){n||p.addActiveNs(e),p.isRunning()&&await N(void 0,e)},loadRecords:e=>v.loadRecords(e,S.isDev()),loadRecord:async e=>(await S.loadRecords([e]))[0],isLoading:e=>v.isLoading(p.getLanguage(),e),isLoaded(e){const n=p.getLanguage();if(!n)return!1;const t=p.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=D(...e),t=P(n);return f.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(p.getInitialOptions().apiKey&&p.getInitialOptions().apiUrl),run:()=>(function(){if((f.getLanguageDetector()||f.getLanguageStorage())&&!p.getAvailableLanguages())throw new Error(a("availableLanguages"));if(!p.getLanguage()&&!p.getInitialOptions().defaultLanguage)throw new Error(a(["defaultLanguage","language"]))}(),p.isRunning()||(p.setRunning(!0),f.run(),h=A()),Promise.resolve(h)),stop(){p.isRunning()&&(f.stop(),p.setRunning(!1))}}));return S}const N=0,C=1,P=2;class A extends Error{constructor(e,n,t){let a;a=e===N?"Empty parameter":e===C?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function S(e){return/\s/.test(e)}const T=0,I=1,x=2,U=3,B=4,z=new Set([x,I,T]),K="'",$=new Set(["{","}",K]),M=e=>/[0-9a-zA-Z_]/.test(e);function V(e,n){const[t,a]=function(e){let n=T,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new A(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(N),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case T:i===K?(t+=i,n=I):"{"===i?(c(),n=U):(t+=i,n=T);break;case I:$.has(i)?(t=t.slice(0,-1)+i,n=x):(t+=i,n=T);break;case x:i===K?n=T:(t+=i,n=x);break;case U:"}"===i?(l(),n=T):S(i)?""!==a&&(l(),n=B):(M(i)||g(C),a+=i,n=U);break;case B:"}"==i?n=T:S(i)?n=B:g(C)}return z.has(n)||g(P),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}exports.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>V(e,n)}),e),exports.LanguageDetectorError=f,exports.LanguageStorageError=v,exports.RecordFetchError=p,exports.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=k(e.options,t),n),init(n){const t=function(e){const n=F({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,findPositions:n.findPositions,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(k(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},exports.createFetchFunction=l,exports.getFallback=i,exports.getFallbackArray=o,exports.getTranslateProps=D; | ||
//# sourceMappingURL=tolgee.cjs.min.js.map |
@@ -77,3 +77,3 @@ function isPromise(value) { | ||
const createFetchFunction = (fetchFn = defaultFetchFunction) => { | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.23.3" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.24.0" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
}; | ||
@@ -80,0 +80,0 @@ |
@@ -1,2 +0,2 @@ | ||
function e(e){return Boolean(e&&"function"==typeof e.then)}function n(n,t){return e(n)?Promise.resolve(n).then(t):t(n)}function t(n,t,a){function i(e){const a=t(e);throw n.emit(a),console.error(a),a}try{const n=a();return e(n)?n.catch(i):n}catch(e){i(e)}}function a(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function i(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function o(e){return i(e)||[]}function r(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?o(n):o(null==n?void 0:n[e]);var t}function s(e){return Array.from(new Set(e))}function g(e){return e?e.replace(/\/+$/,""):e}const c=(e,n)=>fetch(e,n),l=(e=c)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.23.3"},null==t?void 0:t.headers)}));function u(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function d(e,n,t){const a=new Set,i=new Set;let r=[];function s(){if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(r.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(o(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class f extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class p extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const h=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):h(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},m=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},b=({language:e,namespace:n})=>n?`${e}:${n}`:e;function y(n,t,a,i,r,g,c){const l=new Map,u=new Map;let d={},p=0;function v(e,t,a){const i=b(e);u.set(i,{data:h(t),version:a}),n.onCacheChange.emit(e)}async function y(i,o){let r;if(o)try{r=await a(i)}catch(e){const t=new f(i,e,!0);n.onError.emit(t),console.warn(t)}return r||(r=await async function(a){let i;const o=d[b(a)];return"function"==typeof o&&(i=o()),i||(i=t(a)),e(i)?null==i?void 0:i.catch((e=>{const t=new f(a,e);throw n.onError.emit(t),console.error(t),t})):i}(i)),r}const O=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=m(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),p+=1},addRecord(e,n){v(e,n,p)},exists(e,n=!1){const t=u.get(b(e));return t&&n?t.version===p:Boolean(t)},getRecord(e){var n;return null===(n=u.get(b(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(b(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return s(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(e,t,a){var i;const o=null===(i=u.get(b(e)))||void 0===i?void 0:i.data;null==o||o.set(t,a),n.onCacheChange.emit(Object.assign(Object.assign({},e),{key:t}))},isFetching(e){if(r())return!0;if(void 0===e)return l.size>0;const n=o(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(m(e).namespace))))},isLoading(e,n){const t=o(n);return Boolean(r()||Array.from(l.keys()).find((n=>{const a=m(n);return(!t.length||t.includes(a.namespace))&&!O.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const t=e.map((e=>{const t=i(e),a=b(t),o=l.get(a);if(o)return{new:!1,promise:o,keyObject:t,cacheKey:a};const r=y(t,n)||Promise.resolve(void 0);return l.set(a,r),{new:!0,promise:r,keyObject:t,cacheKey:a}}));g.notify(),c.notify();const a=await Promise.all(t.map((e=>e.promise)));return t.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=a[n];t?O.addRecord(e.keyObject,t):O.getRecord(e.keyObject)||O.addRecord(e.keyObject,{})}})),g.notify(),c.notify(),t.map((e=>O.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},m(e)),{data:n.data})))});return O}function O(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const L="invalid",j={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:L,apiUrl:"https://app.tolgee.io",fetch:l(),onTranslationMissing:({key:e})=>e},k=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function w(e,n){const t=k(j,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=l(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function E(e,a,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,target:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},f=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function h(e){const n=s({key:e.key,ns:e.ns});return P.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:a().fetch}}function b(e){u.observer=null==e?void 0:e()}function y(){return Boolean(u.observer)}function j(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function w(e){l.ui=e}function E(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function N(e){u.languageDetector=e}function D(e){e&&u.backends.push(e)}function C(e){u.devBackend=e}const P=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:j,setObserver:b,hasObserver:y,setUi:w,hasUi:E,setDevBackend:C,addBackend:D,setLanguageDetector:N,setLanguageStorage:R}))},findPositions:f,run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:t,apiUrl:i,projectId:o,highlight:P.highlight,changeTranslation:g,findPositions:f,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(n=u.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:h,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return n(t(c.onError,(e=>new v("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return t(c.onError,(e=>new p("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>t(c.onError,(e=>new v("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:async({language:e,namespace:n})=>{for(const t of u.backends){const a=await t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:async({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=u.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(P.getDevBackend()),formatTranslation(n){var t,{formatEnabled:i}=n,o=O(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:f}=o,p=null!=s?s:g;let v="";null==s&&(v=a().onTranslationMissing(o));let h=null!=p?p:f?"":v;const m=e(),b=i||!(null===(t=u.observer)||void 0===t?void 0:t.outputNotFormattable),y=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=y(h);try{if(p&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&p&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(j=e)?j:"string"==typeof(null==j?void 0:j.message)?j.message:void 0)||L,t=a().onFormatError,i=typeof t;h="string"===i?t:"function"===i?t(n,o):L,h=y(h)}var j;return h}});return P}const R=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const N=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=O(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function D({options:t}){const i=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:u(a),onLanguageChange:u(a),onLoadingChange:u(a),onFetchingChange:u(a),onInitialLoaded:u(a),onRunningChange:u(a),onCacheChange:u(a),onUpdate:d(a,e,n),onPermanentChange:u(a),onError:u(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(b,O),c=R(!1,(()=>v.isFetching()),i.onFetchingChange.emit),l=R(!1,(()=>I.isLoading()),i.onLoadingChange.emit),f=function(e,n,t){let a,i=w();const c=Object.freeze({init(e){i=w(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||c.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>s([...i.initialOptions.ns||[i.initialOptions.defaultNs],...o(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?s([n,...r(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>o(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>m(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?c.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:g(e.apiUrl)}):void 0}});return c}(i.onLanguageChange,i.onPendingLanguageChange,i.onRunningChange),p=E(f.getLanguage,f.getInitialOptions,f.getAvailableLanguages,L,P,A,k,i),v=y(i,p.getBackendRecord,p.getBackendDevRecord,f.withDefaultNs,f.isInitialLoading,c,l);let h;function b(){return f.getFallbackNs()}function O(e){return f.getDefaultNs(e)}function L(e){return[...o(O(e)),...b()]}function j(e){return[...o(null!=e?e:O()),...f.getRequiredNamespaces()]}function k(e,n,t){const a=f.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function D(e){f.init(e),v.addStaticData(f.getInitialOptions().staticData)}function C(e,t){const a=function(e,n){const t=f.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(I.loadRecords(a),(()=>{}))}function P({key:e,ns:n}){const t=f.getFallbackLangs(),a=L(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function A({key:e,ns:n,language:t}){const a=L(null!=n?n:void 0),i=f.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function F(){const t=n(function(){if(f.getLanguage())return;return n(p.getInitialLanguage(),(e=>{const n=e||f.getInitialOptions().defaultLanguage;n&&f.setLanguage(n)}))}(),(()=>C()));if(e(t))return f.setInitialLoading(!0),c.notify(),l.notify(),Promise.resolve(t).then((()=>{f.setInitialLoading(!1),c.notify(),l.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}t&&D(t),i.onUpdate.listen((()=>{f.isRunning()&&p.retranslate()}));const I=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),f),p),v),{init:D,getTranslation:A,changeTranslation:k,getTranslationNs:P,getDefaultAndFallbackNs:L,findPositions:p.findPositions,async changeLanguage(e){f.getPendingLanguage()===e&&f.getLanguage()===e||(f.setPendingLanguage(e),f.isRunning()&&await C(e),e===f.getPendingLanguage()&&(f.setLanguage(e),await p.setStoredLanguage(e)))},async addActiveNs(e,n){n||f.addActiveNs(e),f.isRunning()&&await C(void 0,e)},loadRecords:e=>v.loadRecords(e,I.isDev()),loadRecord:async e=>(await I.loadRecords([e]))[0],isLoading:e=>v.isLoading(f.getLanguage(),e),isLoaded(e){const n=f.getLanguage();if(!n)return!1;const t=f.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=N(...e),t=A(n);return p.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(f.getInitialOptions().apiKey&&f.getInitialOptions().apiUrl),run:()=>(function(){if((p.getLanguageDetector()||p.getLanguageStorage())&&!f.getAvailableLanguages())throw new Error(a("availableLanguages"));if(!f.getLanguage()&&!f.getInitialOptions().defaultLanguage)throw new Error(a(["defaultLanguage","language"]))}(),f.isRunning()||(f.setRunning(!0),p.run(),h=F()),Promise.resolve(h)),stop(){f.isRunning()&&(p.stop(),f.setRunning(!1))}}));return I}const C=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=k(e.options,t),n),init(n){const t=function(e){const n=D({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,findPositions:n.findPositions,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(k(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},P=0,A=1,F=2;class I extends Error{constructor(e,n,t){let a;a=e===P?"Empty parameter":e===A?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function S(e){return/\s/.test(e)}const T=0,U=1,B=2,x=3,z=4,K=new Set([B,U,T]),$="'",M=new Set(["{","}",$]),V=e=>/[0-9a-zA-Z_]/.test(e);function W(e,n){const[t,a]=function(e){let n=T,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new I(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(P),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case T:i===$?(t+=i,n=U):"{"===i?(c(),n=x):(t+=i,n=T);break;case U:M.has(i)?(t=t.slice(0,-1)+i,n=B):(t+=i,n=T);break;case B:i===$?n=T:(t+=i,n=B);break;case x:"}"===i?(l(),n=T):S(i)?""!==a&&(l(),n=z):(V(i)||g(A),a+=i,n=x);break;case z:"}"==i?n=T:S(i)?n=z:g(A)}return K.has(n)||g(F),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}const q=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>W(e,n)}),e);export{q as FormatSimple,p as LanguageDetectorError,v as LanguageStorageError,f as RecordFetchError,C as TolgeeCore,l as createFetchFunction,i as getFallback,o as getFallbackArray,N as getTranslateProps}; | ||
function e(e){return Boolean(e&&"function"==typeof e.then)}function n(n,t){return e(n)?Promise.resolve(n).then(t):t(n)}function t(n,t,a){function i(e){const a=t(e);throw n.emit(a),console.error(a),a}try{const n=a();return e(n)?n.catch(i):n}catch(e){i(e)}}function a(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function i(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function o(e){return i(e)||[]}function r(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?o(n):o(null==n?void 0:n[e]);var t}function s(e){return Array.from(new Set(e))}function g(e){return e?e.replace(/\/+$/,""):e}const c=(e,n)=>fetch(e,n),l=(e=c)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.24.0"},null==t?void 0:t.headers)}));function u(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function d(e,n,t){const a=new Set,i=new Set;let r=[];function s(){if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(r.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(o(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class f extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class p extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const h=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):h(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},m=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},b=({language:e,namespace:n})=>n?`${e}:${n}`:e;function y(n,t,a,i,r,g,c){const l=new Map,u=new Map;let d={},p=0;function v(e,t,a){const i=b(e);u.set(i,{data:h(t),version:a}),n.onCacheChange.emit(e)}async function y(i,o){let r;if(o)try{r=await a(i)}catch(e){const t=new f(i,e,!0);n.onError.emit(t),console.warn(t)}return r||(r=await async function(a){let i;const o=d[b(a)];return"function"==typeof o&&(i=o()),i||(i=t(a)),e(i)?null==i?void 0:i.catch((e=>{const t=new f(a,e);throw n.onError.emit(t),console.error(t),t})):i}(i)),r}const O=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=m(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),p+=1},addRecord(e,n){v(e,n,p)},exists(e,n=!1){const t=u.get(b(e));return t&&n?t.version===p:Boolean(t)},getRecord(e){var n;return null===(n=u.get(b(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(b(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return s(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(e,t,a){var i;const o=null===(i=u.get(b(e)))||void 0===i?void 0:i.data;null==o||o.set(t,a),n.onCacheChange.emit(Object.assign(Object.assign({},e),{key:t}))},isFetching(e){if(r())return!0;if(void 0===e)return l.size>0;const n=o(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(m(e).namespace))))},isLoading(e,n){const t=o(n);return Boolean(r()||Array.from(l.keys()).find((n=>{const a=m(n);return(!t.length||t.includes(a.namespace))&&!O.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const t=e.map((e=>{const t=i(e),a=b(t),o=l.get(a);if(o)return{new:!1,promise:o,keyObject:t,cacheKey:a};const r=y(t,n)||Promise.resolve(void 0);return l.set(a,r),{new:!0,promise:r,keyObject:t,cacheKey:a}}));g.notify(),c.notify();const a=await Promise.all(t.map((e=>e.promise)));return t.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=a[n];t?O.addRecord(e.keyObject,t):O.getRecord(e.keyObject)||O.addRecord(e.keyObject,{})}})),g.notify(),c.notify(),t.map((e=>O.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},m(e)),{data:n.data})))});return O}function O(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const L="invalid",j={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:L,apiUrl:"https://app.tolgee.io",fetch:l(),onTranslationMissing:({key:e})=>e},k=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function w(e,n){const t=k(j,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=l(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function E(e,a,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,target:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},f=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function h(e){const n=s({key:e.key,ns:e.ns});return P.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:a().fetch}}function b(e){u.observer=null==e?void 0:e()}function y(){return Boolean(u.observer)}function j(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function w(e){l.ui=e}function E(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function N(e){u.languageDetector=e}function D(e){e&&u.backends.push(e)}function C(e){u.devBackend=e}const P=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:j,setObserver:b,hasObserver:y,setUi:w,hasUi:E,setDevBackend:C,addBackend:D,setLanguageDetector:N,setLanguageStorage:R}))},findPositions:f,run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:t,apiUrl:i,projectId:o,highlight:P.highlight,changeTranslation:g,findPositions:f,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(n=u.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:h,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return n(t(c.onError,(e=>new v("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return t(c.onError,(e=>new p("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>t(c.onError,(e=>new v("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:async({language:e,namespace:n})=>{for(const t of u.backends){const a=await t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:async({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=u.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(P.getDevBackend()),formatTranslation(n){var t,{formatEnabled:i}=n,o=O(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:f}=o,p=null!=s?s:g;let v="";null==s&&(v=a().onTranslationMissing(o));let h=null!=p?p:f?"":v;const m=e(),b=i||!(null===(t=u.observer)||void 0===t?void 0:t.outputNotFormattable),y=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=y(h);try{if(p&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&p&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(j=e)?j:"string"==typeof(null==j?void 0:j.message)?j.message:void 0)||L,t=a().onFormatError,i=typeof t;h="string"===i?t:"function"===i?t(n,o):L,h=y(h)}var j;return h}});return P}const R=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const N=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=O(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function D({options:t}){const i=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:u(a),onLanguageChange:u(a),onLoadingChange:u(a),onFetchingChange:u(a),onInitialLoaded:u(a),onRunningChange:u(a),onCacheChange:u(a),onUpdate:d(a,e,n),onPermanentChange:u(a),onError:u(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(b,O),c=R(!1,(()=>v.isFetching()),i.onFetchingChange.emit),l=R(!1,(()=>I.isLoading()),i.onLoadingChange.emit),f=function(e,n,t){let a,i=w();const c=Object.freeze({init(e){i=w(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||c.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>s([...i.initialOptions.ns||[i.initialOptions.defaultNs],...o(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?s([n,...r(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>o(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>m(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?c.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:g(e.apiUrl)}):void 0}});return c}(i.onLanguageChange,i.onPendingLanguageChange,i.onRunningChange),p=E(f.getLanguage,f.getInitialOptions,f.getAvailableLanguages,L,P,A,k,i),v=y(i,p.getBackendRecord,p.getBackendDevRecord,f.withDefaultNs,f.isInitialLoading,c,l);let h;function b(){return f.getFallbackNs()}function O(e){return f.getDefaultNs(e)}function L(e){return[...o(O(e)),...b()]}function j(e){return[...o(null!=e?e:O()),...f.getRequiredNamespaces()]}function k(e,n,t){const a=f.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function D(e){f.init(e),v.addStaticData(f.getInitialOptions().staticData)}function C(e,t){const a=function(e,n){const t=f.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(I.loadRecords(a),(()=>{}))}function P({key:e,ns:n}){const t=f.getFallbackLangs(),a=L(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function A({key:e,ns:n,language:t}){const a=L(null!=n?n:void 0),i=f.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function F(){const t=n(function(){if(f.getLanguage())return;return n(p.getInitialLanguage(),(e=>{const n=e||f.getInitialOptions().defaultLanguage;n&&f.setLanguage(n)}))}(),(()=>C()));if(e(t))return f.setInitialLoading(!0),c.notify(),l.notify(),Promise.resolve(t).then((()=>{f.setInitialLoading(!1),c.notify(),l.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}t&&D(t),i.onUpdate.listen((()=>{f.isRunning()&&p.retranslate()}));const I=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),f),p),v),{init:D,getTranslation:A,changeTranslation:k,getTranslationNs:P,getDefaultAndFallbackNs:L,findPositions:p.findPositions,async changeLanguage(e){f.getPendingLanguage()===e&&f.getLanguage()===e||(f.setPendingLanguage(e),f.isRunning()&&await C(e),e===f.getPendingLanguage()&&(f.setLanguage(e),await p.setStoredLanguage(e)))},async addActiveNs(e,n){n||f.addActiveNs(e),f.isRunning()&&await C(void 0,e)},loadRecords:e=>v.loadRecords(e,I.isDev()),loadRecord:async e=>(await I.loadRecords([e]))[0],isLoading:e=>v.isLoading(f.getLanguage(),e),isLoaded(e){const n=f.getLanguage();if(!n)return!1;const t=f.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=N(...e),t=A(n);return p.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(f.getInitialOptions().apiKey&&f.getInitialOptions().apiUrl),run:()=>(function(){if((p.getLanguageDetector()||p.getLanguageStorage())&&!f.getAvailableLanguages())throw new Error(a("availableLanguages"));if(!f.getLanguage()&&!f.getInitialOptions().defaultLanguage)throw new Error(a(["defaultLanguage","language"]))}(),f.isRunning()||(f.setRunning(!0),p.run(),h=F()),Promise.resolve(h)),stop(){f.isRunning()&&(p.stop(),f.setRunning(!1))}}));return I}const C=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=k(e.options,t),n),init(n){const t=function(e){const n=D({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,findPositions:n.findPositions,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(k(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},P=0,A=1,F=2;class I extends Error{constructor(e,n,t){let a;a=e===P?"Empty parameter":e===A?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function S(e){return/\s/.test(e)}const T=0,U=1,B=2,x=3,z=4,K=new Set([B,U,T]),$="'",M=new Set(["{","}",$]),V=e=>/[0-9a-zA-Z_]/.test(e);function W(e,n){const[t,a]=function(e){let n=T,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new I(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(P),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case T:i===$?(t+=i,n=U):"{"===i?(c(),n=x):(t+=i,n=T);break;case U:M.has(i)?(t=t.slice(0,-1)+i,n=B):(t+=i,n=T);break;case B:i===$?n=T:(t+=i,n=B);break;case x:"}"===i?(l(),n=T):S(i)?""!==a&&(l(),n=z):(V(i)||g(A),a+=i,n=x);break;case z:"}"==i?n=T:S(i)?n=z:g(A)}return K.has(n)||g(F),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}const q=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>W(e,n)}),e);export{q as FormatSimple,p as LanguageDetectorError,v as LanguageStorageError,f as RecordFetchError,C as TolgeeCore,l as createFetchFunction,i as getFallback,o as getFallbackArray,N as getTranslateProps}; | ||
//# sourceMappingURL=tolgee.esm.min.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@tolgee/core"]={})}(this,(function(e){"use strict";function n(e){return Boolean(e&&"function"==typeof e.then)}function t(e,t){return n(e)?Promise.resolve(e).then(t):t(e)}function a(e,t,a){function i(n){const a=t(n);throw e.emit(a),console.error(a),a}try{const e=a();return n(e)?e.catch(i):e}catch(e){i(e)}}function i(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function o(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function r(e){return o(e)||[]}function s(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?r(n):r(null==n?void 0:n[e]);var t}function g(e){return Array.from(new Set(e))}function c(e){return e?e.replace(/\/+$/,""):e}const l=(e,n)=>fetch(e,n),u=(e=l)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.23.3"},null==t?void 0:t.headers)}));function d(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function f(e,n,t){const a=new Set,i=new Set;let o=[];function s(){if(0===o.length)return;const e=o;o=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(o.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(r(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class p extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class h extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const m=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):m(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},b=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},y=({language:e,namespace:n})=>n?`${e}:${n}`:e;function L(e,t,a,i,o,s,c){const l=new Map,u=new Map;let d={},f=0;function v(n,t,a){const i=y(n);u.set(i,{data:m(t),version:a}),e.onCacheChange.emit(n)}async function h(i,o){let r;if(o)try{r=await a(i)}catch(n){const t=new p(i,n,!0);e.onError.emit(t),console.warn(t)}return r||(r=await async function(a){let i;const o=d[y(a)];return"function"==typeof o&&(i=o()),i||(i=t(a)),n(i)?null==i?void 0:i.catch((n=>{const t=new p(a,n);throw e.onError.emit(t),console.error(t),t})):i}(i)),r}const L=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=b(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),f+=1},addRecord(e,n){v(e,n,f)},exists(e,n=!1){const t=u.get(y(e));return t&&n?t.version===f:Boolean(t)},getRecord(e){var n;return null===(n=u.get(y(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(y(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(y({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return g(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(y({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(n,t,a){var i;const o=null===(i=u.get(y(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.onCacheChange.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching(e){if(o())return!0;if(void 0===e)return l.size>0;const n=r(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(b(e).namespace))))},isLoading(e,n){const t=r(n);return Boolean(o()||Array.from(l.keys()).find((n=>{const a=b(n);return(!t.length||t.includes(a.namespace))&&!L.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const t=e.map((e=>{const t=i(e),a=y(t),o=l.get(a);if(o)return{new:!1,promise:o,keyObject:t,cacheKey:a};const r=h(t,n)||Promise.resolve(void 0);return l.set(a,r),{new:!0,promise:r,keyObject:t,cacheKey:a}}));s.notify(),c.notify();const a=await Promise.all(t.map((e=>e.promise)));return t.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=a[n];t?L.addRecord(e.keyObject,t):L.getRecord(e.keyObject)||L.addRecord(e.keyObject,{})}})),s.notify(),c.notify(),t.map((e=>L.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},b(e)),{data:n.data})))});return L}function O(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const j="invalid",k={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:j,apiUrl:"https://app.tolgee.io",fetch:u(),onTranslationMissing:({key:e})=>e},w=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function E(e,n){const t=w(k,null==n?void 0:n.initialOptions,e);return t.apiUrl=c(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=u(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function R(e,n,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,target:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},f=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function p(e){const n=s({key:e.key,ns:e.ns});return C.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:n().fetch}}function b(e){u.observer=null==e?void 0:e()}function y(){return Boolean(u.observer)}function L(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function w(e){l.ui=e}function E(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function D(e){u.languageDetector=e}function F(e){e&&u.backends.push(e)}function N(e){u.devBackend=e}const C=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:L,setObserver:b,hasObserver:y,setUi:w,hasUi:E,setDevBackend:N,addBackend:F,setLanguageDetector:D,setLanguageStorage:R}))},findPositions:f,run(){var e,t;const{apiKey:a,apiUrl:i,projectId:o,observerOptions:r}=n();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:a,apiUrl:i,projectId:o,highlight:C.highlight,changeTranslation:g,findPositions:f,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(t=u.observer)||void 0===t||t.run({mouseHighlight:!0,options:r,translate:p,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return t(a(c.onError,(e=>new h("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return a(c.onError,(e=>new v("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>a(c.onError,(e=>new h("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:async({language:e,namespace:n})=>{for(const t of u.backends){const a=await t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:async({language:e,namespace:t})=>{var a;const{apiKey:i,apiUrl:o,projectId:r}=n();return null===(a=u.devBackend)||void 0===a?void 0:a.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:t},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(C.getDevBackend()),formatTranslation(t){var a,{formatEnabled:i}=t,o=O(t,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:f}=o,p=null!=s?s:g;let v="";null==s&&(v=n().onTranslationMissing(o));let h=null!=p?p:f?"":v;const m=e(),b=i||!(null===(a=u.observer)||void 0===a?void 0:a.outputNotFormattable),y=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=y(h);try{if(p&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&p&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const t=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||j,a=n().onFormatError,i=typeof a;h="string"===i?a:"function"===i?a(t,o):j,h=y(h)}var L;return h}});return C}const D=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const F=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=O(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function N({options:e}){const a=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:d(a),onLanguageChange:d(a),onLoadingChange:d(a),onFetchingChange:d(a),onInitialLoaded:d(a),onRunningChange:d(a),onCacheChange:d(a),onUpdate:f(a,e,n),onPermanentChange:d(a),onError:d(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(m,y),o=D(!1,(()=>v.isFetching()),a.onFetchingChange.emit),l=D(!1,(()=>A.isLoading()),a.onLoadingChange.emit),u=function(e,n,t){let a,i=E();const o=Object.freeze({init(e){i=E(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||o.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){r(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){r(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>g([...i.initialOptions.ns||[i.initialOptions.defaultNs],...r(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||o.getLanguage();return n?g([n,...s(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>r(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>b(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?o.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:c(e.apiUrl)}):void 0}});return o}(a.onLanguageChange,a.onPendingLanguageChange,a.onRunningChange),p=R(u.getLanguage,u.getInitialOptions,u.getAvailableLanguages,O,C,P,k,a),v=L(a,p.getBackendRecord,p.getBackendDevRecord,u.withDefaultNs,u.isInitialLoading,o,l);let h;function m(){return u.getFallbackNs()}function y(e){return u.getDefaultNs(e)}function O(e){return[...r(y(e)),...m()]}function j(e){return[...r(null!=e?e:y()),...u.getRequiredNamespaces()]}function k(e,n,t){const a=u.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function w(e){u.init(e),v.addStaticData(u.getInitialOptions().staticData)}function N(e,n){const a=function(e,n){const t=u.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,n);if(a.length)return t(A.loadRecords(a),(()=>{}))}function C({key:e,ns:n}){const t=u.getFallbackLangs(),a=O(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function P({key:e,ns:n,language:t}){const a=O(null!=n?n:void 0),i=u.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function T(){const e=t(function(){if(u.getLanguage())return;return t(p.getInitialLanguage(),(e=>{const n=e||u.getInitialOptions().defaultLanguage;n&&u.setLanguage(n)}))}(),(()=>N()));if(n(e))return u.setInitialLoading(!0),o.notify(),l.notify(),Promise.resolve(e).then((()=>{u.setInitialLoading(!1),o.notify(),l.notify(),a.onInitialLoaded.emit()}));a.onInitialLoaded.emit()}e&&w(e),a.onUpdate.listen((()=>{u.isRunning()&&p.retranslate()}));const A=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},a),u),p),v),{init:w,getTranslation:P,changeTranslation:k,getTranslationNs:C,getDefaultAndFallbackNs:O,findPositions:p.findPositions,async changeLanguage(e){u.getPendingLanguage()===e&&u.getLanguage()===e||(u.setPendingLanguage(e),u.isRunning()&&await N(e),e===u.getPendingLanguage()&&(u.setLanguage(e),await p.setStoredLanguage(e)))},async addActiveNs(e,n){n||u.addActiveNs(e),u.isRunning()&&await N(void 0,e)},loadRecords:e=>v.loadRecords(e,A.isDev()),loadRecord:async e=>(await A.loadRecords([e]))[0],isLoading:e=>v.isLoading(u.getLanguage(),e),isLoaded(e){const n=u.getLanguage();if(!n)return!1;const t=u.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=F(...e),t=P(n);return p.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(u.getInitialOptions().apiKey&&u.getInitialOptions().apiUrl),run:()=>(function(){if((p.getLanguageDetector()||p.getLanguageStorage())&&!u.getAvailableLanguages())throw new Error(i("availableLanguages"));if(!u.getLanguage()&&!u.getInitialOptions().defaultLanguage)throw new Error(i(["defaultLanguage","language"]))}(),u.isRunning()||(u.setRunning(!0),p.run(),h=T()),Promise.resolve(h)),stop(){u.isRunning()&&(p.stop(),u.setRunning(!1))}}));return A}const C=0,P=1,T=2;class A extends Error{constructor(e,n,t){let a;a=e===C?"Empty parameter":e===P?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function S(e){return/\s/.test(e)}const I=0,U=1,x=2,B=3,z=4,K=new Set([x,U,I]),$="'",M=new Set(["{","}",$]),V=e=>/[0-9a-zA-Z_]/.test(e);function W(e,n){const[t,a]=function(e){let n=I,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new A(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(C),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case I:i===$?(t+=i,n=U):"{"===i?(c(),n=B):(t+=i,n=I);break;case U:M.has(i)?(t=t.slice(0,-1)+i,n=x):(t+=i,n=I);break;case x:i===$?n=I:(t+=i,n=x);break;case B:"}"===i?(l(),n=I):S(i)?""!==a&&(l(),n=z):(V(i)||g(P),a+=i,n=B);break;case z:"}"==i?n=I:S(i)?n=z:g(P)}return K.has(n)||g(T),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}e.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>W(e,n)}),e),e.LanguageDetectorError=v,e.LanguageStorageError=h,e.RecordFetchError=p,e.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=w(e.options,t),n),init(n){const t=function(e){const n=N({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,findPositions:n.findPositions,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(w(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},e.createFetchFunction=u,e.getFallback=o,e.getFallbackArray=r,e.getTranslateProps=F,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@tolgee/core"]={})}(this,(function(e){"use strict";function n(e){return Boolean(e&&"function"==typeof e.then)}function t(e,t){return n(e)?Promise.resolve(e).then(t):t(e)}function a(e,t,a){function i(n){const a=t(n);throw e.emit(a),console.error(a),a}try{const e=a();return n(e)?e.catch(i):e}catch(e){i(e)}}function i(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function o(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function r(e){return o(e)||[]}function s(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?r(n):r(null==n?void 0:n[e]);var t}function g(e){return Array.from(new Set(e))}function c(e){return e?e.replace(/\/+$/,""):e}const l=(e,n)=>fetch(e,n),u=(e=l)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.24.0"},null==t?void 0:t.headers)}));function d(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function f(e,n,t){const a=new Set,i=new Set;let o=[];function s(){if(0===o.length)return;const e=o;o=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(o.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(r(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class p extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class h extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const m=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):m(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},b=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},y=({language:e,namespace:n})=>n?`${e}:${n}`:e;function L(e,t,a,i,o,s,c){const l=new Map,u=new Map;let d={},f=0;function v(n,t,a){const i=y(n);u.set(i,{data:m(t),version:a}),e.onCacheChange.emit(n)}async function h(i,o){let r;if(o)try{r=await a(i)}catch(n){const t=new p(i,n,!0);e.onError.emit(t),console.warn(t)}return r||(r=await async function(a){let i;const o=d[y(a)];return"function"==typeof o&&(i=o()),i||(i=t(a)),n(i)?null==i?void 0:i.catch((n=>{const t=new p(a,n);throw e.onError.emit(t),console.error(t),t})):i}(i)),r}const L=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=b(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),f+=1},addRecord(e,n){v(e,n,f)},exists(e,n=!1){const t=u.get(y(e));return t&&n?t.version===f:Boolean(t)},getRecord(e){var n;return null===(n=u.get(y(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(y(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(y({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return g(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(y({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(n,t,a){var i;const o=null===(i=u.get(y(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.onCacheChange.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching(e){if(o())return!0;if(void 0===e)return l.size>0;const n=r(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(b(e).namespace))))},isLoading(e,n){const t=r(n);return Boolean(o()||Array.from(l.keys()).find((n=>{const a=b(n);return(!t.length||t.includes(a.namespace))&&!L.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const t=e.map((e=>{const t=i(e),a=y(t),o=l.get(a);if(o)return{new:!1,promise:o,keyObject:t,cacheKey:a};const r=h(t,n)||Promise.resolve(void 0);return l.set(a,r),{new:!0,promise:r,keyObject:t,cacheKey:a}}));s.notify(),c.notify();const a=await Promise.all(t.map((e=>e.promise)));return t.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=a[n];t?L.addRecord(e.keyObject,t):L.getRecord(e.keyObject)||L.addRecord(e.keyObject,{})}})),s.notify(),c.notify(),t.map((e=>L.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},b(e)),{data:n.data})))});return L}function O(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const j="invalid",k={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:j,apiUrl:"https://app.tolgee.io",fetch:u(),onTranslationMissing:({key:e})=>e},w=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function E(e,n){const t=w(k,null==n?void 0:n.initialOptions,e);return t.apiUrl=c(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=u(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function R(e,n,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,target:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},f=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function p(e){const n=s({key:e.key,ns:e.ns});return C.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:n().fetch}}function b(e){u.observer=null==e?void 0:e()}function y(){return Boolean(u.observer)}function L(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function w(e){l.ui=e}function E(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function D(e){u.languageDetector=e}function F(e){e&&u.backends.push(e)}function N(e){u.devBackend=e}const C=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:L,setObserver:b,hasObserver:y,setUi:w,hasUi:E,setDevBackend:N,addBackend:F,setLanguageDetector:D,setLanguageStorage:R}))},findPositions:f,run(){var e,t;const{apiKey:a,apiUrl:i,projectId:o,observerOptions:r}=n();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:a,apiUrl:i,projectId:o,highlight:C.highlight,changeTranslation:g,findPositions:f,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(t=u.observer)||void 0===t||t.run({mouseHighlight:!0,options:r,translate:p,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return t(a(c.onError,(e=>new h("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return a(c.onError,(e=>new v("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>a(c.onError,(e=>new h("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:async({language:e,namespace:n})=>{for(const t of u.backends){const a=await t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:async({language:e,namespace:t})=>{var a;const{apiKey:i,apiUrl:o,projectId:r}=n();return null===(a=u.devBackend)||void 0===a?void 0:a.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:t},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(C.getDevBackend()),formatTranslation(t){var a,{formatEnabled:i}=t,o=O(t,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:f}=o,p=null!=s?s:g;let v="";null==s&&(v=n().onTranslationMissing(o));let h=null!=p?p:f?"":v;const m=e(),b=i||!(null===(a=u.observer)||void 0===a?void 0:a.outputNotFormattable),y=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=y(h);try{if(p&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&p&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const t=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||j,a=n().onFormatError,i=typeof a;h="string"===i?a:"function"===i?a(t,o):j,h=y(h)}var L;return h}});return C}const D=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const F=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=O(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function N({options:e}){const a=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:d(a),onLanguageChange:d(a),onLoadingChange:d(a),onFetchingChange:d(a),onInitialLoaded:d(a),onRunningChange:d(a),onCacheChange:d(a),onUpdate:f(a,e,n),onPermanentChange:d(a),onError:d(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(m,y),o=D(!1,(()=>v.isFetching()),a.onFetchingChange.emit),l=D(!1,(()=>A.isLoading()),a.onLoadingChange.emit),u=function(e,n,t){let a,i=E();const o=Object.freeze({init(e){i=E(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||o.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){r(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){r(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>g([...i.initialOptions.ns||[i.initialOptions.defaultNs],...r(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||o.getLanguage();return n?g([n,...s(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>r(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>b(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?o.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:c(e.apiUrl)}):void 0}});return o}(a.onLanguageChange,a.onPendingLanguageChange,a.onRunningChange),p=R(u.getLanguage,u.getInitialOptions,u.getAvailableLanguages,O,C,P,k,a),v=L(a,p.getBackendRecord,p.getBackendDevRecord,u.withDefaultNs,u.isInitialLoading,o,l);let h;function m(){return u.getFallbackNs()}function y(e){return u.getDefaultNs(e)}function O(e){return[...r(y(e)),...m()]}function j(e){return[...r(null!=e?e:y()),...u.getRequiredNamespaces()]}function k(e,n,t){const a=u.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function w(e){u.init(e),v.addStaticData(u.getInitialOptions().staticData)}function N(e,n){const a=function(e,n){const t=u.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,n);if(a.length)return t(A.loadRecords(a),(()=>{}))}function C({key:e,ns:n}){const t=u.getFallbackLangs(),a=O(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function P({key:e,ns:n,language:t}){const a=O(null!=n?n:void 0),i=u.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function T(){const e=t(function(){if(u.getLanguage())return;return t(p.getInitialLanguage(),(e=>{const n=e||u.getInitialOptions().defaultLanguage;n&&u.setLanguage(n)}))}(),(()=>N()));if(n(e))return u.setInitialLoading(!0),o.notify(),l.notify(),Promise.resolve(e).then((()=>{u.setInitialLoading(!1),o.notify(),l.notify(),a.onInitialLoaded.emit()}));a.onInitialLoaded.emit()}e&&w(e),a.onUpdate.listen((()=>{u.isRunning()&&p.retranslate()}));const A=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},a),u),p),v),{init:w,getTranslation:P,changeTranslation:k,getTranslationNs:C,getDefaultAndFallbackNs:O,findPositions:p.findPositions,async changeLanguage(e){u.getPendingLanguage()===e&&u.getLanguage()===e||(u.setPendingLanguage(e),u.isRunning()&&await N(e),e===u.getPendingLanguage()&&(u.setLanguage(e),await p.setStoredLanguage(e)))},async addActiveNs(e,n){n||u.addActiveNs(e),u.isRunning()&&await N(void 0,e)},loadRecords:e=>v.loadRecords(e,A.isDev()),loadRecord:async e=>(await A.loadRecords([e]))[0],isLoading:e=>v.isLoading(u.getLanguage(),e),isLoaded(e){const n=u.getLanguage();if(!n)return!1;const t=u.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=F(...e),t=P(n);return p.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(u.getInitialOptions().apiKey&&u.getInitialOptions().apiUrl),run:()=>(function(){if((p.getLanguageDetector()||p.getLanguageStorage())&&!u.getAvailableLanguages())throw new Error(i("availableLanguages"));if(!u.getLanguage()&&!u.getInitialOptions().defaultLanguage)throw new Error(i(["defaultLanguage","language"]))}(),u.isRunning()||(u.setRunning(!0),p.run(),h=T()),Promise.resolve(h)),stop(){u.isRunning()&&(p.stop(),u.setRunning(!1))}}));return A}const C=0,P=1,T=2;class A extends Error{constructor(e,n,t){let a;a=e===C?"Empty parameter":e===P?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function S(e){return/\s/.test(e)}const I=0,U=1,x=2,B=3,z=4,K=new Set([x,U,I]),$="'",M=new Set(["{","}",$]),V=e=>/[0-9a-zA-Z_]/.test(e);function W(e,n){const[t,a]=function(e){let n=I,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new A(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(C),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case I:i===$?(t+=i,n=U):"{"===i?(c(),n=B):(t+=i,n=I);break;case U:M.has(i)?(t=t.slice(0,-1)+i,n=x):(t+=i,n=I);break;case x:i===$?n=I:(t+=i,n=x);break;case B:"}"===i?(l(),n=I):S(i)?""!==a&&(l(),n=z):(V(i)||g(P),a+=i,n=B);break;case z:"}"==i?n=I:S(i)?n=z:g(P)}return K.has(n)||g(T),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}e.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>W(e,n)}),e),e.LanguageDetectorError=v,e.LanguageStorageError=h,e.RecordFetchError=p,e.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=w(e.options,t),n),init(n){const t=function(e){const n=N({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,findPositions:n.findPositions,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(w(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},e.createFetchFunction=u,e.getFallback=o,e.getFallbackArray=r,e.getTranslateProps=F,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=tolgee.umd.min.js.map |
{ | ||
"name": "@tolgee/core", | ||
"version": "5.23.3", | ||
"version": "5.24.0", | ||
"description": "Library providing ability to translate messages directly in context of developed application.", | ||
@@ -74,3 +74,3 @@ "main": "./dist/tolgee.cjs.js", | ||
"sideEffects": false, | ||
"gitHead": "6cbf0126c2765a49d4d04abb99b4d00fce6d89f2" | ||
"gitHead": "77a60a1a6d863b44ea098b566fcbcfda9b60d8a1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package