vanilla-intlayer 8.12.1 → 8.12.3
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/client/installIntlayer.cjs +1 -0
- package/dist/cjs/client/installIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -0
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -0
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +1 -0
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +1 -0
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
- package/dist/cjs/editor/useEditor.cjs +1 -0
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/format/useCompact.cjs +1 -0
- package/dist/cjs/format/useCompact.cjs.map +1 -1
- package/dist/cjs/format/useCurrency.cjs +1 -0
- package/dist/cjs/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/format/useDate.cjs +1 -0
- package/dist/cjs/format/useDate.cjs.map +1 -1
- package/dist/cjs/format/useIntl.cjs +1 -0
- package/dist/cjs/format/useIntl.cjs.map +1 -1
- package/dist/cjs/format/useList.cjs +1 -0
- package/dist/cjs/format/useList.cjs.map +1 -1
- package/dist/cjs/format/useNumber.cjs +1 -0
- package/dist/cjs/format/useNumber.cjs.map +1 -1
- package/dist/cjs/format/usePercentage.cjs +1 -0
- package/dist/cjs/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/format/useRelativeTime.cjs +1 -0
- package/dist/cjs/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/format/useUnit.cjs +1 -0
- package/dist/cjs/format/useUnit.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +1 -0
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +1 -0
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/installIntlayerHTML.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs +35 -7
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +0 -6
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -1
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/renderIntlayerNode.cjs.map +1 -1
- package/dist/esm/client/installIntlayer.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs.map +1 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -1
- package/dist/esm/format/useCompact.mjs.map +1 -1
- package/dist/esm/format/useCurrency.mjs.map +1 -1
- package/dist/esm/format/useDate.mjs.map +1 -1
- package/dist/esm/format/useIntl.mjs.map +1 -1
- package/dist/esm/format/useList.mjs.map +1 -1
- package/dist/esm/format/useNumber.mjs.map +1 -1
- package/dist/esm/format/usePercentage.mjs.map +1 -1
- package/dist/esm/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/format/useUnit.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/installIntlayerHTML.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs +36 -4
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +2 -2
- package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -1
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/renderIntlayerNode.mjs.map +1 -1
- package/dist/types/client/installIntlayer.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +5 -4
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/client/useRewriteURL.d.ts.map +1 -1
- package/dist/types/editor/useEditor.d.ts.map +1 -1
- package/dist/types/format/useCompact.d.ts.map +1 -1
- package/dist/types/format/useCurrency.d.ts.map +1 -1
- package/dist/types/format/useDate.d.ts.map +1 -1
- package/dist/types/format/useIntl.d.ts.map +1 -1
- package/dist/types/format/useList.d.ts.map +1 -1
- package/dist/types/format/useNumber.d.ts.map +1 -1
- package/dist/types/format/usePercentage.d.ts.map +1 -1
- package/dist/types/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/format/useUnit.d.ts.map +1 -1
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -1
- package/dist/types/html/installIntlayerHTML.d.ts.map +1 -1
- package/dist/types/html/types.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
- package/dist/types/markdown/compiler.d.ts +40 -4
- package/dist/types/markdown/compiler.d.ts.map +1 -1
- package/dist/types/markdown/index.d.ts +2 -2
- package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -1
- package/dist/types/markdown/runtime.d.ts.map +1 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_editor_useEditor = require('../editor/useEditor.cjs');
|
|
3
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
5
|
let _intlayer_config_client = require("@intlayer/config/client");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installIntlayer.cjs","names":["internationalization"],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useEditor } from '../editor/useEditor';\n\ntype LocaleListener = (locale: LocalesValues) => void;\n\nexport class IntlayerClient {\n private _locale: LocalesValues;\n private _listeners: Set<LocaleListener> = new Set();\n isCookieEnabled: boolean;\n\n constructor(locale?: LocalesValues, isCookieEnabled = true) {\n const { defaultLocale } = internationalization ?? {};\n\n setIntlayerIdentifier();\n\n this._locale =\n (locale as LocalesValues) ?? (defaultLocale as LocalesValues);\n this.isCookieEnabled = isCookieEnabled;\n }\n\n get locale(): LocalesValues {\n return this._locale;\n }\n\n setLocale(newLocale: LocalesValues): void {\n this._locale = newLocale;\n for (const listener of this._listeners) {\n listener(newLocale);\n }\n }\n\n subscribe(listener: LocaleListener): () => void {\n this._listeners.add(listener);\n return () => {\n this._listeners.delete(listener);\n };\n }\n\n /**\n * Fire all listeners with the current locale without changing it.\n * Used to trigger re-renders after async data loads.\n */\n notify(): void {\n for (const listener of this._listeners) {\n listener(this._locale);\n }\n }\n}\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerClient | null = null;\n\n/**\n * Create and return a single IntlayerClient instance.\n */\nexport const createIntlayerClient = (\n locale?: LocalesValues,\n isCookieEnabled = true\n): IntlayerClient => {\n if (instance) return instance;\n\n instance = new IntlayerClient(locale, isCookieEnabled);\n return instance;\n};\n\n/**\n * Get the current IntlayerClient instance, creating one with defaults if needed.\n */\nexport const getIntlayerClient = (): IntlayerClient => {\n if (!instance) {\n instance = new IntlayerClient();\n }\n return instance;\n};\n\n/**\n * Install Intlayer into your vanilla JS application.\n *\n * Call this once at application startup, before any Intlayer APIs are used.\n *\n * When called with a `config` argument, `window.INTLAYER_CONFIG` is set so\n * that `@intlayer/config/built` resolves the correct values in the browser\n * without requiring module aliasing in the bundler configuration.\n *\n * @param locale - Initial locale (defaults to config defaultLocale).\n * @param isCookieEnabled - Whether to persist locale in cookies/localStorage.\n * @param config - Optional Intlayer configuration. When provided, sets\n * `window.INTLAYER_CONFIG` with the browser-safe subset of the config so\n * the application works without a Vite/webpack plugin alias.\n * @returns The IntlayerClient singleton.\n *\n * @example\n * ```ts\n * import { installIntlayer } from 'vanilla-intlayer';\n *\n * // With explicit config (no build plugin alias needed):\n * installIntlayer('en', true, {\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n *\n * // With build plugin (alias handles config automatically):\n * installIntlayer('en');\n * ```\n */\nexport const installIntlayer = ({\n locale,\n isCookieEnabled,\n}: {\n locale?: LocalesValues;\n isCookieEnabled?: boolean;\n} = {}): IntlayerClient => {\n const client = createIntlayerClient(locale, isCookieEnabled);\n\n useEditor();\n\n return client;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"installIntlayer.cjs","names":["internationalization"],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useEditor } from '../editor/useEditor';\n\ntype LocaleListener = (locale: LocalesValues) => void;\n\nexport class IntlayerClient {\n private _locale: LocalesValues;\n private _listeners: Set<LocaleListener> = new Set();\n isCookieEnabled: boolean;\n\n constructor(locale?: LocalesValues, isCookieEnabled = true) {\n const { defaultLocale } = internationalization ?? {};\n\n setIntlayerIdentifier();\n\n this._locale =\n (locale as LocalesValues) ?? (defaultLocale as LocalesValues);\n this.isCookieEnabled = isCookieEnabled;\n }\n\n get locale(): LocalesValues {\n return this._locale;\n }\n\n setLocale(newLocale: LocalesValues): void {\n this._locale = newLocale;\n for (const listener of this._listeners) {\n listener(newLocale);\n }\n }\n\n subscribe(listener: LocaleListener): () => void {\n this._listeners.add(listener);\n return () => {\n this._listeners.delete(listener);\n };\n }\n\n /**\n * Fire all listeners with the current locale without changing it.\n * Used to trigger re-renders after async data loads.\n */\n notify(): void {\n for (const listener of this._listeners) {\n listener(this._locale);\n }\n }\n}\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerClient | null = null;\n\n/**\n * Create and return a single IntlayerClient instance.\n */\nexport const createIntlayerClient = (\n locale?: LocalesValues,\n isCookieEnabled = true\n): IntlayerClient => {\n if (instance) return instance;\n\n instance = new IntlayerClient(locale, isCookieEnabled);\n return instance;\n};\n\n/**\n * Get the current IntlayerClient instance, creating one with defaults if needed.\n */\nexport const getIntlayerClient = (): IntlayerClient => {\n if (!instance) {\n instance = new IntlayerClient();\n }\n return instance;\n};\n\n/**\n * Install Intlayer into your vanilla JS application.\n *\n * Call this once at application startup, before any Intlayer APIs are used.\n *\n * When called with a `config` argument, `window.INTLAYER_CONFIG` is set so\n * that `@intlayer/config/built` resolves the correct values in the browser\n * without requiring module aliasing in the bundler configuration.\n *\n * @param locale - Initial locale (defaults to config defaultLocale).\n * @param isCookieEnabled - Whether to persist locale in cookies/localStorage.\n * @param config - Optional Intlayer configuration. When provided, sets\n * `window.INTLAYER_CONFIG` with the browser-safe subset of the config so\n * the application works without a Vite/webpack plugin alias.\n * @returns The IntlayerClient singleton.\n *\n * @example\n * ```ts\n * import { installIntlayer } from 'vanilla-intlayer';\n *\n * // With explicit config (no build plugin alias needed):\n * installIntlayer('en', true, {\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n *\n * // With build plugin (alias handles config automatically):\n * installIntlayer('en');\n * ```\n */\nexport const installIntlayer = ({\n locale,\n isCookieEnabled,\n}: {\n locale?: LocalesValues;\n isCookieEnabled?: boolean;\n} = {}): IntlayerClient => {\n const client = createIntlayerClient(locale, isCookieEnabled);\n\n useEditor();\n\n return client;\n};\n"],"mappings":";;;;;;;AAOA,IAAa,iBAAb,MAA4B;CAC1B,AAAQ;CACR,AAAQ,6BAAkC,IAAI,KAAK;CACnD;CAEA,YAAY,QAAwB,kBAAkB,MAAM;EAC1D,MAAM,EAAE,kBAAkBA,+CAAwB,EAAE;AAEpD,sDAAuB;AAEvB,OAAK,UACF,UAA6B;AAChC,OAAK,kBAAkB;;CAGzB,IAAI,SAAwB;AAC1B,SAAO,KAAK;;CAGd,UAAU,WAAgC;AACxC,OAAK,UAAU;AACf,OAAK,MAAM,YAAY,KAAK,WAC1B,UAAS,UAAU;;CAIvB,UAAU,UAAsC;AAC9C,OAAK,WAAW,IAAI,SAAS;AAC7B,eAAa;AACX,QAAK,WAAW,OAAO,SAAS;;;;;;;CAQpC,SAAe;AACb,OAAK,MAAM,YAAY,KAAK,WAC1B,UAAS,KAAK,QAAQ;;;;;;AAQ5B,IAAI,WAAkC;;;;AAKtC,MAAa,wBACX,QACA,kBAAkB,SACC;AACnB,KAAI,SAAU,QAAO;AAErB,YAAW,IAAI,eAAe,QAAQ,gBAAgB;AACtD,QAAO;;;;;AAMT,MAAa,0BAA0C;AACrD,KAAI,CAAC,SACH,YAAW,IAAI,gBAAgB;AAEjC,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCT,MAAa,mBAAmB,EAC9B,QACA,oBAIE,EAAE,KAAqB;CACzB,MAAM,SAAS,qBAAqB,QAAQ,gBAAgB;AAE5D,qCAAW;AAEX,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["getIntlayerClient","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\n\nexport type WithOnChange<T> = T & {\n /**\n * Subscribe to locale changes. The callback receives the fresh content\n * whenever the active locale changes. Returns the content object itself\n * for convenient one-liner patterns:\n *\n * ```ts\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p')!.textContent = String(c.greeting);\n * });\n * ```\n */\n onChange: (\n callback: <T extends Dictionary, L extends LocalesValues>(\n content: DeepTransformContent<T['content'], L>\n ) => void\n ) => WithOnChange<T>;\n};\n\n/**\n * Get the translated content for a raw dictionary object and optionally\n * subscribe to locale changes via the chainable `.onChange()` method —\n * mirroring the API of `react-intlayer`.\n *\n * Unlike `useIntlayer` (which takes a registered key), this function accepts a\n * dictionary object directly — useful for dictionaries loaded asynchronously\n * or defined inline.\n *\n * The function returns the current content **directly** (same shape as\n * `getDictionary(dict)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useDictionary(myDict);\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useDictionary(myDict);\n * const content = useDictionary(myDict).onChange((c) => render(c));\n * ```\n *\n * @param dictionary - The raw dictionary object.\n * @param locale - Optional locale override.\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import myDict from './myDictionary.content';\n * import { installIntlayer, useDictionary } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p').textContent = String(c.greeting);\n * });\n *\n * document.querySelector('p').textContent = String(content.greeting);\n * ```\n */\nexport const useDictionary = <\n const T extends Dictionary,\n const L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const content = getDictionary(\n dictionary,\n (locale ?? client.locale) as L\n ) as WithOnChange<DeepTransformContent<T['content'], L>>;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n client.subscribe((newLocale) => {\n callback(getDictionary(dictionary, (locale ?? newLocale) as L));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,iBAIX,YACA,WACwD;CACxD,MAAM,SAASA,
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["getIntlayerClient","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\n\nexport type WithOnChange<T> = T & {\n /**\n * Subscribe to locale changes. The callback receives the fresh content\n * whenever the active locale changes. Returns the content object itself\n * for convenient one-liner patterns:\n *\n * ```ts\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p')!.textContent = String(c.greeting);\n * });\n * ```\n */\n onChange: (\n callback: <T extends Dictionary, L extends LocalesValues>(\n content: DeepTransformContent<T['content'], L>\n ) => void\n ) => WithOnChange<T>;\n};\n\n/**\n * Get the translated content for a raw dictionary object and optionally\n * subscribe to locale changes via the chainable `.onChange()` method —\n * mirroring the API of `react-intlayer`.\n *\n * Unlike `useIntlayer` (which takes a registered key), this function accepts a\n * dictionary object directly — useful for dictionaries loaded asynchronously\n * or defined inline.\n *\n * The function returns the current content **directly** (same shape as\n * `getDictionary(dict)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useDictionary(myDict);\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useDictionary(myDict);\n * const content = useDictionary(myDict).onChange((c) => render(c));\n * ```\n *\n * @param dictionary - The raw dictionary object.\n * @param locale - Optional locale override.\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import myDict from './myDictionary.content';\n * import { installIntlayer, useDictionary } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p').textContent = String(c.greeting);\n * });\n *\n * document.querySelector('p').textContent = String(content.greeting);\n * ```\n */\nexport const useDictionary = <\n const T extends Dictionary,\n const L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const content = getDictionary(\n dictionary,\n (locale ?? client.locale) as L\n ) as WithOnChange<DeepTransformContent<T['content'], L>>;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n client.subscribe((newLocale) => {\n callback(getDictionary(dictionary, (locale ?? newLocale) as L));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,iBAIX,YACA,WACwD;CACxD,MAAM,SAASA,kDAAmB;CAClC,MAAM,UAAUC,oCACd,YACC,UAAU,OAAO,OACnB;AAED,SAAQ,YACN,aACG;AACH,SAAO,WAAW,cAAc;AAC9B,YAASA,oCAAc,YAAa,UAAU,UAAgB,CAAC;IAC/D;AACF,SAAO;;AAGT,QAAO"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_getDictionary = require('../getDictionary.cjs');
|
|
3
4
|
const require_client_installIntlayer = require('./installIntlayer.cjs');
|
|
4
5
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["getIntlayerClient","internationalization","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\nimport type { WithOnChange } from './useDictionary';\n\n/** Simple in-memory cache shared across all calls in the same page. */\nconst cache = new Map<string, Dictionary>();\n\n/** Tracks in-flight loads to avoid duplicate fetches. */\nconst inflight = new Map<string, Promise<void>>();\n\nconst loadDictionary = <T extends Dictionary>(\n cacheKey: string,\n loader: () => Promise<T>\n): Promise<void> => {\n if (cache.has(cacheKey)) return Promise.resolve();\n if (inflight.has(cacheKey)) return inflight.get(cacheKey)!;\n\n const promise = loader().then((dictionary) => {\n cache.set(cacheKey, dictionary);\n inflight.delete(cacheKey);\n });\n\n inflight.set(cacheKey, promise);\n return promise;\n};\n\n/**\n * Dynamically load and transform a locale-keyed dictionary.\n *\n * Works like `useIntlayer` / `useDictionary` but accepts a locale-keyed map\n * of lazy loaders instead of a pre-imported dictionary. Call it inside your\n * render function — the first call triggers a background fetch and returns\n * placeholder values; when the load completes the client notifies all\n * subscribers (including your render loop) so the render runs again with real\n * content. Subsequent calls for the same locale return immediately from cache.\n *\n * Locale switches follow the same two-phase pattern: placeholder on first\n * render, real content after the locale bundle loads.\n *\n * @param dictionaryLoaders - Locale-keyed map of `() => Promise<Dictionary>`.\n * @param key - Dictionary key (used for cache namespacing).\n * @param locale - Optional locale override.\n *\n * @example\n * ```ts\n * import dynDic from '../.intlayer/dynamic_dictionary/app.mjs';\n *\n * const render = () => {\n * const content = useDictionaryDynamic(dynDic, 'app');\n * document.querySelector('h1')!.textContent = String(content.title);\n * };\n *\n * render();\n * getIntlayerClient().subscribe(() => render());\n * ```\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const L extends LocalesValues = LocalesValues,\n>(\n dictionaryLoaders: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const currentLocale = (locale ??\n client.locale ??\n internationalization.defaultLocale) as L;\n\n const cacheKey = `${String(key)}.${currentLocale}`;\n const loader = (dictionaryLoaders as Record<string, () => Promise<T>>)[\n currentLocale\n ];\n\n // --- Cache hit: return real content synchronously ---\n const cached = cache.get(cacheKey);\n if (cached) {\n const content = getDictionary(cached as T, currentLocale) as WithOnChange<\n DeepTransformContent<T['content'], L>\n >;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n // Re-fire whenever content reloads (locale change → new cache entry).\n client.subscribe((newLocale) => {\n const newKey = `${String(key)}.${newLocale}`;\n const newLoader = (\n dictionaryLoaders as Record<string, () => Promise<T>>\n )[newLocale];\n\n if (!newLoader) return;\n\n loadDictionary(newKey, newLoader).then(() => {\n const dict = cache.get(newKey);\n if (dict) {\n callback(\n getDictionary(dict as T, newLocale as L) as DeepTransformContent<\n T['content'],\n L\n >\n );\n }\n });\n });\n\n return content;\n };\n\n return content;\n }\n\n // --- Cache miss: kick off background load, then notify to re-render ---\n if (loader) {\n loadDictionary(cacheKey, loader).then(() => {\n client.notify();\n });\n }\n\n // Placeholder proxy — safe for any property access while loading.\n const recursiveProxy: any = new Proxy(() => {}, {\n get: (_t, prop) => {\n if (prop === Symbol.toPrimitive) return () => '';\n if (prop === 'toString') return () => '';\n if (prop === 'valueOf') return () => '';\n if (prop === 'then') return undefined; // not a Promise\n if (prop === 'onChange') return (_cb: any) => recursiveProxy;\n return recursiveProxy;\n },\n apply: () => recursiveProxy,\n });\n\n return recursiveProxy as WithOnChange<DeepTransformContent<T['content'], L>>;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["getIntlayerClient","internationalization","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\nimport type { WithOnChange } from './useDictionary';\n\n/** Simple in-memory cache shared across all calls in the same page. */\nconst cache = new Map<string, Dictionary>();\n\n/** Tracks in-flight loads to avoid duplicate fetches. */\nconst inflight = new Map<string, Promise<void>>();\n\nconst loadDictionary = <T extends Dictionary>(\n cacheKey: string,\n loader: () => Promise<T>\n): Promise<void> => {\n if (cache.has(cacheKey)) return Promise.resolve();\n if (inflight.has(cacheKey)) return inflight.get(cacheKey)!;\n\n const promise = loader().then((dictionary) => {\n cache.set(cacheKey, dictionary);\n inflight.delete(cacheKey);\n });\n\n inflight.set(cacheKey, promise);\n return promise;\n};\n\n/**\n * Dynamically load and transform a locale-keyed dictionary.\n *\n * Works like `useIntlayer` / `useDictionary` but accepts a locale-keyed map\n * of lazy loaders instead of a pre-imported dictionary. Call it inside your\n * render function — the first call triggers a background fetch and returns\n * placeholder values; when the load completes the client notifies all\n * subscribers (including your render loop) so the render runs again with real\n * content. Subsequent calls for the same locale return immediately from cache.\n *\n * Locale switches follow the same two-phase pattern: placeholder on first\n * render, real content after the locale bundle loads.\n *\n * @param dictionaryLoaders - Locale-keyed map of `() => Promise<Dictionary>`.\n * @param key - Dictionary key (used for cache namespacing).\n * @param locale - Optional locale override.\n *\n * @example\n * ```ts\n * import dynDic from '../.intlayer/dynamic_dictionary/app.mjs';\n *\n * const render = () => {\n * const content = useDictionaryDynamic(dynDic, 'app');\n * document.querySelector('h1')!.textContent = String(content.title);\n * };\n *\n * render();\n * getIntlayerClient().subscribe(() => render());\n * ```\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const L extends LocalesValues = LocalesValues,\n>(\n dictionaryLoaders: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const currentLocale = (locale ??\n client.locale ??\n internationalization.defaultLocale) as L;\n\n const cacheKey = `${String(key)}.${currentLocale}`;\n const loader = (dictionaryLoaders as Record<string, () => Promise<T>>)[\n currentLocale\n ];\n\n // --- Cache hit: return real content synchronously ---\n const cached = cache.get(cacheKey);\n if (cached) {\n const content = getDictionary(cached as T, currentLocale) as WithOnChange<\n DeepTransformContent<T['content'], L>\n >;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n // Re-fire whenever content reloads (locale change → new cache entry).\n client.subscribe((newLocale) => {\n const newKey = `${String(key)}.${newLocale}`;\n const newLoader = (\n dictionaryLoaders as Record<string, () => Promise<T>>\n )[newLocale];\n\n if (!newLoader) return;\n\n loadDictionary(newKey, newLoader).then(() => {\n const dict = cache.get(newKey);\n if (dict) {\n callback(\n getDictionary(dict as T, newLocale as L) as DeepTransformContent<\n T['content'],\n L\n >\n );\n }\n });\n });\n\n return content;\n };\n\n return content;\n }\n\n // --- Cache miss: kick off background load, then notify to re-render ---\n if (loader) {\n loadDictionary(cacheKey, loader).then(() => {\n client.notify();\n });\n }\n\n // Placeholder proxy — safe for any property access while loading.\n const recursiveProxy: any = new Proxy(() => {}, {\n get: (_t, prop) => {\n if (prop === Symbol.toPrimitive) return () => '';\n if (prop === 'toString') return () => '';\n if (prop === 'valueOf') return () => '';\n if (prop === 'then') return undefined; // not a Promise\n if (prop === 'onChange') return (_cb: any) => recursiveProxy;\n return recursiveProxy;\n },\n apply: () => recursiveProxy,\n });\n\n return recursiveProxy as WithOnChange<DeepTransformContent<T['content'], L>>;\n};\n"],"mappings":";;;;;;;;AAaA,MAAM,wBAAQ,IAAI,KAAyB;;AAG3C,MAAM,2BAAW,IAAI,KAA4B;AAEjD,MAAM,kBACJ,UACA,WACkB;AAClB,KAAI,MAAM,IAAI,SAAS,CAAE,QAAO,QAAQ,SAAS;AACjD,KAAI,SAAS,IAAI,SAAS,CAAE,QAAO,SAAS,IAAI,SAAS;CAEzD,MAAM,UAAU,QAAQ,CAAC,MAAM,eAAe;AAC5C,QAAM,IAAI,UAAU,WAAW;AAC/B,WAAS,OAAO,SAAS;GACzB;AAEF,UAAS,IAAI,UAAU,QAAQ;AAC/B,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCT,MAAa,wBAKX,mBACA,KACA,WACwD;CACxD,MAAM,SAASA,kDAAmB;CAClC,MAAM,gBAAiB,UACrB,OAAO,UACPC,4CAAqB;CAEvB,MAAM,WAAW,GAAG,OAAO,IAAI,CAAC,GAAG;CACnC,MAAM,SAAU,kBACd;CAIF,MAAM,SAAS,MAAM,IAAI,SAAS;AAClC,KAAI,QAAQ;EACV,MAAM,UAAUC,oCAAc,QAAa,cAAc;AAIzD,UAAQ,YACN,aACG;AAEH,UAAO,WAAW,cAAc;IAC9B,MAAM,SAAS,GAAG,OAAO,IAAI,CAAC,GAAG;IACjC,MAAM,YACJ,kBACA;AAEF,QAAI,CAAC,UAAW;AAEhB,mBAAe,QAAQ,UAAU,CAAC,WAAW;KAC3C,MAAM,OAAO,MAAM,IAAI,OAAO;AAC9B,SAAI,KACF,UACEA,oCAAc,MAAW,UAAe,CAIzC;MAEH;KACF;AAEF,UAAO;;AAGT,SAAO;;AAIT,KAAI,OACF,gBAAe,UAAU,OAAO,CAAC,WAAW;AAC1C,SAAO,QAAQ;GACf;CAIJ,MAAM,iBAAsB,IAAI,YAAY,IAAI;EAC9C,MAAM,IAAI,SAAS;AACjB,OAAI,SAAS,OAAO,YAAa,cAAa;AAC9C,OAAI,SAAS,WAAY,cAAa;AACtC,OAAI,SAAS,UAAW,cAAa;AACrC,OAAI,SAAS,OAAQ,QAAO;AAC5B,OAAI,SAAS,WAAY,SAAQ,QAAa;AAC9C,UAAO;;EAET,aAAa;EACd,CAAC;AAEF,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["getIntlayerClient","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\nimport type { WithOnChange } from './useDictionary';\n\n/**\n * Get the translated content for the given key and optionally subscribe to\n * locale changes via the chainable `.onChange()` method — mirroring the API\n * of `react-intlayer`'s `useIntlayer`.\n *\n * Unlike React (where the hook system automatically re-runs on re-render),\n * vanilla JS has no component lifecycle. The `.onChange()` callback is the\n * explicit equivalent: it is called with fresh content whenever the active\n * locale changes. Use it to patch your DOM or trigger a full re-render.\n *\n * The function returns the current content **directly** (same shape as\n * `getIntlayer(key)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useIntlayer('app');\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useIntlayer('app');\n * const content = useIntlayer('app').onChange((c) => render(c));\n * ```\n *\n * For cleanup (e.g. Vite HMR), subscribe via `getIntlayerClient().subscribe()`\n * and hold the returned unsubscribe function.\n *\n * @param key - Dictionary key registered in your intlayer content files.\n * @param locale - Optional locale override (defaults to the current app locale).\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import { installIntlayer, useIntlayer } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * // Static read (no subscription)\n * const content = useIntlayer('homepage');\n * document.querySelector('h1').textContent = String(content.title);\n *\n * // Reactive read — onChange is called on every locale change\n * useIntlayer('homepage').onChange((c) => {\n * document.querySelector('h1').textContent = String(c.title);\n * });\n * ```\n */\nexport const useIntlayer = <const T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): WithOnChange<DeepTransformContent<DictionaryRegistryContent<T>>> => {\n const client = getIntlayerClient();\n const content = getIntlayer(key, locale ?? client.locale) as WithOnChange<\n DeepTransformContent<DictionaryRegistryContent<T>>\n >;\n\n content.onChange = (callback) => {\n client.subscribe((newLocale) => {\n callback(getIntlayer(key, (locale ?? newLocale) as typeof locale));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,eACX,KACA,WACqE;CACrE,MAAM,SAASA,
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["getIntlayerClient","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\nimport type { WithOnChange } from './useDictionary';\n\n/**\n * Get the translated content for the given key and optionally subscribe to\n * locale changes via the chainable `.onChange()` method — mirroring the API\n * of `react-intlayer`'s `useIntlayer`.\n *\n * Unlike React (where the hook system automatically re-runs on re-render),\n * vanilla JS has no component lifecycle. The `.onChange()` callback is the\n * explicit equivalent: it is called with fresh content whenever the active\n * locale changes. Use it to patch your DOM or trigger a full re-render.\n *\n * The function returns the current content **directly** (same shape as\n * `getIntlayer(key)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useIntlayer('app');\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useIntlayer('app');\n * const content = useIntlayer('app').onChange((c) => render(c));\n * ```\n *\n * For cleanup (e.g. Vite HMR), subscribe via `getIntlayerClient().subscribe()`\n * and hold the returned unsubscribe function.\n *\n * @param key - Dictionary key registered in your intlayer content files.\n * @param locale - Optional locale override (defaults to the current app locale).\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import { installIntlayer, useIntlayer } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * // Static read (no subscription)\n * const content = useIntlayer('homepage');\n * document.querySelector('h1').textContent = String(content.title);\n *\n * // Reactive read — onChange is called on every locale change\n * useIntlayer('homepage').onChange((c) => {\n * document.querySelector('h1').textContent = String(c.title);\n * });\n * ```\n */\nexport const useIntlayer = <const T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): WithOnChange<DeepTransformContent<DictionaryRegistryContent<T>>> => {\n const client = getIntlayerClient();\n const content = getIntlayer(key, locale ?? client.locale) as WithOnChange<\n DeepTransformContent<DictionaryRegistryContent<T>>\n >;\n\n content.onChange = (callback) => {\n client.subscribe((newLocale) => {\n callback(getIntlayer(key, (locale ?? newLocale) as typeof locale));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,eACX,KACA,WACqE;CACrE,MAAM,SAASA,kDAAmB;CAClC,MAAM,UAAUC,gCAAY,KAAK,UAAU,OAAO,OAAO;AAIzD,SAAQ,YAAY,aAAa;AAC/B,SAAO,WAAW,cAAc;AAC9B,YAASA,gCAAY,KAAM,UAAU,UAA4B,CAAC;IAClE;AACF,SAAO;;AAGT,QAAO"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('./installIntlayer.cjs');
|
|
3
4
|
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
4
5
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":["getIntlayerClient","internationalization"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayerClient } from './installIntlayer';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n subscribe: (callback: (locale: LocalesValues) => void) => () => void;\n};\n\n/**\n * Get the current locale state and locale management utilities.\n *\n * Returns a plain object with the current `locale`, `defaultLocale`,\n * `availableLocales`, a `setLocale` function, and a `subscribe` function\n * to react to locale changes.\n *\n * @param props - Optional configuration.\n * @returns Locale state and management utilities.\n *\n * @example\n * ```ts\n * import { installIntlayer, useLocale } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n *\n * const { locale, availableLocales, setLocale, subscribe } = useLocale();\n *\n * const unsubscribe = subscribe((newLocale) => {\n * console.log('Locale changed to', newLocale);\n * });\n *\n * document.querySelector('#lang-switcher').addEventListener('change', (e) => {\n * setLocale(e.target.value);\n * });\n * ```\n */\nexport const useLocale = (props: UseLocaleProps = {}): UseLocaleResult => {\n const client = getIntlayerClient();\n const { defaultLocale, locales: availableLocales } =\n internationalization ?? {};\n\n const setLocale = (newLocale: LocalesValues): void => {\n if (!(availableLocales ?? []).map(String).includes(newLocale)) {\n console.error(`Locale \"${newLocale}\" is not available.`);\n return;\n }\n\n client.setLocale(newLocale);\n\n setLocaleInStorage(\n newLocale,\n props.isCookieEnabled ?? client.isCookieEnabled ?? true\n );\n\n props.onLocaleChange?.(newLocale as DeclaredLocales);\n };\n\n return {\n locale: client.locale as DeclaredLocales,\n defaultLocale: defaultLocale as DeclaredLocales,\n availableLocales: (availableLocales ?? []) as DeclaredLocales[],\n setLocale,\n subscribe: (callback) => client.subscribe(callback),\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["getIntlayerClient","internationalization"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayerClient } from './installIntlayer';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n subscribe: (callback: (locale: LocalesValues) => void) => () => void;\n};\n\n/**\n * Get the current locale state and locale management utilities.\n *\n * Returns a plain object with the current `locale`, `defaultLocale`,\n * `availableLocales`, a `setLocale` function, and a `subscribe` function\n * to react to locale changes.\n *\n * @param props - Optional configuration.\n * @returns Locale state and management utilities.\n *\n * @example\n * ```ts\n * import { installIntlayer, useLocale } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n *\n * const { locale, availableLocales, setLocale, subscribe } = useLocale();\n *\n * const unsubscribe = subscribe((newLocale) => {\n * console.log('Locale changed to', newLocale);\n * });\n *\n * document.querySelector('#lang-switcher').addEventListener('change', (e) => {\n * setLocale(e.target.value);\n * });\n * ```\n */\nexport const useLocale = (props: UseLocaleProps = {}): UseLocaleResult => {\n const client = getIntlayerClient();\n const { defaultLocale, locales: availableLocales } =\n internationalization ?? {};\n\n const setLocale = (newLocale: LocalesValues): void => {\n if (!(availableLocales ?? []).map(String).includes(newLocale)) {\n console.error(`Locale \"${newLocale}\" is not available.`);\n return;\n }\n\n client.setLocale(newLocale);\n\n setLocaleInStorage(\n newLocale,\n props.isCookieEnabled ?? client.isCookieEnabled ?? true\n );\n\n props.onLocaleChange?.(newLocale as DeclaredLocales);\n };\n\n return {\n locale: client.locale as DeclaredLocales,\n defaultLocale: defaultLocale as DeclaredLocales,\n availableLocales: (availableLocales ?? []) as DeclaredLocales[],\n setLocale,\n subscribe: (callback) => client.subscribe(callback),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,aAAa,QAAwB,EAAE,KAAsB;CACxE,MAAM,SAASA,kDAAmB;CAClC,MAAM,EAAE,eAAe,SAAS,qBAC9BC,+CAAwB,EAAE;CAE5B,MAAM,aAAa,cAAmC;AACpD,MAAI,EAAE,oBAAoB,EAAE,EAAE,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AAC7D,WAAQ,MAAM,WAAW,UAAU,qBAAqB;AACxD;;AAGF,SAAO,UAAU,UAAU;AAE3B,qDACE,WACA,MAAM,mBAAmB,OAAO,mBAAmB,KACpD;AAED,QAAM,iBAAiB,UAA6B;;AAGtD,QAAO;EACL,QAAQ,OAAO;EACA;EACf,kBAAmB,oBAAoB,EAAE;EACzC;EACA,YAAY,aAAa,OAAO,UAAU,SAAS;EACpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.cjs","names":["localeStorageOptions"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getLocaleFromStorageClient,\n LocaleStorageClient,\n localeStorageOptions,\n setLocaleInStorageClient as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Get the current locale from storage (cookie or localStorage).\n */\nexport const localeInStorage = getLocaleFromStorageClient(localeStorageOptions);\n\n/**\n * @deprecated Use localeInStorage instead.\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Persist the locale to storage (cookie and/or localStorage).\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead.\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Returns the current locale from storage and a setter.\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) => {\n const storage = LocaleStorageClient({\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n return {\n localeStorage: storage.getLocale(),\n setLocaleStorage: storage.setLocale,\n };\n};\n\n/**\n * @deprecated Use useLocaleStorage instead.\n */\nexport const useLocaleCookie = useLocaleStorage;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.cjs","names":["localeStorageOptions"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getLocaleFromStorageClient,\n LocaleStorageClient,\n localeStorageOptions,\n setLocaleInStorageClient as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Get the current locale from storage (cookie or localStorage).\n */\nexport const localeInStorage = getLocaleFromStorageClient(localeStorageOptions);\n\n/**\n * @deprecated Use localeInStorage instead.\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Persist the locale to storage (cookie and/or localStorage).\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead.\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Returns the current locale from storage and a setter.\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) => {\n const storage = LocaleStorageClient({\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n return {\n localeStorage: storage.getLocale(),\n setLocaleStorage: storage.setLocale,\n };\n};\n\n/**\n * @deprecated Use useLocaleStorage instead.\n */\nexport const useLocaleCookie = useLocaleStorage;\n"],"mappings":";;;;;;;;AAWA,MAAa,uEAA6CA,0CAAqB;;;;AAK/E,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,uEAEuB,QAAQ;CAC7B,GAAGA;CACH;CACD,CAAC;;;;AAKJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,oBAA8B;CAC7D,MAAM,wDAA8B;EAClC,GAAGA;EACH;EACD,CAAC;AAEF,QAAO;EACL,eAAe,QAAQ,WAAW;EAClC,kBAAkB,QAAQ;EAC3B;;;;;AAMH,MAAa,kBAAkB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('./installIntlayer.cjs');
|
|
3
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
5
|
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRewriteURL.cjs","names":["routing","getIntlayerClient"],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["import { routing } from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getIntlayerClient } from './installIntlayer';\n\nconst rewrite = (locale: string): void => {\n if (typeof window === 'undefined' || !routing?.rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(\n pathname,\n locale as Locale,\n routing?.rewrite\n );\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n};\n\n/**\n * Keep the browser URL in sync with the current locale.\n *\n * Rewrites the current URL immediately and subscribes to future locale changes.\n * Returns an `unsubscribe` function to stop listening.\n *\n * Uses `window.history.replaceState` — no full-page navigation.\n *\n * @returns A cleanup function that removes the locale change listener.\n *\n * @example\n * ```ts\n * import { installIntlayer, useRewriteURL } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n *\n * const unsubscribe = useRewriteURL();\n *\n * // Later, if you want to stop URL rewriting:\n * unsubscribe();\n * ```\n */\nexport const useRewriteURL = (): (() => void) => {\n const client = getIntlayerClient();\n\n // Rewrite immediately for the current locale\n rewrite(client.locale);\n\n return client.subscribe((newLocale) => {\n rewrite(newLocale);\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRewriteURL.cjs","names":["routing","getIntlayerClient"],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["import { routing } from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getIntlayerClient } from './installIntlayer';\n\nconst rewrite = (locale: string): void => {\n if (typeof window === 'undefined' || !routing?.rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(\n pathname,\n locale as Locale,\n routing?.rewrite\n );\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n};\n\n/**\n * Keep the browser URL in sync with the current locale.\n *\n * Rewrites the current URL immediately and subscribes to future locale changes.\n * Returns an `unsubscribe` function to stop listening.\n *\n * Uses `window.history.replaceState` — no full-page navigation.\n *\n * @returns A cleanup function that removes the locale change listener.\n *\n * @example\n * ```ts\n * import { installIntlayer, useRewriteURL } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n *\n * const unsubscribe = useRewriteURL();\n *\n * // Later, if you want to stop URL rewriting:\n * unsubscribe();\n * ```\n */\nexport const useRewriteURL = (): (() => void) => {\n const client = getIntlayerClient();\n\n // Rewrite immediately for the current locale\n rewrite(client.locale);\n\n return client.subscribe((newLocale) => {\n rewrite(newLocale);\n });\n};\n"],"mappings":";;;;;;;AAKA,MAAM,WAAW,WAAyB;AACxC,KAAI,OAAO,WAAW,eAAe,CAACA,gCAAS,QAAS;CAExD,MAAM,WAAW,OAAO,SAAS;CACjC,MAAM,6DACJ,UACA,QACAA,gCAAS,QACV;AAED,KAAI,cAAc,eAAe,SAC/B,QAAO,QAAQ,aACb,OAAO,QAAQ,OACf,IACA,aAAa,OAAO,SAAS,SAAS,OAAO,SAAS,KACvD;;;;;;;;;;;;;;;;;;;;;;;;AA0BL,MAAa,sBAAoC;CAC/C,MAAM,SAASC,kDAAmB;AAGlC,SAAQ,OAAO,OAAO;AAEtB,QAAO,OAAO,WAAW,cAAc;AACrC,UAAQ,UAAU;GAClB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
3
4
|
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.cjs","names":["isEnabled","getIntlayerClient"],"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":"
|
|
1
|
+
{"version":3,"file":"useEditor.cjs","names":["isEnabled","getIntlayerClient"],"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,CAACA,qCACzD,cAAa;CAEf,IAAI,oBAAyC;CAC7C,IAAI,UAAU;AAEd,QAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,MAAI,QAAS;EACb,MAAM,UAA8B,kBAAkB;EACtD,MAAM,SAASC,kDAAmB;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,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
3
4
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompact.cjs","names":["getIntlayerClient"],"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":"
|
|
1
|
+
{"version":3,"file":"useCompact.cjs","names":["getIntlayerClient"],"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,SAASA,kDAAmB;AAElC,SAAQ,GAAG,gDACD,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
3
4
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrency.cjs","names":["getIntlayerClient"],"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":"
|
|
1
|
+
{"version":3,"file":"useCurrency.cjs","names":["getIntlayerClient"],"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,SAASA,kDAAmB;AAElC,SAAQ,GAAG,iDACA,KAAK,IAAI;EAChB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
3
4
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDate.cjs","names":["getIntlayerClient","presets"],"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":"
|
|
1
|
+
{"version":3,"file":"useDate.cjs","names":["getIntlayerClient","presets"],"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,SAASA,kDAAmB;AAElC,SAAQ,GAAG,SAAkC;EAC3C,MAAM,UACJ,OAAO,KAAK,OAAO,WACf;GAAE,GAAGC,kCAAQ,KAAK;GAAK,QAAQ,OAAO;GAAQ,GAC9C;GAAE,GAAG,KAAK;GAAI,QAAQ,KAAK,IAAI,UAAU,OAAO;GAAQ;AAE9D,6CAAY,KAAK,IAAI,QAAsC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
3
4
|
let _intlayer_core_utils = require("@intlayer/core/utils");
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntl.cjs","names":["getIntlayerClient"],"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":"
|
|
1
|
+
{"version":3,"file":"useIntl.cjs","names":["getIntlayerClient"],"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,SAASA,kDAAmB;AAGlC,QAAO;EACL,yCAHoB,UAAU,OAAO,OAGjC;EACJ,YAAY,aACV,OAAO,WAAW,cAAc;AAC9B,+CAAkB,UAAU,UAAU,CAAC;IACvC;EACL"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
3
4
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.cjs","names":["getIntlayerClient"],"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":"
|
|
1
|
+
{"version":3,"file":"useList.cjs","names":["getIntlayerClient"],"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,SAASA,kDAAmB;AAElC,SAAQ,GAAG,6CACJ,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
3
4
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNumber.cjs","names":["getIntlayerClient"],"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":"
|
|
1
|
+
{"version":3,"file":"useNumber.cjs","names":["getIntlayerClient"],"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,SAASA,kDAAmB;AAElC,SAAQ,GAAG,+CACF,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
3
4
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePercentage.cjs","names":["getIntlayerClient"],"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":"
|
|
1
|
+
{"version":3,"file":"usePercentage.cjs","names":["getIntlayerClient"],"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,SAASA,kDAAmB;AAElC,SAAQ,GAAG,mDACE,KAAK,IAAI;EAClB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
3
4
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRelativeTime.cjs","names":["getIntlayerClient"],"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":"
|
|
1
|
+
{"version":3,"file":"useRelativeTime.cjs","names":["getIntlayerClient"],"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,SAASA,kDAAmB;AAElC,SAAQ,GAAG,qDACI,KAAK,IAAI,KAAK,IAAI;EAC7B,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
3
4
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnit.cjs","names":["getIntlayerClient"],"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":"
|
|
1
|
+
{"version":3,"file":"useUnit.cjs","names":["getIntlayerClient"],"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,SAASA,kDAAmB;AAElC,SAAQ,GAAG,8CACH,KAAK,IAAI;EACb,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"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 const T extends Dictionary,\n const 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":"
|
|
1
|
+
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"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 const T extends Dictionary,\n const 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,yDAEkB,YAAY,QAAQA,2BAAW,OAAO,CAAC"}
|
package/dist/cjs/getIntlayer.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"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 const T extends DictionaryKeys,\n const 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":"
|
|
1
|
+
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"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 const T extends DictionaryKeys,\n const 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,uDAEgB,KAAK,QAAQA,2BAAW,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLRenderer.cjs","names":["useHTML"],"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,
|
|
1
|
+
{"version":3,"file":"HTMLRenderer.cjs","names":["useHTML"],"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,UAAUA,0CAAS;AAEzB,SAAQ,YACN,QAAQ,WAAW,SAAS,EAAE,YAAY,CAAsB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installIntlayerHTML.cjs","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;
|
|
1
|
+
{"version":3,"file":"installIntlayerHTML.cjs","names":[],"sources":["../../../src/html/installIntlayerHTML.ts"],"sourcesContent":["import type { HTMLComponents } from './types';\n\nexport type RenderHTMLOptions = {\n components?: HTMLComponents<'permissive', {}>;\n};\n\nexport type RenderHTMLFunction = (\n html: string,\n overrides?: HTMLComponents<'permissive', {}> | RenderHTMLOptions\n) => string;\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerHTMLProvider | null = null;\n\nexport type IntlayerHTMLProvider = {\n renderHTML: RenderHTMLFunction;\n};\n\nexport type IntlayerHTMLPluginOptions = {\n components?: HTMLComponents<'permissive', {}>;\n renderHTML?: RenderHTMLFunction;\n};\n\n/**\n * Create and return a single IntlayerHTMLProvider instance.\n */\nexport const createIntlayerHTMLClient = (\n renderHTML: RenderHTMLFunction\n): IntlayerHTMLProvider => {\n if (instance) return instance;\n instance = { renderHTML };\n return instance;\n};\n\n/**\n * Install the Intlayer HTML provider for your vanilla JS application.\n *\n * @example\n * ```ts\n * import { installIntlayerHTML } from 'vanilla-intlayer';\n *\n * installIntlayerHTML({\n * components: {\n * a: ({ href, children }) => `<a class=\"styled-link\" href=\"${href}\">${children}</a>`,\n * },\n * });\n * ```\n */\nexport const installIntlayerHTML = (\n pluginOptions?: IntlayerHTMLPluginOptions | RenderHTMLFunction\n): IntlayerHTMLProvider => {\n let renderHTML: RenderHTMLFunction;\n\n if (typeof pluginOptions === 'function') {\n renderHTML = pluginOptions;\n } else {\n const { components, renderHTML: customRender } = pluginOptions ?? {};\n\n if (customRender) {\n renderHTML = customRender;\n } else {\n renderHTML = (rawHTML, overrides) => {\n const isOptionsObject =\n overrides &&\n typeof overrides === 'object' &&\n 'components' in overrides;\n\n const overrideComponents = isOptionsObject\n ? (overrides as RenderHTMLOptions).components\n : (overrides as HTMLComponents<'permissive', {}>);\n\n const mergedComponents = {\n ...(components ?? {}),\n ...(overrideComponents ?? {}),\n };\n\n if (!Object.keys(mergedComponents).length) return rawHTML;\n\n // Apply component overrides as simple string replacements.\n // For full component replacement support, provide a custom renderHTML.\n return rawHTML;\n };\n }\n }\n\n return createIntlayerHTMLClient(renderHTML);\n};\n\n/**\n * Access the installed IntlayerHTMLProvider.\n * Returns a fallback renderer that outputs the raw HTML string if no\n * provider has been installed.\n */\nexport const useHTML = (): IntlayerHTMLProvider => {\n if (instance) return instance;\n return { renderHTML: (rawHTML) => rawHTML };\n};\n\n/**\n * Asynchronously install an HTML renderer whose implementation is loaded\n * via a dynamic `import()`.\n *\n * Use this to keep a heavy HTML sanitiser / component renderer out of the\n * initial bundle — the loader is only called the first time this function\n * is executed.\n *\n * The returned promise resolves once the provider is ready. Any calls to\n * `useHTML()` before the promise resolves will use the fallback (identity)\n * renderer.\n *\n * @param loader - A zero-argument async function that resolves to either a\n * `RenderHTMLFunction` or an `IntlayerHTMLPluginOptions` object.\n *\n * @example\n * ```ts\n * // Load a custom HTML sanitiser only when needed\n * await installIntlayerHTMLDynamic(async () => {\n * const DOMPurify = await import('dompurify');\n * return (html) => DOMPurify.sanitize(html);\n * });\n * ```\n */\nexport const installIntlayerHTMLDynamic = async (\n loader: () => Promise<IntlayerHTMLPluginOptions | RenderHTMLFunction>\n): Promise<IntlayerHTMLProvider> => {\n if (instance) return instance;\n const pluginOptions = await loader();\n return installIntlayerHTML(pluginOptions);\n};\n"],"mappings":";;;;;;AAcA,IAAI,WAAwC;;;;AAc5C,MAAa,4BACX,eACyB;AACzB,KAAI,SAAU,QAAO;AACrB,YAAW,EAAE,YAAY;AACzB,QAAO;;;;;;;;;;;;;;;;AAiBT,MAAa,uBACX,kBACyB;CACzB,IAAI;AAEJ,KAAI,OAAO,kBAAkB,WAC3B,cAAa;MACR;EACL,MAAM,EAAE,YAAY,YAAY,iBAAiB,iBAAiB,EAAE;AAEpE,MAAI,aACF,cAAa;MAEb,eAAc,SAAS,cAAc;GAMnC,MAAM,qBAJJ,aACA,OAAO,cAAc,YACrB,gBAAgB,YAGb,UAAgC,aAChC;GAEL,MAAM,mBAAmB;IACvB,GAAI,cAAc,EAAE;IACpB,GAAI,sBAAsB,EAAE;IAC7B;AAED,OAAI,CAAC,OAAO,KAAK,iBAAiB,CAAC,OAAQ,QAAO;AAIlD,UAAO;;;AAKb,QAAO,yBAAyB,WAAW;;;;;;;AAQ7C,MAAa,gBAAsC;AACjD,KAAI,SAAU,QAAO;AACrB,QAAO,EAAE,aAAa,YAAY,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;AA2B7C,MAAa,6BAA6B,OACxC,WACkC;AAClC,KAAI,SAAU,QAAO;AAErB,QAAO,oBAAoB,MADC,QAAQ,CACK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRenderer.cjs","names":["compileMarkdown","useMarkdown"],"sources":["../../../src/markdown/MarkdownRenderer.ts"],"sourcesContent":["import type { HTMLComponents } from '../html/types';\nimport {\n compileMarkdown,\n type MarkdownCompilerOptions,\n type ParsedMarkdown,\n} from './compiler';\nimport {\n type MarkdownProviderOptions,\n type RenderMarkdownFunction,\n useMarkdown,\n} from './installIntlayerMarkdown';\n\nexport type RenderMarkdownProps = MarkdownProviderOptions & {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: string;\n};\n\n/**\n * Renders markdown to an HTML string without using the global provider.\n *\n * @example\n * ```ts\n * import { renderMarkdown } from 'vanilla-intlayer/markdown';\n *\n * document.querySelector('#content').innerHTML = renderMarkdown('# Hello **World**');\n * ```\n */\nexport const renderMarkdown = (\n content: string | ParsedMarkdown,\n {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n }: RenderMarkdownProps = {}\n): string => {\n const options: MarkdownCompilerOptions = {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n };\n return compileMarkdown(content, options);\n};\n\n/**\n * Returns a render function that uses the global provider's configuration\n * (installed via `installIntlayerMarkdown`), falling back to `compileMarkdown`.\n */\nexport const useMarkdownRenderer = (\n props: RenderMarkdownProps = {}\n): ((content: string | ParsedMarkdown) => string | Promise<string>) => {\n const provider = useMarkdown();\n\n return (content: string | ParsedMarkdown) =>\n provider.renderMarkdown(\n content,\n {\n forceBlock: props.forceBlock,\n forceInline: props.forceInline,\n preserveFrontmatter: props.preserveFrontmatter,\n tagfilter: props.tagfilter,\n },\n props.components,\n props.wrapper\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAa,kBACX,SACA,EACE,YACA,aACA,qBACA,cACuB,
|
|
1
|
+
{"version":3,"file":"MarkdownRenderer.cjs","names":["compileMarkdown","useMarkdown"],"sources":["../../../src/markdown/MarkdownRenderer.ts"],"sourcesContent":["import type { HTMLComponents } from '../html/types';\nimport {\n compileMarkdown,\n type MarkdownCompilerOptions,\n type ParsedMarkdown,\n} from './compiler';\nimport {\n type MarkdownProviderOptions,\n type RenderMarkdownFunction,\n useMarkdown,\n} from './installIntlayerMarkdown';\n\nexport type RenderMarkdownProps = MarkdownProviderOptions & {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: string;\n};\n\n/**\n * Renders markdown to an HTML string without using the global provider.\n *\n * @example\n * ```ts\n * import { renderMarkdown } from 'vanilla-intlayer/markdown';\n *\n * document.querySelector('#content').innerHTML = renderMarkdown('# Hello **World**');\n * ```\n */\nexport const renderMarkdown = (\n content: string | ParsedMarkdown,\n {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n }: RenderMarkdownProps = {}\n): string => {\n const options: MarkdownCompilerOptions = {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n };\n return compileMarkdown(content, options);\n};\n\n/**\n * Returns a render function that uses the global provider's configuration\n * (installed via `installIntlayerMarkdown`), falling back to `compileMarkdown`.\n */\nexport const useMarkdownRenderer = (\n props: RenderMarkdownProps = {}\n): ((content: string | ParsedMarkdown) => string | Promise<string>) => {\n const provider = useMarkdown();\n\n return (content: string | ParsedMarkdown) =>\n provider.renderMarkdown(\n content,\n {\n forceBlock: props.forceBlock,\n forceInline: props.forceInline,\n preserveFrontmatter: props.preserveFrontmatter,\n tagfilter: props.tagfilter,\n },\n props.components,\n props.wrapper\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAa,kBACX,SACA,EACE,YACA,aACA,qBACA,cACuB,EAAE,KAChB;AAOX,QAAOA,0CAAgB,SAAS;EAL9B;EACA;EACA;EACA;EAEqC,CAAC;;;;;;AAO1C,MAAa,uBACX,QAA6B,EAAE,KACsC;CACrE,MAAM,WAAWC,sDAAa;AAE9B,SAAQ,YACN,SAAS,eACP,SACA;EACE,YAAY,MAAM;EAClB,aAAa,MAAM;EACnB,qBAAqB,MAAM;EAC3B,WAAW,MAAM;EAClB,EACD,MAAM,YACN,MAAM,QACP"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_markdown_runtime = require('./runtime.cjs');
|
|
3
4
|
let _intlayer_core_markdown = require("@intlayer/core/markdown");
|
|
4
5
|
|
|
@@ -9,6 +10,24 @@ let _intlayer_core_markdown = require("@intlayer/core/markdown");
|
|
|
9
10
|
* Compiles markdown to an HTML string for use with `innerHTML` or the
|
|
10
11
|
* `renderMarkdown` utility.
|
|
11
12
|
*/
|
|
13
|
+
/**
|
|
14
|
+
* **Step 1 of 2 — parse only.**
|
|
15
|
+
* Converts a raw markdown string into a `ParsedMarkdown` AST without rendering
|
|
16
|
+
* any HTML. Use this when you need to:
|
|
17
|
+
* - Cache the parsed result and render it several times with different options.
|
|
18
|
+
* - Inspect or transform the AST before rendering.
|
|
19
|
+
* - Defer the render step to a later point.
|
|
20
|
+
*
|
|
21
|
+
* @param markdown - The markdown source string.
|
|
22
|
+
* @param options - Options that affect parsing (sanitizer, slugify, …).
|
|
23
|
+
* @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const ast = parseMarkdown('# Hello **World**');
|
|
28
|
+
* document.querySelector('#content').innerHTML = compileMarkdown(ast);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
12
31
|
const parseMarkdown = (markdown = "", options = {}) => {
|
|
13
32
|
const { components, namedCodesToUnicode, sanitizer, slugify, ...compilerOptions } = options;
|
|
14
33
|
return (0, _intlayer_core_markdown.parseMarkdown)(markdown, {
|
|
@@ -19,6 +38,22 @@ const parseMarkdown = (markdown = "", options = {}) => {
|
|
|
19
38
|
slugify
|
|
20
39
|
}, compilerOptions);
|
|
21
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* **Steps 1 + 2 — parse and render in one shot.**
|
|
43
|
+
* Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and
|
|
44
|
+
* returns an HTML string. Insert the result into the DOM via `innerHTML` or
|
|
45
|
+
* the `renderMarkdown` utility.
|
|
46
|
+
*
|
|
47
|
+
* @param input - Markdown string or pre-parsed AST.
|
|
48
|
+
* @param options - Rendering options (custom components, sanitizer, slugify, …).
|
|
49
|
+
* @returns An HTML string representing the rendered markdown.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* document.querySelector('#content').innerHTML =
|
|
54
|
+
* compileMarkdown('# Hello **World**');
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
22
57
|
const compileMarkdown = (input = "", options = {}) => {
|
|
23
58
|
if (typeof input === "string") return (0, _intlayer_core_markdown.compileWithOptions)(input, require_markdown_runtime.default, options);
|
|
24
59
|
const { components, namedCodesToUnicode, sanitizer, slugify, ...compilerOptions } = options;
|
|
@@ -30,15 +65,8 @@ const compileMarkdown = (input = "", options = {}) => {
|
|
|
30
65
|
slugify
|
|
31
66
|
}, compilerOptions);
|
|
32
67
|
};
|
|
33
|
-
const compiler = compileMarkdown;
|
|
34
|
-
const compile = compileMarkdown;
|
|
35
68
|
|
|
36
69
|
//#endregion
|
|
37
|
-
exports.RuleType = _intlayer_core_markdown.RuleType;
|
|
38
|
-
exports.compile = compile;
|
|
39
70
|
exports.compileMarkdown = compileMarkdown;
|
|
40
|
-
exports.compiler = compiler;
|
|
41
71
|
exports.parseMarkdown = parseMarkdown;
|
|
42
|
-
exports.sanitizer = _intlayer_core_markdown.sanitizer;
|
|
43
|
-
exports.slugify = _intlayer_core_markdown.slugify;
|
|
44
72
|
//# sourceMappingURL=compiler.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.cjs","names":["vanillaRuntime"],"sources":["../../../src/markdown/compiler.ts"],"sourcesContent":["/**\n * Vanilla JS adapter for the framework-agnostic markdown processor.\n *\n * Compiles markdown to an HTML string for use with `innerHTML` or the\n * `renderMarkdown` utility.\n */\n\nimport {\n type CompileOptions,\n compileWithOptions,\n parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n
|
|
1
|
+
{"version":3,"file":"compiler.cjs","names":["vanillaRuntime"],"sources":["../../../src/markdown/compiler.ts"],"sourcesContent":["/**\n * Vanilla JS adapter for the framework-agnostic markdown processor.\n *\n * Compiles markdown to an HTML string for use with `innerHTML` or the\n * `renderMarkdown` utility.\n */\n\nimport {\n type CompileOptions,\n compileWithOptions,\n parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n type MarkdownContext,\n type ParsedMarkdown,\n} from '@intlayer/core/markdown';\nimport { vanillaRuntime } from './runtime';\n\n/**\n * Options accepted by `compileMarkdown` and `parseMarkdown` to customise\n * rendering behaviour (custom components, sanitizer, slugify, rule hooks, …).\n */\nexport type MarkdownCompilerOptions = CompileOptions;\n\n/**\n * Intermediate AST produced by `parseMarkdown`.\n * Pass this to `compileMarkdown` to skip re-parsing when the same content is\n * rendered multiple times.\n */\nexport type { ParsedMarkdown };\n\n/**\n * **Step 1 of 2 — parse only.**\n * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering\n * any HTML. Use this when you need to:\n * - Cache the parsed result and render it several times with different options.\n * - Inspect or transform the AST before rendering.\n * - Defer the render step to a later point.\n *\n * @param markdown - The markdown source string.\n * @param options - Options that affect parsing (sanitizer, slugify, …).\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```ts\n * const ast = parseMarkdown('# Hello **World**');\n * document.querySelector('#content').innerHTML = compileMarkdown(ast);\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: MarkdownCompilerOptions = {}\n): ParsedMarkdown => {\n const {\n components,\n namedCodesToUnicode,\n sanitizer,\n slugify,\n ...compilerOptions\n } = options;\n\n const ctx: MarkdownContext<any> = {\n runtime: vanillaRuntime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n return coreParseMarkdown(markdown, ctx, compilerOptions);\n};\n\n/**\n * **Steps 1 + 2 — parse and render in one shot.**\n * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and\n * returns an HTML string. Insert the result into the DOM via `innerHTML` or\n * the `renderMarkdown` utility.\n *\n * @param input - Markdown string or pre-parsed AST.\n * @param options - Rendering options (custom components, sanitizer, slugify, …).\n * @returns An HTML string representing the rendered markdown.\n *\n * @example\n * ```ts\n * document.querySelector('#content').innerHTML =\n * compileMarkdown('# Hello **World**');\n * ```\n */\nexport const compileMarkdown = (\n input: string | ParsedMarkdown = '',\n options: MarkdownCompilerOptions = {}\n): string => {\n if (typeof input === 'string') {\n return compileWithOptions(input, vanillaRuntime, options) as string;\n }\n\n const {\n components,\n namedCodesToUnicode,\n sanitizer,\n slugify,\n ...compilerOptions\n } = options;\n\n const ctx: MarkdownContext<any> = {\n runtime: vanillaRuntime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n return coreRenderMarkdownAst(input, ctx, compilerOptions) as string;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,iBACX,WAAmB,IACnB,UAAmC,EAAE,KAClB;CACnB,MAAM,EACJ,YACA,qBACA,WACA,SACA,GAAG,oBACD;AAUJ,mDAAyB,UAAU;EAPjC,SAASA;EACT;EACA;EACW;EACX;EAGoC,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;AAmB1D,MAAa,mBACX,QAAiC,IACjC,UAAmC,EAAE,KAC1B;AACX,KAAI,OAAO,UAAU,SACnB,wDAA0B,OAAOA,kCAAgB,QAAQ;CAG3D,MAAM,EACJ,YACA,qBACA,WACA,SACA,GAAG,oBACD;AAUJ,uDAA6B,OAAO;EAPlC,SAASA;EACT;EACA;EACW;EACX;EAGqC,EAAE,gBAAgB"}
|
|
@@ -2,17 +2,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_markdown_compiler = require('./compiler.cjs');
|
|
3
3
|
const require_markdown_installIntlayerMarkdown = require('./installIntlayerMarkdown.cjs');
|
|
4
4
|
const require_markdown_MarkdownRenderer = require('./MarkdownRenderer.cjs');
|
|
5
|
-
let _intlayer_core_markdown = require("@intlayer/core/markdown");
|
|
6
5
|
|
|
7
|
-
exports.RuleType = _intlayer_core_markdown.RuleType;
|
|
8
|
-
exports.compile = require_markdown_compiler.compile;
|
|
9
6
|
exports.compileMarkdown = require_markdown_compiler.compileMarkdown;
|
|
10
|
-
exports.compiler = require_markdown_compiler.compiler;
|
|
11
7
|
exports.installIntlayerMarkdown = require_markdown_installIntlayerMarkdown.installIntlayerMarkdown;
|
|
12
8
|
exports.installIntlayerMarkdownDynamic = require_markdown_installIntlayerMarkdown.installIntlayerMarkdownDynamic;
|
|
13
9
|
exports.parseMarkdown = require_markdown_compiler.parseMarkdown;
|
|
14
10
|
exports.renderMarkdown = require_markdown_MarkdownRenderer.renderMarkdown;
|
|
15
|
-
exports.sanitizer = _intlayer_core_markdown.sanitizer;
|
|
16
|
-
exports.slugify = _intlayer_core_markdown.slugify;
|
|
17
11
|
exports.useMarkdown = require_markdown_installIntlayerMarkdown.useMarkdown;
|
|
18
12
|
exports.useMarkdownRenderer = require_markdown_MarkdownRenderer.useMarkdownRenderer;
|