vanilla-intlayer 8.8.0 → 8.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/client/index.cjs +24 -1
- package/dist/cjs/client/installIntlayer.cjs +98 -1
- package/dist/cjs/client/installIntlayer.cjs.map +1 -0
- package/dist/cjs/client/useDictionary.cjs +59 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -0
- package/dist/cjs/client/useDictionaryDynamic.cjs +93 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/client/useIntlayer.cjs +65 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -0
- package/dist/cjs/client/useLocale.cjs +58 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -0
- package/dist/cjs/client/useLocaleStorage.cjs +51 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -0
- package/dist/cjs/client/useRewriteURL.cjs +46 -1
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -0
- package/dist/cjs/editor/useEditor.cjs +49 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -0
- package/dist/cjs/format/index.cjs +20 -1
- package/dist/cjs/format/useCompact.cjs +17 -1
- package/dist/cjs/format/useCompact.cjs.map +1 -0
- package/dist/cjs/format/useCurrency.cjs +17 -1
- package/dist/cjs/format/useCurrency.cjs.map +1 -0
- package/dist/cjs/format/useDate.cjs +26 -1
- package/dist/cjs/format/useDate.cjs.map +1 -0
- package/dist/cjs/format/useIntl.cjs +44 -1
- package/dist/cjs/format/useIntl.cjs.map +1 -0
- package/dist/cjs/format/useList.cjs +17 -1
- package/dist/cjs/format/useList.cjs.map +1 -0
- package/dist/cjs/format/useNumber.cjs +20 -1
- package/dist/cjs/format/useNumber.cjs.map +1 -0
- package/dist/cjs/format/usePercentage.cjs +17 -1
- package/dist/cjs/format/usePercentage.cjs.map +1 -0
- package/dist/cjs/format/useRelativeTime.cjs +17 -1
- package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
- package/dist/cjs/format/useUnit.cjs +17 -1
- package/dist/cjs/format/useUnit.cjs.map +1 -0
- package/dist/cjs/getDictionary.cjs +11 -1
- package/dist/cjs/getDictionary.cjs.map +1 -0
- package/dist/cjs/getIntlayer.cjs +11 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -0
- package/dist/cjs/html/HTMLRenderer.cjs +22 -1
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -0
- package/dist/cjs/html/index.cjs +9 -1
- package/dist/cjs/html/installIntlayerHTML.cjs +91 -1
- package/dist/cjs/html/installIntlayerHTML.cjs.map +1 -0
- package/dist/cjs/html/types.cjs +0 -1
- package/dist/cjs/index.cjs +37 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +41 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
- package/dist/cjs/markdown/compiler.cjs +37 -1
- package/dist/cjs/markdown/compiler.cjs.map +1 -0
- package/dist/cjs/markdown/index.cjs +11 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +98 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -0
- package/dist/cjs/markdown/runtime.cjs +87 -1
- package/dist/cjs/markdown/runtime.cjs.map +1 -0
- package/dist/cjs/plugins.cjs +240 -1
- package/dist/cjs/plugins.cjs.map +1 -0
- package/dist/cjs/renderIntlayerNode.cjs +44 -1
- package/dist/cjs/renderIntlayerNode.cjs.map +1 -0
- package/dist/esm/client/index.mjs +9 -8
- package/dist/esm/client/installIntlayer.mjs +93 -2
- package/dist/esm/client/installIntlayer.mjs.map +1 -0
- package/dist/esm/client/useDictionary.mjs +55 -8
- package/dist/esm/client/useDictionary.mjs.map +1 -0
- package/dist/esm/client/useDictionaryDynamic.mjs +82 -28
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/client/useIntlayer.mjs +61 -8
- package/dist/esm/client/useIntlayer.mjs.map +1 -0
- package/dist/esm/client/useLocale.mjs +51 -17
- package/dist/esm/client/useLocale.mjs.map +1 -0
- package/dist/esm/client/useLocaleStorage.mjs +39 -13
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -0
- package/dist/esm/client/useRewriteURL.mjs +40 -12
- package/dist/esm/client/useRewriteURL.mjs.map +1 -0
- package/dist/esm/editor/useEditor.mjs +47 -2
- package/dist/esm/editor/useEditor.mjs.map +1 -0
- package/dist/esm/format/index.mjs +11 -10
- package/dist/esm/format/useCompact.mjs +11 -8
- package/dist/esm/format/useCompact.mjs.map +1 -0
- package/dist/esm/format/useCurrency.mjs +11 -8
- package/dist/esm/format/useCurrency.mjs.map +1 -0
- package/dist/esm/format/useDate.mjs +18 -12
- package/dist/esm/format/useDate.mjs.map +1 -0
- package/dist/esm/format/useIntl.mjs +36 -8
- package/dist/esm/format/useIntl.mjs.map +1 -0
- package/dist/esm/format/useList.mjs +11 -8
- package/dist/esm/format/useList.mjs.map +1 -0
- package/dist/esm/format/useNumber.mjs +14 -8
- package/dist/esm/format/useNumber.mjs.map +1 -0
- package/dist/esm/format/usePercentage.mjs +11 -8
- package/dist/esm/format/usePercentage.mjs.map +1 -0
- package/dist/esm/format/useRelativeTime.mjs +11 -8
- package/dist/esm/format/useRelativeTime.mjs.map +1 -0
- package/dist/esm/format/useUnit.mjs +11 -8
- package/dist/esm/format/useUnit.mjs.map +1 -0
- package/dist/esm/getDictionary.mjs +7 -4
- package/dist/esm/getDictionary.mjs.map +1 -0
- package/dist/esm/getIntlayer.mjs +7 -4
- package/dist/esm/getIntlayer.mjs.map +1 -0
- package/dist/esm/html/HTMLRenderer.mjs +17 -5
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -0
- package/dist/esm/html/index.mjs +4 -3
- package/dist/esm/html/installIntlayerHTML.mjs +81 -13
- package/dist/esm/html/installIntlayerHTML.mjs.map +1 -0
- package/dist/esm/index.mjs +13 -12
- package/dist/esm/markdown/MarkdownRenderer.mjs +36 -16
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
- package/dist/esm/markdown/compiler.mjs +28 -4
- package/dist/esm/markdown/compiler.mjs.map +1 -0
- package/dist/esm/markdown/index.mjs +5 -4
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +86 -23
- package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -0
- package/dist/esm/markdown/runtime.mjs +60 -28
- package/dist/esm/markdown/runtime.mjs.map +1 -0
- package/dist/esm/plugins.mjs +187 -134
- package/dist/esm/plugins.mjs.map +1 -0
- package/dist/esm/renderIntlayerNode.mjs +32 -15
- package/dist/esm/renderIntlayerNode.mjs.map +1 -0
- package/dist/types/client/index.d.ts +8 -0
- package/dist/{client → types/client}/installIntlayer.d.ts +27 -20
- package/dist/types/client/installIntlayer.d.ts.map +1 -0
- package/dist/{client → types/client}/useDictionary.d.ts +22 -17
- package/dist/types/client/useDictionary.d.ts.map +1 -0
- package/dist/{client → types/client}/useDictionaryDynamic.d.ts +10 -5
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/{client → types/client}/useIntlayer.d.ts +9 -4
- package/dist/types/client/useIntlayer.d.ts.map +1 -0
- package/dist/{client → types/client}/useLocale.d.ts +14 -10
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/client/useLocaleStorage.d.ts +37 -0
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
- package/dist/{client → types/client}/useRewriteURL.d.ts +5 -1
- package/dist/types/client/useRewriteURL.d.ts.map +1 -0
- package/dist/{editor → types/editor}/useEditor.d.ts +5 -1
- package/dist/types/editor/useEditor.d.ts.map +1 -0
- package/dist/types/format/index.d.ts +10 -0
- package/dist/types/format/useCompact.d.ts +7 -0
- package/dist/types/format/useCompact.d.ts.map +1 -0
- package/dist/types/format/useCurrency.d.ts +7 -0
- package/dist/types/format/useCurrency.d.ts.map +1 -0
- package/dist/types/format/useDate.d.ts +10 -0
- package/dist/types/format/useDate.d.ts.map +1 -0
- package/dist/{format → types/format}/useIntl.d.ts +10 -5
- package/dist/types/format/useIntl.d.ts.map +1 -0
- package/dist/types/format/useList.d.ts +7 -0
- package/dist/types/format/useList.d.ts.map +1 -0
- package/dist/types/format/useNumber.d.ts +10 -0
- package/dist/types/format/useNumber.d.ts.map +1 -0
- package/dist/types/format/usePercentage.d.ts +7 -0
- package/dist/types/format/usePercentage.d.ts.map +1 -0
- package/dist/types/format/useRelativeTime.d.ts +7 -0
- package/dist/types/format/useRelativeTime.d.ts.map +1 -0
- package/dist/types/format/useUnit.d.ts +7 -0
- package/dist/types/format/useUnit.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +9 -0
- package/dist/types/getDictionary.d.ts.map +1 -0
- package/dist/types/getIntlayer.d.ts +8 -0
- package/dist/types/getIntlayer.d.ts.map +1 -0
- package/dist/types/html/HTMLRenderer.d.ts +21 -0
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -0
- package/dist/types/html/index.d.ts +4 -0
- package/dist/{html → types/html}/installIntlayerHTML.d.ts +18 -13
- package/dist/types/html/installIntlayerHTML.d.ts.map +1 -0
- package/dist/{html → types/html}/types.d.ts +12 -14
- package/dist/types/html/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +32 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
- package/dist/types/markdown/compiler.d.ts +23 -0
- package/dist/types/markdown/compiler.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +4 -0
- package/dist/types/markdown/installIntlayerMarkdown.d.ts +71 -0
- package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -0
- package/dist/types/markdown/runtime.d.ts +16 -0
- package/dist/types/markdown/runtime.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +80 -0
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/types/renderIntlayerNode.d.ts +31 -0
- package/dist/types/renderIntlayerNode.d.ts.map +1 -0
- package/package.json +10 -13
- package/dist/client/index.d.ts +0 -7
- package/dist/client/useLocaleStorage.d.ts +0 -31
- package/dist/format/index.d.ts +0 -9
- package/dist/format/useCompact.d.ts +0 -2
- package/dist/format/useCurrency.d.ts +0 -2
- package/dist/format/useDate.d.ts +0 -5
- package/dist/format/useList.d.ts +0 -2
- package/dist/format/useNumber.d.ts +0 -5
- package/dist/format/usePercentage.d.ts +0 -2
- package/dist/format/useRelativeTime.d.ts +0 -2
- package/dist/format/useUnit.d.ts +0 -2
- package/dist/getDictionary.d.ts +0 -4
- package/dist/getIntlayer.d.ts +0 -3
- package/dist/html/HTMLRenderer.d.ts +0 -14
- package/dist/html/index.d.ts +0 -3
- package/dist/index.d.ts +0 -11
- package/dist/installIntlayer-C99qMzFH.mjs +0 -47
- package/dist/installIntlayer-_1cC62gP.js +0 -1
- package/dist/markdown/MarkdownRenderer.d.ts +0 -22
- package/dist/markdown/compiler.d.ts +0 -19
- package/dist/markdown/index.d.ts +0 -3
- package/dist/markdown/installIntlayerMarkdown.d.ts +0 -70
- package/dist/markdown/runtime.d.ts +0 -12
- package/dist/plugins-Cv8sSUPw.js +0 -1
- package/dist/plugins.d.ts +0 -78
- package/dist/renderIntlayerNode.d.ts +0 -22
|
@@ -1,2 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
|
2
|
-
import { useDate
|
|
3
|
-
import { useNumber
|
|
4
|
-
import { useRelativeTime
|
|
5
|
-
import { useCompact
|
|
6
|
-
import { useIntl
|
|
7
|
-
import { useList
|
|
8
|
-
import { usePercentage
|
|
9
|
-
import { useCurrency
|
|
10
|
-
|
|
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 {
|
|
2
|
-
import { compact
|
|
1
|
+
import { getIntlayerClient } from "../client/installIntlayer.mjs";
|
|
2
|
+
import { compact } from "@intlayer/core/formatters";
|
|
3
|
+
|
|
3
4
|
//#region src/format/useCompact.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return (...
|
|
7
|
-
...
|
|
8
|
-
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 {
|
|
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 {
|
|
2
|
-
import { currency
|
|
1
|
+
import { getIntlayerClient } from "../client/installIntlayer.mjs";
|
|
2
|
+
import { currency } from "@intlayer/core/formatters";
|
|
3
|
+
|
|
3
4
|
//#region src/format/useCurrency.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return (...
|
|
7
|
-
...
|
|
8
|
-
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 {
|
|
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 {
|
|
2
|
-
import { date
|
|
1
|
+
import { getIntlayerClient } from "../client/installIntlayer.mjs";
|
|
2
|
+
import { date, presets } from "@intlayer/core/formatters";
|
|
3
|
+
|
|
3
4
|
//#region src/format/useDate.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
...
|
|
12
|
-
locale:
|
|
15
|
+
...args[1],
|
|
16
|
+
locale: args[1]?.locale ?? client.locale
|
|
13
17
|
};
|
|
14
|
-
return
|
|
18
|
+
return date(args[0], options);
|
|
15
19
|
};
|
|
16
20
|
};
|
|
21
|
+
|
|
17
22
|
//#endregion
|
|
18
|
-
export {
|
|
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 {
|
|
2
|
-
import { bindIntl
|
|
1
|
+
import { getIntlayerClient } from "../client/installIntlayer.mjs";
|
|
2
|
+
import { bindIntl } from "@intlayer/core/utils";
|
|
3
|
+
|
|
3
4
|
//#region src/format/useIntl.ts
|
|
4
|
-
|
|
5
|
-
|
|
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:
|
|
8
|
-
subscribe: (
|
|
9
|
-
|
|
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 {
|
|
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 {
|
|
2
|
-
import { list
|
|
1
|
+
import { getIntlayerClient } from "../client/installIntlayer.mjs";
|
|
2
|
+
import { list } from "@intlayer/core/formatters";
|
|
3
|
+
|
|
3
4
|
//#region src/format/useList.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return (...
|
|
7
|
-
...
|
|
8
|
-
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 {
|
|
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 {
|
|
2
|
-
import { number
|
|
1
|
+
import { getIntlayerClient } from "../client/installIntlayer.mjs";
|
|
2
|
+
import { number } from "@intlayer/core/formatters";
|
|
3
|
+
|
|
3
4
|
//#region src/format/useNumber.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 {
|
|
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 {
|
|
2
|
-
import { percentage
|
|
1
|
+
import { getIntlayerClient } from "../client/installIntlayer.mjs";
|
|
2
|
+
import { percentage } from "@intlayer/core/formatters";
|
|
3
|
+
|
|
3
4
|
//#region src/format/usePercentage.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return (...
|
|
7
|
-
...
|
|
8
|
-
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 {
|
|
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 {
|
|
2
|
-
import { relativeTime
|
|
1
|
+
import { getIntlayerClient } from "../client/installIntlayer.mjs";
|
|
2
|
+
import { relativeTime } from "@intlayer/core/formatters";
|
|
3
|
+
|
|
3
4
|
//#region src/format/useRelativeTime.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return (...
|
|
7
|
-
...
|
|
8
|
-
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 {
|
|
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 {
|
|
2
|
-
import { units
|
|
1
|
+
import { getIntlayerClient } from "../client/installIntlayer.mjs";
|
|
2
|
+
import { units } from "@intlayer/core/formatters";
|
|
3
|
+
|
|
3
4
|
//#region src/format/useUnit.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return (...
|
|
7
|
-
...
|
|
8
|
-
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 {
|
|
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
|
|
2
|
-
import { getDictionary as
|
|
1
|
+
import { getPlugins } from "./plugins.mjs";
|
|
2
|
+
import { getDictionary as getDictionary$1 } from "@intlayer/core/interpreter";
|
|
3
|
+
|
|
3
4
|
//#region src/getDictionary.ts
|
|
4
|
-
|
|
5
|
+
const getDictionary = (dictionary, locale) => getDictionary$1(dictionary, locale, getPlugins(locale));
|
|
6
|
+
|
|
5
7
|
//#endregion
|
|
6
|
-
export {
|
|
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"}
|
package/dist/esm/getIntlayer.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { getPlugins
|
|
2
|
-
import { getIntlayer as
|
|
1
|
+
import { getPlugins } from "./plugins.mjs";
|
|
2
|
+
import { getIntlayer as getIntlayer$1 } from "@intlayer/core/interpreter";
|
|
3
|
+
|
|
3
4
|
//#region src/getIntlayer.ts
|
|
4
|
-
|
|
5
|
+
const getIntlayer = (key, locale) => getIntlayer$1(key, locale, getPlugins(locale));
|
|
6
|
+
|
|
5
7
|
//#endregion
|
|
6
|
-
export {
|
|
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
|
|
1
|
+
import { useHTML } from "./installIntlayerHTML.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/html/HTMLRenderer.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 {
|
|
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"}
|
package/dist/esm/html/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { installIntlayerHTML
|
|
2
|
-
import { renderHTML
|
|
3
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
13
|
-
|
|
40
|
+
if (!Object.keys(mergedComponents).length) return rawHTML;
|
|
41
|
+
return rawHTML;
|
|
42
|
+
};
|
|
14
43
|
}
|
|
15
|
-
return
|
|
16
|
-
}
|
|
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 {
|
|
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"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { getPlugins
|
|
2
|
-
import { getIntlayer
|
|
3
|
-
import { getDictionary
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import "./client/
|
|
12
|
-
|
|
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 };
|