vanilla-intlayer 8.8.0 → 8.9.0

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 (209) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/cjs/client/index.cjs +24 -1
  3. package/dist/cjs/client/installIntlayer.cjs +98 -1
  4. package/dist/cjs/client/installIntlayer.cjs.map +1 -0
  5. package/dist/cjs/client/useDictionary.cjs +59 -1
  6. package/dist/cjs/client/useDictionary.cjs.map +1 -0
  7. package/dist/cjs/client/useDictionaryDynamic.cjs +93 -1
  8. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -0
  9. package/dist/cjs/client/useIntlayer.cjs +65 -1
  10. package/dist/cjs/client/useIntlayer.cjs.map +1 -0
  11. package/dist/cjs/client/useLocale.cjs +58 -1
  12. package/dist/cjs/client/useLocale.cjs.map +1 -0
  13. package/dist/cjs/client/useLocaleStorage.cjs +51 -1
  14. package/dist/cjs/client/useLocaleStorage.cjs.map +1 -0
  15. package/dist/cjs/client/useRewriteURL.cjs +46 -1
  16. package/dist/cjs/client/useRewriteURL.cjs.map +1 -0
  17. package/dist/cjs/editor/useEditor.cjs +49 -1
  18. package/dist/cjs/editor/useEditor.cjs.map +1 -0
  19. package/dist/cjs/format/index.cjs +20 -1
  20. package/dist/cjs/format/useCompact.cjs +17 -1
  21. package/dist/cjs/format/useCompact.cjs.map +1 -0
  22. package/dist/cjs/format/useCurrency.cjs +17 -1
  23. package/dist/cjs/format/useCurrency.cjs.map +1 -0
  24. package/dist/cjs/format/useDate.cjs +26 -1
  25. package/dist/cjs/format/useDate.cjs.map +1 -0
  26. package/dist/cjs/format/useIntl.cjs +44 -1
  27. package/dist/cjs/format/useIntl.cjs.map +1 -0
  28. package/dist/cjs/format/useList.cjs +17 -1
  29. package/dist/cjs/format/useList.cjs.map +1 -0
  30. package/dist/cjs/format/useNumber.cjs +20 -1
  31. package/dist/cjs/format/useNumber.cjs.map +1 -0
  32. package/dist/cjs/format/usePercentage.cjs +17 -1
  33. package/dist/cjs/format/usePercentage.cjs.map +1 -0
  34. package/dist/cjs/format/useRelativeTime.cjs +17 -1
  35. package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
  36. package/dist/cjs/format/useUnit.cjs +17 -1
  37. package/dist/cjs/format/useUnit.cjs.map +1 -0
  38. package/dist/cjs/getDictionary.cjs +11 -1
  39. package/dist/cjs/getDictionary.cjs.map +1 -0
  40. package/dist/cjs/getIntlayer.cjs +11 -1
  41. package/dist/cjs/getIntlayer.cjs.map +1 -0
  42. package/dist/cjs/html/HTMLRenderer.cjs +22 -1
  43. package/dist/cjs/html/HTMLRenderer.cjs.map +1 -0
  44. package/dist/cjs/html/index.cjs +9 -1
  45. package/dist/cjs/html/installIntlayerHTML.cjs +91 -1
  46. package/dist/cjs/html/installIntlayerHTML.cjs.map +1 -0
  47. package/dist/cjs/html/types.cjs +0 -1
  48. package/dist/cjs/index.cjs +37 -1
  49. package/dist/cjs/markdown/MarkdownRenderer.cjs +41 -1
  50. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
  51. package/dist/cjs/markdown/compiler.cjs +37 -1
  52. package/dist/cjs/markdown/compiler.cjs.map +1 -0
  53. package/dist/cjs/markdown/index.cjs +11 -1
  54. package/dist/cjs/markdown/installIntlayerMarkdown.cjs +98 -1
  55. package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -0
  56. package/dist/cjs/markdown/runtime.cjs +87 -1
  57. package/dist/cjs/markdown/runtime.cjs.map +1 -0
  58. package/dist/cjs/plugins.cjs +240 -1
  59. package/dist/cjs/plugins.cjs.map +1 -0
  60. package/dist/cjs/renderIntlayerNode.cjs +44 -1
  61. package/dist/cjs/renderIntlayerNode.cjs.map +1 -0
  62. package/dist/esm/client/index.mjs +9 -8
  63. package/dist/esm/client/installIntlayer.mjs +93 -2
  64. package/dist/esm/client/installIntlayer.mjs.map +1 -0
  65. package/dist/esm/client/useDictionary.mjs +55 -8
  66. package/dist/esm/client/useDictionary.mjs.map +1 -0
  67. package/dist/esm/client/useDictionaryDynamic.mjs +82 -28
  68. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -0
  69. package/dist/esm/client/useIntlayer.mjs +61 -8
  70. package/dist/esm/client/useIntlayer.mjs.map +1 -0
  71. package/dist/esm/client/useLocale.mjs +51 -17
  72. package/dist/esm/client/useLocale.mjs.map +1 -0
  73. package/dist/esm/client/useLocaleStorage.mjs +39 -13
  74. package/dist/esm/client/useLocaleStorage.mjs.map +1 -0
  75. package/dist/esm/client/useRewriteURL.mjs +40 -12
  76. package/dist/esm/client/useRewriteURL.mjs.map +1 -0
  77. package/dist/esm/editor/useEditor.mjs +47 -2
  78. package/dist/esm/editor/useEditor.mjs.map +1 -0
  79. package/dist/esm/format/index.mjs +11 -10
  80. package/dist/esm/format/useCompact.mjs +11 -8
  81. package/dist/esm/format/useCompact.mjs.map +1 -0
  82. package/dist/esm/format/useCurrency.mjs +11 -8
  83. package/dist/esm/format/useCurrency.mjs.map +1 -0
  84. package/dist/esm/format/useDate.mjs +18 -12
  85. package/dist/esm/format/useDate.mjs.map +1 -0
  86. package/dist/esm/format/useIntl.mjs +36 -8
  87. package/dist/esm/format/useIntl.mjs.map +1 -0
  88. package/dist/esm/format/useList.mjs +11 -8
  89. package/dist/esm/format/useList.mjs.map +1 -0
  90. package/dist/esm/format/useNumber.mjs +14 -8
  91. package/dist/esm/format/useNumber.mjs.map +1 -0
  92. package/dist/esm/format/usePercentage.mjs +11 -8
  93. package/dist/esm/format/usePercentage.mjs.map +1 -0
  94. package/dist/esm/format/useRelativeTime.mjs +11 -8
  95. package/dist/esm/format/useRelativeTime.mjs.map +1 -0
  96. package/dist/esm/format/useUnit.mjs +11 -8
  97. package/dist/esm/format/useUnit.mjs.map +1 -0
  98. package/dist/esm/getDictionary.mjs +7 -4
  99. package/dist/esm/getDictionary.mjs.map +1 -0
  100. package/dist/esm/getIntlayer.mjs +7 -4
  101. package/dist/esm/getIntlayer.mjs.map +1 -0
  102. package/dist/esm/html/HTMLRenderer.mjs +17 -5
  103. package/dist/esm/html/HTMLRenderer.mjs.map +1 -0
  104. package/dist/esm/html/index.mjs +4 -3
  105. package/dist/esm/html/installIntlayerHTML.mjs +81 -13
  106. package/dist/esm/html/installIntlayerHTML.mjs.map +1 -0
  107. package/dist/esm/index.mjs +13 -12
  108. package/dist/esm/markdown/MarkdownRenderer.mjs +36 -16
  109. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
  110. package/dist/esm/markdown/compiler.mjs +28 -4
  111. package/dist/esm/markdown/compiler.mjs.map +1 -0
  112. package/dist/esm/markdown/index.mjs +5 -4
  113. package/dist/esm/markdown/installIntlayerMarkdown.mjs +86 -23
  114. package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -0
  115. package/dist/esm/markdown/runtime.mjs +60 -28
  116. package/dist/esm/markdown/runtime.mjs.map +1 -0
  117. package/dist/esm/plugins.mjs +187 -134
  118. package/dist/esm/plugins.mjs.map +1 -0
  119. package/dist/esm/renderIntlayerNode.mjs +32 -15
  120. package/dist/esm/renderIntlayerNode.mjs.map +1 -0
  121. package/dist/types/client/index.d.ts +8 -0
  122. package/dist/{client → types/client}/installIntlayer.d.ts +27 -20
  123. package/dist/types/client/installIntlayer.d.ts.map +1 -0
  124. package/dist/{client → types/client}/useDictionary.d.ts +22 -17
  125. package/dist/types/client/useDictionary.d.ts.map +1 -0
  126. package/dist/{client → types/client}/useDictionaryDynamic.d.ts +10 -5
  127. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
  128. package/dist/{client → types/client}/useIntlayer.d.ts +9 -4
  129. package/dist/types/client/useIntlayer.d.ts.map +1 -0
  130. package/dist/{client → types/client}/useLocale.d.ts +14 -10
  131. package/dist/types/client/useLocale.d.ts.map +1 -0
  132. package/dist/types/client/useLocaleStorage.d.ts +37 -0
  133. package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
  134. package/dist/{client → types/client}/useRewriteURL.d.ts +5 -1
  135. package/dist/types/client/useRewriteURL.d.ts.map +1 -0
  136. package/dist/{editor → types/editor}/useEditor.d.ts +5 -1
  137. package/dist/types/editor/useEditor.d.ts.map +1 -0
  138. package/dist/types/format/index.d.ts +10 -0
  139. package/dist/types/format/useCompact.d.ts +7 -0
  140. package/dist/types/format/useCompact.d.ts.map +1 -0
  141. package/dist/types/format/useCurrency.d.ts +7 -0
  142. package/dist/types/format/useCurrency.d.ts.map +1 -0
  143. package/dist/types/format/useDate.d.ts +10 -0
  144. package/dist/types/format/useDate.d.ts.map +1 -0
  145. package/dist/{format → types/format}/useIntl.d.ts +10 -5
  146. package/dist/types/format/useIntl.d.ts.map +1 -0
  147. package/dist/types/format/useList.d.ts +7 -0
  148. package/dist/types/format/useList.d.ts.map +1 -0
  149. package/dist/types/format/useNumber.d.ts +10 -0
  150. package/dist/types/format/useNumber.d.ts.map +1 -0
  151. package/dist/types/format/usePercentage.d.ts +7 -0
  152. package/dist/types/format/usePercentage.d.ts.map +1 -0
  153. package/dist/types/format/useRelativeTime.d.ts +7 -0
  154. package/dist/types/format/useRelativeTime.d.ts.map +1 -0
  155. package/dist/types/format/useUnit.d.ts +7 -0
  156. package/dist/types/format/useUnit.d.ts.map +1 -0
  157. package/dist/types/getDictionary.d.ts +9 -0
  158. package/dist/types/getDictionary.d.ts.map +1 -0
  159. package/dist/types/getIntlayer.d.ts +8 -0
  160. package/dist/types/getIntlayer.d.ts.map +1 -0
  161. package/dist/types/html/HTMLRenderer.d.ts +21 -0
  162. package/dist/types/html/HTMLRenderer.d.ts.map +1 -0
  163. package/dist/types/html/index.d.ts +4 -0
  164. package/dist/{html → types/html}/installIntlayerHTML.d.ts +18 -13
  165. package/dist/types/html/installIntlayerHTML.d.ts.map +1 -0
  166. package/dist/{html → types/html}/types.d.ts +12 -14
  167. package/dist/types/html/types.d.ts.map +1 -0
  168. package/dist/types/index.d.ts +20 -0
  169. package/dist/types/index.d.ts.map +1 -0
  170. package/dist/types/markdown/MarkdownRenderer.d.ts +32 -0
  171. package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
  172. package/dist/types/markdown/compiler.d.ts +23 -0
  173. package/dist/types/markdown/compiler.d.ts.map +1 -0
  174. package/dist/types/markdown/index.d.ts +4 -0
  175. package/dist/types/markdown/installIntlayerMarkdown.d.ts +71 -0
  176. package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -0
  177. package/dist/types/markdown/runtime.d.ts +16 -0
  178. package/dist/types/markdown/runtime.d.ts.map +1 -0
  179. package/dist/types/plugins.d.ts +80 -0
  180. package/dist/types/plugins.d.ts.map +1 -0
  181. package/dist/types/renderIntlayerNode.d.ts +31 -0
  182. package/dist/types/renderIntlayerNode.d.ts.map +1 -0
  183. package/package.json +10 -13
  184. package/dist/client/index.d.ts +0 -7
  185. package/dist/client/useLocaleStorage.d.ts +0 -31
  186. package/dist/format/index.d.ts +0 -9
  187. package/dist/format/useCompact.d.ts +0 -2
  188. package/dist/format/useCurrency.d.ts +0 -2
  189. package/dist/format/useDate.d.ts +0 -5
  190. package/dist/format/useList.d.ts +0 -2
  191. package/dist/format/useNumber.d.ts +0 -5
  192. package/dist/format/usePercentage.d.ts +0 -2
  193. package/dist/format/useRelativeTime.d.ts +0 -2
  194. package/dist/format/useUnit.d.ts +0 -2
  195. package/dist/getDictionary.d.ts +0 -4
  196. package/dist/getIntlayer.d.ts +0 -3
  197. package/dist/html/HTMLRenderer.d.ts +0 -14
  198. package/dist/html/index.d.ts +0 -3
  199. package/dist/index.d.ts +0 -11
  200. package/dist/installIntlayer-C99qMzFH.mjs +0 -47
  201. package/dist/installIntlayer-_1cC62gP.js +0 -1
  202. package/dist/markdown/MarkdownRenderer.d.ts +0 -22
  203. package/dist/markdown/compiler.d.ts +0 -19
  204. package/dist/markdown/index.d.ts +0 -3
  205. package/dist/markdown/installIntlayerMarkdown.d.ts +0 -70
  206. package/dist/markdown/runtime.d.ts +0 -12
  207. package/dist/plugins-Cv8sSUPw.js +0 -1
  208. package/dist/plugins.d.ts +0 -78
  209. package/dist/renderIntlayerNode.d.ts +0 -22
