lit-intlayer 9.9.3 → 9.9.4

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.
Files changed (72) hide show
  1. package/dist/cjs/client/IntlayerBinding.cjs +93 -1
  2. package/dist/cjs/client/index.cjs +28 -1
  3. package/dist/cjs/client/installIntlayer.cjs +6 -1
  4. package/dist/cjs/client/useDictionary.cjs +24 -1
  5. package/dist/cjs/client/useDictionaryDynamic.cjs +47 -1
  6. package/dist/cjs/client/useIntlayer.cjs +30 -1
  7. package/dist/cjs/client/useLocale.cjs +90 -1
  8. package/dist/cjs/client/useLocaleStorage.cjs +56 -1
  9. package/dist/cjs/client/useRewriteURL.cjs +48 -1
  10. package/dist/cjs/editor/useEditor.cjs +3 -1
  11. package/dist/cjs/format/index.cjs +19 -1
  12. package/dist/cjs/format/useCompact.cjs +34 -1
  13. package/dist/cjs/format/useCurrency.cjs +34 -1
  14. package/dist/cjs/format/useDate.cjs +52 -1
  15. package/dist/cjs/format/useIntl.cjs +66 -1
  16. package/dist/cjs/format/useList.cjs +34 -1
  17. package/dist/cjs/format/useNumber.cjs +40 -1
  18. package/dist/cjs/format/usePercentage.cjs +34 -1
  19. package/dist/cjs/format/useRelativeTime.cjs +34 -1
  20. package/dist/cjs/format/useUnit.cjs +34 -1
  21. package/dist/cjs/getDictionary.cjs +14 -1
  22. package/dist/cjs/getIntlayer.cjs +14 -1
  23. package/dist/cjs/html/HTMLRenderer.cjs +53 -1
  24. package/dist/cjs/html/index.cjs +8 -1
  25. package/dist/cjs/html/installIntlayerHTML.cjs +90 -1
  26. package/dist/cjs/html/types.cjs +1 -1
  27. package/dist/cjs/index.cjs +41 -1
  28. package/dist/cjs/markdown/MarkdownRenderer.cjs +97 -1
  29. package/dist/cjs/markdown/compiler.cjs +72 -1
  30. package/dist/cjs/markdown/index.cjs +12 -1
  31. package/dist/cjs/markdown/installIntlayerMarkdown.cjs +98 -1
  32. package/dist/cjs/markdown/runtime.cjs +86 -1
  33. package/dist/cjs/plugins.cjs +217 -3
  34. package/dist/cjs/renderIntlayerNode.cjs +29 -1
  35. package/dist/esm/client/IntlayerBinding.mjs +75 -33
  36. package/dist/esm/client/index.mjs +9 -9
  37. package/dist/esm/client/installIntlayer.mjs +1 -1
  38. package/dist/esm/client/useDictionary.mjs +22 -10
  39. package/dist/esm/client/useDictionaryDynamic.mjs +44 -11
  40. package/dist/esm/client/useIntlayer.mjs +28 -10
  41. package/dist/esm/client/useLocale.mjs +71 -19
  42. package/dist/esm/client/useLocaleStorage.mjs +45 -12
  43. package/dist/esm/client/useRewriteURL.mjs +36 -18
  44. package/dist/esm/editor/useEditor.mjs +1 -1
  45. package/dist/esm/format/index.mjs +10 -10
  46. package/dist/esm/format/useCompact.mjs +23 -19
  47. package/dist/esm/format/useCurrency.mjs +23 -19
  48. package/dist/esm/format/useDate.mjs +37 -27
  49. package/dist/esm/format/useIntl.mjs +54 -13
  50. package/dist/esm/format/useList.mjs +23 -19
  51. package/dist/esm/format/useNumber.mjs +29 -19
  52. package/dist/esm/format/usePercentage.mjs +23 -19
  53. package/dist/esm/format/useRelativeTime.mjs +23 -19
  54. package/dist/esm/format/useUnit.mjs +23 -19
  55. package/dist/esm/getDictionary.mjs +11 -6
  56. package/dist/esm/getIntlayer.mjs +11 -6
  57. package/dist/esm/html/HTMLRenderer.mjs +38 -13
  58. package/dist/esm/html/index.mjs +3 -3
  59. package/dist/esm/html/installIntlayerHTML.mjs +82 -13
  60. package/dist/esm/index.mjs +12 -12
  61. package/dist/esm/markdown/MarkdownRenderer.mjs +66 -26
  62. package/dist/esm/markdown/compiler.mjs +68 -22
  63. package/dist/esm/markdown/index.mjs +4 -4
  64. package/dist/esm/markdown/installIntlayerMarkdown.mjs +87 -23
  65. package/dist/esm/markdown/runtime.mjs +58 -28
  66. package/dist/esm/plugins.mjs +156 -106
  67. package/dist/esm/renderIntlayerNode.mjs +17 -17
  68. package/dist/installIntlayer-CCMOc1XT.mjs +174 -0
  69. package/dist/installIntlayer-HB8aIQ-i.js +203 -0
  70. package/package.json +7 -7
  71. package/dist/installIntlayer-CFvvijL7.js +0 -1
  72. package/dist/installIntlayer-CTpPd7yz.mjs +0 -82
