@prefabs.tech/vue3-i18n 0.28.0 → 0.29.1

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.
@@ -34,28 +34,28 @@ function S(e) {
34
34
  }
35
35
  function b(...e) {
36
36
  const t = [], n = () => {
37
- t.forEach((a) => a()), t.length = 0;
38
- }, o = (a, c, u, p) => (a.addEventListener(c, u, p), () => a.removeEventListener(c, u, p)), l = C(() => {
39
- const a = $(v(e[0])).filter((c) => c != null);
40
- return a.every((c) => typeof c != "string") ? a : void 0;
41
- }), r = oe(
37
+ t.forEach((r) => r()), t.length = 0;
38
+ }, o = (r, a, u, p) => (r.addEventListener(a, u, p), () => r.removeEventListener(a, u, p)), l = C(() => {
39
+ const r = $(v(e[0])).filter((a) => a != null);
40
+ return r.every((a) => typeof a != "string") ? r : void 0;
41
+ }), c = oe(
42
42
  () => {
43
- var a, c;
43
+ var r, a;
44
44
  return [
45
- (c = (a = l.value) == null ? void 0 : a.map((u) => S(u))) != null ? c : [W].filter((u) => u != null),
45
+ (a = (r = l.value) == null ? void 0 : r.map((u) => S(u))) != null ? a : [W].filter((u) => u != null),
46
46
  $(v(l.value ? e[1] : e[0])),
47
47
  $(M(l.value ? e[2] : e[1])),
48
48
  // @ts-expect-error - TypeScript gets the correct types, but somehow still complains
49
49
  v(l.value ? e[3] : e[2])
50
50
  ];
51
51
  },
52
- ([a, c, u, p]) => {
53
- if (n(), !a?.length || !c?.length || !u?.length)
52
+ ([r, a, u, p]) => {
53
+ if (n(), !r?.length || !a?.length || !u?.length)
54
54
  return;
55
55
  const g = ee(p) ? { ...p } : p;
56
56
  t.push(
57
- ...a.flatMap(
58
- (h) => c.flatMap(
57
+ ...r.flatMap(
58
+ (h) => a.flatMap(
59
59
  (m) => u.map((k) => o(h, m, k, g))
60
60
  )
61
61
  )
@@ -63,21 +63,21 @@ function b(...e) {
63
63
  },
64
64
  { flush: "post" }
65
65
  ), f = () => {
66
- r(), n();
66
+ c(), n();
67
67
  };
68
68
  return X(n), f;
69
69
  }
70
70
  let T = !1;
71
71
  function le(e, t, n = {}) {
72
- const { window: o = W, ignore: l = [], capture: r = !0, detectIframe: f = !1, controls: a = !1 } = n;
72
+ const { window: o = W, ignore: l = [], capture: c = !0, detectIframe: f = !1, controls: r = !1 } = n;
73
73
  if (!o)
74
- return a ? { stop: y, cancel: y, trigger: y } : y;
74
+ return r ? { stop: y, cancel: y, trigger: y } : y;
75
75
  if (te && !T) {
76
76
  T = !0;
77
77
  const s = { passive: !0 };
78
78
  Array.from(o.document.body.children).forEach((i) => b(i, "click", y, s)), b(o.document.documentElement, "click", y, s);
79
79
  }
80
- let c = !0;
80
+ let a = !0;
81
81
  const u = (s) => v(l).some((i) => {
82
82
  if (typeof i == "string")
83
83
  return Array.from(o.document.querySelectorAll(i)).some((d) => d === s.target || s.composedPath().includes(d));
@@ -97,8 +97,8 @@ function le(e, t, n = {}) {
97
97
  const h = (s) => {
98
98
  const i = S(e);
99
99
  if (s.target != null && !(!(i instanceof Element) && p(e) && g(e, s)) && !(!i || i === s.target || s.composedPath().includes(i))) {
100
- if ("detail" in s && s.detail === 0 && (c = !u(s)), !c) {
101
- c = !0;
100
+ if ("detail" in s && s.detail === 0 && (a = !u(s)), !a) {
101
+ a = !0;
102
102
  return;
103
103
  }
104
104
  t(s);
@@ -110,10 +110,10 @@ function le(e, t, n = {}) {
110
110
  m || (m = !0, setTimeout(() => {
111
111
  m = !1;
112
112
  }, 0), h(s));
113
- }, { passive: !0, capture: r }),
113
+ }, { passive: !0, capture: c }),
114
114
  b(o, "pointerdown", (s) => {
115
115
  const i = S(e);
116
- c = !u(s) && !!(i && !s.composedPath().includes(i));
116
+ a = !u(s) && !!(i && !s.composedPath().includes(i));
117
117
  }, { passive: !0 }),
118
118
  f && b(o, "blur", (s) => {
119
119
  setTimeout(() => {
@@ -123,23 +123,23 @@ function le(e, t, n = {}) {
123
123
  }, 0);
124
124
  }, { passive: !0 })
125
125
  ].filter(Boolean), A = () => k.forEach((s) => s());
126
- return a ? {
126
+ return r ? {
127
127
  stop: A,
128
128
  cancel: () => {
129
- c = !1;
129
+ a = !1;
130
130
  },
131
131
  trigger: (s) => {
132
- c = !0, h(s), c = !1;
132
+ a = !0, h(s), a = !1;
133
133
  }
134
134
  } : A;
135
135
  }
136
- const se = { class: "badge" }, re = {
136
+ const se = { class: "badge" }, ce = {
137
137
  key: 0,
138
138
  class: "country"
139
- }, ce = {
139
+ }, re = {
140
140
  name: "LocaleBadge"
141
141
  }, ae = /* @__PURE__ */ B({
142
- ...ce,
142
+ ...re,
143
143
  props: {
144
144
  locale: {
145
145
  required: !0,
@@ -152,9 +152,9 @@ const se = { class: "badge" }, re = {
152
152
  if (l.length > 1)
153
153
  return l[1];
154
154
  });
155
- return (l, r) => (_(), L("span", se, [
155
+ return (l, c) => (_(), L("span", se, [
156
156
  N(I(n.value) + " ", 1),
157
- o.value ? (_(), L("span", re, I(o.value), 1)) : V("", !0)
157
+ o.value ? (_(), L("span", ce, I(o.value), 1)) : V("", !0)
158
158
  ]));
159
159
  }
160
160
  }), ie = (e, t) => {
@@ -208,28 +208,28 @@ const se = { class: "badge" }, re = {
208
208
  }
209
209
  },
210
210
  setup(e) {
211
- const { availableLocales: t, locale: n, t: o } = F(), l = Q(), r = x(!1), f = (g) => {
212
- n.value = g, r.value = !1;
211
+ const { availableLocales: t, locale: n, t: o } = F(), l = Q(), c = x(!1), f = (g) => {
212
+ n.value = g, c.value = !1;
213
213
  const { setLocale: h } = q(l.slug);
214
214
  h(g);
215
- }, a = C(() => ({
215
+ }, r = C(() => ({
216
216
  locale: n.value,
217
217
  name: u(n.value)
218
- })), c = () => {
219
- r.value = !r.value;
218
+ })), a = () => {
219
+ c.value = !c.value;
220
220
  }, u = (g) => o(`locales.${g}`), p = x(null);
221
221
  return le(p, (g) => {
222
- r.value = !1;
222
+ c.value = !1;
223
223
  }), (g, h) => (_(), L("nav", {
224
224
  ref_key: "dzangolabVueI18nLocaleSwitcher",
225
225
  ref: p,
226
- class: P(["locale-switcher", { expanded: r.value }])
226
+ class: P(["locale-switcher", { expanded: c.value }])
227
227
  }, [
228
228
  w("div", {
229
229
  class: "locale-trigger",
230
- onClick: c
230
+ onClick: a
231
231
  }, [
232
- w("div", ge, I(a.value.name), 1),
232
+ w("div", ge, I(r.value.name), 1),
233
233
  w("span", me, [
234
234
  Z(g.$slots, "icon", {}, () => [
235
235
  h[0] || (h[0] = w("svg", {
@@ -251,7 +251,7 @@ const se = { class: "badge" }, re = {
251
251
  w("ul", he, [
252
252
  (_(!0), L(H, null, J(M(t), (m) => (_(), L("li", {
253
253
  key: m,
254
- class: P([{ current: m === a.value.locale }, "truncated"]),
254
+ class: P([{ current: m === r.value.locale }, "truncated"]),
255
255
  onClick: (k) => f(m)
256
256
  }, [
257
257
  K(pe, {
@@ -280,41 +280,39 @@ const se = { class: "badge" }, re = {
280
280
  let n;
281
281
  return e.some((o) => {
282
282
  const l = o.split("-");
283
- let r = [];
283
+ let c = [];
284
284
  for (let f = 1; f <= l.length; f++)
285
- if (r = (r.length === 0 ? t : r).filter((a) => a.startsWith(l.slice(0, f).join("-"))), r.length === 1)
286
- return n = r[0], !0;
285
+ if (c = (c.length === 0 ? t : c).filter((r) => r.startsWith(l.slice(0, f).join("-"))), c.length === 1)
286
+ return n = c[0], !0;
287
287
  }), n;
288
288
  }, be = (e, t) => {
289
289
  if (!t)
290
290
  return e;
291
291
  const n = {};
292
292
  for (const o in t) {
293
- const l = t[o], r = e[o];
294
- n[o] = r ? {
295
- ...r,
293
+ const l = t[o], c = e[o];
294
+ n[o] = c ? {
295
+ ...c,
296
296
  ...l
297
297
  } : l;
298
298
  }
299
299
  for (const o in e) {
300
300
  if (n[o])
301
301
  continue;
302
- const l = t[o], r = e[o];
302
+ const l = t[o], c = e[o];
303
303
  n[o] = l ? {
304
- ...r,
304
+ ...c,
305
305
  ...l
306
- } : r;
306
+ } : c;
307
307
  }
308
308
  return n;
309
309
  }, Se = (e) => {
310
- const t = e.config.i18n, n = e.config.slug, { getLocale: o, setLocale: l } = q(n), r = o();
311
- if (!r) {
312
- const c = Le(
313
- navigator.languages,
314
- t.supportedLocales
315
- );
316
- l(c);
317
- }
310
+ const t = e.config.i18n, n = e.config.slug, { getLocale: o, setLocale: l } = q(n);
311
+ let c = o();
312
+ c || (c = Le(
313
+ navigator.languages,
314
+ t.supportedLocales
315
+ ), l(c));
318
316
  const f = be(
319
317
  ye(t.supportedLocales),
320
318
  t?.messages
@@ -323,7 +321,7 @@ const se = { class: "badge" }, re = {
323
321
  ...t,
324
322
  globalInjection: !0,
325
323
  legacy: !1,
326
- locale: r,
324
+ locale: c,
327
325
  messages: f
328
326
  });
329
327
  }, $e = {
@@ -1 +1 @@
1
- (function(f,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("vue-i18n"),require("vue"),require("@prefabs.tech/vue3-config")):typeof define=="function"&&define.amd?define(["exports","vue-i18n","vue","@prefabs.tech/vue3-config"],k):(f=typeof globalThis<"u"?globalThis:f||self,k(f.PrefabsTechVue3I18n={},f.VueI18n,f.Vue,f.PrefabsTechVue3Config))})(this,function(f,k,e,M){"use strict";function j(t){return e.getCurrentScope()?(e.onScopeDispose(t),!0):!1}const V=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const v=Object.prototype.toString,q=t=>v.call(t)==="[object Object]",b=()=>{},x=D();function D(){var t,n;return V&&((t=window?.navigator)==null?void 0:t.userAgent)&&(/iP(?:ad|hone|od)/.test(window.navigator.userAgent)||((n=window?.navigator)==null?void 0:n.maxTouchPoints)>2&&/iPad|Macintosh/.test(window?.navigator.userAgent))}function E(t){return Array.isArray(t)?t:[t]}function W(t,n,o){return e.watch(t,n,{...o,immediate:!0})}const I=V?window:void 0;function w(t){var n;const o=e.toValue(t);return(n=o?.$el)!=null?n:o}function L(...t){const n=[],o=()=>{n.forEach(i=>i()),n.length=0},l=(i,a,d,g)=>(i.addEventListener(a,d,g),()=>i.removeEventListener(a,d,g)),c=e.computed(()=>{const i=E(e.toValue(t[0])).filter(a=>a!=null);return i.every(a=>typeof a!="string")?i:void 0}),s=W(()=>{var i,a;return[(a=(i=c.value)==null?void 0:i.map(d=>w(d)))!=null?a:[I].filter(d=>d!=null),E(e.toValue(c.value?t[1]:t[0])),E(e.unref(c.value?t[2]:t[1])),e.toValue(c.value?t[3]:t[2])]},([i,a,d,g])=>{if(o(),!i?.length||!a?.length||!d?.length)return;const h=q(g)?{...g}:g;n.push(...i.flatMap(y=>a.flatMap(_=>d.map(S=>l(y,_,S,h)))))},{flush:"post"}),m=()=>{s(),o()};return j(o),m}let P=!1;function z(t,n,o={}){const{window:l=I,ignore:c=[],capture:s=!0,detectIframe:m=!1,controls:i=!1}=o;if(!l)return i?{stop:b,cancel:b,trigger:b}:b;if(x&&!P){P=!0;const r={passive:!0};Array.from(l.document.body.children).forEach(u=>L(u,"click",b,r)),L(l.document.documentElement,"click",b,r)}let a=!0;const d=r=>e.toValue(c).some(u=>{if(typeof u=="string")return Array.from(l.document.querySelectorAll(u)).some(p=>p===r.target||r.composedPath().includes(p));{const p=w(u);return p&&(r.target===p||r.composedPath().includes(p))}});function g(r){const u=e.toValue(r);return u&&u.$.subTree.shapeFlag===16}function h(r,u){const p=e.toValue(r),C=p.$.subTree&&p.$.subTree.children;return C==null||!Array.isArray(C)?!1:C.some(A=>A.el===u.target||u.composedPath().includes(A.el))}const y=r=>{const u=w(t);if(r.target!=null&&!(!(u instanceof Element)&&g(t)&&h(t,r))&&!(!u||u===r.target||r.composedPath().includes(u))){if("detail"in r&&r.detail===0&&(a=!d(r)),!a){a=!0;return}n(r)}};let _=!1;const S=[L(l,"click",r=>{_||(_=!0,setTimeout(()=>{_=!1},0),y(r))},{passive:!0,capture:s}),L(l,"pointerdown",r=>{const u=w(t);a=!d(r)&&!!(u&&!r.composedPath().includes(u))},{passive:!0}),m&&L(l,"blur",r=>{setTimeout(()=>{var u;const p=w(t);((u=l.document.activeElement)==null?void 0:u.tagName)==="IFRAME"&&!p?.contains(l.document.activeElement)&&n(r)},0)},{passive:!0})].filter(Boolean),O=()=>S.forEach(r=>r());return i?{stop:O,cancel:()=>{a=!1},trigger:r=>{a=!0,y(r),a=!1}}:O}const F={class:"badge"},G={key:0,class:"country"},R={name:"LocaleBadge"},U=e.defineComponent({...R,props:{locale:{required:!0,type:String}},setup(t){const n=t,o=e.computed(()=>n.locale.substring(0,2)),l=e.computed(()=>{const c=n.locale.split("-");if(c.length>1)return c[1]});return(c,s)=>(e.openBlock(),e.createElementBlock("span",F,[e.createTextVNode(e.toDisplayString(o.value)+" ",1),l.value?(e.openBlock(),e.createElementBlock("span",G,e.toDisplayString(l.value),1)):e.createCommentVNode("",!0)]))}}),Z=((t,n)=>{const o=t.__vccOpts||t;for(const[l,c]of n)o[l]=c;return o})(U,[["__scopeId","data-v-c1291edf"]]),H={class:"locale"},J={name:"LocaleOption"},K=e.defineComponent({...J,props:{locale:{required:!0,type:String},name:{required:!0,type:String},showBadges:{default:!0,type:Boolean}},setup(t){return(n,o)=>(e.openBlock(),e.createElementBlock("div",H,[t.showBadges?(e.openBlock(),e.createBlock(Z,{key:0,locale:t.locale},null,8,["locale"])):e.createCommentVNode("",!0),e.createTextVNode(" "+e.toDisplayString(t.name),1)]))}}),B=t=>{const n=`${t}.locale`;return{getLocale:()=>{const c=localStorage.getItem(n);return c||void 0},setLocale:c=>{c?localStorage.setItem(n,c):localStorage.removeItem(n)}}},Q={class:"locale truncated"},X={class:"truncated"},Y={class:"dropdown"},ee=["onClick"],te={name:"LocaleSwitcher"},ne=e.defineComponent({...te,props:{showBadges:{default:!0,type:Boolean}},setup(t){const{availableLocales:n,locale:o,t:l}=k.useI18n(),c=M.useConfig(),s=e.ref(!1),m=h=>{o.value=h,s.value=!1;const{setLocale:y}=B(c.slug);y(h)},i=e.computed(()=>({locale:o.value,name:d(o.value)})),a=()=>{s.value=!s.value},d=h=>l(`locales.${h}`),g=e.ref(null);return z(g,h=>{s.value=!1}),(h,y)=>(e.openBlock(),e.createElementBlock("nav",{ref_key:"dzangolabVueI18nLocaleSwitcher",ref:g,class:e.normalizeClass(["locale-switcher",{expanded:s.value}])},[e.createElementVNode("div",{class:"locale-trigger",onClick:a},[e.createElementVNode("div",Q,e.toDisplayString(i.value.name),1),e.createElementVNode("span",X,[e.renderSlot(h.$slots,"icon",{},()=>[y[0]||(y[0]=e.createElementVNode("svg",{"aria-label":"open user menu",fill:"none",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},[e.createElementVNode("path",{"clip-rule":"evenodd","fill-rule":"evenodd",d:"M12 7C12.2652 7 12.5196 7.10536 12.7071 7.29289L19.7071 14.2929C20.0976 14.6834 20.0976 15.3166 19.7071 15.7071C19.3166 16.0976 18.6834 16.0976 18.2929 15.7071L12 9.41421L5.70711 15.7071C5.31658 16.0976 4.68342 16.0976 4.29289 15.7071C3.90237 15.3166 3.90237 14.6834 4.29289 14.2929L11.2929 7.29289C11.4804 7.10536 11.7348 7 12 7Z",fill:"currentColor"})],-1))])])]),e.createElementVNode("ul",Y,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(n),_=>(e.openBlock(),e.createElementBlock("li",{key:_,class:e.normalizeClass([{current:_===i.value.locale},"truncated"]),onClick:S=>m(_)},[e.createVNode(K,{locale:_,name:d(_),"show-badges":t.showBadges},null,8,["locale","name","show-badges"])],10,ee))),128))])],2))}}),oe={en:"English","en-GB":"English (GB)","en-US":"English (US)",fr:"Français",th:"ไทย"},le=t=>{const n={};for(const o of t)n[o]={locales:oe};return n},T=(t,n)=>{let o;return t.some(l=>{const c=l.split("-");let s=[];for(let m=1;m<=c.length;m++)if(s=(s.length===0?n:s).filter(i=>i.startsWith(c.slice(0,m).join("-"))),s.length===1)return o=s[0],!0}),o},$=(t,n)=>{if(!n)return t;const o={};for(const l in n){const c=n[l],s=t[l];o[l]=s?{...s,...c}:c}for(const l in t){if(o[l])continue;const c=n[l],s=t[l];o[l]=c?{...s,...c}:s}return o},N=t=>{const n=t.config.i18n,o=t.config.slug,{getLocale:l,setLocale:c}=B(o),s=l();if(!s){const a=T(navigator.languages,n.supportedLocales);c(a)}const m=$(le(n.supportedLocales),n?.messages);return k.createI18n({...n,globalInjection:!0,legacy:!1,locale:s,messages:m})},ce={install:(t,n)=>{const o=N(n);t.use(o)}};Object.defineProperty(f,"useI18n",{enumerable:!0,get:()=>k.useI18n}),f.LocaleSwitcher=ne,f.createI18n=N,f.default=ce,f.getPreferredLocale=T,f.prependMessages=$,f.useLocaleStore=B,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(f,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("vue-i18n"),require("vue"),require("@prefabs.tech/vue3-config")):typeof define=="function"&&define.amd?define(["exports","vue-i18n","vue","@prefabs.tech/vue3-config"],k):(f=typeof globalThis<"u"?globalThis:f||self,k(f.PrefabsTechVue3I18n={},f.VueI18n,f.Vue,f.PrefabsTechVue3Config))})(this,function(f,k,e,M){"use strict";function j(t){return e.getCurrentScope()?(e.onScopeDispose(t),!0):!1}const V=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const v=Object.prototype.toString,q=t=>v.call(t)==="[object Object]",b=()=>{},x=D();function D(){var t,n;return V&&((t=window?.navigator)==null?void 0:t.userAgent)&&(/iP(?:ad|hone|od)/.test(window.navigator.userAgent)||((n=window?.navigator)==null?void 0:n.maxTouchPoints)>2&&/iPad|Macintosh/.test(window?.navigator.userAgent))}function E(t){return Array.isArray(t)?t:[t]}function W(t,n,o){return e.watch(t,n,{...o,immediate:!0})}const I=V?window:void 0;function w(t){var n;const o=e.toValue(t);return(n=o?.$el)!=null?n:o}function L(...t){const n=[],o=()=>{n.forEach(a=>a()),n.length=0},l=(a,i,d,g)=>(a.addEventListener(i,d,g),()=>a.removeEventListener(i,d,g)),c=e.computed(()=>{const a=E(e.toValue(t[0])).filter(i=>i!=null);return a.every(i=>typeof i!="string")?a:void 0}),s=W(()=>{var a,i;return[(i=(a=c.value)==null?void 0:a.map(d=>w(d)))!=null?i:[I].filter(d=>d!=null),E(e.toValue(c.value?t[1]:t[0])),E(e.unref(c.value?t[2]:t[1])),e.toValue(c.value?t[3]:t[2])]},([a,i,d,g])=>{if(o(),!a?.length||!i?.length||!d?.length)return;const h=q(g)?{...g}:g;n.push(...a.flatMap(y=>i.flatMap(_=>d.map(S=>l(y,_,S,h)))))},{flush:"post"}),m=()=>{s(),o()};return j(o),m}let P=!1;function z(t,n,o={}){const{window:l=I,ignore:c=[],capture:s=!0,detectIframe:m=!1,controls:a=!1}=o;if(!l)return a?{stop:b,cancel:b,trigger:b}:b;if(x&&!P){P=!0;const r={passive:!0};Array.from(l.document.body.children).forEach(u=>L(u,"click",b,r)),L(l.document.documentElement,"click",b,r)}let i=!0;const d=r=>e.toValue(c).some(u=>{if(typeof u=="string")return Array.from(l.document.querySelectorAll(u)).some(p=>p===r.target||r.composedPath().includes(p));{const p=w(u);return p&&(r.target===p||r.composedPath().includes(p))}});function g(r){const u=e.toValue(r);return u&&u.$.subTree.shapeFlag===16}function h(r,u){const p=e.toValue(r),C=p.$.subTree&&p.$.subTree.children;return C==null||!Array.isArray(C)?!1:C.some(A=>A.el===u.target||u.composedPath().includes(A.el))}const y=r=>{const u=w(t);if(r.target!=null&&!(!(u instanceof Element)&&g(t)&&h(t,r))&&!(!u||u===r.target||r.composedPath().includes(u))){if("detail"in r&&r.detail===0&&(i=!d(r)),!i){i=!0;return}n(r)}};let _=!1;const S=[L(l,"click",r=>{_||(_=!0,setTimeout(()=>{_=!1},0),y(r))},{passive:!0,capture:s}),L(l,"pointerdown",r=>{const u=w(t);i=!d(r)&&!!(u&&!r.composedPath().includes(u))},{passive:!0}),m&&L(l,"blur",r=>{setTimeout(()=>{var u;const p=w(t);((u=l.document.activeElement)==null?void 0:u.tagName)==="IFRAME"&&!p?.contains(l.document.activeElement)&&n(r)},0)},{passive:!0})].filter(Boolean),O=()=>S.forEach(r=>r());return a?{stop:O,cancel:()=>{i=!1},trigger:r=>{i=!0,y(r),i=!1}}:O}const F={class:"badge"},G={key:0,class:"country"},R={name:"LocaleBadge"},U=e.defineComponent({...R,props:{locale:{required:!0,type:String}},setup(t){const n=t,o=e.computed(()=>n.locale.substring(0,2)),l=e.computed(()=>{const c=n.locale.split("-");if(c.length>1)return c[1]});return(c,s)=>(e.openBlock(),e.createElementBlock("span",F,[e.createTextVNode(e.toDisplayString(o.value)+" ",1),l.value?(e.openBlock(),e.createElementBlock("span",G,e.toDisplayString(l.value),1)):e.createCommentVNode("",!0)]))}}),Z=((t,n)=>{const o=t.__vccOpts||t;for(const[l,c]of n)o[l]=c;return o})(U,[["__scopeId","data-v-c1291edf"]]),H={class:"locale"},J={name:"LocaleOption"},K=e.defineComponent({...J,props:{locale:{required:!0,type:String},name:{required:!0,type:String},showBadges:{default:!0,type:Boolean}},setup(t){return(n,o)=>(e.openBlock(),e.createElementBlock("div",H,[t.showBadges?(e.openBlock(),e.createBlock(Z,{key:0,locale:t.locale},null,8,["locale"])):e.createCommentVNode("",!0),e.createTextVNode(" "+e.toDisplayString(t.name),1)]))}}),B=t=>{const n=`${t}.locale`;return{getLocale:()=>{const c=localStorage.getItem(n);return c||void 0},setLocale:c=>{c?localStorage.setItem(n,c):localStorage.removeItem(n)}}},Q={class:"locale truncated"},X={class:"truncated"},Y={class:"dropdown"},ee=["onClick"],te={name:"LocaleSwitcher"},ne=e.defineComponent({...te,props:{showBadges:{default:!0,type:Boolean}},setup(t){const{availableLocales:n,locale:o,t:l}=k.useI18n(),c=M.useConfig(),s=e.ref(!1),m=h=>{o.value=h,s.value=!1;const{setLocale:y}=B(c.slug);y(h)},a=e.computed(()=>({locale:o.value,name:d(o.value)})),i=()=>{s.value=!s.value},d=h=>l(`locales.${h}`),g=e.ref(null);return z(g,h=>{s.value=!1}),(h,y)=>(e.openBlock(),e.createElementBlock("nav",{ref_key:"dzangolabVueI18nLocaleSwitcher",ref:g,class:e.normalizeClass(["locale-switcher",{expanded:s.value}])},[e.createElementVNode("div",{class:"locale-trigger",onClick:i},[e.createElementVNode("div",Q,e.toDisplayString(a.value.name),1),e.createElementVNode("span",X,[e.renderSlot(h.$slots,"icon",{},()=>[y[0]||(y[0]=e.createElementVNode("svg",{"aria-label":"open user menu",fill:"none",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},[e.createElementVNode("path",{"clip-rule":"evenodd","fill-rule":"evenodd",d:"M12 7C12.2652 7 12.5196 7.10536 12.7071 7.29289L19.7071 14.2929C20.0976 14.6834 20.0976 15.3166 19.7071 15.7071C19.3166 16.0976 18.6834 16.0976 18.2929 15.7071L12 9.41421L5.70711 15.7071C5.31658 16.0976 4.68342 16.0976 4.29289 15.7071C3.90237 15.3166 3.90237 14.6834 4.29289 14.2929L11.2929 7.29289C11.4804 7.10536 11.7348 7 12 7Z",fill:"currentColor"})],-1))])])]),e.createElementVNode("ul",Y,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(n),_=>(e.openBlock(),e.createElementBlock("li",{key:_,class:e.normalizeClass([{current:_===a.value.locale},"truncated"]),onClick:S=>m(_)},[e.createVNode(K,{locale:_,name:d(_),"show-badges":t.showBadges},null,8,["locale","name","show-badges"])],10,ee))),128))])],2))}}),oe={en:"English","en-GB":"English (GB)","en-US":"English (US)",fr:"Français",th:"ไทย"},le=t=>{const n={};for(const o of t)n[o]={locales:oe};return n},T=(t,n)=>{let o;return t.some(l=>{const c=l.split("-");let s=[];for(let m=1;m<=c.length;m++)if(s=(s.length===0?n:s).filter(a=>a.startsWith(c.slice(0,m).join("-"))),s.length===1)return o=s[0],!0}),o},$=(t,n)=>{if(!n)return t;const o={};for(const l in n){const c=n[l],s=t[l];o[l]=s?{...s,...c}:c}for(const l in t){if(o[l])continue;const c=n[l],s=t[l];o[l]=c?{...s,...c}:s}return o},N=t=>{const n=t.config.i18n,o=t.config.slug,{getLocale:l,setLocale:c}=B(o);let s=l();s||(s=T(navigator.languages,n.supportedLocales),c(s));const m=$(le(n.supportedLocales),n?.messages);return k.createI18n({...n,globalInjection:!0,legacy:!1,locale:s,messages:m})},ce={install:(t,n)=>{const o=N(n);t.use(o)}};Object.defineProperty(f,"useI18n",{enumerable:!0,get:()=>k.useI18n}),f.LocaleSwitcher=ne,f.createI18n=N,f.default=ce,f.getPreferredLocale=T,f.prependMessages=$,f.useLocaleStore=B,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prefabs.tech/vue3-i18n",
3
- "version": "0.28.0",
3
+ "version": "0.29.1",
4
4
  "description": "Vue3 I18n Plugin",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,9 +20,9 @@
20
20
  "vue-i18n": "9.1.10"
21
21
  },
22
22
  "devDependencies": {
23
- "@prefabs.tech/eslint-config": "0.2.0",
24
- "@prefabs.tech/tsconfig": "0.2.0",
25
- "@prefabs.tech/vue3-config": "0.28.0",
23
+ "@prefabs.tech/eslint-config": "0.2.1",
24
+ "@prefabs.tech/tsconfig": "0.2.1",
25
+ "@prefabs.tech/vue3-config": "0.29.1",
26
26
  "@types/node": "24.10.1",
27
27
  "@typescript-eslint/eslint-plugin": "8.24.1",
28
28
  "@typescript-eslint/parser": "8.24.1",
@@ -49,7 +49,7 @@
49
49
  "vue-tsc": "1.2.0"
50
50
  },
51
51
  "peerDependencies": {
52
- "@prefabs.tech/vue3-config": "0.28.0",
52
+ "@prefabs.tech/vue3-config": "0.29.1",
53
53
  "@vueuse/core": ">=9.4.0",
54
54
  "pinia": ">=2.0",
55
55
  "vue": ">=3.2"
@@ -64,10 +64,10 @@
64
64
  "lint:fix": "eslint . --ext .vue --fix",
65
65
  "snapshot:update": "vitest --environment jsdom run --update",
66
66
  "sort-package": "npx sort-package-json",
67
- "test": "vitest --environment jsdom run --coverage",
68
- "test:component": "vitest --environment jsdom run component/",
69
- "test:snapshot": "vitest --environment jsdom run snapshot/",
70
- "test:unit": "vitest --environment jsdom run unit/",
67
+ "test": "vitest --environment jsdom run --coverage --passWithNoTests",
68
+ "test:component": "vitest --environment jsdom run component/ --passWithNoTests",
69
+ "test:snapshot": "vitest --environment jsdom run snapshot/ --passWithNoTests",
70
+ "test:unit": "vitest --environment jsdom run unit/ --passWithNoTests",
71
71
  "test:watch": "vitest",
72
72
  "typecheck": "vue-tsc --noEmit -p tsconfig.json --composite false"
73
73
  }