@tolgee/core
Advanced tools
Comparing version 5.22.1-prerelease.aa2f05c1.0 to 5.22.1-prerelease.b7e76156.0
@@ -81,3 +81,3 @@ 'use strict'; | ||
const createFetchFunction = (fetchFn = defaultFetchFunction) => { | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.22.1-prerelease.aa2f05c1.0" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.22.1-prerelease.b7e76156.0" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
}; | ||
@@ -602,3 +602,3 @@ | ||
}; | ||
const onClick = async ({ keysAndDefaults, event }) => { | ||
const onClick = async ({ keysAndDefaults, target }) => { | ||
var _a; | ||
@@ -617,3 +617,3 @@ const withNs = keysAndDefaults.map(({ key, ns, defaultValue }) => { | ||
}); | ||
(_a = instances.ui) === null || _a === void 0 ? void 0 : _a.handleElementClick(withNs, event); | ||
(_a = instances.ui) === null || _a === void 0 ? void 0 : _a.handleElementClick(withNs, target); | ||
}; | ||
@@ -698,2 +698,3 @@ const findPositions = (key, ns) => { | ||
addPlugin, | ||
findPositions: findPositions, | ||
run() { | ||
@@ -1152,3 +1153,3 @@ var _a, _b; | ||
} | ||
const self = Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, events), state), pluginService), cache), { init: init, getTranslation: getTranslation, changeTranslation: changeTranslation, getTranslationNs: getTranslationNs, getDefaultAndFallbackNs: getDefaultAndFallbackNs, async changeLanguage(language) { | ||
const self = Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, events), state), pluginService), cache), { init: init, getTranslation: getTranslation, changeTranslation: changeTranslation, getTranslationNs: getTranslationNs, getDefaultAndFallbackNs: getDefaultAndFallbackNs, findPositions: pluginService.findPositions, async changeLanguage(language) { | ||
if (state.getPendingLanguage() === language && | ||
@@ -1365,2 +1366,6 @@ state.getLanguage() === language) { | ||
/** | ||
* Find positions of keys in the DOM. | ||
*/ | ||
findPositions: controller.findPositions, | ||
/** | ||
* @return current Tolgee options. | ||
@@ -1367,0 +1372,0 @@ */ |
@@ -81,3 +81,3 @@ 'use strict'; | ||
const createFetchFunction = (fetchFn = defaultFetchFunction) => { | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.22.1-prerelease.aa2f05c1.0" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.22.1-prerelease.b7e76156.0" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
}; | ||
@@ -602,3 +602,3 @@ | ||
}; | ||
const onClick = async ({ keysAndDefaults, event }) => { | ||
const onClick = async ({ keysAndDefaults, target }) => { | ||
var _a; | ||
@@ -617,3 +617,3 @@ const withNs = keysAndDefaults.map(({ key, ns, defaultValue }) => { | ||
}); | ||
(_a = instances.ui) === null || _a === void 0 ? void 0 : _a.handleElementClick(withNs, event); | ||
(_a = instances.ui) === null || _a === void 0 ? void 0 : _a.handleElementClick(withNs, target); | ||
}; | ||
@@ -698,2 +698,3 @@ const findPositions = (key, ns) => { | ||
addPlugin, | ||
findPositions: findPositions, | ||
run() { | ||
@@ -1152,3 +1153,3 @@ var _a, _b; | ||
} | ||
const self = Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, events), state), pluginService), cache), { init: init, getTranslation: getTranslation, changeTranslation: changeTranslation, getTranslationNs: getTranslationNs, getDefaultAndFallbackNs: getDefaultAndFallbackNs, async changeLanguage(language) { | ||
const self = Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, events), state), pluginService), cache), { init: init, getTranslation: getTranslation, changeTranslation: changeTranslation, getTranslationNs: getTranslationNs, getDefaultAndFallbackNs: getDefaultAndFallbackNs, findPositions: pluginService.findPositions, async changeLanguage(language) { | ||
if (state.getPendingLanguage() === language && | ||
@@ -1365,2 +1366,6 @@ state.getLanguage() === language) { | ||
/** | ||
* Find positions of keys in the DOM. | ||
*/ | ||
findPositions: controller.findPositions, | ||
/** | ||
* @return current Tolgee options. | ||
@@ -1367,0 +1372,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return Boolean(e&&"function"==typeof e.then)}function n(n,t){return e(n)?Promise.resolve(n).then(t):t(n)}function t(n,t,a){function i(e){const a=t(e);throw n.emit(a),console.error(a),a}try{const n=a();return e(n)?n.catch(i):n}catch(e){i(e)}}function a(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function i(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function o(e){return i(e)||[]}function r(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?o(n):o(null==n?void 0:n[e]);var t}function s(e){return Array.from(new Set(e))}function g(e){return e?e.replace(/\/+$/,""):e}Object.defineProperty(exports,"__esModule",{value:!0});const c=(e,n)=>fetch(e,n),l=(e=c)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.22.1-prerelease.aa2f05c1.0"},null==t?void 0:t.headers)}));function u(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function d(e,n,t){const a=new Set,i=new Set;let r=[];function s(){if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(r.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(o(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class p extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class f extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const h=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):h(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},m=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},b=({language:e,namespace:n})=>n?`${e}:${n}`:e;function y(n,t,a,i,r,g,c){const l=new Map,u=new Map;let d={},f=0;function v(e,t,a){const i=b(e);u.set(i,{data:h(t),version:a}),n.onCacheChange.emit(e)}function y(a){let i;if(!i){const e=d[b(a)];"function"==typeof e&&(i=e())}return i||(i=t(a)),e(i)?null==i?void 0:i.catch((e=>{const t=new p(a,e);throw n.onError.emit(t),console.error(t),t})):i}const L=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=m(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),f+=1},addRecord(e,n){v(e,n,f)},exists(e,n=!1){const t=u.get(b(e));return t&&n?t.version===f:Boolean(t)},getRecord(e){var n;return null===(n=u.get(b(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(b(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return s(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(e,t,a){var i;const o=null===(i=u.get(b(e)))||void 0===i?void 0:i.data;null==o||o.set(t,a),n.onCacheChange.emit(Object.assign(Object.assign({},e),{key:t}))},isFetching(e){if(r())return!0;if(void 0===e)return l.size>0;const n=o(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(m(e).namespace))))},isLoading(e,n){const t=o(n);return Boolean(r()||Array.from(l.keys()).find((n=>{const a=m(n);return(!t.length||t.includes(a.namespace))&&!L.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,t){const o=e.map((e=>{const o=i(e),r=b(o),s=l.get(r);if(s)return{new:!1,promise:s,keyObject:o,cacheKey:r};const g=function(e,t){var i;let o;return t&&(o=null===(i=a(e))||void 0===i?void 0:i.catch((t=>{const a=new p(e,t,!0);return n.onError.emit(a),console.warn(a),y(e)}))),o||(o=y(e)),o}(o,t)||Promise.resolve(void 0);return l.set(r,g),{new:!0,promise:g,keyObject:o,cacheKey:r}}));g.notify(),c.notify();const r=await Promise.all(o.map((e=>e.promise)));return o.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=r[n];t?L.addRecord(e.keyObject,t):L.getRecord(e.keyObject)||L.addRecord(e.keyObject,{})}})),g.notify(),c.notify(),o.map((e=>L.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},m(e)),{data:n.data})))});return L}function L(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const O="invalid",j={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:O,apiUrl:"https://app.tolgee.io",fetch:l(),onTranslationMissing:({key:e})=>e},k=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function E(e,n){const t=k(j,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=l(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function w(e,a,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},p=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function h(e){const n=s({key:e.key,ns:e.ns});return C.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:a().fetch}}function b(e){u.observer=null==e?void 0:e()}function y(){return Boolean(u.observer)}function j(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function E(e){l.ui=e}function w(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function D(e){u.languageDetector=e}function F(e){e&&u.backends.push(e)}function N(e){u.devBackend=e}const C=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:j,setObserver:b,hasObserver:y,setUi:E,hasUi:w,setDevBackend:N,addBackend:F,setLanguageDetector:D,setLanguageStorage:R}))},run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:t,apiUrl:i,projectId:o,highlight:C.highlight,changeTranslation:g,findPositions:p,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(n=u.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:h,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return n(t(c.onError,(e=>new v("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return t(c.onError,(e=>new f("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>t(c.onError,(e=>new v("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:({language:e,namespace:n})=>{for(const t of u.backends){const a=t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=u.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(C.getDevBackend()),formatTranslation(n){var t,{formatEnabled:i}=n,o=L(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:p}=o,f=null!=s?s:g;let v="";null==s&&(v=a().onTranslationMissing(o));let h=null!=f?f:p?"":v;const m=e(),b=i||!(null===(t=u.observer)||void 0===t?void 0:t.outputNotFormattable),y=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=y(h);try{if(f&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&f&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(j=e)?j:"string"==typeof(null==j?void 0:j.message)?j.message:void 0)||O,t=a().onFormatError,i=typeof t;h="string"===i?t:"function"===i?t(n,o):O,h=y(h)}var j;return h}});return C}const R=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const D=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=L(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function F({options:t}){const i=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:u(a),onLanguageChange:u(a),onLoadingChange:u(a),onFetchingChange:u(a),onInitialLoaded:u(a),onRunningChange:u(a),onCacheChange:u(a),onUpdate:d(a,e,n),onPermanentChange:u(a),onError:u(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(b,L),c=R(!1,(()=>v.isFetching()),i.onFetchingChange.emit),l=R(!1,(()=>T.isLoading()),i.onLoadingChange.emit),p=function(e,n,t){let a,i=E();const c=Object.freeze({init(e){i=E(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||c.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>s([...i.initialOptions.ns||[i.initialOptions.defaultNs],...o(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?s([n,...r(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>o(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>m(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?c.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:g(e.apiUrl)}):void 0}});return c}(i.onLanguageChange,i.onPendingLanguageChange,i.onRunningChange),f=w(p.getLanguage,p.getInitialOptions,p.getAvailableLanguages,O,C,A,k,i),v=y(i,f.getBackendRecord,f.getBackendDevRecord,p.withDefaultNs,p.isInitialLoading,c,l);let h;function b(){return p.getFallbackNs()}function L(e){return p.getDefaultNs(e)}function O(e){return[...o(L(e)),...b()]}function j(e){return[...o(null!=e?e:L()),...p.getRequiredNamespaces()]}function k(e,n,t){const a=p.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function F(e){p.init(e),v.addStaticData(p.getInitialOptions().staticData)}function N(e,t){const a=function(e,n){const t=p.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(T.loadRecords(a),(()=>{}))}function C({key:e,ns:n}){const t=p.getFallbackLangs(),a=O(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function A({key:e,ns:n,language:t}){const a=O(null!=n?n:void 0),i=p.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function S(){const t=n(function(){if(p.getLanguage())return;return n(f.getInitialLanguage(),(e=>{const n=e||p.getInitialOptions().defaultLanguage;n&&p.setLanguage(n)}))}(),(()=>N()));if(e(t))return p.setInitialLoading(!0),c.notify(),l.notify(),Promise.resolve(t).then((()=>{p.setInitialLoading(!1),c.notify(),l.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}t&&F(t),i.onUpdate.listen((()=>{p.isRunning()&&f.retranslate()}));const T=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),p),f),v),{init:F,getTranslation:A,changeTranslation:k,getTranslationNs:C,getDefaultAndFallbackNs:O,async changeLanguage(e){p.getPendingLanguage()===e&&p.getLanguage()===e||(p.setPendingLanguage(e),p.isRunning()&&await N(e),e===p.getPendingLanguage()&&(p.setLanguage(e),await f.setStoredLanguage(e)))},async addActiveNs(e,n){n||p.addActiveNs(e),p.isRunning()&&await N(void 0,e)},loadRecords:e=>v.loadRecords(e,T.isDev()),loadRecord:async e=>(await T.loadRecords([e]))[0],isLoading:e=>v.isLoading(p.getLanguage(),e),isLoaded(e){const n=p.getLanguage();if(!n)return!1;const t=p.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=D(...e),t=A(n);return f.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(p.getInitialOptions().apiKey&&p.getInitialOptions().apiUrl),run:()=>(function(){if((f.getLanguageDetector()||f.getLanguageStorage())&&!p.getAvailableLanguages())throw new Error(a("availableLanguages"));if(!p.getLanguage()&&!p.getInitialOptions().defaultLanguage)throw new Error(a(["defaultLanguage","language"]))}(),p.isRunning()||(p.setRunning(!0),f.run(),h=S()),Promise.resolve(h)),stop(){p.isRunning()&&(f.stop(),p.setRunning(!1))}}));return T}const N=0,C=1,A=2;class S extends Error{constructor(e,n,t){let a;a=e===N?"Empty parameter":e===C?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function T(e){return/\s/.test(e)}const I=0,P=1,x=2,U=3,B=4,z=new Set([x,P,I]),K="'",$=new Set(["{","}",K]),M=e=>/[0-9a-zA-Z_]/.test(e);function V(e,n){const[t,a]=function(e){let n=I,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new S(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(N),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case I:i===K?(t+=i,n=P):"{"===i?(c(),n=U):(t+=i,n=I);break;case P:$.has(i)?(t=t.slice(0,-1)+i,n=x):(t+=i,n=I);break;case x:i===K?n=I:(t+=i,n=x);break;case U:"}"===i?(l(),n=I):T(i)?""!==a&&(l(),n=B):(M(i)||g(C),a+=i,n=U);break;case B:"}"==i?n=I:T(i)?n=B:g(C)}return z.has(n)||g(A),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}exports.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>V(e,n)}),e),exports.LanguageDetectorError=f,exports.LanguageStorageError=v,exports.RecordFetchError=p,exports.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=k(e.options,t),n),init(n){const t=function(e){const n=F({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(k(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},exports.createFetchFunction=l,exports.getFallback=i,exports.getFallbackArray=o,exports.getTranslateProps=D; | ||
"use strict";function e(e){return Boolean(e&&"function"==typeof e.then)}function n(n,t){return e(n)?Promise.resolve(n).then(t):t(n)}function t(n,t,a){function i(e){const a=t(e);throw n.emit(a),console.error(a),a}try{const n=a();return e(n)?n.catch(i):n}catch(e){i(e)}}function a(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function i(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function o(e){return i(e)||[]}function r(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?o(n):o(null==n?void 0:n[e]);var t}function s(e){return Array.from(new Set(e))}function g(e){return e?e.replace(/\/+$/,""):e}Object.defineProperty(exports,"__esModule",{value:!0});const c=(e,n)=>fetch(e,n),l=(e=c)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.22.1-prerelease.b7e76156.0"},null==t?void 0:t.headers)}));function u(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function d(e,n,t){const a=new Set,i=new Set;let r=[];function s(){if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(r.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(o(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class p extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class f extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const h=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):h(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},m=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},b=({language:e,namespace:n})=>n?`${e}:${n}`:e;function y(n,t,a,i,r,g,c){const l=new Map,u=new Map;let d={},f=0;function v(e,t,a){const i=b(e);u.set(i,{data:h(t),version:a}),n.onCacheChange.emit(e)}function y(a){let i;if(!i){const e=d[b(a)];"function"==typeof e&&(i=e())}return i||(i=t(a)),e(i)?null==i?void 0:i.catch((e=>{const t=new p(a,e);throw n.onError.emit(t),console.error(t),t})):i}const L=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=m(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),f+=1},addRecord(e,n){v(e,n,f)},exists(e,n=!1){const t=u.get(b(e));return t&&n?t.version===f:Boolean(t)},getRecord(e){var n;return null===(n=u.get(b(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(b(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return s(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(e,t,a){var i;const o=null===(i=u.get(b(e)))||void 0===i?void 0:i.data;null==o||o.set(t,a),n.onCacheChange.emit(Object.assign(Object.assign({},e),{key:t}))},isFetching(e){if(r())return!0;if(void 0===e)return l.size>0;const n=o(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(m(e).namespace))))},isLoading(e,n){const t=o(n);return Boolean(r()||Array.from(l.keys()).find((n=>{const a=m(n);return(!t.length||t.includes(a.namespace))&&!L.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,t){const o=e.map((e=>{const o=i(e),r=b(o),s=l.get(r);if(s)return{new:!1,promise:s,keyObject:o,cacheKey:r};const g=function(e,t){var i;let o;return t&&(o=null===(i=a(e))||void 0===i?void 0:i.catch((t=>{const a=new p(e,t,!0);return n.onError.emit(a),console.warn(a),y(e)}))),o||(o=y(e)),o}(o,t)||Promise.resolve(void 0);return l.set(r,g),{new:!0,promise:g,keyObject:o,cacheKey:r}}));g.notify(),c.notify();const r=await Promise.all(o.map((e=>e.promise)));return o.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=r[n];t?L.addRecord(e.keyObject,t):L.getRecord(e.keyObject)||L.addRecord(e.keyObject,{})}})),g.notify(),c.notify(),o.map((e=>L.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},m(e)),{data:n.data})))});return L}function L(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const O="invalid",j={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:O,apiUrl:"https://app.tolgee.io",fetch:l(),onTranslationMissing:({key:e})=>e},k=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function E(e,n){const t=k(j,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=l(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function w(e,a,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,target:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},p=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function h(e){const n=s({key:e.key,ns:e.ns});return C.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:a().fetch}}function b(e){u.observer=null==e?void 0:e()}function y(){return Boolean(u.observer)}function j(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function E(e){l.ui=e}function w(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function D(e){u.languageDetector=e}function F(e){e&&u.backends.push(e)}function N(e){u.devBackend=e}const C=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:j,setObserver:b,hasObserver:y,setUi:E,hasUi:w,setDevBackend:N,addBackend:F,setLanguageDetector:D,setLanguageStorage:R}))},findPositions:p,run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:t,apiUrl:i,projectId:o,highlight:C.highlight,changeTranslation:g,findPositions:p,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(n=u.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:h,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return n(t(c.onError,(e=>new v("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return t(c.onError,(e=>new f("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>t(c.onError,(e=>new v("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:({language:e,namespace:n})=>{for(const t of u.backends){const a=t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=u.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(C.getDevBackend()),formatTranslation(n){var t,{formatEnabled:i}=n,o=L(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:p}=o,f=null!=s?s:g;let v="";null==s&&(v=a().onTranslationMissing(o));let h=null!=f?f:p?"":v;const m=e(),b=i||!(null===(t=u.observer)||void 0===t?void 0:t.outputNotFormattable),y=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=y(h);try{if(f&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&f&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(j=e)?j:"string"==typeof(null==j?void 0:j.message)?j.message:void 0)||O,t=a().onFormatError,i=typeof t;h="string"===i?t:"function"===i?t(n,o):O,h=y(h)}var j;return h}});return C}const R=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const D=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=L(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function F({options:t}){const i=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:u(a),onLanguageChange:u(a),onLoadingChange:u(a),onFetchingChange:u(a),onInitialLoaded:u(a),onRunningChange:u(a),onCacheChange:u(a),onUpdate:d(a,e,n),onPermanentChange:u(a),onError:u(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(b,L),c=R(!1,(()=>v.isFetching()),i.onFetchingChange.emit),l=R(!1,(()=>S.isLoading()),i.onLoadingChange.emit),p=function(e,n,t){let a,i=E();const c=Object.freeze({init(e){i=E(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||c.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>s([...i.initialOptions.ns||[i.initialOptions.defaultNs],...o(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?s([n,...r(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>o(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>m(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?c.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:g(e.apiUrl)}):void 0}});return c}(i.onLanguageChange,i.onPendingLanguageChange,i.onRunningChange),f=w(p.getLanguage,p.getInitialOptions,p.getAvailableLanguages,O,C,P,k,i),v=y(i,f.getBackendRecord,f.getBackendDevRecord,p.withDefaultNs,p.isInitialLoading,c,l);let h;function b(){return p.getFallbackNs()}function L(e){return p.getDefaultNs(e)}function O(e){return[...o(L(e)),...b()]}function j(e){return[...o(null!=e?e:L()),...p.getRequiredNamespaces()]}function k(e,n,t){const a=p.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function F(e){p.init(e),v.addStaticData(p.getInitialOptions().staticData)}function N(e,t){const a=function(e,n){const t=p.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(S.loadRecords(a),(()=>{}))}function C({key:e,ns:n}){const t=p.getFallbackLangs(),a=O(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function P({key:e,ns:n,language:t}){const a=O(null!=n?n:void 0),i=p.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function A(){const t=n(function(){if(p.getLanguage())return;return n(f.getInitialLanguage(),(e=>{const n=e||p.getInitialOptions().defaultLanguage;n&&p.setLanguage(n)}))}(),(()=>N()));if(e(t))return p.setInitialLoading(!0),c.notify(),l.notify(),Promise.resolve(t).then((()=>{p.setInitialLoading(!1),c.notify(),l.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}t&&F(t),i.onUpdate.listen((()=>{p.isRunning()&&f.retranslate()}));const S=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),p),f),v),{init:F,getTranslation:P,changeTranslation:k,getTranslationNs:C,getDefaultAndFallbackNs:O,findPositions:f.findPositions,async changeLanguage(e){p.getPendingLanguage()===e&&p.getLanguage()===e||(p.setPendingLanguage(e),p.isRunning()&&await N(e),e===p.getPendingLanguage()&&(p.setLanguage(e),await f.setStoredLanguage(e)))},async addActiveNs(e,n){n||p.addActiveNs(e),p.isRunning()&&await N(void 0,e)},loadRecords:e=>v.loadRecords(e,S.isDev()),loadRecord:async e=>(await S.loadRecords([e]))[0],isLoading:e=>v.isLoading(p.getLanguage(),e),isLoaded(e){const n=p.getLanguage();if(!n)return!1;const t=p.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=D(...e),t=P(n);return f.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(p.getInitialOptions().apiKey&&p.getInitialOptions().apiUrl),run:()=>(function(){if((f.getLanguageDetector()||f.getLanguageStorage())&&!p.getAvailableLanguages())throw new Error(a("availableLanguages"));if(!p.getLanguage()&&!p.getInitialOptions().defaultLanguage)throw new Error(a(["defaultLanguage","language"]))}(),p.isRunning()||(p.setRunning(!0),f.run(),h=A()),Promise.resolve(h)),stop(){p.isRunning()&&(f.stop(),p.setRunning(!1))}}));return S}const N=0,C=1,P=2;class A extends Error{constructor(e,n,t){let a;a=e===N?"Empty parameter":e===C?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function S(e){return/\s/.test(e)}const T=0,I=1,x=2,U=3,B=4,z=new Set([x,I,T]),K="'",$=new Set(["{","}",K]),M=e=>/[0-9a-zA-Z_]/.test(e);function V(e,n){const[t,a]=function(e){let n=T,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new A(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(N),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case T:i===K?(t+=i,n=I):"{"===i?(c(),n=U):(t+=i,n=T);break;case I:$.has(i)?(t=t.slice(0,-1)+i,n=x):(t+=i,n=T);break;case x:i===K?n=T:(t+=i,n=x);break;case U:"}"===i?(l(),n=T):S(i)?""!==a&&(l(),n=B):(M(i)||g(C),a+=i,n=U);break;case B:"}"==i?n=T:S(i)?n=B:g(C)}return z.has(n)||g(P),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}exports.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>V(e,n)}),e),exports.LanguageDetectorError=f,exports.LanguageStorageError=v,exports.RecordFetchError=p,exports.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=k(e.options,t),n),init(n){const t=function(e){const n=F({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,findPositions:n.findPositions,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(k(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},exports.createFetchFunction=l,exports.getFallback=i,exports.getFallbackArray=o,exports.getTranslateProps=D; | ||
//# sourceMappingURL=tolgee.cjs.min.js.map |
@@ -77,3 +77,3 @@ function isPromise(value) { | ||
const createFetchFunction = (fetchFn = defaultFetchFunction) => { | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.22.1-prerelease.aa2f05c1.0" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
return (input, init) => fetchFn(input, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'X-Tolgee-SDK-Type': 'JS', 'X-Tolgee-SDK-Version': "5.22.1-prerelease.b7e76156.0" }, init === null || init === void 0 ? void 0 : init.headers) })); | ||
}; | ||
@@ -598,3 +598,3 @@ | ||
}; | ||
const onClick = async ({ keysAndDefaults, event }) => { | ||
const onClick = async ({ keysAndDefaults, target }) => { | ||
var _a; | ||
@@ -613,3 +613,3 @@ const withNs = keysAndDefaults.map(({ key, ns, defaultValue }) => { | ||
}); | ||
(_a = instances.ui) === null || _a === void 0 ? void 0 : _a.handleElementClick(withNs, event); | ||
(_a = instances.ui) === null || _a === void 0 ? void 0 : _a.handleElementClick(withNs, target); | ||
}; | ||
@@ -694,2 +694,3 @@ const findPositions = (key, ns) => { | ||
addPlugin, | ||
findPositions: findPositions, | ||
run() { | ||
@@ -1148,3 +1149,3 @@ var _a, _b; | ||
} | ||
const self = Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, events), state), pluginService), cache), { init: init, getTranslation: getTranslation, changeTranslation: changeTranslation, getTranslationNs: getTranslationNs, getDefaultAndFallbackNs: getDefaultAndFallbackNs, async changeLanguage(language) { | ||
const self = Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, events), state), pluginService), cache), { init: init, getTranslation: getTranslation, changeTranslation: changeTranslation, getTranslationNs: getTranslationNs, getDefaultAndFallbackNs: getDefaultAndFallbackNs, findPositions: pluginService.findPositions, async changeLanguage(language) { | ||
if (state.getPendingLanguage() === language && | ||
@@ -1361,2 +1362,6 @@ state.getLanguage() === language) { | ||
/** | ||
* Find positions of keys in the DOM. | ||
*/ | ||
findPositions: controller.findPositions, | ||
/** | ||
* @return current Tolgee options. | ||
@@ -1363,0 +1368,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
function e(e){return Boolean(e&&"function"==typeof e.then)}function n(n,t){return e(n)?Promise.resolve(n).then(t):t(n)}function t(n,t,a){function i(e){const a=t(e);throw n.emit(a),console.error(a),a}try{const n=a();return e(n)?n.catch(i):n}catch(e){i(e)}}function a(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function i(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function o(e){return i(e)||[]}function r(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?o(n):o(null==n?void 0:n[e]);var t}function s(e){return Array.from(new Set(e))}function g(e){return e?e.replace(/\/+$/,""):e}const c=(e,n)=>fetch(e,n),l=(e=c)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.22.1-prerelease.aa2f05c1.0"},null==t?void 0:t.headers)}));function u(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function d(e,n,t){const a=new Set,i=new Set;let r=[];function s(){if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(r.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(o(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class p extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class f extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const h=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):h(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},m=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},b=({language:e,namespace:n})=>n?`${e}:${n}`:e;function O(n,t,a,i,r,g,c){const l=new Map,u=new Map;let d={},f=0;function v(e,t,a){const i=b(e);u.set(i,{data:h(t),version:a}),n.onCacheChange.emit(e)}function O(a){let i;if(!i){const e=d[b(a)];"function"==typeof e&&(i=e())}return i||(i=t(a)),e(i)?null==i?void 0:i.catch((e=>{const t=new p(a,e);throw n.onError.emit(t),console.error(t),t})):i}const y=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=m(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),f+=1},addRecord(e,n){v(e,n,f)},exists(e,n=!1){const t=u.get(b(e));return t&&n?t.version===f:Boolean(t)},getRecord(e){var n;return null===(n=u.get(b(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(b(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return s(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(e,t,a){var i;const o=null===(i=u.get(b(e)))||void 0===i?void 0:i.data;null==o||o.set(t,a),n.onCacheChange.emit(Object.assign(Object.assign({},e),{key:t}))},isFetching(e){if(r())return!0;if(void 0===e)return l.size>0;const n=o(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(m(e).namespace))))},isLoading(e,n){const t=o(n);return Boolean(r()||Array.from(l.keys()).find((n=>{const a=m(n);return(!t.length||t.includes(a.namespace))&&!y.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,t){const o=e.map((e=>{const o=i(e),r=b(o),s=l.get(r);if(s)return{new:!1,promise:s,keyObject:o,cacheKey:r};const g=function(e,t){var i;let o;return t&&(o=null===(i=a(e))||void 0===i?void 0:i.catch((t=>{const a=new p(e,t,!0);return n.onError.emit(a),console.warn(a),O(e)}))),o||(o=O(e)),o}(o,t)||Promise.resolve(void 0);return l.set(r,g),{new:!0,promise:g,keyObject:o,cacheKey:r}}));g.notify(),c.notify();const r=await Promise.all(o.map((e=>e.promise)));return o.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=r[n];t?y.addRecord(e.keyObject,t):y.getRecord(e.keyObject)||y.addRecord(e.keyObject,{})}})),g.notify(),c.notify(),o.map((e=>y.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},m(e)),{data:n.data})))});return y}function y(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const L="invalid",j={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:L,apiUrl:"https://app.tolgee.io",fetch:l(),onTranslationMissing:({key:e})=>e},k=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function w(e,n){const t=k(j,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=l(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function E(e,a,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},p=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function h(e){const n=s({key:e.key,ns:e.ns});return A.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:a().fetch}}function b(e){u.observer=null==e?void 0:e()}function O(){return Boolean(u.observer)}function j(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function w(e){l.ui=e}function E(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function N(e){u.languageDetector=e}function D(e){e&&u.backends.push(e)}function C(e){u.devBackend=e}const A=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:j,setObserver:b,hasObserver:O,setUi:w,hasUi:E,setDevBackend:C,addBackend:D,setLanguageDetector:N,setLanguageStorage:R}))},run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:t,apiUrl:i,projectId:o,highlight:A.highlight,changeTranslation:g,findPositions:p,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(n=u.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:h,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return n(t(c.onError,(e=>new v("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return t(c.onError,(e=>new f("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>t(c.onError,(e=>new v("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:({language:e,namespace:n})=>{for(const t of u.backends){const a=t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=u.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(A.getDevBackend()),formatTranslation(n){var t,{formatEnabled:i}=n,o=y(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:p}=o,f=null!=s?s:g;let v="";null==s&&(v=a().onTranslationMissing(o));let h=null!=f?f:p?"":v;const m=e(),b=i||!(null===(t=u.observer)||void 0===t?void 0:t.outputNotFormattable),O=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=O(h);try{if(f&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&f&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(j=e)?j:"string"==typeof(null==j?void 0:j.message)?j.message:void 0)||L,t=a().onFormatError,i=typeof t;h="string"===i?t:"function"===i?t(n,o):L,h=O(h)}var j;return h}});return A}const R=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const N=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=y(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function D({options:t}){const i=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:u(a),onLanguageChange:u(a),onLoadingChange:u(a),onFetchingChange:u(a),onInitialLoaded:u(a),onRunningChange:u(a),onCacheChange:u(a),onUpdate:d(a,e,n),onPermanentChange:u(a),onError:u(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(b,y),c=R(!1,(()=>v.isFetching()),i.onFetchingChange.emit),l=R(!1,(()=>S.isLoading()),i.onLoadingChange.emit),p=function(e,n,t){let a,i=w();const c=Object.freeze({init(e){i=w(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||c.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>s([...i.initialOptions.ns||[i.initialOptions.defaultNs],...o(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?s([n,...r(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>o(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>m(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?c.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:g(e.apiUrl)}):void 0}});return c}(i.onLanguageChange,i.onPendingLanguageChange,i.onRunningChange),f=E(p.getLanguage,p.getInitialOptions,p.getAvailableLanguages,L,A,F,k,i),v=O(i,f.getBackendRecord,f.getBackendDevRecord,p.withDefaultNs,p.isInitialLoading,c,l);let h;function b(){return p.getFallbackNs()}function y(e){return p.getDefaultNs(e)}function L(e){return[...o(y(e)),...b()]}function j(e){return[...o(null!=e?e:y()),...p.getRequiredNamespaces()]}function k(e,n,t){const a=p.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function D(e){p.init(e),v.addStaticData(p.getInitialOptions().staticData)}function C(e,t){const a=function(e,n){const t=p.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(S.loadRecords(a),(()=>{}))}function A({key:e,ns:n}){const t=p.getFallbackLangs(),a=L(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function F({key:e,ns:n,language:t}){const a=L(null!=n?n:void 0),i=p.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function I(){const t=n(function(){if(p.getLanguage())return;return n(f.getInitialLanguage(),(e=>{const n=e||p.getInitialOptions().defaultLanguage;n&&p.setLanguage(n)}))}(),(()=>C()));if(e(t))return p.setInitialLoading(!0),c.notify(),l.notify(),Promise.resolve(t).then((()=>{p.setInitialLoading(!1),c.notify(),l.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}t&&D(t),i.onUpdate.listen((()=>{p.isRunning()&&f.retranslate()}));const S=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),p),f),v),{init:D,getTranslation:F,changeTranslation:k,getTranslationNs:A,getDefaultAndFallbackNs:L,async changeLanguage(e){p.getPendingLanguage()===e&&p.getLanguage()===e||(p.setPendingLanguage(e),p.isRunning()&&await C(e),e===p.getPendingLanguage()&&(p.setLanguage(e),await f.setStoredLanguage(e)))},async addActiveNs(e,n){n||p.addActiveNs(e),p.isRunning()&&await C(void 0,e)},loadRecords:e=>v.loadRecords(e,S.isDev()),loadRecord:async e=>(await S.loadRecords([e]))[0],isLoading:e=>v.isLoading(p.getLanguage(),e),isLoaded(e){const n=p.getLanguage();if(!n)return!1;const t=p.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=N(...e),t=F(n);return f.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(p.getInitialOptions().apiKey&&p.getInitialOptions().apiUrl),run:()=>(function(){if((f.getLanguageDetector()||f.getLanguageStorage())&&!p.getAvailableLanguages())throw new Error(a("availableLanguages"));if(!p.getLanguage()&&!p.getInitialOptions().defaultLanguage)throw new Error(a(["defaultLanguage","language"]))}(),p.isRunning()||(p.setRunning(!0),f.run(),h=I()),Promise.resolve(h)),stop(){p.isRunning()&&(f.stop(),p.setRunning(!1))}}));return S}const C=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=k(e.options,t),n),init(n){const t=function(e){const n=D({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(k(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},A=0,F=1,I=2;class S extends Error{constructor(e,n,t){let a;a=e===A?"Empty parameter":e===F?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function T(e){return/\s/.test(e)}const P=0,U=1,B=2,x=3,z=4,K=new Set([B,U,P]),$="'",M=new Set(["{","}",$]),V=e=>/[0-9a-zA-Z_]/.test(e);function W(e,n){const[t,a]=function(e){let n=P,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new S(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(A),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case P:i===$?(t+=i,n=U):"{"===i?(c(),n=x):(t+=i,n=P);break;case U:M.has(i)?(t=t.slice(0,-1)+i,n=B):(t+=i,n=P);break;case B:i===$?n=P:(t+=i,n=B);break;case x:"}"===i?(l(),n=P):T(i)?""!==a&&(l(),n=z):(V(i)||g(F),a+=i,n=x);break;case z:"}"==i?n=P:T(i)?n=z:g(F)}return K.has(n)||g(I),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}const q=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>W(e,n)}),e);export{q as FormatSimple,f as LanguageDetectorError,v as LanguageStorageError,p as RecordFetchError,C as TolgeeCore,l as createFetchFunction,i as getFallback,o as getFallbackArray,N as getTranslateProps}; | ||
function e(e){return Boolean(e&&"function"==typeof e.then)}function n(n,t){return e(n)?Promise.resolve(n).then(t):t(n)}function t(n,t,a){function i(e){const a=t(e);throw n.emit(a),console.error(a),a}try{const n=a();return e(n)?n.catch(i):n}catch(e){i(e)}}function a(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function i(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function o(e){return i(e)||[]}function r(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?o(n):o(null==n?void 0:n[e]);var t}function s(e){return Array.from(new Set(e))}function g(e){return e?e.replace(/\/+$/,""):e}const c=(e,n)=>fetch(e,n),l=(e=c)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.22.1-prerelease.b7e76156.0"},null==t?void 0:t.headers)}));function u(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function d(e,n,t){const a=new Set,i=new Set;let r=[];function s(){if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(r.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(o(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class f extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class p extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const h=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):h(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},m=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},b=({language:e,namespace:n})=>n?`${e}:${n}`:e;function O(n,t,a,i,r,g,c){const l=new Map,u=new Map;let d={},p=0;function v(e,t,a){const i=b(e);u.set(i,{data:h(t),version:a}),n.onCacheChange.emit(e)}function O(a){let i;if(!i){const e=d[b(a)];"function"==typeof e&&(i=e())}return i||(i=t(a)),e(i)?null==i?void 0:i.catch((e=>{const t=new f(a,e);throw n.onError.emit(t),console.error(t),t})):i}const y=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=m(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),p+=1},addRecord(e,n){v(e,n,p)},exists(e,n=!1){const t=u.get(b(e));return t&&n?t.version===p:Boolean(t)},getRecord(e){var n;return null===(n=u.get(b(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(b(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return s(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(b({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(e,t,a){var i;const o=null===(i=u.get(b(e)))||void 0===i?void 0:i.data;null==o||o.set(t,a),n.onCacheChange.emit(Object.assign(Object.assign({},e),{key:t}))},isFetching(e){if(r())return!0;if(void 0===e)return l.size>0;const n=o(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(m(e).namespace))))},isLoading(e,n){const t=o(n);return Boolean(r()||Array.from(l.keys()).find((n=>{const a=m(n);return(!t.length||t.includes(a.namespace))&&!y.exists({namespace:a.namespace,language:e})})))},async loadRecords(e,t){const o=e.map((e=>{const o=i(e),r=b(o),s=l.get(r);if(s)return{new:!1,promise:s,keyObject:o,cacheKey:r};const g=function(e,t){var i;let o;return t&&(o=null===(i=a(e))||void 0===i?void 0:i.catch((t=>{const a=new f(e,t,!0);return n.onError.emit(a),console.warn(a),O(e)}))),o||(o=O(e)),o}(o,t)||Promise.resolve(void 0);return l.set(r,g),{new:!0,promise:g,keyObject:o,cacheKey:r}}));g.notify(),c.notify();const r=await Promise.all(o.map((e=>e.promise)));return o.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=r[n];t?y.addRecord(e.keyObject,t):y.getRecord(e.keyObject)||y.addRecord(e.keyObject,{})}})),g.notify(),c.notify(),o.map((e=>y.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},m(e)),{data:n.data})))});return y}function y(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const L="invalid",j={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:L,apiUrl:"https://app.tolgee.io",fetch:l(),onTranslationMissing:({key:e})=>e},k=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function w(e,n){const t=k(j,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=l(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function E(e,a,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,target:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},f=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function h(e){const n=s({key:e.key,ns:e.ns});return P.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:a().fetch}}function b(e){u.observer=null==e?void 0:e()}function O(){return Boolean(u.observer)}function j(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function w(e){l.ui=e}function E(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function N(e){u.languageDetector=e}function D(e){e&&u.backends.push(e)}function C(e){u.devBackend=e}const P=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:j,setObserver:b,hasObserver:O,setUi:w,hasUi:E,setDevBackend:C,addBackend:D,setLanguageDetector:N,setLanguageStorage:R}))},findPositions:f,run(){var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:t,apiUrl:i,projectId:o,highlight:P.highlight,changeTranslation:g,findPositions:f,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(n=u.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:h,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return n(t(c.onError,(e=>new v("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return t(c.onError,(e=>new p("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>t(c.onError,(e=>new v("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:({language:e,namespace:n})=>{for(const t of u.backends){const a=t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=u.devBackend)||void 0===t?void 0:t.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(P.getDevBackend()),formatTranslation(n){var t,{formatEnabled:i}=n,o=y(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:f}=o,p=null!=s?s:g;let v="";null==s&&(v=a().onTranslationMissing(o));let h=null!=p?p:f?"":v;const m=e(),b=i||!(null===(t=u.observer)||void 0===t?void 0:t.outputNotFormattable),O=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=O(h);try{if(p&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&p&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(j=e)?j:"string"==typeof(null==j?void 0:j.message)?j.message:void 0)||L,t=a().onFormatError,i=typeof t;h="string"===i?t:"function"===i?t(n,o):L,h=O(h)}var j;return h}});return P}const R=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const N=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=y(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function D({options:t}){const i=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:u(a),onLanguageChange:u(a),onLoadingChange:u(a),onFetchingChange:u(a),onInitialLoaded:u(a),onRunningChange:u(a),onCacheChange:u(a),onUpdate:d(a,e,n),onPermanentChange:u(a),onError:u(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(b,y),c=R(!1,(()=>v.isFetching()),i.onFetchingChange.emit),l=R(!1,(()=>I.isLoading()),i.onLoadingChange.emit),f=function(e,n,t){let a,i=w();const c=Object.freeze({init(e){i=w(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||c.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>s([...i.initialOptions.ns||[i.initialOptions.defaultNs],...o(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||c.getLanguage();return n?s([n,...r(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>o(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>m(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?c.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:g(e.apiUrl)}):void 0}});return c}(i.onLanguageChange,i.onPendingLanguageChange,i.onRunningChange),p=E(f.getLanguage,f.getInitialOptions,f.getAvailableLanguages,L,P,A,k,i),v=O(i,p.getBackendRecord,p.getBackendDevRecord,f.withDefaultNs,f.isInitialLoading,c,l);let h;function b(){return f.getFallbackNs()}function y(e){return f.getDefaultNs(e)}function L(e){return[...o(y(e)),...b()]}function j(e){return[...o(null!=e?e:y()),...f.getRequiredNamespaces()]}function k(e,n,t){const a=f.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function D(e){f.init(e),v.addStaticData(f.getInitialOptions().staticData)}function C(e,t){const a=function(e,n){const t=f.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(I.loadRecords(a),(()=>{}))}function P({key:e,ns:n}){const t=f.getFallbackLangs(),a=L(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function A({key:e,ns:n,language:t}){const a=L(null!=n?n:void 0),i=f.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function F(){const t=n(function(){if(f.getLanguage())return;return n(p.getInitialLanguage(),(e=>{const n=e||f.getInitialOptions().defaultLanguage;n&&f.setLanguage(n)}))}(),(()=>C()));if(e(t))return f.setInitialLoading(!0),c.notify(),l.notify(),Promise.resolve(t).then((()=>{f.setInitialLoading(!1),c.notify(),l.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}t&&D(t),i.onUpdate.listen((()=>{f.isRunning()&&p.retranslate()}));const I=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),f),p),v),{init:D,getTranslation:A,changeTranslation:k,getTranslationNs:P,getDefaultAndFallbackNs:L,findPositions:p.findPositions,async changeLanguage(e){f.getPendingLanguage()===e&&f.getLanguage()===e||(f.setPendingLanguage(e),f.isRunning()&&await C(e),e===f.getPendingLanguage()&&(f.setLanguage(e),await p.setStoredLanguage(e)))},async addActiveNs(e,n){n||f.addActiveNs(e),f.isRunning()&&await C(void 0,e)},loadRecords:e=>v.loadRecords(e,I.isDev()),loadRecord:async e=>(await I.loadRecords([e]))[0],isLoading:e=>v.isLoading(f.getLanguage(),e),isLoaded(e){const n=f.getLanguage();if(!n)return!1;const t=f.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=N(...e),t=A(n);return p.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(f.getInitialOptions().apiKey&&f.getInitialOptions().apiUrl),run:()=>(function(){if((p.getLanguageDetector()||p.getLanguageStorage())&&!f.getAvailableLanguages())throw new Error(a("availableLanguages"));if(!f.getLanguage()&&!f.getInitialOptions().defaultLanguage)throw new Error(a(["defaultLanguage","language"]))}(),f.isRunning()||(f.setRunning(!0),p.run(),h=F()),Promise.resolve(h)),stop(){f.isRunning()&&(p.stop(),f.setRunning(!1))}}));return I}const C=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=k(e.options,t),n),init(n){const t=function(e){const n=D({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,findPositions:n.findPositions,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(k(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},P=0,A=1,F=2;class I extends Error{constructor(e,n,t){let a;a=e===P?"Empty parameter":e===A?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function S(e){return/\s/.test(e)}const T=0,U=1,B=2,x=3,z=4,K=new Set([B,U,T]),$="'",M=new Set(["{","}",$]),V=e=>/[0-9a-zA-Z_]/.test(e);function W(e,n){const[t,a]=function(e){let n=T,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new I(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(P),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case T:i===$?(t+=i,n=U):"{"===i?(c(),n=x):(t+=i,n=T);break;case U:M.has(i)?(t=t.slice(0,-1)+i,n=B):(t+=i,n=T);break;case B:i===$?n=T:(t+=i,n=B);break;case x:"}"===i?(l(),n=T):S(i)?""!==a&&(l(),n=z):(V(i)||g(A),a+=i,n=x);break;case z:"}"==i?n=T:S(i)?n=z:g(A)}return K.has(n)||g(F),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}const q=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>W(e,n)}),e);export{q as FormatSimple,p as LanguageDetectorError,v as LanguageStorageError,f as RecordFetchError,C as TolgeeCore,l as createFetchFunction,i as getFallback,o as getFallbackArray,N as getTranslateProps}; | ||
//# sourceMappingURL=tolgee.esm.min.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@tolgee/core"]={})}(this,(function(e){"use strict";function n(e){return Boolean(e&&"function"==typeof e.then)}function t(e,t){return n(e)?Promise.resolve(e).then(t):t(e)}function a(e,t,a){function i(n){const a=t(n);throw e.emit(a),console.error(a),a}try{const e=a();return n(e)?e.catch(i):e}catch(e){i(e)}}function i(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function o(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function r(e){return o(e)||[]}function s(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?r(n):r(null==n?void 0:n[e]);var t}function g(e){return Array.from(new Set(e))}function c(e){return e?e.replace(/\/+$/,""):e}const l=(e,n)=>fetch(e,n),u=(e=l)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.22.1-prerelease.aa2f05c1.0"},null==t?void 0:t.headers)}));function d(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function f(e,n,t){const a=new Set,i=new Set;let o=[];function s(){if(0===o.length)return;const e=o;o=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(o.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(r(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class p extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class h extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const m=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):m(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},b=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},y=({language:e,namespace:n})=>n?`${e}:${n}`:e;function L(e,t,a,i,o,s,c){const l=new Map,u=new Map;let d={},f=0;function v(n,t,a){const i=y(n);u.set(i,{data:m(t),version:a}),e.onCacheChange.emit(n)}function h(a){let i;if(!i){const e=d[y(a)];"function"==typeof e&&(i=e())}return i||(i=t(a)),n(i)?null==i?void 0:i.catch((n=>{const t=new p(a,n);throw e.onError.emit(t),console.error(t),t})):i}const L=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=b(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),f+=1},addRecord(e,n){v(e,n,f)},exists(e,n=!1){const t=u.get(y(e));return t&&n?t.version===f:Boolean(t)},getRecord(e){var n;return null===(n=u.get(y(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(y(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(y({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return g(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(y({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(n,t,a){var i;const o=null===(i=u.get(y(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.onCacheChange.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching(e){if(o())return!0;if(void 0===e)return l.size>0;const n=r(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(b(e).namespace))))},isLoading(e,n){const t=r(n);return Boolean(o()||Array.from(l.keys()).find((n=>{const a=b(n);return(!t.length||t.includes(a.namespace))&&!L.exists({namespace:a.namespace,language:e})})))},async loadRecords(n,t){const o=n.map((n=>{const o=i(n),r=y(o),s=l.get(r);if(s)return{new:!1,promise:s,keyObject:o,cacheKey:r};const g=function(n,t){var i;let o;return t&&(o=null===(i=a(n))||void 0===i?void 0:i.catch((t=>{const a=new p(n,t,!0);return e.onError.emit(a),console.warn(a),h(n)}))),o||(o=h(n)),o}(o,t)||Promise.resolve(void 0);return l.set(r,g),{new:!0,promise:g,keyObject:o,cacheKey:r}}));s.notify(),c.notify();const r=await Promise.all(o.map((e=>e.promise)));return o.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=r[n];t?L.addRecord(e.keyObject,t):L.getRecord(e.keyObject)||L.addRecord(e.keyObject,{})}})),s.notify(),c.notify(),o.map((e=>L.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},b(e)),{data:n.data})))});return L}function O(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const j="invalid",k={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:j,apiUrl:"https://app.tolgee.io",fetch:u(),onTranslationMissing:({key:e})=>e},E=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function w(e,n){const t=E(k,null==n?void 0:n.initialOptions,e);return t.apiUrl=c(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=u(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function R(e,n,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},f=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function p(e){const n=s({key:e.key,ns:e.ns});return C.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:n().fetch}}function b(e){u.observer=null==e?void 0:e()}function y(){return Boolean(u.observer)}function L(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function E(e){l.ui=e}function w(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function D(e){u.languageDetector=e}function F(e){e&&u.backends.push(e)}function N(e){u.devBackend=e}const C=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:L,setObserver:b,hasObserver:y,setUi:E,hasUi:w,setDevBackend:N,addBackend:F,setLanguageDetector:D,setLanguageStorage:R}))},run(){var e,t;const{apiKey:a,apiUrl:i,projectId:o,observerOptions:r}=n();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:a,apiUrl:i,projectId:o,highlight:C.highlight,changeTranslation:g,findPositions:f,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(t=u.observer)||void 0===t||t.run({mouseHighlight:!0,options:r,translate:p,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return t(a(c.onError,(e=>new h("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return a(c.onError,(e=>new v("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>a(c.onError,(e=>new h("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:({language:e,namespace:n})=>{for(const t of u.backends){const a=t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:({language:e,namespace:t})=>{var a;const{apiKey:i,apiUrl:o,projectId:r}=n();return null===(a=u.devBackend)||void 0===a?void 0:a.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:t},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(C.getDevBackend()),formatTranslation(t){var a,{formatEnabled:i}=t,o=O(t,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:f}=o,p=null!=s?s:g;let v="";null==s&&(v=n().onTranslationMissing(o));let h=null!=p?p:f?"":v;const m=e(),b=i||!(null===(a=u.observer)||void 0===a?void 0:a.outputNotFormattable),y=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=y(h);try{if(p&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&p&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const t=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||j,a=n().onFormatError,i=typeof a;h="string"===i?a:"function"===i?a(t,o):j,h=y(h)}var L;return h}});return C}const D=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const F=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=O(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function N({options:e}){const a=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:d(a),onLanguageChange:d(a),onLoadingChange:d(a),onFetchingChange:d(a),onInitialLoaded:d(a),onRunningChange:d(a),onCacheChange:d(a),onUpdate:f(a,e,n),onPermanentChange:d(a),onError:d(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(m,y),o=D(!1,(()=>v.isFetching()),a.onFetchingChange.emit),l=D(!1,(()=>S.isLoading()),a.onLoadingChange.emit),u=function(e,n,t){let a,i=w();const o=Object.freeze({init(e){i=w(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||o.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){r(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){r(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>g([...i.initialOptions.ns||[i.initialOptions.defaultNs],...r(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||o.getLanguage();return n?g([n,...s(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>r(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>b(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?o.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:c(e.apiUrl)}):void 0}});return o}(a.onLanguageChange,a.onPendingLanguageChange,a.onRunningChange),p=R(u.getLanguage,u.getInitialOptions,u.getAvailableLanguages,O,C,T,k,a),v=L(a,p.getBackendRecord,p.getBackendDevRecord,u.withDefaultNs,u.isInitialLoading,o,l);let h;function m(){return u.getFallbackNs()}function y(e){return u.getDefaultNs(e)}function O(e){return[...r(y(e)),...m()]}function j(e){return[...r(null!=e?e:y()),...u.getRequiredNamespaces()]}function k(e,n,t){const a=u.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function E(e){u.init(e),v.addStaticData(u.getInitialOptions().staticData)}function N(e,n){const a=function(e,n){const t=u.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,n);if(a.length)return t(S.loadRecords(a),(()=>{}))}function C({key:e,ns:n}){const t=u.getFallbackLangs(),a=O(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function T({key:e,ns:n,language:t}){const a=O(null!=n?n:void 0),i=u.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function A(){const e=t(function(){if(u.getLanguage())return;return t(p.getInitialLanguage(),(e=>{const n=e||u.getInitialOptions().defaultLanguage;n&&u.setLanguage(n)}))}(),(()=>N()));if(n(e))return u.setInitialLoading(!0),o.notify(),l.notify(),Promise.resolve(e).then((()=>{u.setInitialLoading(!1),o.notify(),l.notify(),a.onInitialLoaded.emit()}));a.onInitialLoaded.emit()}e&&E(e),a.onUpdate.listen((()=>{u.isRunning()&&p.retranslate()}));const S=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},a),u),p),v),{init:E,getTranslation:T,changeTranslation:k,getTranslationNs:C,getDefaultAndFallbackNs:O,async changeLanguage(e){u.getPendingLanguage()===e&&u.getLanguage()===e||(u.setPendingLanguage(e),u.isRunning()&&await N(e),e===u.getPendingLanguage()&&(u.setLanguage(e),await p.setStoredLanguage(e)))},async addActiveNs(e,n){n||u.addActiveNs(e),u.isRunning()&&await N(void 0,e)},loadRecords:e=>v.loadRecords(e,S.isDev()),loadRecord:async e=>(await S.loadRecords([e]))[0],isLoading:e=>v.isLoading(u.getLanguage(),e),isLoaded(e){const n=u.getLanguage();if(!n)return!1;const t=u.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=F(...e),t=T(n);return p.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(u.getInitialOptions().apiKey&&u.getInitialOptions().apiUrl),run:()=>(function(){if((p.getLanguageDetector()||p.getLanguageStorage())&&!u.getAvailableLanguages())throw new Error(i("availableLanguages"));if(!u.getLanguage()&&!u.getInitialOptions().defaultLanguage)throw new Error(i(["defaultLanguage","language"]))}(),u.isRunning()||(u.setRunning(!0),p.run(),h=A()),Promise.resolve(h)),stop(){u.isRunning()&&(p.stop(),u.setRunning(!1))}}));return S}const C=0,T=1,A=2;class S extends Error{constructor(e,n,t){let a;a=e===C?"Empty parameter":e===T?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function I(e){return/\s/.test(e)}const P=0,U=1,x=2,B=3,z=4,K=new Set([x,U,P]),$="'",M=new Set(["{","}",$]),V=e=>/[0-9a-zA-Z_]/.test(e);function W(e,n){const[t,a]=function(e){let n=P,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new S(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(C),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case P:i===$?(t+=i,n=U):"{"===i?(c(),n=B):(t+=i,n=P);break;case U:M.has(i)?(t=t.slice(0,-1)+i,n=x):(t+=i,n=P);break;case x:i===$?n=P:(t+=i,n=x);break;case B:"}"===i?(l(),n=P):I(i)?""!==a&&(l(),n=z):(V(i)||g(T),a+=i,n=B);break;case z:"}"==i?n=P:I(i)?n=z:g(T)}return K.has(n)||g(A),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}e.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>W(e,n)}),e),e.LanguageDetectorError=v,e.LanguageStorageError=h,e.RecordFetchError=p,e.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=E(e.options,t),n),init(n){const t=function(e){const n=N({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,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}(E(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},e.createFetchFunction=u,e.getFallback=o,e.getFallbackArray=r,e.getTranslateProps=F,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@tolgee/core"]={})}(this,(function(e){"use strict";function n(e){return Boolean(e&&"function"==typeof e.then)}function t(e,t){return n(e)?Promise.resolve(e).then(t):t(e)}function a(e,t,a){function i(n){const a=t(n);throw e.emit(a),console.error(a),a}try{const e=a();return n(e)?e.catch(i):e}catch(e){i(e)}}function i(e){const n=(Array.isArray(e)?e:[e]).map((e=>`'${e}'`)),t=n.slice(-2).join(" or ");return`Tolgee: You need to specify ${[...n.slice(0,-2),t].join(", ")} option`}function o(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function r(e){return o(e)||[]}function s(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?r(n):r(null==n?void 0:n[e]);var t}function g(e){return Array.from(new Set(e))}function c(e){return e?e.replace(/\/+$/,""):e}const l=(e,n)=>fetch(e,n),u=(e=l)=>(n,t)=>e(n,Object.assign(Object.assign({},t),{headers:Object.assign({"X-Tolgee-SDK-Type":"JS","X-Tolgee-SDK-Version":"5.22.1-prerelease.b7e76156.0"},null==t?void 0:t.headers)}));function d(e){let n=[];return Object.freeze({listen(e){const t=n=>{e(n)};return n.push(t),{unsubscribe(){n=n.filter((e=>t!==e))}}},emit(t){e()&&n.forEach((e=>e({value:t})))}})}function f(e,n,t){const a=new Set,i=new Set;let o=[];function s(){if(0===o.length)return;const e=o;o=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));!function(e){const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))}(t?Array.from(t.keys()):void 0)}return Object.freeze({emit(n,t){e()&&(o.push(n),t?setTimeout(s,0):s())},listen(e){a.add(e);return{unsubscribe:()=>{a.delete(e)}}},listenSome(e){const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(r(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a}})}class p extends Error{constructor(e,n,t=!1){const{language:a,namespace:i}=e;super(`Tolgee: Failed to fetch record for "${a}"${i&&` and "${i}"`}`),this.cause=n,this.isDev=t,this.name="RecordFetchError",this.language=a,this.namespace=i}}class v extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageDetectorError"}}class h extends Error{constructor(e,n){super(e),this.cause=n,this.name="LanguageStorageError"}}const m=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):m(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},b=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},y=({language:e,namespace:n})=>n?`${e}:${n}`:e;function L(e,t,a,i,o,s,c){const l=new Map,u=new Map;let d={},f=0;function v(n,t,a){const i=y(n);u.set(i,{data:m(t),version:a}),e.onCacheChange.emit(n)}function h(a){let i;if(!i){const e=d[y(a)];"function"==typeof e&&(i=e())}return i||(i=t(a)),n(i)?null==i?void 0:i.catch((n=>{const t=new p(a,n);throw e.onError.emit(t),console.error(t),t})):i}const L=Object.freeze({addStaticData(e){e&&(d=Object.assign(Object.assign({},d),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=b(e),a=u.get(e);a&&0!==a.version||v(t,n,0)}})))},invalidate(){l.clear(),f+=1},addRecord(e,n){v(e,n,f)},exists(e,n=!1){const t=u.get(y(e));return t&&n?t.version===f:Boolean(t)},getRecord(e){var n;return null===(n=u.get(y(i(e))))||void 0===n?void 0:n.data},getTranslation(e,n){var t;return null===(t=u.get(y(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(y({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return g(e)},getTranslationFallback(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(y({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation(n,t,a){var i;const o=null===(i=u.get(y(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.onCacheChange.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching(e){if(o())return!0;if(void 0===e)return l.size>0;const n=r(e);return Boolean(Array.from(l.keys()).find((e=>n.includes(b(e).namespace))))},isLoading(e,n){const t=r(n);return Boolean(o()||Array.from(l.keys()).find((n=>{const a=b(n);return(!t.length||t.includes(a.namespace))&&!L.exists({namespace:a.namespace,language:e})})))},async loadRecords(n,t){const o=n.map((n=>{const o=i(n),r=y(o),s=l.get(r);if(s)return{new:!1,promise:s,keyObject:o,cacheKey:r};const g=function(n,t){var i;let o;return t&&(o=null===(i=a(n))||void 0===i?void 0:i.catch((t=>{const a=new p(n,t,!0);return e.onError.emit(a),console.warn(a),h(n)}))),o||(o=h(n)),o}(o,t)||Promise.resolve(void 0);return l.set(r,g),{new:!0,promise:g,keyObject:o,cacheKey:r}}));s.notify(),c.notify();const r=await Promise.all(o.map((e=>e.promise)));return o.forEach(((e,n)=>{const t=l.get(e.cacheKey)!==e.promise;if(e.new&&!t){l.delete(e.cacheKey);const t=r[n];t?L.addRecord(e.keyObject,t):L.getRecord(e.keyObject)||L.addRecord(e.keyObject,{})}})),s.notify(),c.notify(),o.map((e=>L.getRecord(e.keyObject)))},getAllRecords:()=>Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},b(e)),{data:n.data})))});return L}function O(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const j="invalid",k={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"],fullKeyEncode:!1},observerType:"invisible",onFormatError:j,apiUrl:"https://app.tolgee.io",fetch:u(),onTranslationMissing:({key:e})=>e},E=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n};function w(e,n){const t=E(k,null==n?void 0:n.initialOptions,e);return t.apiUrl=c(t.apiUrl),(null==e?void 0:e.fetch)&&(t.fetch=u(e.fetch)),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}}function R(e,n,i,o,r,s,g,c){const l={ui:void 0},u={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},d=async({keysAndDefaults:e,target:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,fallbackNamespaces:o(n),namespace:r({key:e,ns:n})[0],translation:s({key:e,ns:n})})));null===(t=u.ui)||void 0===t||t.handleElementClick(a,n)},f=(e,n)=>{var t;return(null===(t=u.observer)||void 0===t?void 0:t.findPositions(e,n))||[]};function p(e){const n=s({key:e.key,ns:e.ns});return C.formatTranslation(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))}function m(){return{fetch:n().fetch}}function b(e){u.observer=null==e?void 0:e()}function y(){return Boolean(u.observer)}function L(e){e&&u.formatters.push(e)}function k(e){u.finalFormatter=e}function E(e){l.ui=e}function w(){return Boolean(l.ui)}function R(e){u.languageStorage=e}function D(e){u.languageDetector=e}function F(e){e&&u.backends.push(e)}function N(e){u.devBackend=e}const C=Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:k,addFormatter:L,setObserver:b,hasObserver:y,setUi:E,hasUi:w,setDevBackend:N,addBackend:F,setLanguageDetector:D,setLanguageStorage:R}))},findPositions:f,run(){var e,t;const{apiKey:a,apiUrl:i,projectId:o,observerOptions:r}=n();u.ui=null===(e=l.ui)||void 0===e?void 0:e.call(l,{apiKey:a,apiUrl:i,projectId:o,highlight:C.highlight,changeTranslation:g,findPositions:f,onPermanentChange:e=>c.onPermanentChange.emit(e)}),null===(t=u.observer)||void 0===t||t.run({mouseHighlight:!0,options:r,translate:p,onClick:d})},stop(){var e;u.ui=void 0,null===(e=u.observer)||void 0===e||e.stop()},getLanguageStorage:()=>u.languageStorage,getInitialLanguage(){const e=i();return t(a(c.onError,(e=>new h("Tolgee: Failed to load language",e)),(()=>{var e;return null===(e=u.languageStorage)||void 0===e?void 0:e.getLanguage(m())})),(n=>e&&!e.includes(n)||!n?function(){if(!u.languageDetector)return;const e=i();return a(c.onError,(e=>new v("Tolgee: Failed to detect language",e)),(()=>{var n;return null===(n=u.languageDetector)||void 0===n?void 0:n.getLanguage(Object.assign({availableLanguages:e},m()))}))}():n))},setStoredLanguage:e=>a(c.onError,(e=>new h("Tolgee: Failed to store language",e)),(()=>{var n;return null===(n=u.languageStorage)||void 0===n?void 0:n.setLanguage(e,m())})),getDevBackend:()=>u.devBackend,getBackendRecord:({language:e,namespace:n})=>{for(const t of u.backends){const a=t.getRecord(Object.assign({language:e,namespace:n},m()));if(void 0!==a)return a}},getBackendDevRecord:({language:e,namespace:t})=>{var a;const{apiKey:i,apiUrl:o,projectId:r}=n();return null===(a=u.devBackend)||void 0===a?void 0:a.getRecord(Object.assign({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:t},m()))},getLanguageDetector:()=>u.languageDetector,retranslate(){var e;null===(e=u.observer)||void 0===e||e.retranslate()},highlight:(e,n)=>{var t,a;return(null===(a=null===(t=u.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},unwrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap(e){var n;return u.observer?null===(n=u.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:()=>Boolean(C.getDevBackend()),formatTranslation(t){var a,{formatEnabled:i}=t,o=O(t,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:c,params:l,ns:d,orEmpty:f}=o,p=null!=s?s:g;let v="";null==s&&(v=n().onTranslationMissing(o));let h=null!=p?p:f?"":v;const m=e(),b=i||!(null===(a=u.observer)||void 0===a?void 0:a.outputNotFormattable),y=e=>u.observer&&!c?u.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:d}):e;h=y(h);try{if(p&&m&&b)for(const e of u.formatters)h=e.format({translation:h,language:m,params:l});u.finalFormatter&&p&&m&&b&&(h=u.finalFormatter.format({translation:h,language:m,params:l}))}catch(e){console.error(e);const t=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||j,a=n().onFormatError,i=typeof a;h="string"===i?a:"function"===i?a(t,o):j,h=y(h)}var L;return h}});return C}const D=(e,n,t)=>{let a=e;return Object.freeze({init(e){a=e},notify(){const e=n();a!==e&&t(e),a=e}})};const F=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=O(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a};function N({options:e}){const a=function(e,n){let t=!0;function a(){return t}const i=Object.freeze({onPendingLanguageChange:d(a),onLanguageChange:d(a),onLoadingChange:d(a),onFetchingChange:d(a),onInitialLoaded:d(a),onRunningChange:d(a),onCacheChange:d(a),onUpdate:f(a,e,n),onPermanentChange:d(a),onError:d(a),setEmitterActive(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.onPendingLanguageChange.listen(n);case"language":return i.onLanguageChange.listen(n);case"loading":return i.onLoadingChange.listen(n);case"fetching":return i.onFetchingChange.listen(n);case"initialLoad":return i.onInitialLoaded.listen(n);case"running":return i.onRunningChange.listen(n);case"cache":return i.onCacheChange.listen(n);case"update":return i.onUpdate.listen(n);case"permanentChange":return i.onPermanentChange.listen(n);case"error":return i.onError.listen(n)}}});return i.onInitialLoaded.listen((()=>i.onUpdate.emit())),i.onLanguageChange.listen((()=>i.onUpdate.emit())),i.onCacheChange.listen((({value:e})=>i.onUpdate.emit([e.namespace],!0))),i}(m,y),o=D(!1,(()=>v.isFetching()),a.onFetchingChange.emit),l=D(!1,(()=>A.isLoading()),a.onLoadingChange.emit),u=function(e,n,t){let a,i=w();const o=Object.freeze({init(e){i=w(e,i)},isRunning:()=>i.isRunning,setRunning(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:()=>i.isInitialLoading,setInitialLoading(e){i.isInitialLoading=e},getLanguage:()=>i.language||i.initialOptions.language,setLanguage(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:()=>i.pendingLanguage||o.getLanguage(),setPendingLanguage(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:()=>Object.assign(Object.assign({},i.initialOptions),a),addActiveNs(e){r(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs(e){r(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:()=>g([...i.initialOptions.ns||[i.initialOptions.defaultNs],...r(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()]),getFallbackLangs(e){const n=e||o.getLanguage();return n?g([n,...s(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:()=>r(i.initialOptions.fallbackNs),getDefaultNs:e=>void 0===e?i.initialOptions.defaultNs:e,getAvailableLanguages(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>b(e).language));return Array.from(new Set(e))}},withDefaultNs:e=>({namespace:void 0===e.namespace?o.getInitialOptions().defaultNs:e.namespace,language:e.language}),overrideCredentials(e){a=e?Object.assign(Object.assign({},e),{apiUrl:c(e.apiUrl)}):void 0}});return o}(a.onLanguageChange,a.onPendingLanguageChange,a.onRunningChange),p=R(u.getLanguage,u.getInitialOptions,u.getAvailableLanguages,O,C,P,k,a),v=L(a,p.getBackendRecord,p.getBackendDevRecord,u.withDefaultNs,u.isInitialLoading,o,l);let h;function m(){return u.getFallbackNs()}function y(e){return u.getDefaultNs(e)}function O(e){return[...r(y(e)),...m()]}function j(e){return[...r(null!=e?e:y()),...u.getRequiredNamespaces()]}function k(e,n,t){const a=u.withDefaultNs(e),i=v.getTranslation(a,n);return v.changeTranslation(a,n,t),{revert(){v.changeTranslation(a,n,i)}}}function E(e){u.init(e),v.addStaticData(u.getInitialOptions().staticData)}function N(e,n){const a=function(e,n){const t=u.getFallbackLangs(e),a=j(n),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,n);if(a.length)return t(A.loadRecords(a),(()=>{}))}function C({key:e,ns:n}){const t=u.getFallbackLangs(),a=O(null!=n?n:void 0);return v.getTranslationNs(a,t,e)}function P({key:e,ns:n,language:t}){const a=O(null!=n?n:void 0),i=u.getFallbackLangs(t);return v.getTranslationFallback(a,i,e)}function T(){const e=t(function(){if(u.getLanguage())return;return t(p.getInitialLanguage(),(e=>{const n=e||u.getInitialOptions().defaultLanguage;n&&u.setLanguage(n)}))}(),(()=>N()));if(n(e))return u.setInitialLoading(!0),o.notify(),l.notify(),Promise.resolve(e).then((()=>{u.setInitialLoading(!1),o.notify(),l.notify(),a.onInitialLoaded.emit()}));a.onInitialLoaded.emit()}e&&E(e),a.onUpdate.listen((()=>{u.isRunning()&&p.retranslate()}));const A=Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},a),u),p),v),{init:E,getTranslation:P,changeTranslation:k,getTranslationNs:C,getDefaultAndFallbackNs:O,findPositions:p.findPositions,async changeLanguage(e){u.getPendingLanguage()===e&&u.getLanguage()===e||(u.setPendingLanguage(e),u.isRunning()&&await N(e),e===u.getPendingLanguage()&&(u.setLanguage(e),await p.setStoredLanguage(e)))},async addActiveNs(e,n){n||u.addActiveNs(e),u.isRunning()&&await N(void 0,e)},loadRecords:e=>v.loadRecords(e,A.isDev()),loadRecord:async e=>(await A.loadRecords([e]))[0],isLoading:e=>v.isLoading(u.getLanguage(),e),isLoaded(e){const n=u.getLanguage();if(!n)return!1;const t=u.getFallbackLangs(n),a=j(e),i=[];return t.forEach((e=>{a.forEach((n=>{v.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=F(...e),t=P(n);return p.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:()=>Boolean(u.getInitialOptions().apiKey&&u.getInitialOptions().apiUrl),run:()=>(function(){if((p.getLanguageDetector()||p.getLanguageStorage())&&!u.getAvailableLanguages())throw new Error(i("availableLanguages"));if(!u.getLanguage()&&!u.getInitialOptions().defaultLanguage)throw new Error(i(["defaultLanguage","language"]))}(),u.isRunning()||(u.setRunning(!0),p.run(),h=T()),Promise.resolve(h)),stop(){u.isRunning()&&(p.stop(),u.setRunning(!1))}}));return A}const C=0,P=1,T=2;class A extends Error{constructor(e,n,t){let a;a=e===C?"Empty parameter":e===P?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function S(e){return/\s/.test(e)}const I=0,U=1,x=2,B=3,z=4,K=new Set([x,U,I]),$="'",M=new Set(["{","}",$]),V=e=>/[0-9a-zA-Z_]/.test(e);function W(e,n){const[t,a]=function(e){let n=I,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new A(n,s,e)}const c=()=>{o.push(t),t=""},l=()=>{""===a&&g(C),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case I:i===$?(t+=i,n=U):"{"===i?(c(),n=B):(t+=i,n=I);break;case U:M.has(i)?(t=t.slice(0,-1)+i,n=x):(t+=i,n=I);break;case x:i===$?n=I:(t+=i,n=x);break;case B:"}"===i?(l(),n=I):S(i)?""!==a&&(l(),n=z):(V(i)||g(P),a+=i,n=B);break;case z:"}"==i?n=I:S(i)?n=z:g(P)}return K.has(n)||g(T),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}e.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>W(e,n)}),e),e.LanguageDetectorError=v,e.LanguageStorageError=h,e.RecordFetchError=p,e.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=E(e.options,t),n),init(n){const t=function(e){const n=N({options:e});function t(e){const t=n.isRunning();t&&n.stop(),e(),n.isDev()&&n.invalidate(),t&&n.run()}n.isDev()&&n.invalidate();const a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,findPositions:n.findPositions,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a}(E(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},e.createFetchFunction=u,e.getFallback=o,e.getFallbackArray=r,e.getTranslateProps=F,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=tolgee.umd.min.js.map |
@@ -13,2 +13,3 @@ import { CacheDescriptor, NsFallback, TolgeeOptions, TFnType, NsType, KeyAndNamespacesInternal } from '../types'; | ||
getDefaultAndFallbackNs: (ns?: NsType) => string[]; | ||
findPositions: import("../types").FindPositionsInterface; | ||
changeLanguage(language: string): Promise<void>; | ||
@@ -15,0 +16,0 @@ addActiveNs(ns: NsFallback, forget?: boolean): Promise<void>; |
@@ -1,5 +0,6 @@ | ||
import { BackendDevMiddleware, TranslatePropsInternal, HighlightInterface, LanguageDetectorMiddleware, LanguageStorageMiddleware, ChangeTranslationInterface, WrapperWrapProps, Unwrapped, KeyAndNamespacesInternal, TolgeePlugin, TolgeeInstance, TolgeeOptionsInternal, BackendGetRecordInternal } from '../../types'; | ||
import { BackendDevMiddleware, TranslatePropsInternal, HighlightInterface, LanguageDetectorMiddleware, LanguageStorageMiddleware, ChangeTranslationInterface, WrapperWrapProps, Unwrapped, KeyAndNamespacesInternal, TolgeePlugin, TolgeeInstance, TolgeeOptionsInternal, FindPositionsInterface, BackendGetRecordInternal } from '../../types'; | ||
import { EventsInstance } from '../Events/Events'; | ||
export declare function Plugins(getLanguage: () => string | undefined, getInitialOptions: () => TolgeeOptionsInternal, getAvailableLanguages: () => string[] | undefined, getFallbackNamespaces: (ns: string | undefined) => string[], getTranslationNs: (props: KeyAndNamespacesInternal) => string[], getTranslation: (props: KeyAndNamespacesInternal) => string | undefined, changeTranslation: ChangeTranslationInterface, events: EventsInstance): Readonly<{ | ||
addPlugin: (tolgeeInstance: TolgeeInstance, plugin: TolgeePlugin) => void; | ||
findPositions: FindPositionsInterface; | ||
run(): void; | ||
@@ -6,0 +7,0 @@ stop(): void; |
@@ -128,2 +128,6 @@ import { TolgeeOptions, TolgeePlugin, DevCredentials, TFnType, DefaultParamType, TranslationKey } from './types'; | ||
/** | ||
* Find positions of keys in the DOM. | ||
*/ | ||
findPositions: import("./types").FindPositionsInterface; | ||
/** | ||
* @return current Tolgee options. | ||
@@ -130,0 +134,0 @@ */ |
@@ -90,3 +90,3 @@ import { ChangeTranslationInterface, TreeTranslationsData } from './cache'; | ||
keysAndDefaults: KeyAndParams[]; | ||
event: any; | ||
target: HTMLElement; | ||
}) => void; | ||
@@ -127,3 +127,3 @@ export type Highlighter = { | ||
export interface UiInterface { | ||
handleElementClick(keysAndDefaults: UiKeyOption[], event: any): Promise<void>; | ||
handleElementClick(keysAndDefaults: UiKeyOption[], target: HTMLElement): Promise<void>; | ||
} | ||
@@ -130,0 +130,0 @@ export type PluginTools = Readonly<{ |
{ | ||
"name": "@tolgee/core", | ||
"version": "5.22.1-prerelease.aa2f05c1.0", | ||
"version": "5.22.1-prerelease.b7e76156.0", | ||
"description": "Library providing ability to translate messages directly in context of developed application.", | ||
@@ -73,3 +73,3 @@ "main": "./dist/tolgee.cjs.js", | ||
"sideEffects": false, | ||
"gitHead": "49bca46df27a3851cada7bc8598c9c488862fbb6" | ||
"gitHead": "80101a03b3d109714236e051892b9e77c20d27c2" | ||
} |
@@ -210,2 +210,3 @@ import { Events } from './Events/Events'; | ||
getDefaultAndFallbackNs: getDefaultAndFallbackNs, | ||
findPositions: pluginService.findPositions, | ||
async changeLanguage(language: string) { | ||
@@ -212,0 +213,0 @@ if ( |
@@ -60,3 +60,3 @@ import { | ||
const onClick: TranslationOnClick = async ({ keysAndDefaults, event }) => { | ||
const onClick: TranslationOnClick = async ({ keysAndDefaults, target }) => { | ||
const withNs: UiKeyOption[] = keysAndDefaults.map( | ||
@@ -76,3 +76,3 @@ ({ key, ns, defaultValue }) => { | ||
); | ||
instances.ui?.handleElementClick(withNs, event); | ||
instances.ui?.handleElementClick(withNs, target); | ||
}; | ||
@@ -190,3 +190,3 @@ | ||
addPlugin, | ||
findPositions: findPositions, | ||
run() { | ||
@@ -193,0 +193,0 @@ const { apiKey, apiUrl, projectId, observerOptions } = |
@@ -175,2 +175,7 @@ import { Controller } from './Controller/Controller'; | ||
/** | ||
* Find positions of keys in the DOM. | ||
*/ | ||
findPositions: controller.findPositions, | ||
/** | ||
* @return current Tolgee options. | ||
@@ -177,0 +182,0 @@ */ |
@@ -132,3 +132,3 @@ import { ChangeTranslationInterface, TreeTranslationsData } from './cache'; | ||
keysAndDefaults: KeyAndParams[]; | ||
event: any; | ||
target: HTMLElement; | ||
}) => void; | ||
@@ -176,3 +176,6 @@ | ||
export interface UiInterface { | ||
handleElementClick(keysAndDefaults: UiKeyOption[], event: any): Promise<void>; | ||
handleElementClick( | ||
keysAndDefaults: UiKeyOption[], | ||
target: HTMLElement | ||
): Promise<void>; | ||
} | ||
@@ -179,0 +182,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 too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
995490
13525