vue-intlayer 9.5.2 → 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`});let e=require("vue"),t=require("@intlayer/config/built"),n=require("@intlayer/config/client");var r=Symbol(`intlayer`),i=null,a=(r,a=!0,o)=>{if(i)return i;(0,n.setIntlayerIdentifier)();let{defaultLocale:s}=t.internationalization??{},c=(0,e.ref)(r??s),l=e=>{c.value=e},u=(0,e.ref)(o);return i={locale:(0,e.readonly)(c),setLocale:l,variant:(0,e.readonly)(u),setVariant:e=>{u.value=e},isCookieEnabled:a},i},o=(e,t)=>{let{locale:n,isCookieEnabled:i,variant:o}=t??{},s=a(n,i,o);return e.provide(r,s),process.env.INTLAYER_EDITOR_ENABLED!==`false`&&Promise.resolve().then(()=>require("../editor/useEditor.cjs")).then(({useEditor:t})=>{t(e)}).catch(()=>{}),process.env.INTLAYER_ANALYTICS_ENABLED!==`false`&&Promise.resolve().then(()=>require("../analytics/useAnalytics.cjs")).then(({useAnalytics:t})=>{t(e)}).catch(()=>{}),e},s={install:o};exports.INTLAYER_SYMBOL=r,exports.createIntlayerClient=a,exports.installIntlayer=o,exports.intlayer=s;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue"),t=require("@intlayer/config/built"),n=require("@intlayer/config/client");var r=Symbol(`intlayer`),i=null,a=(r,a=!0,o)=>{if(i)return i;(0,n.setIntlayerIdentifier)();let{defaultLocale:s}=t.internationalization??{},c=(0,e.ref)(r??s),l=e=>{c.value=e},u=(0,e.ref)(o);return i={locale:(0,e.readonly)(c),setLocale:l,variant:(0,e.readonly)(u),setVariant:e=>{u.value=e},isCookieEnabled:a},i},o=(e,t)=>{let{locale:n,isCookieEnabled:i,variant:o}=t??{},s=a(n,i,o);return e.provide(r,s),process.env.INTLAYER_EDITOR_ENABLED!==`false`&&Promise.resolve().then(()=>require("../editor/useEditor.cjs")).then(({useEditor:t})=>{t(e)}).catch(()=>{}),process.env.INTLAYER_ANALYTICS_ENABLED!==`false`&&Promise.resolve().then(()=>require("../analytics/useAnalytics.cjs")).then(({useAnalytics:t})=>{t(e)}).catch(()=>{}),process.env.INTLAYER_DEVTOOLS_ENABLED!==`false`&&Promise.resolve().then(()=>require("../devtools/index.cjs")).then(({enableIntlayerDevtools:t})=>{t(e)}).catch(()=>{}),e},s={install:o};exports.INTLAYER_SYMBOL=r,exports.createIntlayerClient=a,exports.installIntlayer=o,exports.intlayer=s;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=e=>typeof e==`object`&&!!e&&!Array.isArray(e),t=t=>e(t)&&t.nodeType===`translation`&&e(t.translation),n=e=>{if(typeof e==`string`)return e;try{return JSON.stringify(e)??String(e)}catch{return String(e)}},r=(i,a,o)=>{let s=a.length===0?`(root)`:a.join(`.`);if(t(i)){o[s]=i.translation;return}if(e(i)&&typeof i.nodeType==`string`){o[s]=n(i[i.nodeType]);return}if(Array.isArray(i)){i.forEach((e,t)=>{r(e,[...a,String(t)],o)});return}if(e(i)){for(let[e,t]of Object.entries(i))r(t,[...a,e],o);return}a.length>0&&(o[a.join(`.`)]=n(i))},i=e=>{let t={};return r(e.content,[],t),t};exports.formatDictionaryForInspector=i;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./formatDictionaryForInspector.cjs");let t=require("@intlayer/dictionaries-entry"),n=require("@vue/devtools-api");var r=`intlayer`,i=`intlayer-dictionaries-inspector`,a=a=>{(0,n.setupDevtoolsPlugin)({id:r,label:`Intlayer`,packageName:`vue-intlayer`,homepage:`https://intlayer.org`,componentStateTypes:[r],app:a},n=>{n.addInspector({id:i,label:`Intlayer`,icon:`language`,treeFilterPlaceholder:`Search dictionaries`}),n.on.getInspectorTree(e=>{if(e.inspectorId!==`intlayer-dictionaries-inspector`)return;let n=(0,t.getDictionaries)(),r=Object.keys(n);e.rootNodes=r.length===0?[{id:`intlayer-no-dictionaries`,label:`No dictionaries loaded. Add an Intlayer build plugin (e.g. vite-intlayer) to generate them.`}]:r.map(e=>({id:e,label:e}))}),n.on.getInspectorState(n=>{if(n.inspectorId!==`intlayer-dictionaries-inspector`)return;let r=(0,t.getDictionaries)()[n.nodeId];if(!r){n.state={};return}let i=e.formatDictionaryForInspector(r);n.state={Translations:Object.entries(i).map(([e,t])=>({key:e,value:t,editable:!1})),Metadata:[{key:`key`,value:r.key,editable:!1},{key:`title`,value:r.title??``,editable:!1},{key:`description`,value:r.description??``,editable:!1}]}})})};exports.INTLAYER_DEVTOOLS_PLUGIN_ID=r,exports.INTLAYER_DICTIONARIES_INSPECTOR_ID=i,exports.enableIntlayerDevtools=a;
@@ -23,6 +23,8 @@ var i = Symbol("intlayer"), a = null, o = (i, o = !0, s) => {
23
23
  t(e);
24
24
  }).catch(() => {}), process.env.INTLAYER_ANALYTICS_ENABLED !== "false" && import("../analytics/useAnalytics.mjs").then(({ useAnalytics: t }) => {
25
25
  t(e);
26
+ }).catch(() => {}), process.env.INTLAYER_DEVTOOLS_ENABLED !== "false" && import("../devtools/index.mjs").then(({ enableIntlayerDevtools: t }) => {
27
+ t(e);
26
28
  }).catch(() => {}), e;
