vanilla-intlayer 8.9.7 → 8.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/cjs/client/installIntlayer.cjs.map +1 -1
  2. package/dist/cjs/client/useDictionary.cjs.map +1 -1
  3. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
  4. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  5. package/dist/cjs/client/useLocale.cjs.map +1 -1
  6. package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
  7. package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
  8. package/dist/cjs/editor/useEditor.cjs.map +1 -1
  9. package/dist/cjs/format/useCompact.cjs.map +1 -1
  10. package/dist/cjs/format/useCurrency.cjs.map +1 -1
  11. package/dist/cjs/format/useDate.cjs.map +1 -1
  12. package/dist/cjs/format/useIntl.cjs.map +1 -1
  13. package/dist/cjs/format/useList.cjs.map +1 -1
  14. package/dist/cjs/format/useNumber.cjs.map +1 -1
  15. package/dist/cjs/format/usePercentage.cjs.map +1 -1
  16. package/dist/cjs/format/useRelativeTime.cjs.map +1 -1
  17. package/dist/cjs/format/useUnit.cjs.map +1 -1
  18. package/dist/cjs/getDictionary.cjs.map +1 -1
  19. package/dist/cjs/getIntlayer.cjs.map +1 -1
  20. package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
  21. package/dist/cjs/html/installIntlayerHTML.cjs.map +1 -1
  22. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
  23. package/dist/cjs/markdown/compiler.cjs.map +1 -1
  24. package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -1
  25. package/dist/cjs/markdown/runtime.cjs.map +1 -1
  26. package/dist/cjs/plugins.cjs.map +1 -1
  27. package/dist/cjs/renderIntlayerNode.cjs.map +1 -1
  28. package/dist/esm/client/installIntlayer.mjs.map +1 -1
  29. package/dist/esm/client/useDictionary.mjs.map +1 -1
  30. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
  31. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  32. package/dist/esm/client/useLocale.mjs.map +1 -1
  33. package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
  34. package/dist/esm/client/useRewriteURL.mjs.map +1 -1
  35. package/dist/esm/editor/useEditor.mjs.map +1 -1
  36. package/dist/esm/format/useCompact.mjs.map +1 -1
  37. package/dist/esm/format/useCurrency.mjs.map +1 -1
  38. package/dist/esm/format/useDate.mjs.map +1 -1
  39. package/dist/esm/format/useIntl.mjs.map +1 -1
  40. package/dist/esm/format/useList.mjs.map +1 -1
  41. package/dist/esm/format/useNumber.mjs.map +1 -1
  42. package/dist/esm/format/usePercentage.mjs.map +1 -1
  43. package/dist/esm/format/useRelativeTime.mjs.map +1 -1
  44. package/dist/esm/format/useUnit.mjs.map +1 -1
  45. package/dist/esm/getDictionary.mjs.map +1 -1
  46. package/dist/esm/getIntlayer.mjs.map +1 -1
  47. package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
  48. package/dist/esm/html/installIntlayerHTML.mjs.map +1 -1
  49. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
  50. package/dist/esm/markdown/compiler.mjs.map +1 -1
  51. package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -1
  52. package/dist/esm/markdown/runtime.mjs.map +1 -1
  53. package/dist/esm/plugins.mjs.map +1 -1
  54. package/dist/esm/renderIntlayerNode.mjs.map +1 -1
  55. package/dist/types/client/installIntlayer.d.ts.map +1 -1
  56. package/dist/types/client/useDictionary.d.ts.map +1 -1
  57. package/dist/types/client/useIntlayer.d.ts.map +1 -1
  58. package/dist/types/client/useLocale.d.ts.map +1 -1
  59. package/dist/types/client/useLocaleStorage.d.ts +4 -5
  60. package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
  61. package/dist/types/client/useRewriteURL.d.ts.map +1 -1
  62. package/dist/types/editor/useEditor.d.ts.map +1 -1
  63. package/dist/types/format/useCompact.d.ts.map +1 -1
  64. package/dist/types/format/useCurrency.d.ts.map +1 -1
  65. package/dist/types/format/useDate.d.ts.map +1 -1
  66. package/dist/types/format/useIntl.d.ts.map +1 -1
  67. package/dist/types/format/useList.d.ts.map +1 -1
  68. package/dist/types/format/useNumber.d.ts.map +1 -1
  69. package/dist/types/format/usePercentage.d.ts.map +1 -1
  70. package/dist/types/format/useRelativeTime.d.ts.map +1 -1
  71. package/dist/types/format/useUnit.d.ts.map +1 -1
  72. package/dist/types/html/HTMLRenderer.d.ts.map +1 -1
  73. package/dist/types/html/installIntlayerHTML.d.ts.map +1 -1
  74. package/dist/types/html/types.d.ts.map +1 -1
  75. package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
  76. package/dist/types/markdown/compiler.d.ts.map +1 -1
  77. package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -1
  78. package/dist/types/markdown/runtime.d.ts.map +1 -1
  79. package/dist/types/plugins.d.ts.map +1 -1
  80. package/package.json +7 -7
