@generaltranslation/react-core 11.4.18 → 12.0.0-samsara.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/components-rsc.d.mts +1 -0
  3. package/dist/components.d.mts +1 -0
  4. package/dist/context/InternalGTProvider.cjs.map +1 -1
  5. package/dist/context/InternalGTProvider.d.ts +3 -2
  6. package/dist/context/InternalGTProvider.d.ts.map +1 -1
  7. package/dist/context/InternalGTProvider.mjs.map +1 -1
  8. package/dist/context/context.cjs.map +1 -1
  9. package/dist/context/context.mjs.map +1 -1
  10. package/dist/functions/helpers/getTranslationsSnapshot.cjs.map +1 -1
  11. package/dist/functions/helpers/getTranslationsSnapshot.d.ts +2 -2
  12. package/dist/functions/helpers/getTranslationsSnapshot.d.ts.map +1 -1
  13. package/dist/functions/helpers/getTranslationsSnapshot.mjs.map +1 -1
  14. package/dist/functions/translation/t.cjs.map +1 -1
  15. package/dist/functions/translation/t.d.ts.map +1 -1
  16. package/dist/functions/translation/t.mjs.map +1 -1
  17. package/dist/hooks/external-store/useTrackedTranslationResolver.cjs.map +1 -1
  18. package/dist/hooks/external-store/useTrackedTranslationResolver.d.ts +1 -1
  19. package/dist/hooks/external-store/useTrackedTranslationResolver.mjs.map +1 -1
  20. package/dist/hooks/external-store.cjs.map +1 -1
  21. package/dist/hooks/external-store.mjs.map +1 -1
  22. package/dist/hooks/utils/missing-translation.cjs.map +1 -1
  23. package/dist/hooks/utils/missing-translation.d.ts +2 -2
  24. package/dist/hooks/utils/missing-translation.d.ts.map +1 -1
  25. package/dist/hooks/utils/missing-translation.mjs.map +1 -1
  26. package/dist/hooks.d.mts +1 -0
  27. package/dist/i18n-cache/ReactI18nCache.cjs.map +1 -1
  28. package/dist/i18n-cache/ReactI18nCache.d.ts +2 -2
  29. package/dist/i18n-cache/ReactI18nCache.d.ts.map +1 -1
  30. package/dist/i18n-cache/ReactI18nCache.mjs.map +1 -1
  31. package/dist/i18n-cache/singleton-operations.cjs.map +1 -1
  32. package/dist/i18n-cache/singleton-operations.mjs.map +1 -1
  33. package/dist/i18n-store/I18nStore.cjs.map +1 -1
  34. package/dist/i18n-store/I18nStore.d.ts +6 -5
  35. package/dist/i18n-store/I18nStore.d.ts.map +1 -1
  36. package/dist/i18n-store/I18nStore.mjs.map +1 -1
  37. package/dist/i18n-store/storeTypes.d.ts +4 -3
  38. package/dist/i18n-store/storeTypes.d.ts.map +1 -1
  39. package/dist/i18n-store/useI18nStore.cjs.map +1 -1
  40. package/dist/i18n-store/useI18nStore.mjs.map +1 -1
  41. package/dist/i18n-store/utils/translations.cjs.map +1 -1
  42. package/dist/i18n-store/utils/translations.mjs.map +1 -1
  43. package/dist/pure.d.mts +1 -0
  44. package/dist/unstable/t.cjs +2 -0
  45. package/dist/unstable/t.cjs.map +1 -0
  46. package/dist/unstable/t.d.ts +16 -0
  47. package/dist/unstable/t.d.ts.map +1 -0
  48. package/dist/unstable/t.mjs +2 -0
  49. package/dist/unstable/t.mjs.map +1 -0
  50. package/dist/unstable/useGT.cjs +2 -0
  51. package/dist/unstable/useGT.cjs.map +1 -0
  52. package/dist/unstable/useGT.d.ts +17 -0
  53. package/dist/unstable/useGT.d.ts.map +1 -0
  54. package/dist/unstable/useGT.mjs +2 -0
  55. package/dist/unstable/useGT.mjs.map +1 -0
  56. package/dist/unstable/useMessages.cjs +2 -0
  57. package/dist/unstable/useMessages.cjs.map +1 -0
  58. package/dist/unstable/useMessages.d.ts +16 -0
  59. package/dist/unstable/useMessages.d.ts.map +1 -0
  60. package/dist/unstable/useMessages.mjs +2 -0
  61. package/dist/unstable/useMessages.mjs.map +1 -0
  62. package/dist/unstable.cjs +1 -0
  63. package/dist/unstable.d.mts +1 -0
  64. package/dist/unstable.d.ts +5 -0
  65. package/dist/unstable.mjs +1 -0
  66. package/package.json +46 -32
@@ -1,9 +1,9 @@
1
- import { Translation } from "gt-i18n/types";
1
+ import { Content } from "@generaltranslation/format/types";
2
2
  import { I18nCacheConstructorParams } from "gt-i18n/internal/types";
3
3
  import { I18nCache } from "gt-i18n/internal";
4
4
 
5
5
  //#region src/i18n-cache/ReactI18nCache.d.ts
6
- declare class ReactI18nCache extends I18nCache<Translation> {}
6
+ declare class ReactI18nCache extends I18nCache<Content> {}
7
7
  type ReactI18nCacheParams = I18nCacheConstructorParams;
8
8
  //#endregion
9
9
  export { ReactI18nCache, ReactI18nCacheParams };
@@ -1 +1 @@
1
- {"version":3,"file":"ReactI18nCache.d.ts","names":[],"sources":["../../src/i18n-cache/ReactI18nCache.ts"],"mappings":";;;;;cAIa,cAAA,SAAuB,SAAA,CAAU,WAAA;AAAA,KAClC,oBAAA,GAAuB,0BAAA"}
1
+ {"version":3,"file":"ReactI18nCache.d.ts","names":[],"sources":["../../src/i18n-cache/ReactI18nCache.ts"],"mappings":";;;;;cAIa,cAAA,SAAuB,SAAA,CAAU,OAAA;AAAA,KAClC,oBAAA,GAAuB,0BAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"ReactI18nCache.mjs","names":[],"sources":["../../src/i18n-cache/ReactI18nCache.ts"],"sourcesContent":["import { I18nCache } from 'gt-i18n/internal';\nimport type { I18nCacheConstructorParams } from 'gt-i18n/internal/types';\nimport type { Translation } from 'gt-i18n/types';\n\nexport class ReactI18nCache extends I18nCache<Translation> {}\nexport type ReactI18nCacheParams = I18nCacheConstructorParams;\n"],"mappings":"6CAIA,IAAa,EAAb,cAAoC,CAAuB"}
1
+ {"version":3,"file":"ReactI18nCache.mjs","names":[],"sources":["../../src/i18n-cache/ReactI18nCache.ts"],"sourcesContent":["import { I18nCache } from 'gt-i18n/internal';\nimport type { I18nCacheConstructorParams } from 'gt-i18n/internal/types';\nimport type { Content } from '@generaltranslation/format/types';\n\nexport class ReactI18nCache extends I18nCache<Content> {}\nexport type ReactI18nCacheParams = I18nCacheConstructorParams;\n"],"mappings":"6CAIA,IAAa,EAAb,cAAoC,CAAmB"}
@@ -1 +1 @@
1
- {"version":3,"file":"singleton-operations.cjs","names":[],"sources":["../../src/i18n-cache/singleton-operations.ts"],"sourcesContent":["import { getI18nCache, setI18nCache } from 'gt-i18n/internal';\nimport type { I18nCache } from 'gt-i18n/internal';\nimport type { Translation } from 'gt-i18n/types';\nimport type { ReactI18nCache } from './ReactI18nCache';\n\n// ===== I18n Cache ===== //\n\nexport function getReactI18nCache(): ReactI18nCache {\n return getI18nCache() as ReactI18nCache;\n}\n\nexport function setReactI18nCache(i18nCache: ReactI18nCache): void {\n setI18nCache(i18nCache as I18nCache<Translation>);\n}\n"],"mappings":"+EAOA,SAAgB,GAAoC,CAClD,OAAA,EAAA,EAAA,eAAqB,CAGvB,SAAgB,EAAkB,EAAiC,EACjE,EAAA,EAAA,cAAa,EAAoC"}
1
+ {"version":3,"file":"singleton-operations.cjs","names":[],"sources":["../../src/i18n-cache/singleton-operations.ts"],"sourcesContent":["import { getI18nCache, setI18nCache } from 'gt-i18n/internal';\nimport type { I18nCache } from 'gt-i18n/internal';\nimport type { Content } from '@generaltranslation/format/types';\nimport type { ReactI18nCache } from './ReactI18nCache';\n\n// ===== I18n Cache ===== //\n\nexport function getReactI18nCache(): ReactI18nCache {\n return getI18nCache() as ReactI18nCache;\n}\n\nexport function setReactI18nCache(i18nCache: ReactI18nCache): void {\n setI18nCache(i18nCache as I18nCache<Content>);\n}\n"],"mappings":"+EAOA,SAAgB,GAAoC,CAClD,OAAA,EAAA,EAAA,eAAqB,CAGvB,SAAgB,EAAkB,EAAiC,EACjE,EAAA,EAAA,cAAa,EAAgC"}
@@ -1 +1 @@
1
- {"version":3,"file":"singleton-operations.mjs","names":[],"sources":["../../src/i18n-cache/singleton-operations.ts"],"sourcesContent":["import { getI18nCache, setI18nCache } from 'gt-i18n/internal';\nimport type { I18nCache } from 'gt-i18n/internal';\nimport type { Translation } from 'gt-i18n/types';\nimport type { ReactI18nCache } from './ReactI18nCache';\n\n// ===== I18n Cache ===== //\n\nexport function getReactI18nCache(): ReactI18nCache {\n return getI18nCache() as ReactI18nCache;\n}\n\nexport function setReactI18nCache(i18nCache: ReactI18nCache): void {\n setI18nCache(i18nCache as I18nCache<Translation>);\n}\n"],"mappings":"kEAOA,SAAgB,GAAoC,CAClD,OAAO,GAAc,CAGvB,SAAgB,EAAkB,EAAiC,CACjE,EAAa,EAAoC"}
1
+ {"version":3,"file":"singleton-operations.mjs","names":[],"sources":["../../src/i18n-cache/singleton-operations.ts"],"sourcesContent":["import { getI18nCache, setI18nCache } from 'gt-i18n/internal';\nimport type { I18nCache } from 'gt-i18n/internal';\nimport type { Content } from '@generaltranslation/format/types';\nimport type { ReactI18nCache } from './ReactI18nCache';\n\n// ===== I18n Cache ===== //\n\nexport function getReactI18nCache(): ReactI18nCache {\n return getI18nCache() as ReactI18nCache;\n}\n\nexport function setReactI18nCache(i18nCache: ReactI18nCache): void {\n setI18nCache(i18nCache as I18nCache<Content>);\n}\n"],"mappings":"kEAOA,SAAgB,GAAoC,CAClD,OAAO,GAAc,CAGvB,SAAgB,EAAkB,EAAiC,CACjE,EAAa,EAAgC"}
@@ -1 +1 @@
1
- {"version":3,"file":"I18nStore.cjs","names":["getReactI18nCache","subscribeToSet","lookupTranslation","lookupDictionaryEntry","lookupDictionaryObject"],"sources":["../../src/i18n-store/I18nStore.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getTranslateListenerKey } from 'gt-i18n/internal';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n StoreListener,\n TranslateEventListener,\n TranslateLookup,\n TranslateSnapshot,\n Unsubscribe,\n} from './storeTypes';\nimport type { Dictionary, Translation } from 'gt-i18n/types';\nimport { subscribeToSet } from './utils/subscriptions';\nimport { Hash, Locale } from 'gt-i18n/internal/types';\nimport { getReactI18nCache } from '../i18n-cache/singleton-operations';\nimport { lookupTranslation } from './utils/translations';\nimport {\n lookupDictionaryEntry,\n lookupDictionaryObject,\n} from './utils/dictionaries';\n\nexport type DictionaryStoreListener = (event: DictionaryLookup) => void;\n\nconst MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS = 100;\n\nfunction getRuntimeTranslationErrorDedupeKey(error: unknown): string {\n if (error instanceof Error) {\n return `${error.name}|${error.message}`;\n }\n if (error !== null && typeof error === 'object') {\n try {\n return `object|${JSON.stringify(error)}`;\n } catch {\n return `object|${String(error)}`;\n }\n }\n return `${typeof error}|${String(error)}`;\n}\n\n/**\n * I18nStore gives us the ability to perform client-side updates to translations.\n * Primarily useful for dev hot reload.\n *\n * This is the stateful primitive behind lookup subscriptions and runtime\n * translation requests. It intentionally does not know whether lookups are\n * being served from SPA singletons or SRA provider snapshots; that policy lives\n * in LookupAdapter, not in this store.\n */\nexport class I18nStore {\n // ----- Listener Sets ----- //\n\n private translateListeners = new Set<TranslateEventListener>();\n private dictionaryEntryListeners = new Set<DictionaryStoreListener>();\n private dictionaryObjectListeners = new Set<DictionaryStoreListener>();\n private loggedRuntimeTranslationErrors = new Set<string>();\n\n /**\n * I18nCache must be already initialized\n */\n constructor() {}\n\n // ========== Translation Updates ========== //\n\n updateTranslations = (\n translations: Record<Locale, Record<Hash, Translation>>\n ): void => {\n getReactI18nCache().updateTranslations(translations);\n };\n\n updateDictionaries = (dictionaries: Record<Locale, Dictionary>): void => {\n getReactI18nCache().updateDictionaries(dictionaries);\n };\n\n // ========== runtime translation ========== //\n\n translate = async <T extends Translation>(\n lookup: TranslateLookup<T>\n ): Promise<void> => {\n return getReactI18nCache()\n .lookupTranslationWithFallback(\n lookup.locale,\n lookup.message,\n lookup.options\n )\n .then(() => {\n this.emitTranslateEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryEntry = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryObject = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryObjWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n /**\n * Runtime translation runs fire-and-forget, so a rejected request (for\n * example a 401 from an invalid dev API key) is logged here instead of\n * escaping as an unhandled rejection that kills the dev server during SSR.\n * Identical failures log once.\n */\n private logRuntimeTranslationError(error: unknown): void {\n const details = formatDiagnosticErrorDetails(error);\n const dedupeKey = getRuntimeTranslationErrorDedupeKey(error);\n if (this.loggedRuntimeTranslationErrors.has(dedupeKey)) return;\n this.loggedRuntimeTranslationErrors.add(dedupeKey);\n if (\n this.loggedRuntimeTranslationErrors.size >\n MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS\n ) {\n const oldest = this.loggedRuntimeTranslationErrors.values().next().value;\n if (oldest !== undefined) {\n this.loggedRuntimeTranslationErrors.delete(oldest);\n }\n }\n console.error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'A runtime translation request failed.',\n wayOut: 'Rendering falls back to untranslated content.',\n details,\n })\n );\n }\n\n // ========== UseSyncExternalStore ========== //\n\n // ----- Subscriptions ----- //\n\n // Keep subscription methods as arrow fields so hooks can pass them by\n // reference without losing access to this store instance.\n subscribeToTranslate = <T extends Translation>(\n lookup: TranslateLookup<T>,\n listener: StoreListener\n ): Unsubscribe => {\n const lookupKey = getTranslateListenerKey(lookup);\n const wrappedListener: TranslateEventListener = (lookup) => {\n if (getTranslateListenerKey(lookup) === lookupKey) {\n listener();\n }\n };\n return subscribeToSet(this.translateListeners, wrappedListener);\n };\n\n subscribeToTranslationEvents = (\n listener: TranslateEventListener\n ): Unsubscribe => {\n return subscribeToSet(this.translateListeners, listener);\n };\n\n subscribeToDictionaryEntryEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryEntryListeners, listener);\n };\n\n subscribeToDictionaryObjectEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryObjectListeners, listener);\n };\n\n // ----- Snapshots ----- //\n\n getTranslateSnapshot = <T extends Translation>(\n lookup: TranslateLookup<T>,\n translationsSnapshot: Record<Locale, Record<Hash, Translation>> = {}\n ): TranslateSnapshot<T> => {\n return (\n lookupTranslation(translationsSnapshot, lookup) ??\n getReactI18nCache().lookupTranslation<T>(\n lookup.locale,\n lookup.message,\n lookup.options\n )\n );\n };\n\n getDictionaryEntrySnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryEntrySnapshot => {\n return (\n lookupDictionaryEntry(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionary(lookup.locale, lookup.id)\n );\n };\n\n getDictionaryObjectSnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryObjectSnapshot => {\n return (\n lookupDictionaryObject(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionaryObj(lookup.locale, lookup.id)\n );\n };\n\n // ----- Listener Utilities ----- //\n\n private emitTranslateEvent(event: TranslateLookup): void {\n this.translateListeners.forEach((listener) => listener(event));\n }\n\n private emitDictionaryEvent(event: DictionaryLookup): void {\n this.dictionaryEntryListeners.forEach((listener) => listener(event));\n this.dictionaryObjectListeners.forEach((listener) => {\n listener(event);\n });\n }\n}\n"],"mappings":"qSA6BA,SAAS,EAAoC,EAAwB,CACnE,GAAI,aAAiB,MACnB,MAAO,GAAG,EAAM,KAAK,GAAG,EAAM,UAEhC,GAAsB,OAAO,GAAU,UAAnC,EACF,GAAI,CACF,MAAO,UAAU,KAAK,UAAU,EAAM,QAChC,CACN,MAAO,UAAU,OAAO,EAAM,GAGlC,MAAO,GAAG,OAAO,EAAM,GAAG,OAAO,EAAM,GAYzC,IAAa,EAAb,KAAuB,CAGrB,mBAA6B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ALsB,GAAW,EAC1D,EAAA,EAAA,yBAA4B,EAAO,GAAK,GACtC,GAAU,EAGiD,EAGjE,6BACE,GAEOA,EAAAA,eAAe,KAAK,mBAAoB,EAAS,CAG1D,iCACE,GAEOA,EAAAA,eAAe,KAAK,yBAA0B,EAAS,CAGhE,kCACE,GAEOA,EAAAA,eAAe,KAAK,0BAA2B,EAAS,CAKjE,sBACE,EACA,EAAkE,EAAE,GAGlEC,EAAAA,kBAAkB,EAAsB,EAAO,EAC/CF,EAAAA,mBAAmB,CAAC,kBAClB,EAAO,OACP,EAAO,QACP,EAAO,QACR,CAIL,4BACE,EACA,EAAmD,EAAE,GAGnDG,EAAAA,sBAAsB,EAAsB,EAAO,EACnDH,EAAAA,mBAAmB,CAAC,iBAAiB,EAAO,OAAQ,EAAO,GAAG,CAIlE,6BACE,EACA,EAAmD,EAAE,GAGnDI,EAAAA,uBAAuB,EAAsB,EAAO,EACpDJ,EAAAA,mBAAmB,CAAC,oBAAoB,EAAO,OAAQ,EAAO,GAAG,CAMrE,mBAA2B,EAA8B,CACvD,KAAK,mBAAmB,QAAS,GAAa,EAAS,EAAM,CAAC,CAGhE,oBAA4B,EAA+B,CACzD,KAAK,yBAAyB,QAAS,GAAa,EAAS,EAAM,CAAC,CACpE,KAAK,0BAA0B,QAAS,GAAa,CACnD,EAAS,EAAM,EACf"}
1
+ {"version":3,"file":"I18nStore.cjs","names":["getReactI18nCache","subscribeToSet","lookupTranslation","lookupDictionaryEntry","lookupDictionaryObject"],"sources":["../../src/i18n-store/I18nStore.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getTranslateListenerKey } from 'gt-i18n/internal';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n StoreListener,\n TranslateEventListener,\n TranslateLookup,\n TranslateSnapshot,\n Unsubscribe,\n} from './storeTypes';\nimport type { Dictionary } from 'gt-i18n/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport { subscribeToSet } from './utils/subscriptions';\nimport { Hash, Locale } from 'gt-i18n/internal/types';\nimport { getReactI18nCache } from '../i18n-cache/singleton-operations';\nimport { lookupTranslation } from './utils/translations';\nimport {\n lookupDictionaryEntry,\n lookupDictionaryObject,\n} from './utils/dictionaries';\n\nexport type DictionaryStoreListener = (event: DictionaryLookup) => void;\n\nconst MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS = 100;\n\nfunction getRuntimeTranslationErrorDedupeKey(error: unknown): string {\n if (error instanceof Error) {\n return `${error.name}|${error.message}`;\n }\n if (error !== null && typeof error === 'object') {\n try {\n return `object|${JSON.stringify(error)}`;\n } catch {\n return `object|${String(error)}`;\n }\n }\n return `${typeof error}|${String(error)}`;\n}\n\n/**\n * I18nStore gives us the ability to perform client-side updates to translations.\n * Primarily useful for dev hot reload.\n *\n * This is the stateful primitive behind lookup subscriptions and runtime\n * translation requests. It intentionally does not know whether lookups are\n * being served from SPA singletons or SRA provider snapshots; that policy lives\n * in LookupAdapter, not in this store.\n */\nexport class I18nStore {\n // ----- Listener Sets ----- //\n\n private translateListeners = new Set<TranslateEventListener>();\n private dictionaryEntryListeners = new Set<DictionaryStoreListener>();\n private dictionaryObjectListeners = new Set<DictionaryStoreListener>();\n private loggedRuntimeTranslationErrors = new Set<string>();\n\n /**\n * I18nCache must be already initialized\n */\n constructor() {}\n\n // ========== Translation Updates ========== //\n\n updateTranslations = (\n translations: Record<Locale, Record<Hash, Content>>\n ): void => {\n getReactI18nCache().updateTranslations(translations);\n };\n\n updateDictionaries = (dictionaries: Record<Locale, Dictionary>): void => {\n getReactI18nCache().updateDictionaries(dictionaries);\n };\n\n // ========== runtime translation ========== //\n\n translate = async <T extends Content>(\n lookup: TranslateLookup<T>\n ): Promise<void> => {\n return getReactI18nCache()\n .lookupTranslationWithFallback(\n lookup.locale,\n lookup.message,\n lookup.options\n )\n .then(() => {\n this.emitTranslateEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryEntry = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryObject = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryObjWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n /**\n * Runtime translation runs fire-and-forget, so a rejected request (for\n * example a 401 from an invalid dev API key) is logged here instead of\n * escaping as an unhandled rejection that kills the dev server during SSR.\n * Identical failures log once.\n */\n private logRuntimeTranslationError(error: unknown): void {\n const details = formatDiagnosticErrorDetails(error);\n const dedupeKey = getRuntimeTranslationErrorDedupeKey(error);\n if (this.loggedRuntimeTranslationErrors.has(dedupeKey)) return;\n this.loggedRuntimeTranslationErrors.add(dedupeKey);\n if (\n this.loggedRuntimeTranslationErrors.size >\n MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS\n ) {\n const oldest = this.loggedRuntimeTranslationErrors.values().next().value;\n if (oldest !== undefined) {\n this.loggedRuntimeTranslationErrors.delete(oldest);\n }\n }\n console.error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'A runtime translation request failed.',\n wayOut: 'Rendering falls back to untranslated content.',\n details,\n })\n );\n }\n\n // ========== UseSyncExternalStore ========== //\n\n // ----- Subscriptions ----- //\n\n // Keep subscription methods as arrow fields so hooks can pass them by\n // reference without losing access to this store instance.\n subscribeToTranslate = <T extends Content>(\n lookup: TranslateLookup<T>,\n listener: StoreListener\n ): Unsubscribe => {\n const lookupKey = getTranslateListenerKey(lookup);\n const wrappedListener: TranslateEventListener = (lookup) => {\n if (getTranslateListenerKey(lookup) === lookupKey) {\n listener();\n }\n };\n return subscribeToSet(this.translateListeners, wrappedListener);\n };\n\n subscribeToTranslationEvents = (\n listener: TranslateEventListener\n ): Unsubscribe => {\n return subscribeToSet(this.translateListeners, listener);\n };\n\n subscribeToDictionaryEntryEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryEntryListeners, listener);\n };\n\n subscribeToDictionaryObjectEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryObjectListeners, listener);\n };\n\n // ----- Snapshots ----- //\n\n getTranslateSnapshot = <T extends Content>(\n lookup: TranslateLookup<T>,\n translationsSnapshot: Record<Locale, Record<Hash, Content>> = {}\n ): TranslateSnapshot<T> => {\n return (\n lookupTranslation(translationsSnapshot, lookup) ??\n getReactI18nCache().lookupTranslation<T>(\n lookup.locale,\n lookup.message,\n lookup.options\n )\n );\n };\n\n getDictionaryEntrySnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryEntrySnapshot => {\n return (\n lookupDictionaryEntry(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionary(lookup.locale, lookup.id)\n );\n };\n\n getDictionaryObjectSnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryObjectSnapshot => {\n return (\n lookupDictionaryObject(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionaryObj(lookup.locale, lookup.id)\n );\n };\n\n // ----- Listener Utilities ----- //\n\n private emitTranslateEvent(event: TranslateLookup): void {\n this.translateListeners.forEach((listener) => listener(event));\n }\n\n private emitDictionaryEvent(event: DictionaryLookup): void {\n this.dictionaryEntryListeners.forEach((listener) => listener(event));\n this.dictionaryObjectListeners.forEach((listener) => {\n listener(event);\n });\n }\n}\n"],"mappings":"qSA8BA,SAAS,EAAoC,EAAwB,CACnE,GAAI,aAAiB,MACnB,MAAO,GAAG,EAAM,KAAK,GAAG,EAAM,UAEhC,GAAsB,OAAO,GAAU,UAAnC,EACF,GA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Q,iCACR,SAAU,QACV,aAAc,wCACd,OAAQ,gDACR,UACD,CAAC,CACH,EASH,sBACE,EACA,IACgB,CAChB,IAAM,GAAA,EAAA,EAAA,yBAAoC,EAAO,CAMjD,OAAOC,EAAAA,eAAe,KAAK,mBALsB,GAAW,EAC1D,EAAA,EAAA,yBAA4B,EAAO,GAAK,GACtC,GAAU,EAGiD,EAGjE,6BACE,GAEOA,EAAAA,eAAe,KAAK,mBAAoB,EAAS,CAG1D,iCACE,GAEOA,EAAAA,eAAe,KAAK,yBAA0B,EAAS,CAGhE,kCACE,GAEOA,EAAAA,eAAe,KAAK,0BAA2B,EAAS,CAKjE,sBACE,EACA,EAA8D,EAAE,GAG9DC,EAAAA,kBAAkB,EAAsB,EAAO,EAC/CF,EAAAA,mBAAmB,CAAC,kBAClB,EAAO,OACP,EAAO,QACP,EAAO,QACR,CAIL,4BACE,EACA,EAAmD,EAAE,GAGnDG,EAAAA,sBAAsB,EAAsB,EAAO,EACnDH,EAAAA,mBAAmB,CAAC,iBAAiB,EAAO,OAAQ,EAAO,GAAG,CAIlE,6BACE,EACA,EAAmD,EAAE,GAGnDI,EAAAA,uBAAuB,EAAsB,EAAO,EACpDJ,EAAAA,mBAAmB,CAAC,oBAAoB,EAAO,OAAQ,EAAO,GAAG,CAMrE,mBAA2B,EAA8B,CACvD,KAAK,mBAAmB,QAAS,GAAa,EAAS,EAAM,CAAC,CAGhE,oBAA4B,EAA+B,CACzD,KAAK,yBAAyB,QAAS,GAAa,EAAS,EAAM,CAAC,CACpE,KAAK,0BAA0B,QAAS,GAAa,CACnD,EAAS,EAAM,EACf"}
@@ -1,5 +1,6 @@
1
1
  import { DictionaryEntrySnapshot, DictionaryLookup, DictionaryObjectSnapshot, StoreListener, TranslateEventListener, TranslateLookup, TranslateSnapshot, Unsubscribe } from "./storeTypes.js";
2
- import { Dictionary, Translation } from "gt-i18n/types";
2
+ import { Dictionary } from "gt-i18n/types";
3
+ import { Content } from "@generaltranslation/format/types";
3
4
  import { Hash, Locale } from "gt-i18n/internal/types";
4
5
 
5
6
  //#region src/i18n-store/I18nStore.d.ts
@@ -22,9 +23,9 @@ declare class I18nStore {
22
23
  * I18nCache must be already initialized
23
24
  */
24
25
  constructor();
25
- updateTranslations: (translations: Record<Locale, Record<Hash, Translation>>) => void;
26
+ updateTranslations: (translations: Record<Locale, Record<Hash, Content>>) => void;
26
27
  updateDictionaries: (dictionaries: Record<Locale, Dictionary>) => void;
27
- translate: <T extends Translation>(lookup: TranslateLookup<T>) => Promise<void>;
28
+ translate: <T extends Content>(lookup: TranslateLookup<T>) => Promise<void>;
28
29
  translateDictionaryEntry: (lookup: DictionaryLookup) => void;
29
30
  translateDictionaryObject: (lookup: DictionaryLookup) => void;
30
31
  /**
@@ -34,11 +35,11 @@ declare class I18nStore {
34
35
  * Identical failures log once.
35
36
  */
36
37
  private logRuntimeTranslationError;
37
- subscribeToTranslate: <T extends Translation>(lookup: TranslateLookup<T>, listener: StoreListener) => Unsubscribe;
38
+ subscribeToTranslate: <T extends Content>(lookup: TranslateLookup<T>, listener: StoreListener) => Unsubscribe;
38
39
  subscribeToTranslationEvents: (listener: TranslateEventListener) => Unsubscribe;
39
40
  subscribeToDictionaryEntryEvents: (listener: DictionaryStoreListener) => Unsubscribe;
40
41
  subscribeToDictionaryObjectEvents: (listener: DictionaryStoreListener) => Unsubscribe;
41
- getTranslateSnapshot: <T extends Translation>(lookup: TranslateLookup<T>, translationsSnapshot?: Record<Locale, Record<Hash, Translation>>) => TranslateSnapshot<T>;
42
+ getTranslateSnapshot: <T extends Content>(lookup: TranslateLookup<T>, translationsSnapshot?: Record<Locale, Record<Hash, Content>>) => TranslateSnapshot<T>;
42
43
  getDictionaryEntrySnapshot: (lookup: DictionaryLookup, dictionariesSnapshot?: Record<Locale, Dictionary>) => DictionaryEntrySnapshot;
43
44
  getDictionaryObjectSnapshot: (lookup: DictionaryLookup, dictionariesSnapshot?: Record<Locale, Dictionary>) => DictionaryObjectSnapshot;
44
45
  private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pC,wBAAA;EAAA,QASK,kBAAA;EAAA,QAIA,mBAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"I18nStore.mjs","names":[],"sources":["../../src/i18n-store/I18nStore.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getTranslateListenerKey } from 'gt-i18n/internal';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n StoreListener,\n TranslateEventListener,\n TranslateLookup,\n TranslateSnapshot,\n Unsubscribe,\n} from './storeTypes';\nimport type { Dictionary, Translation } from 'gt-i18n/types';\nimport { subscribeToSet } from './utils/subscriptions';\nimport { Hash, Locale } from 'gt-i18n/internal/types';\nimport { getReactI18nCache } from '../i18n-cache/singleton-operations';\nimport { lookupTranslation } from './utils/translations';\nimport {\n lookupDictionaryEntry,\n lookupDictionaryObject,\n} from './utils/dictionaries';\n\nexport type DictionaryStoreListener = (event: DictionaryLookup) => void;\n\nconst MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS = 100;\n\nfunction getRuntimeTranslationErrorDedupeKey(error: unknown): string {\n if (error instanceof Error) {\n return `${error.name}|${error.message}`;\n }\n if (error !== null && typeof error === 'object') {\n try {\n return `object|${JSON.stringify(error)}`;\n } catch {\n return `object|${String(error)}`;\n }\n }\n return `${typeof error}|${String(error)}`;\n}\n\n/**\n * I18nStore gives us the ability to perform client-side updates to translations.\n * Primarily useful for dev hot reload.\n *\n * This is the stateful primitive behind lookup subscriptions and runtime\n * translation requests. It intentionally does not know whether lookups are\n * being served from SPA singletons or SRA provider snapshots; that policy lives\n * in LookupAdapter, not in this store.\n */\nexport class I18nStore {\n // ----- Listener Sets ----- //\n\n private translateListeners = new Set<TranslateEventListener>();\n private dictionaryEntryListeners = new Set<DictionaryStoreListener>();\n private dictionaryObjectListeners = new Set<DictionaryStoreListener>();\n private loggedRuntimeTranslationErrors = new Set<string>();\n\n /**\n * I18nCache must be already initialized\n */\n constructor() {}\n\n // ========== Translation Updates ========== //\n\n updateTranslations = (\n translations: Record<Locale, Record<Hash, Translation>>\n ): void => {\n getReactI18nCache().updateTranslations(translations);\n };\n\n updateDictionaries = (dictionaries: Record<Locale, Dictionary>): void => {\n getReactI18nCache().updateDictionaries(dictionaries);\n };\n\n // ========== runtime translation ========== //\n\n translate = async <T extends Translation>(\n lookup: TranslateLookup<T>\n ): Promise<void> => {\n return getReactI18nCache()\n .lookupTranslationWithFallback(\n lookup.locale,\n lookup.message,\n lookup.options\n )\n .then(() => {\n this.emitTranslateEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryEntry = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryObject = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryObjWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n /**\n * Runtime translation runs fire-and-forget, so a rejected request (for\n * example a 401 from an invalid dev API key) is logged here instead of\n * escaping as an unhandled rejection that kills the dev server during SSR.\n * Identical failures log once.\n */\n private logRuntimeTranslationError(error: unknown): void {\n const details = formatDiagnosticErrorDetails(error);\n const dedupeKey = getRuntimeTranslationErrorDedupeKey(error);\n if (this.loggedRuntimeTranslationErrors.has(dedupeKey)) return;\n this.loggedRuntimeTranslationErrors.add(dedupeKey);\n if (\n this.loggedRuntimeTranslationErrors.size >\n MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS\n ) {\n const oldest = this.loggedRuntimeTranslationErrors.values().next().value;\n if (oldest !== undefined) {\n this.loggedRuntimeTranslationErrors.delete(oldest);\n }\n }\n console.error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'A runtime translation request failed.',\n wayOut: 'Rendering falls back to untranslated content.',\n details,\n })\n );\n }\n\n // ========== UseSyncExternalStore ========== //\n\n // ----- Subscriptions ----- //\n\n // Keep subscription methods as arrow fields so hooks can pass them by\n // reference without losing access to this store instance.\n subscribeToTranslate = <T extends Translation>(\n lookup: TranslateLookup<T>,\n listener: StoreListener\n ): Unsubscribe => {\n const lookupKey = getTranslateListenerKey(lookup);\n const wrappedListener: TranslateEventListener = (lookup) => {\n if (getTranslateListenerKey(lookup) === lookupKey) {\n listener();\n }\n };\n return subscribeToSet(this.translateListeners, wrappedListener);\n };\n\n subscribeToTranslationEvents = (\n listener: TranslateEventListener\n ): Unsubscribe => {\n return subscribeToSet(this.translateListeners, listener);\n };\n\n subscribeToDictionaryEntryEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryEntryListeners, listener);\n };\n\n subscribeToDictionaryObjectEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryObjectListeners, listener);\n };\n\n // ----- Snapshots ----- //\n\n getTranslateSnapshot = <T extends Translation>(\n lookup: TranslateLookup<T>,\n translationsSnapshot: Record<Locale, Record<Hash, Translation>> = {}\n ): TranslateSnapshot<T> => {\n return (\n lookupTranslation(translationsSnapshot, lookup) ??\n getReactI18nCache().lookupTranslation<T>(\n lookup.locale,\n lookup.message,\n lookup.options\n )\n );\n };\n\n getDictionaryEntrySnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryEntrySnapshot => {\n return (\n lookupDictionaryEntry(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionary(lookup.locale, lookup.id)\n );\n };\n\n getDictionaryObjectSnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryObjectSnapshot => {\n return (\n lookupDictionaryObject(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionaryObj(lookup.locale, lookup.id)\n );\n };\n\n // ----- Listener Utilities ----- //\n\n private emitTranslateEvent(event: TranslateLookup): void {\n this.translateListeners.forEach((listener) => listener(event));\n }\n\n private emitDictionaryEvent(event: DictionaryLookup): void {\n this.dictionaryEntryListeners.forEach((listener) => listener(event));\n this.dictionaryObjectListeners.forEach((listener) => {\n listener(event);\n });\n }\n}\n"],"mappings":"mcA6BA,SAAS,EAAoC,EAAwB,CACnE,GAAI,aAAiB,MACnB,MAAO,GAAG,EAAM,KAAK,GAAG,EAAM,UAEhC,GAAsB,OAAO,GAAU,UAAnC,EACF,GAAI,CACF,MAAO,UAAU,KAAK,UAAU,EAAM,QAChC,CACN,MAAO,UAAU,OAAO,EAAM,GAGlC,MAAO,GAAG,OAAO,EAAM,GAAG,OAAO,EAAM,GAYzC,IAAa,EAAb,KAAuB,CAGrB,mBAA6B,IAAI,IACjC,yBAAmC,IAAI,IACvC,0BAAoC,IAAI,IACxC,+BAAyC,IAAI,IAK7C,aAAc,EAId,mBACE,GACS,CACT,GAAmB,CAAC,mBAAmB,EAAa,EAGtD,mBAAsB,GAAmD,CACvE,GAAmB,CAAC,mBAAmB,EAAa,EAKtD,UAAY,KACV,IAEO,GAAmB,CACvB,8BACC,EAAO,OACP,EAAO,QACP,EAAO,QACR,CACA,SAAW,CACV,KAAK,mBAAmB,EAAO,EAC/B,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,CAG7D,yBAA4B,GAAmC,CAC7D,GAAmB,CAChB,6BAA6B,EAAO,OAAQ,EAAO,GAAG,CACtD,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAG7D,0BAA6B,GAAmC,CAC9D,GAAmB,CAChB,gCAAgC,EAAO,OAAQ,EAAO,GAAG,CACzD,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EA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s","names":[],"sources":["../../src/i18n-store/I18nStore.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getTranslateListenerKey } from 'gt-i18n/internal';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n StoreListener,\n TranslateEventListener,\n TranslateLookup,\n TranslateSnapshot,\n Unsubscribe,\n} from './storeTypes';\nimport type { Dictionary } from 'gt-i18n/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport { subscribeToSet } from './utils/subscriptions';\nimport { Hash, Locale } from 'gt-i18n/internal/types';\nimport { getReactI18nCache } from '../i18n-cache/singleton-operations';\nimport { lookupTranslation } from './utils/translations';\nimport {\n lookupDictionaryEntry,\n lookupDictionaryObject,\n} from './utils/dictionaries';\n\nexport type DictionaryStoreListener = (event: DictionaryLookup) => void;\n\nconst MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS = 100;\n\nfunction getRuntimeTranslationErrorDedupeKey(error: unknown): string {\n if (error instanceof Error) {\n return `${error.name}|${error.message}`;\n }\n if (error !== null && typeof error === 'object') {\n try {\n return `object|${JSON.stringify(error)}`;\n } catch {\n return `object|${String(error)}`;\n }\n }\n return `${typeof error}|${String(error)}`;\n}\n\n/**\n * I18nStore gives us the ability to perform client-side updates to translations.\n * Primarily useful for dev hot reload.\n *\n * This is the stateful primitive behind lookup subscriptions and runtime\n * translation requests. It intentionally does not know whether lookups are\n * being served from SPA singletons or SRA provider snapshots; that policy lives\n * in LookupAdapter, not in this store.\n */\nexport class I18nStore {\n // ----- Listener Sets ----- //\n\n private translateListeners = new Set<TranslateEventListener>();\n private dictionaryEntryListeners = new Set<DictionaryStoreListener>();\n private dictionaryObjectListeners = new Set<DictionaryStoreListener>();\n private loggedRuntimeTranslationErrors = new Set<string>();\n\n /**\n * I18nCache must be already initialized\n */\n constructor() {}\n\n // ========== Translation Updates ========== //\n\n updateTranslations = (\n translations: Record<Locale, Record<Hash, Content>>\n ): void => {\n getReactI18nCache().updateTranslations(translations);\n };\n\n updateDictionaries = (dictionaries: Record<Locale, Dictionary>): void => {\n getReactI18nCache().updateDictionaries(dictionaries);\n };\n\n // ========== runtime translation ========== //\n\n translate = async <T extends Content>(\n lookup: TranslateLookup<T>\n ): Promise<void> => {\n return getReactI18nCache()\n .lookupTranslationWithFallback(\n lookup.locale,\n lookup.message,\n lookup.options\n )\n .then(() => {\n this.emitTranslateEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryEntry = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryObject = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryObjWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n /**\n * Runtime translation runs fire-and-forget, so a rejected request (for\n * example a 401 from an invalid dev API key) is logged here instead of\n * escaping as an unhandled rejection that kills the dev server during SSR.\n * Identical failures log once.\n */\n private logRuntimeTranslationError(error: unknown): void {\n const details = formatDiagnosticErrorDetails(error);\n const dedupeKey = getRuntimeTranslationErrorDedupeKey(error);\n if (this.loggedRuntimeTranslationErrors.has(dedupeKey)) return;\n this.loggedRuntimeTranslationErrors.add(dedupeKey);\n if (\n this.loggedRuntimeTranslationErrors.size >\n MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS\n ) {\n const oldest = this.loggedRuntimeTranslationErrors.values().next().value;\n if (oldest !== undefined) {\n this.loggedRuntimeTranslationErrors.delete(oldest);\n }\n }\n console.error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'A runtime translation request failed.',\n wayOut: 'Rendering falls back to untranslated content.',\n details,\n })\n );\n }\n\n // ========== UseSyncExternalStore ========== //\n\n // ----- Subscriptions ----- //\n\n // Keep subscription methods as arrow fields so hooks can pass them by\n // reference without losing access to this store instance.\n subscribeToTranslate = <T extends Content>(\n lookup: TranslateLookup<T>,\n listener: StoreListener\n ): Unsubscribe => {\n const lookupKey = getTranslateListenerKey(lookup);\n const wrappedListener: TranslateEventListener = (lookup) => {\n if (getTranslateListenerKey(lookup) === lookupKey) {\n listener();\n }\n };\n return subscribeToSet(this.translateListeners, wrappedListener);\n };\n\n subscribeToTranslationEvents = (\n listener: TranslateEventListener\n ): Unsubscribe => {\n return subscribeToSet(this.translateListeners, listener);\n };\n\n subscribeToDictionaryEntryEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryEntryListeners, listener);\n };\n\n subscribeToDictionaryObjectEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryObjectListeners, listener);\n };\n\n // ----- Snapshots ----- //\n\n getTranslateSnapshot = <T extends Content>(\n lookup: TranslateLookup<T>,\n translationsSnapshot: Record<Locale, Record<Hash, Content>> = {}\n ): TranslateSnapshot<T> => {\n return (\n lookupTranslation(translationsSnapshot, lookup) ??\n getReactI18nCache().lookupTranslation<T>(\n lookup.locale,\n lookup.message,\n lookup.options\n )\n );\n };\n\n getDictionaryEntrySnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryEntrySnapshot => {\n return (\n lookupDictionaryEntry(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionary(lookup.locale, lookup.id)\n );\n };\n\n getDictionaryObjectSnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryObjectSnapshot => {\n return (\n lookupDictionaryObject(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionaryObj(lookup.locale, lookup.id)\n );\n };\n\n // ----- Listener Utilities ----- //\n\n private emitTranslateEvent(event: TranslateLookup): void {\n this.translateListeners.forEach((listener) => listener(event));\n }\n\n private emitDictionaryEvent(event: DictionaryLookup): void {\n this.dictionaryEntryListeners.forEach((listener) => listener(event));\n this.dictionaryObjectListeners.forEach((listener) => {\n listener(event);\n });\n }\n}\n"],"mappings":"mcA8BA,SAAS,EAAoC,EAAwB,CACnE,GAAI,aAAiB,MACnB,MAAO,GAAG,EAAM,KAAK,GAAG,EAAM,UAEhC,GAAsB,OAAO,GAAU,UAAnC,EACF,GAAI,CACF,MAAO,UAAU,KAAK,UAAU,EAAM,QAChC,CACN,MAAO,UAAU,OAAO,EAAM,GAGlC,MAAO,GAAG,OAAO,EAAM,GAAG,OAAO,EAAM,GAYzC,IAAa,EAAb,KAAuB,CAGrB,mBAA6B,IAAI,IACjC,yBAAmC,IAAI,IACvC,0BAAoC,IAAI,IACxC,+BAAyC,IAAI,IAK7C,aAAc,EAId,mBACE,GACS,CACT,GAAmB,CAAC,mBAAmB,EAAa,EAGtD,mBAAsB,GAAmD,CACvE,GAAmB,CAAC,mBAAmB,EAAa,EAKtD,UAAY,KACV,IAEO,GAAmB,CACvB,8BACC,EAAO,OACP,EAAO,QACP,EAAO,QACR,CACA,SAAW,CACV,KAAK,mBAAmB,EAAO,EAC/B,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,CAG7D,yBAA4B,GAAmC,CAC7D,GAAmB,CAChB,6BAA6B,EAAO,OAAQ,EAAO,GAAG,CACtD,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAG7D,0BAA6B,GAAmC,CAC9D,GAAmB,CAChB,gCAAgC,EAAO,OAAQ,EAAO,GAAG,CACzD,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAS7D,2BAAmC,EAAsB,CACvD,IAAM,EAAU,EAA6B,EAAM,CAC7C,EAAY,EAAoC,EAAM,CACxD,SAAK,+BAA+B,IAAI,EAAU,CAEtD,IADA,KAAK,+BAA+B,IAAI,EAAU,CAEhD,KAAK,+BAA+B,KACpC,IACA,CACA,IAAM,EAAS,KAAK,+BAA+B,QAAQ,CAAC,MAAM,CAAC,MAC/D,IAAW,IAAA,IACb,KAAK,+BAA+B,OAAO,EAAO,CAGtD,QAAQ,MACN,EAAwB,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,wCACd,OAAQ,gDACR,UACD,CAAC,CACH,EASH,sBACE,EACA,IACgB,CAChB,IAAM,EAAY,EAAwB,EAAO,CAMjD,OAAO,EAAe,KAAK,mBALsB,GAAW,CACtD,EAAwB,EAAO,GAAK,GACtC,GAAU,EAGiD,EAGjE,6BACE,GAEO,EAAe,KAAK,mBAAoB,EAAS,CAG1D,iCACE,GAEO,EAAe,KAAK,yBAA0B,EAAS,CAGhE,kCACE,GAEO,EAAe,KAAK,0BAA2B,EAAS,CAKjE,sBACE,EACA,EAA8D,EAAE,GAG9D,EAAkB,EAAsB,EAAO,EAC/C,GAAmB,CAAC,kBAClB,EAAO,OACP,EAAO,QACP,EAAO,QACR,CAIL,4BACE,EACA,EAAmD,EAAE,GAGnD,EAAsB,EAAsB,EAAO,EACnD,GAAmB,CAAC,iBAAiB,EAAO,OAAQ,EAAO,GAAG,CAIlE,6BACE,EACA,EAAmD,EAAE,GAGnD,EAAuB,EAAsB,EAAO,EACpD,GAAmB,CAAC,oBAAoB,EAAO,OAAQ,EAAO,GAAG,CAMrE,mBAA2B,EAA8B,CACvD,KAAK,mBAAmB,QAAS,GAAa,EAAS,EAAM,CAAC,CAGhE,oBAA4B,EAA+B,CACzD,KAAK,yBAAyB,QAAS,GAAa,EAAS,EAAM,CAAC,CACpE,KAAK,0BAA0B,QAAS,GAAa,CACnD,EAAS,EAAM,EACf"}
@@ -1,11 +1,12 @@
1
- import { DictionaryEntry, DictionaryObject, Translation } from "gt-i18n/types";
1
+ import { DictionaryEntry, DictionaryObject } from "gt-i18n/types";
2
+ import { Content } from "@generaltranslation/format/types";
2
3
  import { LookupOptions } from "gt-i18n/internal/types";
3
4
 
4
5
  //#region src/i18n-store/storeTypes.d.ts
5
6
  type Unsubscribe = () => void;
6
7
  type StoreListener = () => void;
7
8
  type TranslateEventListener = (lookup: TranslateLookup) => void;
8
- type TranslateLookup<T extends Translation = Translation> = {
9
+ type TranslateLookup<T extends Content = Content> = {
9
10
  locale: string;
10
11
  message: T;
11
12
  options: LookupOptions;
@@ -14,7 +15,7 @@ type DictionaryLookup = {
14
15
  locale: string;
15
16
  id: string;
16
17
  };
17
- type TranslateSnapshot<T extends Translation = Translation> = T | undefined;
18
+ type TranslateSnapshot<T extends Content = Content> = T | undefined;
18
19
  type DictionaryEntrySnapshot = DictionaryEntry | undefined;
19
20
  type DictionaryObjectSnapshot = DictionaryObject | undefined;
20
21
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"storeTypes.d.ts","names":[],"sources":["../../src/i18n-store/storeTypes.ts"],"mappings":";;;;KASY,WAAA;AAAA,KACA,aAAA;AAAA,KACA,sBAAA,IAA0B,MAAA,EAAQ,eAAA;AAAA,KAIlC,eAAA,WAA0B,WAAA,GAAc,WAAA;EAClD,MAAA;EACA,OAAA,EAAS,CAAA;EACT,OAAA,EAAS,aAAA;AAAA;AAAA,KAGC,gBAAA;EACV,MAAA;EACA,EAAA;AAAA;AAAA,KAIU,iBAAA,WAA4B,WAAA,GAAc,WAAA,IAClD,CAAA;AAAA,KAIQ,uBAAA,GAA0B,eAAA;AAAA,KAC1B,wBAAA,GAA2B,gBAAA"}
1
+ {"version":3,"file":"storeTypes.d.ts","names":[],"sources":["../../src/i18n-store/storeTypes.ts"],"mappings":";;;;;KAMY,WAAA;AAAA,KACA,aAAA;AAAA,KACA,sBAAA,IAA0B,MAAA,EAAQ,eAAA;AAAA,KAIlC,eAAA,WAA0B,OAAA,GAAU,OAAA;EAC9C,MAAA;EACA,OAAA,EAAS,CAAA;EACT,OAAA,EAAS,aAAA;AAAA;AAAA,KAGC,gBAAA;EACV,MAAA;EACA,EAAA;AAAA;AAAA,KAIU,iBAAA,WAA4B,OAAA,GAAU,OAAA,IAAW,CAAA;AAAA,KAGjD,uBAAA,GAA0B,eAAA;AAAA,KAC1B,wBAAA,GAA2B,gBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useI18nStore.cjs","names":["useGTContext","getI18nStore"],"sources":["../../src/i18n-store/useI18nStore.ts"],"sourcesContent":["import { Dictionary, Hash, Locale } from 'gt-i18n/internal/types';\nimport { useGTContext } from '../context/context';\nimport { I18nStore } from './I18nStore';\nimport { getI18nStore } from './singleton-operations';\nimport { Translation } from 'gt-i18n/types';\n\nexport function useI18nStore(): I18nStore {\n const context = useGTContext();\n return context?.i18nStore || getI18nStore();\n}\n\nexport function useTranslationsSnapshot(): Record<\n Locale,\n Record<Hash, Translation>\n> {\n const context = useGTContext();\n return context?.translationsSnapshot || {};\n}\n\nexport function useDictionariesSnapshot(): Record<Locale, Dictionary> {\n const context = useGTContext();\n return context?.dictionariesSnapshot || {};\n}\n"],"mappings":"kFAMA,SAAgB,GAA0B,CAExC,OADgBA,EAAAA,cACF,EAAE,WAAaC,EAAAA,cAAc,CAG7C,SAAgB,GAGd,CAEA,OADgBD,EAAAA,cACF,EAAE,sBAAwB,EAAE,CAG5C,SAAgB,GAAsD,CAEpE,OADgBA,EAAAA,cACF,EAAE,sBAAwB,EAAE"}
1
+ {"version":3,"file":"useI18nStore.cjs","names":["useGTContext","getI18nStore"],"sources":["../../src/i18n-store/useI18nStore.ts"],"sourcesContent":["import { Dictionary, Hash, Locale } from 'gt-i18n/internal/types';\nimport { useGTContext } from '../context/context';\nimport { I18nStore } from './I18nStore';\nimport { getI18nStore } from './singleton-operations';\nimport type { Content } from '@generaltranslation/format/types';\n\nexport function useI18nStore(): I18nStore {\n const context = useGTContext();\n return context?.i18nStore || getI18nStore();\n}\n\nexport function useTranslationsSnapshot(): Record<\n Locale,\n Record<Hash, Content>\n> {\n const context = useGTContext();\n return context?.translationsSnapshot || {};\n}\n\nexport function useDictionariesSnapshot(): Record<Locale, Dictionary> {\n const context = useGTContext();\n return context?.dictionariesSnapshot || {};\n}\n"],"mappings":"kFAMA,SAAgB,GAA0B,CAExC,OADgBA,EAAAA,cACF,EAAE,WAAaC,EAAAA,cAAc,CAG7C,SAAgB,GAGd,CAEA,OADgBD,EAAAA,cACF,EAAE,sBAAwB,EAAE,CAG5C,SAAgB,GAAsD,CAEpE,OADgBA,EAAAA,cACF,EAAE,sBAAwB,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"useI18nStore.mjs","names":[],"sources":["../../src/i18n-store/useI18nStore.ts"],"sourcesContent":["import { Dictionary, Hash, Locale } from 'gt-i18n/internal/types';\nimport { useGTContext } from '../context/context';\nimport { I18nStore } from './I18nStore';\nimport { getI18nStore } from './singleton-operations';\nimport { Translation } from 'gt-i18n/types';\n\nexport function useI18nStore(): I18nStore {\n const context = useGTContext();\n return context?.i18nStore || getI18nStore();\n}\n\nexport function useTranslationsSnapshot(): Record<\n Locale,\n Record<Hash, Translation>\n> {\n const context = useGTContext();\n return context?.translationsSnapshot || {};\n}\n\nexport function useDictionariesSnapshot(): Record<Locale, Dictionary> {\n const context = useGTContext();\n return context?.dictionariesSnapshot || {};\n}\n"],"mappings":"gHAMA,SAAgB,GAA0B,CAExC,OADgB,GACF,EAAE,WAAa,GAAc,CAG7C,SAAgB,GAGd,CAEA,OADgB,GACF,EAAE,sBAAwB,EAAE,CAG5C,SAAgB,GAAsD,CAEpE,OADgB,GACF,EAAE,sBAAwB,EAAE"}
1
+ {"version":3,"file":"useI18nStore.mjs","names":[],"sources":["../../src/i18n-store/useI18nStore.ts"],"sourcesContent":["import { Dictionary, Hash, Locale } from 'gt-i18n/internal/types';\nimport { useGTContext } from '../context/context';\nimport { I18nStore } from './I18nStore';\nimport { getI18nStore } from './singleton-operations';\nimport type { Content } from '@generaltranslation/format/types';\n\nexport function useI18nStore(): I18nStore {\n const context = useGTContext();\n return context?.i18nStore || getI18nStore();\n}\n\nexport function useTranslationsSnapshot(): Record<\n Locale,\n Record<Hash, Content>\n> {\n const context = useGTContext();\n return context?.translationsSnapshot || {};\n}\n\nexport function useDictionariesSnapshot(): Record<Locale, Dictionary> {\n const context = useGTContext();\n return context?.dictionariesSnapshot || {};\n}\n"],"mappings":"gHAMA,SAAgB,GAA0B,CAExC,OADgB,GACF,EAAE,WAAa,GAAc,CAG7C,SAAgB,GAGd,CAEA,OADgB,GACF,EAAE,sBAAwB,EAAE,CAG5C,SAAgB,GAAsD,CAEpE,OADgB,GACF,EAAE,sBAAwB,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"translations.cjs","names":[],"sources":["../../../src/i18n-store/utils/translations.ts"],"sourcesContent":["import { hashMessage } from 'gt-i18n/internal';\nimport type { Hash, Locale } from 'gt-i18n/internal/types';\nimport type { Translation } from 'gt-i18n/types';\nimport type { TranslateLookup, TranslateSnapshot } from '../storeTypes';\n\nexport function lookupTranslation<T extends Translation>(\n translationsSnapshot: Record<Locale, Record<Hash, Translation>> | undefined,\n lookup: TranslateLookup<T>\n): TranslateSnapshot<T> {\n const hash =\n lookup.options.$_hash ?? hashMessage(lookup.message, lookup.options);\n return translationsSnapshot?.[lookup.locale]?.[hash] as TranslateSnapshot<T>;\n}\n"],"mappings":"kFAKA,SAAgB,EACd,EACA,EACsB,CACtB,IAAM,EACJ,EAAO,QAAQ,SAAA,EAAA,EAAA,aAAsB,EAAO,QAAS,EAAO,QAAQ,CACtE,OAAO,IAAuB,EAAO,UAAU"}
1
+ {"version":3,"file":"translations.cjs","names":[],"sources":["../../../src/i18n-store/utils/translations.ts"],"sourcesContent":["import { hashMessage } from 'gt-i18n/internal';\nimport type { Hash, Locale } from 'gt-i18n/internal/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport type { TranslateLookup, TranslateSnapshot } from '../storeTypes';\n\nexport function lookupTranslation<T extends Content>(\n translationsSnapshot: Record<Locale, Record<Hash, Content>> | undefined,\n lookup: TranslateLookup<T>\n): TranslateSnapshot<T> {\n const hash =\n lookup.options.$_hash ?? hashMessage(lookup.message, lookup.options);\n return translationsSnapshot?.[lookup.locale]?.[hash] as TranslateSnapshot<T>;\n}\n"],"mappings":"kFAKA,SAAgB,EACd,EACA,EACsB,CACtB,IAAM,EACJ,EAAO,QAAQ,SAAA,EAAA,EAAA,aAAsB,EAAO,QAAS,EAAO,QAAQ,CACtE,OAAO,IAAuB,EAAO,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"translations.mjs","names":[],"sources":["../../../src/i18n-store/utils/translations.ts"],"sourcesContent":["import { hashMessage } from 'gt-i18n/internal';\nimport type { Hash, Locale } from 'gt-i18n/internal/types';\nimport type { Translation } from 'gt-i18n/types';\nimport type { TranslateLookup, TranslateSnapshot } from '../storeTypes';\n\nexport function lookupTranslation<T extends Translation>(\n translationsSnapshot: Record<Locale, Record<Hash, Translation>> | undefined,\n lookup: TranslateLookup<T>\n): TranslateSnapshot<T> {\n const hash =\n lookup.options.$_hash ?? hashMessage(lookup.message, lookup.options);\n return translationsSnapshot?.[lookup.locale]?.[hash] as TranslateSnapshot<T>;\n}\n"],"mappings":"+CAKA,SAAgB,EACd,EACA,EACsB,CACtB,IAAM,EACJ,EAAO,QAAQ,QAAU,EAAY,EAAO,QAAS,EAAO,QAAQ,CACtE,OAAO,IAAuB,EAAO,UAAU"}
1
+ {"version":3,"file":"translations.mjs","names":[],"sources":["../../../src/i18n-store/utils/translations.ts"],"sourcesContent":["import { hashMessage } from 'gt-i18n/internal';\nimport type { Hash, Locale } from 'gt-i18n/internal/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport type { TranslateLookup, TranslateSnapshot } from '../storeTypes';\n\nexport function lookupTranslation<T extends Content>(\n translationsSnapshot: Record<Locale, Record<Hash, Content>> | undefined,\n lookup: TranslateLookup<T>\n): TranslateSnapshot<T> {\n const hash =\n lookup.options.$_hash ?? hashMessage(lookup.message, lookup.options);\n return translationsSnapshot?.[lookup.locale]?.[hash] as TranslateSnapshot<T>;\n}\n"],"mappings":"+CAKA,SAAgB,EACd,EACA,EACsB,CACtB,IAAM,EACJ,EAAO,QAAQ,QAAU,EAAY,EAAO,QAAS,EAAO,QAAQ,CACtE,OAAO,IAAuB,EAAO,UAAU"}
@@ -0,0 +1 @@
1
+ export * from './pure.js';
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../setup/i18nConfig.cjs`),t=require(`../condition-store/singleton-operations.cjs`);let n=require(`gt-i18n/internal`),r=require(`generaltranslation/internal`),i=require(`gt-i18n/unstable/internal`);const a=()=>e.getI18nConfig().getRenderStrategy()===`SPA`,o=(0,i.createGT)({getLocale:()=>t.getConditionStore().getLocale(),getEnableI18n:()=>a()&&t.getConditionStore().getEnableI18n()});function s(e){let t=(0,n.getRuntimeEnvironment)()===`development`,i=(0,r.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`t from /unstable is only available in client-rendered (SPA) apps`,fix:`In components, use useGT(); on the server, use getGT()`,wayOut:t?void 0:`The source message was rendered`,details:`Message: "${e.join(``)}"`});if(t)throw Error(i);console.error(i)}function c(e,t,n){return a()||s(t),e(t,...n)}const l=((e,...t)=>{if(Array.isArray(e))return c(o,e,t);let n=o(e);return(e,...t)=>c(n,e,t)});exports.t=l;
2
+ //# sourceMappingURL=t.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"t.cjs","names":["getI18nConfig","getReadonlyConditionStore"],"sources":["../../src/unstable/t.ts"],"sourcesContent":["import type { GT, GTOptions } from 'gt-i18n/unstable';\nimport { getRuntimeEnvironment } from 'gt-i18n/internal';\nimport { createGT } from 'gt-i18n/unstable/internal';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { getReadonlyConditionStore } from '../condition-store/singleton-operations';\nimport { getI18nConfig } from '../setup/i18nConfig';\n\ntype LooseTag = (strings: TemplateStringsArray, ...holes: unknown[]) => string;\n\n// Only a client-rendered app knows its locale and has its catalog loaded\n// wherever t runs, module level included. Server renders use useGT() or\n// getGT(), which load the request locale first.\nconst isSpa = () => getI18nConfig().getRenderStrategy() === 'SPA';\n\nconst gt = /* @__PURE__ */ createGT({\n getLocale: () => getReadonlyConditionStore().getLocale(),\n // Outside an SPA, t renders the source once the misuse is reported.\n getEnableI18n: () => isSpa() && getReadonlyConditionStore().getEnableI18n(),\n}) as unknown as LooseTag & ((options: GTOptions) => LooseTag);\n\nfunction reportServerRenderedUse(strings: TemplateStringsArray): void {\n const development = getRuntimeEnvironment() === 'development';\n const message = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 't from /unstable is only available in client-rendered (SPA) apps',\n fix: 'In components, use useGT(); on the server, use getGT()',\n wayOut: development ? undefined : 'The source message was rendered',\n details: `Message: \"${strings.join('')}\"`,\n });\n if (development) throw new Error(message);\n console.error(message);\n}\n\nfunction translate(\n tag: LooseTag,\n strings: TemplateStringsArray,\n holes: unknown[]\n): string {\n if (!isSpa()) reportServerRenderedUse(strings);\n return tag(strings, ...holes);\n}\n\n/**\n * Translates a message tree with the current locale. Client-rendered (SPA)\n * apps only, where it also works at module level; server-rendered apps use\n * useGT() or getGT().\n *\n * @example\n * t`Hello, ${{ name }}!`;\n * t({ context: 'button' })`Save`;\n */\nexport const t = ((\n first: TemplateStringsArray | GTOptions,\n ...holes: unknown[]\n) => {\n if (Array.isArray(first)) {\n return translate(gt, first as unknown as TemplateStringsArray, holes);\n }\n const tag = gt(first as GTOptions);\n return (strings: TemplateStringsArray, ...nested: unknown[]) =>\n translate(tag, strings, nested);\n}) as GT;\n"],"mappings":"mQAYA,MAAM,MAAcA,EAAAA,eAAe,CAAC,mBAAmB,GAAK,MAEtD,GAAqB,EAAA,EAAA,UAAS,CAClC,cAAiBC,EAAAA,mBAA2B,CAAC,WAAW,CAExD,kBAAqB,GAAO,EAAIA,EAAAA,mBAA2B,CAAC,eAAe,CAC5E,CAAC,CAEF,SAAS,EAAwB,EAAqC,CACpE,IAAM,GAAA,EAAA,EAAA,wBAAqC,GAAK,cAC1C,GAAA,EAAA,EAAA,yBAAkC,CACtC,OAAQ,iCACR,SAAU,QACV,aACE,mEACF,IAAK,yDACL,OAAQ,EAAc,IAAA,GAAY,kCAClC,QAAS,aAAa,EAAQ,KAAK,GAAG,CAAC,GACxC,CAAC,CACF,GAAI,EAAa,MAAU,MAAM,EAAQ,CACzC,QAAQ,MAAM,EAAQ,CAGxB,SAAS,EACP,EACA,EACA,EACQ,CAER,OADK,GAAO,EAAE,EAAwB,EAAQ,CACvC,EAAI,EAAS,GAAG,EAAM,CAY/B,MAAa,IACX,EACA,GAAG,IACA,CACH,GAAI,MAAM,QAAQ,EAAM,CACtB,OAAO,EAAU,EAAI,EAA0C,EAAM,CAEvE,IAAM,EAAM,EAAG,EAAmB,CAClC,OAAQ,EAA+B,GAAG,IACxC,EAAU,EAAK,EAAS,EAAO"}
@@ -0,0 +1,16 @@
1
+ import { GT } from "gt-i18n/unstable";
2
+
3
+ //#region src/unstable/t.d.ts
4
+ /**
5
+ * Translates a message tree with the current locale. Client-rendered (SPA)
6
+ * apps only, where it also works at module level; server-rendered apps use
7
+ * useGT() or getGT().
8
+ *
9
+ * @example
10
+ * t`Hello, ${{ name }}!`;
11
+ * t({ context: 'button' })`Save`;
12
+ */
13
+ declare const t: GT;
14
+ //#endregion
15
+ export { t };
16
+ //# sourceMappingURL=t.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"t.d.ts","names":[],"sources":["../../src/unstable/t.ts"],"mappings":";;;;;AAqDA;;;;;;;cAAa,CAAA,EAUP,EAAA"}
@@ -0,0 +1,2 @@
1
+ import{getI18nConfig as e}from"../setup/i18nConfig.mjs";import{getConditionStore as t}from"../condition-store/singleton-operations.mjs";import{getRuntimeEnvironment as n}from"gt-i18n/internal";import{createDiagnosticMessage as r}from"generaltranslation/internal";import{createGT as i}from"gt-i18n/unstable/internal";const a=()=>e().getRenderStrategy()===`SPA`,o=i({getLocale:()=>t().getLocale(),getEnableI18n:()=>a()&&t().getEnableI18n()});function s(e){let t=n()===`development`,i=r({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`t from /unstable is only available in client-rendered (SPA) apps`,fix:`In components, use useGT(); on the server, use getGT()`,wayOut:t?void 0:`The source message was rendered`,details:`Message: "${e.join(``)}"`});if(t)throw Error(i);console.error(i)}function c(e,t,n){return a()||s(t),e(t,...n)}const l=((e,...t)=>{if(Array.isArray(e))return c(o,e,t);let n=o(e);return(e,...t)=>c(n,e,t)});export{l as t};
2
+ //# sourceMappingURL=t.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"t.mjs","names":["getI18nConfig","getReadonlyConditionStore"],"sources":["../../src/unstable/t.ts"],"sourcesContent":["import type { GT, GTOptions } from 'gt-i18n/unstable';\nimport { getRuntimeEnvironment } from 'gt-i18n/internal';\nimport { createGT } from 'gt-i18n/unstable/internal';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { getReadonlyConditionStore } from '../condition-store/singleton-operations';\nimport { getI18nConfig } from '../setup/i18nConfig';\n\ntype LooseTag = (strings: TemplateStringsArray, ...holes: unknown[]) => string;\n\n// Only a client-rendered app knows its locale and has its catalog loaded\n// wherever t runs, module level included. Server renders use useGT() or\n// getGT(), which load the request locale first.\nconst isSpa = () => getI18nConfig().getRenderStrategy() === 'SPA';\n\nconst gt = /* @__PURE__ */ createGT({\n getLocale: () => getReadonlyConditionStore().getLocale(),\n // Outside an SPA, t renders the source once the misuse is reported.\n getEnableI18n: () => isSpa() && getReadonlyConditionStore().getEnableI18n(),\n}) as unknown as LooseTag & ((options: GTOptions) => LooseTag);\n\nfunction reportServerRenderedUse(strings: TemplateStringsArray): void {\n const development = getRuntimeEnvironment() === 'development';\n const message = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 't from /unstable is only available in client-rendered (SPA) apps',\n fix: 'In components, use useGT(); on the server, use getGT()',\n wayOut: development ? undefined : 'The source message was rendered',\n details: `Message: \"${strings.join('')}\"`,\n });\n if (development) throw new Error(message);\n console.error(message);\n}\n\nfunction translate(\n tag: LooseTag,\n strings: TemplateStringsArray,\n holes: unknown[]\n): string {\n if (!isSpa()) reportServerRenderedUse(strings);\n return tag(strings, ...holes);\n}\n\n/**\n * Translates a message tree with the current locale. Client-rendered (SPA)\n * apps only, where it also works at module level; server-rendered apps use\n * useGT() or getGT().\n *\n * @example\n * t`Hello, ${{ name }}!`;\n * t({ context: 'button' })`Save`;\n */\nexport const t = ((\n first: TemplateStringsArray | GTOptions,\n ...holes: unknown[]\n) => {\n if (Array.isArray(first)) {\n return translate(gt, first as unknown as TemplateStringsArray, holes);\n }\n const tag = gt(first as GTOptions);\n return (strings: TemplateStringsArray, ...nested: unknown[]) =>\n translate(tag, strings, nested);\n}) as GT;\n"],"mappings":"4TAYA,MAAM,MAAcA,GAAe,CAAC,mBAAmB,GAAK,MAEtD,EAAqB,EAAS,CAClC,cAAiBC,GAA2B,CAAC,WAAW,CAExD,kBAAqB,GAAO,EAAIA,GAA2B,CAAC,eAAe,CAC5E,CAAC,CAEF,SAAS,EAAwB,EAAqC,CACpE,IAAM,EAAc,GAAuB,GAAK,cAC1C,EAAU,EAAwB,CACtC,OAAQ,iCACR,SAAU,QACV,aACE,mEACF,IAAK,yDACL,OAAQ,EAAc,IAAA,GAAY,kCAClC,QAAS,aAAa,EAAQ,KAAK,GAAG,CAAC,GACxC,CAAC,CACF,GAAI,EAAa,MAAU,MAAM,EAAQ,CACzC,QAAQ,MAAM,EAAQ,CAGxB,SAAS,EACP,EACA,EACA,EACQ,CAER,OADK,GAAO,EAAE,EAAwB,EAAQ,CACvC,EAAI,EAAS,GAAG,EAAM,CAY/B,MAAa,IACX,EACA,GAAG,IACA,CACH,GAAI,MAAM,QAAQ,EAAM,CACtB,OAAO,EAAU,EAAI,EAA0C,EAAM,CAEvE,IAAM,EAAM,EAAG,EAAmB,CAClC,OAAQ,EAA+B,GAAG,IACxC,EAAU,EAAK,EAAS,EAAO"}
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../hooks/condition-store.cjs`),t=require(`../hooks/utils.cjs`),n=require(`../hooks/external-store/useTrackedTranslationResolver.cjs`);let r=require(`react`),i=require(`gt-i18n/unstable/internal`);function a(){let{locale:a,shouldTranslate:o}=t.useTranslationConditions(),s=e.useEnableI18n(),c=n.useTrackedTranslationResolver(void 0,a,o);return(0,r.useMemo)(()=>(0,i.createGT)({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,message:e,options:t})}),[a,s,c])}exports.useGT=a;
2
+ //# sourceMappingURL=useGT.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGT.cjs","names":["useTranslationConditions","useEnableI18n","useTrackedTranslationResolver"],"sources":["../../src/unstable/useGT.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { GT } from 'gt-i18n/unstable';\nimport { createGT } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns a GT bound to the render locale. Like the legacy useGT(), it reads\n * the provider's translations snapshot, then the I18nCache, and in dev hot\n * reload sends misses for runtime translation and re-renders when they\n * arrive. Other misses render the source.\n *\n * @example\n * const gt = useGT();\n * gt`Hello, ${{ name }}!`;\n */\nexport function useGT(): GT {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createGT({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (message, options) =>\n resolveTranslation({ locale: options.$locale, message, options }),\n }),\n [locale, enableI18n, resolveTranslation]\n );\n}\n"],"mappings":"kQAiBA,SAAgB,GAAY,CAC1B,GAAM,CAAE,SAAQ,mBAAoBA,EAAAA,0BAA0B,CACxD,EAAaC,EAAAA,eAAe,CAC5B,EAAqBC,EAAAA,8BACzB,IAAA,GACA,EACA,EACD,CACD,OAAA,EAAA,EAAA,cAAA,EAAA,EAAA,UAEa,CACP,cAAiB,EACjB,kBAAqB,EACrB,mBAAoB,EAAS,IAC3B,EAAmB,CAAE,OAAQ,EAAQ,QAAS,UAAS,UAAS,CAAC,CACpE,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
@@ -0,0 +1,17 @@
1
+ import { GT } from "gt-i18n/unstable";
2
+
3
+ //#region src/unstable/useGT.d.ts
4
+ /**
5
+ * Returns a GT bound to the render locale. Like the legacy useGT(), it reads
6
+ * the provider's translations snapshot, then the I18nCache, and in dev hot
7
+ * reload sends misses for runtime translation and re-renders when they
8
+ * arrive. Other misses render the source.
9
+ *
10
+ * @example
11
+ * const gt = useGT();
12
+ * gt`Hello, ${{ name }}!`;
13
+ */
14
+ declare function useGT(): GT;
15
+ //#endregion
16
+ export { useGT };
17
+ //# sourceMappingURL=useGT.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGT.d.ts","names":[],"sources":["../../src/unstable/useGT.ts"],"mappings":";;;;;AAiBA;;;;;;;;iBAAgB,KAAA,CAAA,GAAS,EAAA"}
@@ -0,0 +1,2 @@
1
+ import{useEnableI18n as e}from"../hooks/condition-store.mjs";import{useTranslationConditions as t}from"../hooks/utils.mjs";import{useTrackedTranslationResolver as n}from"../hooks/external-store/useTrackedTranslationResolver.mjs";import{useMemo as r}from"react";import{createGT as i}from"gt-i18n/unstable/internal";function a(){let{locale:a,shouldTranslate:o}=t(),s=e(),c=n(void 0,a,o);return r(()=>i({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,message:e,options:t})}),[a,s,c])}export{a as useGT};
2
+ //# sourceMappingURL=useGT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGT.mjs","names":[],"sources":["../../src/unstable/useGT.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { GT } from 'gt-i18n/unstable';\nimport { createGT } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns a GT bound to the render locale. Like the legacy useGT(), it reads\n * the provider's translations snapshot, then the I18nCache, and in dev hot\n * reload sends misses for runtime translation and re-renders when they\n * arrive. Other misses render the source.\n *\n * @example\n * const gt = useGT();\n * gt`Hello, ${{ name }}!`;\n */\nexport function useGT(): GT {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createGT({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (message, options) =>\n resolveTranslation({ locale: options.$locale, message, options }),\n }),\n [locale, enableI18n, resolveTranslation]\n );\n}\n"],"mappings":"0TAiBA,SAAgB,GAAY,CAC1B,GAAM,CAAE,SAAQ,mBAAoB,GAA0B,CACxD,EAAa,GAAe,CAC5B,EAAqB,EACzB,IAAA,GACA,EACA,EACD,CACD,OAAO,MAEH,EAAS,CACP,cAAiB,EACjB,kBAAqB,EACrB,mBAAoB,EAAS,IAC3B,EAAmB,CAAE,OAAQ,EAAQ,QAAS,UAAS,UAAS,CAAC,CACpE,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../hooks/condition-store.cjs`),t=require(`../hooks/utils.cjs`),n=require(`../hooks/external-store/useTrackedTranslationResolver.cjs`);let r=require(`react`),i=require(`gt-i18n/unstable/internal`);function a(){let{locale:a,shouldTranslate:o}=t.useTranslationConditions(),s=e.useEnableI18n(),c=n.useTrackedTranslationResolver(void 0,a,o);return(0,r.useMemo)(()=>(0,i.createMessages)({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,message:e,options:t})}),[a,s,c])}exports.useMessages=a;
2
+ //# sourceMappingURL=useMessages.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMessages.cjs","names":["useTranslationConditions","useEnableI18n","useTrackedTranslationResolver"],"sources":["../../src/unstable/useMessages.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { M } from 'gt-i18n/unstable';\nimport { createMessages } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns an m bound to the render locale, which renders messages from msg().\n * Like useGT(), it reads the provider's translations snapshot, then the\n * I18nCache, and in dev hot reload sends misses for runtime translation.\n *\n * @example\n * const m = useMessages();\n * m(msg`Hello, ${{ name }}!`);\n */\nexport function useMessages(): M {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createMessages({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (message, options) =>\n resolveTranslation({ locale: options.$locale, message, options }),\n }),\n [locale, enableI18n, resolveTranslation]\n );\n}\n"],"mappings":"kQAgBA,SAAgB,GAAiB,CAC/B,GAAM,CAAE,SAAQ,mBAAoBA,EAAAA,0BAA0B,CACxD,EAAaC,EAAAA,eAAe,CAC5B,EAAqBC,EAAAA,8BACzB,IAAA,GACA,EACA,EACD,CACD,OAAA,EAAA,EAAA,cAAA,EAAA,EAAA,gBAEmB,CACb,cAAiB,EACjB,kBAAqB,EACrB,mBAAoB,EAAS,IAC3B,EAAmB,CAAE,OAAQ,EAAQ,QAAS,UAAS,UAAS,CAAC,CACpE,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
@@ -0,0 +1,16 @@
1
+ import { M } from "gt-i18n/unstable";
2
+
3
+ //#region src/unstable/useMessages.d.ts
4
+ /**
5
+ * Returns an m bound to the render locale, which renders messages from msg().
6
+ * Like useGT(), it reads the provider's translations snapshot, then the
7
+ * I18nCache, and in dev hot reload sends misses for runtime translation.
8
+ *
9
+ * @example
10
+ * const m = useMessages();
11
+ * m(msg`Hello, ${{ name }}!`);
12
+ */
13
+ declare function useMessages(): M;
14
+ //#endregion
15
+ export { useMessages };
16
+ //# sourceMappingURL=useMessages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMessages.d.ts","names":[],"sources":["../../src/unstable/useMessages.ts"],"mappings":";;;;;AAgBA;;;;;;;iBAAgB,WAAA,CAAA,GAAe,CAAA"}
@@ -0,0 +1,2 @@
1
+ import{useEnableI18n as e}from"../hooks/condition-store.mjs";import{useTranslationConditions as t}from"../hooks/utils.mjs";import{useTrackedTranslationResolver as n}from"../hooks/external-store/useTrackedTranslationResolver.mjs";import{useMemo as r}from"react";import{createMessages as i}from"gt-i18n/unstable/internal";function a(){let{locale:a,shouldTranslate:o}=t(),s=e(),c=n(void 0,a,o);return r(()=>i({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,message:e,options:t})}),[a,s,c])}export{a as useMessages};
2
+ //# sourceMappingURL=useMessages.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMessages.mjs","names":[],"sources":["../../src/unstable/useMessages.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { M } from 'gt-i18n/unstable';\nimport { createMessages } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns an m bound to the render locale, which renders messages from msg().\n * Like useGT(), it reads the provider's translations snapshot, then the\n * I18nCache, and in dev hot reload sends misses for runtime translation.\n *\n * @example\n * const m = useMessages();\n * m(msg`Hello, ${{ name }}!`);\n */\nexport function useMessages(): M {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createMessages({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (message, options) =>\n resolveTranslation({ locale: options.$locale, message, options }),\n }),\n [locale, enableI18n, resolveTranslation]\n );\n}\n"],"mappings":"gUAgBA,SAAgB,GAAiB,CAC/B,GAAM,CAAE,SAAQ,mBAAoB,GAA0B,CACxD,EAAa,GAAe,CAC5B,EAAqB,EACzB,IAAA,GACA,EACA,EACD,CACD,OAAO,MAEH,EAAe,CACb,cAAiB,EACjB,kBAAqB,EACrB,mBAAoB,EAAS,IAC3B,EAAmB,CAAE,OAAQ,EAAQ,QAAS,UAAS,UAAS,CAAC,CACpE,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./unstable/t.cjs`),t=require(`./unstable/useGT.cjs`),n=require(`./unstable/useMessages.cjs`);let r=require(`gt-i18n/unstable`);Object.defineProperty(exports,`date`,{enumerable:!0,get:function(){return r.date}}),Object.defineProperty(exports,`derive`,{enumerable:!0,get:function(){return r.derive}}),Object.defineProperty(exports,`mFallback`,{enumerable:!0,get:function(){return r.mFallback}}),Object.defineProperty(exports,`msg`,{enumerable:!0,get:function(){return r.msg}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return r.n}}),Object.defineProperty(exports,`number`,{enumerable:!0,get:function(){return r.number}}),Object.defineProperty(exports,`part`,{enumerable:!0,get:function(){return r.part}}),Object.defineProperty(exports,`plural`,{enumerable:!0,get:function(){return r.plural}}),Object.defineProperty(exports,`select`,{enumerable:!0,get:function(){return r.select}}),Object.defineProperty(exports,`selectordinal`,{enumerable:!0,get:function(){return r.selectordinal}}),exports.t=e.t,exports.useGT=t.useGT,exports.useMessages=n.useMessages;
@@ -0,0 +1 @@
1
+ export * from './unstable.js';
@@ -0,0 +1,5 @@
1
+ import { t } from "./unstable/t.js";
2
+ import { useGT } from "./unstable/useGT.js";
3
+ import { useMessages } from "./unstable/useMessages.js";
4
+ import { Fragment, GT, GTOptions, M, Msg, Placeholder, date, derive, mFallback, msg, n, number, part, plural, select, selectordinal } from "gt-i18n/unstable";
5
+ export { type Fragment, type GT, type GTOptions, type M, type Msg, type Placeholder, date, derive, mFallback, msg, n, number, part, plural, select, selectordinal, t, useGT, useMessages };
@@ -0,0 +1 @@
1
+ import{t as e}from"./unstable/t.mjs";import{useGT as t}from"./unstable/useGT.mjs";import{useMessages as n}from"./unstable/useMessages.mjs";import{date as r,derive as i,mFallback as a,msg as o,n as s,number as c,part as l,plural as u,select as d,selectordinal as f}from"gt-i18n/unstable";export{r as date,i as derive,a as mFallback,o as msg,s as n,c as number,l as part,u as plural,d as select,f as selectordinal,e as t,t as useGT,n as useMessages};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@generaltranslation/react-core",
3
- "version": "11.4.18",
3
+ "version": "12.0.0-samsara.1",
4
4
  "description": "A pure React library for internationalization",