27
29
  }, c = { install: s };
28
30
  //#endregion
@@ -0,0 +1,35 @@
1
+ //#region src/devtools/formatDictionaryForInspector.ts
2
+ var e = (e) => typeof e == "object" && !!e && !Array.isArray(e), t = (t) => e(t) && t.nodeType === "translation" && e(t.translation), n = (e) => {
3
+ if (typeof e == "string") return e;
4
+ try {
5
+ return JSON.stringify(e) ?? String(e);
6
+ } catch {
7
+ return String(e);
8
+ }
9
+ }, r = (i, a, o) => {
10
+ let s = a.length === 0 ? "(root)" : a.join(".");
11
+ if (t(i)) {
12
+ o[s] = i.translation;
13
+ return;
14
+ }
15
+ if (e(i) && typeof i.nodeType == "string") {
16
+ o[s] = n(i[i.nodeType]);
17
+ return;
18
+ }
19
+ if (Array.isArray(i)) {
20
+ i.forEach((e, t) => {
21
+ r(e, [...a, String(t)], o);
22
+ });
23
+ return;
24
+ }
25
+ if (e(i)) {
26
+ for (let [e, t] of Object.entries(i)) r(t, [...a, e], o);
27
+ return;
28
+ }
29
+ a.length > 0 && (o[a.join(".")] = n(i));
30
+ }, i = (e) => {
31
+ let t = {};
32
+ return r(e.content, [], t), t;
33
+ };
34
+ //#endregion
35
+ export { i as formatDictionaryForInspector };
@@ -0,0 +1,65 @@
1
+ import { formatDictionaryForInspector as e } from "./formatDictionaryForInspector.mjs";
2
+ import { getDictionaries as t } from "@intlayer/dictionaries-entry";
3
+ import { setupDevtoolsPlugin as n } from "@vue/devtools-api";
4
+ //#region src/devtools/index.ts
5
+ var r = "intlayer", i = "intlayer-dictionaries-inspector", a = (a) => {
6
+ n({
7
+ id: r,
8
+ label: "Intlayer",
9
+ packageName: "vue-intlayer",
10
+ homepage: "https://intlayer.org",
11
+ componentStateTypes: [r],
12
+ app: a
13
+ }, (n) => {
14
+ n.addInspector({
15
+ id: i,
16
+ label: "Intlayer",
17
+ icon: "language",
18
+ treeFilterPlaceholder: "Search dictionaries"
19
+ }), n.on.getInspectorTree((e) => {
20
+ if (e.inspectorId !== "intlayer-dictionaries-inspector") return;
21
+ let n = t(), r = Object.keys(n);
22
+ e.rootNodes = r.length === 0 ? [{
23
+ id: "intlayer-no-dictionaries",
24
+ label: "No dictionaries loaded. Add an Intlayer build plugin (e.g. vite-intlayer) to generate them."
25
+ }] : r.map((e) => ({
26
+ id: e,
27
+ label: e
28
+ }));
29
+ }), n.on.getInspectorState((n) => {
30
+ if (n.inspectorId !== "intlayer-dictionaries-inspector") return;
31
+ let r = t()[n.nodeId];
32
+ if (!r) {
33
+ n.state = {};
34
+ return;
35
+ }
36
+ let i = e(r);
37
+ n.state = {
38
+ Translations: Object.entries(i).map(([e, t]) => ({
39
+ key: e,
40
+ value: t,
41
+ editable: !1
42
+ })),
43
+ Metadata: [
44
+ {
45
+ key: "key",
46
+ value: r.key,
47
+ editable: !1
48
+ },
49
+ {
50
+ key: "title",
51
+ value: r.title ?? "",
52
+ editable: !1
53
+ },
54
+ {
55
+ key: "description",
56
+ value: r.description ?? "",
57
+ editable: !1
58
+ }
59
+ ]
60
+ };
61
+ });
62
+ });
63
+ };
64
+ //#endregion
65
+ export { r as INTLAYER_DEVTOOLS_PLUGIN_ID, i as INTLAYER_DICTIONARIES_INSPECTOR_ID, a as enableIntlayerDevtools };
@@ -2,13 +2,13 @@ import { LocalesValues } from '@intlayer/types/module_augmentation';
2
2
  /**
3
3
  * Get the locale cookie
4
4
  */
