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
@@ -1,2 +1,47 @@
1
- import { a as e } from "../../installIntlayer-C99qMzFH.mjs";
2
- export { e as useEditor };
1
+ import { getIntlayerClient } from "../client/installIntlayer.mjs";
2
+ import { isEnabled } from "@intlayer/editor/isEnabled";
3
+
4
+ //#region src/editor/useEditor.ts
5
+ /**
6
+ * Initialises the Intlayer visual editor client.
7
+ *
8
+ * Does nothing when `INTLAYER_EDITOR_ENABLED` is `"false"` or the editor
9
+ * package reports that it is disabled.
10
+ *
11
+ * Call this once at application startup.
12
+ *
13
+ * @returns A cleanup function that stops the editor.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { installIntlayer, useEditor } from 'vanilla-intlayer';
18
+ *
19
+ * installIntlayer('en');
20
+ * const stopEditor = useEditor();
21
+ * ```
22
+ */
23
+ const useEditor = () => {
24
+ if (process.env["INTLAYER_EDITOR_ENABLED"] === "false" || !isEnabled) return () => {};
25
+ let unsubscribeLocale = null;
26
+ let stopped = false;
27
+ import("@intlayer/editor").then(({ initEditorClient }) => {
28
+ if (stopped) return;
29
+ const manager = initEditorClient();
30
+ const client = getIntlayerClient();
31
+ manager.currentLocale.set(client.locale);
32
+ unsubscribeLocale = client.subscribe((newLocale) => {
33
+ manager.currentLocale.set(newLocale);
34
+ });
35
+ });
36
+ return () => {
37
+ stopped = true;
38
+ unsubscribeLocale?.();
39
+ import("@intlayer/editor").then(({ stopEditorClient }) => {
40
+ stopEditorClient();
41
+ });
42
+ };
43
+ };
44
+
45
+ //#endregion
46
+ export { useEditor };
47
+ //# sourceMappingURL=useEditor.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEditor.mjs","names":[],"sources":["../../../src/editor/useEditor.ts"],"sourcesContent":["import type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getIntlayerClient } from '../client/installIntlayer';\n\n/**\n * Initialises the Intlayer visual editor client.\n *\n * Does nothing when `INTLAYER_EDITOR_ENABLED` is `\"false\"` or the editor\n * package reports that it is disabled.\n *\n * Call this once at application startup.\n *\n * @returns A cleanup function that stops the editor.\n *\n * @example\n * ```ts\n * import { installIntlayer, useEditor } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n * const stopEditor = useEditor();\n * ```\n */\n\nexport const useEditor = (): (() => void) => {\n if (process.env['INTLAYER_EDITOR_ENABLED'] === 'false' || !isEnabled)\n return () => {};\n\n let unsubscribeLocale: (() => void) | null = null;\n let stopped = false;\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n if (stopped) return;\n const manager: EditorStateManager = initEditorClient();\n const client = getIntlayerClient();\n\n manager.currentLocale.set(client.locale as Locale);\n\n unsubscribeLocale = client.subscribe((newLocale) => {\n manager.currentLocale.set(newLocale as Locale);\n });\n });\n\n return () => {\n stopped = true;\n unsubscribeLocale?.();\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,kBAAgC;AAC3C,KAAI,QAAQ,IAAI,+BAA+B,WAAW,CAAC,UACzD,cAAa;CAEf,IAAI,oBAAyC;CAC7C,IAAI,UAAU;AAEd,QAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,MAAI,QAAS;EACb,MAAM,UAA8B,kBAAkB;EACtD,MAAM,SAAS,mBAAmB;AAElC,UAAQ,cAAc,IAAI,OAAO,OAAiB;AAElD,sBAAoB,OAAO,WAAW,cAAc;AAClD,WAAQ,cAAc,IAAI,UAAoB;IAC9C;GACF;AAEF,cAAa;AACX,YAAU;AACV,uBAAqB;AACrB,SAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,qBAAkB;IAClB"}
@@ -1,10 +1,11 @@
1
- import { useUnit as e } from "./useUnit.mjs";
2
- import { useDate as t } from "./useDate.mjs";
3
- import { useNumber as n } from "./useNumber.mjs";
4
- import { useRelativeTime as r } from "./useRelativeTime.mjs";
5
- import { useCompact as i } from "./useCompact.mjs";
6
- import { useIntl as a } from "./useIntl.mjs";
7
- import { useList as o } from "./useList.mjs";
8
- import { usePercentage as s } from "./usePercentage.mjs";
9
- import { useCurrency as c } from "./useCurrency.mjs";
10
- export { i as useCompact, c as useCurrency, t as useDate, a as useIntl, o as useList, n as useNumber, s as usePercentage, r as useRelativeTime, e as useUnit };
1
+ import { useUnit } from "./useUnit.mjs";
2
+ import { useDate } from "./useDate.mjs";
3
+ import { useNumber } from "./useNumber.mjs";
4
+ import { useRelativeTime } from "./useRelativeTime.mjs";
5
+ import { useCompact } from "./useCompact.mjs";
6
+ import { useIntl } from "./useIntl.mjs";
7
+ import { useList } from "./useList.mjs";
8
+ import { usePercentage } from "./usePercentage.mjs";
9
+ import { useCurrency } from "./useCurrency.mjs";
10
+
11
+ export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
@@ -1,12 +1,15 @@
1
- import { r as e } from "../../installIntlayer-C99qMzFH.mjs";
2
- import { compact as t } from "@intlayer/core/formatters";
1
+ import { getIntlayerClient } from "../client/installIntlayer.mjs";
2
+ import { compact } from "@intlayer/core/formatters";
3
+
3
4
  //#region src/format/useCompact.ts
