solid-intlayer 9.5.1 → 9.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -328,4 +328,4 @@ Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https:/
328
328
 
329
329
  If you like Intlayer, give us a ⭐ on GitHub. It helps others discover the project! [See why GitHub Stars matter](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md#why-github-stars-matter-).
330
330
 
331
- [![Star History Chart](https://api.star-history.com/svg?repos=aymericzip/intlayer&type=Date)](https://api.star-history.com/#aymericzip/intlayer&Date)
331
+ [![Star History Chart](https://api.star-history.com/svg?repos=aymericzip/intlayer&type=Date)](https://star-history.com/#aymericzip/intlayer&Date)
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./exposureSink.cjs"),t=require("../../isEnabled-CuTKz0YA.js"),n=require("../client/IntlayerProvider.cjs");let r=require("solid-js");var i=()=>{if(process.env.INTLAYER_ANALYTICS_ENABLED===`false`||!t.t)return;let{locale:i}=n.useIntlayerContext(),[a,o]=(0,r.createSignal)(null),s=!1,c=!1;(0,r.onMount)(()=>{Promise.resolve().then(()=>require("../../esm-BeJJ8BHD.js")).then(({initAnalyticsClient:t,buildContentExposure:n})=>{if(s)return;let r=t();c=!0;let a=i?.();a&&r.setLocale(a),r.trackPageView({reason:`initial`}),e.setExposureSink(e=>r.trackContentExposure(n(e))),o(r)}).catch(()=>{})});let l;(0,r.createEffect)(()=>{let e=a(),t=i?.();if(!(!e||!t)){if(l===void 0){l=t;return}l!==t&&(l=t,e.setLocale(t),e.trackPageView({reason:`locale_change`}))}}),(0,r.onCleanup)(()=>{s=!0,e.setExposureSink(null),Promise.resolve().then(()=>require("../../esm-BeJJ8BHD.js")).then(({stopAnalyticsClient:e})=>{c&&e()}).catch(()=>{})})};exports.useAnalytics=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./exposureSink.cjs"),t=require("../../isEnabled-CuTKz0YA.js"),n=require("../client/IntlayerProvider.cjs");let r=require("solid-js");var i=()=>{if(process.env.INTLAYER_ANALYTICS_ENABLED===`false`||!t.t)return;let{locale:i}=n.useIntlayerContext(),[a,o]=(0,r.createSignal)(null),s=!1,c=!1;(0,r.onMount)(()=>{Promise.resolve().then(()=>require("../../esm-DXg1m_y3.js")).then(({initAnalyticsClient:t,buildContentExposure:n})=>{if(s)return;let r=t();c=!0;let a=i?.();a&&r.setLocale(a),r.trackPageView({reason:`initial`}),e.setExposureSink(e=>r.trackContentExposure(n(e))),o(r)}).catch(()=>{})});let l;(0,r.createEffect)(()=>{let e=a(),t=i?.();if(e&&t){if(l===void 0){l=t;return}l!==t&&(l=t,e.setLocale(t),e.trackPageView({reason:`locale_change`}))}}),(0,r.onCleanup)(()=>{s=!0,e.setExposureSink(null),Promise.resolve().then(()=>require("../../esm-DXg1m_y3.js")).then(({stopAnalyticsClient:e})=>{c&&e()}).catch(()=>{})})};exports.useAnalytics=i;
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../isEnabled-CuTKz0YA.js");var t=()=>t=>{process.env.INTLAYER_ANALYTICS_ENABLED===`false`||!e.t||Promise.resolve().then(()=>require("../../esm-BeJJ8BHD.js")).then(({getGlobalAnalyticsClient:e})=>{e()?.trackConversion(t)}).catch(()=>{})};exports.useConversion=t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../isEnabled-CuTKz0YA.js");var t=()=>t=>{process.env.INTLAYER_ANALYTICS_ENABLED!==`false`&&e.t&&Promise.resolve().then(()=>require("../../esm-DXg1m_y3.js")).then(({getGlobalAnalyticsClient:e})=>{e()?.trackConversion(t)}).catch(()=>{})};exports.useConversion=t;
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../isEnabled-CuTKz0YA.js");let t=require("solid-js");var n=(n,r,i)=>{let[a,o]=(0,t.createSignal)(r[0]??``),[s,c]=(0,t.createSignal)(!1),l=!1,u=!1;return(0,t.onMount)(()=>{process.env.INTLAYER_ANALYTICS_ENABLED===`false`||!e.t||Promise.resolve().then(()=>require("../../esm-BeJJ8BHD.js")).then(({initAnalyticsClient:e})=>{if(l)return;let t=e();u=!0;let a=t.getVariant(n,r,i);o(a),c(!0),t.trackContentExposure({dictionaryKey:n,keyPath:``,nodeType:`experiment`,experimentKey:n,variant:a})}).catch(()=>{})}),(0,t.onCleanup)(()=>{l=!0,Promise.resolve().then(()=>require("../../esm-BeJJ8BHD.js")).then(({stopAnalyticsClient:e})=>{u&&e()}).catch(()=>{})}),{variant:a,isAssigned:s}};exports.useExperiment=n;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../isEnabled-CuTKz0YA.js");let t=require("solid-js");var n=(n,r,i)=>{let[a,o]=(0,t.createSignal)(r[0]??``),[s,c]=(0,t.createSignal)(!1),l=!1,u=!1;return(0,t.onMount)(()=>{process.env.INTLAYER_ANALYTICS_ENABLED!==`false`&&e.t&&Promise.resolve().then(()=>require("../../esm-DXg1m_y3.js")).then(({initAnalyticsClient:e})=>{if(l)return;let t=e();u=!0;let a=t.getVariant(n,r,i);o(a),c(!0),t.trackContentExposure({dictionaryKey:n,keyPath:``,nodeType:`experiment`,experimentKey:n,variant:a})}).catch(()=>{})}),(0,t.onCleanup)(()=>{l=!0,Promise.resolve().then(()=>require("../../esm-DXg1m_y3.js")).then(({stopAnalyticsClient:e})=>{u&&e()}).catch(()=>{})}),{variant:a,isAssigned:s}};exports.useExperiment=n;
@@ -7,7 +7,7 @@ var s = () => {
7
7
  if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !t) return;
8
8
  let { locale: s } = n(), [c, l] = i(null), u = !1, d = !1;
9
9
  o(() => {
10
- import("../../esm-yuHc2Obh.mjs").then(({ initAnalyticsClient: t, buildContentExposure: n }) => {
10
+ import("../../esm-DZ1bEPA6.mjs").then(({ initAnalyticsClient: t, buildContentExposure: n }) => {
11
11
  if (u) return;
12
12
  let r = t();
13
13
  d = !0;
@@ -18,7 +18,7 @@ var s = () => {
18
18
  let f;
19
19
  r(() => {
20
20
  let e = c(), t = s?.();
21
- if (!(!e || !t)) {
21
+ if (e && t) {
22
22
  if (f === void 0) {
23
23
  f = t;
24
24
  return;
@@ -26,7 +26,7 @@ var s = () => {
26
26
  f !== t && (f = t, e.setLocale(t), e.trackPageView({ reason: "locale_change" }));
27
27
  }
28
28
  }), a(() => {
29
- u = !0, e(null), import("../../esm-yuHc2Obh.mjs").then(({ stopAnalyticsClient: e }) => {
29
+ u = !0, e(null), import("../../esm-DZ1bEPA6.mjs").then(({ stopAnalyticsClient: e }) => {
30
30
  d && e();
31
31
  }).catch(() => {});
32
32
  });
@@ -1,7 +1,7 @@
1
1
  import { t as e } from "../../isEnabled-BbWU6Ox5.mjs";
2
2
  //#region src/analytics/useConversion.ts
3
3
  var t = () => (t) => {
4
- process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !e || import("../../esm-yuHc2Obh.mjs").then(({ getGlobalAnalyticsClient: e }) => {
4
+ process.env.INTLAYER_ANALYTICS_ENABLED !== "false" && e && import("../../esm-DZ1bEPA6.mjs").then(({ getGlobalAnalyticsClient: e }) => {
5
5
  e()?.trackConversion(t);
6
6
  }).catch(() => {});
7
7
  };
@@ -4,7 +4,7 @@ import { createSignal as t, onCleanup as n, onMount as r } from "solid-js";
4
4
  var i = (i, a, o) => {
5
5
  let [s, c] = t(a[0] ?? ""), [l, u] = t(!1), d = !1, f = !1;
6
6
  return r(() => {
7
- process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !e || import("../../esm-yuHc2Obh.mjs").then(({ initAnalyticsClient: e }) => {
7
+ process.env.INTLAYER_ANALYTICS_ENABLED !== "false" && e && import("../../esm-DZ1bEPA6.mjs").then(({ initAnalyticsClient: e }) => {
8
8
  if (d) return;
9
9
  let t = e();
10
10
  f = !0;
@@ -18,7 +18,7 @@ var i = (i, a, o) => {
18
18
  });
19
19
  }).catch(() => {});
20
20
  }), n(() => {
21
- d = !0, import("../../esm-yuHc2Obh.mjs").then(({ stopAnalyticsClient: e }) => {
21
+ d = !0, import("../../esm-DZ1bEPA6.mjs").then(({ stopAnalyticsClient: e }) => {
22
22
  f && e();
23
23
  }).catch(() => {});
24
24
  }), {
@@ -0,0 +1 @@
1
+ const e=require("./isEnabled-CuTKz0YA.js");let t=require("@intlayer/config/built");var n=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0},r=(e,t,r,i)=>{if(r.length===0)throw Error(`assignVariant requires at least one variant`);if(r.length===1)return r[0];let a=n(`${e}:${t}`)/4294967296;if(!i||i.length!==r.length){let e=Math.floor(a*r.length);return r[Math.min(e,r.length-1)]}let o=i.reduce((e,t)=>e+t,0);if(o<=0)return r[Math.floor(a*r.length)];let s=0,c=a*o;for(let e=0;e<r.length;e++)if(s+=i[e],c<s)return r[e];return r[r.length-1]},i=``,a=e=>[e.url,e.dictionaryKey,e.keyPath,e.locale,e.experimentKey??``,e.variant??``].join(i),o=({max:e})=>{let t=[],n=new Map,r=()=>t.length+n.size,i=()=>{for(;r()>e&&n.size>0;){let e=n.keys().next().value;n.delete(e)}r()>e&&(t=t.slice(r()-e))};return{push:e=>{if(e.type===`content_exposure`){let t=a(e),r=n.get(t);r?(r.count=(r.count??1)+(e.count??1),r.t=e.t):n.set(t,{...e,count:e.count??1})}else t.push(e);return i(),r()},drain:()=>{let e=[...t,...n.values()];return t=[],n.clear(),e},size:r}},s=(e,t)=>t>=1?!0:t<=0?!1:n(e)/4294967295<t,c=`__intlayer_analytics_sid__`,l=()=>{let e=typeof globalThis<`u`?globalThis.crypto:void 0;return e?.randomUUID?e.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`},u=()=>{if(typeof window>`u`||!window.sessionStorage)return l();try{let e=window.sessionStorage.getItem(c);if(e)return e;let t=l();return window.sessionStorage.setItem(c,t),t}catch{return l()}},d=(e,t,{useBeacon:n=!1,token:r}={})=>{try{let i=JSON.stringify(t);return n&&typeof navigator<`u`&&typeof navigator.sendBeacon==`function`?navigator.sendBeacon(e,i):typeof fetch==`function`&&(fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`,...r?{Authorization:`Bearer ${r}`}:{}},body:i,keepalive:!0,credentials:`omit`,mode:`cors`}).catch(()=>{}),!0)}catch{return!1}},f=e=>{if(typeof window>`u`)return;let t=window.requestIdleCallback;if(typeof t==`function`){t(()=>e());return}setTimeout(e,1)},p=`__intlayer_public_token__`,m=6e4,h=()=>{try{let e=window.sessionStorage?.getItem(p);if(!e)return null;let t=JSON.parse(e);return typeof t?.token!=`string`||typeof t?.expiresAt!=`number`?null:t}catch{return null}},g=e=>{try{window.sessionStorage?.setItem(p,JSON.stringify(e))}catch{}},_=({backendURL:e,clientId:t})=>{let n=`${e.replace(/\/$/,``)}/api/public/token`,r=null,i=null,a=e=>e!==null&&e.expiresAt-m>Date.now(),o=()=>{if(a(r))return r.token;if(typeof window<`u`){let e=h();if(a(e))return r=e,e.token}},s=async()=>{try{let e=await fetch(n,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clientId:t}),credentials:`omit`,mode:`cors`});if(!e.ok)return;let i=await e.json(),a=i?.data?.token,o=i?.data?.expiresIn??0;if(!a||o<=0)return;r={token:a,expiresAt:Date.now()+o*1e3},typeof window<`u`&&g(r)}catch{}finally{i=null}};return{getToken:o,prime:()=>{t&&typeof fetch==`function`&&(o()||(i||=s()))}}},v=`intlayer-analytics/1`,y=()=>typeof window>`u`||!window.location?``:window.location.pathname,b=()=>{if(!(typeof document>`u`||!document.referrer))try{return new URL(document.referrer).host}catch{return}},x=t=>{let n=u(),i=e.r(),a=!i&&s(n,t.sampleRate),c=o({max:t.maxBufferSize}),l=`${t.backendURL.replace(/\/$/,``)}/api/analytics/events`,p=_({backendURL:t.backendURL,clientId:t.clientId}),m=``,h=null,g=!1,x=null,S=null,C=new Set,w=(e=!1)=>{let r=c.drain(),i=p.getToken();for(let a=0;a<r.length;a+=200)d(l,{token:i,clientId:i?void 0:t.clientId,sessionId:n,sdkVersion:v,events:r.slice(a,a+200)},{useBeacon:e,token:i})},T=e=>{c.push(e)>=t.maxBufferSize&&w()},E=e=>{m=e},D=(e={})=>{if(!a)return;let t=e.url??y(),n=e.reason??`initial`;(n!==`route_change`||t!==S)&&(S=t,C=new Set,T({type:`page_view`,t:Date.now(),url:t,locale:e.locale??m,ref:e.ref??b(),vw:e.vw??(typeof window<`u`?window.innerWidth:void 0),vh:e.vh??(typeof window<`u`?window.innerHeight:void 0),reason:n}))},O=e=>{if(!a)return;let t=e.locale??m,n=[e.dictionaryKey,e.keyPath,t,e.experimentKey??``,e.variant??``].join(``);C.has(n)||(C.add(n),T({...e,type:`content_exposure`,t:Date.now(),url:y(),locale:t}))},k=e=>{i||(T({...e,type:`conversion`,t:Date.now(),url:y(),locale:e.locale??m}),w())},A=(e,t,i)=>r(n,e,t,i),j=()=>{if(typeof window>`u`)return;let e=()=>{document.visibilityState===`hidden`&&w(!0)},t=()=>w(!0),n=()=>D({reason:`route_change`});document.addEventListener(`visibilitychange`,e),window.addEventListener(`pagehide`,t,{capture:!0}),window.addEventListener(`popstate`,n);let r=window.history,i=r.pushState,a=function(...e){let t=i.apply(this,e);return D({reason:`route_change`}),t};r.pushState=a,x=()=>{document.removeEventListener(`visibilitychange`,e),window.removeEventListener(`pagehide`,t,{capture:!0}),window.removeEventListener(`popstate`,n),r.pushState===a&&(r.pushState=i)}};return{setLocale:E,trackPageView:D,trackContentExposure:O,trackConversion:k,getVariant:A,flush:w,start:()=>{g||i||(g=!0,p.prime(),h=setInterval(w,t.flushInterval),h?.unref?.(),f(j))},stop:()=>{g&&(g=!1,h&&=(clearInterval(h),null),x?.(),x=null,w(!0))}}},S=`__intlayer_analytics_client__`,C=`__intlayer_analytics_ref_count__`,w=()=>typeof window>`u`?null:window[S]??null,T=e=>{typeof window>`u`||(window[S]=e)},E=()=>{if(typeof window>`u`)return 0;let e=window;return e[C]=(e[C]??0)+1,e[C]},D=()=>{if(typeof window>`u`)return 0;let e=window;return e[C]=Math.max(0,(e[C]??0)-1),e[C]},O=()=>{E();let e=w();if(e)return e;let n=x({backendURL:t.editor?.backendURL??``,clientId:t.editor?.clientId,flushInterval:t.analytics?.flushInterval??2e4,maxBufferSize:500,sampleRate:t.analytics?.sampleRate??1});return T(n),n.start(),n},k=()=>{D()>0||(w()?.stop(),T(null))},A=e=>e.map(e=>e.key===void 0?`*`:String(e.key)).join(`.`),j=e=>({dictionaryKey:e.dictionaryKey,keyPath:A(e.keyPath),locale:e.locale,nodeType:e.nodeType,experimentKey:e.experimentKey,variant:e.variant});exports.buildContentExposure=j,exports.getGlobalAnalyticsClient=w,exports.initAnalyticsClient=O,exports.stopAnalyticsClient=k;
@@ -131,7 +131,7 @@ var r = (e) => {
131
131
  return {
132
132
  getToken: o,
133
133
  prime: () => {
134
- !t || typeof fetch != "function" || o() || (i ||= s());
134
+ t && typeof fetch == "function" && (o() || (i ||= s()));
135
135
  }
136
136
  };
137
137
  }, y = "intlayer-analytics/1", b = () => typeof window > "u" || !window.location ? "" : window.location.pathname, x = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-intlayer",
3
- "version": "9.5.1",
3
+ "version": "9.5.3",
4
4
  "private": false,
5
5
  "description": "Easily internationalize i18n your Solid applications with type-safe multilingual content management.",
6
6
  "keywords": [
@@ -113,17 +113,17 @@
113
113
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
114
114
  },
115
115
  "dependencies": {
116
- "@intlayer/api": "9.5.1",
117
- "@intlayer/config": "9.5.1",
118
- "@intlayer/core": "9.5.1",
119
- "@intlayer/editor": "9.5.1",
120
- "@intlayer/types": "9.5.1"
116
+ "@intlayer/api": "9.5.3",
117
+ "@intlayer/config": "9.5.3",
118
+ "@intlayer/core": "9.5.3",
119
+ "@intlayer/editor": "9.5.3",
120
+ "@intlayer/types": "9.5.3"
121
121
  },
122
122
  "devDependencies": {
123
123
  "@solidjs/testing-library": "0.8.10",
124
124
  "@testing-library/jest-dom": "7.0.1",
125
125
  "@testing-library/user-event": "14.6.7",
126
- "@types/node": "26.5.0",
126
+ "@types/node": "^22",
127
127
  "@typescript/typescript6": "^6.0.2",
128
128
  "@utils/ts-config": "1.0.4",
129
129
  "@utils/ts-config-types": "1.0.4",
@@ -132,7 +132,7 @@
132
132
  "rimraf": "6.1.3",
133
133
  "tsdown": "0.23.0",
134
134
  "typescript": "7.0.2",
135
- "vite": "8.2.2",
135
+ "vite": "8.3.0",
136
136
  "vite-plugin-dts": "5.1.0",
137
137
  "vite-plugin-solid": "2.11.14",
138
138
  "vitest": "5.0.0"
@@ -141,7 +141,7 @@
141
141
  "solid-js": ">=1.0.0"
142
142
  },
143
143
  "optionalDependencies": {
144
- "@intlayer/analytics": "9.5.1"
144
+ "@intlayer/analytics": "9.5.3"
145
145
  },
146
146
  "engines": {
147
147
  "node": ">=14.18"
@@ -1 +0,0 @@
1
- const e=require("./isEnabled-CuTKz0YA.js");let t=require("@intlayer/config/built");var n=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0},r=(e,t,r,i)=>{if(r.length===0)throw Error(`assignVariant requires at least one variant`);if(r.length===1)return r[0];let a=n(`${e}:${t}`)/4294967296;if(!i||i.length!==r.length){let e=Math.floor(a*r.length);return r[Math.min(e,r.length-1)]}let o=i.reduce((e,t)=>e+t,0);if(o<=0)return r[Math.floor(a*r.length)];let s=0,c=a*o;for(let e=0;e<r.length;e++)if(s+=i[e],c<s)return r[e];return r[r.length-1]},i=``,a=e=>[e.url,e.dictionaryKey,e.keyPath,e.locale,e.experimentKey??``,e.variant??``].join(i),o=({max:e})=>{let t=[],n=new Map,r=()=>t.length+n.size,i=()=>{for(;r()>e&&n.size>0;){let e=n.keys().next().value;n.delete(e)}r()>e&&(t=t.slice(r()-e))};return{push:e=>{if(e.type===`content_exposure`){let t=a(e),r=n.get(t);r?(r.count=(r.count??1)+(e.count??1),r.t=e.t):n.set(t,{...e,count:e.count??1})}else t.push(e);return i(),r()},drain:()=>{let e=[...t,...n.values()];return t=[],n.clear(),e},size:r}},s=(e,t)=>t>=1?!0:t<=0?!1:n(e)/4294967295<t,c=`__intlayer_analytics_sid__`,l=()=>{let e=typeof globalThis<`u`?globalThis.crypto:void 0;return e?.randomUUID?e.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`},u=()=>{if(typeof window>`u`||!window.sessionStorage)return l();try{let e=window.sessionStorage.getItem(c);if(e)return e;let t=l();return window.sessionStorage.setItem(c,t),t}catch{return l()}},d=(e,t,{useBeacon:n=!1,token:r}={})=>{try{let i=JSON.stringify(t);return n&&typeof navigator<`u`&&typeof navigator.sendBeacon==`function`?navigator.sendBeacon(e,i):typeof fetch==`function`&&(fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`,...r?{Authorization:`Bearer ${r}`}:{}},body:i,keepalive:!0,credentials:`omit`,mode:`cors`}).catch(()=>{}),!0)}catch{return!1}},f=e=>{if(typeof window>`u`)return;let t=window.requestIdleCallback;if(typeof t==`function`){t(()=>e());return}setTimeout(e,1)},p=`__intlayer_public_token__`,m=6e4,h=()=>{try{let e=window.sessionStorage?.getItem(p);if(!e)return null;let t=JSON.parse(e);return typeof t?.token!=`string`||typeof t?.expiresAt!=`number`?null:t}catch{return null}},g=e=>{try{window.sessionStorage?.setItem(p,JSON.stringify(e))}catch{}},_=({backendURL:e,clientId:t})=>{let n=`${e.replace(/\/$/,``)}/api/public/token`,r=null,i=null,a=e=>e!==null&&e.expiresAt-m>Date.now(),o=()=>{if(a(r))return r.token;if(typeof window<`u`){let e=h();if(a(e))return r=e,e.token}},s=async()=>{try{let e=await fetch(n,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clientId:t}),credentials:`omit`,mode:`cors`});if(!e.ok)return;let i=await e.json(),a=i?.data?.token,o=i?.data?.expiresIn??0;if(!a||o<=0)return;r={token:a,expiresAt:Date.now()+o*1e3},typeof window<`u`&&g(r)}catch{}finally{i=null}};return{getToken:o,prime:()=>{!t||typeof fetch!=`function`||o()||(i||=s())}}},v=`intlayer-analytics/1`,y=()=>typeof window>`u`||!window.location?``:window.location.pathname,b=()=>{if(!(typeof document>`u`||!document.referrer))try{return new URL(document.referrer).host}catch{return}},x=t=>{let n=u(),i=e.r(),a=!i&&s(n,t.sampleRate),c=o({max:t.maxBufferSize}),l=`${t.backendURL.replace(/\/$/,``)}/api/analytics/events`,p=_({backendURL:t.backendURL,clientId:t.clientId}),m=``,h=null,g=!1,x=null,S=null,C=new Set,w=(e=!1)=>{let r=c.drain(),i=p.getToken();for(let a=0;a<r.length;a+=200)d(l,{token:i,clientId:i?void 0:t.clientId,sessionId:n,sdkVersion:v,events:r.slice(a,a+200)},{useBeacon:e,token:i})},T=e=>{c.push(e)>=t.maxBufferSize&&w()},E=e=>{m=e},D=(e={})=>{if(!a)return;let t=e.url??y(),n=e.reason??`initial`;(n!==`route_change`||t!==S)&&(S=t,C=new Set,T({type:`page_view`,t:Date.now(),url:t,locale:e.locale??m,ref:e.ref??b(),vw:e.vw??(typeof window<`u`?window.innerWidth:void 0),vh:e.vh??(typeof window<`u`?window.innerHeight:void 0),reason:n}))},O=e=>{if(!a)return;let t=e.locale??m,n=[e.dictionaryKey,e.keyPath,t,e.experimentKey??``,e.variant??``].join(``);C.has(n)||(C.add(n),T({...e,type:`content_exposure`,t:Date.now(),url:y(),locale:t}))},k=e=>{i||(T({...e,type:`conversion`,t:Date.now(),url:y(),locale:e.locale??m}),w())},A=(e,t,i)=>r(n,e,t,i),j=()=>{if(typeof window>`u`)return;let e=()=>{document.visibilityState===`hidden`&&w(!0)},t=()=>w(!0),n=()=>D({reason:`route_change`});document.addEventListener(`visibilitychange`,e),window.addEventListener(`pagehide`,t,{capture:!0}),window.addEventListener(`popstate`,n);let r=window.history,i=r.pushState,a=function(...e){let t=i.apply(this,e);return D({reason:`route_change`}),t};r.pushState=a,x=()=>{document.removeEventListener(`visibilitychange`,e),window.removeEventListener(`pagehide`,t,{capture:!0}),window.removeEventListener(`popstate`,n),r.pushState===a&&(r.pushState=i)}};return{setLocale:E,trackPageView:D,trackContentExposure:O,trackConversion:k,getVariant:A,flush:w,start:()=>{g||i||(g=!0,p.prime(),h=setInterval(w,t.flushInterval),h?.unref?.(),f(j))},stop:()=>{g&&(g=!1,h&&=(clearInterval(h),null),x?.(),x=null,w(!0))}}},S=`__intlayer_analytics_client__`,C=`__intlayer_analytics_ref_count__`,w=()=>typeof window>`u`?null:window[S]??null,T=e=>{typeof window>`u`||(window[S]=e)},E=()=>{if(typeof window>`u`)return 0;let e=window;return e[C]=(e[C]??0)+1,e[C]},D=()=>{if(typeof window>`u`)return 0;let e=window;return e[C]=Math.max(0,(e[C]??0)-1),e[C]},O=()=>{E();let e=w();if(e)return e;let n=x({backendURL:t.editor?.backendURL??``,clientId:t.editor?.clientId,flushInterval:t.analytics?.flushInterval??2e4,maxBufferSize:500,sampleRate:t.analytics?.sampleRate??1});return T(n),n.start(),n},k=()=>{D()>0||(w()?.stop(),T(null))},A=e=>e.map(e=>e.key===void 0?`*`:String(e.key)).join(`.`),j=e=>({dictionaryKey:e.dictionaryKey,keyPath:A(e.keyPath),locale:e.locale,nodeType:e.nodeType,experimentKey:e.experimentKey,variant:e.variant});exports.buildContentExposure=j,exports.getGlobalAnalyticsClient=w,exports.initAnalyticsClient=O,exports.stopAnalyticsClient=k;