5
- export declare const localeInStorage: import('intlayer').Locale | undefined;
5
+ export declare const localeInStorage: import('@intlayer/types').Locale | undefined;
6
6
  /**
7
7
  * @deprecated Use localeInStorage instead
8
8
  *
9
9
  * Get the locale cookie
10
10
  */
11
- export declare const localeCookie: import('intlayer').Locale | undefined;
11
+ export declare const localeCookie: import('@intlayer/types').Locale | undefined;
12
12
  /**
13
13
  * Set the locale cookie
14
14
  */
@@ -23,7 +23,7 @@ export declare const setLocaleCookie: (locale: LocalesValues, isCookieEnabled: b
23
23
  * Composable that provides the locale storage and a function to set it
24
24
  */
25
25
  export declare const useLocaleStorage: (isCookieEnabled?: boolean) => {
26
- localeStorage: import('vue').ComputedRef<import('intlayer').Locale>;
26
+ localeStorage: import('vue').ComputedRef<import('@intlayer/types').Locale>;
27
27
  setLocaleStorage: (locale: LocalesValues) => void;
28
28
  };
29
29
  /**
@@ -34,6 +34,6 @@ export declare const useLocaleStorage: (isCookieEnabled?: boolean) => {
34
34
  * Composable that provides the locale cookie and a function to set it
35
35
  */
36
36
  export declare const useLocaleCookie: (isCookieEnabled?: boolean) => {
37
- localeStorage: import('vue').ComputedRef<import('intlayer').Locale>;
37
+ localeStorage: import('vue').ComputedRef<import('@intlayer/types').Locale>;
38
38
  setLocaleStorage: (locale: LocalesValues) => void;
39
39
  };
@@ -0,0 +1,13 @@
1
+ import { Dictionary } from '@intlayer/types/dictionary';
2
+ /**
3
+ * Flattened representation of a dictionary content for the devtools
4
+ * inspector: each leaf path maps to its per-locale translations, or to a
5
+ * stringified fallback for non-translation content.
6
+ */
7
+ export type FlattenedDictionary = Record<string, Record<string, string> | string>;
8
+ /**
9
+ * Recursively flatten a dictionary content into leaf-path entries.
10
+ * Translation nodes are exposed as their locale-to-string map; any other
11
+ * node type falls back to a string rendering.
12
+ */
13
+ export declare const formatDictionaryForInspector: (dictionary: Dictionary) => FlattenedDictionary;
@@ -0,0 +1,12 @@
1
+ import { App } from 'vue';
2
+ export declare const INTLAYER_DEVTOOLS_PLUGIN_ID = "intlayer";
3
+ export declare const INTLAYER_DICTIONARIES_INSPECTOR_ID = "intlayer-dictionaries-inspector";
4
+ /**
5
+ * Register the Intlayer plugin in Vue Devtools with a read-only inspector
6
+ * listing the loaded dictionaries and their translations.
7
+ *
8
+ * Lazy-loaded by `installIntlayer`; safe to call only in a browser
9
+ * environment where the devtools hook may exist — `setupDevtoolsPlugin`
10
+ * no-ops when Vue Devtools is not installed.
11
+ */
12
+ export declare const enableIntlayerDevtools: (app: App) => void;
@@ -9,5 +9,5 @@
9
9
  * ```
10
10
  */
11
11
  export declare const useCompact: () => import('vue').ComputedRef<(value: string | number, options?: (Intl.NumberFormatOptions & {
12
- locale?: import('intlayer').LocalesValues;
12
+ locale?: import('@intlayer/types').LocalesValues;
13
13
  }) | undefined) => string>;
@@ -20,5 +20,5 @@
20
20
  * ```
21
21
  */
22
22
  export declare const useCurrency: () => import('vue').ComputedRef<(value: string | number, options?: (Intl.NumberFormatOptions & {
23
- locale?: import('intlayer').LocalesValues;
23
+ locale?: import('@intlayer/types').LocalesValues;
24
24
  }) | undefined) => string>;
@@ -18,5 +18,5 @@
18
18
  * ```
19
19
  */
20
20
  export declare const useDate: () => import('vue').ComputedRef<(date: string | number | Date, options?: (Intl.DateTimeFormatOptions & {
21
- locale?: import('intlayer').LocalesValues;
21
+ locale?: import('@intlayer/types').LocalesValues;
22
22
  }) | import('@intlayer/core/formatters').DateTimePreset | undefined) => string>;
@@ -17,5 +17,5 @@
17
17
  * ```
18
18
  */
19
19
  export declare const useList: () => import('vue').ComputedRef<(values: (string | number)[], options?: (import('@intlayer/core/formatters').ListFormatOptions & {
20
- locale?: import('intlayer').LocalesValues;
20
+ locale?: import('@intlayer/types').LocalesValues;
21
21
  }) | undefined) => string>;
@@ -18,5 +18,5 @@
18
18
  * ```
19
19
  */
20
20
  export declare const useNumber: () => import('vue').ComputedRef<(value: string | number, args_1?: (Intl.NumberFormatOptions & {
21
- locale?: import('intlayer').LocalesValues;
21
+ locale?: import('@intlayer/types').LocalesValues;
22
22
  }) | undefined) => string>;
@@ -12,5 +12,5 @@
12
12
  * ```
13
13
  */
14
14
  export declare const usePercentage: () => import('vue').ComputedRef<(value: string | number, args_1?: (Intl.NumberFormatOptions & {
15
- locale?: import('intlayer').LocalesValues;
15
+ locale?: import('@intlayer/types').LocalesValues;
16
16
  }) | undefined) => string>;
@@ -15,6 +15,6 @@
15
15
  * ```
16
16
  */
17
17
  export declare const useRelativeTime: () => import('vue').ComputedRef<(from: string | number | Date, to?: string | number | Date | undefined, options?: (Intl.RelativeTimeFormatOptions & {
18
- locale?: import('intlayer').LocalesValues;
18
+ locale?: import('@intlayer/types').LocalesValues;
19
19
  unit?: Intl.RelativeTimeFormatUnit;
20
20
  }) | undefined) => string>;
@@ -14,5 +14,5 @@
14
14
  * ```
15
15
  */
16
16
  export declare const useUnit: () => import('vue').ComputedRef<(value: string | number, options?: (Intl.NumberFormatOptions & {
17
- locale?: import('intlayer').LocalesValues;
17
+ locale?: import('@intlayer/types').LocalesValues;
18
18
  }) | undefined) => string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-intlayer",
3
- "version": "9.5.2",
3
+ "version": "9.5.3",
4
4
  "private": false,
5
5
  "description": "Easily internationalize i18n your Vue applications with type-safe multilingual content management.",
6
6
  "keywords": [
@@ -102,11 +102,13 @@
102
102
  "typecheck": "vue-tsc --noEmit --project tsconfig.types.json"
103
103
  },
104
104
  "dependencies": {
105
- "@intlayer/api": "9.5.2",
106
- "@intlayer/config": "9.5.2",
107
- "@intlayer/core": "9.5.2",
108
- "@intlayer/editor": "9.5.2",
109
- "@intlayer/types": "9.5.2"
105
+ "@intlayer/api": "9.5.3",
106
+ "@intlayer/config": "9.5.3",
107
+ "@intlayer/core": "9.5.3",
108
+ "@intlayer/dictionaries-entry": "9.5.3",
109
+ "@intlayer/editor": "9.5.3",
110
+ "@intlayer/types": "9.5.3",
111
+ "@vue/devtools-api": "^6.6.4"
110
112
  },
111
113
  "devDependencies": {
112
114
  "@types/node": "^22",
@@ -125,7 +127,7 @@
125
127
  "vue-tsc": "3.3.9"
126
128
  },
127
129
  "peerDependencies": {
128
- "intlayer": "9.5.2",
130
+ "intlayer": "9.5.3",
129
131
  "vue": ">=3.0.0"
130
132
  },
131
133
  "peerDependenciesMeta": {
@@ -134,7 +136,7 @@
134
136
  }
135
137
  },