4
- var n = () => {
5
- let n = e();
6
- return (...e) => t(e[0], {
7
- ...e[1],
8
- locale: e[1]?.locale ?? n.locale
5
+ const useCompact = () => {
6
+ const client = getIntlayerClient();
7
+ return (...args) => compact(args[0], {
8
+ ...args[1],
9
+ locale: args[1]?.locale ?? client.locale
9
10
  });
10
11
  };
12
+
11
13
  //#endregion
12
- export { n as useCompact };
14
+ export { useCompact };
15
+ //# sourceMappingURL=useCompact.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCompact.mjs","names":[],"sources":["../../../src/format/useCompact.ts"],"sourcesContent":["import { compact } from '@intlayer/core/formatters';\nimport { getIntlayerClient } from '../client/installIntlayer';\n\nexport const useCompact = () => {\n const client = getIntlayerClient();\n\n return (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? client.locale,\n });\n};\n"],"mappings":";;;;AAGA,MAAa,mBAAmB;CAC9B,MAAM,SAAS,mBAAmB;AAElC,SAAQ,GAAG,SACT,QAAQ,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
@@ -1,12 +1,15 @@
1
- import { r as e } from "../../installIntlayer-C99qMzFH.mjs";
2
- import { currency as t } from "@intlayer/core/formatters";
1
+ import { getIntlayerClient } from "../client/installIntlayer.mjs";
2
+ import { currency } from "@intlayer/core/formatters";
3
+
3
4
  //#region src/format/useCurrency.ts
4
- var n = () => {
5
- let n = e();
6
- return (...e) => t(e[0], {
7
- ...e[1],
8
- locale: e[1]?.locale ?? n.locale
5
+ const useCurrency = () => {
6
+ const client = getIntlayerClient();
7
+ return (...args) => currency(args[0], {
8
+ ...args[1],
9
+ locale: args[1]?.locale ?? client.locale
9
10
  });
10
11
  };
12
+
11
13
  //#endregion
12
- export { n as useCurrency };
14
+ export { useCurrency };
15
+ //# sourceMappingURL=useCurrency.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCurrency.mjs","names":[],"sources":["../../../src/format/useCurrency.ts"],"sourcesContent":["import { currency } from '@intlayer/core/formatters';\nimport { getIntlayerClient } from '../client/installIntlayer';\n\nexport const useCurrency = () => {\n const client = getIntlayerClient();\n\n return (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? client.locale,\n });\n};\n"],"mappings":";;;;AAGA,MAAa,oBAAoB;CAC/B,MAAM,SAAS,mBAAmB;AAElC,SAAQ,GAAG,SACT,SAAS,KAAK,IAAI;EAChB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
@@ -1,18 +1,24 @@
1
- import { r as e } from "../../installIntlayer-C99qMzFH.mjs";
2
- import { date as t, presets as n } from "@intlayer/core/formatters";
1
+ import { getIntlayerClient } from "../client/installIntlayer.mjs";
2
+ import { date, presets } from "@intlayer/core/formatters";
3
+
3
4
  //#region src/format/useDate.ts
4
- var r = () => {
5
- let r = e();
6
- return (...e) => {
7
- let i = typeof e[1] == "string" ? {
8
- ...n[e[1]],
9
- locale: r.locale
5
+ /**
6
+ * Vanilla JS hook that provides a localized date/time formatter.
7
+ */
8
+ const useDate = () => {
9
+ const client = getIntlayerClient();
10
+ return (...args) => {
11
+ const options = typeof args[1] === "string" ? {
12
+ ...presets[args[1]],
13
+ locale: client.locale
10
14
  } : {
11
- ...e[1],
12
- locale: e[1]?.locale ?? r.locale
15
+ ...args[1],
16
+ locale: args[1]?.locale ?? client.locale
13
17
  };
14
- return t(e[0], i);
18
+ return date(args[0], options);
15
19
  };
16
20
  };
21
+
17
22
  //#endregion
18
- export { r as useDate };
23
+ export { useDate };
24
+ //# sourceMappingURL=useDate.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDate.mjs","names":[],"sources":["../../../src/format/useDate.ts"],"sourcesContent":["import { date, presets } from '@intlayer/core/formatters';\nimport { getIntlayerClient } from '../client/installIntlayer';\n\n/**\n * Vanilla JS hook that provides a localized date/time formatter.\n */\nexport const useDate = () => {\n const client = getIntlayerClient();\n\n return (...args: Parameters<typeof date>) => {\n const options =\n typeof args[1] === 'string'\n ? { ...presets[args[1]], locale: client.locale }\n : { ...args[1], locale: args[1]?.locale ?? client.locale };\n\n return date(args[0], options as Parameters<typeof date>[1]);\n };\n};\n"],"mappings":";;;;;;;AAMA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,mBAAmB;AAElC,SAAQ,GAAG,SAAkC;EAC3C,MAAM,UACJ,OAAO,KAAK,OAAO,WACf;GAAE,GAAG,QAAQ,KAAK;GAAK,QAAQ,OAAO;GAAQ,GAC9C;GAAE,GAAG,KAAK;GAAI,QAAQ,KAAK,IAAI,UAAU,OAAO;GAAQ;AAE9D,SAAO,KAAK,KAAK,IAAI,QAAsC"}
@@ -1,14 +1,42 @@
1
- import { r as e } from "../../installIntlayer-C99qMzFH.mjs";
2
- import { bindIntl as t } from "@intlayer/core/utils";
1
+ import { getIntlayerClient } from "../client/installIntlayer.mjs";
2
+ import { bindIntl } from "@intlayer/core/utils";
3
+
3
4
  //#region src/format/useIntl.ts
4
- var n = (n) => {
5
- let r = e();
5
+ /**
6
+ * Get a locale-bound `Intl` object and subscribe to locale changes.
7
+ *
8
+ * The returned `intl` property acts like the native `Intl` namespace but
9
+ * automatically uses the current application locale, so you do not need to
10
+ * pass the locale manually to `NumberFormat`, `DateTimeFormat`, etc.
11
+ *
12
+ * @param locale - Optional locale override.
13
+ * @returns An object with `intl: WrappedIntl` and a `subscribe` function.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { installIntlayer, useIntl } from 'vanilla-intlayer';
18
+ *
19
+ * installIntlayer('en');
20
+ *
21
+ * const { intl, subscribe } = useIntl();
22
+ *
23
+ * console.log(new intl.NumberFormat({ style: 'currency', currency: 'USD' }).format(9.99));
24
+ *
25
+ * const unsubscribe = subscribe((newIntl) => {
26
+ * console.log(new newIntl.NumberFormat({ style: 'currency', currency: 'USD' }).format(9.99));
27
+ * });
28
+ * ```
29
+ */
30
+ const useIntl = (locale) => {
31
+ const client = getIntlayerClient();
6
32
  return {
7
- intl: t(n ?? r.locale),
8
- subscribe: (e) => r.subscribe((r) => {
9
- e(t(n ?? r));
33
+ intl: bindIntl(locale ?? client.locale),
34
+ subscribe: (callback) => client.subscribe((newLocale) => {
35
+ callback(bindIntl(locale ?? newLocale));
10
36
  })
11
37
  };
12
38
  };
39
+
13
40
  //#endregion
14
- export { n as useIntl };
41
+ export { useIntl };
42
+ //# sourceMappingURL=useIntl.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../src/format/useIntl.ts"],"sourcesContent":["import { bindIntl, type WrappedIntl } from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getIntlayerClient } from '../client/installIntlayer';\n\n/**\n * Get a locale-bound `Intl` object and subscribe to locale changes.\n *\n * The returned `intl` property acts like the native `Intl` namespace but\n * automatically uses the current application locale, so you do not need to\n * pass the locale manually to `NumberFormat`, `DateTimeFormat`, etc.\n *\n * @param locale - Optional locale override.\n * @returns An object with `intl: WrappedIntl` and a `subscribe` function.\n *\n * @example\n * ```ts\n * import { installIntlayer, useIntl } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n *\n * const { intl, subscribe } = useIntl();\n *\n * console.log(new intl.NumberFormat({ style: 'currency', currency: 'USD' }).format(9.99));\n *\n * const unsubscribe = subscribe((newIntl) => {\n * console.log(new newIntl.NumberFormat({ style: 'currency', currency: 'USD' }).format(9.99));\n * });\n * ```\n */\nexport const useIntl = (\n locale?: LocalesValues\n): {\n intl: WrappedIntl;\n subscribe: (callback: (intl: WrappedIntl) => void) => () => void;\n} => {\n const client = getIntlayerClient();\n const intl = bindIntl(locale ?? client.locale);\n\n return {\n intl,\n subscribe: (callback) =>\n client.subscribe((newLocale) => {\n callback(bindIntl(locale ?? newLocale));\n }),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,WACX,WAIG;CACH,MAAM,SAAS,mBAAmB;AAGlC,QAAO;EACL,MAHW,SAAS,UAAU,OAAO,OAGjC;EACJ,YAAY,aACV,OAAO,WAAW,cAAc;AAC9B,YAAS,SAAS,UAAU,UAAU,CAAC;IACvC;EACL"}
@@ -1,12 +1,15 @@
1
- import { r as e } from "../../installIntlayer-C99qMzFH.mjs";
2
- import { list as t } from "@intlayer/core/formatters";
1
+ import { getIntlayerClient } from "../client/installIntlayer.mjs";
2
+ import { list } from "@intlayer/core/formatters";
3
+
3
4
  //#region src/format/useList.ts
4
- var n = () => {
5
- let n = e();
6
- return (...e) => t(e[0], {
7
- ...e[1],
8
- locale: e[1]?.locale ?? n.locale
5
+ const useList = () => {
6
+ const client = getIntlayerClient();
7
+ return (...args) => list(args[0], {
8
+ ...args[1],
9
+ locale: args[1]?.locale ?? client.locale
9
10
  });
10
11
  };
12
+
11
13
  //#endregion
12
- export { n as useList };
14
+ export { useList };
15
+ //# sourceMappingURL=useList.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useList.mjs","names":[],"sources":["../../../src/format/useList.ts"],"sourcesContent":["import { list } from '@intlayer/core/formatters';\nimport { getIntlayerClient } from '../client/installIntlayer';\n\nexport const useList = () => {\n const client = getIntlayerClient();\n\n return (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? client.locale,\n });\n};\n"],"mappings":";;;;AAGA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,mBAAmB;AAElC,SAAQ,GAAG,SACT,KAAK,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
@@ -1,12 +1,18 @@
1
- import { r as e } from "../../installIntlayer-C99qMzFH.mjs";
2
- import { number as t } from "@intlayer/core/formatters";
1
+ import { getIntlayerClient } from "../client/installIntlayer.mjs";
2
+ import { number } from "@intlayer/core/formatters";
3
+
3
4
  //#region src/format/useNumber.ts
4
- var n = () => {
5
- let n = e();
6
- return (...e) => t(e[0], {
7
- ...e[1],
8
- locale: e[1]?.locale ?? n.locale
5
+ /**
6
+ * Vanilla JS hook that provides a localized number formatter.
7
+ */
8
+ const useNumber = () => {
9
+ const client = getIntlayerClient();
10
+ return (...args) => number(args[0], {
11
+ ...args[1],
12
+ locale: args[1]?.locale ?? client.locale
9
13
  });
10
14
  };
15
+
11
16
  //#endregion
12
- export { n as useNumber };
17
+ export { useNumber };
18
+ //# sourceMappingURL=useNumber.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNumber.mjs","names":[],"sources":["../../../src/format/useNumber.ts"],"sourcesContent":["import { number } from '@intlayer/core/formatters';\nimport { getIntlayerClient } from '../client/installIntlayer';\n\n/**\n * Vanilla JS hook that provides a localized number formatter.\n */\nexport const useNumber = () => {\n const client = getIntlayerClient();\n\n return (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? client.locale,\n });\n};\n"],"mappings":";;;;;;;AAMA,MAAa,kBAAkB;CAC7B,MAAM,SAAS,mBAAmB;AAElC,SAAQ,GAAG,SACT,OAAO,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
@@ -1,12 +1,15 @@
1
- import { r as e } from "../../installIntlayer-C99qMzFH.mjs";
2
- import { percentage as t } from "@intlayer/core/formatters";
1
+ import { getIntlayerClient } from "../client/installIntlayer.mjs";
2
+ import { percentage } from "@intlayer/core/formatters";
3
+
3
4
  //#region src/format/usePercentage.ts
4
- var n = () => {
5
- let n = e();
6
- return (...e) => t(e[0], {
7
- ...e[1],
8
- locale: e[1]?.locale ?? n.locale
5
+ const usePercentage = () => {
6
+ const client = getIntlayerClient();
7
+ return (...args) => percentage(args[0], {
8
+ ...args[1],
9
+ locale: args[1]?.locale ?? client.locale
9
10
  });
10
11
  };
12
+
11
13
  //#endregion
12
- export { n as usePercentage };
14
+ export { usePercentage };
15
+ //# sourceMappingURL=usePercentage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../src/format/usePercentage.ts"],"sourcesContent":["import { percentage } from '@intlayer/core/formatters';\nimport { getIntlayerClient } from '../client/installIntlayer';\n\nexport const usePercentage = () => {\n const client = getIntlayerClient();\n\n return (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? client.locale,\n });\n};\n"],"mappings":";;;;AAGA,MAAa,sBAAsB;CACjC,MAAM,SAAS,mBAAmB;AAElC,SAAQ,GAAG,SACT,WAAW,KAAK,IAAI;EAClB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
@@ -1,12 +1,15 @@
1
- import { r as e } from "../../installIntlayer-C99qMzFH.mjs";
2
- import { relativeTime as t } from "@intlayer/core/formatters";
1
+ import { getIntlayerClient } from "../client/installIntlayer.mjs";
2
+ import { relativeTime } from "@intlayer/core/formatters";
3
+
3
4
  //#region src/format/useRelativeTime.ts
4
- var n = () => {
5
- let n = e();
6
- return (...e) => t(e[0], e[1], {
7
- ...e[2],
8
- locale: e[2]?.locale ?? n.locale
5
+ const useRelativeTime = () => {
6
+ const client = getIntlayerClient();
7
+ return (...args) => relativeTime(args[0], args[1], {
8
+ ...args[2],
9
+ locale: args[2]?.locale ?? client.locale
9
10
  });
10
11
  };
12
+
11
13
  //#endregion
12
- export { n as useRelativeTime };
14
+ export { useRelativeTime };
15
+ //# sourceMappingURL=useRelativeTime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../src/format/useRelativeTime.ts"],"sourcesContent":["import { relativeTime } from '@intlayer/core/formatters';\nimport { getIntlayerClient } from '../client/installIntlayer';\n\nexport const useRelativeTime = () => {\n const client = getIntlayerClient();\n\n return (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? client.locale,\n });\n};\n"],"mappings":";;;;AAGA,MAAa,wBAAwB;CACnC,MAAM,SAAS,mBAAmB;AAElC,SAAQ,GAAG,SACT,aAAa,KAAK,IAAI,KAAK,IAAI;EAC7B,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
@@ -1,12 +1,15 @@
1
- import { r as e } from "../../installIntlayer-C99qMzFH.mjs";
2
- import { units as t } from "@intlayer/core/formatters";
1
+ import { getIntlayerClient } from "../client/installIntlayer.mjs";
2
+ import { units } from "@intlayer/core/formatters";
3
+
3
4
  //#region src/format/useUnit.ts
4
- var n = () => {
5
- let n = e();
6
- return (...e) => t(e[0], {
7
- ...e[1],
8
- locale: e[1]?.locale ?? n.locale
5
+ const useUnit = () => {
6
+ const client = getIntlayerClient();
7
+ return (...args) => units(args[0], {
8
+ ...args[1],
9
+ locale: args[1]?.locale ?? client.locale
9
10
  });
10
11
  };
12
+
11
13
  //#endregion
12
- export { n as useUnit };
14
+ export { useUnit };
15
+ //# sourceMappingURL=useUnit.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../src/format/useUnit.ts"],"sourcesContent":["import { units } from '@intlayer/core/formatters';\nimport { getIntlayerClient } from '../client/installIntlayer';\n\nexport const useUnit = () => {\n const client = getIntlayerClient();\n\n return (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? client.locale,\n });\n};\n"],"mappings":";;;;AAGA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,mBAAmB;AAElC,SAAQ,GAAG,SACT,MAAM,KAAK,IAAI;EACb,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
@@ -1,6 +1,9 @@
1
- import { getPlugins as e } from "./plugins.mjs";
2
- import { getDictionary as t } from "@intlayer/core/interpreter";
1
+ import { getPlugins } from "./plugins.mjs";
2
+ import { getDictionary as getDictionary$1 } from "@intlayer/core/interpreter";
3
+
3
4
  //#region src/getDictionary.ts
4
- var n = (n, r) => t(n, r, e(r));
5
+ const getDictionary = (dictionary, locale) => getDictionary$1(dictionary, locale, getPlugins(locale));
6
+
5
7
  //#endregion
6
- export { n as getDictionary };
8
+ export { getDictionary };
9
+ //# sourceMappingURL=getDictionary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDictionary.mjs","names":["getDictionaryCore"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): DeepTransformContent<T['content'], L> =>\n getDictionaryCore(dictionary, locale, getPlugins(locale)) as any;\n"],"mappings":";;;;AAQA,MAAa,iBAIX,YACA,WAEAA,gBAAkB,YAAY,QAAQ,WAAW,OAAO,CAAC"}
@@ -1,6 +1,9 @@
1
- import { getPlugins as e } from "./plugins.mjs";
2
- import { getIntlayer as t } from "@intlayer/core/interpreter";
1
+ import { getPlugins } from "./plugins.mjs";
2
+ import { getIntlayer as getIntlayer$1 } from "@intlayer/core/interpreter";
3
+
3
4
  //#region src/getIntlayer.ts
4
- var n = (n, r) => t(n, r, e(r));
5
+ const getIntlayer = (key, locale) => getIntlayer$1(key, locale, getPlugins(locale));
6
+
5
7
  //#endregion
6
- export { n as getIntlayer };
8
+ export { getIntlayer };
9
+ //# sourceMappingURL=getIntlayer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getIntlayer.mjs","names":["getIntlayerCore"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n): DeepTransformContent<DictionaryRegistryContent<T>, L> =>\n getIntlayerCore(key, locale, getPlugins(locale)) as any;\n"],"mappings":";;;;AASA,MAAa,eAIX,KACA,WAEAA,cAAgB,KAAK,QAAQ,WAAW,OAAO,CAAC"}
@@ -1,8 +1,20 @@
1
- import { useHTML as e } from "./installIntlayerHTML.mjs";
1
+ import { useHTML } from "./installIntlayerHTML.mjs";
2
+
2
3
  //#region src/html/HTMLRenderer.ts
3
- var t = (e, t = {}) => e, n = ({ components: t } = {}) => {
4
- let n = e();
5
- return (e) => n.renderHTML(e, { components: t });
4
+ /**
5
+ * Renders an HTML string directly, without a global provider.
6
+ * Returns the raw string unchanged.
7
+ */
8
+ const renderHTML = (content, _props = {}) => content;
9
+ /**
10
+ * Returns a render function that uses the global provider's configuration
11
+ * (installed via `installIntlayerHTML`), falling back to identity.
12
+ */
13
+ const useHTMLRenderer = ({ components } = {}) => {
14
+ const context = useHTML();
15
+ return (content) => context.renderHTML(content, { components });
6
16
  };
17
+
7
18
  //#endregion
8
- export { t as renderHTML, n as useHTMLRenderer };
19
+ export { renderHTML, useHTMLRenderer };
20
+ //# sourceMappingURL=HTMLRenderer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HTMLRenderer.mjs","names":[],"sources":["../../../src/html/HTMLRenderer.ts"],"sourcesContent":["import { type RenderHTMLOptions, useHTML } from './installIntlayerHTML';\nimport type { HTMLComponents } from './types';\n\nexport type RenderHTMLProps = {\n components?: HTMLComponents<'permissive', {}>;\n};\n\n/**\n * Renders an HTML string directly, without a global provider.\n * Returns the raw string unchanged.\n */\nexport const renderHTML = (\n content: string,\n _props: RenderHTMLProps = {}\n): string => content;\n\n/**\n * Returns a render function that uses the global provider's configuration\n * (installed via `installIntlayerHTML`), falling back to identity.\n */\nexport const useHTMLRenderer = ({\n components,\n}: RenderHTMLProps = {}): ((content: string) => string) => {\n const context = useHTML();\n\n return (content: string) =>\n context.renderHTML(content, { components } as RenderHTMLOptions);\n};\n"],"mappings":";;;;;;;AAWA,MAAa,cACX,SACA,SAA0B,EAAE,KACjB;;;;;AAMb,MAAa,mBAAmB,EAC9B,eACmB,EAAE,KAAoC;CACzD,MAAM,UAAU,SAAS;AAEzB,SAAQ,YACN,QAAQ,WAAW,SAAS,EAAE,YAAY,CAAsB"}
@@ -1,3 +1,4 @@
1
- import { installIntlayerHTML as e, installIntlayerHTMLDynamic as t, useHTML as n } from "./installIntlayerHTML.mjs";
2
- import { renderHTML as r, useHTMLRenderer as i } from "./HTMLRenderer.mjs";
3
- export { e as installIntlayerHTML, t as installIntlayerHTMLDynamic, r as renderHTML, n as useHTML, i as useHTMLRenderer };
1
+ import { installIntlayerHTML, installIntlayerHTMLDynamic, useHTML } from "./installIntlayerHTML.mjs";
2
+ import { renderHTML, useHTMLRenderer } from "./HTMLRenderer.mjs";
3
+
4
+ export { installIntlayerHTML, installIntlayerHTMLDynamic, renderHTML, useHTML, useHTMLRenderer };
@@ -1,18 +1,86 @@
1
1
  //#region src/html/installIntlayerHTML.ts
2
- var e = null, t = (t) => e || (e = { renderHTML: t }, e), n = (e) => {
3
- let n;
4
- if (typeof e == "function") n = e;
2
+ /**
3
+ * Singleton instance
4
+ */
5
+ let instance = null;
6
+ /**
7
+ * Create and return a single IntlayerHTMLProvider instance.
8
+ */
9
+ const createIntlayerHTMLClient = (renderHTML) => {
10
+ if (instance) return instance;
11
+ instance = { renderHTML };
12
+ return instance;
13
+ };
14
+ /**
15
+ * Install the Intlayer HTML provider for your vanilla JS application.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { installIntlayerHTML } from 'vanilla-intlayer';
20
+ *
21
+ * installIntlayerHTML({
22
+ * components: {
23
+ * a: ({ href, children }) => `<a class="styled-link" href="${href}">${children}</a>`,
24
+ * },
25
+ * });
26
+ * ```
27
+ */
28
+ const installIntlayerHTML = (pluginOptions) => {
29
+ let renderHTML;
30
+ if (typeof pluginOptions === "function") renderHTML = pluginOptions;
5
31
  else {
6
- let { components: t, renderHTML: r } = e ?? {};
7
- n = r || ((e, n) => {
8
- let r = n && typeof n == "object" && "components" in n ? n.components : n, i = {
9
- ...t ?? {},
10
- ...r ?? {}
32
+ const { components, renderHTML: customRender } = pluginOptions ?? {};
33
+ if (customRender) renderHTML = customRender;
34
+ else renderHTML = (rawHTML, overrides) => {
35
+ const overrideComponents = overrides && typeof overrides === "object" && "components" in overrides ? overrides.components : overrides;
36
+ const mergedComponents = {
37
+ ...components ?? {},
38
+ ...overrideComponents ?? {}
11
39
  };
12
- return Object.keys(i).length, e;
13
- });
40
+ if (!Object.keys(mergedComponents).length) return rawHTML;
41
+ return rawHTML;
42
+ };
14
43
  }
15
- return t(n);
16
- }, r = () => e || { renderHTML: (e) => e }, i = async (t) => e || n(await t());
44
+ return createIntlayerHTMLClient(renderHTML);
45
+ };
46
+ /**
47
+ * Access the installed IntlayerHTMLProvider.
48
+ * Returns a fallback renderer that outputs the raw HTML string if no
49
+ * provider has been installed.
50
+ */
51
+ const useHTML = () => {
52
+ if (instance) return instance;
53
+ return { renderHTML: (rawHTML) => rawHTML };
54
+ };
55
+ /**
56
+ * Asynchronously install an HTML renderer whose implementation is loaded
57
+ * via a dynamic `import()`.
58
+ *
59
+ * Use this to keep a heavy HTML sanitiser / component renderer out of the
60
+ * initial bundle — the loader is only called the first time this function
61
+ * is executed.
62
+ *
63
+ * The returned promise resolves once the provider is ready. Any calls to
64
+ * `useHTML()` before the promise resolves will use the fallback (identity)
65
+ * renderer.
66
+ *
67
+ * @param loader - A zero-argument async function that resolves to either a
68
+ * `RenderHTMLFunction` or an `IntlayerHTMLPluginOptions` object.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * // Load a custom HTML sanitiser only when needed
73
+ * await installIntlayerHTMLDynamic(async () => {
74
+ * const DOMPurify = await import('dompurify');
75
+ * return (html) => DOMPurify.sanitize(html);
76
+ * });
77
+ * ```
78
+ */
79
+ const installIntlayerHTMLDynamic = async (loader) => {
80
+ if (instance) return instance;
81
+ return installIntlayerHTML(await loader());
82
+ };
83
+
17
84
  //#endregion
18
- export { t as createIntlayerHTMLClient, n as installIntlayerHTML, i as installIntlayerHTMLDynamic, r as useHTML };
85
+ export { createIntlayerHTMLClient, installIntlayerHTML, installIntlayerHTMLDynamic, useHTML };
86
+ //# sourceMappingURL=installIntlayerHTML.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installIntlayerHTML.mjs","names":[],"sources":["../../../src/html/installIntlayerHTML.ts"],"sourcesContent":["import type { HTMLComponents } from './types';\n\nexport type RenderHTMLOptions = {\n components?: HTMLComponents<'permissive', {}>;\n};\n\nexport type RenderHTMLFunction = (\n html: string,\n overrides?: HTMLComponents<'permissive', {}> | RenderHTMLOptions\n) => string;\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerHTMLProvider | null = null;\n\nexport type IntlayerHTMLProvider = {\n renderHTML: RenderHTMLFunction;\n};\n\nexport type IntlayerHTMLPluginOptions = {\n components?: HTMLComponents<'permissive', {}>;\n renderHTML?: RenderHTMLFunction;\n};\n\n/**\n * Create and return a single IntlayerHTMLProvider instance.\n */\nexport const createIntlayerHTMLClient = (\n renderHTML: RenderHTMLFunction\n): IntlayerHTMLProvider => {\n if (instance) return instance;\n instance = { renderHTML };\n return instance;\n};\n\n/**\n * Install the Intlayer HTML provider for your vanilla JS application.\n *\n * @example\n * ```ts\n * import { installIntlayerHTML } from 'vanilla-intlayer';\n *\n * installIntlayerHTML({\n * components: {\n * a: ({ href, children }) => `<a class=\"styled-link\" href=\"${href}\">${children}</a>`,\n * },\n * });\n * ```\n */\nexport const installIntlayerHTML = (\n pluginOptions?: IntlayerHTMLPluginOptions | RenderHTMLFunction\n): IntlayerHTMLProvider => {\n let renderHTML: RenderHTMLFunction;\n\n if (typeof pluginOptions === 'function') {\n renderHTML = pluginOptions;\n } else {\n const { components, renderHTML: customRender } = pluginOptions ?? {};\n\n if (customRender) {\n renderHTML = customRender;\n } else {\n renderHTML = (rawHTML, overrides) => {\n const isOptionsObject =\n overrides &&\n typeof overrides === 'object' &&\n 'components' in overrides;\n\n const overrideComponents = isOptionsObject\n ? (overrides as RenderHTMLOptions).components\n : (overrides as HTMLComponents<'permissive', {}>);\n\n const mergedComponents = {\n ...(components ?? {}),\n ...(overrideComponents ?? {}),\n };\n\n if (!Object.keys(mergedComponents).length) return rawHTML;\n\n // Apply component overrides as simple string replacements.\n // For full component replacement support, provide a custom renderHTML.\n return rawHTML;\n };\n }\n }\n\n return createIntlayerHTMLClient(renderHTML);\n};\n\n/**\n * Access the installed IntlayerHTMLProvider.\n * Returns a fallback renderer that outputs the raw HTML string if no\n * provider has been installed.\n */\nexport const useHTML = (): IntlayerHTMLProvider => {\n if (instance) return instance;\n return { renderHTML: (rawHTML) => rawHTML };\n};\n\n/**\n * Asynchronously install an HTML renderer whose implementation is loaded\n * via a dynamic `import()`.\n *\n * Use this to keep a heavy HTML sanitiser / component renderer out of the\n * initial bundle — the loader is only called the first time this function\n * is executed.\n *\n * The returned promise resolves once the provider is ready. Any calls to\n * `useHTML()` before the promise resolves will use the fallback (identity)\n * renderer.\n *\n * @param loader - A zero-argument async function that resolves to either a\n * `RenderHTMLFunction` or an `IntlayerHTMLPluginOptions` object.\n *\n * @example\n * ```ts\n * // Load a custom HTML sanitiser only when needed\n * await installIntlayerHTMLDynamic(async () => {\n * const DOMPurify = await import('dompurify');\n * return (html) => DOMPurify.sanitize(html);\n * });\n * ```\n */\nexport const installIntlayerHTMLDynamic = async (\n loader: () => Promise<IntlayerHTMLPluginOptions | RenderHTMLFunction>\n): Promise<IntlayerHTMLProvider> => {\n if (instance) return instance;\n const pluginOptions = await loader();\n return installIntlayerHTML(pluginOptions);\n};\n"],"mappings":";;;;AAcA,IAAI,WAAwC;;;;AAc5C,MAAa,4BACX,eACyB;AACzB,KAAI,SAAU,QAAO;AACrB,YAAW,EAAE,YAAY;AACzB,QAAO;;;;;;;;;;;;;;;;AAiBT,MAAa,uBACX,kBACyB;CACzB,IAAI;AAEJ,KAAI,OAAO,kBAAkB,WAC3B,cAAa;MACR;EACL,MAAM,EAAE,YAAY,YAAY,iBAAiB,iBAAiB,EAAE;AAEpE,MAAI,aACF,cAAa;MAEb,eAAc,SAAS,cAAc;GAMnC,MAAM,qBAJJ,aACA,OAAO,cAAc,YACrB,gBAAgB,YAGb,UAAgC,aAChC;GAEL,MAAM,mBAAmB;IACvB,GAAI,cAAc,EAAE;IACpB,GAAI,sBAAsB,EAAE;IAC7B;AAED,OAAI,CAAC,OAAO,KAAK,iBAAiB,CAAC,OAAQ,QAAO;AAIlD,UAAO;;;AAKb,QAAO,yBAAyB,WAAW;;;;;;;AAQ7C,MAAa,gBAAsC;AACjD,KAAI,SAAU,QAAO;AACrB,QAAO,EAAE,aAAa,YAAY,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;AA2B7C,MAAa,6BAA6B,OACxC,WACkC;AAClC,KAAI,SAAU,QAAO;AAErB,QAAO,oBAAoB,MADC,QAAQ,CACK"}
@@ -1,12 +1,13 @@
1
- import { getPlugins as e, htmlPlugin as t, insertionPlugin as n, intlayerNodePlugins as r, markdownPlugin as i, markdownStringPlugin as a } from "./plugins.mjs";
2
- import { getIntlayer as o } from "./getIntlayer.mjs";
3
- import { getDictionary as s } from "./getDictionary.mjs";
4
- import { a as c, i as l, n as u, r as d, t as f } from "../installIntlayer-C99qMzFH.mjs";
5
- import { useDictionary as p } from "./client/useDictionary.mjs";
6
- import { useDictionaryDynamic as m } from "./client/useDictionaryDynamic.mjs";
7
- import { useIntlayer as h } from "./client/useIntlayer.mjs";
8
- import { localeCookie as g, localeInStorage as _, setLocaleCookie as v, setLocaleInStorage as y, useLocaleCookie as b, useLocaleStorage as x } from "./client/useLocaleStorage.mjs";
9
- import { useLocale as S } from "./client/useLocale.mjs";
10
- import { useRewriteURL as C } from "./client/useRewriteURL.mjs";
11
- import "./client/index.mjs";
12
- export { f as IntlayerClient, u as createIntlayerClient, s as getDictionary, o as getIntlayer, d as getIntlayerClient, e as getPlugins, t as htmlPlugin, n as insertionPlugin, l as installIntlayer, r as intlayerNodePlugins, g as localeCookie, _ as localeInStorage, i as markdownPlugin, a as markdownStringPlugin, v as setLocaleCookie, y as setLocaleInStorage, p as useDictionary, m as useDictionaryDynamic, c as useEditor, h as useIntlayer, S as useLocale, b as useLocaleCookie, x as useLocaleStorage, C as useRewriteURL };
1
+ import { getPlugins, htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin } from "./plugins.mjs";
2
+ import { getIntlayer } from "./getIntlayer.mjs";
3
+ import { getDictionary } from "./getDictionary.mjs";
4
+ import { useEditor } from "./editor/useEditor.mjs";
5
+ import { IntlayerClient, createIntlayerClient, getIntlayerClient, installIntlayer } from "./client/installIntlayer.mjs";
6
+ import { useDictionary } from "./client/useDictionary.mjs";
7
+ import { useDictionaryDynamic } from "./client/useDictionaryDynamic.mjs";
8
+ import { useIntlayer } from "./client/useIntlayer.mjs";
9
+ import { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./client/useLocaleStorage.mjs";
10
+ import { useLocale } from "./client/useLocale.mjs";
11
+ import { useRewriteURL } from "./client/useRewriteURL.mjs";
12
+
13
+ export { IntlayerClient, createIntlayerClient, getDictionary, getIntlayer, getIntlayerClient, getPlugins, htmlPlugin, insertionPlugin, installIntlayer, intlayerNodePlugins, localeCookie, localeInStorage, markdownPlugin, markdownStringPlugin, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useEditor, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage, useRewriteURL };