New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tolgee/core

Package Overview
Dependencies
Maintainers
2
Versions
361
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tolgee/core - npm Package Compare versions

Comparing version 5.10.1 to 5.10.2-prerelease.2a0213ec.0

36

./dist/tolgee.cjs.js

@@ -185,2 +185,3 @@ 'use strict';

onUpdate: EventEmitterSelective(isActive, getFallbackNs, getDefaultNs),
onPermanentChange: EventEmitter(isActive),
setEmitterActive(active) {

@@ -207,2 +208,4 @@ emitterActive = active;

return self.onUpdate.listen(handler);
case 'permanentChange':
return self.onPermanentChange.listen(handler);
}

@@ -482,2 +485,3 @@ }),

passToParent: ['option', 'optgroup'],
fullKeyEncode: false,
};

@@ -493,2 +497,3 @@

apiUrl: DEFAULT_API_URL,
fetch: (input, options) => fetch(input, options),
};

@@ -516,3 +521,3 @@ const combineOptions = (...states) => {

function Plugins(getLanguage, getInitialOptions, getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation) {
function Plugins(getLanguage, getInitialOptions, getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation, onPermanentChange) {
const plugins = {

@@ -557,2 +562,5 @@ ui: undefined,

}
function getCommonProps() {
return { fetch: getInitialOptions().fetch };
}
function setObserver(observer) {

@@ -589,5 +597,3 @@ instances.observer = observer === null || observer === void 0 ? void 0 : observer();

const availableLanguages = getAvailableLanguages();
return instances.languageDetector.getLanguage({
availableLanguages,
});
return instances.languageDetector.getLanguage(Object.assign({ availableLanguages }, getCommonProps()));
}

@@ -629,2 +635,3 @@ function addBackend(backend) {

findPositions,
onPermanentChange,
});

@@ -649,3 +656,3 @@ (_b = instances.observer) === null || _b === void 0 ? void 0 : _b.run({

const availableLanguages = getAvailableLanguages();
const languageOrPromise = (_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.getLanguage();
const languageOrPromise = (_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.getLanguage(getCommonProps());
return valueOrPromise(languageOrPromise, (language) => {

@@ -661,3 +668,3 @@ if ((!availableLanguages || availableLanguages.includes(language)) &&

var _a;
(_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.setLanguage(language);
(_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.setLanguage(language, getCommonProps());
},

@@ -669,3 +676,4 @@ getDevBackend() {

for (const backend of instances.backends) {
const data = backend.getRecord({ language, namespace });
const data = backend.getRecord(Object.assign({ language,
namespace }, getCommonProps()));
if (isPromise(data)) {

@@ -687,9 +695,7 @@ return data === null || data === void 0 ? void 0 : data.catch((e) => {

const { apiKey, apiUrl, projectId } = getInitialOptions();
return (_a = instances.devBackend) === null || _a === void 0 ? void 0 : _a.getRecord({
apiKey,
return (_a = instances.devBackend) === null || _a === void 0 ? void 0 : _a.getRecord(Object.assign({ apiKey,
apiUrl,
projectId,
language,
namespace,
});
namespace }, getCommonProps()));
}),

@@ -962,3 +968,3 @@ getLanguageDetector() {

const state = State(events.onLanguageChange, events.onPendingLanguageChange, events.onRunningChange);
const pluginService = Plugins(state.getLanguage, state.getInitialOptions, state.getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation);
const pluginService = Plugins(state.getLanguage, state.getInitialOptions, state.getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation, onPermanentChange);
const cache = Cache(events.onCacheChange, pluginService.getBackendRecord, pluginService.getBackendDevRecord, state.withDefaultNs, state.isInitialLoading, fetchingObserver, loadingObserver);

@@ -1002,2 +1008,8 @@ if (options) {

}
function onPermanentChange(props) {
events.onPermanentChange.emit({
key: props.key,
namespace: props.namespace,
});
}
function init(options) {

@@ -1004,0 +1016,0 @@ state.init(options);

@@ -185,2 +185,3 @@ 'use strict';

onUpdate: EventEmitterSelective(isActive, getFallbackNs, getDefaultNs),
onPermanentChange: EventEmitter(isActive),
setEmitterActive(active) {

@@ -207,2 +208,4 @@ emitterActive = active;

return self.onUpdate.listen(handler);
case 'permanentChange':
return self.onPermanentChange.listen(handler);
}

@@ -482,2 +485,3 @@ }),

passToParent: ['option', 'optgroup'],
fullKeyEncode: false,
};

@@ -493,2 +497,3 @@

apiUrl: DEFAULT_API_URL,
fetch: (input, options) => fetch(input, options),
};

@@ -516,3 +521,3 @@ const combineOptions = (...states) => {

function Plugins(getLanguage, getInitialOptions, getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation) {
function Plugins(getLanguage, getInitialOptions, getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation, onPermanentChange) {
const plugins = {

@@ -557,2 +562,5 @@ ui: undefined,

}
function getCommonProps() {
return { fetch: getInitialOptions().fetch };
}
function setObserver(observer) {

@@ -589,5 +597,3 @@ instances.observer = observer === null || observer === void 0 ? void 0 : observer();

const availableLanguages = getAvailableLanguages();
return instances.languageDetector.getLanguage({
availableLanguages,
});
return instances.languageDetector.getLanguage(Object.assign({ availableLanguages }, getCommonProps()));
}

@@ -629,2 +635,3 @@ function addBackend(backend) {

findPositions,
onPermanentChange,
});

@@ -649,3 +656,3 @@ (_b = instances.observer) === null || _b === void 0 ? void 0 : _b.run({

const availableLanguages = getAvailableLanguages();
const languageOrPromise = (_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.getLanguage();
const languageOrPromise = (_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.getLanguage(getCommonProps());
return valueOrPromise(languageOrPromise, (language) => {

@@ -661,3 +668,3 @@ if ((!availableLanguages || availableLanguages.includes(language)) &&

var _a;
(_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.setLanguage(language);
(_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.setLanguage(language, getCommonProps());
},

@@ -669,3 +676,4 @@ getDevBackend() {

for (const backend of instances.backends) {
const data = backend.getRecord({ language, namespace });
const data = backend.getRecord(Object.assign({ language,
namespace }, getCommonProps()));
if (isPromise(data)) {

@@ -687,9 +695,7 @@ return data === null || data === void 0 ? void 0 : data.catch((e) => {

const { apiKey, apiUrl, projectId } = getInitialOptions();
return (_a = instances.devBackend) === null || _a === void 0 ? void 0 : _a.getRecord({
apiKey,
return (_a = instances.devBackend) === null || _a === void 0 ? void 0 : _a.getRecord(Object.assign({ apiKey,
apiUrl,
projectId,
language,
namespace,
});
namespace }, getCommonProps()));
}),

@@ -962,3 +968,3 @@ getLanguageDetector() {

const state = State(events.onLanguageChange, events.onPendingLanguageChange, events.onRunningChange);
const pluginService = Plugins(state.getLanguage, state.getInitialOptions, state.getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation);
const pluginService = Plugins(state.getLanguage, state.getInitialOptions, state.getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation, onPermanentChange);
const cache = Cache(events.onCacheChange, pluginService.getBackendRecord, pluginService.getBackendDevRecord, state.withDefaultNs, state.isInitialLoading, fetchingObserver, loadingObserver);

@@ -1002,2 +1008,8 @@ if (options) {

}
function onPermanentChange(props) {
events.onPermanentChange.emit({
key: props.key,
namespace: props.namespace,
});
}
function init(options) {

@@ -1004,0 +1016,0 @@ state.init(options);

@@ -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(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 a(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function i(e){return a(e)||[]}function o(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?i(n):i(null==n?void 0:n[e]);var t}function r(e){return Array.from(new Set(e))}function s(e){return e?e.replace(/\/+$/,""):e}function g(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 c(e,n,t){const a=new Set,o=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());o.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};o.add(n);const a={unsubscribe:()=>{o.delete(n)},subscribeNs:e=>(i(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}Object.defineProperty(exports,"__esModule",{value:!0});const l=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):l(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},u=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},d=({language:e,namespace:n})=>n?`${e}:${n}`:e;function p(e,n,t,a,o,s,g){const c=new Map,p=new Map;let f={},v=0;function h(n,t,a){const i=d(n);p.set(i,{data:l(t),version:a}),e.emit(n)}function b(e){let t;if(!t){const n=f[d(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}const m=Object.freeze({addStaticData(e){e&&(f=Object.assign(Object.assign({},f),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=u(e),a=p.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate(){c.clear(),v+=1},addRecord(e,n){h(e,n,v)},exists(e,n=!1){const t=p.get(d(e));return t&&n?t.version===v:Boolean(t)},getRecord(e){var n;return null===(n=p.get(d(a(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=p.get(d(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=p.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return r(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=p.get(d({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=p.get(d(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching(e){if(o())return!0;if(void 0===e)return c.size>0;const n=i(e);return Boolean(Array.from(c.keys()).find((e=>n.includes(u(e).namespace))))},isLoading(e,n){const t=i(n);return Boolean(o()||Array.from(c.keys()).find((n=>{const a=u(n);return(!t.length||t.includes(a.namespace))&&!m.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const i=e.map((e=>{const i=a(e),o=d(i),r=c.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),b(e))))),i||(i=b(e)),i}(i,n)||Promise.resolve(void 0);return c.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));s.notify(),g.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=c.get(e.cacheKey)!==e.promise;if(e.new&&!t){c.delete(e.cacheKey);const t=o[n];t?m.addRecord(e.keyObject,t):m.getRecord(e.keyObject)||m.addRecord(e.keyObject,{})}})),s.notify(),g.notify(),i.map((e=>m.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(p.entries()).map((([e,n])=>Object.assign(Object.assign({},u(e)),{data:n.data})))});return m}function f(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 v="invalid",h={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"]},observerType:"invisible",onFormatError:v,apiUrl:"https://app.tolgee.io"},b=(...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 m(e,n){const t=b(h,null==n?void 0:n.initialOptions,e);return t.apiUrl=s(t.apiUrl),{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 y(t,a,i,o,r,s){const g={ui:void 0},c={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},l=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=c.ui)||void 0===t||t.handleElementClick(a,n)},u=(e,n)=>{var t;return(null===(t=c.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function d(e){const n=r({key:e.key,ns:e.ns});return w.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function p(e){c.observer=null==e?void 0:e()}function h(){return Boolean(c.observer)}function b(e){e&&c.formatters.push(e)}function m(e){c.finalFormatter=e}function y(e){g.ui=e}function L(){return Boolean(g.ui)}function O(e){c.languageStorage=e}function j(e){c.languageDetector=e}function k(e){e&&c.backends.push(e)}function R(e){c.devBackend=e}const w=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:m,addFormatter:b,setObserver:p,hasObserver:h,setUi:y,hasUi:L,setDevBackend:R,addBackend:k,setLanguageDetector:j,setLanguageStorage:O}))},run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();c.ui=null===(e=g.ui)||void 0===e?void 0:e.call(g,{apiKey:t,apiUrl:i,projectId:o,highlight:w.highlight,changeTranslation:s,findPositions:u}),null===(n=c.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:d,onClick:l})},stop(){var e;c.ui=void 0,null===(e=c.observer)||void 0===e||e.stop()},getLanguageStorage:()=>c.languageStorage,getInitialLanguage(){var e;const t=i();return n(null===(e=c.languageStorage)||void 0===e?void 0:e.getLanguage(),(e=>t&&!t.includes(e)||!e?function(){if(!c.languageDetector)return;const e=i();return c.languageDetector.getLanguage({availableLanguages:e})}():e))},setStoredLanguage(e){var n;null===(n=c.languageStorage)||void 0===n||n.setLanguage(e)},getDevBackend:()=>c.devBackend,getBackendRecord:({language:n,namespace:t})=>{for(const a of c.backends){const i=a.getRecord({language:n,namespace:t});if(e(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=c.devBackend)||void 0===t?void 0:t.getRecord({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n})},getLanguageDetector:()=>c.languageDetector,retranslate(){var e;null===(e=c.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=c.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(w.getDevBackend()),formatTranslation(e){var n,{formatEnabled:i}=e,o=f(e,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:l,params:u,orEmpty:d,ns:p}=o,h=s||g;let b=h||(d?"":r);const m=t(),y=i||!(null===(n=c.observer)||void 0===n?void 0:n.outputNotFormattable),L=e=>c.observer&&!l?c.observer.wrap({key:r,translation:e,defaultValue:g,params:u,ns:p}):e;b=L(b);try{if(h&&m&&y)for(const e of c.formatters)b=e.format({translation:b,language:m,params:u});c.finalFormatter&&h&&m&&y&&(b=c.finalFormatter.format({translation:b,language:m,params:u}))}catch(e){console.error(e);const n=("string"==typeof(O=e)?O:"string"==typeof(null==O?void 0:O.message)?O.message:void 0)||v,t=a().onFormatError,i=typeof t;b="string"===i?t:"function"===i?t(n,o):v,b=L(b)}var O;return b}});return w}const L=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const O=(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=f(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 j({options:a}){const l=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:g(a),onLanguageChange:g(a),onLoadingChange:g(a),onFetchingChange:g(a),onInitialLoaded:g(a),onRunningChange:g(a),onCacheChange:g(a),onUpdate:c(a,e,n),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)}}});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}(j,k),d=L(!1,(()=>b.isFetching()),l.onFetchingChange.emit),f=L(!1,(()=>F.isLoading()),l.onLoadingChange.emit),v=function(e,n,t){let a,g=m();const c=Object.freeze({init(e){g=m(e,g)},isRunning:()=>g.isRunning,setRunning(e){g.isRunning!==e&&(g.isRunning=e,t.emit(e))},isInitialLoading:()=>g.isInitialLoading,setInitialLoading(e){g.isInitialLoading=e},getLanguage:()=>g.language||g.initialOptions.language,setLanguage(n){g.language!==n&&(g.language=n,e.emit(n))},getPendingLanguage:()=>g.pendingLanguage||c.getLanguage(),setPendingLanguage(e){g.pendingLanguage!==e&&(g.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},g.initialOptions),a),addActiveNs(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n?g.activeNamespaces.set(e,n+1):g.activeNamespaces.set(e,1)}))},removeActiveNs(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n&&n>1?g.activeNamespaces.set(e,n-1):g.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>r([...g.initialOptions.ns||[g.initialOptions.defaultNs],...i(g.initialOptions.fallbackNs),...g.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?r([n,...o(n,g.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>i(g.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?g.initialOptions.defaultNs:e,getAvailableLanguages(){if(g.initialOptions.availableLanguages)return g.initialOptions.availableLanguages;if(g.initialOptions.staticData){const e=Object.keys(g.initialOptions.staticData).map((e=>u(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:s(e.apiUrl)}):void 0}});return c}(l.onLanguageChange,l.onPendingLanguageChange,l.onRunningChange),h=y(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=R(n||void 0);return b.getTranslationNs(a,t,e)}),D,E),b=p(l.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,d,f);function j(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function R(e){return[...i(k(e)),...j()]}function w(e){return[...i(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=b.getTranslation(a,n);return b.changeTranslation(a,n,t),{revert(){b.changeTranslation(a,n,i)}}}function N(e){v.init(e),b.addStaticData(v.getInitialOptions().staticData)}function A(e,t){const a=function(e,n){const t=v.getFallbackLangs(e),a=w(n),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(F.loadRecords(a),(()=>{}))}function D({key:e,ns:n,language:t}){const a=R(n||void 0),i=v.getFallbackLangs(t);return b.getTranslationFallback(a,i,e)}function I(){const t=n(function(){if(v.getLanguage())return;return n(h.getInitialLanguage(),(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>A()));if(e(t))return v.setInitialLoading(!0),d.notify(),f.notify(),Promise.resolve(t).then((()=>{v.setInitialLoading(!1),d.notify(),f.notify(),l.onInitialLoaded.emit()}));l.onInitialLoaded.emit()}a&&N(a),l.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const F=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},l),v),h),b),{init:N,getTranslation:D,changeTranslation:E,async changeLanguage(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await A(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},async addActiveNs(e,n){n||v.addActiveNs(e),v.isRunning()&&await A(void 0,e)},loadRecords:e=>b.loadRecords(e,F.isDev()),loadRecord:async e=>(await F.loadRecords([e]))[0],isLoading:e=>b.isLoading(v.getLanguage(),e),isLoaded(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=w(e),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=O(...e),t=D(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl),run(){let e;return function(){if((h.getLanguageDetector()||h.getLanguageStorage())&&!v.getAvailableLanguages())throw new Error(t("availableLanguages"));if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw new Error(t(["defaultLanguage","language"]))}(),v.isRunning()||(v.setRunning(!0),h.run(),e=I()),Promise.resolve(e)},stop(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}));return F}const k=0,R=1,w=2;class E extends Error{constructor(e,n,t){let a;a=e===k?"Empty parameter":e===R?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function N(e){return/\s/.test(e)}const A=0,D=1,I=2,F=3,C=4,S=new Set([I,D,A]),P="'",T=new Set(["{","}",P]),U=e=>/[0-9a-zA-Z_]/.test(e);function x(e,n){const[t,a]=function(e){let n=A,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new E(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(k),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case A:i===P?(t+=i,n=D):"{"===i?(c(),n=F):(t+=i,n=A);break;case D:T.has(i)?(t=t.slice(0,-1)+i,n=I):(t+=i,n=A);break;case I:i===P?n=A:(t+=i,n=I);break;case F:"}"===i?(l(),n=A):N(i)?""!==a&&(l(),n=C):(U(i)||g(R),a+=i,n=F);break;case C:"}"==i?n=A:N(i)?n=C:g(R)}return S.has(n)||g(w),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})=>x(e,n)}),e),exports.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=b(e.options,t),n),init(n){const t=function(e){const n=j({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,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}(b(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},exports.getFallback=a,exports.getFallbackArray=i,exports.getTranslateProps=O;
"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(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 a(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function i(e){return a(e)||[]}function o(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?i(n):i(null==n?void 0:n[e]);var t}function r(e){return Array.from(new Set(e))}function s(e){return e?e.replace(/\/+$/,""):e}function g(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 c(e,n,t){const a=new Set,o=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());o.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};o.add(n);const a={unsubscribe:()=>{o.delete(n)},subscribeNs:e=>(i(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}Object.defineProperty(exports,"__esModule",{value:!0});const l=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):l(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},u=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},d=({language:e,namespace:n})=>n?`${e}:${n}`:e;function p(e,n,t,a,o,s,g){const c=new Map,p=new Map;let f={},v=0;function h(n,t,a){const i=d(n);p.set(i,{data:l(t),version:a}),e.emit(n)}function m(e){let t;if(!t){const n=f[d(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}const b=Object.freeze({addStaticData(e){e&&(f=Object.assign(Object.assign({},f),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=u(e),a=p.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate(){c.clear(),v+=1},addRecord(e,n){h(e,n,v)},exists(e,n=!1){const t=p.get(d(e));return t&&n?t.version===v:Boolean(t)},getRecord(e){var n;return null===(n=p.get(d(a(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=p.get(d(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=p.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return r(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=p.get(d({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=p.get(d(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching(e){if(o())return!0;if(void 0===e)return c.size>0;const n=i(e);return Boolean(Array.from(c.keys()).find((e=>n.includes(u(e).namespace))))},isLoading(e,n){const t=i(n);return Boolean(o()||Array.from(c.keys()).find((n=>{const a=u(n);return(!t.length||t.includes(a.namespace))&&!b.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const i=e.map((e=>{const i=a(e),o=d(i),r=c.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),m(e))))),i||(i=m(e)),i}(i,n)||Promise.resolve(void 0);return c.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));s.notify(),g.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=c.get(e.cacheKey)!==e.promise;if(e.new&&!t){c.delete(e.cacheKey);const t=o[n];t?b.addRecord(e.keyObject,t):b.getRecord(e.keyObject)||b.addRecord(e.keyObject,{})}})),s.notify(),g.notify(),i.map((e=>b.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(p.entries()).map((([e,n])=>Object.assign(Object.assign({},u(e)),{data:n.data})))});return b}function f(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 v="invalid",h={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:v,apiUrl:"https://app.tolgee.io",fetch:(e,n)=>fetch(e,n)},m=(...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 b(e,n){const t=m(h,null==n?void 0:n.initialOptions,e);return t.apiUrl=s(t.apiUrl),{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 y(t,a,i,o,r,s,g){const c={ui:void 0},l={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},u=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=l.ui)||void 0===t||t.handleElementClick(a,n)},d=(e,n)=>{var t;return(null===(t=l.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function p(e){const n=r({key:e.key,ns:e.ns});return N.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function h(){return{fetch:a().fetch}}function m(e){l.observer=null==e?void 0:e()}function b(){return Boolean(l.observer)}function y(e){e&&l.formatters.push(e)}function O(e){l.finalFormatter=e}function L(e){c.ui=e}function j(){return Boolean(c.ui)}function k(e){l.languageStorage=e}function R(e){l.languageDetector=e}function w(e){e&&l.backends.push(e)}function E(e){l.devBackend=e}const N=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:O,addFormatter:y,setObserver:m,hasObserver:b,setUi:L,hasUi:j,setDevBackend:E,addBackend:w,setLanguageDetector:R,setLanguageStorage:k}))},run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();l.ui=null===(e=c.ui)||void 0===e?void 0:e.call(c,{apiKey:t,apiUrl:i,projectId:o,highlight:N.highlight,changeTranslation:s,findPositions:d,onPermanentChange:g}),null===(n=l.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:p,onClick:u})},stop(){var e;l.ui=void 0,null===(e=l.observer)||void 0===e||e.stop()},getLanguageStorage:()=>l.languageStorage,getInitialLanguage(){var e;const t=i();return n(null===(e=l.languageStorage)||void 0===e?void 0:e.getLanguage(h()),(e=>t&&!t.includes(e)||!e?function(){if(!l.languageDetector)return;const e=i();return l.languageDetector.getLanguage(Object.assign({availableLanguages:e},h()))}():e))},setStoredLanguage(e){var n;null===(n=l.languageStorage)||void 0===n||n.setLanguage(e,h())},getDevBackend:()=>l.devBackend,getBackendRecord:({language:n,namespace:t})=>{for(const a of l.backends){const i=a.getRecord(Object.assign({language:n,namespace:t},h()));if(e(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=l.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},h()))},getLanguageDetector:()=>l.languageDetector,retranslate(){var e;null===(e=l.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=l.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return l.observer?null===(n=l.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return l.observer?null===(n=l.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(N.getDevBackend()),formatTranslation(e){var n,{formatEnabled:i}=e,o=f(e,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:u,orEmpty:d,ns:p}=o,h=s||g;let m=h||(d?"":r);const b=t(),y=i||!(null===(n=l.observer)||void 0===n?void 0:n.outputNotFormattable),O=e=>l.observer&&!c?l.observer.wrap({key:r,translation:e,defaultValue:g,params:u,ns:p}):e;m=O(m);try{if(h&&b&&y)for(const e of l.formatters)m=e.format({translation:m,language:b,params:u});l.finalFormatter&&h&&b&&y&&(m=l.finalFormatter.format({translation:m,language:b,params:u}))}catch(e){console.error(e);const n=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||v,t=a().onFormatError,i=typeof t;m="string"===i?t:"function"===i?t(n,o):v,m=O(m)}var L;return m}});return N}const O=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const L=(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=f(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 j({options:a}){const l=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:g(a),onLanguageChange:g(a),onLoadingChange:g(a),onFetchingChange:g(a),onInitialLoaded:g(a),onRunningChange:g(a),onCacheChange:g(a),onUpdate:c(a,e,n),onPermanentChange:g(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)}}});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}(j,k),d=O(!1,(()=>m.isFetching()),l.onFetchingChange.emit),f=O(!1,(()=>I.isLoading()),l.onLoadingChange.emit),v=function(e,n,t){let a,g=b();const c=Object.freeze({init(e){g=b(e,g)},isRunning:()=>g.isRunning,setRunning(e){g.isRunning!==e&&(g.isRunning=e,t.emit(e))},isInitialLoading:()=>g.isInitialLoading,setInitialLoading(e){g.isInitialLoading=e},getLanguage:()=>g.language||g.initialOptions.language,setLanguage(n){g.language!==n&&(g.language=n,e.emit(n))},getPendingLanguage:()=>g.pendingLanguage||c.getLanguage(),setPendingLanguage(e){g.pendingLanguage!==e&&(g.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},g.initialOptions),a),addActiveNs(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n?g.activeNamespaces.set(e,n+1):g.activeNamespaces.set(e,1)}))},removeActiveNs(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n&&n>1?g.activeNamespaces.set(e,n-1):g.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>r([...g.initialOptions.ns||[g.initialOptions.defaultNs],...i(g.initialOptions.fallbackNs),...g.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?r([n,...o(n,g.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>i(g.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?g.initialOptions.defaultNs:e,getAvailableLanguages(){if(g.initialOptions.availableLanguages)return g.initialOptions.availableLanguages;if(g.initialOptions.staticData){const e=Object.keys(g.initialOptions.staticData).map((e=>u(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:s(e.apiUrl)}):void 0}});return c}(l.onLanguageChange,l.onPendingLanguageChange,l.onRunningChange),h=y(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=R(n||void 0);return m.getTranslationNs(a,t,e)}),A,E,(function(e){l.onPermanentChange.emit({key:e.key,namespace:e.namespace})})),m=p(l.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,d,f);function j(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function R(e){return[...i(k(e)),...j()]}function w(e){return[...i(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=m.getTranslation(a,n);return m.changeTranslation(a,n,t),{revert(){m.changeTranslation(a,n,i)}}}function N(e){v.init(e),m.addStaticData(v.getInitialOptions().staticData)}function C(e,t){const a=function(e,n){const t=v.getFallbackLangs(e),a=w(n),i=[];return t.forEach((e=>{a.forEach((n=>{m.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(I.loadRecords(a),(()=>{}))}function A({key:e,ns:n,language:t}){const a=R(n||void 0),i=v.getFallbackLangs(t);return m.getTranslationFallback(a,i,e)}function D(){const t=n(function(){if(v.getLanguage())return;return n(h.getInitialLanguage(),(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>C()));if(e(t))return v.setInitialLoading(!0),d.notify(),f.notify(),Promise.resolve(t).then((()=>{v.setInitialLoading(!1),d.notify(),f.notify(),l.onInitialLoaded.emit()}));l.onInitialLoaded.emit()}a&&N(a),l.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const I=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},l),v),h),m),{init:N,getTranslation:A,changeTranslation:E,async changeLanguage(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await C(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},async addActiveNs(e,n){n||v.addActiveNs(e),v.isRunning()&&await C(void 0,e)},loadRecords:e=>m.loadRecords(e,I.isDev()),loadRecord:async e=>(await I.loadRecords([e]))[0],isLoading:e=>m.isLoading(v.getLanguage(),e),isLoaded(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=w(e),i=[];return t.forEach((e=>{a.forEach((n=>{m.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=L(...e),t=A(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl),run(){let e;return function(){if((h.getLanguageDetector()||h.getLanguageStorage())&&!v.getAvailableLanguages())throw new Error(t("availableLanguages"));if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw new Error(t(["defaultLanguage","language"]))}(),v.isRunning()||(v.setRunning(!0),h.run(),e=D()),Promise.resolve(e)},stop(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}));return I}const k=0,R=1,w=2;class E extends Error{constructor(e,n,t){let a;a=e===k?"Empty parameter":e===R?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function N(e){return/\s/.test(e)}const C=0,A=1,D=2,I=3,F=4,P=new Set([D,A,C]),S="'",T=new Set(["{","}",S]),U=e=>/[0-9a-zA-Z_]/.test(e);function x(e,n){const[t,a]=function(e){let n=C,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new E(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(k),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case C:i===S?(t+=i,n=A):"{"===i?(c(),n=I):(t+=i,n=C);break;case A:T.has(i)?(t=t.slice(0,-1)+i,n=D):(t+=i,n=C);break;case D:i===S?n=C:(t+=i,n=D);break;case I:"}"===i?(l(),n=C):N(i)?""!==a&&(l(),n=F):(U(i)||g(R),a+=i,n=I);break;case F:"}"==i?n=C:N(i)?n=F:g(R)}return P.has(n)||g(w),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})=>x(e,n)}),e),exports.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=m(e.options,t),n),init(n){const t=function(e){const n=j({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,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}(m(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},exports.getFallback=a,exports.getFallbackArray=i,exports.getTranslateProps=L;
//# sourceMappingURL=tolgee.cjs.min.js.map

@@ -181,2 +181,3 @@ function isPromise(value) {

onUpdate: EventEmitterSelective(isActive, getFallbackNs, getDefaultNs),
onPermanentChange: EventEmitter(isActive),
setEmitterActive(active) {

@@ -203,2 +204,4 @@ emitterActive = active;

return self.onUpdate.listen(handler);
case 'permanentChange':
return self.onPermanentChange.listen(handler);
}

@@ -478,2 +481,3 @@ }),

passToParent: ['option', 'optgroup'],
fullKeyEncode: false,
};

@@ -489,2 +493,3 @@

apiUrl: DEFAULT_API_URL,
fetch: (input, options) => fetch(input, options),
};

@@ -512,3 +517,3 @@ const combineOptions = (...states) => {

function Plugins(getLanguage, getInitialOptions, getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation) {
function Plugins(getLanguage, getInitialOptions, getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation, onPermanentChange) {
const plugins = {

@@ -553,2 +558,5 @@ ui: undefined,

}
function getCommonProps() {
return { fetch: getInitialOptions().fetch };
}
function setObserver(observer) {

@@ -585,5 +593,3 @@ instances.observer = observer === null || observer === void 0 ? void 0 : observer();

const availableLanguages = getAvailableLanguages();
return instances.languageDetector.getLanguage({
availableLanguages,
});
return instances.languageDetector.getLanguage(Object.assign({ availableLanguages }, getCommonProps()));
}

@@ -625,2 +631,3 @@ function addBackend(backend) {

findPositions,
onPermanentChange,
});

@@ -645,3 +652,3 @@ (_b = instances.observer) === null || _b === void 0 ? void 0 : _b.run({

const availableLanguages = getAvailableLanguages();
const languageOrPromise = (_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.getLanguage();
const languageOrPromise = (_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.getLanguage(getCommonProps());
return valueOrPromise(languageOrPromise, (language) => {

@@ -657,3 +664,3 @@ if ((!availableLanguages || availableLanguages.includes(language)) &&

var _a;
(_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.setLanguage(language);
(_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.setLanguage(language, getCommonProps());
},

@@ -665,3 +672,4 @@ getDevBackend() {

for (const backend of instances.backends) {
const data = backend.getRecord({ language, namespace });
const data = backend.getRecord(Object.assign({ language,
namespace }, getCommonProps()));
if (isPromise(data)) {

@@ -683,9 +691,7 @@ return data === null || data === void 0 ? void 0 : data.catch((e) => {

const { apiKey, apiUrl, projectId } = getInitialOptions();
return (_a = instances.devBackend) === null || _a === void 0 ? void 0 : _a.getRecord({
apiKey,
return (_a = instances.devBackend) === null || _a === void 0 ? void 0 : _a.getRecord(Object.assign({ apiKey,
apiUrl,
projectId,
language,
namespace,
});
namespace }, getCommonProps()));
}),

@@ -958,3 +964,3 @@ getLanguageDetector() {

const state = State(events.onLanguageChange, events.onPendingLanguageChange, events.onRunningChange);
const pluginService = Plugins(state.getLanguage, state.getInitialOptions, state.getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation);
const pluginService = Plugins(state.getLanguage, state.getInitialOptions, state.getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation, onPermanentChange);
const cache = Cache(events.onCacheChange, pluginService.getBackendRecord, pluginService.getBackendDevRecord, state.withDefaultNs, state.isInitialLoading, fetchingObserver, loadingObserver);

@@ -998,2 +1004,8 @@ if (options) {

}
function onPermanentChange(props) {
events.onPermanentChange.emit({
key: props.key,
namespace: props.namespace,
});
}
function init(options) {

@@ -1000,0 +1012,0 @@ state.init(options);

@@ -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(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 a(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function i(e){return a(e)||[]}function o(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?i(n):i(null==n?void 0:n[e]);var t}function r(e){return Array.from(new Set(e))}function s(e){return e?e.replace(/\/+$/,""):e}function g(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 c(e,n,t){const a=new Set,o=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());o.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};o.add(n);const a={unsubscribe:()=>{o.delete(n)},subscribeNs:e=>(i(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}const l=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):l(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},u=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},d=({language:e,namespace:n})=>n?`${e}:${n}`:e;function p(e,n,t,a,o,s,g){const c=new Map,p=new Map;let f={},v=0;function h(n,t,a){const i=d(n);p.set(i,{data:l(t),version:a}),e.emit(n)}function m(e){let t;if(!t){const n=f[d(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}const b=Object.freeze({addStaticData(e){e&&(f=Object.assign(Object.assign({},f),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=u(e),a=p.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate(){c.clear(),v+=1},addRecord(e,n){h(e,n,v)},exists(e,n=!1){const t=p.get(d(e));return t&&n?t.version===v:Boolean(t)},getRecord(e){var n;return null===(n=p.get(d(a(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=p.get(d(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=p.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return r(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=p.get(d({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=p.get(d(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching(e){if(o())return!0;if(void 0===e)return c.size>0;const n=i(e);return Boolean(Array.from(c.keys()).find((e=>n.includes(u(e).namespace))))},isLoading(e,n){const t=i(n);return Boolean(o()||Array.from(c.keys()).find((n=>{const a=u(n);return(!t.length||t.includes(a.namespace))&&!b.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const i=e.map((e=>{const i=a(e),o=d(i),r=c.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),m(e))))),i||(i=m(e)),i}(i,n)||Promise.resolve(void 0);return c.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));s.notify(),g.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=c.get(e.cacheKey)!==e.promise;if(e.new&&!t){c.delete(e.cacheKey);const t=o[n];t?b.addRecord(e.keyObject,t):b.getRecord(e.keyObject)||b.addRecord(e.keyObject,{})}})),s.notify(),g.notify(),i.map((e=>b.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(p.entries()).map((([e,n])=>Object.assign(Object.assign({},u(e)),{data:n.data})))});return b}function f(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 v="invalid",h={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"]},observerType:"invisible",onFormatError:v,apiUrl:"https://app.tolgee.io"},m=(...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 b(e,n){const t=m(h,null==n?void 0:n.initialOptions,e);return t.apiUrl=s(t.apiUrl),{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 L(t,a,i,o,r,s){const g={ui:void 0},c={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},l=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=c.ui)||void 0===t||t.handleElementClick(a,n)},u=(e,n)=>{var t;return(null===(t=c.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function d(e){const n=r({key:e.key,ns:e.ns});return w.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function p(e){c.observer=null==e?void 0:e()}function h(){return Boolean(c.observer)}function m(e){e&&c.formatters.push(e)}function b(e){c.finalFormatter=e}function L(e){g.ui=e}function y(){return Boolean(g.ui)}function O(e){c.languageStorage=e}function j(e){c.languageDetector=e}function k(e){e&&c.backends.push(e)}function R(e){c.devBackend=e}const w=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:b,addFormatter:m,setObserver:p,hasObserver:h,setUi:L,hasUi:y,setDevBackend:R,addBackend:k,setLanguageDetector:j,setLanguageStorage:O}))},run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();c.ui=null===(e=g.ui)||void 0===e?void 0:e.call(g,{apiKey:t,apiUrl:i,projectId:o,highlight:w.highlight,changeTranslation:s,findPositions:u}),null===(n=c.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:d,onClick:l})},stop(){var e;c.ui=void 0,null===(e=c.observer)||void 0===e||e.stop()},getLanguageStorage:()=>c.languageStorage,getInitialLanguage(){var e;const t=i();return n(null===(e=c.languageStorage)||void 0===e?void 0:e.getLanguage(),(e=>t&&!t.includes(e)||!e?function(){if(!c.languageDetector)return;const e=i();return c.languageDetector.getLanguage({availableLanguages:e})}():e))},setStoredLanguage(e){var n;null===(n=c.languageStorage)||void 0===n||n.setLanguage(e)},getDevBackend:()=>c.devBackend,getBackendRecord:({language:n,namespace:t})=>{for(const a of c.backends){const i=a.getRecord({language:n,namespace:t});if(e(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=c.devBackend)||void 0===t?void 0:t.getRecord({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n})},getLanguageDetector:()=>c.languageDetector,retranslate(){var e;null===(e=c.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=c.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(w.getDevBackend()),formatTranslation(e){var n,{formatEnabled:i}=e,o=f(e,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:l,params:u,orEmpty:d,ns:p}=o,h=s||g;let m=h||(d?"":r);const b=t(),L=i||!(null===(n=c.observer)||void 0===n?void 0:n.outputNotFormattable),y=e=>c.observer&&!l?c.observer.wrap({key:r,translation:e,defaultValue:g,params:u,ns:p}):e;m=y(m);try{if(h&&b&&L)for(const e of c.formatters)m=e.format({translation:m,language:b,params:u});c.finalFormatter&&h&&b&&L&&(m=c.finalFormatter.format({translation:m,language:b,params:u}))}catch(e){console.error(e);const n=("string"==typeof(O=e)?O:"string"==typeof(null==O?void 0:O.message)?O.message:void 0)||v,t=a().onFormatError,i=typeof t;m="string"===i?t:"function"===i?t(n,o):v,m=y(m)}var O;return m}});return w}const y=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const O=(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=f(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 j({options:a}){const l=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:g(a),onLanguageChange:g(a),onLoadingChange:g(a),onFetchingChange:g(a),onInitialLoaded:g(a),onRunningChange:g(a),onCacheChange:g(a),onUpdate:c(a,e,n),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)}}});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}(j,k),d=y(!1,(()=>m.isFetching()),l.onFetchingChange.emit),f=y(!1,(()=>C.isLoading()),l.onLoadingChange.emit),v=function(e,n,t){let a,g=b();const c=Object.freeze({init(e){g=b(e,g)},isRunning:()=>g.isRunning,setRunning(e){g.isRunning!==e&&(g.isRunning=e,t.emit(e))},isInitialLoading:()=>g.isInitialLoading,setInitialLoading(e){g.isInitialLoading=e},getLanguage:()=>g.language||g.initialOptions.language,setLanguage(n){g.language!==n&&(g.language=n,e.emit(n))},getPendingLanguage:()=>g.pendingLanguage||c.getLanguage(),setPendingLanguage(e){g.pendingLanguage!==e&&(g.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},g.initialOptions),a),addActiveNs(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n?g.activeNamespaces.set(e,n+1):g.activeNamespaces.set(e,1)}))},removeActiveNs(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n&&n>1?g.activeNamespaces.set(e,n-1):g.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>r([...g.initialOptions.ns||[g.initialOptions.defaultNs],...i(g.initialOptions.fallbackNs),...g.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?r([n,...o(n,g.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>i(g.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?g.initialOptions.defaultNs:e,getAvailableLanguages(){if(g.initialOptions.availableLanguages)return g.initialOptions.availableLanguages;if(g.initialOptions.staticData){const e=Object.keys(g.initialOptions.staticData).map((e=>u(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:s(e.apiUrl)}):void 0}});return c}(l.onLanguageChange,l.onPendingLanguageChange,l.onRunningChange),h=L(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=R(n||void 0);return m.getTranslationNs(a,t,e)}),A,E),m=p(l.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,d,f);function j(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function R(e){return[...i(k(e)),...j()]}function w(e){return[...i(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=m.getTranslation(a,n);return m.changeTranslation(a,n,t),{revert(){m.changeTranslation(a,n,i)}}}function N(e){v.init(e),m.addStaticData(v.getInitialOptions().staticData)}function D(e,t){const a=function(e,n){const t=v.getFallbackLangs(e),a=w(n),i=[];return t.forEach((e=>{a.forEach((n=>{m.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(C.loadRecords(a),(()=>{}))}function A({key:e,ns:n,language:t}){const a=R(n||void 0),i=v.getFallbackLangs(t);return m.getTranslationFallback(a,i,e)}function I(){const t=n(function(){if(v.getLanguage())return;return n(h.getInitialLanguage(),(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>D()));if(e(t))return v.setInitialLoading(!0),d.notify(),f.notify(),Promise.resolve(t).then((()=>{v.setInitialLoading(!1),d.notify(),f.notify(),l.onInitialLoaded.emit()}));l.onInitialLoaded.emit()}a&&N(a),l.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const C=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},l),v),h),m),{init:N,getTranslation:A,changeTranslation:E,async changeLanguage(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await D(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},async addActiveNs(e,n){n||v.addActiveNs(e),v.isRunning()&&await D(void 0,e)},loadRecords:e=>m.loadRecords(e,C.isDev()),loadRecord:async e=>(await C.loadRecords([e]))[0],isLoading:e=>m.isLoading(v.getLanguage(),e),isLoaded(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=w(e),i=[];return t.forEach((e=>{a.forEach((n=>{m.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=O(...e),t=A(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl),run(){let e;return function(){if((h.getLanguageDetector()||h.getLanguageStorage())&&!v.getAvailableLanguages())throw new Error(t("availableLanguages"));if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw new Error(t(["defaultLanguage","language"]))}(),v.isRunning()||(v.setRunning(!0),h.run(),e=I()),Promise.resolve(e)},stop(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}));return C}const k=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=m(e.options,t),n),init(n){const t=function(e){const n=j({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,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}(m(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},R=0,w=1,E=2;class N extends Error{constructor(e,n,t){let a;a=e===R?"Empty parameter":e===w?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function D(e){return/\s/.test(e)}const A=0,I=1,C=2,F=3,S=4,P=new Set([C,I,A]),T="'",U=new Set(["{","}",T]),B=e=>/[0-9a-zA-Z_]/.test(e);function x(e,n){const[t,a]=function(e){let n=A,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new N(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(R),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case A:i===T?(t+=i,n=I):"{"===i?(c(),n=F):(t+=i,n=A);break;case I:U.has(i)?(t=t.slice(0,-1)+i,n=C):(t+=i,n=A);break;case C:i===T?n=A:(t+=i,n=C);break;case F:"}"===i?(l(),n=A):D(i)?""!==a&&(l(),n=S):(B(i)||g(w),a+=i,n=F);break;case S:"}"==i?n=A:D(i)?n=S:g(w)}return P.has(n)||g(E),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 z=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>x(e,n)}),e);export{z as FormatSimple,k as TolgeeCore,a as getFallback,i as getFallbackArray,O 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(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 a(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function i(e){return a(e)||[]}function o(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?i(n):i(null==n?void 0:n[e]);var t}function r(e){return Array.from(new Set(e))}function s(e){return e?e.replace(/\/+$/,""):e}function g(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 c(e,n,t){const a=new Set,o=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());o.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};o.add(n);const a={unsubscribe:()=>{o.delete(n)},subscribeNs:e=>(i(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}const l=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):l(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},u=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},d=({language:e,namespace:n})=>n?`${e}:${n}`:e;function p(e,n,t,a,o,s,g){const c=new Map,p=new Map;let f={},v=0;function h(n,t,a){const i=d(n);p.set(i,{data:l(t),version:a}),e.emit(n)}function m(e){let t;if(!t){const n=f[d(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}const b=Object.freeze({addStaticData(e){e&&(f=Object.assign(Object.assign({},f),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=u(e),a=p.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate(){c.clear(),v+=1},addRecord(e,n){h(e,n,v)},exists(e,n=!1){const t=p.get(d(e));return t&&n?t.version===v:Boolean(t)},getRecord(e){var n;return null===(n=p.get(d(a(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=p.get(d(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=p.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return r(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=p.get(d({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=p.get(d(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching(e){if(o())return!0;if(void 0===e)return c.size>0;const n=i(e);return Boolean(Array.from(c.keys()).find((e=>n.includes(u(e).namespace))))},isLoading(e,n){const t=i(n);return Boolean(o()||Array.from(c.keys()).find((n=>{const a=u(n);return(!t.length||t.includes(a.namespace))&&!b.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const i=e.map((e=>{const i=a(e),o=d(i),r=c.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),m(e))))),i||(i=m(e)),i}(i,n)||Promise.resolve(void 0);return c.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));s.notify(),g.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=c.get(e.cacheKey)!==e.promise;if(e.new&&!t){c.delete(e.cacheKey);const t=o[n];t?b.addRecord(e.keyObject,t):b.getRecord(e.keyObject)||b.addRecord(e.keyObject,{})}})),s.notify(),g.notify(),i.map((e=>b.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(p.entries()).map((([e,n])=>Object.assign(Object.assign({},u(e)),{data:n.data})))});return b}function f(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 v="invalid",h={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:v,apiUrl:"https://app.tolgee.io",fetch:(e,n)=>fetch(e,n)},m=(...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 b(e,n){const t=m(h,null==n?void 0:n.initialOptions,e);return t.apiUrl=s(t.apiUrl),{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 y(t,a,i,o,r,s,g){const c={ui:void 0},l={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},u=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=l.ui)||void 0===t||t.handleElementClick(a,n)},d=(e,n)=>{var t;return(null===(t=l.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function p(e){const n=r({key:e.key,ns:e.ns});return N.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function h(){return{fetch:a().fetch}}function m(e){l.observer=null==e?void 0:e()}function b(){return Boolean(l.observer)}function y(e){e&&l.formatters.push(e)}function L(e){l.finalFormatter=e}function O(e){c.ui=e}function j(){return Boolean(c.ui)}function k(e){l.languageStorage=e}function R(e){l.languageDetector=e}function w(e){e&&l.backends.push(e)}function E(e){l.devBackend=e}const N=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:L,addFormatter:y,setObserver:m,hasObserver:b,setUi:O,hasUi:j,setDevBackend:E,addBackend:w,setLanguageDetector:R,setLanguageStorage:k}))},run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();l.ui=null===(e=c.ui)||void 0===e?void 0:e.call(c,{apiKey:t,apiUrl:i,projectId:o,highlight:N.highlight,changeTranslation:s,findPositions:d,onPermanentChange:g}),null===(n=l.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:p,onClick:u})},stop(){var e;l.ui=void 0,null===(e=l.observer)||void 0===e||e.stop()},getLanguageStorage:()=>l.languageStorage,getInitialLanguage(){var e;const t=i();return n(null===(e=l.languageStorage)||void 0===e?void 0:e.getLanguage(h()),(e=>t&&!t.includes(e)||!e?function(){if(!l.languageDetector)return;const e=i();return l.languageDetector.getLanguage(Object.assign({availableLanguages:e},h()))}():e))},setStoredLanguage(e){var n;null===(n=l.languageStorage)||void 0===n||n.setLanguage(e,h())},getDevBackend:()=>l.devBackend,getBackendRecord:({language:n,namespace:t})=>{for(const a of l.backends){const i=a.getRecord(Object.assign({language:n,namespace:t},h()));if(e(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=l.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},h()))},getLanguageDetector:()=>l.languageDetector,retranslate(){var e;null===(e=l.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=l.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return l.observer?null===(n=l.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return l.observer?null===(n=l.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(N.getDevBackend()),formatTranslation(e){var n,{formatEnabled:i}=e,o=f(e,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:u,orEmpty:d,ns:p}=o,h=s||g;let m=h||(d?"":r);const b=t(),y=i||!(null===(n=l.observer)||void 0===n?void 0:n.outputNotFormattable),L=e=>l.observer&&!c?l.observer.wrap({key:r,translation:e,defaultValue:g,params:u,ns:p}):e;m=L(m);try{if(h&&b&&y)for(const e of l.formatters)m=e.format({translation:m,language:b,params:u});l.finalFormatter&&h&&b&&y&&(m=l.finalFormatter.format({translation:m,language:b,params:u}))}catch(e){console.error(e);const n=("string"==typeof(O=e)?O:"string"==typeof(null==O?void 0:O.message)?O.message:void 0)||v,t=a().onFormatError,i=typeof t;m="string"===i?t:"function"===i?t(n,o):v,m=L(m)}var O;return m}});return N}const L=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const O=(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=f(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 j({options:a}){const l=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:g(a),onLanguageChange:g(a),onLoadingChange:g(a),onFetchingChange:g(a),onInitialLoaded:g(a),onRunningChange:g(a),onCacheChange:g(a),onUpdate:c(a,e,n),onPermanentChange:g(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)}}});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}(j,k),d=L(!1,(()=>m.isFetching()),l.onFetchingChange.emit),f=L(!1,(()=>I.isLoading()),l.onLoadingChange.emit),v=function(e,n,t){let a,g=b();const c=Object.freeze({init(e){g=b(e,g)},isRunning:()=>g.isRunning,setRunning(e){g.isRunning!==e&&(g.isRunning=e,t.emit(e))},isInitialLoading:()=>g.isInitialLoading,setInitialLoading(e){g.isInitialLoading=e},getLanguage:()=>g.language||g.initialOptions.language,setLanguage(n){g.language!==n&&(g.language=n,e.emit(n))},getPendingLanguage:()=>g.pendingLanguage||c.getLanguage(),setPendingLanguage(e){g.pendingLanguage!==e&&(g.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},g.initialOptions),a),addActiveNs(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n?g.activeNamespaces.set(e,n+1):g.activeNamespaces.set(e,1)}))},removeActiveNs(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n&&n>1?g.activeNamespaces.set(e,n-1):g.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>r([...g.initialOptions.ns||[g.initialOptions.defaultNs],...i(g.initialOptions.fallbackNs),...g.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?r([n,...o(n,g.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>i(g.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?g.initialOptions.defaultNs:e,getAvailableLanguages(){if(g.initialOptions.availableLanguages)return g.initialOptions.availableLanguages;if(g.initialOptions.staticData){const e=Object.keys(g.initialOptions.staticData).map((e=>u(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:s(e.apiUrl)}):void 0}});return c}(l.onLanguageChange,l.onPendingLanguageChange,l.onRunningChange),h=y(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=R(n||void 0);return m.getTranslationNs(a,t,e)}),D,E,(function(e){l.onPermanentChange.emit({key:e.key,namespace:e.namespace})})),m=p(l.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,d,f);function j(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function R(e){return[...i(k(e)),...j()]}function w(e){return[...i(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=m.getTranslation(a,n);return m.changeTranslation(a,n,t),{revert(){m.changeTranslation(a,n,i)}}}function N(e){v.init(e),m.addStaticData(v.getInitialOptions().staticData)}function C(e,t){const a=function(e,n){const t=v.getFallbackLangs(e),a=w(n),i=[];return t.forEach((e=>{a.forEach((n=>{m.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(I.loadRecords(a),(()=>{}))}function D({key:e,ns:n,language:t}){const a=R(n||void 0),i=v.getFallbackLangs(t);return m.getTranslationFallback(a,i,e)}function A(){const t=n(function(){if(v.getLanguage())return;return n(h.getInitialLanguage(),(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>C()));if(e(t))return v.setInitialLoading(!0),d.notify(),f.notify(),Promise.resolve(t).then((()=>{v.setInitialLoading(!1),d.notify(),f.notify(),l.onInitialLoaded.emit()}));l.onInitialLoaded.emit()}a&&N(a),l.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const I=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},l),v),h),m),{init:N,getTranslation:D,changeTranslation:E,async changeLanguage(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await C(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},async addActiveNs(e,n){n||v.addActiveNs(e),v.isRunning()&&await C(void 0,e)},loadRecords:e=>m.loadRecords(e,I.isDev()),loadRecord:async e=>(await I.loadRecords([e]))[0],isLoading:e=>m.isLoading(v.getLanguage(),e),isLoaded(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=w(e),i=[];return t.forEach((e=>{a.forEach((n=>{m.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=O(...e),t=D(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl),run(){let e;return function(){if((h.getLanguageDetector()||h.getLanguageStorage())&&!v.getAvailableLanguages())throw new Error(t("availableLanguages"));if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw new Error(t(["defaultLanguage","language"]))}(),v.isRunning()||(v.setRunning(!0),h.run(),e=A()),Promise.resolve(e)},stop(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}));return I}const k=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=m(e.options,t),n),init(n){const t=function(e){const n=j({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,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}(m(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},R=0,w=1,E=2;class N extends Error{constructor(e,n,t){let a;a=e===R?"Empty parameter":e===w?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function C(e){return/\s/.test(e)}const D=0,A=1,I=2,P=3,F=4,S=new Set([I,A,D]),T="'",U=new Set(["{","}",T]),B=e=>/[0-9a-zA-Z_]/.test(e);function x(e,n){const[t,a]=function(e){let n=D,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new N(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(R),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case D:i===T?(t+=i,n=A):"{"===i?(c(),n=P):(t+=i,n=D);break;case A:U.has(i)?(t=t.slice(0,-1)+i,n=I):(t+=i,n=D);break;case I:i===T?n=D:(t+=i,n=I);break;case P:"}"===i?(l(),n=D):C(i)?""!==a&&(l(),n=F):(B(i)||g(w),a+=i,n=P);break;case F:"}"==i?n=D:C(i)?n=F:g(w)}return S.has(n)||g(E),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 z=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>x(e,n)}),e);export{z as FormatSimple,k as TolgeeCore,a as getFallback,i as getFallbackArray,O as getTranslateProps};
//# sourceMappingURL=tolgee.esm.min.js.map

@@ -187,2 +187,3 @@ (function (global, factory) {

onUpdate: EventEmitterSelective(isActive, getFallbackNs, getDefaultNs),
onPermanentChange: EventEmitter(isActive),
setEmitterActive(active) {

@@ -209,2 +210,4 @@ emitterActive = active;

return self.onUpdate.listen(handler);
case 'permanentChange':
return self.onPermanentChange.listen(handler);
}

@@ -484,2 +487,3 @@ }),

passToParent: ['option', 'optgroup'],
fullKeyEncode: false,
};

@@ -495,2 +499,3 @@

apiUrl: DEFAULT_API_URL,
fetch: (input, options) => fetch(input, options),
};

@@ -518,3 +523,3 @@ const combineOptions = (...states) => {

function Plugins(getLanguage, getInitialOptions, getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation) {
function Plugins(getLanguage, getInitialOptions, getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation, onPermanentChange) {
const plugins = {

@@ -559,2 +564,5 @@ ui: undefined,

}
function getCommonProps() {
return { fetch: getInitialOptions().fetch };
}
function setObserver(observer) {

@@ -591,5 +599,3 @@ instances.observer = observer === null || observer === void 0 ? void 0 : observer();

const availableLanguages = getAvailableLanguages();
return instances.languageDetector.getLanguage({
availableLanguages,
});
return instances.languageDetector.getLanguage(Object.assign({ availableLanguages }, getCommonProps()));
}

@@ -631,2 +637,3 @@ function addBackend(backend) {

findPositions,
onPermanentChange,
});

@@ -651,3 +658,3 @@ (_b = instances.observer) === null || _b === void 0 ? void 0 : _b.run({

const availableLanguages = getAvailableLanguages();
const languageOrPromise = (_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.getLanguage();
const languageOrPromise = (_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.getLanguage(getCommonProps());
return valueOrPromise(languageOrPromise, (language) => {

@@ -663,3 +670,3 @@ if ((!availableLanguages || availableLanguages.includes(language)) &&

var _a;
(_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.setLanguage(language);
(_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.setLanguage(language, getCommonProps());
},

@@ -671,3 +678,4 @@ getDevBackend() {

for (const backend of instances.backends) {
const data = backend.getRecord({ language, namespace });
const data = backend.getRecord(Object.assign({ language,
namespace }, getCommonProps()));
if (isPromise(data)) {

@@ -689,9 +697,7 @@ return data === null || data === void 0 ? void 0 : data.catch((e) => {

const { apiKey, apiUrl, projectId } = getInitialOptions();
return (_a = instances.devBackend) === null || _a === void 0 ? void 0 : _a.getRecord({
apiKey,
return (_a = instances.devBackend) === null || _a === void 0 ? void 0 : _a.getRecord(Object.assign({ apiKey,
apiUrl,
projectId,
language,
namespace,
});
namespace }, getCommonProps()));
}),

@@ -964,3 +970,3 @@ getLanguageDetector() {

const state = State(events.onLanguageChange, events.onPendingLanguageChange, events.onRunningChange);
const pluginService = Plugins(state.getLanguage, state.getInitialOptions, state.getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation);
const pluginService = Plugins(state.getLanguage, state.getInitialOptions, state.getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation, onPermanentChange);
const cache = Cache(events.onCacheChange, pluginService.getBackendRecord, pluginService.getBackendDevRecord, state.withDefaultNs, state.isInitialLoading, fetchingObserver, loadingObserver);

@@ -1004,2 +1010,8 @@ if (options) {

}
function onPermanentChange(props) {
events.onPermanentChange.emit({
key: props.key,
namespace: props.namespace,
});
}
function init(options) {

@@ -1006,0 +1018,0 @@ state.init(options);

@@ -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){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}function c(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 l(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}})}const u=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):u(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},d=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},f=({language:e,namespace:n})=>n?`${e}:${n}`:e;function p(e,n,t,a,i,r,g){const c=new Map,l=new Map;let p={},v=0;function h(n,t,a){const i=f(n);l.set(i,{data:u(t),version:a}),e.emit(n)}function b(e){let t;if(!t){const n=p[f(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}const m=Object.freeze({addStaticData(e){e&&(p=Object.assign(Object.assign({},p),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=d(e),a=l.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate(){c.clear(),v+=1},addRecord(e,n){h(e,n,v)},exists(e,n=!1){const t=l.get(f(e));return t&&n?t.version===v:Boolean(t)},getRecord(e){var n;return null===(n=l.get(f(a(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=l.get(f(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=l.get(f({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=l.get(f({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=l.get(f(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching(e){if(i())return!0;if(void 0===e)return c.size>0;const n=o(e);return Boolean(Array.from(c.keys()).find((e=>n.includes(d(e).namespace))))},isLoading(e,n){const t=o(n);return Boolean(i()||Array.from(c.keys()).find((n=>{const a=d(n);return(!t.length||t.includes(a.namespace))&&!m.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const i=e.map((e=>{const i=a(e),o=f(i),r=c.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),b(e))))),i||(i=b(e)),i}(i,n)||Promise.resolve(void 0);return c.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));r.notify(),g.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=c.get(e.cacheKey)!==e.promise;if(e.new&&!t){c.delete(e.cacheKey);const t=o[n];t?m.addRecord(e.keyObject,t):m.getRecord(e.keyObject)||m.addRecord(e.keyObject,{})}})),r.notify(),g.notify(),i.map((e=>m.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(l.entries()).map((([e,n])=>Object.assign(Object.assign({},d(e)),{data:n.data})))});return m}function v(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 h="invalid",b={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"]},observerType:"invisible",onFormatError:h,apiUrl:"https://app.tolgee.io"},m=(...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 y(e,n){const t=m(b,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),{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 L(e,a,i,o,r,s){const g={ui:void 0},c={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},l=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=c.ui)||void 0===t||t.handleElementClick(a,n)},u=(e,n)=>{var t;return(null===(t=c.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function d(e){const n=r({key:e.key,ns:e.ns});return w.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function f(e){c.observer=null==e?void 0:e()}function p(){return Boolean(c.observer)}function b(e){e&&c.formatters.push(e)}function m(e){c.finalFormatter=e}function y(e){g.ui=e}function L(){return Boolean(g.ui)}function O(e){c.languageStorage=e}function j(e){c.languageDetector=e}function k(e){e&&c.backends.push(e)}function R(e){c.devBackend=e}const w=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:m,addFormatter:b,setObserver:f,hasObserver:p,setUi:y,hasUi:L,setDevBackend:R,addBackend:k,setLanguageDetector:j,setLanguageStorage:O}))},run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();c.ui=null===(e=g.ui)||void 0===e?void 0:e.call(g,{apiKey:t,apiUrl:i,projectId:o,highlight:w.highlight,changeTranslation:s,findPositions:u}),null===(n=c.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:d,onClick:l})},stop(){var e;c.ui=void 0,null===(e=c.observer)||void 0===e||e.stop()},getLanguageStorage:()=>c.languageStorage,getInitialLanguage(){var e;const n=i();return t(null===(e=c.languageStorage)||void 0===e?void 0:e.getLanguage(),(e=>n&&!n.includes(e)||!e?function(){if(!c.languageDetector)return;const e=i();return c.languageDetector.getLanguage({availableLanguages:e})}():e))},setStoredLanguage(e){var n;null===(n=c.languageStorage)||void 0===n||n.setLanguage(e)},getDevBackend:()=>c.devBackend,getBackendRecord:({language:e,namespace:t})=>{for(const a of c.backends){const i=a.getRecord({language:e,namespace:t});if(n(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=c.devBackend)||void 0===t?void 0:t.getRecord({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n})},getLanguageDetector:()=>c.languageDetector,retranslate(){var e;null===(e=c.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=c.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(w.getDevBackend()),formatTranslation(n){var t,{formatEnabled:i}=n,o=v(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:l,params:u,orEmpty:d,ns:f}=o,p=s||g;let b=p||(d?"":r);const m=e(),y=i||!(null===(t=c.observer)||void 0===t?void 0:t.outputNotFormattable),L=e=>c.observer&&!l?c.observer.wrap({key:r,translation:e,defaultValue:g,params:u,ns:f}):e;b=L(b);try{if(p&&m&&y)for(const e of c.formatters)b=e.format({translation:b,language:m,params:u});c.finalFormatter&&p&&m&&y&&(b=c.finalFormatter.format({translation:b,language:m,params:u}))}catch(e){console.error(e);const n=("string"==typeof(O=e)?O:"string"==typeof(null==O?void 0:O.message)?O.message:void 0)||h,t=a().onFormatError,i=typeof t;b="string"===i?t:"function"===i?t(n,o):h,b=L(b)}var O;return b}});return w}const O=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const j=(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=v(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 k({options:e}){const i=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:c(a),onLanguageChange:c(a),onLoadingChange:c(a),onFetchingChange:c(a),onInitialLoaded:c(a),onRunningChange:c(a),onCacheChange:c(a),onUpdate:l(a,e,n),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)}}});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,k),u=O(!1,(()=>b.isFetching()),i.onFetchingChange.emit),f=O(!1,(()=>F.isLoading()),i.onLoadingChange.emit),v=function(e,n,t){let a,i=y();const c=Object.freeze({init(e){i=y(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=>d(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),h=L(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=R(n||void 0);return b.getTranslationNs(a,t,e)}),D,E),b=p(i.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,u,f);function m(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function R(e){return[...o(k(e)),...m()]}function w(e){return[...o(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=b.getTranslation(a,n);return b.changeTranslation(a,n,t),{revert(){b.changeTranslation(a,n,i)}}}function N(e){v.init(e),b.addStaticData(v.getInitialOptions().staticData)}function A(e,n){const a=function(e,n){const t=v.getFallbackLangs(e),a=w(n),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,n);if(a.length)return t(F.loadRecords(a),(()=>{}))}function D({key:e,ns:n,language:t}){const a=R(n||void 0),i=v.getFallbackLangs(t);return b.getTranslationFallback(a,i,e)}function I(){const e=t(function(){if(v.getLanguage())return;return t(h.getInitialLanguage(),(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>A()));if(n(e))return v.setInitialLoading(!0),u.notify(),f.notify(),Promise.resolve(e).then((()=>{v.setInitialLoading(!1),u.notify(),f.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}e&&N(e),i.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const F=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),v),h),b),{init:N,getTranslation:D,changeTranslation:E,async changeLanguage(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await A(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},async addActiveNs(e,n){n||v.addActiveNs(e),v.isRunning()&&await A(void 0,e)},loadRecords:e=>b.loadRecords(e,F.isDev()),loadRecord:async e=>(await F.loadRecords([e]))[0],isLoading:e=>b.isLoading(v.getLanguage(),e),isLoaded(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=w(e),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=j(...e),t=D(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl),run(){let e;return function(){if((h.getLanguageDetector()||h.getLanguageStorage())&&!v.getAvailableLanguages())throw new Error(a("availableLanguages"));if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw new Error(a(["defaultLanguage","language"]))}(),v.isRunning()||(v.setRunning(!0),h.run(),e=I()),Promise.resolve(e)},stop(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}));return F}const R=0,w=1,E=2;class N extends Error{constructor(e,n,t){let a;a=e===R?"Empty parameter":e===w?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function A(e){return/\s/.test(e)}const D=0,I=1,F=2,C=3,S=4,P=new Set([F,I,D]),T="'",U=new Set(["{","}",T]),B=e=>/[0-9a-zA-Z_]/.test(e);function x(e,n){const[t,a]=function(e){let n=D,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new N(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(R),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case D:i===T?(t+=i,n=I):"{"===i?(c(),n=C):(t+=i,n=D);break;case I:U.has(i)?(t=t.slice(0,-1)+i,n=F):(t+=i,n=D);break;case F:i===T?n=D:(t+=i,n=F);break;case C:"}"===i?(l(),n=D):A(i)?""!==a&&(l(),n=S):(B(i)||g(w),a+=i,n=C);break;case S:"}"==i?n=D:A(i)?n=S:g(w)}return P.has(n)||g(E),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})=>x(e,n)}),e),e.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=m(e.options,t),n),init(n){const t=function(e){const n=k({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,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}(m(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},e.getFallback=i,e.getFallbackArray=o,e.getTranslateProps=j,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){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}function c(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 l(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}})}const u=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):u(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},d=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},f=({language:e,namespace:n})=>n?`${e}:${n}`:e;function p(e,n,t,a,i,r,g){const c=new Map,l=new Map;let p={},v=0;function h(n,t,a){const i=f(n);l.set(i,{data:u(t),version:a}),e.emit(n)}function m(e){let t;if(!t){const n=p[f(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}const b=Object.freeze({addStaticData(e){e&&(p=Object.assign(Object.assign({},p),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=d(e),a=l.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate(){c.clear(),v+=1},addRecord(e,n){h(e,n,v)},exists(e,n=!1){const t=l.get(f(e));return t&&n?t.version===v:Boolean(t)},getRecord(e){var n;return null===(n=l.get(f(a(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=l.get(f(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=l.get(f({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=l.get(f({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=l.get(f(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching(e){if(i())return!0;if(void 0===e)return c.size>0;const n=o(e);return Boolean(Array.from(c.keys()).find((e=>n.includes(d(e).namespace))))},isLoading(e,n){const t=o(n);return Boolean(i()||Array.from(c.keys()).find((n=>{const a=d(n);return(!t.length||t.includes(a.namespace))&&!b.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,n){const i=e.map((e=>{const i=a(e),o=f(i),r=c.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),m(e))))),i||(i=m(e)),i}(i,n)||Promise.resolve(void 0);return c.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));r.notify(),g.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=c.get(e.cacheKey)!==e.promise;if(e.new&&!t){c.delete(e.cacheKey);const t=o[n];t?b.addRecord(e.keyObject,t):b.getRecord(e.keyObject)||b.addRecord(e.keyObject,{})}})),r.notify(),g.notify(),i.map((e=>b.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(l.entries()).map((([e,n])=>Object.assign(Object.assign({},d(e)),{data:n.data})))});return b}function v(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 h="invalid",m={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:h,apiUrl:"https://app.tolgee.io",fetch:(e,n)=>fetch(e,n)},b=(...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 y(e,n){const t=b(m,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),{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 O(e,a,i,o,r,s,g){const c={ui:void 0},l={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},u=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=l.ui)||void 0===t||t.handleElementClick(a,n)},d=(e,n)=>{var t;return(null===(t=l.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function f(e){const n=r({key:e.key,ns:e.ns});return N.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function p(){return{fetch:a().fetch}}function m(e){l.observer=null==e?void 0:e()}function b(){return Boolean(l.observer)}function y(e){e&&l.formatters.push(e)}function O(e){l.finalFormatter=e}function L(e){c.ui=e}function j(){return Boolean(c.ui)}function k(e){l.languageStorage=e}function R(e){l.languageDetector=e}function w(e){e&&l.backends.push(e)}function E(e){l.devBackend=e}const N=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:O,addFormatter:y,setObserver:m,hasObserver:b,setUi:L,hasUi:j,setDevBackend:E,addBackend:w,setLanguageDetector:R,setLanguageStorage:k}))},run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();l.ui=null===(e=c.ui)||void 0===e?void 0:e.call(c,{apiKey:t,apiUrl:i,projectId:o,highlight:N.highlight,changeTranslation:s,findPositions:d,onPermanentChange:g}),null===(n=l.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:f,onClick:u})},stop(){var e;l.ui=void 0,null===(e=l.observer)||void 0===e||e.stop()},getLanguageStorage:()=>l.languageStorage,getInitialLanguage(){var e;const n=i();return t(null===(e=l.languageStorage)||void 0===e?void 0:e.getLanguage(p()),(e=>n&&!n.includes(e)||!e?function(){if(!l.languageDetector)return;const e=i();return l.languageDetector.getLanguage(Object.assign({availableLanguages:e},p()))}():e))},setStoredLanguage(e){var n;null===(n=l.languageStorage)||void 0===n||n.setLanguage(e,p())},getDevBackend:()=>l.devBackend,getBackendRecord:({language:e,namespace:t})=>{for(const a of l.backends){const i=a.getRecord(Object.assign({language:e,namespace:t},p()));if(n(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=l.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},p()))},getLanguageDetector:()=>l.languageDetector,retranslate(){var e;null===(e=l.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=l.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return l.observer?null===(n=l.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return l.observer?null===(n=l.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(N.getDevBackend()),formatTranslation(n){var t,{formatEnabled:i}=n,o=v(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:u,orEmpty:d,ns:f}=o,p=s||g;let m=p||(d?"":r);const b=e(),y=i||!(null===(t=l.observer)||void 0===t?void 0:t.outputNotFormattable),O=e=>l.observer&&!c?l.observer.wrap({key:r,translation:e,defaultValue:g,params:u,ns:f}):e;m=O(m);try{if(p&&b&&y)for(const e of l.formatters)m=e.format({translation:m,language:b,params:u});l.finalFormatter&&p&&b&&y&&(m=l.finalFormatter.format({translation:m,language:b,params:u}))}catch(e){console.error(e);const n=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||h,t=a().onFormatError,i=typeof t;m="string"===i?t:"function"===i?t(n,o):h,m=O(m)}var L;return m}});return N}const L=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const j=(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=v(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 k({options:e}){const i=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:c(a),onLanguageChange:c(a),onLoadingChange:c(a),onFetchingChange:c(a),onInitialLoaded:c(a),onRunningChange:c(a),onCacheChange:c(a),onUpdate:l(a,e,n),onPermanentChange:c(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)}}});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,k),u=L(!1,(()=>m.isFetching()),i.onFetchingChange.emit),f=L(!1,(()=>I.isLoading()),i.onLoadingChange.emit),v=function(e,n,t){let a,i=y();const c=Object.freeze({init(e){i=y(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=>d(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),h=O(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=R(n||void 0);return m.getTranslationNs(a,t,e)}),A,E,(function(e){i.onPermanentChange.emit({key:e.key,namespace:e.namespace})})),m=p(i.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,u,f);function b(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function R(e){return[...o(k(e)),...b()]}function w(e){return[...o(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=m.getTranslation(a,n);return m.changeTranslation(a,n,t),{revert(){m.changeTranslation(a,n,i)}}}function N(e){v.init(e),m.addStaticData(v.getInitialOptions().staticData)}function C(e,n){const a=function(e,n){const t=v.getFallbackLangs(e),a=w(n),i=[];return t.forEach((e=>{a.forEach((n=>{m.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,n);if(a.length)return t(I.loadRecords(a),(()=>{}))}function A({key:e,ns:n,language:t}){const a=R(n||void 0),i=v.getFallbackLangs(t);return m.getTranslationFallback(a,i,e)}function D(){const e=t(function(){if(v.getLanguage())return;return t(h.getInitialLanguage(),(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>C()));if(n(e))return v.setInitialLoading(!0),u.notify(),f.notify(),Promise.resolve(e).then((()=>{v.setInitialLoading(!1),u.notify(),f.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}e&&N(e),i.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const I=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),v),h),m),{init:N,getTranslation:A,changeTranslation:E,async changeLanguage(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await C(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},async addActiveNs(e,n){n||v.addActiveNs(e),v.isRunning()&&await C(void 0,e)},loadRecords:e=>m.loadRecords(e,I.isDev()),loadRecord:async e=>(await I.loadRecords([e]))[0],isLoading:e=>m.isLoading(v.getLanguage(),e),isLoaded(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=w(e),i=[];return t.forEach((e=>{a.forEach((n=>{m.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=j(...e),t=A(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl),run(){let e;return function(){if((h.getLanguageDetector()||h.getLanguageStorage())&&!v.getAvailableLanguages())throw new Error(a("availableLanguages"));if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw new Error(a(["defaultLanguage","language"]))}(),v.isRunning()||(v.setRunning(!0),h.run(),e=D()),Promise.resolve(e)},stop(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}));return I}const R=0,w=1,E=2;class N extends Error{constructor(e,n,t){let a;a=e===R?"Empty parameter":e===w?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function C(e){return/\s/.test(e)}const A=0,D=1,I=2,F=3,P=4,S=new Set([I,D,A]),T="'",U=new Set(["{","}",T]),B=e=>/[0-9a-zA-Z_]/.test(e);function x(e,n){const[t,a]=function(e){let n=A,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new N(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(R),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case A:i===T?(t+=i,n=D):"{"===i?(c(),n=F):(t+=i,n=A);break;case D:U.has(i)?(t=t.slice(0,-1)+i,n=I):(t+=i,n=A);break;case I:i===T?n=A:(t+=i,n=I);break;case F:"}"===i?(l(),n=A):C(i)?""!==a&&(l(),n=P):(B(i)||g(w),a+=i,n=F);break;case P:"}"==i?n=A:C(i)?n=P:g(w)}return S.has(n)||g(E),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})=>x(e,n)}),e),e.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=b(e.options,t),n),init(n){const t=function(e){const n=k({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,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}(b(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},e.getFallback=i,e.getFallbackArray=o,e.getTranslateProps=j,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=tolgee.umd.min.js.map

@@ -1,6 +0,6 @@

import { CacheDescriptor, CacheDescriptorInternal, CacheDescriptorWithKey, NsFallback, TranslationsFlat, TranslationValue, TreeTranslationsData, BackendGetRecord, BackendGetDevRecord } from '../../types';
import { CacheDescriptor, CacheDescriptorInternal, CacheDescriptorWithKey, NsFallback, TranslationsFlat, TranslationValue, TreeTranslationsData, BackendGetRecordInternal } from '../../types';
import { EventEmitterInstance } from '../Events/EventEmitter';
import { TolgeeStaticData } from '../State/initState';
import { ValueObserverInstance } from '../ValueObserver';
export declare function Cache(onCacheChange: EventEmitterInstance<CacheDescriptorWithKey>, backendGetRecord: BackendGetRecord, backendGetDevRecord: BackendGetDevRecord, withDefaultNs: (descriptor: CacheDescriptor) => CacheDescriptorInternal, isInitialLoading: () => boolean, fetchingObserver: ValueObserverInstance<boolean>, loadingObserver: ValueObserverInstance<boolean>): Readonly<{
export declare function Cache(onCacheChange: EventEmitterInstance<CacheDescriptorWithKey>, backendGetRecord: BackendGetRecordInternal, backendGetDevRecord: BackendGetRecordInternal, withDefaultNs: (descriptor: CacheDescriptor) => CacheDescriptorInternal, isInitialLoading: () => boolean, fetchingObserver: ValueObserverInstance<boolean>, loadingObserver: ValueObserverInstance<boolean>): Readonly<{
addStaticData(data: TolgeeStaticData | undefined): void;

@@ -7,0 +7,0 @@ invalidate(): void;

@@ -1,2 +0,2 @@

import { CacheDescriptor, NsFallback, TolgeeOptions, TFnType, KeyAndNamespacesInternal } from '../types';
import { CacheDescriptor, NsFallback, TolgeeOptions, TFnType, KeyAndNamespacesInternal, TranslationDescriptor } from '../types';
declare type StateServiceProps = {

@@ -39,4 +39,4 @@ options?: Partial<TolgeeOptions>;

getDevBackend: () => import("../types").BackendDevMiddleware | undefined;
getBackendRecord: import("../types").BackendGetRecord;
getBackendDevRecord: import("../types").BackendGetRecord;
getBackendRecord: import("../types").BackendGetRecordInternal;
getBackendDevRecord: import("../types").BackendGetRecordInternal;
getLanguageDetector: () => import("../types").LanguageDetectorMiddleware | undefined;

@@ -80,2 +80,3 @@ retranslate: () => void;

onFormatError: import("../types").OnFormatError;
fetch: import("../types").FetchFn;
};

@@ -98,2 +99,3 @@ removeActiveNs: (ns: NsFallback) => void;

onUpdate: import("./Events/EventEmitterSelective").EventEmitterSelectiveInstance;
onPermanentChange: import("./Events/EventEmitter").EventEmitterInstance<TranslationDescriptor>;
setEmitterActive: (active: boolean) => void;

@@ -100,0 +102,0 @@ on: import("../types").TolgeeOn<keyof import("../types").EventType>;

@@ -1,2 +0,2 @@

import { CacheDescriptorWithKey, TolgeeOn } from '../../types';
import { CacheDescriptorWithKey, TolgeeOn, TranslationDescriptor } from '../../types';
export declare function Events(getFallbackNs: () => string[], getDefaultNs: () => string): Readonly<{

@@ -11,2 +11,3 @@ onPendingLanguageChange: import("./EventEmitter").EventEmitterInstance<string>;

onUpdate: import("./EventEmitterSelective").EventEmitterSelectiveInstance;
onPermanentChange: import("./EventEmitter").EventEmitterInstance<TranslationDescriptor>;
setEmitterActive(active: boolean): void;

@@ -13,0 +14,0 @@ on: TolgeeOn<keyof import("../../types").EventType>;

@@ -1,3 +0,3 @@

import { BackendDevMiddleware, BackendGetRecord, TranslatePropsInternal, HighlightInterface, LanguageDetectorMiddleware, LanguageStorageMiddleware, ChangeTranslationInterface, WrapperWrapProps, Unwrapped, KeyAndNamespacesInternal, TolgeePlugin, TolgeeInstance, TolgeeOptionsInternal } from '../../types';
export declare function Plugins(getLanguage: () => string | undefined, getInitialOptions: () => TolgeeOptionsInternal, getAvailableLanguages: () => string[] | undefined, getTranslationNs: (props: KeyAndNamespacesInternal) => string[], getTranslation: (props: KeyAndNamespacesInternal) => string | undefined, changeTranslation: ChangeTranslationInterface): Readonly<{
import { BackendDevMiddleware, TranslatePropsInternal, HighlightInterface, LanguageDetectorMiddleware, LanguageStorageMiddleware, ChangeTranslationInterface, WrapperWrapProps, Unwrapped, KeyAndNamespacesInternal, TolgeePlugin, TolgeeInstance, TolgeeOptionsInternal, BackendGetRecordInternal, TranslationDescriptor } from '../../types';
export declare function Plugins(getLanguage: () => string | undefined, getInitialOptions: () => TolgeeOptionsInternal, getAvailableLanguages: () => string[] | undefined, getTranslationNs: (props: KeyAndNamespacesInternal) => string[], getTranslation: (props: KeyAndNamespacesInternal) => string | undefined, changeTranslation: ChangeTranslationInterface, onPermanentChange: (props: TranslationDescriptor) => void): Readonly<{
addPlugin: (tolgeeInstance: TolgeeInstance, plugin: TolgeePlugin) => void;

@@ -10,4 +10,4 @@ run(): void;

getDevBackend(): BackendDevMiddleware | undefined;
getBackendRecord: BackendGetRecord;
getBackendDevRecord: BackendGetRecord;
getBackendRecord: BackendGetRecordInternal;
getBackendDevRecord: BackendGetRecordInternal;
getLanguageDetector(): LanguageDetectorMiddleware | undefined;

@@ -14,0 +14,0 @@ retranslate(): void;

@@ -1,2 +0,2 @@

import { FallbackGeneral, FallbackLanguageOption, TreeTranslationsData, OnFormatError } from '../../types';
import { FallbackGeneral, FallbackLanguageOption, TreeTranslationsData, OnFormatError, FetchFn } from '../../types';
import { ObserverOptions, ObserverOptionsInternal } from './observerOptions';

@@ -74,2 +74,6 @@ export declare const DEFAULT_FORMAT_ERROR = "invalid";

onFormatError: OnFormatError;
/**
* Define custom fetch function, used for fetching the translations
*/
fetch: FetchFn;
};

@@ -76,0 +80,0 @@ export declare type TolgeeOptions = Partial<Omit<TolgeeOptionsInternal, 'observerOptions'>> & {

@@ -38,2 +38,6 @@ export declare type ObserverOptionsInternal = {

passToParent: (keyof HTMLElementTagNameMap)[] | ((node: Element) => boolean);
/**
* Encodes full key info into the invisble characters (default: false)
*/
fullKeyEncode: boolean;
};

@@ -40,0 +44,0 @@ export declare type ObserverOptions = Partial<ObserverOptionsInternal>;

@@ -29,2 +29,3 @@ import { CacheDescriptor, CacheDescriptorInternal, DevCredentials, NsFallback, NsType } from '../../types';

onFormatError: import("../../types").OnFormatError;
fetch: import("../../types").FetchFn;
};

@@ -31,0 +32,0 @@ addActiveNs(ns: NsFallback): void;

@@ -137,5 +137,3 @@ import { TolgeeOptions, TolgeePlugin, DevCredentials, TFnType, DefaultParamType, TranslationKey } from './types';

availableLanguages?: string[] | undefined;
fallbackLanguage?: import("./types").FallbackLanguageOption; /**
* Turn off/on events emitting. Is on by default.
*/
fallbackLanguage?: import("./types").FallbackLanguageOption;
ns?: string[] | undefined;

@@ -148,2 +146,3 @@ fallbackNs?: import("./types").FallbackGeneral;

onFormatError: import("./types").OnFormatError;
fetch: import("./types").FetchFn;
};

@@ -150,0 +149,0 @@ /**

@@ -20,3 +20,3 @@ import type { NsFallback } from './general';

export declare type Listener<T> = (e: ListenerEvent<T>) => void;
export declare type TolgeeEvent = 'language' | 'pendingLanguage' | 'loading' | 'fetching' | 'initialLoad' | 'running' | 'cache' | 'update';
export declare type TolgeeEvent = 'language' | 'pendingLanguage' | 'loading' | 'fetching' | 'initialLoad' | 'running' | 'cache' | 'update' | 'permanentChange';
export interface EventType {

@@ -31,2 +31,3 @@ language: string;

update: void;
permanentChange: CacheDescriptorWithKey;
}

@@ -67,3 +68,11 @@ export declare type TolgeeOn<E extends keyof EventType = keyof EventType> = {

(event: 'cache', handler: Listener<CacheDescriptorWithKey>): Subscription;
/**
* Translation was changed or created via dev tools
*/
(event: 'permanentChange', handler: Listener<CacheDescriptorWithKey>): Subscription;
(event: E, handler: unknown): Subscription;
};
export declare type TranslationDescriptor = {
key: string;
namespace: string | undefined;
};

@@ -35,2 +35,3 @@ export declare type FallbackGeneral = undefined | false | string | string[];

export declare type KeyAndNamespacesInternal = Pick<TranslatePropsInternal, 'key' | 'ns' | 'language'>;
export declare type FetchFn = (input: string | URL, init?: RequestInit | undefined) => Promise<Response>;
export {};
import { ChangeTranslationInterface, TreeTranslationsData } from './cache';
import { NsFallback, NsType, TranslateParams, TranslatePropsInternal } from './general';
import { FetchFn, NsFallback, NsType, TranslateParams, TranslatePropsInternal } from './general';
import type { ObserverOptionsInternal } from '../Controller/State/observerOptions';
import { TolgeeInstance } from '../TolgeeCore';
import { TranslationDescriptor } from './events';
export declare type BackendDevProps = {

@@ -10,2 +11,5 @@ apiUrl?: string;

};
export declare type CommonProps = {
fetch: FetchFn;
};
export declare type BackendGetRecordProps = {

@@ -15,7 +19,8 @@ language: string;

};
export declare type BackendGetRecord = (data: BackendGetRecordProps) => Promise<TreeTranslationsData | undefined> | undefined;
export declare type BackendGetRecord = (data: BackendGetRecordProps & CommonProps) => Promise<TreeTranslationsData | undefined> | undefined;
export interface BackendMiddleware {
getRecord: BackendGetRecord;
}
export declare type BackendGetDevRecord = (data: BackendGetRecordProps & BackendDevProps) => Promise<TreeTranslationsData | undefined> | undefined;
export declare type BackendGetDevRecord = (data: BackendGetRecordProps & CommonProps & BackendDevProps) => Promise<TreeTranslationsData | undefined> | undefined;
export declare type BackendGetRecordInternal = (data: BackendGetRecordProps & BackendDevProps) => Promise<TreeTranslationsData | undefined> | undefined;
export declare type BackendDevMiddleware = {

@@ -61,2 +66,3 @@ getRecord: BackendGetDevRecord;

availableLanguages: string[];
fetch: FetchFn;
};

@@ -67,4 +73,4 @@ export declare type LanguageDetectorMiddleware = {

export declare type LanguageStorageMiddleware = {
getLanguage: () => string | undefined | Promise<string | undefined>;
setLanguage: (language: string) => void | Promise<void>;
getLanguage: (props: CommonProps) => string | undefined | Promise<string | undefined>;
setLanguage: (language: string, props: CommonProps) => void | Promise<void>;
};

@@ -117,2 +123,3 @@ export declare type DevCredentials = undefined | {

changeTranslation: ChangeTranslationInterface;
onPermanentChange: (props: TranslationDescriptor) => void;
};

@@ -119,0 +126,0 @@ export declare type UiKeyOption = {

{
"name": "@tolgee/core",
"version": "5.10.1",
"version": "5.10.2-prerelease.2a0213ec.0",
"description": "Library providing ability to translate messages directly in context of developed application.",

@@ -71,3 +71,3 @@ "main": "./dist/tolgee.cjs.js",

"sideEffects": false,
"gitHead": "619a60f30c44c59db1866be0fcbc7f5dc26eb81d"
"gitHead": "07b34d549bf6983a486617d508ee1489fbbc73f5"
}

@@ -9,4 +9,3 @@ import {

TreeTranslationsData,
BackendGetRecord,
BackendGetDevRecord,
BackendGetRecordInternal,
} from '../../types';

@@ -34,4 +33,4 @@ import { getFallbackArray, unique } from '../../helpers';

onCacheChange: EventEmitterInstance<CacheDescriptorWithKey>,
backendGetRecord: BackendGetRecord,
backendGetDevRecord: BackendGetDevRecord,
backendGetRecord: BackendGetRecordInternal,
backendGetDevRecord: BackendGetRecordInternal,
withDefaultNs: (descriptor: CacheDescriptor) => CacheDescriptorInternal,

@@ -38,0 +37,0 @@ isInitialLoading: () => boolean,

@@ -9,2 +9,3 @@ import { Events } from './Events/Events';

KeyAndNamespacesInternal,
TranslationDescriptor,
} from '../types';

@@ -48,3 +49,4 @@ import { Cache } from './Cache/Cache';

getTranslation,
changeTranslation
changeTranslation,
onPermanentChange
);

@@ -110,2 +112,9 @@

function onPermanentChange(props: TranslationDescriptor) {
events.onPermanentChange.emit({
key: props.key,
namespace: props.namespace,
});
}
function init(options: Partial<TolgeeOptions>) {

@@ -112,0 +121,0 @@ state.init(options);

import { EventEmitter } from './EventEmitter';
import { EventEmitterSelective } from './EventEmitterSelective';
import { CacheDescriptorWithKey, TolgeeOn } from '../../types';
import {
CacheDescriptorWithKey,
TolgeeOn,
TranslationDescriptor,
} from '../../types';

@@ -24,2 +28,3 @@ export function Events(

onUpdate: EventEmitterSelective(isActive, getFallbackNs, getDefaultNs),
onPermanentChange: EventEmitter<TranslationDescriptor>(isActive),
setEmitterActive(active: boolean) {

@@ -46,2 +51,4 @@ emitterActive = active;

return self.onUpdate.listen(handler as any);
case 'permanentChange':
return self.onPermanentChange.listen(handler as any);
}

@@ -48,0 +55,0 @@ }) as TolgeeOn,

import { getErrorMessage, isPromise, valueOrPromise } from '../../helpers';
import {
BackendDevMiddleware,
BackendGetRecord,
BackendMiddleware,

@@ -25,2 +24,4 @@ FormatterMiddleware,

FindPositionsInterface,
BackendGetRecordInternal,
TranslationDescriptor,
} from '../../types';

@@ -35,3 +36,4 @@ import { DEFAULT_FORMAT_ERROR } from '../State/initState';

getTranslation: (props: KeyAndNamespacesInternal) => string | undefined,
changeTranslation: ChangeTranslationInterface
changeTranslation: ChangeTranslationInterface,
onPermanentChange: (props: TranslationDescriptor) => void
) {

@@ -86,2 +88,6 @@ const plugins = {

function getCommonProps() {
return { fetch: getInitialOptions().fetch };
}
function setObserver(observer: ObserverMiddleware | undefined) {

@@ -132,2 +138,3 @@ instances.observer = observer?.();

availableLanguages,
...getCommonProps(),
});

@@ -175,2 +182,3 @@ }

findPositions,
onPermanentChange,
});

@@ -197,3 +205,5 @@

const availableLanguages = getAvailableLanguages();
const languageOrPromise = instances.languageStorage?.getLanguage();
const languageOrPromise = instances.languageStorage?.getLanguage(
getCommonProps()
);

@@ -212,3 +222,3 @@ return valueOrPromise(languageOrPromise, (language) => {

setStoredLanguage(language: string) {
instances.languageStorage?.setLanguage(language);
instances.languageStorage?.setLanguage(language, getCommonProps());
},

@@ -222,3 +232,7 @@

for (const backend of instances.backends) {
const data = backend.getRecord({ language, namespace });
const data = backend.getRecord({
language,
namespace,
...getCommonProps(),
});
if (isPromise(data)) {

@@ -236,3 +250,3 @@ return data?.catch((e) => {

return undefined;
}) as BackendGetRecord,
}) as BackendGetRecordInternal,

@@ -247,4 +261,5 @@ getBackendDevRecord: (({ language, namespace }) => {

namespace,
...getCommonProps(),
});
}) as BackendGetRecord,
}) as BackendGetRecordInternal,

@@ -251,0 +266,0 @@ getLanguageDetector() {

@@ -6,2 +6,3 @@ import {

OnFormatError,
FetchFn,
} from '../../types';

@@ -101,2 +102,7 @@ import { sanitizeUrl } from '../../helpers';

onFormatError: OnFormatError;
/**
* Define custom fetch function, used for fetching the translations
*/
fetch: FetchFn;
};

@@ -125,2 +131,3 @@

apiUrl: DEFAULT_API_URL,
fetch: (input, options) => fetch(input, options),
};

@@ -127,0 +134,0 @@

@@ -46,2 +46,7 @@ export type ObserverOptionsInternal = {

passToParent: (keyof HTMLElementTagNameMap)[] | ((node: Element) => boolean);
/**
* Encodes full key info into the invisble characters (default: false)
*/
fullKeyEncode: boolean;
};

@@ -67,2 +72,3 @@

passToParent: ['option', 'optgroup'],
fullKeyEncode: false,
};

@@ -30,3 +30,4 @@ import type { NsFallback } from './general';

| 'cache'
| 'update';
| 'update'
| 'permanentChange';

@@ -42,2 +43,3 @@ export interface EventType {

update: void;
permanentChange: CacheDescriptorWithKey;
}

@@ -86,3 +88,17 @@

(event: 'cache', handler: Listener<CacheDescriptorWithKey>): Subscription;
/**
* Translation was changed or created via dev tools
*/
(
event: 'permanentChange',
handler: Listener<CacheDescriptorWithKey>
): Subscription;
(event: E, handler: unknown): Subscription;
};
export type TranslationDescriptor = {
key: string;
namespace: string | undefined;
};

@@ -61,1 +61,6 @@ export type FallbackGeneral = undefined | false | string | string[];

>;
export type FetchFn = (
input: string | URL,
init?: RequestInit | undefined
) => Promise<Response>;
import { ChangeTranslationInterface, TreeTranslationsData } from './cache';
import {
FetchFn,
NsFallback,

@@ -10,2 +11,3 @@ NsType,

import { TolgeeInstance } from '../TolgeeCore';
import { TranslationDescriptor } from './events';

@@ -18,2 +20,6 @@ export type BackendDevProps = {

export type CommonProps = {
fetch: FetchFn;
};
export type BackendGetRecordProps = {

@@ -25,3 +31,3 @@ language: string;

export type BackendGetRecord = (
data: BackendGetRecordProps
data: BackendGetRecordProps & CommonProps
) => Promise<TreeTranslationsData | undefined> | undefined;

@@ -34,2 +40,6 @@

export type BackendGetDevRecord = (
data: BackendGetRecordProps & CommonProps & BackendDevProps
) => Promise<TreeTranslationsData | undefined> | undefined;
export type BackendGetRecordInternal = (
data: BackendGetRecordProps & BackendDevProps

@@ -89,2 +99,3 @@ ) => Promise<TreeTranslationsData | undefined> | undefined;

availableLanguages: string[];
fetch: FetchFn;
};

@@ -99,4 +110,6 @@

export type LanguageStorageMiddleware = {
getLanguage: () => string | undefined | Promise<string | undefined>;
setLanguage: (language: string) => void | Promise<void>;
getLanguage: (
props: CommonProps
) => string | undefined | Promise<string | undefined>;
setLanguage: (language: string, props: CommonProps) => void | Promise<void>;
};

@@ -159,2 +172,3 @@

changeTranslation: ChangeTranslationInterface;
onPermanentChange: (props: TranslationDescriptor) => void;
};

@@ -161,0 +175,0 @@

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 not supported yet

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 not supported yet

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 not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc