intor 2.3.16 → 2.3.17

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 (67) hide show
  1. package/dist/next/src/adapters/next/navigation/use-pathname.js +2 -2
  2. package/dist/react/export/react/index.js +2 -2
  3. package/dist/react/src/client/react/helpers/{use-runtime-state.js → use-intor.js} +2 -2
  4. package/dist/react/src/client/react/navigation/use-execute-navigation.js +2 -2
  5. package/dist/react/src/client/react/navigation/use-resolve-navigation.js +2 -2
  6. package/dist/react/src/client/react/provider/intor-provider.js +1 -8
  7. package/dist/react/src/client/react/provider/{use-intor.js → use-intor-context.js} +3 -3
  8. package/dist/react/src/client/react/render/create-react-renderer.js +9 -19
  9. package/dist/react/src/client/react/render/render-rich-message-react.js +2 -2
  10. package/dist/react/src/client/react/translator/use-translator.js +6 -2
  11. package/dist/svelte/export/svelte/index.js +2 -2
  12. package/dist/svelte/src/client/svelte/helpers/{create-runtime-state.js → create-intor.js} +2 -2
  13. package/dist/svelte/src/client/svelte/{runtime/create-intor.js → store/create-intor-store.js} +4 -4
  14. package/dist/svelte/src/client/svelte/{runtime/create-intor-api.js → store/create-translator-bindings.js} +3 -3
  15. package/dist/types/export/react/index.d.ts +2 -2
  16. package/dist/types/export/server/index.d.ts +1 -1
  17. package/dist/types/export/svelte/index.d.ts +1 -1
  18. package/dist/types/export/vue/index.d.ts +1 -1
  19. package/dist/types/src/adapters/next/server/intor.d.ts +2 -2
  20. package/dist/types/src/client/react/helpers/index.d.ts +1 -1
  21. package/dist/types/src/client/react/helpers/use-intor.d.ts +5 -0
  22. package/dist/types/src/client/react/index.d.ts +2 -2
  23. package/dist/types/src/client/react/provider/index.d.ts +2 -2
  24. package/dist/types/src/client/react/provider/types.d.ts +10 -11
  25. package/dist/types/src/client/react/provider/use-intor-context.d.ts +3 -0
  26. package/dist/types/src/client/react/render/create-react-renderer.d.ts +1 -13
  27. package/dist/types/src/client/react/render/render-rich-message-react.d.ts +1 -1
  28. package/dist/types/src/client/react/render/types.d.ts +5 -19
  29. package/dist/types/src/client/react/translator/trans.d.ts +5 -5
  30. package/dist/types/src/client/svelte/helpers/create-intor.d.ts +4 -0
  31. package/dist/types/src/client/svelte/helpers/index.d.ts +1 -1
  32. package/dist/types/src/client/svelte/index.d.ts +2 -2
  33. package/dist/types/src/client/svelte/store/create-intor-store.d.ts +2 -0
  34. package/dist/types/src/client/svelte/{runtime/create-intor-api.d.ts → store/create-translator-bindings.d.ts} +1 -1
  35. package/dist/types/src/client/svelte/store/index.d.ts +2 -0
  36. package/dist/types/src/client/svelte/{runtime → store}/types.d.ts +3 -3
  37. package/dist/types/src/client/vue/helpers/index.d.ts +1 -1
  38. package/dist/types/src/client/vue/helpers/use-intor.d.ts +4 -0
  39. package/dist/types/src/client/vue/index.d.ts +2 -2
  40. package/dist/types/src/client/vue/provider/index.d.ts +1 -0
  41. package/dist/types/src/client/vue/provider/types.d.ts +12 -12
  42. package/dist/types/src/client/vue/render/create-vue-renderer.d.ts +1 -13
  43. package/dist/types/src/client/vue/render/types.d.ts +5 -19
  44. package/dist/types/src/server/index.d.ts +1 -1
  45. package/dist/types/src/server/intor/index.d.ts +1 -1
  46. package/dist/types/src/server/intor/intor.d.ts +2 -2
  47. package/dist/types/src/server/intor/types.d.ts +1 -1
  48. package/dist/types/src/server/translator/create-translator.d.ts +1 -1
  49. package/dist/vue/export/vue/index.js +1 -1
  50. package/dist/vue/src/client/vue/helpers/{use-runtime-state.js → use-intor.js} +2 -2
  51. package/dist/vue/src/client/vue/provider/intor-provider.js +16 -28
  52. package/dist/vue/src/client/vue/render/create-vue-renderer.js +8 -18
  53. package/dist/vue/src/client/vue/render/render-rich-message-vue.js +1 -1
  54. package/dist/vue/src/client/vue/translator/use-translator.js +1 -1
  55. package/package.json +3 -3
  56. package/dist/types/src/client/react/helpers/use-runtime-state.d.ts +0 -12
  57. package/dist/types/src/client/react/provider/use-intor.d.ts +0 -3
  58. package/dist/types/src/client/svelte/helpers/create-runtime-state.d.ts +0 -12
  59. package/dist/types/src/client/svelte/runtime/create-intor.d.ts +0 -2
  60. package/dist/types/src/client/svelte/runtime/index.d.ts +0 -2
  61. package/dist/types/src/client/vue/helpers/use-runtime-state.d.ts +0 -11
  62. package/dist/types/src/client/vue/provider/resolver/resolve-runtime.d.ts +0 -10
  63. package/dist/vue/src/client/vue/provider/resolver/resolve-runtime.js +0 -32
  64. /package/dist/svelte/src/client/svelte/{runtime → store}/effects/locale-effects.js +0 -0
  65. /package/dist/svelte/src/client/svelte/{runtime → store}/effects/messages-effects.js +0 -0
  66. /package/dist/types/src/client/svelte/{runtime → store}/effects/locale-effects.d.ts +0 -0
  67. /package/dist/types/src/client/svelte/{runtime → store}/effects/messages-effects.d.ts +0 -0
@@ -1,5 +1,5 @@
1
1
  import { usePathname as usePathname$1 } from 'next/navigation';
2
- import { useIntor } from 'intor/react';
2
+ import { useIntorContext } from 'intor/react';
3
3
  import '../../../core/error/intor-error.js';
4
4
  import 'logry';
5
5
  import { localizePathname } from '../../../routing/pathname/localize-pathname.js';
@@ -17,7 +17,7 @@ import { localizePathname } from '../../../routing/pathname/localize-pathname.js
17
17
  * @platform Next.js
18
18
  */
19
19
  const usePathname = () => {
20
- const { config, locale } = useIntor();
20
+ const { config, locale } = useIntorContext();
21
21
  const rawPathname = usePathname$1();
22
22
  return localizePathname(rawPathname, config, locale);
23
23
  };