136
138
  "optionalDependencies": {
137
- "@intlayer/analytics": "9.5.2"
139
+ "@intlayer/analytics": "9.5.3"
138
140
  },
139
141
  "engines": {
140
142
  "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;
@@ -1,261 +0,0 @@
1
- import { r as e } from "./isEnabled-BbWU6Ox5.mjs";
2
- import { analytics as t, editor as n } from "@intlayer/config/built";
3
- //#region ../@intlayer/analytics/dist/esm/utils/hash.mjs
4
- var r = (e) => {
5
- let t = 2166136261;
6
- for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
7
- return t >>> 0;
8
- }, i = (e, t, n, i) => {
9
- if (n.length === 0) throw Error("assignVariant requires at least one variant");
10
- if (n.length === 1) return n[0];
11
- let a = r(`${e}:${t}`) / 4294967296;
12
- if (!i || i.length !== n.length) {
13
- let e = Math.floor(a * n.length);
14
- return n[Math.min(e, n.length - 1)];
15
- }
16
- let o = i.reduce((e, t) => e + t, 0);
17
- if (o <= 0) return n[Math.floor(a * n.length)];
18
- let s = 0, c = a * o;
19
- for (let e = 0; e < n.length; e++) if (s += i[e], c < s) return n[e];
20
- return n[n.length - 1];
21
- }, a = "", o = (e) => [
22
- e.url,
23
- e.dictionaryKey,
24
- e.keyPath,
25
- e.locale,
26
- e.experimentKey ?? "",
27
- e.variant ?? ""
28
- ].join(a), s = ({ max: e }) => {
29
- let t = [], n = /* @__PURE__ */ new Map(), r = () => t.length + n.size, i = () => {
30
- for (; r() > e && n.size > 0;) {
31
- let e = n.keys().next().value;
32
- n.delete(e);
33
- }
34
- r() > e && (t = t.slice(r() - e));
35
- };
36
- return {
37
- push: (e) => {
38
- if (e.type === "content_exposure") {
39
- let t = o(e), r = n.get(t);
40
- r ? (r.count = (r.count ?? 1) + (e.count ?? 1), r.t = e.t) : n.set(t, {
41
- ...e,
42
- count: e.count ?? 1
43
- });
44
- } else t.push(e);
45
- return i(), r();
46
- },
47
- drain: () => {
48
- let e = [...t, ...n.values()];
49
- return t = [], n.clear(), e;
50
- },
51
- size: r
52
- };
53
- }, c = (e, t) => t >= 1 ? !0 : t <= 0 ? !1 : r(e) / 4294967295 < t, l = "__intlayer_analytics_sid__", u = () => {
54
- let e = typeof globalThis < "u" ? globalThis.crypto : void 0;
55
- return e?.randomUUID ? e.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
56
- }, d = () => {
57
- if (typeof window > "u" || !window.sessionStorage) return u();
58
- try {
59
- let e = window.sessionStorage.getItem(l);
60
- if (e) return e;
61
- let t = u();
62
- return window.sessionStorage.setItem(l, t), t;
63
- } catch {
64
- return u();
65
- }
66
- }, f = (e, t, { useBeacon: n = !1, token: r } = {}) => {
67
- try {
68
- let i = JSON.stringify(t);
69
- return n && typeof navigator < "u" && typeof navigator.sendBeacon == "function" ? navigator.sendBeacon(e, i) : typeof fetch == "function" && (fetch(e, {
70
- method: "POST",
71
- headers: {
72
- "Content-Type": "application/json",
73
- ...r ? { Authorization: `Bearer ${r}` } : {}
74
- },
75
- body: i,
76
- keepalive: !0,
77
- credentials: "omit",
78
- mode: "cors"
79
- }).catch(() => {}), !0);
80
- } catch {
81
- return !1;
82
- }
83
- }, p = (e) => {
84
- if (typeof window > "u") return;
85
- let t = window.requestIdleCallback;
86
- if (typeof t == "function") {
87
- t(() => e());
88
- return;
89
- }
90
- setTimeout(e, 1);
91
- }, m = "__intlayer_public_token__", h = 6e4, g = () => {
92
- try {
93
- let e = window.sessionStorage?.getItem(m);
94
- if (!e) return null;
95
- let t = JSON.parse(e);
96
- return typeof t?.token != "string" || typeof t?.expiresAt != "number" ? null : t;
97
- } catch {
98
- return null;
99
- }
100
- }, _ = (e) => {
101
- try {
102
- window.sessionStorage?.setItem(m, JSON.stringify(e));
103
- } catch {}
104
- }, v = ({ backendURL: e, clientId: t }) => {
105
- let n = `${e.replace(/\/$/, "")}/api/public/token`, r = null, i = null, a = (e) => e !== null && e.expiresAt - h > Date.now(), o = () => {
106
- if (a(r)) return r.token;
107
- if (typeof window < "u") {
108
- let e = g();
109
- if (a(e)) return r = e, e.token;
110
- }
111
- }, s = async () => {
112
- try {
113
- let e = await fetch(n, {
114
- method: "POST",
115
- headers: { "Content-Type": "application/json" },
116
- body: JSON.stringify({ clientId: t }),
117
- credentials: "omit",
118
- mode: "cors"
119
- });
120
- if (!e.ok) return;
121
- let i = await e.json(), a = i?.data?.token, o = i?.data?.expiresIn ?? 0;
122
- if (!a || o <= 0) return;
123
- r = {
124
- token: a,
125
- expiresAt: Date.now() + o * 1e3
126
- }, typeof window < "u" && _(r);
127
- } catch {} finally {
128
- i = null;
129
- }
130
- };
131
- return {
132
- getToken: o,
133
- prime: () => {
134
- !t || typeof fetch != "function" || o() || (i ||= s());
135
- }
136
- };
137
- }, y = "intlayer-analytics/1", b = () => typeof window > "u" || !window.location ? "" : window.location.pathname, x = () => {
138
- if (!(typeof document > "u" || !document.referrer)) try {
139
- return new URL(document.referrer).host;
140
- } catch {
141
- return;
142
- }
143
- }, S = (t) => {
144
- let n = d(), r = e(), a = !r && c(n, t.sampleRate), o = s({ max: t.maxBufferSize }), l = `${t.backendURL.replace(/\/$/, "")}/api/analytics/events`, u = v({
145
- backendURL: t.backendURL,
146
- clientId: t.clientId
147
- }), m = "", h = null, g = !1, _ = null, S = null, C = /* @__PURE__ */ new Set(), w = (e = !1) => {
148
- let r = o.drain(), i = u.getToken();
149
- for (let a = 0; a < r.length; a += 200) f(l, {
150
- token: i,
151
- clientId: i ? void 0 : t.clientId,
152
- sessionId: n,
153
- sdkVersion: y,
154
- events: r.slice(a, a + 200)
155
- }, {
156
- useBeacon: e,
157
- token: i
158
- });
159
- }, T = (e) => {
160
- o.push(e) >= t.maxBufferSize && w();
161
- }, E = (e) => {
162
- m = e;
163
- }, D = (e = {}) => {
164
- if (!a) return;
165
- let t = e.url ?? b(), n = e.reason ?? "initial";
166
- (n !== "route_change" || t !== S) && (S = t, C = /* @__PURE__ */ new Set(), T({
167
- type: "page_view",
168
- t: Date.now(),
169
- url: t,
170
- locale: e.locale ?? m,
171
- ref: e.ref ?? x(),
172
- vw: e.vw ?? (typeof window < "u" ? window.innerWidth : void 0),
173
- vh: e.vh ?? (typeof window < "u" ? window.innerHeight : void 0),
174
- reason: n
175
- }));
176
- }, O = (e) => {
177
- if (!a) return;
178
- let t = e.locale ?? m, n = [
179
- e.dictionaryKey,
180
- e.keyPath,
181
- t,
182
- e.experimentKey ?? "",
183
- e.variant ?? ""
184
- ].join("");
185
- C.has(n) || (C.add(n), T({
186
- ...e,
187
- type: "content_exposure",
188
- t: Date.now(),
189
- url: b(),
190
- locale: t
191
- }));
192
- }, k = (e) => {
193
- r || (T({
194
- ...e,
195
- type: "conversion",
196
- t: Date.now(),
197
- url: b(),
198
- locale: e.locale ?? m
199
- }), w());
200
- }, A = (e, t, r) => i(n, e, t, r), j = () => {
201
- if (typeof window > "u") return;
202
- let e = () => {
203
- document.visibilityState === "hidden" && w(!0);
204
- }, t = () => w(!0), n = () => D({ reason: "route_change" });
205
- document.addEventListener("visibilitychange", e), window.addEventListener("pagehide", t, { capture: !0 }), window.addEventListener("popstate", n);
206
- let r = window.history, i = r.pushState, a = function(...e) {
207
- let t = i.apply(this, e);
208
- return D({ reason: "route_change" }), t;
209
- };
210
- r.pushState = a, _ = () => {
211
- document.removeEventListener("visibilitychange", e), window.removeEventListener("pagehide", t, { capture: !0 }), window.removeEventListener("popstate", n), r.pushState === a && (r.pushState = i);
212
- };
213
- };
214
- return {
215
- setLocale: E,
216
- trackPageView: D,
217
- trackContentExposure: O,
218
- trackConversion: k,
219
- getVariant: A,
220
- flush: w,
221
- start: () => {
222
- g || r || (g = !0, u.prime(), h = setInterval(w, t.flushInterval), h?.unref?.(), p(j));
223
- },
224
- stop: () => {
225
- g && (g = !1, h &&= (clearInterval(h), null), _?.(), _ = null, w(!0));
226
- }
227
- };
228
- }, C = "__intlayer_analytics_client__", w = "__intlayer_analytics_ref_count__", T = () => typeof window > "u" ? null : window[C] ?? null, E = (e) => {
229
- typeof window > "u" || (window[C] = e);
230
- }, D = () => {
231
- if (typeof window > "u") return 0;
232
- let e = window;
233
- return e[w] = (e[w] ?? 0) + 1, e[w];
234
- }, O = () => {
235
- if (typeof window > "u") return 0;
236
- let e = window;
237
- return e[w] = Math.max(0, (e[w] ?? 0) - 1), e[w];
238
- }, k = () => {
239
- D();
240
- let e = T();
241
- if (e) return e;
242
- let r = S({
243
- backendURL: n?.backendURL ?? "",
244
- clientId: n?.clientId,
245
- flushInterval: t?.flushInterval ?? 2e4,
246
- maxBufferSize: 500,
247
- sampleRate: t?.sampleRate ?? 1
248
- });
249
- return E(r), r.start(), r;
250
- }, A = () => {
251
- O() > 0 || (T()?.stop(), E(null));
252
- }, j = (e) => e.map((e) => e.key === void 0 ? "*" : String(e.key)).join("."), M = (e) => ({
253
- dictionaryKey: e.dictionaryKey,
254
- keyPath: j(e.keyPath),
255
- locale: e.locale,
256
- nodeType: e.nodeType,
257
- experimentKey: e.experimentKey,
258
- variant: e.variant
259
- });
260
- //#endregion
261
- export { M as buildContentExposure, T as getGlobalAnalyticsClient, k as initAnalyticsClient, A as stopAnalyticsClient };