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