@@ -1,49 +1,91 @@
1
- import { loadingContentPlaceholder as e } from "@intlayer/core/dictionaryManipulator";
2
- import { r as t } from "../../installIntlayer-CTpPd7yz.mjs";
1
+ import { loadingContentPlaceholder } from "@intlayer/core/dictionaryManipulator";
2
+ import { r as getIntlayerClient } from "../../installIntlayer-CCMOc1XT.mjs";
3
3
  // src/client/IntlayerBinding.ts
4
- var n = class {
4
+ /**
5
+ * `ReactiveController` that keeps a Lit element in sync with Intlayer locale
6
+ * changes and, optionally, async dictionary load events.
7
+ *
8
+ * Registered automatically by `.observe(this)` — you should never need to
9
+ * instantiate it directly.
10
+ *
11
+ * @param host - The Lit element to update.
12
+ * @param onConnect - Called inside `hostConnected` (after locale subscription
13
+ * is set up). Useful for triggering an immediate update
14
+ * when the dictionary is already cached.
15
+ * @param onDisconnect - Called inside `hostDisconnected`. Useful for removing
16
+ * the host from a dictionary's update-host registry.
17
+ */
18
+ var IntlayerBinding = class {
5
19
  host;
6
20
  unsubscribeLocale = null;
7
21
  onConnect;
8
22
  onDisconnect;
9
- constructor(e, t, n) {
10
- this.host = e, this.onConnect = t, this.onDisconnect = n, this.host.addController(this);
23
+ constructor(host, onConnect, onDisconnect) {
24
+ this.host = host;
25
+ this.onConnect = onConnect;
26
+ this.onDisconnect = onDisconnect;
27
+ this.host.addController(this);
11
28
  }
12
29
  hostConnected() {
13
- let e = t();
14
- this.unsubscribeLocale = e.subscribe(() => {
30
+ const client = getIntlayerClient();
31
+ this.unsubscribeLocale = client.subscribe(() => {
15
32
  this.host.requestUpdate();
16
- }), this.onConnect?.();
33
+ });
34
+ this.onConnect?.();
17
35
  }
18
36
  hostDisconnected() {
19
- this.unsubscribeLocale?.(), this.unsubscribeLocale = null, this.onDisconnect?.();
37
+ this.unsubscribeLocale?.();
38
+ this.unsubscribeLocale = null;
39
+ this.onDisconnect?.();
20
40
  }
21
- }, r = (r) => {
22
- let i = t(), a = /* @__PURE__ */ new Set(), o, s, c, l = !1, u = () => {
23
- if (!l || s !== i.locale || c !== i.variant) {
24
- l = !0, s = i.locale, c = i.variant;
25
- let e = r({
26
- contextLocale: i.locale,
27
- contextVariant: i.variant
28
- }, (e) => {
29
- o = { content: e };
30
- for (let e of a) e.requestUpdate();
41
+ };
42
+ /**
43
+ * Wraps content read for the client's locale and variant (read again whenever
44
+ * either changes) in an {@link IntlayerLitProxy}. Chain `.observe(this)` so
45
+ * the host re-renders on locale changes and once loading content lands; while
46
+ * the first content loads, every access renders `''`. Shared by `useDictionary`,
47
+ * `useIntlayer` and `useDictionaryDynamic`.
48
+ */
49
+ var createContentProxy = (readContent) => {
50
+ const client = getIntlayerClient();
51
+ const hosts = /* @__PURE__ */ new Set();
52
+ let current;
53
+ let readLocale;
54
+ let readVariant;
55
+ let hasRead = false;
56
+ const getContent = () => {
57
+ if (!hasRead || readLocale !== client.locale || readVariant !== client.variant) {
58
+ hasRead = true;
59
+ readLocale = client.locale;
60
+ readVariant = client.variant;
61
+ const settled = readContent({
62
+ contextLocale: client.locale,
63
+ contextVariant: client.variant
64
+ }, (content) => {
65
+ current = { content };
66
+ for (const host of hosts) host.requestUpdate();
31
67
  });
32
- e && (o = e);
68
+ if (settled) current = settled;
33
69
  }
34
- return o;
70
+ return current;
35
71
  };
36
- u();
37
- let d = new Proxy({}, { get(t, r) {
38
- if (r === "observe") return (e) => (a.add(e), new n(e, () => {
39
- o && e.requestUpdate();
40
- }, () => a.delete(e)), d);
41
- if (r === "then" || typeof r == "string" && r.startsWith("_$")) return;
42
- let i = u();
43
- if (!i) return e[r];
44
- let s = i.content;
45
- return r === Symbol.toPrimitive ? () => s?.[Symbol.toPrimitive]?.() ?? "" : r === "toString" ? () => String(s?.toString?.() ?? "") : s?.[r];
72
+ getContent();
73
+ const proxy = new Proxy({}, { get(_target, property) {
74
+ if (property === "observe") return (host) => {
75
+ hosts.add(host);
76
+ new IntlayerBinding(host, () => {
77
+ if (current) host.requestUpdate();
78
+ }, () => hosts.delete(host));
79
+ return proxy;
80
+ };
81
+ if (property === "then" || typeof property === "string" && property.startsWith("_$")) return;
82
+ const loaded = getContent();
83
+ if (!loaded) return loadingContentPlaceholder[property];
84
+ const content = loaded.content;
85
+ if (property === Symbol.toPrimitive) return () => content?.[Symbol.toPrimitive]?.() ?? "";
86
+ if (property === "toString") return () => String(content?.toString?.() ?? "");
87
+ return content?.[property];
46
88
  } });
47
- return d;
89
+ return proxy;
48
90
  };
49
- export { n as IntlayerBinding, r as createContentProxy };
91
+ export { IntlayerBinding, createContentProxy };
@@ -1,9 +1,9 @@
1
- import { IntlayerBinding as e, createContentProxy as t } from "./IntlayerBinding.mjs";
2
- import { i as n, n as r, r as i, t as a } from "../../installIntlayer-CTpPd7yz.mjs";
3
- import { useDictionary as o } from "./useDictionary.mjs";
4
- import { useDictionaryDynamic as s } from "./useDictionaryDynamic.mjs";
5
- import { useIntlayer as c } from "./useIntlayer.mjs";
6
- import { LocaleController as l, useLocale as u } from "./useLocale.mjs";
7
- import { getLocaleInStorage as d, localeCookie as f, localeInStorage as p, setLocaleCookie as m, setLocaleInStorage as h, useLocaleCookie as g, useLocaleStorage as _ } from "./useLocaleStorage.mjs";
8
- import { useRewriteURL as v } from "./useRewriteURL.mjs";
9
- export { e as IntlayerBinding, a as IntlayerClient, l as LocaleController, t as createContentProxy, r as createIntlayerClient, i as getIntlayerClient, d as getLocaleInStorage, n as installIntlayer, f as localeCookie, p as localeInStorage, m as setLocaleCookie, h as setLocaleInStorage, o as useDictionary, s as useDictionaryDynamic, c as useIntlayer, u as useLocale, g as useLocaleCookie, _ as useLocaleStorage, v as useRewriteURL };
1
+ import { IntlayerBinding, createContentProxy } from "./IntlayerBinding.mjs";
2
+ import { i as installIntlayer, n as createIntlayerClient, r as getIntlayerClient, t as IntlayerClient } from "../../installIntlayer-CCMOc1XT.mjs";
3
+ import { useDictionary } from "./useDictionary.mjs";
4
+ import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
5
+ import { useIntlayer } from "./useIntlayer.mjs";
6
+ import { LocaleController, useLocale } from "./useLocale.mjs";
7
+ import { getLocaleInStorage, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./useLocaleStorage.mjs";
8
+ import { useRewriteURL } from "./useRewriteURL.mjs";
9
+ export { IntlayerBinding, IntlayerClient, LocaleController, createContentProxy, createIntlayerClient, getIntlayerClient, getLocaleInStorage, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage, useRewriteURL };
@@ -1 +1 @@
1
- export { t as IntlayerClient, n as createIntlayerClient, r as getIntlayerClient, i as installIntlayer } from "../../installIntlayer-CTpPd7yz.mjs";
1
+ export { t as IntlayerClient, n as createIntlayerClient, r as getIntlayerClient, i as installIntlayer } from "../../installIntlayer-CCMOc1XT.mjs";
@@ -1,11 +1,23 @@
1
- import { resolveDictionaryArgument as e } from "@intlayer/core/dictionaryManipulator";
2
- import { getDictionary as t } from "../getDictionary.mjs";
3
- import { createContentProxy as n } from "./IntlayerBinding.mjs";
1
+ import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
2
+ import { getDictionary } from "../getDictionary.mjs";
3
+ import { createContentProxy } from "./IntlayerBinding.mjs";
4
4
  // src/client/useDictionary.ts
5
- var r = (r, i) => n(({ contextLocale: n, contextVariant: a }) => ({ content: process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? t(r, i ?? n) : t(r, e({
6
- localeOrSelector: i,
7
- contextLocale: n,
8
- contextVariant: a,
9
- dictionaryKey: r.key
10
- })) }));
11
- export { r as useDictionary };
5
+ /**
6
+ * Returns the content for a raw dictionary (or qualified dictionary group),
7
+ * wrapped in an {@link IntlayerLitProxy} so the caller can subscribe to locale
8
+ * changes via a Lit `ReactiveController`.
9
+ *
10
+ * The second argument is either a locale or a selector object (`{ item }`,
11
+ * `{ variant }`, optionally combined with `locale`).
12
+ *
13
+ * @param dictionary - The raw dictionary (or qualified group) object.
14
+ * @param localeOrSelector - Optional locale or selector.
15
+ * @returns An {@link IntlayerLitProxy} with an `.observe()` registration method.
16
+ */
17
+ var useDictionary = (dictionary, localeOrSelector) => createContentProxy(({ contextLocale, contextVariant }) => ({ content: process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" ? getDictionary(dictionary, resolveDictionaryArgument({
18
+ localeOrSelector,
19
+ contextLocale,
20
+ contextVariant,
21
+ dictionaryKey: dictionary.key
22
+ })) : getDictionary(dictionary, localeOrSelector ?? contextLocale) }));
23
+ export { useDictionary };
@@ -1,13 +1,46 @@
1
- import { createDynamicContentStore as e } from "@intlayer/core/dictionaryManipulator";
2
- import { getDictionary as t } from "../getDictionary.mjs";
3
- import { createContentProxy as n } from "./IntlayerBinding.mjs";
1
+ import { createDynamicContentStore } from "@intlayer/core/dictionaryManipulator";
2
+ import { getDictionary } from "../getDictionary.mjs";
3
+ import { createContentProxy } from "./IntlayerBinding.mjs";
4
4
  // src/client/useDictionaryDynamic.ts
5
- var r = e((e, n) => t(e, n)), i = (e, t, i) => {
6
- let a = r.createReader(e, String(t));
7
- return n(({ contextLocale: e, contextVariant: t }, n) => a({
8
- localeOrSelector: i,
9
- contextLocale: e,
10
- contextVariant: t
11
- }, n));
5
+ /** Content cache shared by every dynamic read of the page. */
6
+ var dynamicContentStore = createDynamicContentStore((dictionary, argument) => getDictionary(dictionary, argument));
7
+ /**
8
+ * Returns the translated content for a lazily-loaded dictionary, wrapped in an
9
+ * {@link IntlayerLitProxy} so the caller can register a Lit `ReactiveController`
10
+ * that keeps the element in sync with both the async bundle load and locale
11
+ * changes.
12
+ *
13
+ * This is the babel-optimized counterpart of `useIntlayer` when
14
+ * `importMode = 'dynamic'` — it accepts the locale-keyed loader map injected
15
+ * by the build plugin, matching the same signature as `react-intlayer` and
16
+ * other framework adapters.
17
+ *
18
+ * While loading, property accesses return the shared loading placeholder,
19
+ * which renders `''`. Chain `.observe(this)` so Lit triggers `requestUpdate()`
20
+ * once the bundle is ready and on every subsequent locale change.
21
+ *
22
+ * The `intlayerLitPlugin` Vite plugin automatically appends
23
+ * `.observe(this)` at build / serve time, so manual chaining is usually
24
+ * unnecessary.
25
+ *
26
+ * @param dictionaryPromise - Locale-keyed loader map, or a qualified loader map.
27
+ * @param key - The dictionary key (used for cache namespacing).
28
+ * @param localeOrSelector - Optional locale or selector.
29
+ * @returns An {@link IntlayerLitProxy} proxy with an `.observe()` method.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // Typically injected by the babel/SWC optimization plugin:
34
+ * import _hash_dyn from '.intlayer/dynamic_dictionaries/app.mjs';
35
+ * private content = useDictionaryDynamic(_hash_dyn, 'app').observe(this);
36
+ * ```
37
+ */
38
+ var useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
39
+ const readContent = dynamicContentStore.createReader(dictionaryPromise, String(key));
40
+ return createContentProxy(({ contextLocale, contextVariant }, onLoad) => readContent({
41
+ localeOrSelector,
42
+ contextLocale,
43
+ contextVariant
44
+ }, onLoad));
12
45
  };
13
- export { i as useDictionaryDynamic };
46
+ export { useDictionaryDynamic };
@@ -1,11 +1,29 @@
1
- import { resolveDictionaryArgument as e } from "@intlayer/core/dictionaryManipulator";
2
- import { getIntlayer as t } from "../getIntlayer.mjs";
3
- import { createContentProxy as n } from "./IntlayerBinding.mjs";
1
+ import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
2
+ import { getIntlayer } from "../getIntlayer.mjs";
3
+ import { createContentProxy } from "./IntlayerBinding.mjs";
4
4
  // src/client/useIntlayer.ts
5
- var r = (r, i) => n(({ contextLocale: n, contextVariant: a }) => ({ content: process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? t(r, i ?? n) : t(r, e({
6
- localeOrSelector: i,
7
- contextLocale: n,
8
- contextVariant: a,
9
- dictionaryKey: r
10
- })) }));
11
- export { r as useIntlayer };
5
+ /**
6
+ * Returns the translated content for the given dictionary key, wrapped in an
7
+ * {@link IntlayerLitProxy} so the caller can subscribe to locale changes via
8
+ * a Lit `ReactiveController`.
9
+ *
10
+ * Matches the same signature as `react-intlayer` and all other framework
11
+ * adapters:
12
+ * ```ts
13
+ * private content = useIntlayer('my-component').observe(this);
14
+ * ```
15
+ *
16
+ * The babel/SWC optimization plugin transforms this at build time into either:
17
+ * - static mode: `useDictionary(_hash)` — synchronous JSON import
18
+ * - dynamic mode: `useDictionaryDynamic(_dyn, 'key')` — lazy locale split
19
+ *
20
+ * In non-optimized builds (dev without babel) the content is read from
21
+ * `getIntlayer`, again whenever the client locale or variant changes.
22
+ */
23
+ var useIntlayer = (key, localeOrSelector) => createContentProxy(({ contextLocale, contextVariant }) => ({ content: process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" ? getIntlayer(key, resolveDictionaryArgument({
24
+ localeOrSelector,
25
+ contextLocale,
26
+ contextVariant,
27
+ dictionaryKey: key
28
+ })) : getIntlayer(key, localeOrSelector ?? contextLocale) }));
29
+ export { useIntlayer };
@@ -1,36 +1,88 @@
1
- import { internationalization as e } from "@intlayer/config/built";
2
- import { r as t } from "../../installIntlayer-CTpPd7yz.mjs";
3
- import { setLocaleInStorage as n } from "./useLocaleStorage.mjs";
1
+ import { internationalization } from "@intlayer/config/built";
2
+ import { r as getIntlayerClient } from "../../installIntlayer-CCMOc1XT.mjs";
3
+ import { setLocaleInStorage } from "./useLocaleStorage.mjs";
4
4
  // src/client/useLocale.ts
5
- var r = class {
5
+ /**
6
+ * ReactiveController that exposes the current locale and a `setLocale` setter.
7
+ * The host element re-renders whenever the locale changes.
8
+ */
9
+ var LocaleController = class {
6
10
  host;
7
11
  _isCookieEnabled;
8
12
  _onLocaleChange;
9
13
  _unsubscribe = null;
14
+ /** The currently active locale. */
10
15
  locale;
16
+ /** The application's default locale (from config). */
11
17
  defaultLocale;
18
+ /** All available locales (from config). */
12
19
  availableLocales;
13
- constructor(n, r = {}) {
14
- this.host = n, this._isCookieEnabled = r.isCookieEnabled, this._onLocaleChange = r.onLocaleChange;
15
- let i = t(), { defaultLocale: a, locales: o } = e ?? {};
16
- this.locale = i.locale, this.defaultLocale = a, this.availableLocales = o ?? [], n.addController(this);
20
+ constructor(host, props = {}) {
21
+ this.host = host;
22
+ this._isCookieEnabled = props.isCookieEnabled;
23
+ this._onLocaleChange = props.onLocaleChange;
24
+ const client = getIntlayerClient();
25
+ const { defaultLocale, locales: availableLocales } = internationalization ?? {};
26
+ this.locale = client.locale;
27
+ this.defaultLocale = defaultLocale;
28
+ this.availableLocales = availableLocales ?? [];
29
+ host.addController(this);
17
30
  }
18
- setLocale = (e) => {
19
- if (!this.availableLocales.map(String).includes(e)) {
20
- console.error(`Locale "${e}" is not available.`);
31
+ /**
32
+ * Change the application locale.
33
+ * Validates against `availableLocales`, persists to storage, and triggers a re-render.
34
+ */
35
+ setLocale = (newLocale) => {
36
+ if (!this.availableLocales.map(String).includes(newLocale)) {
37
+ console.error(`Locale "${newLocale}" is not available.`);
21
38
  return;
22
39
  }
23
- let r = t();
24
- r.setLocale(e), n(e, this._isCookieEnabled ?? r.isCookieEnabled ?? !0), this._onLocaleChange?.(e);
40
+ const client = getIntlayerClient();
41
+ client.setLocale(newLocale);
42
+ setLocaleInStorage(newLocale, this._isCookieEnabled ?? client.isCookieEnabled ?? true);
43
+ this._onLocaleChange?.(newLocale);
25
44
  };
26
45
  hostConnected() {
27
- let e = t();
28
- this._unsubscribe = e.subscribe((e) => {
29
- this.locale = e, this.host.requestUpdate();
46
+ const client = getIntlayerClient();
47
+ this._unsubscribe = client.subscribe((newLocale) => {
48
+ this.locale = newLocale;
49
+ this.host.requestUpdate();
30
50
  });
31
51
  }
32
52
  hostDisconnected() {
33
- this._unsubscribe?.(), this._unsubscribe = null;
53
+ this._unsubscribe?.();
54
+ this._unsubscribe = null;
34
55
  }
35
- }, i = (e, t = {}) => new r(e, t);
36
- export { r as LocaleController, i as useLocale };
56
+ };
57
+ /**
58
+ * Reactive hook that provides locale management.
59
+ *
60
+ * Returns a `LocaleController` with:
61
+ * - `locale` — the current locale (updates the host on change)
62
+ * - `defaultLocale` — the config default locale
63
+ * - `availableLocales` — all configured locales
64
+ * - `setLocale(locale)` — switches the app locale
65
+ *
66
+ * @param host - The LitElement (or any ReactiveControllerHost).
67
+ * @param props - Optional configuration.
68
+ * @returns A `LocaleController`.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * class LocaleSwitcher extends LitElement {
73
+ * private locale = useLocale(this);
74
+ *
75
+ * render() {
76
+ * return html`
77
+ * <select @change=${(e: Event) => this.locale.setLocale((e.target as HTMLSelectElement).value as any)}>
78
+ * ${this.locale.availableLocales.map(
79
+ * (loc) => html`<option value=${loc} ?selected=${loc === this.locale.locale}>${loc}</option>`
80
+ * )}
81
+ * </select>
82
+ * `;
83
+ * }
84
+ * }
85
+ * ```
86
+ */
87
+ var useLocale = (host, props = {}) => new LocaleController(host, props);
88
+ export { LocaleController, useLocale };
@@ -1,16 +1,49 @@
1
- import { LocaleStorageClient as e, getCachedLocaleFromStorageClient as t, getLocaleFromStorageClient as n, localeStorageOptions as r, setLocaleInStorageClient as i } from "@intlayer/core/utils";
1
+ import { LocaleStorageClient, getCachedLocaleFromStorageClient, getLocaleFromStorageClient, localeStorageOptions, setLocaleInStorageClient } from "@intlayer/core/utils";
2
2
  // src/client/useLocaleStorage.ts
3
- var a = t, o = /* @__PURE__ */ n(r), s = o, c = (e, t) => i(e, {
4
- ...r,
5
- isCookieEnabled: t
6
- }), l = c, u = (t) => {
7
- let n = e({
8
- ...r,
9
- isCookieEnabled: t
3
+ /**
4
+ * Reads the locale persisted in the browser storage (cookie, localStorage…).
5
+ *
6
+ * Unlike `localeInStorage`, read on first call rather than at import, then
7
+ * cached until the next `setLocaleInStorage`. Never cached on the server.
8
+ */
9
+ var getLocaleInStorage = getCachedLocaleFromStorageClient;
10
+ /**
11
+ * Get the current locale from storage (cookie or localStorage).
12
+ *
13
+ * Read once at import time; marked pure so bundlers drop the read when nothing
14
+ * imports it.
15
+ */
16
+ var localeInStorage = /* @__PURE__ */ getLocaleFromStorageClient(localeStorageOptions);
17
+ /**
18
+ * @deprecated Use localeInStorage instead.
19
+ */
20
+ var localeCookie = localeInStorage;
21
+ /**
22
+ * Persist the locale to storage (cookie and/or localStorage).
23
+ */
24
+ var setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorageClient(locale, {
25
+ ...localeStorageOptions,
26
+ isCookieEnabled
27
+ });
28
+ /**
29
+ * @deprecated Use setLocaleInStorage instead.
30
+ */
31
+ var setLocaleCookie = setLocaleInStorage;
32
+ /**
33
+ * Returns the current locale from storage and a setter.
34
+ */
35
+ var useLocaleStorage = (isCookieEnabled) => {
36
+ const storage = LocaleStorageClient({
37
+ ...localeStorageOptions,
38
+ isCookieEnabled
10
39
  });
11
40
  return {
12
- localeStorage: n.getLocale(),
13
- setLocaleStorage: n.setLocale
41
+ localeStorage: storage.getLocale(),
42
+ setLocaleStorage: storage.setLocale
14
43
  };
15
- }, d = u;
16
- export { a as getLocaleInStorage, s as localeCookie, o as localeInStorage, l as setLocaleCookie, c as setLocaleInStorage, d as useLocaleCookie, u as useLocaleStorage };
44
+ };
45
+ /**
46
+ * @deprecated Use useLocaleStorage instead.
47
+ */
48
+ var useLocaleCookie = useLocaleStorage;
49
+ export { getLocaleInStorage, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
@@ -1,29 +1,47 @@
1
- import { routing as e } from "@intlayer/config/built";
2
- import { getRewritePath as t } from "@intlayer/core/localization";
3
- import { r as n } from "../../installIntlayer-CTpPd7yz.mjs";
1
+ import { routing } from "@intlayer/config/built";
2
+ import { getRewritePath } from "@intlayer/core/localization";
3
+ import { r as getIntlayerClient } from "../../installIntlayer-CCMOc1XT.mjs";
4
4
  // src/client/useRewriteURL.ts
5
- var r = class {
5
+ /**
6
+ * ReactiveController that keeps the browser URL in sync with the current locale.
7
+ *
8
+ * Uses `window.history.replaceState` to update the address bar without
9
+ * triggering a full navigation.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * class AppShell extends LitElement {
14
+ * private _rewrite = useRewriteURL(this);
15
+ * }
16
+ * ```
17
+ */
18
+ var RewriteURLController = class {
6
19
  _host;
7
20
  _unsubscribe = null;
8
- constructor(e) {
9
- this._host = e, e.addController(this);
21
+ constructor(host) {
22
+ this._host = host;
23
+ host.addController(this);
10
24
  }
11
- _rewrite(n) {
12
- let r = e?.rewrite;
13
- if (typeof window > "u" || !r) return;
14
- let i = window.location.pathname, a = t(i, n, r);
15
- a && a !== i && window.history.replaceState(window.history.state, "", a + window.location.search + window.location.hash);
25
+ _rewrite(locale) {
26
+ const rewrite = routing?.rewrite;
27
+ if (typeof window === "undefined" || !rewrite) return;
28
+ const pathname = window.location.pathname;
29
+ const targetPath = getRewritePath(pathname, locale, rewrite);
30
+ if (targetPath && targetPath !== pathname) window.history.replaceState(window.history.state, "", targetPath + window.location.search + window.location.hash);
16
31
  }
17
32
  hostConnected() {
18
- let e = n();
19
- this._rewrite(e.locale), this._unsubscribe = e.subscribe((e) => {
20
- this._rewrite(e);
33
+ const client = getIntlayerClient();
34
+ this._rewrite(client.locale);
35
+ this._unsubscribe = client.subscribe((newLocale) => {
36
+ this._rewrite(newLocale);
21
37
  });
22
38
  }
23
39
  hostDisconnected() {
24
- this._unsubscribe?.(), this._unsubscribe = null;
40
+ this._unsubscribe?.();
41
+ this._unsubscribe = null;
25
42
  }
26
- }, i = (e) => {
27
- new r(e);
28
43
  };
29
- export { i as useRewriteURL };
44
+ var useRewriteURL = (host) => {
45
+ new RewriteURLController(host);
46
+ };
47
+ export { useRewriteURL };
@@ -1 +1 @@
1
- export { a as useEditor } from "../../installIntlayer-CTpPd7yz.mjs";
1
+ export { a as useEditor } from "../../installIntlayer-CCMOc1XT.mjs";
@@ -1,10 +1,10 @@
1
- import { useCompact as e } from "./useCompact.mjs";
2
- import { useCurrency as t } from "./useCurrency.mjs";
3
- import { useDate as n } from "./useDate.mjs";
4
- import { useIntl as r } from "./useIntl.mjs";
5
- import { useList as i } from "./useList.mjs";
6
- import { useNumber as a } from "./useNumber.mjs";
7
- import { usePercentage as o } from "./usePercentage.mjs";
8
- import { useRelativeTime as s } from "./useRelativeTime.mjs";
9
- import { useUnit as c } from "./useUnit.mjs";
10
- export { e as useCompact, t as useCurrency, n as useDate, r as useIntl, i as useList, a as useNumber, o as usePercentage, s as useRelativeTime, c as useUnit };
1
+ import { useCompact } from "./useCompact.mjs";
2
+ import { useCurrency } from "./useCurrency.mjs";
3
+ import { useDate } from "./useDate.mjs";
4
+ import { useIntl } from "./useIntl.mjs";
5
+ import { useList } from "./useList.mjs";
6
+ import { useNumber } from "./useNumber.mjs";
7
+ import { usePercentage } from "./usePercentage.mjs";
8
+ import { useRelativeTime } from "./useRelativeTime.mjs";
9
+ import { useUnit } from "./useUnit.mjs";
10
+ export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
@@ -1,29 +1,33 @@
1
- import { compact as e } from "@intlayer/core/formatters";
2
- import { r as t } from "../../installIntlayer-CTpPd7yz.mjs";
1
+ import { compact } from "@intlayer/core/formatters";
2
+ import { r as getIntlayerClient } from "../../installIntlayer-CCMOc1XT.mjs";
3
3
  // src/format/useCompact.ts
4
- var n = class {
4
+ var CompactController = class {
5
5
  host;
6
6
  _unsubscribe = null;
7
7
  value;
8
- constructor(n) {
9
- this.host = n;
10
- let r = t();
11
- this.value = (...t) => e(t[0], {
12
- ...t[1],
13
- locale: t[1]?.locale ?? r.locale
14
- }), n.addController(this);
8
+ constructor(host) {
9
+ this.host = host;
10
+ const client = getIntlayerClient();
11
+ this.value = (...args) => compact(args[0], {
12
+ ...args[1],
13
+ locale: args[1]?.locale ?? client.locale
14
+ });
15
+ host.addController(this);
15
16
  }
16
17
  hostConnected() {
17
- let n = t();
18
- this._unsubscribe = n.subscribe((t) => {
19
- this.value = (...n) => e(n[0], {
20
- ...n[1],
21
- locale: n[1]?.locale ?? t
22
- }), this.host.requestUpdate();
18
+ const client = getIntlayerClient();
19
+ this._unsubscribe = client.subscribe((newLocale) => {
20
+ this.value = (...args) => compact(args[0], {
21
+ ...args[1],
22
+ locale: args[1]?.locale ?? newLocale
23
+ });
24
+ this.host.requestUpdate();
23
25
  });
24
26
  }
25
27
  hostDisconnected() {
26
- this._unsubscribe?.(), this._unsubscribe = null;
28
+ this._unsubscribe?.();
29
+ this._unsubscribe = null;
27
30
  }
28
- }, r = (e) => new n(e);
29
- export { r as useCompact };
31
+ };
32
+ var useCompact = (host) => new CompactController(host);
33
+ export { useCompact };