@@ -0,0 +1,29 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -1 +1,24 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../../installIntlayer-_1cC62gP.js`),t=require(`./useDictionary.cjs`),n=require(`./useDictionaryDynamic.cjs`),r=require(`./useIntlayer.cjs`),i=require(`./useLocaleStorage.cjs`),a=require(`./useLocale.cjs`),o=require(`./useRewriteURL.cjs`);exports.IntlayerClient=e.t,exports.createIntlayerClient=e.n,exports.getIntlayerClient=e.r,exports.installIntlayer=e.i,exports.localeCookie=i.localeCookie,exports.localeInStorage=i.localeInStorage,exports.setLocaleCookie=i.setLocaleCookie,exports.setLocaleInStorage=i.setLocaleInStorage,exports.useDictionary=t.useDictionary,exports.useDictionaryDynamic=n.useDictionaryDynamic,exports.useIntlayer=r.useIntlayer,exports.useLocale=a.useLocale,exports.useLocaleCookie=i.useLocaleCookie,exports.useLocaleStorage=i.useLocaleStorage,exports.useRewriteURL=o.useRewriteURL;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_client_installIntlayer = require('./installIntlayer.cjs');
3
+ const require_client_useDictionary = require('./useDictionary.cjs');
4
+ const require_client_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
5
+ const require_client_useIntlayer = require('./useIntlayer.cjs');
6
+ const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
7
+ const require_client_useLocale = require('./useLocale.cjs');
8
+ const require_client_useRewriteURL = require('./useRewriteURL.cjs');
9
+
10
+ exports.IntlayerClient = require_client_installIntlayer.IntlayerClient;
11
+ exports.createIntlayerClient = require_client_installIntlayer.createIntlayerClient;
12
+ exports.getIntlayerClient = require_client_installIntlayer.getIntlayerClient;
13
+ exports.installIntlayer = require_client_installIntlayer.installIntlayer;
14
+ exports.localeCookie = require_client_useLocaleStorage.localeCookie;
15
+ exports.localeInStorage = require_client_useLocaleStorage.localeInStorage;
16
+ exports.setLocaleCookie = require_client_useLocaleStorage.setLocaleCookie;
17
+ exports.setLocaleInStorage = require_client_useLocaleStorage.setLocaleInStorage;
18
+ exports.useDictionary = require_client_useDictionary.useDictionary;
19
+ exports.useDictionaryDynamic = require_client_useDictionaryDynamic.useDictionaryDynamic;
20
+ exports.useIntlayer = require_client_useIntlayer.useIntlayer;
21
+ exports.useLocale = require_client_useLocale.useLocale;
22
+ exports.useLocaleCookie = require_client_useLocaleStorage.useLocaleCookie;
23
+ exports.useLocaleStorage = require_client_useLocaleStorage.useLocaleStorage;
24
+ exports.useRewriteURL = require_client_useRewriteURL.useRewriteURL;
@@ -1 +1,98 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../../installIntlayer-_1cC62gP.js`);exports.IntlayerClient=e.t,exports.createIntlayerClient=e.n,exports.getIntlayerClient=e.r,exports.installIntlayer=e.i;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_editor_useEditor = require('../editor/useEditor.cjs');
4
+ let _intlayer_config_built = require("@intlayer/config/built");
5
+ let _intlayer_config_client = require("@intlayer/config/client");
6
+
7
+ //#region src/client/installIntlayer.ts
8
+ var IntlayerClient = class {
9
+ _locale;
10
+ _listeners = /* @__PURE__ */ new Set();
11
+ isCookieEnabled;
12
+ constructor(locale, isCookieEnabled = true) {
13
+ const { defaultLocale } = _intlayer_config_built.internationalization ?? {};
14
+ (0, _intlayer_config_client.setIntlayerIdentifier)();
15
+ this._locale = locale ?? defaultLocale;
16
+ this.isCookieEnabled = isCookieEnabled;
17
+ }
18
+ get locale() {
19
+ return this._locale;
20
+ }
21
+ setLocale(newLocale) {
22
+ this._locale = newLocale;
23
+ for (const listener of this._listeners) listener(newLocale);
24
+ }
25
+ subscribe(listener) {
26
+ this._listeners.add(listener);
27
+ return () => {
28
+ this._listeners.delete(listener);
29
+ };
30
+ }
31
+ /**
32
+ * Fire all listeners with the current locale without changing it.
33
+ * Used to trigger re-renders after async data loads.
34
+ */
35
+ notify() {
36
+ for (const listener of this._listeners) listener(this._locale);
37
+ }
38
+ };
39
+ /**
40
+ * Singleton instance
41
+ */
42
+ let instance = null;
43
+ /**
44
+ * Create and return a single IntlayerClient instance.
45
+ */
46
+ const createIntlayerClient = (locale, isCookieEnabled = true) => {
47
+ if (instance) return instance;
48
+ instance = new IntlayerClient(locale, isCookieEnabled);
49
+ return instance;
50
+ };
51
+ /**
52
+ * Get the current IntlayerClient instance, creating one with defaults if needed.
53
+ */
54
+ const getIntlayerClient = () => {
55
+ if (!instance) instance = new IntlayerClient();
56
+ return instance;
57
+ };
58
+ /**
59
+ * Install Intlayer into your vanilla JS application.
60
+ *
61
+ * Call this once at application startup, before any Intlayer APIs are used.
62
+ *
63
+ * When called with a `config` argument, `window.INTLAYER_CONFIG` is set so
64
+ * that `@intlayer/config/built` resolves the correct values in the browser
65
+ * without requiring module aliasing in the bundler configuration.
66
+ *
67
+ * @param locale - Initial locale (defaults to config defaultLocale).
68
+ * @param isCookieEnabled - Whether to persist locale in cookies/localStorage.
69
+ * @param config - Optional Intlayer configuration. When provided, sets
70
+ * `window.INTLAYER_CONFIG` with the browser-safe subset of the config so
71
+ * the application works without a Vite/webpack plugin alias.
72
+ * @returns The IntlayerClient singleton.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * import { installIntlayer } from 'vanilla-intlayer';
77
+ *
78
+ * // With explicit config (no build plugin alias needed):
79
+ * installIntlayer('en', true, {
80
+ * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },
81
+ * });
82
+ *
83
+ * // With build plugin (alias handles config automatically):
84
+ * installIntlayer('en');
85
+ * ```
86
+ */
87
+ const installIntlayer = ({ locale, isCookieEnabled } = {}) => {
88
+ const client = createIntlayerClient(locale, isCookieEnabled);
89
+ require_editor_useEditor.useEditor();
90
+ return client;
91
+ };
92
+
93
+ //#endregion
94
+ exports.IntlayerClient = IntlayerClient;
95
+ exports.createIntlayerClient = createIntlayerClient;
96
+ exports.getIntlayerClient = getIntlayerClient;
97
+ exports.installIntlayer = installIntlayer;
98
+ //# sourceMappingURL=installIntlayer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installIntlayer.cjs","names":["internationalization"],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useEditor } from '../editor/useEditor';\n\ntype LocaleListener = (locale: LocalesValues) => void;\n\nexport class IntlayerClient {\n private _locale: LocalesValues;\n private _listeners: Set<LocaleListener> = new Set();\n isCookieEnabled: boolean;\n\n constructor(locale?: LocalesValues, isCookieEnabled = true) {\n const { defaultLocale } = internationalization ?? {};\n\n setIntlayerIdentifier();\n\n this._locale =\n (locale as LocalesValues) ?? (defaultLocale as LocalesValues);\n this.isCookieEnabled = isCookieEnabled;\n }\n\n get locale(): LocalesValues {\n return this._locale;\n }\n\n setLocale(newLocale: LocalesValues): void {\n this._locale = newLocale;\n for (const listener of this._listeners) {\n listener(newLocale);\n }\n }\n\n subscribe(listener: LocaleListener): () => void {\n this._listeners.add(listener);\n return () => {\n this._listeners.delete(listener);\n };\n }\n\n /**\n * Fire all listeners with the current locale without changing it.\n * Used to trigger re-renders after async data loads.\n */\n notify(): void {\n for (const listener of this._listeners) {\n listener(this._locale);\n }\n }\n}\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerClient | null = null;\n\n/**\n * Create and return a single IntlayerClient instance.\n */\nexport const createIntlayerClient = (\n locale?: LocalesValues,\n isCookieEnabled = true\n): IntlayerClient => {\n if (instance) return instance;\n\n instance = new IntlayerClient(locale, isCookieEnabled);\n return instance;\n};\n\n/**\n * Get the current IntlayerClient instance, creating one with defaults if needed.\n */\nexport const getIntlayerClient = (): IntlayerClient => {\n if (!instance) {\n instance = new IntlayerClient();\n }\n return instance;\n};\n\n/**\n * Install Intlayer into your vanilla JS application.\n *\n * Call this once at application startup, before any Intlayer APIs are used.\n *\n * When called with a `config` argument, `window.INTLAYER_CONFIG` is set so\n * that `@intlayer/config/built` resolves the correct values in the browser\n * without requiring module aliasing in the bundler configuration.\n *\n * @param locale - Initial locale (defaults to config defaultLocale).\n * @param isCookieEnabled - Whether to persist locale in cookies/localStorage.\n * @param config - Optional Intlayer configuration. When provided, sets\n * `window.INTLAYER_CONFIG` with the browser-safe subset of the config so\n * the application works without a Vite/webpack plugin alias.\n * @returns The IntlayerClient singleton.\n *\n * @example\n * ```ts\n * import { installIntlayer } from 'vanilla-intlayer';\n *\n * // With explicit config (no build plugin alias needed):\n * installIntlayer('en', true, {\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n *\n * // With build plugin (alias handles config automatically):\n * installIntlayer('en');\n * ```\n */\nexport const installIntlayer = ({\n locale,\n isCookieEnabled,\n}: {\n locale?: LocalesValues;\n isCookieEnabled?: boolean;\n} = {}): IntlayerClient => {\n const client = createIntlayerClient(locale, isCookieEnabled);\n\n useEditor();\n\n return client;\n};\n"],"mappings":";;;;;;;AAOA,IAAa,iBAAb,MAA4B;CAC1B,AAAQ;CACR,AAAQ,6BAAkC,IAAI,KAAK;CACnD;CAEA,YAAY,QAAwB,kBAAkB,MAAM;EAC1D,MAAM,EAAE,kBAAkBA,+CAAwB,EAAE;AAEpD,sDAAuB;AAEvB,OAAK,UACF,UAA6B;AAChC,OAAK,kBAAkB;;CAGzB,IAAI,SAAwB;AAC1B,SAAO,KAAK;;CAGd,UAAU,WAAgC;AACxC,OAAK,UAAU;AACf,OAAK,MAAM,YAAY,KAAK,WAC1B,UAAS,UAAU;;CAIvB,UAAU,UAAsC;AAC9C,OAAK,WAAW,IAAI,SAAS;AAC7B,eAAa;AACX,QAAK,WAAW,OAAO,SAAS;;;;;;;CAQpC,SAAe;AACb,OAAK,MAAM,YAAY,KAAK,WAC1B,UAAS,KAAK,QAAQ;;;;;;AAQ5B,IAAI,WAAkC;;;;AAKtC,MAAa,wBACX,QACA,kBAAkB,SACC;AACnB,KAAI,SAAU,QAAO;AAErB,YAAW,IAAI,eAAe,QAAQ,gBAAgB;AACtD,QAAO;;;;;AAMT,MAAa,0BAA0C;AACrD,KAAI,CAAC,SACH,YAAW,IAAI,gBAAgB;AAEjC,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCT,MAAa,mBAAmB,EAC9B,QACA,oBAIE,EAAE,KAAqB;CACzB,MAAM,SAAS,qBAAqB,QAAQ,gBAAgB;AAE5D,qCAAW;AAEX,QAAO"}
@@ -1 +1,59 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../getDictionary.cjs`),t=require(`../../installIntlayer-_1cC62gP.js`);var n=(n,r)=>{let i=t.r(),a=e.getDictionary(n,r??i.locale);return a.onChange=t=>(i.subscribe(i=>{t(e.getDictionary(n,r??i))}),a),a};exports.useDictionary=n;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_getDictionary = require('../getDictionary.cjs');
3
+ const require_client_installIntlayer = require('./installIntlayer.cjs');
4
+
5
+ //#region src/client/useDictionary.ts
6
+ /**
7
+ * Get the translated content for a raw dictionary object and optionally
8
+ * subscribe to locale changes via the chainable `.onChange()` method —
9
+ * mirroring the API of `react-intlayer`.
10
+ *
11
+ * Unlike `useIntlayer` (which takes a registered key), this function accepts a
12
+ * dictionary object directly — useful for dictionaries loaded asynchronously
13
+ * or defined inline.
14
+ *
15
+ * The function returns the current content **directly** (same shape as
16
+ * `getDictionary(dict)`), plus the `.onChange()` helper:
17
+ *
18
+ * ```ts
19
+ * // React
20
+ * const content = useDictionary(myDict);
21
+ *
22
+ * // Vanilla — identical surface API, opt-in reactivity via .onChange()
23
+ * const content = useDictionary(myDict);
24
+ * const content = useDictionary(myDict).onChange((c) => render(c));
25
+ * ```
26
+ *
27
+ * @param dictionary - The raw dictionary object.
28
+ * @param locale - Optional locale override.
29
+ * @returns The current translated content with an `.onChange()` method.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import myDict from './myDictionary.content';
34
+ * import { installIntlayer, useDictionary } from 'vanilla-intlayer';
35
+ *
36
+ * installIntlayer();
37
+ *
38
+ * const content = useDictionary(myDict).onChange((c) => {
39
+ * document.querySelector('p').textContent = String(c.greeting);
40
+ * });
41
+ *
42
+ * document.querySelector('p').textContent = String(content.greeting);
43
+ * ```
44
+ */
45
+ const useDictionary = (dictionary, locale) => {
46
+ const client = require_client_installIntlayer.getIntlayerClient();
47
+ const content = require_getDictionary.getDictionary(dictionary, locale ?? client.locale);
48
+ content.onChange = (callback) => {
49
+ client.subscribe((newLocale) => {
50
+ callback(require_getDictionary.getDictionary(dictionary, locale ?? newLocale));
51
+ });
52
+ return content;
53
+ };
54
+ return content;
55
+ };
56
+
57
+ //#endregion
58
+ exports.useDictionary = useDictionary;
59
+ //# sourceMappingURL=useDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionary.cjs","names":["getIntlayerClient","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\n\nexport type WithOnChange<T> = T & {\n /**\n * Subscribe to locale changes. The callback receives the fresh content\n * whenever the active locale changes. Returns the content object itself\n * for convenient one-liner patterns:\n *\n * ```ts\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p')!.textContent = String(c.greeting);\n * });\n * ```\n */\n onChange: (\n callback: <T extends Dictionary, L extends LocalesValues>(\n content: DeepTransformContent<T['content'], L>\n ) => void\n ) => WithOnChange<T>;\n};\n\n/**\n * Get the translated content for a raw dictionary object and optionally\n * subscribe to locale changes via the chainable `.onChange()` method —\n * mirroring the API of `react-intlayer`.\n *\n * Unlike `useIntlayer` (which takes a registered key), this function accepts a\n * dictionary object directly — useful for dictionaries loaded asynchronously\n * or defined inline.\n *\n * The function returns the current content **directly** (same shape as\n * `getDictionary(dict)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useDictionary(myDict);\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useDictionary(myDict);\n * const content = useDictionary(myDict).onChange((c) => render(c));\n * ```\n *\n * @param dictionary - The raw dictionary object.\n * @param locale - Optional locale override.\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import myDict from './myDictionary.content';\n * import { installIntlayer, useDictionary } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p').textContent = String(c.greeting);\n * });\n *\n * document.querySelector('p').textContent = String(content.greeting);\n * ```\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const content = getDictionary(\n dictionary,\n (locale ?? client.locale) as L\n ) as WithOnChange<DeepTransformContent<T['content'], L>>;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n client.subscribe((newLocale) => {\n callback(getDictionary(dictionary, (locale ?? newLocale) as L));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,iBAIX,YACA,WACwD;CACxD,MAAM,SAASA,kDAAmB;CAClC,MAAM,UAAUC,oCACd,YACC,UAAU,OAAO,OACnB;AAED,SAAQ,YACN,aACG;AACH,SAAO,WAAW,cAAc;AAC9B,YAASA,oCAAc,YAAa,UAAU,UAAgB,CAAC;IAC/D;AACF,SAAO;;AAGT,QAAO"}
@@ -1 +1,93 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../../plugins-Cv8sSUPw.js`);const e=require(`../getDictionary.cjs`),t=require(`../../installIntlayer-_1cC62gP.js`);let n=require(`@intlayer/config/built`);var r=new Map,i=new Map,a=(e,t)=>{if(r.has(e))return Promise.resolve();if(i.has(e))return i.get(e);let n=t().then(t=>{r.set(e,t),i.delete(e)});return i.set(e,n),n},o=(i,o,s)=>{let c=t.r(),l=s??c.locale??n.internationalization.defaultLocale,u=`${String(o)}.${l}`,d=i[l],f=r.get(u);if(f){let t=e.getDictionary(f,l);return t.onChange=n=>(c.subscribe(t=>{let s=`${String(o)}.${t}`,c=i[t];c&&a(s,c).then(()=>{let i=r.get(s);i&&n(e.getDictionary(i,t))})}),t),t}d&&a(u,d).then(()=>{c.notify()});let p=new Proxy(()=>{},{get:(e,t)=>{if(t===Symbol.toPrimitive||t===`toString`||t===`valueOf`)return()=>``;if(t!==`then`)return t===`onChange`?e=>p:p},apply:()=>p});return p};exports.useDictionaryDynamic=o;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_getDictionary = require('../getDictionary.cjs');
4
+ const require_client_installIntlayer = require('./installIntlayer.cjs');
5
+ let _intlayer_config_built = require("@intlayer/config/built");
6
+
7
+ //#region src/client/useDictionaryDynamic.ts
8
+ /** Simple in-memory cache shared across all calls in the same page. */
9
+ const cache = /* @__PURE__ */ new Map();
10
+ /** Tracks in-flight loads to avoid duplicate fetches. */
11
+ const inflight = /* @__PURE__ */ new Map();
12
+ const loadDictionary = (cacheKey, loader) => {
13
+ if (cache.has(cacheKey)) return Promise.resolve();
14
+ if (inflight.has(cacheKey)) return inflight.get(cacheKey);
15
+ const promise = loader().then((dictionary) => {
16
+ cache.set(cacheKey, dictionary);
17
+ inflight.delete(cacheKey);
18
+ });
19
+ inflight.set(cacheKey, promise);
20
+ return promise;
21
+ };
22
+ /**
23
+ * Dynamically load and transform a locale-keyed dictionary.
24
+ *
25
+ * Works like `useIntlayer` / `useDictionary` but accepts a locale-keyed map
26
+ * of lazy loaders instead of a pre-imported dictionary. Call it inside your
27
+ * render function — the first call triggers a background fetch and returns
28
+ * placeholder values; when the load completes the client notifies all
29
+ * subscribers (including your render loop) so the render runs again with real
30
+ * content. Subsequent calls for the same locale return immediately from cache.
31
+ *
32
+ * Locale switches follow the same two-phase pattern: placeholder on first
33
+ * render, real content after the locale bundle loads.
34
+ *
35
+ * @param dictionaryLoaders - Locale-keyed map of `() => Promise<Dictionary>`.
36
+ * @param key - Dictionary key (used for cache namespacing).
37
+ * @param locale - Optional locale override.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import dynDic from '../.intlayer/dynamic_dictionary/app.mjs';
42
+ *
43
+ * const render = () => {
44
+ * const content = useDictionaryDynamic(dynDic, 'app');
45
+ * document.querySelector('h1')!.textContent = String(content.title);
46
+ * };
47
+ *
48
+ * render();
49
+ * getIntlayerClient().subscribe(() => render());
50
+ * ```
51
+ */
52
+ const useDictionaryDynamic = (dictionaryLoaders, key, locale) => {
53
+ const client = require_client_installIntlayer.getIntlayerClient();
54
+ const currentLocale = locale ?? client.locale ?? _intlayer_config_built.internationalization.defaultLocale;
55
+ const cacheKey = `${String(key)}.${currentLocale}`;
56
+ const loader = dictionaryLoaders[currentLocale];
57
+ const cached = cache.get(cacheKey);
58
+ if (cached) {
59
+ const content = require_getDictionary.getDictionary(cached, currentLocale);
60
+ content.onChange = (callback) => {
61
+ client.subscribe((newLocale) => {
62
+ const newKey = `${String(key)}.${newLocale}`;
63
+ const newLoader = dictionaryLoaders[newLocale];
64
+ if (!newLoader) return;
65
+ loadDictionary(newKey, newLoader).then(() => {
66
+ const dict = cache.get(newKey);
67
+ if (dict) callback(require_getDictionary.getDictionary(dict, newLocale));
68
+ });
69
+ });
70
+ return content;
71
+ };
72
+ return content;
73
+ }
74
+ if (loader) loadDictionary(cacheKey, loader).then(() => {
75
+ client.notify();
76
+ });
77
+ const recursiveProxy = new Proxy(() => {}, {
78
+ get: (_t, prop) => {
79
+ if (prop === Symbol.toPrimitive) return () => "";
80
+ if (prop === "toString") return () => "";
81
+ if (prop === "valueOf") return () => "";
82
+ if (prop === "then") return void 0;
83
+ if (prop === "onChange") return (_cb) => recursiveProxy;
84
+ return recursiveProxy;
85
+ },
86
+ apply: () => recursiveProxy
87
+ });
88
+ return recursiveProxy;
89
+ };
90
+
91
+ //#endregion
92
+ exports.useDictionaryDynamic = useDictionaryDynamic;
93
+ //# sourceMappingURL=useDictionaryDynamic.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionaryDynamic.cjs","names":["getIntlayerClient","internationalization","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\nimport type { WithOnChange } from './useDictionary';\n\n/** Simple in-memory cache shared across all calls in the same page. */\nconst cache = new Map<string, Dictionary>();\n\n/** Tracks in-flight loads to avoid duplicate fetches. */\nconst inflight = new Map<string, Promise<void>>();\n\nconst loadDictionary = <T extends Dictionary>(\n cacheKey: string,\n loader: () => Promise<T>\n): Promise<void> => {\n if (cache.has(cacheKey)) return Promise.resolve();\n if (inflight.has(cacheKey)) return inflight.get(cacheKey)!;\n\n const promise = loader().then((dictionary) => {\n cache.set(cacheKey, dictionary);\n inflight.delete(cacheKey);\n });\n\n inflight.set(cacheKey, promise);\n return promise;\n};\n\n/**\n * Dynamically load and transform a locale-keyed dictionary.\n *\n * Works like `useIntlayer` / `useDictionary` but accepts a locale-keyed map\n * of lazy loaders instead of a pre-imported dictionary. Call it inside your\n * render function — the first call triggers a background fetch and returns\n * placeholder values; when the load completes the client notifies all\n * subscribers (including your render loop) so the render runs again with real\n * content. Subsequent calls for the same locale return immediately from cache.\n *\n * Locale switches follow the same two-phase pattern: placeholder on first\n * render, real content after the locale bundle loads.\n *\n * @param dictionaryLoaders - Locale-keyed map of `() => Promise<Dictionary>`.\n * @param key - Dictionary key (used for cache namespacing).\n * @param locale - Optional locale override.\n *\n * @example\n * ```ts\n * import dynDic from '../.intlayer/dynamic_dictionary/app.mjs';\n *\n * const render = () => {\n * const content = useDictionaryDynamic(dynDic, 'app');\n * document.querySelector('h1')!.textContent = String(content.title);\n * };\n *\n * render();\n * getIntlayerClient().subscribe(() => render());\n * ```\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n L extends LocalesValues = LocalesValues,\n>(\n dictionaryLoaders: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const currentLocale = (locale ??\n client.locale ??\n internationalization.defaultLocale) as L;\n\n const cacheKey = `${String(key)}.${currentLocale}`;\n const loader = (dictionaryLoaders as Record<string, () => Promise<T>>)[\n currentLocale\n ];\n\n // --- Cache hit: return real content synchronously ---\n const cached = cache.get(cacheKey);\n if (cached) {\n const content = getDictionary(cached as T, currentLocale) as WithOnChange<\n DeepTransformContent<T['content'], L>\n >;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n // Re-fire whenever content reloads (locale change → new cache entry).\n client.subscribe((newLocale) => {\n const newKey = `${String(key)}.${newLocale}`;\n const newLoader = (\n dictionaryLoaders as Record<string, () => Promise<T>>\n )[newLocale];\n\n if (!newLoader) return;\n\n loadDictionary(newKey, newLoader).then(() => {\n const dict = cache.get(newKey);\n if (dict) {\n callback(\n getDictionary(dict as T, newLocale as L) as DeepTransformContent<\n T['content'],\n L\n >\n );\n }\n });\n });\n\n return content;\n };\n\n return content;\n }\n\n // --- Cache miss: kick off background load, then notify to re-render ---\n if (loader) {\n loadDictionary(cacheKey, loader).then(() => {\n client.notify();\n });\n }\n\n // Placeholder proxy — safe for any property access while loading.\n const recursiveProxy: any = new Proxy(() => {}, {\n get: (_t, prop) => {\n if (prop === Symbol.toPrimitive) return () => '';\n if (prop === 'toString') return () => '';\n if (prop === 'valueOf') return () => '';\n if (prop === 'then') return undefined; // not a Promise\n if (prop === 'onChange') return (_cb: any) => recursiveProxy;\n return recursiveProxy;\n },\n apply: () => recursiveProxy,\n });\n\n return recursiveProxy as WithOnChange<DeepTransformContent<T['content'], L>>;\n};\n"],"mappings":";;;;;;;;AAaA,MAAM,wBAAQ,IAAI,KAAyB;;AAG3C,MAAM,2BAAW,IAAI,KAA4B;AAEjD,MAAM,kBACJ,UACA,WACkB;AAClB,KAAI,MAAM,IAAI,SAAS,CAAE,QAAO,QAAQ,SAAS;AACjD,KAAI,SAAS,IAAI,SAAS,CAAE,QAAO,SAAS,IAAI,SAAS;CAEzD,MAAM,UAAU,QAAQ,CAAC,MAAM,eAAe;AAC5C,QAAM,IAAI,UAAU,WAAW;AAC/B,WAAS,OAAO,SAAS;GACzB;AAEF,UAAS,IAAI,UAAU,QAAQ;AAC/B,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCT,MAAa,wBAKX,mBACA,KACA,WACwD;CACxD,MAAM,SAASA,kDAAmB;CAClC,MAAM,gBAAiB,UACrB,OAAO,UACPC,4CAAqB;CAEvB,MAAM,WAAW,GAAG,OAAO,IAAI,CAAC,GAAG;CACnC,MAAM,SAAU,kBACd;CAIF,MAAM,SAAS,MAAM,IAAI,SAAS;AAClC,KAAI,QAAQ;EACV,MAAM,UAAUC,oCAAc,QAAa,cAAc;AAIzD,UAAQ,YACN,aACG;AAEH,UAAO,WAAW,cAAc;IAC9B,MAAM,SAAS,GAAG,OAAO,IAAI,CAAC,GAAG;IACjC,MAAM,YACJ,kBACA;AAEF,QAAI,CAAC,UAAW;AAEhB,mBAAe,QAAQ,UAAU,CAAC,WAAW;KAC3C,MAAM,OAAO,MAAM,IAAI,OAAO;AAC9B,SAAI,KACF,UACEA,oCAAc,MAAW,UAAe,CAIzC;MAEH;KACF;AAEF,UAAO;;AAGT,SAAO;;AAIT,KAAI,OACF,gBAAe,UAAU,OAAO,CAAC,WAAW;AAC1C,SAAO,QAAQ;GACf;CAIJ,MAAM,iBAAsB,IAAI,YAAY,IAAI;EAC9C,MAAM,IAAI,SAAS;AACjB,OAAI,SAAS,OAAO,YAAa,cAAa;AAC9C,OAAI,SAAS,WAAY,cAAa;AACtC,OAAI,SAAS,UAAW,cAAa;AACrC,OAAI,SAAS,OAAQ,QAAO;AAC5B,OAAI,SAAS,WAAY,SAAQ,QAAa;AAC9C,UAAO;;EAET,aAAa;EACd,CAAC;AAEF,QAAO"}
@@ -1 +1,65 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../getIntlayer.cjs`),t=require(`../../installIntlayer-_1cC62gP.js`);var n=(n,r)=>{let i=t.r(),a=e.getIntlayer(n,r??i.locale);return a.onChange=t=>(i.subscribe(i=>{t(e.getIntlayer(n,r??i))}),a),a};exports.useIntlayer=n;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_getIntlayer = require('../getIntlayer.cjs');
3
+ const require_client_installIntlayer = require('./installIntlayer.cjs');
4
+
5
+ //#region src/client/useIntlayer.ts
6
+ /**
7
+ * Get the translated content for the given key and optionally subscribe to
8
+ * locale changes via the chainable `.onChange()` method — mirroring the API
9
+ * of `react-intlayer`'s `useIntlayer`.
10
+ *
11
+ * Unlike React (where the hook system automatically re-runs on re-render),
12
+ * vanilla JS has no component lifecycle. The `.onChange()` callback is the
13
+ * explicit equivalent: it is called with fresh content whenever the active
14
+ * locale changes. Use it to patch your DOM or trigger a full re-render.
15
+ *
16
+ * The function returns the current content **directly** (same shape as
17
+ * `getIntlayer(key)`), plus the `.onChange()` helper:
18
+ *
19
+ * ```ts
20
+ * // React
21
+ * const content = useIntlayer('app');
22
+ *
23
+ * // Vanilla — identical surface API, opt-in reactivity via .onChange()
24
+ * const content = useIntlayer('app');
25
+ * const content = useIntlayer('app').onChange((c) => render(c));
26
+ * ```
27
+ *
28
+ * For cleanup (e.g. Vite HMR), subscribe via `getIntlayerClient().subscribe()`
29
+ * and hold the returned unsubscribe function.
30
+ *
31
+ * @param key - Dictionary key registered in your intlayer content files.
32
+ * @param locale - Optional locale override (defaults to the current app locale).
33
+ * @returns The current translated content with an `.onChange()` method.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { installIntlayer, useIntlayer } from 'vanilla-intlayer';
38
+ *
39
+ * installIntlayer();
40
+ *
41
+ * // Static read (no subscription)
42
+ * const content = useIntlayer('homepage');
43
+ * document.querySelector('h1').textContent = String(content.title);
44
+ *
45
+ * // Reactive read — onChange is called on every locale change
46
+ * useIntlayer('homepage').onChange((c) => {
47
+ * document.querySelector('h1').textContent = String(c.title);
48
+ * });
49
+ * ```
50
+ */
51
+ const useIntlayer = (key, locale) => {
52
+ const client = require_client_installIntlayer.getIntlayerClient();
53
+ const content = require_getIntlayer.getIntlayer(key, locale ?? client.locale);
54
+ content.onChange = (callback) => {
55
+ client.subscribe((newLocale) => {
56
+ callback(require_getIntlayer.getIntlayer(key, locale ?? newLocale));
57
+ });
58
+ return content;
59
+ };
60
+ return content;
61
+ };
62
+
63
+ //#endregion
64
+ exports.useIntlayer = useIntlayer;
65
+ //# sourceMappingURL=useIntlayer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntlayer.cjs","names":["getIntlayerClient","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\nimport type { WithOnChange } from './useDictionary';\n\n/**\n * Get the translated content for the given key and optionally subscribe to\n * locale changes via the chainable `.onChange()` method — mirroring the API\n * of `react-intlayer`'s `useIntlayer`.\n *\n * Unlike React (where the hook system automatically re-runs on re-render),\n * vanilla JS has no component lifecycle. The `.onChange()` callback is the\n * explicit equivalent: it is called with fresh content whenever the active\n * locale changes. Use it to patch your DOM or trigger a full re-render.\n *\n * The function returns the current content **directly** (same shape as\n * `getIntlayer(key)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useIntlayer('app');\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useIntlayer('app');\n * const content = useIntlayer('app').onChange((c) => render(c));\n * ```\n *\n * For cleanup (e.g. Vite HMR), subscribe via `getIntlayerClient().subscribe()`\n * and hold the returned unsubscribe function.\n *\n * @param key - Dictionary key registered in your intlayer content files.\n * @param locale - Optional locale override (defaults to the current app locale).\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import { installIntlayer, useIntlayer } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * // Static read (no subscription)\n * const content = useIntlayer('homepage');\n * document.querySelector('h1').textContent = String(content.title);\n *\n * // Reactive read — onChange is called on every locale change\n * useIntlayer('homepage').onChange((c) => {\n * document.querySelector('h1').textContent = String(c.title);\n * });\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): WithOnChange<DeepTransformContent<DictionaryRegistryContent<T>>> => {\n const client = getIntlayerClient();\n const content = getIntlayer(key, locale ?? client.locale) as WithOnChange<\n DeepTransformContent<DictionaryRegistryContent<T>>\n >;\n\n content.onChange = (callback) => {\n client.subscribe((newLocale) => {\n callback(getIntlayer(key, (locale ?? newLocale) as typeof locale));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,eACX,KACA,WACqE;CACrE,MAAM,SAASA,kDAAmB;CAClC,MAAM,UAAUC,gCAAY,KAAK,UAAU,OAAO,OAAO;AAIzD,SAAQ,YAAY,aAAa;AAC/B,SAAO,WAAW,cAAc;AAC9B,YAASA,gCAAY,KAAM,UAAU,UAA4B,CAAC;IAClE;AACF,SAAO;;AAGT,QAAO"}
@@ -1 +1,58 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../../plugins-Cv8sSUPw.js`);const e=require(`../../installIntlayer-_1cC62gP.js`),t=require(`./useLocaleStorage.cjs`);let n=require(`@intlayer/config/built`);var r=(r={})=>{let i=e.r(),{defaultLocale:a,locales:o}=n.internationalization??{};return{locale:i.locale,defaultLocale:a,availableLocales:o??[],setLocale:e=>{if(!(o??[]).map(String).includes(e)){console.error(`Locale "${e}" is not available.`);return}i.setLocale(e),t.setLocaleInStorage(e,r.isCookieEnabled??i.isCookieEnabled??!0),r.onLocaleChange?.(e)},subscribe:e=>i.subscribe(e)}};exports.useLocale=r;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_client_installIntlayer = require('./installIntlayer.cjs');
4
+ const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
5
+ let _intlayer_config_built = require("@intlayer/config/built");
6
+
7
+ //#region src/client/useLocale.ts
8
+ /**
9
+ * Get the current locale state and locale management utilities.
10
+ *
11
+ * Returns a plain object with the current `locale`, `defaultLocale`,
12
+ * `availableLocales`, a `setLocale` function, and a `subscribe` function
13
+ * to react to locale changes.
14
+ *
15
+ * @param props - Optional configuration.
16
+ * @returns Locale state and management utilities.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { installIntlayer, useLocale } from 'vanilla-intlayer';
21
+ *
22
+ * installIntlayer('en');
23
+ *
24
+ * const { locale, availableLocales, setLocale, subscribe } = useLocale();
25
+ *
26
+ * const unsubscribe = subscribe((newLocale) => {
27
+ * console.log('Locale changed to', newLocale);
28
+ * });
29
+ *
30
+ * document.querySelector('#lang-switcher').addEventListener('change', (e) => {
31
+ * setLocale(e.target.value);
32
+ * });
33
+ * ```
34
+ */
35
+ const useLocale = (props = {}) => {
36
+ const client = require_client_installIntlayer.getIntlayerClient();
37
+ const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
38
+ const setLocale = (newLocale) => {
39
+ if (!(availableLocales ?? []).map(String).includes(newLocale)) {
40
+ console.error(`Locale "${newLocale}" is not available.`);
41
+ return;
42
+ }
43
+ client.setLocale(newLocale);
44
+ require_client_useLocaleStorage.setLocaleInStorage(newLocale, props.isCookieEnabled ?? client.isCookieEnabled ?? true);
45
+ props.onLocaleChange?.(newLocale);
46
+ };
47
+ return {
48
+ locale: client.locale,
49
+ defaultLocale,
50
+ availableLocales: availableLocales ?? [],
51
+ setLocale,
52
+ subscribe: (callback) => client.subscribe(callback)
53
+ };
54
+ };
55
+
56
+ //#endregion
57
+ exports.useLocale = useLocale;
58
+ //# sourceMappingURL=useLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.cjs","names":["getIntlayerClient","internationalization"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayerClient } from './installIntlayer';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * Get the current locale state and locale management utilities.\n *\n * Returns a plain object with the current `locale`, `defaultLocale`,\n * `availableLocales`, a `setLocale` function, and a `subscribe` function\n * to react to locale changes.\n *\n * @param props - Optional configuration.\n * @returns Locale state and management utilities.\n *\n * @example\n * ```ts\n * import { installIntlayer, useLocale } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n *\n * const { locale, availableLocales, setLocale, subscribe } = useLocale();\n *\n * const unsubscribe = subscribe((newLocale) => {\n * console.log('Locale changed to', newLocale);\n * });\n *\n * document.querySelector('#lang-switcher').addEventListener('change', (e) => {\n * setLocale(e.target.value);\n * });\n * ```\n */\nexport const useLocale = (\n props: UseLocaleProps = {}\n): {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (newLocale: LocalesValues) => void;\n subscribe: (callback: (locale: LocalesValues) => void) => () => void;\n} => {\n const client = getIntlayerClient();\n const { defaultLocale, locales: availableLocales } =\n internationalization ?? {};\n\n const setLocale = (newLocale: LocalesValues): void => {\n if (!(availableLocales ?? []).map(String).includes(newLocale)) {\n console.error(`Locale \"${newLocale}\" is not available.`);\n return;\n }\n\n client.setLocale(newLocale);\n\n setLocaleInStorage(\n newLocale,\n props.isCookieEnabled ?? client.isCookieEnabled ?? true\n );\n\n props.onLocaleChange?.(newLocale);\n };\n\n return {\n locale: client.locale as DeclaredLocales,\n defaultLocale: defaultLocale as DeclaredLocales,\n availableLocales: (availableLocales ?? []) as DeclaredLocales[],\n setLocale,\n subscribe: (callback) => client.subscribe(callback),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,aACX,QAAwB,EAAE,KAOvB;CACH,MAAM,SAASA,kDAAmB;CAClC,MAAM,EAAE,eAAe,SAAS,qBAC9BC,+CAAwB,EAAE;CAE5B,MAAM,aAAa,cAAmC;AACpD,MAAI,EAAE,oBAAoB,EAAE,EAAE,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AAC7D,WAAQ,MAAM,WAAW,UAAU,qBAAqB;AACxD;;AAGF,SAAO,UAAU,UAAU;AAE3B,qDACE,WACA,MAAM,mBAAmB,OAAO,mBAAmB,KACpD;AAED,QAAM,iBAAiB,UAAU;;AAGnC,QAAO;EACL,QAAQ,OAAO;EACA;EACf,kBAAmB,oBAAoB,EAAE;EACzC;EACA,YAAY,aAAa,OAAO,UAAU,SAAS;EACpD"}
@@ -1 +1,51 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../../plugins-Cv8sSUPw.js`);let e=require(`@intlayer/core/localization`),t=require(`@intlayer/core/utils`);var n=(0,t.getLocaleFromStorageClient)(e.localeStorageOptions),r=n,i=(n,r)=>(0,t.setLocaleInStorageClient)(n,{...e.localeStorageOptions,isCookieEnabled:r}),a=i,o=n=>{let r=(0,t.LocaleStorageClient)({...e.localeStorageOptions,isCookieEnabled:n});return{localeStorage:r.getLocale(),setLocaleStorage:r.setLocale}},s=o;exports.localeCookie=r,exports.localeInStorage=n,exports.setLocaleCookie=a,exports.setLocaleInStorage=i,exports.useLocaleCookie=s,exports.useLocaleStorage=o;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ let _intlayer_core_localization = require("@intlayer/core/localization");
4
+ let _intlayer_core_utils = require("@intlayer/core/utils");
5
+
6
+ //#region src/client/useLocaleStorage.ts
7
+ /**
8
+ * Get the current locale from storage (cookie or localStorage).
9
+ */
10
+ const localeInStorage = (0, _intlayer_core_utils.getLocaleFromStorageClient)(_intlayer_core_localization.localeStorageOptions);
11
+ /**
12
+ * @deprecated Use localeInStorage instead.
13
+ */
14
+ const localeCookie = localeInStorage;
15
+ /**
16
+ * Persist the locale to storage (cookie and/or localStorage).
17
+ */
18
+ const setLocaleInStorage = (locale, isCookieEnabled) => (0, _intlayer_core_utils.setLocaleInStorageClient)(locale, {
19
+ ..._intlayer_core_localization.localeStorageOptions,
20
+ isCookieEnabled
21
+ });
22
+ /**
23
+ * @deprecated Use setLocaleInStorage instead.
24
+ */
25
+ const setLocaleCookie = setLocaleInStorage;
26
+ /**
27
+ * Returns the current locale from storage and a setter.
28
+ */
29
+ const useLocaleStorage = (isCookieEnabled) => {
30
+ const storage = (0, _intlayer_core_utils.LocaleStorageClient)({
31
+ ..._intlayer_core_localization.localeStorageOptions,
32
+ isCookieEnabled
33
+ });
34
+ return {
35
+ localeStorage: storage.getLocale(),
36
+ setLocaleStorage: storage.setLocale
37
+ };
38
+ };
39
+ /**
40
+ * @deprecated Use useLocaleStorage instead.
41
+ */
42
+ const useLocaleCookie = useLocaleStorage;
43
+
44
+ //#endregion
45
+ exports.localeCookie = localeCookie;
46
+ exports.localeInStorage = localeInStorage;
47
+ exports.setLocaleCookie = setLocaleCookie;
48
+ exports.setLocaleInStorage = setLocaleInStorage;
49
+ exports.useLocaleCookie = useLocaleCookie;
50
+ exports.useLocaleStorage = useLocaleStorage;
51
+ //# sourceMappingURL=useLocaleStorage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocaleStorage.cjs","names":["localeStorageOptions"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorageClient,\n LocaleStorageClient,\n setLocaleInStorageClient as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Get the current locale from storage (cookie or localStorage).\n */\nexport const localeInStorage = getLocaleFromStorageClient(localeStorageOptions);\n\n/**\n * @deprecated Use localeInStorage instead.\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Persist the locale to storage (cookie and/or localStorage).\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead.\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Returns the current locale from storage and a setter.\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) => {\n const storage = LocaleStorageClient({\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n return {\n localeStorage: storage.getLocale(),\n setLocaleStorage: storage.setLocale,\n };\n};\n\n/**\n * @deprecated Use useLocaleStorage instead.\n */\nexport const useLocaleCookie = useLocaleStorage;\n"],"mappings":";;;;;;;;;AAWA,MAAa,uEAA6CA,iDAAqB;;;;AAK/E,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,uEAEuB,QAAQ;CAC7B,GAAGA;CACH;CACD,CAAC;;;;AAKJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,oBAA8B;CAC7D,MAAM,wDAA8B;EAClC,GAAGA;EACH;EACD,CAAC;AAEF,QAAO;EACL,eAAe,QAAQ,WAAW;EAClC,kBAAkB,QAAQ;EAC3B;;;;;AAMH,MAAa,kBAAkB"}
@@ -1 +1,46 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../../plugins-Cv8sSUPw.js`);const e=require(`../../installIntlayer-_1cC62gP.js`);let t=require(`@intlayer/config/built`),n=require(`@intlayer/core/localization`);var r=e=>{if(typeof window>`u`||!t.routing?.rewrite)return;let r=window.location.pathname,i=(0,n.getRewritePath)(r,e,t.routing?.rewrite);i&&i!==r&&window.history.replaceState(window.history.state,``,i+window.location.search+window.location.hash)},i=()=>{let t=e.r();return r(t.locale),t.subscribe(e=>{r(e)})};exports.useRewriteURL=i;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_client_installIntlayer = require('./installIntlayer.cjs');
4
+ let _intlayer_config_built = require("@intlayer/config/built");
5
+ let _intlayer_core_localization = require("@intlayer/core/localization");
6
+
7
+ //#region src/client/useRewriteURL.ts
8
+ const rewrite = (locale) => {
9
+ if (typeof window === "undefined" || !_intlayer_config_built.routing?.rewrite) return;
10
+ const pathname = window.location.pathname;
11
+ const targetPath = (0, _intlayer_core_localization.getRewritePath)(pathname, locale, _intlayer_config_built.routing?.rewrite);
12
+ if (targetPath && targetPath !== pathname) window.history.replaceState(window.history.state, "", targetPath + window.location.search + window.location.hash);
13
+ };
14
+ /**
15
+ * Keep the browser URL in sync with the current locale.
16
+ *
17
+ * Rewrites the current URL immediately and subscribes to future locale changes.
18
+ * Returns an `unsubscribe` function to stop listening.
19
+ *
20
+ * Uses `window.history.replaceState` — no full-page navigation.
21
+ *
22
+ * @returns A cleanup function that removes the locale change listener.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { installIntlayer, useRewriteURL } from 'vanilla-intlayer';
27
+ *
28
+ * installIntlayer('en');
29
+ *
30
+ * const unsubscribe = useRewriteURL();
31
+ *
32
+ * // Later, if you want to stop URL rewriting:
33
+ * unsubscribe();
34
+ * ```
35
+ */
36
+ const useRewriteURL = () => {
37
+ const client = require_client_installIntlayer.getIntlayerClient();
38
+ rewrite(client.locale);
39
+ return client.subscribe((newLocale) => {
40
+ rewrite(newLocale);
41
+ });
42
+ };
43
+
44
+ //#endregion
45
+ exports.useRewriteURL = useRewriteURL;
46
+ //# sourceMappingURL=useRewriteURL.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRewriteURL.cjs","names":["routing","getIntlayerClient"],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["import { routing } from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getIntlayerClient } from './installIntlayer';\n\nconst rewrite = (locale: string): void => {\n if (typeof window === 'undefined' || !routing?.rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(\n pathname,\n locale as Locale,\n routing?.rewrite\n );\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n};\n\n/**\n * Keep the browser URL in sync with the current locale.\n *\n * Rewrites the current URL immediately and subscribes to future locale changes.\n * Returns an `unsubscribe` function to stop listening.\n *\n * Uses `window.history.replaceState` — no full-page navigation.\n *\n * @returns A cleanup function that removes the locale change listener.\n *\n * @example\n * ```ts\n * import { installIntlayer, useRewriteURL } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n *\n * const unsubscribe = useRewriteURL();\n *\n * // Later, if you want to stop URL rewriting:\n * unsubscribe();\n * ```\n */\nexport const useRewriteURL = (): (() => void) => {\n const client = getIntlayerClient();\n\n // Rewrite immediately for the current locale\n rewrite(client.locale);\n\n return client.subscribe((newLocale) => {\n rewrite(newLocale);\n });\n};\n"],"mappings":";;;;;;;AAKA,MAAM,WAAW,WAAyB;AACxC,KAAI,OAAO,WAAW,eAAe,CAACA,gCAAS,QAAS;CAExD,MAAM,WAAW,OAAO,SAAS;CACjC,MAAM,6DACJ,UACA,QACAA,gCAAS,QACV;AAED,KAAI,cAAc,eAAe,SAC/B,QAAO,QAAQ,aACb,OAAO,QAAQ,OACf,IACA,aAAa,OAAO,SAAS,SAAS,OAAO,SAAS,KACvD;;;;;;;;;;;;;;;;;;;;;;;;AA0BL,MAAa,sBAAoC;CAC/C,MAAM,SAASC,kDAAmB;AAGlC,SAAQ,OAAO,OAAO;AAEtB,QAAO,OAAO,WAAW,cAAc;AACrC,UAAQ,UAAU;GAClB"}