5
5
  "files": [
6
6
  "dist",
@@ -11,9 +11,9 @@
11
11
  "react": ">=18.0.0"
12
12
  },
13
13
  "dependencies": {
14
- "@generaltranslation/format": "0.1.9",
15
- "generaltranslation": "9.5.9",
16
- "gt-i18n": "1.0.40"
14
+ "@generaltranslation/format": "1.0.0-samsara.2",
15
+ "generaltranslation": "10.0.0-samsara.1",
16
+ "gt-i18n": "2.0.0-samsara.1"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
@@ -33,40 +33,54 @@
33
33
  },
34
34
  "exports": {
35
35
  "./pure": {
36
- "types": "./dist/pure.d.ts",
37
- "require": "./dist/pure.cjs",
38
- "import": "./dist/pure.mjs"
36
+ "require": {
37
+ "types": "./dist/pure.d.ts",
38
+ "default": "./dist/pure.cjs"
39
+ },
40
+ "import": {
41
+ "types": "./dist/pure.d.mts",
42
+ "default": "./dist/pure.mjs"
43
+ }
39
44
  },
40
45
  "./hooks": {
41
- "types": "./dist/hooks.d.ts",
42
- "require": "./dist/hooks.cjs",
43
- "import": "./dist/hooks.mjs"
46
+ "require": {
47
+ "types": "./dist/hooks.d.ts",
48
+ "default": "./dist/hooks.cjs"
49
+ },
50
+ "import": {
51
+ "types": "./dist/hooks.d.mts",
52
+ "default": "./dist/hooks.mjs"
53
+ }
44
54
  },
45
55
  "./components": {
46
- "types": "./dist/components.d.ts",
47
- "require": "./dist/components.cjs",
48
- "import": "./dist/components.mjs"
56
+ "require": {
57
+ "types": "./dist/components.d.ts",
58
+ "default": "./dist/components.cjs"
59
+ },
60
+ "import": {
61
+ "types": "./dist/components.d.mts",
62
+ "default": "./dist/components.mjs"
63
+ }
49
64
  },
50
65
  "./components-rsc": {
51
- "types": "./dist/components-rsc.d.ts",
52
- "require": "./dist/components-rsc.cjs",
53
- "import": "./dist/components-rsc.mjs"
54
- }
55
- },
56
- "typesVersions": {
57
- "*": {
58
- "pure": [
59
- "./dist/pure.d.ts"
60
- ],
61
- "hooks": [
62
- "./dist/hooks.d.ts"
63
- ],
64
- "components": [
65
- "./dist/components.d.ts"
66
- ],
67
- "components-rsc": [
68
- "./dist/components-rsc.d.ts"
69
- ]
66
+ "require": {
67
+ "types": "./dist/components-rsc.d.ts",
68
+ "default": "./dist/components-rsc.cjs"
69
+ },
70
+ "import": {
71
+ "types": "./dist/components-rsc.d.mts",
72
+ "default": "./dist/components-rsc.mjs"
73
+ }
74
+ },
75
+ "./unstable": {
76
+ "require": {
77
+ "types": "./dist/unstable.d.ts",
78
+ "default": "./dist/unstable.cjs"
79
+ },
80
+ "import": {
81
+ "types": "./dist/unstable.d.mts",
82
+ "default": "./dist/unstable.mjs"
83
+ }
70
84
  }
71
85
  },
72
86
  "keywords": [