@@ -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":";;;;;;;AAOA,IAAa,iBAAb,MAA4B;CAC1B,AAAQ;CACR,AAAQ,6BAAkC,IAAI,KAAK;CACnD;CAEA,YAAY,QAAwB,kBAAkB,MAAM;EAC1D,MAAM,EAAE,kBAAkBA,+CAAwB,EAAE;EAEpD,oDAAuB;EAEvB,KAAK,UACF,UAA6B;EAChC,KAAK,kBAAkB;;CAGzB,IAAI,SAAwB;EAC1B,OAAO,KAAK;;CAGd,UAAU,WAAgC;EACxC,KAAK,UAAU;EACf,KAAK,MAAM,YAAY,KAAK,YAC1B,SAAS,UAAU;;CAIvB,UAAU,UAAsC;EAC9C,KAAK,WAAW,IAAI,SAAS;EAC7B,aAAa;GACX,KAAK,WAAW,OAAO,SAAS;;;;;;;CAQpC,SAAe;EACb,KAAK,MAAM,YAAY,KAAK,YAC1B,SAAS,KAAK,QAAQ;;;;;;AAQ5B,IAAI,WAAkC;;;;AAKtC,MAAa,wBACX,QACA,kBAAkB,SACC;CACnB,IAAI,UAAU,OAAO;CAErB,WAAW,IAAI,eAAe,QAAQ,gBAAgB;CACtD,OAAO;;;;;AAMT,MAAa,0BAA0C;CACrD,IAAI,CAAC,UACH,WAAW,IAAI,gBAAgB;CAEjC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCT,MAAa,mBAAmB,EAC9B,QACA,oBAIE,EAAE,KAAqB;CACzB,MAAM,SAAS,qBAAqB,QAAQ,gBAAgB;CAE5D,oCAAW;CAEX,OAAO"}
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 { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\n\nexport type WithOnChange<T> = T & {\n /**\n * Subscribe to locale changes. The callback receives the fresh content\n * whenever the active locale changes. Returns the content object itself\n * for convenient one-liner patterns:\n *\n * ```ts\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p')!.textContent = String(c.greeting);\n * });\n * ```\n */\n onChange: (\n callback: <T extends Dictionary, L extends LocalesValues>(\n content: DeepTransformContent<T['content'], L>\n ) => void\n ) => WithOnChange<T>;\n};\n\n/**\n * Get the translated content for a raw dictionary object and optionally\n * subscribe to locale changes via the chainable `.onChange()` method —\n * mirroring the API of `react-intlayer`.\n *\n * Unlike `useIntlayer` (which takes a registered key), this function accepts a\n * dictionary object directly — useful for dictionaries loaded asynchronously\n * or defined inline.\n *\n * The function returns the current content **directly** (same shape as\n * `getDictionary(dict)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useDictionary(myDict);\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useDictionary(myDict);\n * const content = useDictionary(myDict).onChange((c) => render(c));\n * ```\n *\n * @param dictionary - The raw dictionary object.\n * @param locale - Optional locale override.\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import myDict from './myDictionary.content';\n * import { installIntlayer, useDictionary } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p').textContent = String(c.greeting);\n * });\n *\n * document.querySelector('p').textContent = String(content.greeting);\n * ```\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const content = getDictionary(\n dictionary,\n (locale ?? client.locale) as L\n ) as WithOnChange<DeepTransformContent<T['content'], L>>;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n client.subscribe((newLocale) => {\n callback(getDictionary(dictionary, (locale ?? newLocale) as L));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,iBAIX,YACA,WACwD;CACxD,MAAM,SAASA,kDAAmB;CAClC,MAAM,UAAUC,oCACd,YACC,UAAU,OAAO,OACnB;CAED,QAAQ,YACN,aACG;EACH,OAAO,WAAW,cAAc;GAC9B,SAASA,oCAAc,YAAa,UAAU,UAAgB,CAAC;IAC/D;EACF,OAAO;;CAGT,OAAO"}
1
+ {"version":3,"file":"useDictionary.cjs","names":["getIntlayerClient","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\n\nexport type WithOnChange<T> = T & {\n /**\n * Subscribe to locale changes. The callback receives the fresh content\n * whenever the active locale changes. Returns the content object itself\n * for convenient one-liner patterns:\n *\n * ```ts\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p')!.textContent = String(c.greeting);\n * });\n * ```\n */\n onChange: (\n callback: <T extends Dictionary, L extends LocalesValues>(\n content: DeepTransformContent<T['content'], L>\n ) => void\n ) => WithOnChange<T>;\n};\n\n/**\n * Get the translated content for a raw dictionary object and optionally\n * subscribe to locale changes via the chainable `.onChange()` method —\n * mirroring the API of `react-intlayer`.\n *\n * Unlike `useIntlayer` (which takes a registered key), this function accepts a\n * dictionary object directly — useful for dictionaries loaded asynchronously\n * or defined inline.\n *\n * The function returns the current content **directly** (same shape as\n * `getDictionary(dict)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useDictionary(myDict);\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useDictionary(myDict);\n * const content = useDictionary(myDict).onChange((c) => render(c));\n * ```\n *\n * @param dictionary - The raw dictionary object.\n * @param locale - Optional locale override.\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import myDict from './myDictionary.content';\n * import { installIntlayer, useDictionary } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p').textContent = String(c.greeting);\n * });\n *\n * document.querySelector('p').textContent = String(content.greeting);\n * ```\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const content = getDictionary(\n dictionary,\n (locale ?? client.locale) as L\n ) as WithOnChange<DeepTransformContent<T['content'], L>>;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n client.subscribe((newLocale) => {\n callback(getDictionary(dictionary, (locale ?? newLocale) as L));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,iBAIX,YACA,WACwD;CACxD,MAAM,SAASA,iDAAkB;CACjC,MAAM,UAAUC,oCACd,YACC,UAAU,OAAO,MACpB;CAEA,QAAQ,YACN,aACG;EACH,OAAO,WAAW,cAAc;GAC9B,SAASA,oCAAc,YAAa,UAAU,SAAe,CAAC;EAChE,CAAC;EACD,OAAO;CACT;CAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionaryDynamic.cjs","names":["getIntlayerClient","internationalization","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\nimport type { WithOnChange } from './useDictionary';\n\n/** Simple in-memory cache shared across all calls in the same page. */\nconst cache = new Map<string, Dictionary>();\n\n/** Tracks in-flight loads to avoid duplicate fetches. */\nconst inflight = new Map<string, Promise<void>>();\n\nconst loadDictionary = <T extends Dictionary>(\n cacheKey: string,\n loader: () => Promise<T>\n): Promise<void> => {\n if (cache.has(cacheKey)) return Promise.resolve();\n if (inflight.has(cacheKey)) return inflight.get(cacheKey)!;\n\n const promise = loader().then((dictionary) => {\n cache.set(cacheKey, dictionary);\n inflight.delete(cacheKey);\n });\n\n inflight.set(cacheKey, promise);\n return promise;\n};\n\n/**\n * Dynamically load and transform a locale-keyed dictionary.\n *\n * Works like `useIntlayer` / `useDictionary` but accepts a locale-keyed map\n * of lazy loaders instead of a pre-imported dictionary. Call it inside your\n * render function — the first call triggers a background fetch and returns\n * placeholder values; when the load completes the client notifies all\n * subscribers (including your render loop) so the render runs again with real\n * content. Subsequent calls for the same locale return immediately from cache.\n *\n * Locale switches follow the same two-phase pattern: placeholder on first\n * render, real content after the locale bundle loads.\n *\n * @param dictionaryLoaders - Locale-keyed map of `() => Promise<Dictionary>`.\n * @param key - Dictionary key (used for cache namespacing).\n * @param locale - Optional locale override.\n *\n * @example\n * ```ts\n * import dynDic from '../.intlayer/dynamic_dictionary/app.mjs';\n *\n * const render = () => {\n * const content = useDictionaryDynamic(dynDic, 'app');\n * document.querySelector('h1')!.textContent = String(content.title);\n * };\n *\n * render();\n * getIntlayerClient().subscribe(() => render());\n * ```\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n L extends LocalesValues = LocalesValues,\n>(\n dictionaryLoaders: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const currentLocale = (locale ??\n client.locale ??\n internationalization.defaultLocale) as L;\n\n const cacheKey = `${String(key)}.${currentLocale}`;\n const loader = (dictionaryLoaders as Record<string, () => Promise<T>>)[\n currentLocale\n ];\n\n // --- Cache hit: return real content synchronously ---\n const cached = cache.get(cacheKey);\n if (cached) {\n const content = getDictionary(cached as T, currentLocale) as WithOnChange<\n DeepTransformContent<T['content'], L>\n >;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n // Re-fire whenever content reloads (locale change → new cache entry).\n client.subscribe((newLocale) => {\n const newKey = `${String(key)}.${newLocale}`;\n const newLoader = (\n dictionaryLoaders as Record<string, () => Promise<T>>\n )[newLocale];\n\n if (!newLoader) return;\n\n loadDictionary(newKey, newLoader).then(() => {\n const dict = cache.get(newKey);\n if (dict) {\n callback(\n getDictionary(dict as T, newLocale as L) as DeepTransformContent<\n T['content'],\n L\n >\n );\n }\n });\n });\n\n return content;\n };\n\n return content;\n }\n\n // --- Cache miss: kick off background load, then notify to re-render ---\n if (loader) {\n loadDictionary(cacheKey, loader).then(() => {\n client.notify();\n });\n }\n\n // Placeholder proxy — safe for any property access while loading.\n const recursiveProxy: any = new Proxy(() => {}, {\n get: (_t, prop) => {\n if (prop === Symbol.toPrimitive) return () => '';\n if (prop === 'toString') return () => '';\n if (prop === 'valueOf') return () => '';\n if (prop === 'then') return undefined; // not a Promise\n if (prop === 'onChange') return (_cb: any) => recursiveProxy;\n return recursiveProxy;\n },\n apply: () => recursiveProxy,\n });\n\n return recursiveProxy as WithOnChange<DeepTransformContent<T['content'], L>>;\n};\n"],"mappings":";;;;;;;;AAaA,MAAM,wBAAQ,IAAI,KAAyB;;AAG3C,MAAM,2BAAW,IAAI,KAA4B;AAEjD,MAAM,kBACJ,UACA,WACkB;CAClB,IAAI,MAAM,IAAI,SAAS,EAAE,OAAO,QAAQ,SAAS;CACjD,IAA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alization","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\nimport type { WithOnChange } from './useDictionary';\n\n/** Simple in-memory cache shared across all calls in the same page. */\nconst cache = new Map<string, Dictionary>();\n\n/** Tracks in-flight loads to avoid duplicate fetches. */\nconst inflight = new Map<string, Promise<void>>();\n\nconst loadDictionary = <T extends Dictionary>(\n cacheKey: string,\n loader: () => Promise<T>\n): Promise<void> => {\n if (cache.has(cacheKey)) return Promise.resolve();\n if (inflight.has(cacheKey)) return inflight.get(cacheKey)!;\n\n const promise = loader().then((dictionary) => {\n cache.set(cacheKey, dictionary);\n inflight.delete(cacheKey);\n });\n\n inflight.set(cacheKey, promise);\n return promise;\n};\n\n/**\n * Dynamically load and transform a locale-keyed dictionary.\n *\n * Works like `useIntlayer` / `useDictionary` but accepts a locale-keyed map\n * of lazy loaders instead of a pre-imported dictionary. Call it inside your\n * render function — the first call triggers a background fetch and returns\n * placeholder values; when the load completes the client notifies all\n * subscribers (including your render loop) so the render runs again with real\n * content. Subsequent calls for the same locale return immediately from cache.\n *\n * Locale switches follow the same two-phase pattern: placeholder on first\n * render, real content after the locale bundle loads.\n *\n * @param dictionaryLoaders - Locale-keyed map of `() => Promise<Dictionary>`.\n * @param key - Dictionary key (used for cache namespacing).\n * @param locale - Optional locale override.\n *\n * @example\n * ```ts\n * import dynDic from '../.intlayer/dynamic_dictionary/app.mjs';\n *\n * const render = () => {\n * const content = useDictionaryDynamic(dynDic, 'app');\n * document.querySelector('h1')!.textContent = String(content.title);\n * };\n *\n * render();\n * getIntlayerClient().subscribe(() => render());\n * ```\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n L extends LocalesValues = LocalesValues,\n>(\n dictionaryLoaders: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const currentLocale = (locale ??\n client.locale ??\n internationalization.defaultLocale) as L;\n\n const cacheKey = `${String(key)}.${currentLocale}`;\n const loader = (dictionaryLoaders as Record<string, () => Promise<T>>)[\n currentLocale\n ];\n\n // --- Cache hit: return real content synchronously ---\n const cached = cache.get(cacheKey);\n if (cached) {\n const content = getDictionary(cached as T, currentLocale) as WithOnChange<\n DeepTransformContent<T['content'], L>\n >;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n // Re-fire whenever content reloads (locale change → new cache entry).\n client.subscribe((newLocale) => {\n const newKey = `${String(key)}.${newLocale}`;\n const newLoader = (\n dictionaryLoaders as Record<string, () => Promise<T>>\n )[newLocale];\n\n if (!newLoader) return;\n\n loadDictionary(newKey, newLoader).then(() => {\n const dict = cache.get(newKey);\n if (dict) {\n callback(\n getDictionary(dict as T, newLocale as L) as DeepTransformContent<\n T['content'],\n L\n >\n );\n }\n });\n });\n\n return content;\n };\n\n return content;\n }\n\n // --- Cache miss: kick off background load, then notify to re-render ---\n if (loader) {\n loadDictionary(cacheKey, loader).then(() => {\n client.notify();\n });\n }\n\n // Placeholder proxy — safe for any property access while loading.\n const recursiveProxy: any = new Proxy(() => {}, {\n get: (_t, prop) => {\n if (prop === Symbol.toPrimitive) return () => '';\n if (prop === 'toString') return () => '';\n if (prop === 'valueOf') return () => '';\n if (prop === 'then') return undefined; // not a Promise\n if (prop === 'onChange') return (_cb: any) => recursiveProxy;\n return recursiveProxy;\n },\n apply: () => recursiveProxy,\n });\n\n return recursiveProxy as WithOnChange<DeepTransformContent<T['content'], L>>;\n};\n"],"mappings":";;;;;;;;AAaA,MAAM,wBAAQ,IAAI,IAAwB;;AAG1C,MAAM,2BAAW,IAAI,IAA2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;GAC5B,IAAI,SAAS,YAAY,QAAQ,QAAa;GAC9C,OAAO;EACT;EACA,aAAa;CACf,CAAC;CAED,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"useIntlayer.cjs","names":["getIntlayerClient","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\nimport type { WithOnChange } from './useDictionary';\n\n/**\n * Get the translated content for the given key and optionally subscribe to\n * locale changes via the chainable `.onChange()` method — mirroring the API\n * of `react-intlayer`'s `useIntlayer`.\n *\n * Unlike React (where the hook system automatically re-runs on re-render),\n * vanilla JS has no component lifecycle. The `.onChange()` callback is the\n * explicit equivalent: it is called with fresh content whenever the active\n * locale changes. Use it to patch your DOM or trigger a full re-render.\n *\n * The function returns the current content **directly** (same shape as\n * `getIntlayer(key)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useIntlayer('app');\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useIntlayer('app');\n * const content = useIntlayer('app').onChange((c) => render(c));\n * ```\n *\n * For cleanup (e.g. Vite HMR), subscribe via `getIntlayerClient().subscribe()`\n * and hold the returned unsubscribe function.\n *\n * @param key - Dictionary key registered in your intlayer content files.\n * @param locale - Optional locale override (defaults to the current app locale).\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import { installIntlayer, useIntlayer } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * // Static read (no subscription)\n * const content = useIntlayer('homepage');\n * document.querySelector('h1').textContent = String(content.title);\n *\n * // Reactive read — onChange is called on every locale change\n * useIntlayer('homepage').onChange((c) => {\n * document.querySelector('h1').textContent = String(c.title);\n * });\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): WithOnChange<DeepTransformContent<DictionaryRegistryContent<T>>> => {\n const client = getIntlayerClient();\n const content = getIntlayer(key, locale ?? client.locale) as WithOnChange<\n DeepTransformContent<DictionaryRegistryContent<T>>\n >;\n\n content.onChange = (callback) => {\n client.subscribe((newLocale) => {\n callback(getIntlayer(key, (locale ?? newLocale) as typeof locale));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,eACX,KACA,WACqE;CACrE,MAAM,SAASA,kDAAmB;CAClC,MAAM,UAAUC,gCAAY,KAAK,UAAU,OAAO,OAAO;CAIzD,QAAQ,YAAY,aAAa;EAC/B,OAAO,WAAW,cAAc;GAC9B,SAASA,gCAAY,KAAM,UAAU,UAA4B,CAAC;IAClE;EACF,OAAO;;CAGT,OAAO"}
1
+ {"version":3,"file":"useIntlayer.cjs","names":["getIntlayerClient","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\nimport type { WithOnChange } from './useDictionary';\n\n/**\n * Get the translated content for the given key and optionally subscribe to\n * locale changes via the chainable `.onChange()` method — mirroring the API\n * of `react-intlayer`'s `useIntlayer`.\n *\n * Unlike React (where the hook system automatically re-runs on re-render),\n * vanilla JS has no component lifecycle. The `.onChange()` callback is the\n * explicit equivalent: it is called with fresh content whenever the active\n * locale changes. Use it to patch your DOM or trigger a full re-render.\n *\n * The function returns the current content **directly** (same shape as\n * `getIntlayer(key)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useIntlayer('app');\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useIntlayer('app');\n * const content = useIntlayer('app').onChange((c) => render(c));\n * ```\n *\n * For cleanup (e.g. Vite HMR), subscribe via `getIntlayerClient().subscribe()`\n * and hold the returned unsubscribe function.\n *\n * @param key - Dictionary key registered in your intlayer content files.\n * @param locale - Optional locale override (defaults to the current app locale).\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import { installIntlayer, useIntlayer } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * // Static read (no subscription)\n * const content = useIntlayer('homepage');\n * document.querySelector('h1').textContent = String(content.title);\n *\n * // Reactive read — onChange is called on every locale change\n * useIntlayer('homepage').onChange((c) => {\n * document.querySelector('h1').textContent = String(c.title);\n * });\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): WithOnChange<DeepTransformContent<DictionaryRegistryContent<T>>> => {\n const client = getIntlayerClient();\n const content = getIntlayer(key, locale ?? client.locale) as WithOnChange<\n DeepTransformContent<DictionaryRegistryContent<T>>\n >;\n\n content.onChange = (callback) => {\n client.subscribe((newLocale) => {\n callback(getIntlayer(key, (locale ?? newLocale) as typeof locale));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,eACX,KACA,WACqE;CACrE,MAAM,SAASA,iDAAkB;CACjC,MAAM,UAAUC,gCAAY,KAAK,UAAU,OAAO,MAAM;CAIxD,QAAQ,YAAY,aAAa;EAC/B,OAAO,WAAW,cAAc;GAC9B,SAASA,gCAAY,KAAM,UAAU,SAA2B,CAAC;EACnE,CAAC;EACD,OAAO;CACT;CAEA,OAAO;AACT"}
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,aAAa,QAAwB,EAAE,KAAsB;CACxE,MAAM,SAASA,kDAAmB;CAClC,MAAM,EAAE,eAAe,SAAS,qBAC9BC,+CAAwB,EAAE;CAE5B,MAAM,aAAa,cAAmC;EACpD,IAAI,EAAE,oBAAoB,EAAE,EAAE,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;GAC7D,QAAQ,MAAM,WAAW,UAAU,qBAAqB;GACxD;;EAGF,OAAO,UAAU,UAAU;EAE3B,mDACE,WACA,MAAM,mBAAmB,OAAO,mBAAmB,KACpD;EAED,MAAM,iBAAiB,UAA6B;;CAGtD,OAAO;EACL,QAAQ,OAAO;EACA;EACf,kBAAmB,oBAAoB,EAAE;EACzC;EACA,YAAY,aAAa,OAAO,UAAU,SAAS;EACpD"}
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,GAAG,IAAI,MAAM,EAAE,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 { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorageClient,\n LocaleStorageClient,\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,iDAAqB;;;;AAK/E,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,uEAEuB,QAAQ;CAC7B,GAAGA;CACH;CACD,CAAC;;;;AAKJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,oBAA8B;CAC7D,MAAM,wDAA8B;EAClC,GAAGA;EACH;EACD,CAAC;CAEF,OAAO;EACL,eAAe,QAAQ,WAAW;EAClC,kBAAkB,QAAQ;EAC3B;;;;;AAMH,MAAa,kBAAkB"}
1
+ {"version":3,"file":"useLocaleStorage.cjs","names":["localeStorageOptions"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorageClient,\n LocaleStorageClient,\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,gDAAoB;;;;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":"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,QACV;CAED,IAAI,cAAc,eAAe,UAC/B,OAAO,QAAQ,aACb,OAAO,QAAQ,OACf,IACA,aAAa,OAAO,SAAS,SAAS,OAAO,SAAS,KACvD;;;;;;;;;;;;;;;;;;;;;;;;AA0BL,MAAa,sBAAoC;CAC/C,MAAM,SAASC,kDAAmB;CAGlC,QAAQ,OAAO,OAAO;CAEtB,OAAO,OAAO,WAAW,cAAc;EACrC,QAAQ,UAAU;GAClB"}
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 +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":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,kBAAgC;CAC3C,IAAI,QAAQ,IAAI,+BAA+B,WAAW,CAACA,sCACzD,aAAa;CAEf,IAAI,oBAAyC;CAC7C,IAAI,UAAU;CAEd,OAAO,oBAAoB,MAAM,EAAE,uBAAuB;EACxD,IAAI,SAAS;EACb,MAAM,UAA8B,kBAAkB;EACtD,MAAM,SAASC,kDAAmB;EAElC,QAAQ,cAAc,IAAI,OAAO,OAAiB;EAElD,oBAAoB,OAAO,WAAW,cAAc;GAClD,QAAQ,cAAc,IAAI,UAAoB;IAC9C;GACF;CAEF,aAAa;EACX,UAAU;EACV,qBAAqB;EACrB,OAAO,oBAAoB,MAAM,EAAE,uBAAuB;GACxD,kBAAkB;IAClB"}
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,+BAA+B,WAAW,CAACA,sCACzD,aAAa,CAAC;CAEhB,IAAI,oBAAyC;CAC7C,IAAI,UAAU;CAEd,OAAO,oBAAoB,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,oBAAoB,MAAM,EAAE,uBAAuB;GACxD,iBAAiB;EACnB,CAAC;CACH;AACF"}
@@ -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":";;;;;;AAGA,MAAa,mBAAmB;CAC9B,MAAM,SAASA,kDAAmB;CAElC,QAAQ,GAAG,gDACD,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
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,IAAI,UAAU,OAAO;CACpC,CAAC;AACL"}
@@ -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":";;;;;;AAGA,MAAa,oBAAoB;CAC/B,MAAM,SAASA,kDAAmB;CAElC,QAAQ,GAAG,iDACA,KAAK,IAAI;EAChB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
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,IAAI,UAAU,OAAO;CACpC,CAAC;AACL"}
@@ -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":";;;;;;;;;AAMA,MAAa,gBAAgB;CAC3B,MAAM,SAASA,kDAAmB;CAElC,QAAQ,GAAG,SAAkC;EAC3C,MAAM,UACJ,OAAO,KAAK,OAAO,WACf;GAAE,GAAGC,kCAAQ,KAAK;GAAK,QAAQ,OAAO;GAAQ,GAC9C;GAAE,GAAG,KAAK;GAAI,QAAQ,KAAK,IAAI,UAAU,OAAO;GAAQ;EAE9D,2CAAY,KAAK,IAAI,QAAsC"}
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,IAAI,UAAU,OAAO;EAAO;EAE7D,2CAAY,KAAK,IAAI,OAAqC;CAC5D;AACF"}
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,WACX,WAIG;CACH,MAAM,SAASA,kDAAmB;CAGlC,OAAO;EACL,yCAHoB,UAAU,OAAO,OAGjC;EACJ,YAAY,aACV,OAAO,WAAW,cAAc;GAC9B,4CAAkB,UAAU,UAAU,CAAC;IACvC;EACL"}
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 +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":";;;;;;AAGA,MAAa,gBAAgB;CAC3B,MAAM,SAASA,kDAAmB;CAElC,QAAQ,GAAG,6CACJ,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
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,IAAI,UAAU,OAAO;CACpC,CAAC;AACL"}
@@ -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":";;;;;;;;;AAMA,MAAa,kBAAkB;CAC7B,MAAM,SAASA,kDAAmB;CAElC,QAAQ,GAAG,+CACF,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
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,IAAI,UAAU,OAAO;CACpC,CAAC;AACL"}
@@ -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":";;;;;;AAGA,MAAa,sBAAsB;CACjC,MAAM,SAASA,kDAAmB;CAElC,QAAQ,GAAG,mDACE,KAAK,IAAI;EAClB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
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,IAAI,UAAU,OAAO;CACpC,CAAC;AACL"}
@@ -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":";;;;;;AAGA,MAAa,wBAAwB;CACnC,MAAM,SAASA,kDAAmB;CAElC,QAAQ,GAAG,qDACI,KAAK,IAAI,KAAK,IAAI;EAC7B,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
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,IAAI,UAAU,OAAO;CACpC,CAAC;AACL"}
@@ -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":";;;;;;AAGA,MAAa,gBAAgB;CAC3B,MAAM,SAASA,kDAAmB;CAElC,QAAQ,GAAG,8CACH,KAAK,IAAI;EACb,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU,OAAO;EACnC,CAAC"}
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,IAAI,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 { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): DeepTransformContent<T['content'], L> =>\n getDictionaryCore(dictionary, locale, getPlugins(locale)) as any;\n"],"mappings":";;;;;;AAQA,MAAa,iBAIX,YACA,yDAEkB,YAAY,QAAQA,2BAAW,OAAO,CAAC"}
1
+ {"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): DeepTransformContent<T['content'], L> =>\n getDictionaryCore(dictionary, locale, getPlugins(locale)) as any;\n"],"mappings":";;;;;;AAQA,MAAa,iBAIX,YACA,yDAEkB,YAAY,QAAQA,2BAAW,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n): DeepTransformContent<DictionaryRegistryContent<T>, L> =>\n getIntlayerCore(key, locale, getPlugins(locale)) as any;\n"],"mappings":";;;;;;AASA,MAAa,eAIX,KACA,uDAEgB,KAAK,QAAQA,2BAAW,OAAO,CAAC"}
1
+ {"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n): DeepTransformContent<DictionaryRegistryContent<T>, L> =>\n getIntlayerCore(key, locale, getPlugins(locale)) as any;\n"],"mappings":";;;;;;AASA,MAAa,eAIX,KACA,uDAEgB,KAAK,QAAQA,2BAAW,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"HTMLRenderer.cjs","names":["useHTML"],"sources":["../../../src/html/HTMLRenderer.ts"],"sourcesContent":["import { type RenderHTMLOptions, useHTML } from './installIntlayerHTML';\nimport type { HTMLComponents } from './types';\n\nexport type RenderHTMLProps = {\n components?: HTMLComponents<'permissive', {}>;\n};\n\n/**\n * Renders an HTML string directly, without a global provider.\n * Returns the raw string unchanged.\n */\nexport const renderHTML = (\n content: string,\n _props: RenderHTMLProps = {}\n): string => content;\n\n/**\n * Returns a render function that uses the global provider's configuration\n * (installed via `installIntlayerHTML`), falling back to identity.\n */\nexport const useHTMLRenderer = ({\n components,\n}: RenderHTMLProps = {}): ((content: string) => string) => {\n const context = useHTML();\n\n return (content: string) =>\n context.renderHTML(content, { components } as RenderHTMLOptions);\n};\n"],"mappings":";;;;;;;;AAWA,MAAa,cACX,SACA,SAA0B,EAAE,KACjB;;;;;AAMb,MAAa,mBAAmB,EAC9B,eACmB,EAAE,KAAoC;CACzD,MAAM,UAAUA,0CAAS;CAEzB,QAAQ,YACN,QAAQ,WAAW,SAAS,EAAE,YAAY,CAAsB"}
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"}
@@ -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;CACzB,IAAI,UAAU,OAAO;CACrB,WAAW,EAAE,YAAY;CACzB,OAAO;;;;;;;;;;;;;;;;AAiBT,MAAa,uBACX,kBACyB;CACzB,IAAI;CAEJ,IAAI,OAAO,kBAAkB,YAC3B,aAAa;MACR;EACL,MAAM,EAAE,YAAY,YAAY,iBAAiB,iBAAiB,EAAE;EAEpE,IAAI,cACF,aAAa;OAEb,cAAc,SAAS,cAAc;GAMnC,MAAM,qBAJJ,aACA,OAAO,cAAc,YACrB,gBAAgB,YAGb,UAAgC,aAChC;GAEL,MAAM,mBAAmB;IACvB,GAAI,cAAc,EAAE;IACpB,GAAI,sBAAsB,EAAE;IAC7B;GAED,IAAI,CAAC,OAAO,KAAK,iBAAiB,CAAC,QAAQ,OAAO;GAIlD,OAAO;;;CAKb,OAAO,yBAAyB,WAAW;;;;;;;AAQ7C,MAAa,gBAAsC;CACjD,IAAI,UAAU,OAAO;CACrB,OAAO,EAAE,aAAa,YAAY,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;AA2B7C,MAAa,6BAA6B,OACxC,WACkC;CAClC,IAAI,UAAU,OAAO;CAErB,OAAO,oBAAoB,MADC,QAAQ,CACK"}
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,EAAE,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;CAErB,OAAO,oBAAoB,MADC,OAAO,CACK;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 { compileMarkdown, type MarkdownCompilerOptions } 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,\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) => string | Promise<string>) => {\n const provider = useMarkdown();\n\n return (content: string) =>\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":";;;;;;;;;;;;;;;AAuBA,MAAa,kBACX,SACA,EACE,YACA,aACA,qBACA,cACuB,EAAE,KAChB;CAOX,OAAOA,0CAAgB,SAAS;EAL9B;EACA;EACA;EACA;EAEqC,CAAC;;;;;;AAO1C,MAAa,uBACX,QAA6B,EAAE,KACqB;CACpD,MAAM,WAAWC,sDAAa;CAE9B,QAAQ,YACN,SAAS,eACP,SACA;EACE,YAAY,MAAM;EAClB,aAAa,MAAM;EACnB,qBAAqB,MAAM;EAC3B,WAAW,MAAM;EAClB,EACD,MAAM,YACN,MAAM,QACP"}
1
+ {"version":3,"file":"MarkdownRenderer.cjs","names":["compileMarkdown","useMarkdown"],"sources":["../../../src/markdown/MarkdownRenderer.ts"],"sourcesContent":["import type { HTMLComponents } from '../html/types';\nimport { compileMarkdown, type MarkdownCompilerOptions } 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,\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) => string | Promise<string>) => {\n const provider = useMarkdown();\n\n return (content: string) =>\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":";;;;;;;;;;;;;;;AAuBA,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,MACsB;CACpD,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 +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 sanitizer as defaultSanitizer,\n slugify as defaultSlugify,\n RuleType,\n} from '@intlayer/core/markdown';\nimport { vanillaRuntime } from './runtime';\n\n// Re-export utilities for compatibility\nexport { defaultSanitizer as sanitizer, defaultSlugify as slugify, RuleType };\n\nexport type MarkdownCompilerOptions = CompileOptions;\n\n/**\n * Compile markdown to an HTML string.\n *\n * The resulting string can be inserted into the DOM via `element.innerHTML`\n * or the `renderMarkdown` helper.\n *\n * @example\n * ```ts\n * import { compileMarkdown } from 'vanilla-intlayer/markdown';\n *\n * document.querySelector('#content').innerHTML = compileMarkdown('# Hello **World**');\n * ```\n */\nexport const compileMarkdown = (\n markdown = '',\n options: MarkdownCompilerOptions = {}\n): string => compileWithOptions(markdown, vanillaRuntime, options) as string;\n\n// Aliases for consistency with other adapters\nexport const compiler = compileMarkdown;\nexport const compile = compileMarkdown;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,mBACX,WAAW,IACX,UAAmC,EAAE,qDACP,UAAUA,kCAAgB,QAAQ;AAGlE,MAAa,WAAW;AACxB,MAAa,UAAU"}
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 sanitizer as defaultSanitizer,\n slugify as defaultSlugify,\n RuleType,\n} from '@intlayer/core/markdown';\nimport { vanillaRuntime } from './runtime';\n\n// Re-export utilities for compatibility\nexport { defaultSanitizer as sanitizer, defaultSlugify as slugify, RuleType };\n\nexport type MarkdownCompilerOptions = CompileOptions;\n\n/**\n * Compile markdown to an HTML string.\n *\n * The resulting string can be inserted into the DOM via `element.innerHTML`\n * or the `renderMarkdown` helper.\n *\n * @example\n * ```ts\n * import { compileMarkdown } from 'vanilla-intlayer/markdown';\n *\n * document.querySelector('#content').innerHTML = compileMarkdown('# Hello **World**');\n * ```\n */\nexport const compileMarkdown = (\n markdown = '',\n options: MarkdownCompilerOptions = {}\n): string => compileWithOptions(markdown, vanillaRuntime, options) as string;\n\n// Aliases for consistency with other adapters\nexport const compiler = compileMarkdown;\nexport const compile = compileMarkdown;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,mBACX,WAAW,IACX,UAAmC,CAAC,sDACN,UAAUA,kCAAgB,OAAO;AAGjE,MAAa,WAAW;AACxB,MAAa,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"installIntlayerMarkdown.cjs","names":["compileMarkdown"],"sources":["../../../src/markdown/installIntlayerMarkdown.ts"],"sourcesContent":["import type { HTMLComponents } from '../html/types';\nimport { compileMarkdown, type MarkdownCompilerOptions } from './compiler';\n\nexport type MarkdownProviderOptions = {\n /** Forces the compiler to always output content with a block-level wrapper. */\n forceBlock?: boolean;\n /** Forces the compiler to always output content with an inline wrapper. */\n forceInline?: boolean;\n /** Whether to preserve frontmatter in the markdown content. */\n preserveFrontmatter?: boolean;\n /** Whether to use the GitHub Tag Filter. */\n tagfilter?: boolean;\n};\n\nexport type RenderMarkdownOptions = MarkdownProviderOptions & {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: string;\n};\n\nexport type RenderMarkdownFunction = (\n markdown: string,\n options?: MarkdownProviderOptions,\n components?: HTMLComponents<'permissive', {}>,\n wrapper?: string\n) => string | Promise<string>;\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerMarkdownProvider | null = null;\n\nexport type IntlayerMarkdownProvider = {\n components?: HTMLComponents<'permissive', {}>;\n renderMarkdown: RenderMarkdownFunction;\n};\n\nexport type IntlayerMarkdownPluginOptions = MarkdownProviderOptions & {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: string;\n renderMarkdown?: RenderMarkdownFunction;\n};\n\n/**\n * Create and return a single IntlayerMarkdownProvider instance.\n */\nexport const createIntlayerMarkdownClient = (\n renderMarkdown: RenderMarkdownFunction,\n components?: HTMLComponents<'permissive', {}>\n): IntlayerMarkdownProvider => {\n if (instance) return instance;\n\n instance = { components, renderMarkdown };\n return instance;\n};\n\n/**\n * Install the Intlayer Markdown provider for your vanilla JS application.\n *\n * @example\n * ```ts\n * import { installIntlayerMarkdown } from 'vanilla-intlayer/markdown';\n *\n * installIntlayerMarkdown({ forceBlock: true });\n * ```\n */\nexport const installIntlayerMarkdown = (\n pluginOptions?: IntlayerMarkdownPluginOptions | RenderMarkdownFunction\n): IntlayerMarkdownProvider => {\n let renderMarkdown: RenderMarkdownFunction;\n let providerComponents: HTMLComponents<'permissive', {}> | undefined;\n\n if (typeof pluginOptions === 'function') {\n renderMarkdown = pluginOptions;\n } else {\n const {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n renderMarkdown: customRender,\n } = pluginOptions ?? {};\n\n providerComponents = components;\n\n if (customRender) {\n renderMarkdown = customRender;\n } else {\n const internalOptions: MarkdownCompilerOptions = {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n };\n\n renderMarkdown = (\n markdown,\n options,\n _componentsOverride,\n _wrapperOverride\n ) =>\n compileMarkdown(markdown, {\n ...internalOptions,\n forceBlock: options?.forceBlock ?? internalOptions.forceBlock,\n forceInline: options?.forceInline ?? internalOptions.forceInline,\n preserveFrontmatter:\n options?.preserveFrontmatter ?? internalOptions.preserveFrontmatter,\n tagfilter: options?.tagfilter ?? internalOptions.tagfilter,\n });\n }\n }\n\n return createIntlayerMarkdownClient(renderMarkdown, providerComponents);\n};\n\n/**\n * Access the installed IntlayerMarkdownProvider.\n * Returns a fallback renderer that compiles with default options if no\n * provider has been installed.\n */\nexport const useMarkdown = (): IntlayerMarkdownProvider => {\n if (instance) return instance;\n\n return {\n renderMarkdown: (markdown) => compileMarkdown(markdown),\n };\n};\n\n/**\n * Asynchronously install a markdown renderer whose implementation is loaded\n * via a dynamic `import()`.\n *\n * Use this to keep the markdown compiler out of the initial bundle — the\n * loader is only called the first time this function is executed.\n *\n * The returned promise resolves once the provider is ready. Any calls to\n * `useMarkdown()` before the promise resolves will use the fallback\n * (raw-string) renderer.\n *\n * @param loader - A zero-argument async function that resolves to either a\n * `RenderMarkdownFunction` or an `IntlayerMarkdownPluginOptions` object.\n *\n * @example\n * ```ts\n * // Load a custom markdown renderer (e.g. marked) only when needed\n * await installIntlayerMarkdownDynamic(async () => {\n * const { marked } = await import('marked');\n * return (markdown) => marked(markdown) as string;\n * });\n * ```\n */\nexport const installIntlayerMarkdownDynamic = async (\n loader: () => Promise<IntlayerMarkdownPluginOptions | RenderMarkdownFunction>\n): Promise<IntlayerMarkdownProvider> => {\n if (instance) return instance;\n const pluginOptions = await loader();\n return installIntlayerMarkdown(pluginOptions);\n};\n"],"mappings":";;;;;;;AA6BA,IAAI,WAA4C;;;;AAgBhD,MAAa,gCACX,gBACA,eAC6B;CAC7B,IAAI,UAAU,OAAO;CAErB,WAAW;EAAE;EAAY;EAAgB;CACzC,OAAO;;;;;;;;;;;;AAaT,MAAa,2BACX,kBAC6B;CAC7B,IAAI;CACJ,IAAI;CAEJ,IAAI,OAAO,kBAAkB,YAC3B,iBAAiB;MACZ;EACL,MAAM,EACJ,YACA,SACA,YACA,aACA,qBACA,WACA,gBAAgB,iBACd,iBAAiB,EAAE;EAEvB,qBAAqB;EAErB,IAAI,cACF,iBAAiB;OACZ;GACL,MAAM,kBAA2C;IAC/C;IACA;IACA;IACA;IACD;GAED,kBACE,UACA,SACA,qBACA,qBAEAA,0CAAgB,UAAU;IACxB,GAAG;IACH,YAAY,SAAS,cAAc,gBAAgB;IACnD,aAAa,SAAS,eAAe,gBAAgB;IACrD,qBACE,SAAS,uBAAuB,gBAAgB;IAClD,WAAW,SAAS,aAAa,gBAAgB;IAClD,CAAC;;;CAIR,OAAO,6BAA6B,gBAAgB,mBAAmB;;;;;;;AAQzE,MAAa,oBAA8C;CACzD,IAAI,UAAU,OAAO;CAErB,OAAO,EACL,iBAAiB,aAAaA,0CAAgB,SAAS,EACxD;;;;;;;;;;;;;;;;;;;;;;;;;AA0BH,MAAa,iCAAiC,OAC5C,WACsC;CACtC,IAAI,UAAU,OAAO;CAErB,OAAO,wBAAwB,MADH,QAAQ,CACS"}
1
+ {"version":3,"file":"installIntlayerMarkdown.cjs","names":["compileMarkdown"],"sources":["../../../src/markdown/installIntlayerMarkdown.ts"],"sourcesContent":["import type { HTMLComponents } from '../html/types';\nimport { compileMarkdown, type MarkdownCompilerOptions } from './compiler';\n\nexport type MarkdownProviderOptions = {\n /** Forces the compiler to always output content with a block-level wrapper. */\n forceBlock?: boolean;\n /** Forces the compiler to always output content with an inline wrapper. */\n forceInline?: boolean;\n /** Whether to preserve frontmatter in the markdown content. */\n preserveFrontmatter?: boolean;\n /** Whether to use the GitHub Tag Filter. */\n tagfilter?: boolean;\n};\n\nexport type RenderMarkdownOptions = MarkdownProviderOptions & {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: string;\n};\n\nexport type RenderMarkdownFunction = (\n markdown: string,\n options?: MarkdownProviderOptions,\n components?: HTMLComponents<'permissive', {}>,\n wrapper?: string\n) => string | Promise<string>;\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerMarkdownProvider | null = null;\n\nexport type IntlayerMarkdownProvider = {\n components?: HTMLComponents<'permissive', {}>;\n renderMarkdown: RenderMarkdownFunction;\n};\n\nexport type IntlayerMarkdownPluginOptions = MarkdownProviderOptions & {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: string;\n renderMarkdown?: RenderMarkdownFunction;\n};\n\n/**\n * Create and return a single IntlayerMarkdownProvider instance.\n */\nexport const createIntlayerMarkdownClient = (\n renderMarkdown: RenderMarkdownFunction,\n components?: HTMLComponents<'permissive', {}>\n): IntlayerMarkdownProvider => {\n if (instance) return instance;\n\n instance = { components, renderMarkdown };\n return instance;\n};\n\n/**\n * Install the Intlayer Markdown provider for your vanilla JS application.\n *\n * @example\n * ```ts\n * import { installIntlayerMarkdown } from 'vanilla-intlayer/markdown';\n *\n * installIntlayerMarkdown({ forceBlock: true });\n * ```\n */\nexport const installIntlayerMarkdown = (\n pluginOptions?: IntlayerMarkdownPluginOptions | RenderMarkdownFunction\n): IntlayerMarkdownProvider => {\n let renderMarkdown: RenderMarkdownFunction;\n let providerComponents: HTMLComponents<'permissive', {}> | undefined;\n\n if (typeof pluginOptions === 'function') {\n renderMarkdown = pluginOptions;\n } else {\n const {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n renderMarkdown: customRender,\n } = pluginOptions ?? {};\n\n providerComponents = components;\n\n if (customRender) {\n renderMarkdown = customRender;\n } else {\n const internalOptions: MarkdownCompilerOptions = {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n };\n\n renderMarkdown = (\n markdown,\n options,\n _componentsOverride,\n _wrapperOverride\n ) =>\n compileMarkdown(markdown, {\n ...internalOptions,\n forceBlock: options?.forceBlock ?? internalOptions.forceBlock,\n forceInline: options?.forceInline ?? internalOptions.forceInline,\n preserveFrontmatter:\n options?.preserveFrontmatter ?? internalOptions.preserveFrontmatter,\n tagfilter: options?.tagfilter ?? internalOptions.tagfilter,\n });\n }\n }\n\n return createIntlayerMarkdownClient(renderMarkdown, providerComponents);\n};\n\n/**\n * Access the installed IntlayerMarkdownProvider.\n * Returns a fallback renderer that compiles with default options if no\n * provider has been installed.\n */\nexport const useMarkdown = (): IntlayerMarkdownProvider => {\n if (instance) return instance;\n\n return {\n renderMarkdown: (markdown) => compileMarkdown(markdown),\n };\n};\n\n/**\n * Asynchronously install a markdown renderer whose implementation is loaded\n * via a dynamic `import()`.\n *\n * Use this to keep the markdown compiler out of the initial bundle — the\n * loader is only called the first time this function is executed.\n *\n * The returned promise resolves once the provider is ready. Any calls to\n * `useMarkdown()` before the promise resolves will use the fallback\n * (raw-string) renderer.\n *\n * @param loader - A zero-argument async function that resolves to either a\n * `RenderMarkdownFunction` or an `IntlayerMarkdownPluginOptions` object.\n *\n * @example\n * ```ts\n * // Load a custom markdown renderer (e.g. marked) only when needed\n * await installIntlayerMarkdownDynamic(async () => {\n * const { marked } = await import('marked');\n * return (markdown) => marked(markdown) as string;\n * });\n * ```\n */\nexport const installIntlayerMarkdownDynamic = async (\n loader: () => Promise<IntlayerMarkdownPluginOptions | RenderMarkdownFunction>\n): Promise<IntlayerMarkdownProvider> => {\n if (instance) return instance;\n const pluginOptions = await loader();\n return installIntlayerMarkdown(pluginOptions);\n};\n"],"mappings":";;;;;;;AA6BA,IAAI,WAA4C;;;;AAgBhD,MAAa,gCACX,gBACA,eAC6B;CAC7B,IAAI,UAAU,OAAO;CAErB,WAAW;EAAE;EAAY;CAAe;CACxC,OAAO;AACT;;;;;;;;;;;AAYA,MAAa,2BACX,kBAC6B;CAC7B,IAAI;CACJ,IAAI;CAEJ,IAAI,OAAO,kBAAkB,YAC3B,iBAAiB;MACZ;EACL,MAAM,EACJ,YACA,SACA,YACA,aACA,qBACA,WACA,gBAAgB,iBACd,iBAAiB,CAAC;EAEtB,qBAAqB;EAErB,IAAI,cACF,iBAAiB;OACZ;GACL,MAAM,kBAA2C;IAC/C;IACA;IACA;IACA;GACF;GAEA,kBACE,UACA,SACA,qBACA,qBAEAA,0CAAgB,UAAU;IACxB,GAAG;IACH,YAAY,SAAS,cAAc,gBAAgB;IACnD,aAAa,SAAS,eAAe,gBAAgB;IACrD,qBACE,SAAS,uBAAuB,gBAAgB;IAClD,WAAW,SAAS,aAAa,gBAAgB;GACnD,CAAC;EACL;CACF;CAEA,OAAO,6BAA6B,gBAAgB,kBAAkB;AACxE;;;;;;AAOA,MAAa,oBAA8C;CACzD,IAAI,UAAU,OAAO;CAErB,OAAO,EACL,iBAAiB,aAAaA,0CAAgB,QAAQ,EACxD;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,iCAAiC,OAC5C,WACsC;CACtC,IAAI,UAAU,OAAO;CAErB,OAAO,wBAAwB,MADH,OAAO,CACS;AAC9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.cjs","names":[],"sources":["../../../src/markdown/runtime.ts"],"sourcesContent":["/**\n * Vanilla JS adapter for the framework-agnostic markdown processor.\n *\n * Builds HTML strings which can be inserted into the DOM via `innerHTML`\n * or the `renderMarkdown` utility.\n */\n\nimport type { HTMLTag, MarkdownRuntime } from '@intlayer/core/markdown';\n\nconst SELF_CLOSING_TAGS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n]);\n\nconst buildPropsString = (props: Record<string, any> | null): string => {\n if (!props) return '';\n\n return Object.entries(props)\n .filter(([, v]) => v !== undefined && v !== null)\n .map(([k, v]) => {\n if (typeof v === 'boolean') return v ? k : '';\n if (k === '_innerHTML') return ''; // handled separately\n return `${k}=\"${String(v).replace(/&/g, '&amp;').replace(/\"/g, '&quot;')}\"`;\n })\n .filter(Boolean)\n .join(' ');\n};\n\nconst VANILLA_FRAGMENT = '__vanilla_fragment__';\n\n/**\n * Vanilla-specific MarkdownRuntime that produces HTML strings.\n */\nexport const vanillaRuntime: MarkdownRuntime = {\n createElement: (\n type: any,\n props: Record<string, any> | null,\n ...children: any[]\n ): string => {\n const childStr = children.flat(Infinity).join('');\n\n if (type === VANILLA_FRAGMENT) return childStr;\n\n if (typeof type === 'string') {\n const propsStr = buildPropsString(props);\n const propsWithSpace = propsStr ? ` ${propsStr}` : '';\n const innerHTML = props?._innerHTML;\n\n if (SELF_CLOSING_TAGS.has(type)) {\n return `<${type}${propsWithSpace}>`;\n }\n\n if (innerHTML !== undefined) {\n return `<${type}${propsWithSpace}>${innerHTML}</${type}>`;\n }\n\n return `<${type}${propsWithSpace}>${childStr}</${type}>`;\n }\n\n // Function component override — returns a string\n if (typeof type === 'function') {\n try {\n const result = type({ ...props, children: childStr });\n return typeof result === 'string' ? result : childStr;\n } catch {\n return childStr;\n }\n }\n\n return childStr;\n },\n\n cloneElement: (\n element: unknown,\n _props: Record<string, any>,\n ..._children: any[]\n ): string => {\n return typeof element === 'string' ? element : String(element ?? '');\n },\n\n Fragment: VANILLA_FRAGMENT as any,\n\n /**\n * Normalize props to standard HTML attribute names.\n */\n normalizeProps: (\n _tag: HTMLTag,\n props: Record<string, any>\n ): Record<string, any> => {\n const normalized: Record<string, any> = {};\n\n for (const [key, value] of Object.entries(props)) {\n if (key === 'className') {\n normalized.class = value;\n } else if (key === 'htmlFor') {\n normalized.for = value;\n } else if (key === 'dangerouslySetInnerHTML' && value?.__html) {\n normalized._innerHTML = value.__html;\n } else {\n normalized[key] = value;\n }\n }\n\n return normalized;\n },\n};\n\n/**\n * Creates a vanilla runtime with a custom createElement for advanced use cases.\n */\nexport const createVanillaRuntime = (\n options: {\n onCreateElement?: (\n type: any,\n props: Record<string, any> | null,\n children: any[]\n ) => string;\n } = {}\n): MarkdownRuntime => {\n const { onCreateElement } = options;\n\n if (onCreateElement) {\n return {\n ...vanillaRuntime,\n createElement: (\n type: any,\n props: Record<string, any> | null,\n ...children: any[]\n ): string => onCreateElement(type, props, children),\n };\n }\n\n return vanillaRuntime;\n};\n\nexport default vanillaRuntime;\n"],"mappings":";;;AASA,MAAM,oBAAoB,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,oBAAoB,UAA8C;CACtE,IAAI,CAAC,OAAO,OAAO;CAEnB,OAAO,OAAO,QAAQ,MAAM,CACzB,QAAQ,GAAG,OAAO,MAAM,UAAa,MAAM,KAAK,CAChD,KAAK,CAAC,GAAG,OAAO;EACf,IAAI,OAAO,MAAM,WAAW,OAAO,IAAI,IAAI;EAC3C,IAAI,MAAM,cAAc,OAAO;EAC/B,OAAO,GAAG,EAAE,IAAI,OAAO,EAAE,CAAC,QAAQ,MAAM,QAAQ,CAAC,QAAQ,MAAM,SAAS,CAAC;GACzE,CACD,OAAO,QAAQ,CACf,KAAK,IAAI;;AAGd,MAAM,mBAAmB;;;;AAKzB,MAAa,iBAAkC;CAC7C,gBACE,MACA,OACA,GAAG,aACQ;EACX,MAAM,WAAW,SAAS,KAAK,SAAS,CAAC,KAAK,GAAG;EAEjD,IAAI,SAAS,kBAAkB,OAAO;EAEtC,IAAI,OAAO,SAAS,UAAU;GAC5B,MAAM,WAAW,iBAAiB,MAAM;GACxC,MAAM,iBAAiB,WAAW,IAAI,aAAa;GACnD,MAAM,YAAY,OAAO;GAEzB,IAAI,kBAAkB,IAAI,KAAK,EAC7B,OAAO,IAAI,OAAO,eAAe;GAGnC,IAAI,cAAc,QAChB,OAAO,IAAI,OAAO,eAAe,GAAG,UAAU,IAAI,KAAK;GAGzD,OAAO,IAAI,OAAO,eAAe,GAAG,SAAS,IAAI,KAAK;;EAIxD,IAAI,OAAO,SAAS,YAClB,IAAI;GACF,MAAM,SAAS,KAAK;IAAE,GAAG;IAAO,UAAU;IAAU,CAAC;GACrD,OAAO,OAAO,WAAW,WAAW,SAAS;UACvC;GACN,OAAO;;EAIX,OAAO;;CAGT,eACE,SACA,QACA,GAAG,cACQ;EACX,OAAO,OAAO,YAAY,WAAW,UAAU,OAAO,WAAW,GAAG;;CAGtE,UAAU;;;;CAKV,iBACE,MACA,UACwB;EACxB,MAAM,aAAkC,EAAE;EAE1C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,EAC9C,IAAI,QAAQ,aACV,WAAW,QAAQ;OACd,IAAI,QAAQ,WACjB,WAAW,MAAM;OACZ,IAAI,QAAQ,6BAA6B,OAAO,QACrD,WAAW,aAAa,MAAM;OAE9B,WAAW,OAAO;EAItB,OAAO;;CAEV;;;;AAKD,MAAa,wBACX,UAMI,EAAE,KACc;CACpB,MAAM,EAAE,oBAAoB;CAE5B,IAAI,iBACF,OAAO;EACL,GAAG;EACH,gBACE,MACA,OACA,GAAG,aACQ,gBAAgB,MAAM,OAAO,SAAS;EACpD;CAGH,OAAO"}
1
+ {"version":3,"file":"runtime.cjs","names":[],"sources":["../../../src/markdown/runtime.ts"],"sourcesContent":["/**\n * Vanilla JS adapter for the framework-agnostic markdown processor.\n *\n * Builds HTML strings which can be inserted into the DOM via `innerHTML`\n * or the `renderMarkdown` utility.\n */\n\nimport type { HTMLTag, MarkdownRuntime } from '@intlayer/core/markdown';\n\nconst SELF_CLOSING_TAGS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n]);\n\nconst buildPropsString = (props: Record<string, any> | null): string => {\n if (!props) return '';\n\n return Object.entries(props)\n .filter(([, v]) => v !== undefined && v !== null)\n .map(([k, v]) => {\n if (typeof v === 'boolean') return v ? k : '';\n if (k === '_innerHTML') return ''; // handled separately\n return `${k}=\"${String(v).replace(/&/g, '&amp;').replace(/\"/g, '&quot;')}\"`;\n })\n .filter(Boolean)\n .join(' ');\n};\n\nconst VANILLA_FRAGMENT = '__vanilla_fragment__';\n\n/**\n * Vanilla-specific MarkdownRuntime that produces HTML strings.\n */\nexport const vanillaRuntime: MarkdownRuntime = {\n createElement: (\n type: any,\n props: Record<string, any> | null,\n ...children: any[]\n ): string => {\n const childStr = children.flat(Infinity).join('');\n\n if (type === VANILLA_FRAGMENT) return childStr;\n\n if (typeof type === 'string') {\n const propsStr = buildPropsString(props);\n const propsWithSpace = propsStr ? ` ${propsStr}` : '';\n const innerHTML = props?._innerHTML;\n\n if (SELF_CLOSING_TAGS.has(type)) {\n return `<${type}${propsWithSpace}>`;\n }\n\n if (innerHTML !== undefined) {\n return `<${type}${propsWithSpace}>${innerHTML}</${type}>`;\n }\n\n return `<${type}${propsWithSpace}>${childStr}</${type}>`;\n }\n\n // Function component override — returns a string\n if (typeof type === 'function') {\n try {\n const result = type({ ...props, children: childStr });\n return typeof result === 'string' ? result : childStr;\n } catch {\n return childStr;\n }\n }\n\n return childStr;\n },\n\n cloneElement: (\n element: unknown,\n _props: Record<string, any>,\n ..._children: any[]\n ): string => {\n return typeof element === 'string' ? element : String(element ?? '');\n },\n\n Fragment: VANILLA_FRAGMENT as any,\n\n /**\n * Normalize props to standard HTML attribute names.\n */\n normalizeProps: (\n _tag: HTMLTag,\n props: Record<string, any>\n ): Record<string, any> => {\n const normalized: Record<string, any> = {};\n\n for (const [key, value] of Object.entries(props)) {\n if (key === 'className') {\n normalized.class = value;\n } else if (key === 'htmlFor') {\n normalized.for = value;\n } else if (key === 'dangerouslySetInnerHTML' && value?.__html) {\n normalized._innerHTML = value.__html;\n } else {\n normalized[key] = value;\n }\n }\n\n return normalized;\n },\n};\n\n/**\n * Creates a vanilla runtime with a custom createElement for advanced use cases.\n */\nexport const createVanillaRuntime = (\n options: {\n onCreateElement?: (\n type: any,\n props: Record<string, any> | null,\n children: any[]\n ) => string;\n } = {}\n): MarkdownRuntime => {\n const { onCreateElement } = options;\n\n if (onCreateElement) {\n return {\n ...vanillaRuntime,\n createElement: (\n type: any,\n props: Record<string, any> | null,\n ...children: any[]\n ): string => onCreateElement(type, props, children),\n };\n }\n\n return vanillaRuntime;\n};\n\nexport default vanillaRuntime;\n"],"mappings":";;;AASA,MAAM,oBAAoB,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,oBAAoB,UAA8C;CACtE,IAAI,CAAC,OAAO,OAAO;CAEnB,OAAO,OAAO,QAAQ,KAAK,EACxB,QAAQ,GAAG,OAAO,MAAM,UAAa,MAAM,IAAI,EAC/C,KAAK,CAAC,GAAG,OAAO;EACf,IAAI,OAAO,MAAM,WAAW,OAAO,IAAI,IAAI;EAC3C,IAAI,MAAM,cAAc,OAAO;EAC/B,OAAO,GAAG,EAAE,IAAI,OAAO,CAAC,EAAE,QAAQ,MAAM,OAAO,EAAE,QAAQ,MAAM,QAAQ,EAAE;CAC3E,CAAC,EACA,OAAO,OAAO,EACd,KAAK,GAAG;AACb;AAEA,MAAM,mBAAmB;;;;AAKzB,MAAa,iBAAkC;CAC7C,gBACE,MACA,OACA,GAAG,aACQ;EACX,MAAM,WAAW,SAAS,KAAK,QAAQ,EAAE,KAAK,EAAE;EAEhD,IAAI,SAAS,kBAAkB,OAAO;EAEtC,IAAI,OAAO,SAAS,UAAU;GAC5B,MAAM,WAAW,iBAAiB,KAAK;GACvC,MAAM,iBAAiB,WAAW,IAAI,aAAa;GACnD,MAAM,YAAY,OAAO;GAEzB,IAAI,kBAAkB,IAAI,IAAI,GAC5B,OAAO,IAAI,OAAO,eAAe;GAGnC,IAAI,cAAc,QAChB,OAAO,IAAI,OAAO,eAAe,GAAG,UAAU,IAAI,KAAK;GAGzD,OAAO,IAAI,OAAO,eAAe,GAAG,SAAS,IAAI,KAAK;EACxD;EAGA,IAAI,OAAO,SAAS,YAClB,IAAI;GACF,MAAM,SAAS,KAAK;IAAE,GAAG;IAAO,UAAU;GAAS,CAAC;GACpD,OAAO,OAAO,WAAW,WAAW,SAAS;EAC/C,QAAQ;GACN,OAAO;EACT;EAGF,OAAO;CACT;CAEA,eACE,SACA,QACA,GAAG,cACQ;EACX,OAAO,OAAO,YAAY,WAAW,UAAU,OAAO,WAAW,EAAE;CACrE;CAEA,UAAU;;;;CAKV,iBACE,MACA,UACwB;EACxB,MAAM,aAAkC,CAAC;EAEzC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,GAC7C,IAAI,QAAQ,aACV,WAAW,QAAQ;OACd,IAAI,QAAQ,WACjB,WAAW,MAAM;OACZ,IAAI,QAAQ,6BAA6B,OAAO,QACrD,WAAW,aAAa,MAAM;OAE9B,WAAW,OAAO;EAItB,OAAO;CACT;AACF;;;;AAKA,MAAa,wBACX,UAMI,CAAC,MACe;CACpB,MAAM,EAAE,oBAAoB;CAE5B,IAAI,iBACF,OAAO;EACL,GAAG;EACH,gBACE,MACA,OACA,GAAG,aACQ,gBAAgB,MAAM,OAAO,QAAQ;CACpD;CAGF,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.cjs","names":["editor","renderIntlayerNode","fallbackPlugin","NodeTypes","internationalization","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.ts"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n getHTML,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport {\n compileWithOptions,\n getMarkdownMetadata,\n} from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type { HTMLComponents } from './html/types';\nimport {\n type IntlayerNode as IntlayerNodeCore,\n renderIntlayerNode,\n} from './renderIntlayerNode';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\nexport type IntlayerNode<T, P = {}> = IntlayerNodeCore<T> & P;\n\nconst escapeHtmlAttr = (str: string): string =>\n str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;');\n\nconst escapeHtmlText = (str: string): string =>\n str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, { children, keyPath, dictionaryKey, ...rest }) => {\n if (process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' && editor.enabled) {\n const rawStr = String(children ?? '');\n const keyPathJson = JSON.stringify(keyPath ?? []);\n const dictKey = String(dictionaryKey ?? '');\n\n /**\n * In editor mode, string coercion returns the wrapper HTML so that\n * `element.innerHTML = content.title` automatically inserts the\n * `<intlayer-content-selector-wrapper>` into the DOM.\n */\n const htmlStr = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(rawStr)}</intlayer-content-selector-wrapper>`;\n\n return renderIntlayerNode({\n ...rest,\n value: children as string,\n children: htmlStr,\n keyPath,\n dictionaryKey,\n additionalProps: {\n toElement: (): HTMLElement => {\n const wrapper = document.createElement(\n 'intlayer-content-selector-wrapper'\n );\n wrapper.setAttribute('key-path', keyPathJson);\n wrapper.setAttribute('dictionary-key', dictKey);\n wrapper.textContent = rawStr;\n return wrapper;\n },\n },\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: children as string,\n children,\n });\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, _S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly (infer F)[];\n}\n ? <V extends { [K in Extract<F, string>]: string | number }>(\n values: V\n ) => I extends string ? IntlayerNode<string> : DeepTransformContent<I, L>\n : never;\n\nexport const insertionPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_INSERTION'] === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n { type: NodeTypes.INSERTION },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: (props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const result = splitInsertionTemplate(\n transformedResult,\n values\n );\n const resultStr = result.isSimple\n ? (result.parts as string)\n : (result.parts as string[]).join('');\n\n return deepTransformNode(resultStr, {\n ...subProps,\n plugins: props.plugins,\n children: resultStr,\n });\n };\n },\n };\n\n const transformed = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n if (\n typeof children === 'object' &&\n children !== null &&\n 'nodeType' in children &&\n (\n [NodeTypes.ENUMERATION, NodeTypes.CONDITION] as NodeType[]\n ).includes(children.nodeType as NodeType)\n ) {\n return (values: any) => (arg: any) => {\n const inner = (transformed as (a: any) => any)(arg);\n return typeof inner === 'function' ? inner(values) : inner;\n };\n }\n\n return transformed;\n },\n };\n\n/** ---------------------------------------------\n * MARKDOWN PLUGIN\n * --------------------------------------------- */\n\nconst vanillaRuntime = {\n createElement: (tag: string, props: any, ...children: any[]) => {\n const attrs = Object.entries(props || {})\n .filter(\n ([key]) => key !== 'children' && key !== 'key' && key !== '_innerHTML'\n )\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ');\n const innerHTML = props?._innerHTML;\n const childrenStr =\n innerHTML !== undefined ? innerHTML : children.flat(Infinity).join('');\n return `<${tag}${attrs ? ` ${attrs}` : ''}>${childrenStr}</${tag}>`;\n },\n normalizeProps: (_tag: string, props: Record<string, any>) => {\n const normalized: Record<string, any> = {};\n for (const [key, value] of Object.entries(props)) {\n if (key === 'className') {\n normalized.class = value;\n } else if (key === 'htmlFor') {\n normalized.for = value;\n } else if (key === 'dangerouslySetInnerHTML' && (value as any)?.__html) {\n normalized._innerHTML = (value as any).__html;\n } else {\n normalized[key] = value;\n }\n }\n return normalized;\n },\n};\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n /** Returns the rendered markdown; render with .use(). */\n use: (components?: HTMLComponents<'permissive', {}>) => string;\n }\n >\n : never;\n\nexport const markdownStringPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const { plugins: _plugins, ...rest } = props;\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, subProps) =>\n renderIntlayerNode({\n ...subProps,\n value: metadataNode,\n children: node,\n }),\n };\n\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const compile = (components: any = {}) =>\n compileWithOptions(\n node,\n {\n ...vanillaRuntime,\n createElement: (tag: any, props: any, ...children: any[]) => {\n const override = components[tag];\n if (typeof override === 'function') {\n return override({ ...props, children: children.join('') });\n }\n return vanillaRuntime.createElement(tag, props, ...children);\n },\n },\n {}\n ) as any;\n\n const value = compile();\n let children = node;\n\n if (\n process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' &&\n editor.enabled\n ) {\n const keyPathJson = JSON.stringify(props.keyPath ?? []);\n const dictKey = String(props.dictionaryKey ?? '');\n children = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;\n }\n\n return renderIntlayerNode({\n ...props,\n value,\n children,\n additionalProps: {\n metadata: metadataNodes,\n use: (components?: any) => compile(components),\n },\n }) as any;\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n metadata?: infer U;\n tags?: infer U;\n}\n ? {\n use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<M>;\n metadata: DeepTransformContent<U>;\n }\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n { type: NodeTypes.MARKDOWN },\n ];\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? {\n use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<I>;\n }\n : never;\n\nexport const htmlPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_HTML'] === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n transform: (node: HTMLContent<string>, props) => {\n const htmlStr = node[NodeTypes.HTML];\n\n const use = (components: Record<string, any> = {}) => {\n const wrappedComponents = new Proxy(components, {\n get(target, prop) {\n if (typeof prop === 'string' && prop in target) {\n const Component = target[prop];\n return (props: any) => {\n const children = Array.isArray(props.children)\n ? props.children.join('')\n : props.children;\n return Component({ ...props, children });\n };\n }\n if (typeof prop === 'string' && /^[a-z][a-z0-9]*$/.test(prop)) {\n return (props: any) => {\n const attrs = Object.entries(props)\n .filter(([key]) => key !== 'children' && key !== 'key')\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ');\n const children = Array.isArray(props.children)\n ? props.children.join('')\n : props.children;\n return `<${prop}${attrs ? ` ${attrs}` : ''}>${children}</${prop}>`;\n };\n }\n return undefined;\n },\n });\n\n const result = getHTML(htmlStr, wrappedComponents as any);\n return Array.isArray(result) ? result.join('') : result;\n };\n\n const value = use();\n let children = htmlStr;\n\n if (\n process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' &&\n editor.enabled\n ) {\n const keyPathJson = JSON.stringify(props.keyPath ?? []);\n const dictKey = String(props.dictionaryKey ?? '');\n children = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;\n }\n\n return renderIntlayerNode({\n ...props,\n value,\n children,\n additionalProps: {\n use: (components?: any) => use(components),\n },\n });\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport interface IInterpreterPluginVanilla<T, S, L extends LocalesValues> {\n vanillaIntlayerNode: IntlayerNodeCond<T>;\n vanillaInsertion: InsertionCond<T, S, L>;\n vanillaMarkdown: MarkdownCond<T>;\n vanillaHtml: HTMLPluginCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the `vanilla-intlayer` plugins will override the types of `intlayer` functions.\n * Use `getIntlayer` from `vanilla-intlayer` (not from `intlayer`) to get properly typed\n * `IntlayerNode` wrappers with `.value` access on string/number content.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion'\n> & {\n vanillaIntlayerNode: true;\n vanillaInsertion: true;\n vanillaMarkdown: true;\n vanillaHtml: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for Vanilla content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;AAgDA,MAAM,kBAAkB,QACtB,IAAI,QAAQ,MAAM,QAAQ,CAAC,QAAQ,MAAM,SAAS;AAEpD,MAAM,kBAAkB,QACtB,IAAI,QAAQ,MAAM,QAAQ,CAAC,QAAQ,MAAM,OAAO,CAAC,QAAQ,MAAM,OAAO;AAExE,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YAAY,OAAO,EAAE,UAAU,SAAS,eAAe,GAAG,WAAW;EACnE,IAAI,QAAQ,IAAI,+BAA+B,WAAWA,8BAAO,SAAS;GACxE,MAAM,SAAS,OAAO,YAAY,GAAG;GACrC,MAAM,cAAc,KAAK,UAAU,WAAW,EAAE,CAAC;GACjD,MAAM,UAAU,OAAO,iBAAiB,GAAG;;;;;;GAO3C,MAAM,UAAU,gDAAgD,eAAe,YAAY,CAAC,oBAAoB,eAAe,QAAQ,CAAC,IAAI,eAAe,OAAO,CAAC;GAEnK,OAAOC,8CAAmB;IACxB,GAAG;IACH,OAAO;IACP,UAAU;IACV;IACA;IACA,iBAAiB,EACf,iBAA8B;KAC5B,MAAM,UAAU,SAAS,cACvB,oCACD;KACD,QAAQ,aAAa,YAAY,YAAY;KAC7C,QAAQ,aAAa,kBAAkB,QAAQ;KAC/C,QAAQ,cAAc;KACtB,OAAO;OAEV;IACF,CAAC;;EAGJ,OAAOA,8CAAmB;GACxB,GAAG;GACH,OAAO;GACP;GACD,CAAC;;CAEL;AAgBD,MAAa,kBACX,QAAQ,IAAI,oCAAoC,UAC5CC,4CACA;CACE,IAAI;CACJ,YAAY,SAC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qB,gBAAgB,OACjD;EACDC;+CACa,UAAUD,4CAAqB,cAAc;EAC1DE;+CACa,UAAUF,4CAAqB,cAAc;EAC1DG;EACAC;EACA;EACA;EACA;EACA;EACD;CAED,aAAa,IAAI,UAAU,QAAQ;CAEnC,OAAO"}
1
+ {"version":3,"file":"plugins.cjs","names":["editor","renderIntlayerNode","fallbackPlugin","NodeTypes","internationalization","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.ts"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n getHTML,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport {\n compileWithOptions,\n getMarkdownMetadata,\n} from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type { HTMLComponents } from './html/types';\nimport {\n type IntlayerNode as IntlayerNodeCore,\n renderIntlayerNode,\n} from './renderIntlayerNode';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\nexport type IntlayerNode<T, P = {}> = IntlayerNodeCore<T> & P;\n\nconst escapeHtmlAttr = (str: string): string =>\n str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;');\n\nconst escapeHtmlText = (str: string): string =>\n str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, { children, keyPath, dictionaryKey, ...rest }) => {\n if (process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' && editor.enabled) {\n const rawStr = String(children ?? '');\n const keyPathJson = JSON.stringify(keyPath ?? []);\n const dictKey = String(dictionaryKey ?? '');\n\n /**\n * In editor mode, string coercion returns the wrapper HTML so that\n * `element.innerHTML = content.title` automatically inserts the\n * `<intlayer-content-selector-wrapper>` into the DOM.\n */\n const htmlStr = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(rawStr)}</intlayer-content-selector-wrapper>`;\n\n return renderIntlayerNode({\n ...rest,\n value: children as string,\n children: htmlStr,\n keyPath,\n dictionaryKey,\n additionalProps: {\n toElement: (): HTMLElement => {\n const wrapper = document.createElement(\n 'intlayer-content-selector-wrapper'\n );\n wrapper.setAttribute('key-path', keyPathJson);\n wrapper.setAttribute('dictionary-key', dictKey);\n wrapper.textContent = rawStr;\n return wrapper;\n },\n },\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: children as string,\n children,\n });\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, _S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly (infer F)[];\n}\n ? <V extends { [K in Extract<F, string>]: string | number }>(\n values: V\n ) => I extends string ? IntlayerNode<string> : DeepTransformContent<I, L>\n : never;\n\nexport const insertionPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_INSERTION'] === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n { type: NodeTypes.INSERTION },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: (props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const result = splitInsertionTemplate(\n transformedResult,\n values\n );\n const resultStr = result.isSimple\n ? (result.parts as string)\n : (result.parts as string[]).join('');\n\n return deepTransformNode(resultStr, {\n ...subProps,\n plugins: props.plugins,\n children: resultStr,\n });\n };\n },\n };\n\n const transformed = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n if (\n typeof children === 'object' &&\n children !== null &&\n 'nodeType' in children &&\n (\n [NodeTypes.ENUMERATION, NodeTypes.CONDITION] as NodeType[]\n ).includes(children.nodeType as NodeType)\n ) {\n return (values: any) => (arg: any) => {\n const inner = (transformed as (a: any) => any)(arg);\n return typeof inner === 'function' ? inner(values) : inner;\n };\n }\n\n return transformed;\n },\n };\n\n/** ---------------------------------------------\n * MARKDOWN PLUGIN\n * --------------------------------------------- */\n\nconst vanillaRuntime = {\n createElement: (tag: string, props: any, ...children: any[]) => {\n const attrs = Object.entries(props || {})\n .filter(\n ([key]) => key !== 'children' && key !== 'key' && key !== '_innerHTML'\n )\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ');\n const innerHTML = props?._innerHTML;\n const childrenStr =\n innerHTML !== undefined ? innerHTML : children.flat(Infinity).join('');\n return `<${tag}${attrs ? ` ${attrs}` : ''}>${childrenStr}</${tag}>`;\n },\n normalizeProps: (_tag: string, props: Record<string, any>) => {\n const normalized: Record<string, any> = {};\n for (const [key, value] of Object.entries(props)) {\n if (key === 'className') {\n normalized.class = value;\n } else if (key === 'htmlFor') {\n normalized.for = value;\n } else if (key === 'dangerouslySetInnerHTML' && (value as any)?.__html) {\n normalized._innerHTML = (value as any).__html;\n } else {\n normalized[key] = value;\n }\n }\n return normalized;\n },\n};\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n /** Returns the rendered markdown; render with .use(). */\n use: (components?: HTMLComponents<'permissive', {}>) => string;\n }\n >\n : never;\n\nexport const markdownStringPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const { plugins: _plugins, ...rest } = props;\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, subProps) =>\n renderIntlayerNode({\n ...subProps,\n value: metadataNode,\n children: node,\n }),\n };\n\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const compile = (components: any = {}) =>\n compileWithOptions(\n node,\n {\n ...vanillaRuntime,\n createElement: (tag: any, props: any, ...children: any[]) => {\n const override = components[tag];\n if (typeof override === 'function') {\n return override({ ...props, children: children.join('') });\n }\n return vanillaRuntime.createElement(tag, props, ...children);\n },\n },\n {}\n ) as any;\n\n const value = compile();\n let children = node;\n\n if (\n process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' &&\n editor.enabled\n ) {\n const keyPathJson = JSON.stringify(props.keyPath ?? []);\n const dictKey = String(props.dictionaryKey ?? '');\n children = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;\n }\n\n return renderIntlayerNode({\n ...props,\n value,\n children,\n additionalProps: {\n metadata: metadataNodes,\n use: (components?: any) => compile(components),\n },\n }) as any;\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n metadata?: infer U;\n tags?: infer U;\n}\n ? {\n use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<M>;\n metadata: DeepTransformContent<U>;\n }\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n { type: NodeTypes.MARKDOWN },\n ];\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? {\n use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<I>;\n }\n : never;\n\nexport const htmlPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_HTML'] === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n transform: (node: HTMLContent<string>, props) => {\n const htmlStr = node[NodeTypes.HTML];\n\n const use = (components: Record<string, any> = {}) => {\n const wrappedComponents = new Proxy(components, {\n get(target, prop) {\n if (typeof prop === 'string' && prop in target) {\n const Component = target[prop];\n return (props: any) => {\n const children = Array.isArray(props.children)\n ? props.children.join('')\n : props.children;\n return Component({ ...props, children });\n };\n }\n if (typeof prop === 'string' && /^[a-z][a-z0-9]*$/.test(prop)) {\n return (props: any) => {\n const attrs = Object.entries(props)\n .filter(([key]) => key !== 'children' && key !== 'key')\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ');\n const children = Array.isArray(props.children)\n ? props.children.join('')\n : props.children;\n return `<${prop}${attrs ? ` ${attrs}` : ''}>${children}</${prop}>`;\n };\n }\n return undefined;\n },\n });\n\n const result = getHTML(htmlStr, wrappedComponents as any);\n return Array.isArray(result) ? result.join('') : result;\n };\n\n const value = use();\n let children = htmlStr;\n\n if (\n process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' &&\n editor.enabled\n ) {\n const keyPathJson = JSON.stringify(props.keyPath ?? []);\n const dictKey = String(props.dictionaryKey ?? '');\n children = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;\n }\n\n return renderIntlayerNode({\n ...props,\n value,\n children,\n additionalProps: {\n use: (components?: any) => use(components),\n },\n });\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport interface IInterpreterPluginVanilla<T, S, L extends LocalesValues> {\n vanillaIntlayerNode: IntlayerNodeCond<T>;\n vanillaInsertion: InsertionCond<T, S, L>;\n vanillaMarkdown: MarkdownCond<T>;\n vanillaHtml: HTMLPluginCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the `vanilla-intlayer` plugins will override the types of `intlayer` functions.\n * Use `getIntlayer` from `vanilla-intlayer` (not from `intlayer`) to get properly typed\n * `IntlayerNode` wrappers with `.value` access on string/number content.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion'\n> & {\n vanillaIntlayerNode: true;\n vanillaInsertion: true;\n vanillaMarkdown: true;\n vanillaHtml: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for Vanilla content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;AAgDA,MAAM,kBAAkB,QACtB,IAAI,QAAQ,MAAM,OAAO,EAAE,QAAQ,MAAM,QAAQ;AAEnD,MAAM,kBAAkB,QACtB,IAAI,QAAQ,MAAM,OAAO,EAAE,QAAQ,MAAM,MAAM,EAAE,QAAQ,MAAM,MAAM;AAEvE,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YAAY,OAAO,EAAE,UAAU,SAAS,eAAe,GAAG,WAAW;EACnE,IAAI,QAAQ,IAAI,+BAA+B,WAAWA,8BAAO,SAAS;GACxE,MAAM,SAAS,OAAO,YAAY,EAAE;GACpC,MAAM,cAAc,KAAK,U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AAI,WAAW;EAEf,IACE,QAAQ,IAAI,+BAA+B,WAC3CH,8BAAO,SACP;GACA,MAAM,cAAc,KAAK,UAAU,MAAM,WAAW,CAAC,CAAC;GACtD,MAAM,UAAU,OAAO,MAAM,iBAAiB,EAAE;GAChD,WAAW,gDAAgD,eAAe,WAAW,EAAE,oBAAoB,eAAe,OAAO,EAAE,IAAI,eAAe,KAAK,EAAE;EAC/J;EAEA,OAAOC,8CAAmB;GACxB,GAAG;GACH;GACA;GACA,iBAAiB,EACf,MAAM,eAAqB,IAAI,UAAU,EAC3C;EACF,CAAC;CACH;AACF;AAmCN,MAAM,+BAAe,IAAI,IAAuB;;;;;AAMhD,MAAa,cACX,QACA,WAAW,SACG;CAEd,MAAM,WAAW,GADK,UAAUG,4CAAqB,cACnB,GAAG;CAErC,IAAI,aAAa,IAAI,QAAQ,GAC3B,OAAO,aAAa,IAAI,QAAQ;CAGlC,MAAM,UAAU;oDAEZ,UAAUA,4CAAqB,eAC/B,WAAWA,4CAAqB,gBAAgB,MAClD;EACAC;+CACa,UAAUD,4CAAqB,aAAa;EACzDE;+CACa,UAAUF,4CAAqB,aAAa;EACzDG;EACAC;EACA;EACA;EACA;EACA;CACF;CAEA,aAAa,IAAI,UAAU,OAAO;CAElC,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"renderIntlayerNode.cjs","names":[],"sources":["../../src/renderIntlayerNode.ts"],"sourcesContent":["import type { ResolvedEditor } from '@intlayer/types/module_augmentation';\n\nexport type IntlayerNode<T = string> = ResolvedEditor<\n T & {\n raw: T;\n value: T;\n toString: () => string;\n valueOf: () => T;\n toJSON: () => T;\n __update: (next: IntlayerNode<T>) => void;\n },\n {\n raw: T;\n value: T;\n toString: () => string;\n valueOf: () => T;\n toJSON: () => T;\n __update: (next: IntlayerNode<T>) => void;\n }\n> &\n T;\n\nexport const renderIntlayerNode = <\n T, // Broadened to support arrays, numbers, objects, etc.\n>({\n value,\n children,\n additionalProps = {},\n}: {\n value: T;\n children?: any;\n additionalProps?: Record<string, unknown>;\n [key: string]: unknown;\n}): IntlayerNode<T> => {\n let _value = value;\n\n // When children is a string that differs from value, it acts as a display\n // override (e.g. editor HTML wrapper). Otherwise toString/toPrimitive reflect\n // the live _value so that __update propagates.\n const displayOverride =\n typeof children === 'string' && children !== String(value ?? '')\n ? children\n : null;\n\n const node = {\n toString: () => displayOverride ?? String(_value ?? ''),\n valueOf: () => _value,\n [Symbol.toPrimitive]: () => displayOverride ?? _value,\n toJSON: () => _value,\n\n get raw() {\n return _value;\n },\n set raw(value: T) {\n _value = value;\n },\n\n get value() {\n return _value;\n },\n\n __update(next: any) {\n _value = next?.raw ?? next?.value ?? next;\n },\n\n ...additionalProps,\n };\n\n // Delegate native methods from the underlying value (any type) to node.\n if (_value !== null && _value !== undefined) {\n const valObj = Object(_value); // Safely boxes primitives (e.g., 50 -> Number object)\n const proto = Object.getPrototypeOf(valObj);\n for (const prop of Object.getOwnPropertyNames(proto)) {\n if (prop === 'constructor' || prop in node) continue;\n const valProp = valObj[prop]; // read from instance so length/index values are correct\n if (typeof valProp === 'function') {\n Object.defineProperty(node, prop, {\n value: valProp.bind(_value),\n writable: true,\n configurable: true,\n });\n }\n }\n }\n\n return node as unknown as IntlayerNode<T>;\n};\n"],"mappings":";;;AAsBA,MAAa,sBAEX,EACA,OACA,UACA,kBAAkB,EAAE,OAMC;CACrB,IAAI,SAAS;CAKb,MAAM,kBACJ,OAAO,aAAa,YAAY,aAAa,OAAO,SAAS,GAAG,GAC5D,WACA;CAEN,MAAM,OAAO;EACX,gBAAgB,mBAAmB,OAAO,UAAU,GAAG;EACvD,eAAe;GACd,OAAO,oBAAoB,mBAAmB;EAC/C,cAAc;EAEd,IAAI,MAAM;GACR,OAAO;;EAET,IAAI,IAAI,OAAU;GAChB,SAAS;;EAGX,IAAI,QAAQ;GACV,OAAO;;EAGT,SAAS,MAAW;GAClB,SAAS,MAAM,OAAO,MAAM,SAAS;;EAGvC,GAAG;EACJ;CAGD,IAAI,WAAW,QAAQ,WAAW,QAAW;EAC3C,MAAM,SAAS,OAAO,OAAO;EAC7B,MAAM,QAAQ,OAAO,eAAe,OAAO;EAC3C,KAAK,MAAM,QAAQ,OAAO,oBAAoB,MAAM,EAAE;GACpD,IAAI,SAAS,iBAAiB,QAAQ,MAAM;GAC5C,MAAM,UAAU,OAAO;GACvB,IAAI,OAAO,YAAY,YACrB,OAAO,eAAe,MAAM,MAAM;IAChC,OAAO,QAAQ,KAAK,OAAO;IAC3B,UAAU;IACV,cAAc;IACf,CAAC;;;CAKR,OAAO"}
1
+ {"version":3,"file":"renderIntlayerNode.cjs","names":[],"sources":["../../src/renderIntlayerNode.ts"],"sourcesContent":["import type { ResolvedEditor } from '@intlayer/types/module_augmentation';\n\nexport type IntlayerNode<T = string> = ResolvedEditor<\n T & {\n raw: T;\n value: T;\n toString: () => string;\n valueOf: () => T;\n toJSON: () => T;\n __update: (next: IntlayerNode<T>) => void;\n },\n {\n raw: T;\n value: T;\n toString: () => string;\n valueOf: () => T;\n toJSON: () => T;\n __update: (next: IntlayerNode<T>) => void;\n }\n> &\n T;\n\nexport const renderIntlayerNode = <\n T, // Broadened to support arrays, numbers, objects, etc.\n>({\n value,\n children,\n additionalProps = {},\n}: {\n value: T;\n children?: any;\n additionalProps?: Record<string, unknown>;\n [key: string]: unknown;\n}): IntlayerNode<T> => {\n let _value = value;\n\n // When children is a string that differs from value, it acts as a display\n // override (e.g. editor HTML wrapper). Otherwise toString/toPrimitive reflect\n // the live _value so that __update propagates.\n const displayOverride =\n typeof children === 'string' && children !== String(value ?? '')\n ? children\n : null;\n\n const node = {\n toString: () => displayOverride ?? String(_value ?? ''),\n valueOf: () => _value,\n [Symbol.toPrimitive]: () => displayOverride ?? _value,\n toJSON: () => _value,\n\n get raw() {\n return _value;\n },\n set raw(value: T) {\n _value = value;\n },\n\n get value() {\n return _value;\n },\n\n __update(next: any) {\n _value = next?.raw ?? next?.value ?? next;\n },\n\n ...additionalProps,\n };\n\n // Delegate native methods from the underlying value (any type) to node.\n if (_value !== null && _value !== undefined) {\n const valObj = Object(_value); // Safely boxes primitives (e.g., 50 -> Number object)\n const proto = Object.getPrototypeOf(valObj);\n for (const prop of Object.getOwnPropertyNames(proto)) {\n if (prop === 'constructor' || prop in node) continue;\n const valProp = valObj[prop]; // read from instance so length/index values are correct\n if (typeof valProp === 'function') {\n Object.defineProperty(node, prop, {\n value: valProp.bind(_value),\n writable: true,\n configurable: true,\n });\n }\n }\n }\n\n return node as unknown as IntlayerNode<T>;\n};\n"],"mappings":";;;AAsBA,MAAa,sBAEX,EACA,OACA,UACA,kBAAkB,CAAC,QAME;CACrB,IAAI,SAAS;CAKb,MAAM,kBACJ,OAAO,aAAa,YAAY,aAAa,OAAO,SAAS,EAAE,IAC3D,WACA;CAEN,MAAM,OAAO;EACX,gBAAgB,mBAAmB,OAAO,UAAU,EAAE;EACtD,eAAe;GACd,OAAO,oBAAoB,mBAAmB;EAC/C,cAAc;EAEd,IAAI,MAAM;GACR,OAAO;EACT;EACA,IAAI,IAAI,OAAU;GAChB,SAAS;EACX;EAEA,IAAI,QAAQ;GACV,OAAO;EACT;EAEA,SAAS,MAAW;GAClB,SAAS,MAAM,OAAO,MAAM,SAAS;EACvC;EAEA,GAAG;CACL;CAGA,IAAI,WAAW,QAAQ,WAAW,QAAW;EAC3C,MAAM,SAAS,OAAO,MAAM;EAC5B,MAAM,QAAQ,OAAO,eAAe,MAAM;EAC1C,KAAK,MAAM,QAAQ,OAAO,oBAAoB,KAAK,GAAG;GACpD,IAAI,SAAS,iBAAiB,QAAQ,MAAM;GAC5C,MAAM,UAAU,OAAO;GACvB,IAAI,OAAO,YAAY,YACrB,OAAO,eAAe,MAAM,MAAM;IAChC,OAAO,QAAQ,KAAK,MAAM;IAC1B,UAAU;IACV,cAAc;GAChB,CAAC;EAEL;CACF;CAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"installIntlayer.mjs","names":[],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useEditor } from '../editor/useEditor';\n\ntype LocaleListener = (locale: LocalesValues) => void;\n\nexport class IntlayerClient {\n private _locale: LocalesValues;\n private _listeners: Set<LocaleListener> = new Set();\n isCookieEnabled: boolean;\n\n constructor(locale?: LocalesValues, isCookieEnabled = true) {\n const { defaultLocale } = internationalization ?? {};\n\n setIntlayerIdentifier();\n\n this._locale =\n (locale as LocalesValues) ?? (defaultLocale as LocalesValues);\n this.isCookieEnabled = isCookieEnabled;\n }\n\n get locale(): LocalesValues {\n return this._locale;\n }\n\n setLocale(newLocale: LocalesValues): void {\n this._locale = newLocale;\n for (const listener of this._listeners) {\n listener(newLocale);\n }\n }\n\n subscribe(listener: LocaleListener): () => void {\n this._listeners.add(listener);\n return () => {\n this._listeners.delete(listener);\n };\n }\n\n /**\n * Fire all listeners with the current locale without changing it.\n * Used to trigger re-renders after async data loads.\n */\n notify(): void {\n for (const listener of this._listeners) {\n listener(this._locale);\n }\n }\n}\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerClient | null = null;\n\n/**\n * Create and return a single IntlayerClient instance.\n */\nexport const createIntlayerClient = (\n locale?: LocalesValues,\n isCookieEnabled = true\n): IntlayerClient => {\n if (instance) return instance;\n\n instance = new IntlayerClient(locale, isCookieEnabled);\n return instance;\n};\n\n/**\n * Get the current IntlayerClient instance, creating one with defaults if needed.\n */\nexport const getIntlayerClient = (): IntlayerClient => {\n if (!instance) {\n instance = new IntlayerClient();\n }\n return instance;\n};\n\n/**\n * Install Intlayer into your vanilla JS application.\n *\n * Call this once at application startup, before any Intlayer APIs are used.\n *\n * When called with a `config` argument, `window.INTLAYER_CONFIG` is set so\n * that `@intlayer/config/built` resolves the correct values in the browser\n * without requiring module aliasing in the bundler configuration.\n *\n * @param locale - Initial locale (defaults to config defaultLocale).\n * @param isCookieEnabled - Whether to persist locale in cookies/localStorage.\n * @param config - Optional Intlayer configuration. When provided, sets\n * `window.INTLAYER_CONFIG` with the browser-safe subset of the config so\n * the application works without a Vite/webpack plugin alias.\n * @returns The IntlayerClient singleton.\n *\n * @example\n * ```ts\n * import { installIntlayer } from 'vanilla-intlayer';\n *\n * // With explicit config (no build plugin alias needed):\n * installIntlayer('en', true, {\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n *\n * // With build plugin (alias handles config automatically):\n * installIntlayer('en');\n * ```\n */\nexport const installIntlayer = ({\n locale,\n isCookieEnabled,\n}: {\n locale?: LocalesValues;\n isCookieEnabled?: boolean;\n} = {}): IntlayerClient => {\n const client = createIntlayerClient(locale, isCookieEnabled);\n\n useEditor();\n\n return client;\n};\n"],"mappings":";;;;;AAOA,IAAa,iBAAb,MAA4B;CAC1B,AAAQ;CACR,AAAQ,6BAAkC,IAAI,KAAK;CACnD;CAEA,YAAY,QAAwB,kBAAkB,MAAM;EAC1D,MAAM,EAAE,kBAAkB,wBAAwB,EAAE;EAEpD,uBAAuB;EAEvB,KAAK,UACF,UAA6B;EAChC,KAAK,kBAAkB;;CAGzB,IAAI,SAAwB;EAC1B,OAAO,KAAK;;CAGd,UAAU,WAAgC;EACxC,KAAK,UAAU;EACf,KAAK,MAAM,YAAY,KAAK,YAC1B,SAAS,UAAU;;CAIvB,UAAU,UAAsC;EAC9C,KAAK,WAAW,IAAI,SAAS;EAC7B,aAAa;GACX,KAAK,WAAW,OAAO,SAAS;;;;;;;CAQpC,SAAe;EACb,KAAK,MAAM,YAAY,KAAK,YAC1B,SAAS,KAAK,QAAQ;;;;;;AAQ5B,IAAI,WAAkC;;;;AAKtC,MAAa,wBACX,QACA,kBAAkB,SACC;CACnB,IAAI,UAAU,OAAO;CAErB,WAAW,IAAI,eAAe,QAAQ,gBAAgB;CACtD,OAAO;;;;;AAMT,MAAa,0BAA0C;CACrD,IAAI,CAAC,UACH,WAAW,IAAI,gBAAgB;CAEjC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCT,MAAa,mBAAmB,EAC9B,QACA,oBAIE,EAAE,KAAqB;CACzB,MAAM,SAAS,qBAAqB,QAAQ,gBAAgB;CAE5D,WAAW;CAEX,OAAO"}
1
+ {"version":3,"file":"installIntlayer.mjs","names":[],"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,kBAAkB,wBAAwB,CAAC;EAEnD,sBAAsB;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,UAAU;CAEV,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\n\nexport type WithOnChange<T> = T & {\n /**\n * Subscribe to locale changes. The callback receives the fresh content\n * whenever the active locale changes. Returns the content object itself\n * for convenient one-liner patterns:\n *\n * ```ts\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p')!.textContent = String(c.greeting);\n * });\n * ```\n */\n onChange: (\n callback: <T extends Dictionary, L extends LocalesValues>(\n content: DeepTransformContent<T['content'], L>\n ) => void\n ) => WithOnChange<T>;\n};\n\n/**\n * Get the translated content for a raw dictionary object and optionally\n * subscribe to locale changes via the chainable `.onChange()` method —\n * mirroring the API of `react-intlayer`.\n *\n * Unlike `useIntlayer` (which takes a registered key), this function accepts a\n * dictionary object directly — useful for dictionaries loaded asynchronously\n * or defined inline.\n *\n * The function returns the current content **directly** (same shape as\n * `getDictionary(dict)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useDictionary(myDict);\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useDictionary(myDict);\n * const content = useDictionary(myDict).onChange((c) => render(c));\n * ```\n *\n * @param dictionary - The raw dictionary object.\n * @param locale - Optional locale override.\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import myDict from './myDictionary.content';\n * import { installIntlayer, useDictionary } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p').textContent = String(c.greeting);\n * });\n *\n * document.querySelector('p').textContent = String(content.greeting);\n * ```\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const content = getDictionary(\n dictionary,\n (locale ?? client.locale) as L\n ) as WithOnChange<DeepTransformContent<T['content'], L>>;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n client.subscribe((newLocale) => {\n callback(getDictionary(dictionary, (locale ?? newLocale) as L));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,iBAIX,YACA,WACwD;CACxD,MAAM,SAAS,mBAAmB;CAClC,MAAM,UAAU,cACd,YACC,UAAU,OAAO,OACnB;CAED,QAAQ,YACN,aACG;EACH,OAAO,WAAW,cAAc;GAC9B,SAAS,cAAc,YAAa,UAAU,UAAgB,CAAC;IAC/D;EACF,OAAO;;CAGT,OAAO"}
1
+ {"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { getIntlayerClient } from './installIntlayer';\n\nexport type WithOnChange<T> = T & {\n /**\n * Subscribe to locale changes. The callback receives the fresh content\n * whenever the active locale changes. Returns the content object itself\n * for convenient one-liner patterns:\n *\n * ```ts\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p')!.textContent = String(c.greeting);\n * });\n * ```\n */\n onChange: (\n callback: <T extends Dictionary, L extends LocalesValues>(\n content: DeepTransformContent<T['content'], L>\n ) => void\n ) => WithOnChange<T>;\n};\n\n/**\n * Get the translated content for a raw dictionary object and optionally\n * subscribe to locale changes via the chainable `.onChange()` method —\n * mirroring the API of `react-intlayer`.\n *\n * Unlike `useIntlayer` (which takes a registered key), this function accepts a\n * dictionary object directly — useful for dictionaries loaded asynchronously\n * or defined inline.\n *\n * The function returns the current content **directly** (same shape as\n * `getDictionary(dict)`), plus the `.onChange()` helper:\n *\n * ```ts\n * // React\n * const content = useDictionary(myDict);\n *\n * // Vanilla — identical surface API, opt-in reactivity via .onChange()\n * const content = useDictionary(myDict);\n * const content = useDictionary(myDict).onChange((c) => render(c));\n * ```\n *\n * @param dictionary - The raw dictionary object.\n * @param locale - Optional locale override.\n * @returns The current translated content with an `.onChange()` method.\n *\n * @example\n * ```ts\n * import myDict from './myDictionary.content';\n * import { installIntlayer, useDictionary } from 'vanilla-intlayer';\n *\n * installIntlayer();\n *\n * const content = useDictionary(myDict).onChange((c) => {\n * document.querySelector('p').textContent = String(c.greeting);\n * });\n *\n * document.querySelector('p').textContent = String(content.greeting);\n * ```\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): WithOnChange<DeepTransformContent<T['content'], L>> => {\n const client = getIntlayerClient();\n const content = getDictionary(\n dictionary,\n (locale ?? client.locale) as L\n ) as WithOnChange<DeepTransformContent<T['content'], L>>;\n\n content.onChange = (\n callback: (content: DeepTransformContent<T['content'], L>) => void\n ) => {\n client.subscribe((newLocale) => {\n callback(getDictionary(dictionary, (locale ?? newLocale) as L));\n });\n return content;\n };\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,iBAIX,YACA,WACwD;CACxD,MAAM,SAAS,kBAAkB;CACjC,MAAM,UAAU,cACd,YACC,UAAU,OAAO,MACpB;CAEA,QAAQ,YACN,aACG;EACH,OAAO,WAAW,cAAc;GAC9B,SAAS,cAAc,YAAa,UAAU,SAAe,CAAC;EAChE,CAAC;EACD,OAAO;CACT;CAEA,OAAO;AACT"}