@@ -1,8 +1,8 @@
1
1
  export { IntorProvider } from '../../src/client/react/provider/intor-provider.js';
2
- export { useIntor } from '../../src/client/react/provider/use-intor.js';
2
+ export { useIntorContext } from '../../src/client/react/provider/use-intor-context.js';
3
3
  export { useTranslator } from '../../src/client/react/translator/use-translator.js';
4
4
  export { Trans } from '../../src/client/react/translator/trans.js';
5
5
  export { useResolveNavigation } from '../../src/client/react/navigation/use-resolve-navigation.js';
6
6
  export { useExecuteNavigation } from '../../src/client/react/navigation/use-execute-navigation.js';
7
- export { useRuntimeState } from '../../src/client/react/helpers/use-runtime-state.js';
7
+ export { useIntor } from '../../src/client/react/helpers/use-intor.js';
8
8
  export { getClientLocale } from '../../src/client/shared/helpers/get-client-locale.js';
@@ -4,7 +4,7 @@ import 'logry';
4
4
  import { mergeMessages } from '../../../core/messages/merge-messages.js';
5
5
  import { getClientLocale } from '../../shared/helpers/get-client-locale.js';
6
6
 
7
- function useRuntimeState(config, loader) {
7
+ function useIntor(config, loader) {
8
8
  // ---------------------------------------------------------------------------
9
9
  // Initial locale
10
10
  // ---------------------------------------------------------------------------
@@ -43,4 +43,4 @@ function useRuntimeState(config, loader) {
43
43
  };
44
44
  }
45
45
 
46
- export { useRuntimeState };
46
+ export { useIntor };
@@ -4,10 +4,10 @@ import '../../../core/error/intor-error.js';
4
4
  import 'logry';
5
5
  import { shouldSyncLocale } from '../../../policies/should-sync-locale.js';
6
6
  import '../provider/intor-provider.js';
7
- import { useIntor } from '../provider/use-intor.js';
7
+ import { useIntorContext } from '../provider/use-intor-context.js';
8
8
 
9
9
  function useExecuteNavigation() {
10
- const { config, setLocale, locale: currentLocale } = useIntor();
10
+ const { config, setLocale, locale: currentLocale } = useIntorContext();
11
11
  function executeNavigation(result, e) {
12
12
  const { destination, kind, locale } = result;
13
13
  // External navigation: let browser handle it
@@ -2,10 +2,10 @@ import '../../../core/error/intor-error.js';
2
2
  import 'logry';
3
3
  import { resolveNavigation } from '../../../routing/navigation/resolve-navigation.js';
4
4
  import '../provider/intor-provider.js';
5
- import { useIntor } from '../provider/use-intor.js';
5
+ import { useIntorContext } from '../provider/use-intor-context.js';
6
6
 
7
7
  function useResolveNavigation() {
8
- const { config, locale: currentLocale } = useIntor();
8
+ const { config, locale: currentLocale } = useIntorContext();
9
9
  function resolveNavigation$1(currentPathname, intent) {
10
10
  return resolveNavigation(config, currentLocale, currentPathname, intent);
11
11
  }
@@ -57,14 +57,7 @@ const IntorProvider = ({ value: { config, locale: initialLocale, messages, handl
57
57
  // ---------------------------------------------------------------------------
58
58
  useLocaleEffects(config, locale);
59
59
  useMessagesEffects(config, locale, setRuntimeMessages, setInternalIsLoading);
60
- return (jsx(IntorContext.Provider, { value: {
61
- config,
62
- locale,
63
- setLocale,
64
- messages: effectiveMessages,
65
- isLoading: effectiveIsLoading,
66
- translator,
67
- }, children: children }));
60
+ return (jsx(IntorContext.Provider, { value: { config, locale, setLocale, translator }, children: children }));
68
61
  };
69
62
 
70
63
  export { IntorContext, IntorProvider };
@@ -1,11 +1,11 @@
1
1
  import React__default from 'react';
2
2
  import { IntorContext } from './intor-provider.js';
3
3
 
4
- function useIntor() {
4
+ function useIntorContext() {
5
5
  const context = React__default.useContext(IntorContext);
6
6
  if (!context)
7
- throw new Error("useIntor must be used within IntorProvider");
7
+ throw new Error("useIntorContext must be used within IntorProvider");
8
8
  return context;
9
9
  }
10
10
 
11
- export { useIntor };
11
+ export { useIntorContext };
@@ -2,34 +2,24 @@ import * as React from 'react';
2
2
 
3
3
  /**
4
4
  * Create a React renderer for semantic rich messages.
5
- *
6
- * Transforms semantic AST nodes into React nodes.
7
- * Used together with `render` / `renderRichMessage`.
8
- *
9
- * - Text nodes → plain strings
10
- * - Tag nodes → custom renderer or native element
11
- * - Raw nodes → rendered as-is by the renderer
12
- *
13
- * This renderer is intentionally minimal and stateless.
14
5
  */
15
- const createReactRenderer = (options) => {
16
- const { tagRenderers } = options ?? {};
6
+ const createReactRenderer = (tagRenderers) => {
17
7
  return {
18
8
  /** Render plain text nodes */
19
9
  text(value) {
20
10
  return value;
21
11
  },
22
12
  /** Render semantic tag nodes */
23
- tag(name, attributes, children) {
24
- const renderer = tagRenderers?.[name];
25
- // Custom tag renderer
26
- if (renderer) {
27
- return typeof renderer === "function"
28
- ? renderer(children, attributes)
29
- : renderer;
13
+ tag(name, _attributes, children) {
14
+ // Custom tag renderers override
15
+ const tagRenderer = tagRenderers?.[name];
16
+ if (tagRenderer) {
17
+ return typeof tagRenderer === "function"
18
+ ? tagRenderer(children)
19
+ : tagRenderer;
30
20
  }
31
21
  // Default behavior: render as a native React element
32
- return React.createElement(name, attributes, ...children);
22
+ return React.createElement(name, null, ...children);
33
23
  },
34
24
  /** Render raw (non-tokenized) message values */
35
25
  raw(value) {
@@ -12,8 +12,8 @@ import { createReactRenderer } from './create-react-renderer.js';
12
12
  *
13
13
  * This function is intended for React environments only.
14
14
  */
15
- function renderRichMessageReact(message, tagRenderers) {
16
- const reactRenderer = createReactRenderer({ tagRenderers });
15
+ function renderRichMessageReact(message, tagComponents) {
16
+ const reactRenderer = createReactRenderer(tagComponents);
17
17
  const nodes = renderRichMessage(message, reactRenderer);
18
18
  // Wrap each top-level node with a Fragment to provide a stable key
19
19
  return nodes.map((node, index) => jsx(Fragment, { children: node }, index));
@@ -1,10 +1,10 @@
1
1
  import '../provider/intor-provider.js';
2
- import { useIntor } from '../provider/use-intor.js';
2
+ import { useIntorContext } from '../provider/use-intor-context.js';
3
3
  import { createTRich } from './create-t-rich.js';
4
4
 
5
5
  // Implementation
6
6
  function useTranslator(preKey) {
7
- const { translator, setLocale } = useIntor();
7
+ const { translator, setLocale } = useIntorContext();
8
8
  const scoped = translator.scoped(preKey);
9
9
  return {
10
10
  messages: translator.messages,
@@ -14,6 +14,10 @@ function useTranslator(preKey) {
14
14
  hasKey: preKey ? scoped.hasKey : translator.hasKey,
15
15
  t: preKey ? scoped.t : translator.t,
16
16
  tRich: createTRich(translator, preKey),
17
+ // NOTE:
18
+ // The runtime implementation is intentionally erased.
19
+ // Type safety is guaranteed by public type contracts.
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
21
  };
18
22
  }
19
23
 
@@ -1,3 +1,3 @@
1
- export { createIntor } from '../../src/client/svelte/runtime/create-intor.js';
2
- export { createRuntimeState } from '../../src/client/svelte/helpers/create-runtime-state.js';
1
+ export { createIntorStore } from '../../src/client/svelte/store/create-intor-store.js';
2
+ export { createIntor } from '../../src/client/svelte/helpers/create-intor.js';
3
3
  export { getClientLocale } from '../../src/client/shared/helpers/get-client-locale.js';
@@ -4,7 +4,7 @@ import 'logry';
4
4
  import { mergeMessages } from '../../../core/messages/merge-messages.js';
5
5
  import { getClientLocale } from '../../shared/helpers/get-client-locale.js';
6
6
 
7
- function createRuntimeState(config, loader) {
7
+ function createIntor(config, loader) {
8
8
  // ---------------------------------------------------------------------------
9
9
  // Initial locale
10
10
  // ---------------------------------------------------------------------------
@@ -41,4 +41,4 @@ function createRuntimeState(config, loader) {
41
41
  };
42
42
  }
43
43
 
44
- export { createRuntimeState };
44
+ export { createIntor };
@@ -1,10 +1,10 @@
1
1
  import { Translator } from 'intor-translator';
2
2
  import { writable, readable, derived, get } from 'svelte/store';
3
- import { createIntorApi } from './create-intor-api.js';
3
+ import { createTranslatorBindings } from './create-translator-bindings.js';
4
4
  import { attachLocaleEffects } from './effects/locale-effects.js';
5
5
  import { attachMessagesEffects } from './effects/messages-effects.js';
6
6
 
7
- function createIntor({ config, locale: initialLocale, messages, handlers, plugins, onLocaleChange, isLoading: externalIsLoading, }) {
7
+ function createIntorStore({ config, locale: initialLocale, messages, handlers, plugins, onLocaleChange, isLoading: externalIsLoading, }) {
8
8
  // ---------------------------------------------------------------------------
9
9
  // Internal state
10
10
  // ---------------------------------------------------------------------------
@@ -48,7 +48,7 @@ function createIntor({ config, locale: initialLocale, messages, handlers, plugin
48
48
  // ---------------------------------------------------------------------------
49
49
  attachLocaleEffects(locale, config);
50
50
  attachMessagesEffects({ config, locale, runtimeMessages, internalIsLoading });
51
- const { scoped, t, tRich } = createIntorApi(translator);
51
+ const { scoped, t, tRich } = createTranslatorBindings(translator);
52
52
  return {
53
53
  messages: effectiveMessages,
54
54
  locale,
@@ -60,4 +60,4 @@ function createIntor({ config, locale: initialLocale, messages, handlers, plugin
60
60
  };
61
61
  }
62
62
 
63
- export { createIntor };
63
+ export { createIntorStore };
@@ -1,10 +1,10 @@
1
1
  import { derived } from 'svelte/store';
2
2
  import { renderRichMessageSvelte } from '../render/render-rich-message-svelte.js';
3
3
 
4
- function createIntorApi(translator) {
4
+ function createTranslatorBindings(translator) {
5
5
  const scoped = (preKey) => {
6
6
  const scopedTranslator = derived(translator, ($t) => $t.scoped(preKey));
7
- return createIntorApi(scopedTranslator);
7
+ return createTranslatorBindings(scopedTranslator);
8
8
  };
9
9
  const t = derived(translator, ($t) => {
10
10
  return (key, replacements) => $t.t(key, replacements);
@@ -22,4 +22,4 @@ function createIntorApi(translator) {
22
22
  };
23
23
  }
24
24
 
25
- export { createIntorApi };
25
+ export { createTranslatorBindings };
@@ -1,2 +1,2 @@
1
- export { IntorProvider, type IntorProviderProps, useIntor, // Internal hook.
2
- useTranslator, Trans, useResolveNavigation, useExecuteNavigation, useRuntimeState, getClientLocale, } from "../../src/client/react";
1
+ export { IntorProvider, type IntorProviderProps, useIntorContext, // Internal hook.
2
+ useTranslator, Trans, useResolveNavigation, useExecuteNavigation, useIntor, getClientLocale, } from "../../src/client/react";
@@ -1 +1 @@
1
- export { intor, type ServerSnapshot, loadMessages, getTranslator, loadMessagesFromUrl, } from "../../src/server";
1
+ export { intor, type IntorValue, loadMessages, getTranslator, loadMessagesFromUrl, } from "../../src/server";
@@ -1 +1 @@
1
- export { createIntor, type IntorRuntime, createRuntimeState, getClientLocale, } from "../../src/client/svelte";
1
+ export { createIntorStore, type IntorStore, createIntor, getClientLocale, } from "../../src/client/svelte";
@@ -1 +1 @@
1
- export { IntorProvider, useTranslator, Trans, useRuntimeState, getClientLocale, } from "../../src/client/vue";
1
+ export { IntorProvider, useTranslator, Trans, useIntor, getClientLocale, } from "../../src/client/vue";
@@ -1,7 +1,7 @@
1
1
  import type { IntorResolvedConfig } from "../../../config";
2
2
  import type { MessagesReaders } from "../../../core";
3
3
  import { type GenConfigKeys } from "../../../core";
4
- import { type ServerSnapshot } from "../../../server";
4
+ import { type IntorValue } from "../../../server";
5
5
  /**
6
6
  * Initializes Intor for the current execution context.
7
7
  *
@@ -9,4 +9,4 @@ import { type ServerSnapshot } from "../../../server";
9
9
  * - Permits cache writes during server execution.
10
10
  * @platform Next.js
11
11
  */
12
- export declare function intor<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig, readers?: MessagesReaders): Promise<ServerSnapshot<CK>>;
12
+ export declare function intor<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig, readers?: MessagesReaders): Promise<IntorValue<CK>>;
@@ -1 +1 @@
1
- export { useRuntimeState } from "./use-runtime-state";
1
+ export { useIntor } from "./use-intor";
@@ -0,0 +1,5 @@
1
+ import type { IntorValue } from "../provider";
2
+ import type { IntorResolvedConfig } from "../../../config";
3
+ import type { GenConfigKeys } from "../../../core";
4
+ import type { LocaleMessages } from "intor-translator";
5
+ export declare function useIntor<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig, loader: (locale: string) => Promise<LocaleMessages>): Omit<IntorValue<CK>, "handlers" | "plugins">;
@@ -1,5 +1,5 @@
1
- export { IntorProvider, type IntorProviderProps, useIntor } from "./provider";
1
+ export { IntorProvider, type IntorProviderProps, useIntorContext, } from "./provider";
2
2
  export { useTranslator, Trans } from "./translator";
3
3
  export { useResolveNavigation, useExecuteNavigation } from "./navigation";
4
- export { useRuntimeState } from "./helpers";
4
+ export { useIntor } from "./helpers";
5
5
  export { getClientLocale } from "../shared/helpers";
@@ -1,3 +1,3 @@
1
1
  export { IntorProvider } from "./intor-provider";
2
- export type { IntorProviderProps } from "./types";
3
- export { useIntor } from "./use-intor";
2
+ export type { IntorValue, IntorProviderProps } from "./types";
3
+ export { useIntorContext } from "./use-intor-context";
@@ -3,23 +3,22 @@ import type { GenConfigKeys, GenLocale, GenMessages } from "../../../core";
3
3
  import type { TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
4
4
  import type { Translator } from "intor-translator";
5
5
  import type * as React from "react";
6
+ export interface IntorValue<CK extends GenConfigKeys = "__default__"> {
7
+ config: IntorResolvedConfig;
8
+ locale: GenLocale<CK>;
9
+ messages?: Readonly<GenMessages<CK>>;
10
+ isLoading?: boolean;
11
+ onLocaleChange?: (newLocale: GenLocale<CK>) => Promise<void> | void;
12
+ handlers?: TranslateHandlers;
13
+ plugins?: (TranslatorPlugin | TranslateHook)[];
14
+ }
6
15
  export interface IntorProviderProps<CK extends GenConfigKeys = "__default__"> {
7
- value: {
8
- config: IntorResolvedConfig;
9
- locale: GenLocale<CK>;
10
- messages?: Readonly<GenMessages<CK>>;
11
- isLoading?: boolean;
12
- handlers?: TranslateHandlers;
13
- plugins?: (TranslatorPlugin | TranslateHook)[];
14
- onLocaleChange?: (newLocale: GenLocale<CK>) => Promise<void> | void;
15
- };
16
+ value: IntorValue<CK>;
16
17
  children: React.ReactNode;
17
18
  }
18
19
  export type IntorContextValue<CK extends GenConfigKeys = "__default__"> = {
19
20
  config: IntorResolvedConfig;
20
21
  locale: GenLocale<CK>;
21
22
  setLocale: (locale: GenLocale<CK>) => void;
22
- messages: Readonly<GenMessages<CK>>;
23
- isLoading: boolean;
24
23
  translator: Translator<unknown>;
25
24
  };
@@ -0,0 +1,3 @@
1
+ import type { IntorContextValue } from "./types";
2
+ import type { GenConfigKeys } from "../../../core";
3
+ export declare function useIntorContext<CK extends GenConfigKeys = "__default__">(): IntorContextValue<CK>;
@@ -3,17 +3,5 @@ import type { Renderer } from "intor-translator";
3
3
  import * as React from "react";
4
4
  /**
5
5
  * Create a React renderer for semantic rich messages.
6
- *
7
- * Transforms semantic AST nodes into React nodes.
8
- * Used together with `render` / `renderRichMessage`.
9
- *
10
- * - Text nodes → plain strings
11
- * - Tag nodes → custom renderer or native element
12
- * - Raw nodes → rendered as-is by the renderer
13
- *
14
- * This renderer is intentionally minimal and stateless.
15
6
  */
16
- export declare const createReactRenderer: (options?: {
17
- /** Optional custom renderers for semantic tags */
18
- tagRenderers?: ReactTagRenderers;
19
- }) => Renderer<React.ReactNode>;
7
+ export declare const createReactRenderer: (tagRenderers?: ReactTagRenderers) => Renderer<React.ReactNode>;
@@ -11,4 +11,4 @@ import { type MessageValue } from "intor-translator";
11
11
  *
12
12
  * This function is intended for React environments only.
13
13
  */
14
- export declare function renderRichMessageReact(message: MessageValue, tagRenderers?: ReactTagRenderers): JSX.Element[];
14
+ export declare function renderRichMessageReact(message: MessageValue, tagComponents?: ReactTagRenderers): JSX.Element[];
@@ -1,22 +1,8 @@
1
- import type { Attributes, Rich } from "intor-translator";
2
- /**
3
- * Renderer function for a semantic rich tag.
4
- *
5
- * - `children` are the rendered inner nodes of the tag
6
- * - `attributes` include both schema-defined and runtime attributes
7
- */
8
- type ReactTagRenderer<A = Attributes> = (children: React.ReactNode[], attributes: A & Attributes) => React.ReactNode;
9
- /**
10
- * Mapping of rich tags to React renderers.
11
- *
12
- * - Known tags are strongly typed based on the generated rich schema
13
- * - Unknown tags fall back to a generic renderer signature
14
- *
15
- * This design ensures:
16
- * - Accurate autocompletion for generated tags
17
- * - Fail-soft behavior for dynamic or newly added tags
18
- */
1
+ import type { Rich } from "intor-translator";
2
+ /** Renderer function for a semantic rich tag. */
3
+ type ReactTagRenderer = ((children: React.ReactNode[]) => React.ReactNode) | React.ReactNode;
4
+ /** Mapping of semantic rich tags to React renderers. */
19
5
  export type ReactTagRenderers<RichSchema = Rich> = {
20
- [K in keyof RichSchema]: ReactTagRenderer<RichSchema[K]>;
6
+ [K in keyof RichSchema]: ReactTagRenderer;
21
7
  } & Record<string, ReactTagRenderer>;
22
8
  export {};
@@ -1,7 +1,7 @@
1
1
  import type { ReactTagRenderers } from "../render";
2
- import type { GenConfigKeys, GenMessages, GenReplacements } from "../../../core";
3
- import type { LocalizedKey, LocalizedReplacement, Replacement } from "intor-translator";
4
- type TransProps<CK extends GenConfigKeys = "__default__", K extends string = LocalizedKey<GenMessages<CK>>, R extends Replacement = LocalizedReplacement<GenReplacements<CK>, K>> = {
2
+ import type { GenConfigKeys, GenMessages, GenReplacements, GenRich } from "../../../core";
3
+ import type { LocalizedKey, LocalizedReplacement, LocalizedRich, Replacement } from "intor-translator";
4
+ type TransProps<CK extends GenConfigKeys = "__default__", K extends string = LocalizedKey<GenMessages<CK>>, RI = LocalizedRich<GenRich<CK>, K>, RE extends Replacement = LocalizedReplacement<GenReplacements<CK>, K>> = {
5
5
  /** The message key to translate. */
6
6
  i18nKey: K | (string & {});
7
7
  /**
@@ -10,13 +10,13 @@ type TransProps<CK extends GenConfigKeys = "__default__", K extends string = Loc
10
10
  * Maps a tag name to either a React node or a render function,
11
11
  * allowing customization of rich tag rendering.
12
12
  */
13
- components?: ReactTagRenderers;
13
+ components?: ReactTagRenderers<RI>;
14
14
  /**
15
15
  * Optional replacement values for message interpolation.
16
16
  *
17
17
  * These values are passed to the underlying translator.
18
18
  */
19
- values?: R | Replacement;
19
+ values?: RE | Replacement;
20
20
  };
21
21
  /**
22
22
  * `<Trans />` is a lightweight React component for rendering rich translations.
@@ -0,0 +1,4 @@
1
+ import type { IntorValue } from "../store";
2
+ import type { IntorResolvedConfig } from "../../../config";
3
+ import type { Locale, LocaleMessages } from "intor-translator";
4
+ export declare function createIntor(config: IntorResolvedConfig, loader: (locale: Locale) => Promise<LocaleMessages>): Omit<IntorValue, "handlers" | "plugins">;
@@ -1 +1 @@
1
- export { createRuntimeState } from "./create-runtime-state";
1
+ export { createIntor } from "./create-intor";
@@ -1,3 +1,3 @@
1
- export { createIntor, type IntorRuntime } from "./runtime";
2
- export { createRuntimeState } from "./helpers";
1
+ export { createIntorStore, type IntorStore } from "./store";
2
+ export { createIntor } from "./helpers";
3
3
  export { getClientLocale } from "../shared/helpers";
@@ -0,0 +1,2 @@
1
+ import type { IntorValue, IntorStore } from "./types";
2
+ export declare function createIntorStore({ config, locale: initialLocale, messages, handlers, plugins, onLocaleChange, isLoading: externalIsLoading, }: IntorValue): IntorStore;
@@ -2,7 +2,7 @@ import type { Translator } from "intor-translator";
2
2
  import type { Replacement } from "intor-translator";
3
3
  import { type Readable } from "svelte/store";
4
4
  import { type SvelteTagRenderers } from "../render";
5
- export declare function createIntorApi(translator: Readable<Translator>): {
5
+ export declare function createTranslatorBindings(translator: Readable<Translator>): {
6
6
  scoped: (preKey: string) => {
7
7
  scoped: /*elided*/ any;
8
8
  t: Readable<(key: string, replacements?: Replacement) => string>;
@@ -0,0 +1,2 @@
1
+ export { createIntorStore } from "./create-intor-store";
2
+ export type { IntorValue, IntorStore } from "./types";
@@ -2,16 +2,16 @@ import type { SvelteTagRenderers } from "../render";
2
2
  import type { IntorResolvedConfig } from "../../../config";
3
3
  import type { Locale, Replacement, LocaleMessages, TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
4
4
  import type { Readable, Writable } from "svelte/store";
5
- export type CreateIntorOptions = {
5
+ export type IntorValue = {
6
6
  config: IntorResolvedConfig;
7
7
  locale: Locale;
8
8
  messages?: Readable<LocaleMessages>;
9
9
  isLoading?: Readable<boolean>;
10
+ onLocaleChange?: (newLocale: Locale) => Promise<void> | void;
10
11
  handlers?: TranslateHandlers;
11
12
  plugins?: (TranslatorPlugin | TranslateHook)[];
12
- onLocaleChange?: (newLocale: Locale) => Promise<void> | void;
13
13
  };
14
- export type IntorRuntime = {
14
+ export type IntorStore = {
15
15
  /** `messages`: The message object containing all translations. */
16
16
  messages: Readable<LocaleMessages>;
17
17
  /** Current locale in use. */
@@ -1 +1 @@
1
- export { useRuntimeState } from "./use-runtime-state";
1
+ export { useIntor } from "./use-intor";
@@ -0,0 +1,4 @@
1
+ import type { IntorValue } from "../provider";
2
+ import type { IntorResolvedConfig } from "../../../config";
3
+ import type { Locale, LocaleMessages } from "intor-translator";
4
+ export declare function useIntor(config: IntorResolvedConfig, loader: (locale: Locale) => Promise<LocaleMessages>): Omit<IntorValue, "handlers" | "plugins">;
@@ -1,4 +1,4 @@
1
- export { IntorProvider } from "./provider";
1
+ export { IntorProvider, injectIntor } from "./provider";
2
2
  export { useTranslator, Trans } from "./translator";
3
- export { useRuntimeState } from "./helpers";
3
+ export { useIntor } from "./helpers";
4
4
  export { getClientLocale } from "../shared/helpers";
@@ -1,2 +1,3 @@
1
1
  export { IntorProvider } from "./intor-provider";
2
+ export type { IntorValue } from "./types";
2
3
  export { injectIntor } from "./inject";
@@ -1,22 +1,22 @@
1
- import type { RuntimeState } from "../helpers/use-runtime-state";
2
1
  import type { IntorResolvedConfig } from "../../../config";
3
2
  import type { Locale, LocaleMessages, Translator } from "intor-translator";
4
3
  import type { TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
5
- export interface IntorProviderProps {
6
- config?: IntorResolvedConfig;
7
- locale?: Locale;
8
- messages?: Readonly<LocaleMessages>;
9
- isLoading?: boolean;
4
+ import type { ComputedRef, Ref } from "vue";
5
+ export interface IntorValue {
6
+ config: IntorResolvedConfig;
7
+ locale: Locale;
8
+ messages?: Ref<LocaleMessages>;
9
+ isLoading?: Ref<boolean>;
10
+ onLocaleChange?: (newLocale: Locale) => Promise<void> | void;
10
11
  handlers?: TranslateHandlers;
11
12
  plugins?: (TranslatorPlugin | TranslateHook)[];
12
- onLocaleChange?: (newLocale: Locale) => Promise<void> | void;
13
- runtimeState?: RuntimeState;
13
+ }
14
+ export interface IntorProviderProps {
15
+ value: IntorValue;
14
16
  }
15
17
  export type IntorContextValue = {
16
18
  config: IntorResolvedConfig;
17
- locale: Locale;
19
+ locale: Ref<string>;
18
20
  setLocale: (locale: Locale) => void;
19
- messages: Readonly<LocaleMessages>;
20
- isLoading: boolean;
21
- translator: Translator<unknown>;
21
+ translator: ComputedRef<Translator<unknown>>;
22
22
  };
@@ -3,17 +3,5 @@ import type { Renderer } from "intor-translator";
3
3
  import type { VNodeChild } from "vue";
4
4
  /**
5
5
  * Create a Vue renderer for semantic rich messages.
6
- *
7
- * Transforms semantic AST nodes into Vue VNodes.
8
- * Used together with `render` / `renderRichMessage`.
9
- *
10
- * - Text nodes → plain strings
11
- * - Tag nodes → custom renderer or native element
12
- * - Raw nodes → rendered as-is by the renderer
13
- *
14
- * This renderer is intentionally minimal and stateless.
15
6
  */
16
- export declare const createVueRenderer: (options?: {
17
- /** Optional custom renderers for semantic tags */
18
- tagRenderers?: VueTagRenderers;
19
- }) => Renderer<VNodeChild>;
7
+ export declare const createVueRenderer: (tagRenderers?: VueTagRenderers) => Renderer<VNodeChild>;
@@ -1,23 +1,9 @@
1
- import type { Attributes, Rich } from "intor-translator";
1
+ import type { Rich } from "intor-translator";
2
2
  import type { VNodeChild } from "vue";
3
- /**
4
- * A renderer for a semantic tag in a rich message.
5
- *
6
- * - `children` are the rendered inner nodes of the tag
7
- * - `attributes` include both schema-defined and runtime attributes
8
- */
9
- type VueTagRenderer<A = Attributes> = (children: VNodeChild[], attributes: A & Attributes) => VNodeChild;
10
- /**
11
- * A mapping of semantic tag names to Vue renderers.
12
- *
13
- * - Known tags are strongly typed based on the generated rich schema
14
- * - Unknown tags fall back to a generic renderer signature
15
- *
16
- * This design ensures:
17
- * - Accurate autocompletion for generated tags
18
- * - Fail-soft behavior for dynamic or newly added tags
19
- */
3
+ /** Renderer function for a semantic rich tag. */
4
+ type VueTagRenderer = (children: VNodeChild[]) => VNodeChild | VNodeChild;
5
+ /** Mapping of semantic rich tags to Vue renderers. */
20
6
  export type VueTagRenderers<RichSchema = Rich> = {
21
- [K in keyof RichSchema]: VueTagRenderer<RichSchema[K]>;
7
+ [K in keyof RichSchema]: VueTagRenderer;
22
8
  } & Record<string, VueTagRenderer>;
23
9
  export {};
@@ -1,4 +1,4 @@
1
- export { intor, type ServerSnapshot } from "./intor";
1
+ export { intor, type IntorValue } from "./intor";
2
2
  export { loadMessages } from "./messages";
3
3
  export { type TranslatorInstanceServer } from "./translator";
4
4
  export { getTranslator, type GetTranslatorParams, loadMessagesFromUrl, } from "./helpers";
@@ -1,2 +1,2 @@
1
1
  export { intor } from "./intor";
2
- export type { ServerSnapshot } from "./types";
2
+ export type { IntorValue } from "./types";
@@ -1,4 +1,4 @@
1
- import type { LocaleResolver, ServerSnapshot } from "./types";
1
+ import type { LocaleResolver, IntorValue } from "./types";
2
2
  import type { IntorRuntimeOptions } from "../runtime";
3
3
  import type { IntorResolvedConfig } from "../../config";
4
4
  import { type GenConfigKeys, type GenLocale } from "../../core";
@@ -8,4 +8,4 @@ import { type GenConfigKeys, type GenLocale } from "../../core";
8
8
  * Produces a server-side snapshot for SSR and
9
9
  * full-stack rendering environments.
10
10
  */
11
- export declare function intor<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig, localeOrResolver: LocaleResolver<CK> | GenLocale<CK>, options?: IntorRuntimeOptions): Promise<ServerSnapshot<CK>>;
11
+ export declare function intor<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig, localeOrResolver: LocaleResolver<CK> | GenLocale<CK>, options?: IntorRuntimeOptions): Promise<IntorValue<CK>>;
@@ -1,7 +1,7 @@
1
1
  import type { IntorResolvedConfig } from "../../config";
2
2
  import { type GenConfigKeys, type GenLocale, type GenMessages } from "../../core";
3
3
  export type LocaleResolver<CK extends GenConfigKeys = "__default__"> = (config: IntorResolvedConfig) => GenLocale<CK> | Promise<GenLocale<CK>>;
4
- export interface ServerSnapshot<CK extends GenConfigKeys = "__default__"> {
4
+ export interface IntorValue<CK extends GenConfigKeys = "__default__"> {
5
5
  config: IntorResolvedConfig;
6
6
  locale: GenLocale<CK>;
7
7
  messages: Readonly<GenMessages<CK>>;
@@ -23,6 +23,6 @@ export declare function createTranslator(params: CreateTranslatorParams & {
23
23
  messages: LocaleMessages;
24
24
  locale: string;
25
25
  hasKey: <K extends string>(key: K, targetLocale?: string | undefined) => boolean;
26
- t: <K extends string = string>(key: K, replacements?: import("intor-translator").Replacement | undefined) => import("intor-translator").MessageValue;
26
+ t: <K extends string = string>(key: K, replacements?: import("intor-translator").Replacement | undefined) => string;
27
27
  };
28
28
  export {};
@@ -2,5 +2,5 @@ export { IntorProvider } from '../../src/client/vue/provider/intor-provider.js';
2
2
  import 'vue';
3
3
  export { useTranslator } from '../../src/client/vue/translator/use-translator.js';
4
4
  export { Trans } from '../../src/client/vue/translator/trans.js';
5
- export { useRuntimeState } from '../../src/client/vue/helpers/use-runtime-state.js';
5
+ export { useIntor } from '../../src/client/vue/helpers/use-intor.js';
6
6
  export { getClientLocale } from '../../src/client/shared/helpers/get-client-locale.js';
@@ -4,7 +4,7 @@ import 'logry';
4
4
  import { mergeMessages } from '../../../core/messages/merge-messages.js';
5
5
  import { getClientLocale } from '../../shared/helpers/get-client-locale.js';
6
6
 
7
- function useRuntimeState(config, loader) {
7
+ function useIntor(config, loader) {
8
8
  // ---------------------------------------------------------------------------
9
9
  // Initial locale
10
10
  // ---------------------------------------------------------------------------
@@ -44,4 +44,4 @@ function useRuntimeState(config, loader) {
44
44
  };
45
45
  }
46
46
 
47
- export { useRuntimeState };
47
+ export { useIntor };
@@ -2,27 +2,17 @@ import { Translator } from 'intor-translator';
2
2
  import { defineComponent, ref, computed, provide } from 'vue';
3
3
  import { useLocaleEffects } from './effects/use-locale-effects.js';
4
4
  import { useMessagesEffects } from './effects/use-messages-effects.js';
5
- import { resolveRuntime } from './resolver/resolve-runtime.js';
6
5
 
7
6
  const IntorContextKey = Symbol("IntorContext");
8
7
  const IntorProvider = defineComponent({
9
8
  name: "IntorProvider",
10
- props: {
11
- config: { type: Object, required: false },
12
- locale: { type: String, required: false },
13
- messages: { type: Object, required: false },
14
- handlers: { type: Object, required: false },
15
- plugins: { type: Array, required: false },
16
- onLocaleChange: { type: Function, required: false },
17
- isLoading: { type: Boolean, required: false },
18
- runtimeState: { type: Object, required: false },
19
- },
9
+ props: { value: { type: Object, required: true } },
20
10
  setup(props, { slots }) {
21
- const { config, locale: initialLocale, messages, handlers, plugins, onLocaleChange, isLoading: externalIsLoading, } = resolveRuntime(props);
11
+ const { config, locale: initialLocale, messages, handlers, plugins, onLocaleChange, isLoading: externalIsLoading, } = props.value;
22
12
  // ---------------------------------------------------------------------------
23
13
  // Internal state
24
14
  // ---------------------------------------------------------------------------
25
- const locale = ref(initialLocale.value);
15
+ const locale = ref(initialLocale);
26
16
  const runtimeMessages = ref(null);
27
17
  const internalIsLoading = ref(false);
28
18
  // ---------------------------------------------------------------------------
@@ -34,15 +24,15 @@ const IntorProvider = defineComponent({
34
24
  return;
35
25
  locale.value = newLocale;
36
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- onLocaleChange?.value?.(newLocale); // Notify external listener (fire-and-forget)
27
+ onLocaleChange?.(newLocale); // Notify external listener (fire-and-forget)
38
28
  };
39
29
  // ---------------------------------------------------------------------------
40
30
  // Effective state
41
31
  // ---------------------------------------------------------------------------
42
32
  // external > internal
43
- const effectiveIsLoading = computed(() => !!externalIsLoading.value || internalIsLoading.value);
33
+ const effectiveIsLoading = computed(() => !!externalIsLoading?.value || internalIsLoading.value);
44
34
  // runtime (client refetch) > initial > config (static)
45
- const effectiveMessages = computed(() => runtimeMessages.value || messages.value || config.value.messages || {});
35
+ const effectiveMessages = computed(() => runtimeMessages.value || messages?.value || config.messages || {});
46
36
  // ---------------------------------------------------------------------------
47
37
  // Translator
48
38
  // ---------------------------------------------------------------------------
@@ -51,25 +41,23 @@ const IntorProvider = defineComponent({
51
41
  messages: effectiveMessages.value,
52
42
  locale: locale.value,
53
43
  isLoading: effectiveIsLoading.value,
54
- fallbackLocales: config.value.fallbackLocales,
55
- loadingMessage: config.value.translator?.loadingMessage,
56
- missingMessage: config.value.translator?.missingMessage,
57
- handlers: handlers?.value,
58
- plugins: plugins?.value,
44
+ fallbackLocales: config.fallbackLocales,
45
+ loadingMessage: config.translator?.loadingMessage,
46
+ missingMessage: config.translator?.missingMessage,
47
+ handlers: handlers,
48
+ plugins: plugins,
59
49
  });
60
50
  });
61
51
  // -------------------------------------------------------------------------
62
52
  // Side effects
63
53
  // -------------------------------------------------------------------------
64
- useLocaleEffects(config.value, locale);
65
- useMessagesEffects(config.value, locale, runtimeMessages, internalIsLoading);
54
+ useLocaleEffects(config, locale);
55
+ useMessagesEffects(config, locale, runtimeMessages, internalIsLoading);
66
56
  const contextValue = computed(() => ({
67
- config: config.value,
68
- locale: locale.value,
57
+ config,
58
+ locale,
69
59
  setLocale,
70
- messages: effectiveMessages.value,
71
- isLoading: effectiveIsLoading.value,
72
- translator: translator.value,
60
+ translator,
73
61
  }));
74
62
  provide(IntorContextKey, contextValue);
75
63
  return () => slots.default?.();
@@ -2,34 +2,24 @@ import { h } from 'vue';
2
2
 
3
3
  /**
4
4
  * Create a Vue renderer for semantic rich messages.
5
- *
6
- * Transforms semantic AST nodes into Vue VNodes.
7
- * Used together with `render` / `renderRichMessage`.
8
- *
9
- * - Text nodes → plain strings
10
- * - Tag nodes → custom renderer or native element
11
- * - Raw nodes → rendered as-is by the renderer
12
- *
13
- * This renderer is intentionally minimal and stateless.
14
5
  */
15
- const createVueRenderer = (options) => {
16
- const { tagRenderers } = options ?? {};
6
+ const createVueRenderer = (tagRenderers) => {
17
7
  return {
18
8
  /** Render plain text nodes */
19
9
  text(value) {
20
10
  return value;
21
11
  },
22
12
  /** Render semantic tag nodes */
23
- tag(name, attributes, children) {
24
- const renderer = tagRenderers?.[name];
13
+ tag(name, _attributes, children) {
25
14
  // Custom tag renderer
26
- if (renderer) {
27
- return typeof renderer === "function"
28
- ? renderer(children, attributes)
29
- : renderer;
15
+ const tagRenderer = tagRenderers?.[name];
16
+ if (tagRenderer) {
17
+ return typeof tagRenderer === "function"
18
+ ? tagRenderer(children)
19
+ : tagRenderer;
30
20
  }
31
21
  // Default behavior: render as a native Vue element
32
- return h(name, attributes, children);
22
+ return h(name, null, children);
33
23
  },
34
24
  /** Render raw (non-tokenized) message values */
35
25
  raw(value) {
@@ -12,7 +12,7 @@ import { createVueRenderer } from './create-vue-renderer.js';
12
12
  * This function is intended for Vue environments only.
13
13
  */
14
14
  function renderRichMessageVue(message, tagRenderers) {
15
- const vueRenderer = createVueRenderer({ tagRenderers });
15
+ const vueRenderer = createVueRenderer(tagRenderers);
16
16
  return renderRichMessage(message, vueRenderer);
17
17
  }
18
18
 
@@ -6,7 +6,7 @@ import { createTRich } from './create-t-rich.js';
6
6
  // Implementation
7
7
  function useTranslator(preKey) {
8
8
  const intor = injectIntor();
9
- const translator = computed(() => intor.value.translator);
9
+ const translator = intor.value.translator;
10
10
  const scoped = computed(() => preKey ? translator.value.scoped(preKey) : translator.value);
11
11
  const hasKey = computed(() => scoped.value.hasKey);
12
12
  const t = computed(() => scoped.value.t);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "2.3.16",
3
+ "version": "2.3.17",
4
4
  "description": "The i18n library for modern JavaScript",
5
5
  "author": "Yiming Liao",
6
6
  "homepage": "https://github.com/yiming-liao/intor#readme",
@@ -100,7 +100,7 @@
100
100
  "examples:html": "vite --config examples/html/vite.config.ts"
101
101
  },
102
102
  "dependencies": {
103
- "intor-translator": "^1.4.11",
103
+ "intor-translator": "1.4.13",
104
104
  "logry": "2.1.6",
105
105
  "p-limit": "7.2.0"
106
106
  },
@@ -112,7 +112,7 @@
112
112
  "@testing-library/jest-dom": "6.9.1",
113
113
  "@testing-library/react": "16.3.1",
114
114
  "@testing-library/user-event": "14.6.1",
115
- "@types/express": "^5.0.6",
115
+ "@types/express": "5.0.6",
116
116
  "@types/node": "24.10.1",
117
117
  "@types/react": "19.0.0",
118
118
  "@types/react-dom": "19.0.0",
@@ -1,12 +0,0 @@
1
- import type { IntorResolvedConfig } from "../../../config";
2
- import type { GenConfigKeys, GenLocale, GenMessages } from "../../../core";
3
- import type { LocaleMessages } from "intor-translator";
4
- interface RuntimeState<CK extends GenConfigKeys = "__default__"> {
5
- config: IntorResolvedConfig;
6
- locale: GenLocale<CK>;
7
- messages: GenMessages<CK>;
8
- onLocaleChange: (locale: GenLocale<CK>) => Promise<void>;
9
- isLoading: boolean;
10
- }
11
- export declare function useRuntimeState<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig, loader: (locale: string) => Promise<LocaleMessages>): RuntimeState<CK>;
12
- export {};
@@ -1,3 +0,0 @@
1
- import type { IntorContextValue } from "./types";
2
- import type { GenConfigKeys } from "../../../core";
3
- export declare function useIntor<CK extends GenConfigKeys = "__default__">(): IntorContextValue<CK>;
@@ -1,12 +0,0 @@
1
- import type { IntorResolvedConfig } from "../../../config";
2
- import type { Locale, LocaleMessages } from "intor-translator";
3
- import { type Writable } from "svelte/store";
4
- interface RuntimeState {
5
- config: IntorResolvedConfig;
6
- locale: Locale;
7
- messages: Writable<LocaleMessages>;
8
- onLocaleChange: (locale: Locale) => Promise<void>;
9
- isLoading: Writable<boolean>;
10
- }
11
- export declare function createRuntimeState(config: IntorResolvedConfig, loader: (locale: Locale) => Promise<LocaleMessages>): RuntimeState;
12
- export {};
@@ -1,2 +0,0 @@
1
- import type { CreateIntorOptions, IntorRuntime } from "./types";
2
- export declare function createIntor({ config, locale: initialLocale, messages, handlers, plugins, onLocaleChange, isLoading: externalIsLoading, }: CreateIntorOptions): IntorRuntime;
@@ -1,2 +0,0 @@
1
- export { createIntor } from "./create-intor";
2
- export type { IntorRuntime } from "./types";
@@ -1,11 +0,0 @@
1
- import type { IntorResolvedConfig } from "../../../config";
2
- import type { Locale, LocaleMessages } from "intor-translator";
3
- import { type Ref } from "vue";
4
- export interface RuntimeState {
5
- config: IntorResolvedConfig;
6
- locale: Locale;
7
- messages: Ref<LocaleMessages>;
8
- onLocaleChange: (locale: Locale) => Promise<void>;
9
- isLoading: Ref<boolean>;
10
- }
11
- export declare function useRuntimeState(config: IntorResolvedConfig, loader: (locale: Locale) => Promise<LocaleMessages>): RuntimeState;
@@ -1,10 +0,0 @@
1
- import type { IntorProviderProps } from "../types";
2
- export declare function resolveRuntime(props: IntorProviderProps): {
3
- config: import("vue").ComputedRef<import("../../../../config").IntorResolvedConfig>;
4
- locale: import("vue").ComputedRef<string>;
5
- messages: import("vue").ComputedRef<import("intor-translator").LocaleMessages | undefined>;
6
- isLoading: import("vue").ComputedRef<boolean>;
7
- onLocaleChange: import("vue").ComputedRef<((newLocale: import("intor-translator").Locale) => Promise<void> | void) | undefined>;
8
- handlers: import("vue").Ref<import("intor-translator").TranslateHandlers | undefined, import("intor-translator").TranslateHandlers | undefined> | undefined;
9
- plugins: import("vue").Ref<(import("intor-translator").TranslatorPlugin | import("intor-translator").TranslateHook)[] | undefined, (import("intor-translator").TranslatorPlugin | import("intor-translator").TranslateHook)[] | undefined> | undefined;
10
- };
@@ -1,32 +0,0 @@
1
- import { toRefs, computed } from 'vue';
2
-
3
- function resolveRuntime(props) {
4
- const reactiveProps = toRefs(props);
5
- const runtimeState = computed(() => props.runtimeState);
6
- return {
7
- config: computed(() => {
8
- const value = runtimeState.value?.config ?? reactiveProps.config?.value;
9
- if (!value) {
10
- throw new Error("[Intor] Missing `config`. Provide either `runtimeState.config` or `config` prop.");
11
- }
12
- return value;
13
- }),
14
- locale: computed(() => {
15
- const value = runtimeState.value?.locale ?? reactiveProps.locale?.value;
16
- if (!value) {
17
- throw new Error("[Intor] Missing `locale`. Provide either `runtimeState.locale` or `locale` prop.");
18
- }
19
- return value;
20
- }),
21
- messages: computed(() => runtimeState.value?.messages?.value ?? reactiveProps.messages?.value),
22
- isLoading: computed(() => runtimeState.value?.isLoading?.value ??
23
- reactiveProps.isLoading?.value ??
24
- false),
25
- onLocaleChange: computed(() => runtimeState.value?.onLocaleChange ??
26
- reactiveProps.onLocaleChange?.value),
27
- handlers: reactiveProps.handlers,
28
- plugins: reactiveProps.plugins,
29
- };
30
- }
31
-
32
- export { resolveRuntime };