vanilla-intlayer 9.0.0-canary.8 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/installIntlayer.cjs +0 -1
- package/dist/cjs/client/installIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +0 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +0 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +0 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/usePathname.cjs +0 -1
- package/dist/cjs/client/usePathname.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +0 -1
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
- package/dist/cjs/editor/useEditor.cjs +0 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/format/useCompact.cjs +0 -1
- package/dist/cjs/format/useCompact.cjs.map +1 -1
- package/dist/cjs/format/useCurrency.cjs +0 -1
- package/dist/cjs/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/format/useDate.cjs +0 -1
- package/dist/cjs/format/useDate.cjs.map +1 -1
- package/dist/cjs/format/useIntl.cjs +0 -1
- package/dist/cjs/format/useIntl.cjs.map +1 -1
- package/dist/cjs/format/useList.cjs +0 -1
- package/dist/cjs/format/useList.cjs.map +1 -1
- package/dist/cjs/format/useNumber.cjs +0 -1
- package/dist/cjs/format/useNumber.cjs.map +1 -1
- package/dist/cjs/format/usePercentage.cjs +0 -1
- package/dist/cjs/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/format/useRelativeTime.cjs +0 -1
- package/dist/cjs/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/format/useUnit.cjs +0 -1
- package/dist/cjs/format/useUnit.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +0 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +0 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/installIntlayerHTML.cjs +2 -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 +0 -1
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +2 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -1
- package/dist/cjs/markdown/runtime.cjs +1 -1
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +5 -3
- 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/usePathname.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 +2 -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.map +1 -1
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +2 -1
- package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -1
- package/dist/esm/markdown/runtime.mjs +1 -1
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +6 -4
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/renderIntlayerNode.mjs.map +1 -1
- package/dist/types/client/installIntlayer.d.ts +1 -5
- package/dist/types/client/installIntlayer.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts +0 -1
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +1 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +0 -1
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +0 -1
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +5 -10
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/client/usePathname.d.ts +2 -1
- package/dist/types/client/usePathname.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 +0 -1
- package/dist/types/format/useCompact.d.ts.map +1 -1
- package/dist/types/format/useCurrency.d.ts +0 -1
- package/dist/types/format/useCurrency.d.ts.map +1 -1
- package/dist/types/format/useDate.d.ts +0 -1
- package/dist/types/format/useDate.d.ts.map +1 -1
- package/dist/types/format/useIntl.d.ts +0 -1
- package/dist/types/format/useIntl.d.ts.map +1 -1
- package/dist/types/format/useList.d.ts +0 -1
- package/dist/types/format/useList.d.ts.map +1 -1
- package/dist/types/format/useNumber.d.ts +0 -1
- package/dist/types/format/useNumber.d.ts.map +1 -1
- package/dist/types/format/usePercentage.d.ts +0 -1
- package/dist/types/format/usePercentage.d.ts.map +1 -1
- package/dist/types/format/useRelativeTime.d.ts +0 -1
- package/dist/types/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/format/useUnit.d.ts +0 -1
- package/dist/types/format/useUnit.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +0 -1
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +0 -1
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/html/HTMLRenderer.d.ts +1 -4
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -1
- package/dist/types/html/installIntlayerHTML.d.ts +0 -1
- package/dist/types/html/installIntlayerHTML.d.ts.map +1 -1
- package/dist/types/html/types.d.ts +2 -3
- package/dist/types/html/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRenderer.d.ts +1 -7
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
- package/dist/types/markdown/compiler.d.ts +0 -1
- package/dist/types/markdown/compiler.d.ts.map +1 -1
- package/dist/types/markdown/installIntlayerMarkdown.d.ts +8 -5
- package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -1
- package/dist/types/markdown/runtime.d.ts +0 -1
- package/dist/types/markdown/runtime.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +3 -3
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/renderIntlayerNode.d.ts +1 -6
- package/dist/types/renderIntlayerNode.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_editor_useEditor = require('../editor/useEditor.cjs');
|
|
4
3
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
4
|
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,IAAI;CAClD;CAEA,YAAY,QAAwB,kBAAkB,MAAM;EAC1D,MAAM,EAAE,kBAAkBA,+CAAwB,CAAC;EAEnD,mDAAsB;EAEtB,KAAK,UACF,UAA6B;EAChC,KAAK,kBAAkB;CACzB;CAEA,IAAI,SAAwB;EAC1B,OAAO,KAAK;CACd;CAEA,UAAU,WAAgC;EACxC,KAAK,UAAU;EACf,KAAK,MAAM,YAAY,KAAK,YAC1B,SAAS,SAAS;CAEtB;CAEA,UAAU,UAAsC;EAC9C,KAAK,WAAW,IAAI,QAAQ;EAC5B,aAAa;GACX,KAAK,WAAW,OAAO,QAAQ;EACjC;CACF;;;;;CAMA,SAAe;EACb,KAAK,MAAM,YAAY,KAAK,YAC1B,SAAS,KAAK,OAAO;CAEzB;AACF;;;;AAKA,IAAI,WAAkC;;;;AAKtC,MAAa,wBACX,QACA,kBAAkB,SACC;CACnB,IAAI,UAAU,OAAO;CAErB,WAAW,IAAI,eAAe,QAAQ,eAAe;CACrD,OAAO;AACT;;;;AAKA,MAAa,0BAA0C;CACrD,IAAI,CAAC,UACH,WAAW,IAAI,eAAe;CAEhC,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,mBAAmB,EAC9B,QACA,oBAIE,CAAC,MAAsB;CACzB,MAAM,SAAS,qBAAqB,QAAQ,eAAe;CAE3D,mCAAU;CAEV,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["getIntlayerClient","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\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: (callback: (content: any) => void) => WithOnChange<T>;\n};\n\n/**\n * Get the content for a raw dictionary (or qualified dictionary group) and\n * optionally subscribe to locale changes via the chainable `.onChange()`\n * method — mirroring the API of `react-intlayer`.\n *\n * The second argument is either a locale or a selector object (`{ item }`,\n * `{ variant }`, optionally combined with `locale`).\n *\n * @param dictionary - The raw dictionary (or qualified group) object.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The current content with an `.onChange()` method.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): WithOnChange<\n DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n >\n> => {\n const client = getIntlayerClient();\n\n const isSelector =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n const explicitLocale = isSelector\n ? (localeOrSelector as DictionarySelector).locale\n : (localeOrSelector as LocalesValues | undefined);\n\n const read = (locale: LocalesValues | undefined) =>\n isSelector\n ? getDictionary(dictionary, {\n ...(localeOrSelector as DictionarySelector),\n locale,\n } as A)\n : getDictionary(dictionary, locale as A);\n\n const content = read(explicitLocale ?? client.locale) as WithOnChange<any>;\n\n // A selector can resolve to null/array; only objects carry `.onChange`.\n if (content != null && typeof content === 'object') {\n content.onChange = (callback) => {\n client.subscribe((newLocale) => {\n callback(read(explicitLocale ?? newLocale));\n });\n return content;\n };\n }\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA2CA,MAAa,iBAMX,YACA,qBAMG;CACH,MAAM,SAASA,
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["getIntlayerClient","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\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: (callback: (content: any) => void) => WithOnChange<T>;\n};\n\n/**\n * Get the content for a raw dictionary (or qualified dictionary group) and\n * optionally subscribe to locale changes via the chainable `.onChange()`\n * method — mirroring the API of `react-intlayer`.\n *\n * The second argument is either a locale or a selector object (`{ item }`,\n * `{ variant }`, optionally combined with `locale`).\n *\n * @param dictionary - The raw dictionary (or qualified group) object.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The current content with an `.onChange()` method.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): WithOnChange<\n DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n >\n> => {\n const client = getIntlayerClient();\n\n const isSelector =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n const explicitLocale = isSelector\n ? (localeOrSelector as DictionarySelector).locale\n : (localeOrSelector as LocalesValues | undefined);\n\n const read = (locale: LocalesValues | undefined) =>\n isSelector\n ? getDictionary(dictionary, {\n ...(localeOrSelector as DictionarySelector),\n locale,\n } as A)\n : getDictionary(dictionary, locale as A);\n\n const content = read(explicitLocale ?? client.locale) as WithOnChange<any>;\n\n // A selector can resolve to null/array; only objects carry `.onChange`.\n if (content != null && typeof content === 'object') {\n content.onChange = (callback) => {\n client.subscribe((newLocale) => {\n callback(read(explicitLocale ?? newLocale));\n });\n return content;\n };\n }\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA2CA,MAAa,iBAMX,YACA,qBAMG;CACH,MAAM,SAASA,iDAAkB;CAEjC,MAAM,aACJ,QAAQ,IAAI,iCAAiC,WAC7C,OAAO,qBAAqB,YAC5B,qBAAqB;CACvB,MAAM,iBAAiB,aAClB,iBAAwC,SACxC;CAEL,MAAM,QAAQ,WACZ,aACIC,oCAAc,YAAY;EACxB,GAAI;EACJ;CACF,CAAM,IACNA,oCAAc,YAAY,MAAW;CAE3C,MAAM,UAAU,KAAK,kBAAkB,OAAO,MAAM;CAGpD,IAAI,WAAW,QAAQ,OAAO,YAAY,UACxC,QAAQ,YAAY,aAAa;EAC/B,OAAO,WAAW,cAAc;GAC9B,SAAS,KAAK,kBAAkB,SAAS,CAAC;EAC5C,CAAC;EACD,OAAO;CACT;CAGF,OAAO;AACT"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_getDictionary = require('../getDictionary.cjs');
|
|
4
3
|
const require_client_installIntlayer = require('./installIntlayer.cjs');
|
|
5
4
|
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 {\n getDictionarySelectorCacheKey,\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContentAsync,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n DictionarySelectorForKey,\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\n/** Resolved-content cache for qualified (collection/variant/meta) keys. */\nconst qualifiedCache = new Map<string, unknown>();\nconst qualifiedInflight = 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/** Placeholder proxy — safe for any property access while loading. */\nconst 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/**\n * Dynamically load and transform a dictionary (plain or qualified).\n *\n * For a qualified loader map (collection / variant, possibly\n * combined), only the chunk(s) the selector targets are loaded. For a plain\n * loader map, the locale chunk is loaded. The first call returns a placeholder\n * and triggers a background load; the client then notifies subscribers so the\n * render runs again with real content.\n *\n * @param dictionaryLoaders - Locale-keyed loader map, or a qualified loader map.\n * @param key - Dictionary key (used for cache namespacing).\n * @param localeOrSelector - Optional locale or selector.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = LocalesValues,\n>(\n dictionaryLoaders:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n): WithOnChange<DeepTransformContent<T['content']>> => {\n const client = getIntlayerClient();\n const defaultLocale = internationalization.defaultLocale;\n\n // --- Qualified loader map (collection / variant) ---\n if (\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryLoaders)\n ) {\n const loaderMap = dictionaryLoaders;\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(localeOrSelector);\n const selectorId = getDictionarySelectorCacheKey(selector);\n\n const buildKey = (locale: string) =>\n `${String(key)}.${locale}.${selectorId}`;\n const resolveContent = (locale: LocalesValues) =>\n resolveQualifiedDynamicContentAsync({\n loaderMap,\n key: String(key),\n locale,\n selector,\n transform: (dictionary) => getDictionary(dictionary, locale),\n });\n\n const currentLocale = (selectorLocale ??\n client.locale ??\n defaultLocale) as LocalesValues;\n const cacheKey = buildKey(currentLocale);\n\n const attachOnChange = (content: any) => {\n if (content != null && typeof content === 'object') {\n content.onChange = (callback: (c: any) => void) => {\n client.subscribe((newLocale) => {\n const locale = (selectorLocale ?? newLocale) as LocalesValues;\n const newKey = buildKey(locale);\n\n if (qualifiedCache.has(newKey)) {\n callback(qualifiedCache.get(newKey));\n return;\n }\n\n resolveContent(locale).then((resolved) => {\n qualifiedCache.set(newKey, resolved);\n callback(resolved);\n });\n });\n return content;\n };\n }\n return content;\n };\n\n if (qualifiedCache.has(cacheKey)) {\n return attachOnChange(qualifiedCache.get(cacheKey)) as any;\n }\n\n if (!qualifiedInflight.has(cacheKey)) {\n const promise = resolveContent(currentLocale).then((resolved) => {\n qualifiedCache.set(cacheKey, resolved);\n qualifiedInflight.delete(cacheKey);\n client.notify();\n });\n qualifiedInflight.set(cacheKey, promise);\n }\n\n return recursiveProxy;\n }\n\n // --- Plain locale-keyed loader map ---\n const locale =\n typeof localeOrSelector === 'string'\n ? (localeOrSelector as LocalesValues)\n : undefined;\n const currentLocale = (locale ?? client.locale ?? defaultLocale) as A;\n\n const cacheKey = `${String(key)}.${currentLocale}`;\n const loader = (dictionaryLoaders as Record<string, () => Promise<T>>)[\n currentLocale as string\n ];\n\n // --- Cache hit: return real content synchronously ---\n const cached = cache.get(cacheKey);\n if (cached) {\n const content = getDictionary(cached, currentLocale) as WithOnChange<\n DeepTransformContent<T['content']>\n >;\n\n content.onChange = (callback) => {\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(getDictionary(dict, newLocale as A) as any);\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 return recursiveProxy;\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 {\n getDictionarySelectorCacheKey,\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContentAsync,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n DictionarySelectorForKey,\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\n/** Resolved-content cache for qualified (collection/variant/meta) keys. */\nconst qualifiedCache = new Map<string, unknown>();\nconst qualifiedInflight = 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/** Placeholder proxy — safe for any property access while loading. */\nconst 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/**\n * Dynamically load and transform a dictionary (plain or qualified).\n *\n * For a qualified loader map (collection / variant, possibly\n * combined), only the chunk(s) the selector targets are loaded. For a plain\n * loader map, the locale chunk is loaded. The first call returns a placeholder\n * and triggers a background load; the client then notifies subscribers so the\n * render runs again with real content.\n *\n * @param dictionaryLoaders - Locale-keyed loader map, or a qualified loader map.\n * @param key - Dictionary key (used for cache namespacing).\n * @param localeOrSelector - Optional locale or selector.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = LocalesValues,\n>(\n dictionaryLoaders:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n): WithOnChange<DeepTransformContent<T['content']>> => {\n const client = getIntlayerClient();\n const defaultLocale = internationalization.defaultLocale;\n\n // --- Qualified loader map (collection / variant) ---\n if (\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryLoaders)\n ) {\n const loaderMap = dictionaryLoaders;\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(localeOrSelector);\n const selectorId = getDictionarySelectorCacheKey(selector);\n\n const buildKey = (locale: string) =>\n `${String(key)}.${locale}.${selectorId}`;\n const resolveContent = (locale: LocalesValues) =>\n resolveQualifiedDynamicContentAsync({\n loaderMap,\n key: String(key),\n locale,\n selector,\n transform: (dictionary) => getDictionary(dictionary, locale),\n });\n\n const currentLocale = (selectorLocale ??\n client.locale ??\n defaultLocale) as LocalesValues;\n const cacheKey = buildKey(currentLocale);\n\n const attachOnChange = (content: any) => {\n if (content != null && typeof content === 'object') {\n content.onChange = (callback: (c: any) => void) => {\n client.subscribe((newLocale) => {\n const locale = (selectorLocale ?? newLocale) as LocalesValues;\n const newKey = buildKey(locale);\n\n if (qualifiedCache.has(newKey)) {\n callback(qualifiedCache.get(newKey));\n return;\n }\n\n resolveContent(locale).then((resolved) => {\n qualifiedCache.set(newKey, resolved);\n callback(resolved);\n });\n });\n return content;\n };\n }\n return content;\n };\n\n if (qualifiedCache.has(cacheKey)) {\n return attachOnChange(qualifiedCache.get(cacheKey)) as any;\n }\n\n if (!qualifiedInflight.has(cacheKey)) {\n const promise = resolveContent(currentLocale).then((resolved) => {\n qualifiedCache.set(cacheKey, resolved);\n qualifiedInflight.delete(cacheKey);\n client.notify();\n });\n qualifiedInflight.set(cacheKey, promise);\n }\n\n return recursiveProxy;\n }\n\n // --- Plain locale-keyed loader map ---\n const locale =\n typeof localeOrSelector === 'string'\n ? (localeOrSelector as LocalesValues)\n : undefined;\n const currentLocale = (locale ?? client.locale ?? defaultLocale) as A;\n\n const cacheKey = `${String(key)}.${currentLocale}`;\n const loader = (dictionaryLoaders as Record<string, () => Promise<T>>)[\n currentLocale as string\n ];\n\n // --- Cache hit: return real content synchronously ---\n const cached = cache.get(cacheKey);\n if (cached) {\n const content = getDictionary(cached, currentLocale) as WithOnChange<\n DeepTransformContent<T['content']>\n >;\n\n content.onChange = (callback) => {\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(getDictionary(dict, newLocale as A) as any);\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 return recursiveProxy;\n};\n"],"mappings":";;;;;;;;AAqBA,MAAM,wBAAQ,IAAI,IAAwB;;AAG1C,MAAM,2BAAW,IAAI,IAA2B;;AAGhD,MAAM,iCAAiB,IAAI,IAAqB;AAChD,MAAM,oCAAoB,IAAI,IAA2B;AAEzD,MAAM,kBACJ,UACA,WACkB;CAClB,IAAI,MAAM,IAAI,QAAQ,GAAG,OAAO,QAAQ,QAAQ;CAChD,IAAI,SAAS,IAAI,QAAQ,GAAG,OAAO,SAAS,IAAI,QAAQ;CAExD,MAAM,UAAU,OAAO,CAAC,CAAC,MAAM,eAAe;EAC5C,MAAM,IAAI,UAAU,UAAU;EAC9B,SAAS,OAAO,QAAQ;CAC1B,CAAC;CAED,SAAS,IAAI,UAAU,OAAO;CAC9B,OAAO;AACT;;AAGA,MAAM,iBAAsB,IAAI,YAAY,CAAC,GAAG;CAC9C,MAAM,IAAI,SAAS;EACjB,IAAI,SAAS,OAAO,aAAa,aAAa;EAC9C,IAAI,SAAS,YAAY,aAAa;EACtC,IAAI,SAAS,WAAW,aAAa;EACrC,IAAI,SAAS,QAAQ,OAAO;EAC5B,IAAI,SAAS,YAAY,QAAQ,QAAa;EAC9C,OAAO;CACT;CACA,aAAa;AACf,CAAC;;;;;;;;;;;;;;AAeD,MAAa,wBAKX,mBAGA,KACA,qBACqD;CACrD,MAAM,SAASA,iDAAkB;CACjC,MAAM,gBAAgBC,4CAAqB;CAG3C,IACE,QAAQ,IAAI,iCAAiC,iFACjB,iBAAiB,GAC7C;EACA,MAAM,YAAY;EAClB,MAAM,EAAE,QAAQ,gBAAgB,+EACS,gBAAgB;EACzD,MAAM,qFAA2C,QAAQ;EAEzD,MAAM,YAAY,WAChB,GAAG,OAAO,GAAG,EAAE,GAAG,OAAO,GAAG;EAC9B,MAAM,kBAAkB,yFACc;GAClC;GACA,KAAK,OAAO,GAAG;GACf;GACA;GACA,YAAY,eAAeC,oCAAc,YAAY,MAAM;EAC7D,CAAC;EAEH,MAAM,gBAAiB,kBACrB,OAAO,UACP;EACF,MAAM,WAAW,SAAS,aAAa;EAEvC,MAAM,kBAAkB,YAAiB;GACvC,IAAI,WAAW,QAAQ,OAAO,YAAY,UACxC,QAAQ,YAAY,aAA+B;IACjD,OAAO,WAAW,cAAc;KAC9B,MAAM,SAAU,kBAAkB;KAClC,MAAM,SAAS,SAAS,MAAM;KAE9B,IAAI,eAAe,IAAI,MAAM,GAAG;MAC9B,SAAS,eAAe,IAAI,MAAM,CAAC;MACnC;KACF;KAEA,eAAe,MAAM,CAAC,CAAC,MAAM,aAAa;MACxC,eAAe,IAAI,QAAQ,QAAQ;MACnC,SAAS,QAAQ;KACnB,CAAC;IACH,CAAC;IACD,OAAO;GACT;GAEF,OAAO;EACT;EAEA,IAAI,eAAe,IAAI,QAAQ,GAC7B,OAAO,eAAe,eAAe,IAAI,QAAQ,CAAC;EAGpD,IAAI,CAAC,kBAAkB,IAAI,QAAQ,GAAG;GACpC,MAAM,UAAU,eAAe,aAAa,CAAC,CAAC,MAAM,aAAa;IAC/D,eAAe,IAAI,UAAU,QAAQ;IACrC,kBAAkB,OAAO,QAAQ;IACjC,OAAO,OAAO;GAChB,CAAC;GACD,kBAAkB,IAAI,UAAU,OAAO;EACzC;EAEA,OAAO;CACT;CAOA,MAAM,iBAHJ,OAAO,qBAAqB,WACvB,mBACD,WAC2B,OAAO,UAAU;CAElD,MAAM,WAAW,GAAG,OAAO,GAAG,EAAE,GAAG;CACnC,MAAM,SAAU,kBACd;CAIF,MAAM,SAAS,MAAM,IAAI,QAAQ;CACjC,IAAI,QAAQ;EACV,MAAM,UAAUA,oCAAc,QAAQ,aAAa;EAInD,QAAQ,YAAY,aAAa;GAE/B,OAAO,WAAW,cAAc;IAC9B,MAAM,SAAS,GAAG,OAAO,GAAG,EAAE,GAAG;IACjC,MAAM,YACJ,kBACA;IAEF,IAAI,CAAC,WAAW;IAEhB,eAAe,QAAQ,SAAS,CAAC,CAAC,WAAW;KAC3C,MAAM,OAAO,MAAM,IAAI,MAAM;KAC7B,IAAI,MACF,SAASA,oCAAc,MAAM,SAAc,CAAQ;IAEvD,CAAC;GACH,CAAC;GAED,OAAO;EACT;EAEA,OAAO;CACT;CAGA,IAAI,QACF,eAAe,UAAU,MAAM,CAAC,CAAC,WAAW;EAC1C,OAAO,OAAO;CAChB,CAAC;CAGH,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["getIntlayerClient","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\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 * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `locale` composes with any selector and overrides the current locale\n *\n * The function returns the current content **directly** (same shape as\n * `getIntlayer(key)`), plus the `.onChange()` helper.\n *\n * @param key - Dictionary key registered in your intlayer content files.\n * @param localeOrSelector - Optional locale or selector.\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 * const content = useIntlayer('homepage');\n * const faq2 = useIntlayer('faq', { item: 2 });\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): WithOnChange<\n DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>\n> => {\n const client = getIntlayerClient();\n\n const isSelector =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n const explicitLocale = isSelector\n ? (localeOrSelector as DictionarySelector).locale\n : (localeOrSelector as LocalesValues | undefined);\n\n const read = (locale: LocalesValues | undefined) =>\n isSelector\n ? getIntlayer(key, {\n ...(localeOrSelector as DictionarySelector),\n locale,\n } as A)\n : getIntlayer(key, locale as A);\n\n const content = read(explicitLocale ?? client.locale) as WithOnChange<any>;\n\n // A selector can resolve to null/array; only objects carry `.onChange`.\n if (content != null && typeof content === 'object') {\n content.onChange = (callback) => {\n client.subscribe((newLocale) => {\n callback(read(explicitLocale ?? newLocale));\n });\n return content;\n };\n }\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,eAIX,KACA,qBAGG;CACH,MAAM,SAASA,
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["getIntlayerClient","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\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 * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `locale` composes with any selector and overrides the current locale\n *\n * The function returns the current content **directly** (same shape as\n * `getIntlayer(key)`), plus the `.onChange()` helper.\n *\n * @param key - Dictionary key registered in your intlayer content files.\n * @param localeOrSelector - Optional locale or selector.\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 * const content = useIntlayer('homepage');\n * const faq2 = useIntlayer('faq', { item: 2 });\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): WithOnChange<\n DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>\n> => {\n const client = getIntlayerClient();\n\n const isSelector =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n const explicitLocale = isSelector\n ? (localeOrSelector as DictionarySelector).locale\n : (localeOrSelector as LocalesValues | undefined);\n\n const read = (locale: LocalesValues | undefined) =>\n isSelector\n ? getIntlayer(key, {\n ...(localeOrSelector as DictionarySelector),\n locale,\n } as A)\n : getIntlayer(key, locale as A);\n\n const content = read(explicitLocale ?? client.locale) as WithOnChange<any>;\n\n // A selector can resolve to null/array; only objects carry `.onChange`.\n if (content != null && typeof content === 'object') {\n content.onChange = (callback) => {\n client.subscribe((newLocale) => {\n callback(read(explicitLocale ?? newLocale));\n });\n return content;\n };\n }\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,eAIX,KACA,qBAGG;CACH,MAAM,SAASA,iDAAkB;CAEjC,MAAM,aACJ,QAAQ,IAAI,iCAAiC,WAC7C,OAAO,qBAAqB,YAC5B,qBAAqB;CACvB,MAAM,iBAAiB,aAClB,iBAAwC,SACxC;CAEL,MAAM,QAAQ,WACZ,aACIC,gCAAY,KAAK;EACf,GAAI;EACJ;CACF,CAAM,IACNA,gCAAY,KAAK,MAAW;CAElC,MAAM,UAAU,KAAK,kBAAkB,OAAO,MAAM;CAGpD,IAAI,WAAW,QAAQ,OAAO,YAAY,UACxC,QAAQ,YAAY,aAAa;EAC/B,OAAO,WAAW,cAAc;GAC9B,SAAS,KAAK,kBAAkB,SAAS,CAAC;EAC5C,CAAC;EACD,OAAO;CACT;CAGF,OAAO;AACT"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('./installIntlayer.cjs');
|
|
4
3
|
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
5
4
|
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,CAAC,MAAuB;CACxE,MAAM,SAASA,iDAAkB;CACjC,MAAM,EAAE,eAAe,SAAS,qBAC9BC,+CAAwB,CAAC;CAE3B,MAAM,aAAa,cAAmC;EACpD,IAAI,EAAE,oBAAoB,CAAC,EAAC,CAAE,IAAI,MAAM,CAAC,CAAC,SAAS,SAAS,GAAG;GAC7D,QAAQ,MAAM,WAAW,UAAU,oBAAoB;GACvD;EACF;EAEA,OAAO,UAAU,SAAS;EAE1B,mDACE,WACA,MAAM,mBAAmB,OAAO,mBAAmB,IACrD;EAEA,MAAM,iBAAiB,SAA4B;CACrD;CAEA,OAAO;EACL,QAAQ,OAAO;EACA;EACf,kBAAmB,oBAAoB,CAAC;EACxC;EACA,YAAY,aAAa,OAAO,UAAU,QAAQ;CACpD;AACF"}
|
|
@@ -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,yCAAoB;;;;AAK9E,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,uEAEuB,QAAQ;CAC7B,GAAGA;CACH;AACF,CAAC;;;;AAKH,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,oBAA8B;CAC7D,MAAM,wDAA8B;EAClC,GAAGA;EACH;CACF,CAAC;CAED,OAAO;EACL,eAAe,QAAQ,UAAU;EACjC,kBAAkB,QAAQ;CAC5B;AACF;;;;AAKA,MAAa,kBAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePathname.cjs","names":[],"sources":["../../../src/client/usePathname.ts"],"sourcesContent":["import { getPathWithoutLocale } from '@intlayer/core/localization';\n\nexport type UsePathnameResult = {\n /** Current pathname without the locale prefix. */\n pathname: string;\n /**\n * Subscribe to pathname changes triggered by browser navigation.\n *\n * @param callback - Called with the new pathname on every `popstate` event.\n * @returns A cleanup function that removes the event listener.\n */\n subscribe: (callback: (pathname: string) => void) => () => void;\n};\n\n/**\n * Returns the current pathname with the locale segment removed, plus a\n * `subscribe` function to react to browser navigation changes.\n *\n * Falls back to an empty string during server-side rendering.\n *\n * @returns An object with the current pathname and a subscribe function.\n *\n * @example\n * ```ts\n * import { usePathname } from 'vanilla-intlayer';\n *\n * const { pathname, subscribe } = usePathname();\n *\n * const unsubscribe = subscribe((newPathname) => {\n * document.querySelector('.active')?.classList.remove('active');\n * document.querySelector(`[href=\"${newPathname}\"]`)?.classList.add('active');\n * });\n * ```\n */\nexport const usePathname = (): UsePathnameResult => {\n const getPathname = (): string =>\n typeof window !== 'undefined'\n ? getPathWithoutLocale(window.location.pathname)\n : '';\n\n const subscribe = (callback: (pathname: string) => void): (() => void) => {\n const handleLocationChange = (): void => callback(getPathname());\n window.addEventListener('popstate', handleLocationChange);\n return () => window.removeEventListener('popstate', handleLocationChange);\n };\n\n return {\n pathname: getPathname(),\n subscribe,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePathname.cjs","names":[],"sources":["../../../src/client/usePathname.ts"],"sourcesContent":["import { getPathWithoutLocale } from '@intlayer/core/localization';\n\nexport type UsePathnameResult = {\n /** Current pathname without the locale prefix. */\n pathname: string;\n /**\n * Subscribe to pathname changes triggered by browser navigation.\n *\n * @param callback - Called with the new pathname on every `popstate` event.\n * @returns A cleanup function that removes the event listener.\n */\n subscribe: (callback: (pathname: string) => void) => () => void;\n};\n\n/**\n * Returns the current pathname with the locale segment removed, plus a\n * `subscribe` function to react to browser navigation changes.\n *\n * Falls back to an empty string during server-side rendering.\n *\n * @returns An object with the current pathname and a subscribe function.\n *\n * @example\n * ```ts\n * import { usePathname } from 'vanilla-intlayer';\n *\n * const { pathname, subscribe } = usePathname();\n *\n * const unsubscribe = subscribe((newPathname) => {\n * document.querySelector('.active')?.classList.remove('active');\n * document.querySelector(`[href=\"${newPathname}\"]`)?.classList.add('active');\n * });\n * ```\n */\nexport const usePathname = (): UsePathnameResult => {\n const getPathname = (): string =>\n typeof window !== 'undefined'\n ? getPathWithoutLocale(window.location.pathname)\n : '';\n\n const subscribe = (callback: (pathname: string) => void): (() => void) => {\n const handleLocationChange = (): void => callback(getPathname());\n window.addEventListener('popstate', handleLocationChange);\n return () => window.removeEventListener('popstate', handleLocationChange);\n };\n\n return {\n pathname: getPathname(),\n subscribe,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,oBAAuC;CAClD,MAAM,oBACJ,OAAO,WAAW,oEACO,OAAO,SAAS,QAAQ,IAC7C;CAEN,MAAM,aAAa,aAAuD;EACxE,MAAM,6BAAmC,SAAS,YAAY,CAAC;EAC/D,OAAO,iBAAiB,YAAY,oBAAoB;EACxD,aAAa,OAAO,oBAAoB,YAAY,oBAAoB;CAC1E;CAEA,OAAO;EACL,UAAU,YAAY;EACtB;CACF;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('./installIntlayer.cjs');
|
|
4
3
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
4
|
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;CACxC,IAAI,OAAO,WAAW,eAAe,CAACA,gCAAS,SAAS;CAExD,MAAM,WAAW,OAAO,SAAS;CACjC,MAAM,6DACJ,UACA,QACAA,gCAAS,OACX;CAEA,IAAI,cAAc,eAAe,UAC/B,OAAO,QAAQ,aACb,OAAO,QAAQ,OACf,IACA,aAAa,OAAO,SAAS,SAAS,OAAO,SAAS,IACxD;AAEJ;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,sBAAoC;CAC/C,MAAM,SAASC,iDAAkB;CAGjC,QAAQ,OAAO,MAAM;CAErB,OAAO,OAAO,WAAW,cAAc;EACrC,QAAQ,SAAS;CACnB,CAAC;AACH"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
4
3
|
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
5
4
|
|
|
@@ -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;CAC3C,IAAI,QAAQ,IAAI,4BAA4B,WAAW,CAACA,sCACtD,aAAa,CAAC;CAEhB,IAAI,oBAAyC;CAC7C,IAAI,UAAU;CAEd,OAAO,mBAAmB,CAAC,MAAM,EAAE,uBAAuB;EACxD,IAAI,SAAS;EACb,MAAM,UAA8B,iBAAiB;EACrD,MAAM,SAASC,iDAAkB;EAEjC,QAAQ,cAAc,IAAI,OAAO,MAAgB;EAEjD,oBAAoB,OAAO,WAAW,cAAc;GAClD,QAAQ,cAAc,IAAI,SAAmB;EAC/C,CAAC;CACH,CAAC;CAED,aAAa;EACX,UAAU;EACV,oBAAoB;EACpB,OAAO,mBAAmB,CAAC,MAAM,EAAE,uBAAuB;GACxD,iBAAiB;EACnB,CAAC;CACH;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
4
3
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
5
4
|
|
|
@@ -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,iDAAkB;CAEjC,QAAQ,GAAG,gDACD,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU,OAAO;CACpC,CAAC;AACL"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
4
3
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
5
4
|
|
|
@@ -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,iDAAkB;CAEjC,QAAQ,GAAG,iDACA,KAAK,IAAI;EAChB,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU,OAAO;CACpC,CAAC;AACL"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
4
3
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
5
4
|
|
|
@@ -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,iDAAkB;CAEjC,QAAQ,GAAG,SAAkC;EAC3C,MAAM,UACJ,OAAO,KAAK,OAAO,WACf;GAAE,GAAGC,kCAAQ,KAAK;GAAK,QAAQ,OAAO;EAAO,IAC7C;GAAE,GAAG,KAAK;GAAI,QAAQ,KAAK,EAAE,EAAE,UAAU,OAAO;EAAO;EAE7D,2CAAY,KAAK,IAAI,OAAqC;CAC5D;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
4
3
|
let _intlayer_core_utils = require("@intlayer/core/utils");
|
|
5
4
|
|
|
@@ -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,iDAAkB;CAGjC,OAAO;EACL,yCAHoB,UAAU,OAAO,MAGlC;EACH,YAAY,aACV,OAAO,WAAW,cAAc;GAC9B,4CAAkB,UAAU,SAAS,CAAC;EACxC,CAAC;CACL;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
4
3
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
5
4
|
|
|
@@ -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,iDAAkB;CAEjC,QAAQ,GAAG,6CACJ,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU,OAAO;CACpC,CAAC;AACL"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
4
3
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
5
4
|
|
|
@@ -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,iDAAkB;CAEjC,QAAQ,GAAG,+CACF,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU,OAAO;CACpC,CAAC;AACL"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
4
3
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
5
4
|
|
|
@@ -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,iDAAkB;CAEjC,QAAQ,GAAG,mDACE,KAAK,IAAI;EAClB,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU,OAAO;CACpC,CAAC;AACL"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
4
3
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
5
4
|
|
|
@@ -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,iDAAkB;CAEjC,QAAQ,GAAG,qDACI,KAAK,IAAI,KAAK,IAAI;EAC7B,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU,OAAO;CACpC,CAAC;AACL"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_client_installIntlayer = require('../client/installIntlayer.cjs');
|
|
4
3
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
5
4
|
|
|
@@ -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,iDAAkB;CAEjC,QAAQ,GAAG,8CACH,KAAK,IAAI;EACb,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU,OAAO;CACpC,CAAC;AACL"}
|
|
@@ -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 {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Transforms a dictionary (or qualified dictionary group) and returns its\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getDictionaryCore(\n dictionary,\n localeOrSelector,\n getPlugins(locale)\n ) as any;\n};\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 {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Transforms a dictionary (or qualified dictionary group) and returns its\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getDictionaryCore(\n dictionary,\n localeOrSelector,\n getPlugins(locale)\n ) as any;\n};\n"],"mappings":";;;;;;;;;;AAmBA,MAAa,iBAMX,YACA,qBAIG;CAOH,qDACE,YACA,kBACAA,2BARA,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,gBAMa,CACnB;AACF"}
|
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 DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getIntlayerCore(key, localeOrSelector, getPlugins(locale)) as any;\n};\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 DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getIntlayerCore(key, localeOrSelector, getPlugins(locale)) as any;\n};\n"],"mappings":";;;;;;;;;;AAgBA,MAAa,eAIX,KACA,qBAIG;CAOH,mDAAuB,KAAK,kBAAkBA,2BAL5C,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,gBAGyD,CAAC;AAClE"}
|
|
@@ -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,CAAC,MAChB;;;;;AAMb,MAAa,mBAAmB,EAC9B,eACmB,CAAC,MAAqC;CACzD,MAAM,UAAUA,yCAAQ;CAExB,QAAQ,YACN,QAAQ,WAAW,SAAS,EAAE,WAAW,CAAsB;AACnE"}
|
|
@@ -80,7 +80,8 @@ const useHTML = () => {
|
|
|
80
80
|
*/
|
|
81
81
|
const installIntlayerHTMLDynamic = async (loader) => {
|
|
82
82
|
if (instance) return instance;
|
|
83
|
-
|
|
83
|
+
const pluginOptions = await loader();
|
|
84
|
+
return installIntlayerHTML(pluginOptions);
|
|
84
85
|
};
|
|
85
86
|
|
|
86
87
|
//#endregion
|
|
@@ -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;CACzB,IAAI,UAAU,OAAO;CACrB,WAAW,EAAE,WAAW;CACxB,OAAO;AACT;;;;;;;;;;;;;;;AAgBA,MAAa,uBACX,kBACyB;CACzB,IAAI;CAEJ,IAAI,OAAO,kBAAkB,YAC3B,aAAa;MACR;EACL,MAAM,EAAE,YAAY,YAAY,iBAAiB,iBAAiB,CAAC;EAEnE,IAAI,cACF,aAAa;OAEb,cAAc,SAAS,cAAc;GAMnC,MAAM,qBAJJ,aACA,OAAO,cAAc,YACrB,gBAAgB,YAGb,UAAgC,aAChC;GAEL,MAAM,mBAAmB;IACvB,GAAI,cAAc,CAAC;IACnB,GAAI,sBAAsB,CAAC;GAC7B;GAEA,IAAI,CAAC,OAAO,KAAK,gBAAgB,CAAC,CAAC,QAAQ,OAAO;GAIlD,OAAO;EACT;CAEJ;CAEA,OAAO,yBAAyB,UAAU;AAC5C;;;;;;AAOA,MAAa,gBAAsC;CACjD,IAAI,UAAU,OAAO;CACrB,OAAO,EAAE,aAAa,YAAY,QAAQ;AAC5C;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,6BAA6B,OACxC,WACkC;CAClC,IAAI,UAAU,OAAO;CACrB,MAAM,gBAAgB,MAAM,OAAO;CACnC,OAAO,oBAAoB,aAAa;AAC1C"}
|
|
@@ -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,CAAC,MACf;CAOX,OAAOA,0CAAgB,SAAS;EAL9B;EACA;EACA;EACA;CAEoC,CAAC;AACzC;;;;;AAMA,MAAa,uBACX,QAA6B,CAAC,MACuC;CACrE,MAAM,WAAWC,qDAAY;CAE7B,QAAQ,YACN,SAAS,eACP,SACA;EACE,YAAY,MAAM;EAClB,aAAa,MAAM;EACnB,qBAAqB,MAAM;EAC3B,WAAW,MAAM;CACnB,GACA,MAAM,YACN,MAAM,OACR;AACJ"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_markdown_runtime = require('./runtime.cjs');
|
|
4
3
|
let _intlayer_core_markdown = require("@intlayer/core/markdown");
|
|
5
4
|
|
|
@@ -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 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":"
|
|
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,CAAC,MACjB;CACnB,MAAM,EACJ,YACA,qBACA,WACA,SACA,GAAG,oBACD;CAUJ,kDAAyB,UAAU;EAPjC,SAASA;EACT;EACA;EACW;EACX;CAGmC,GAAG,eAAe;AACzD;;;;;;;;;;;;;;;;;AAkBA,MAAa,mBACX,QAAiC,IACjC,UAAmC,CAAC,MACzB;CACX,IAAI,OAAO,UAAU,UACnB,uDAA0B,OAAOA,kCAAgB,OAAO;CAG1D,MAAM,EACJ,YACA,qBACA,WACA,SACA,GAAG,oBACD;CAUJ,sDAA6B,OAAO;EAPlC,SAASA;EACT;EACA;EACW;EACX;CAGoC,GAAG,eAAe;AAC1D"}
|
|
@@ -87,7 +87,8 @@ const useMarkdown = () => {
|
|
|
87
87
|
*/
|
|
88
88
|
const installIntlayerMarkdownDynamic = async (loader) => {
|
|
89
89
|
if (instance) return instance;
|
|
90
|
-
|
|
90
|
+
const pluginOptions = await loader();
|
|
91
|
+
return installIntlayerMarkdown(pluginOptions);
|
|
91
92
|
};
|
|
92
93
|
|
|
93
94
|
//#endregion
|