@openrails/contentkit-ui 0.98.0 → 0.98.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@ export interface ContentKitUiProviderProps {
12
12
  messages?: ContentKitUiMessageBundle | readonly ContentKitUiMessageBundle[];
13
13
  /** Host translation hook, consulted before the bundles. */
14
14
  t?: ContentKitUiTranslate;
15
- /** Device-pixel density range images and covers are picked for. Default [2, 3]. */
15
+ /** Device-pixel density range images and covers are picked for. Default [1, 3]. */
16
16
  density?: DensityRange;
17
17
  /** Playable videos preview muted inline (hover, or in view on touch). Default true. */
18
18
  inlinePreview?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","names":[],"sources":["../src/provider.tsx"],"sourcesContent":["import { useEffect, useMemo, useState, type ReactNode } from \"react\";\nimport type { ContentKitUiAppearance } from \"./appearance.js\";\nimport { DEFAULT_DENSITY, type DensityRange } from \"./client/rendition.js\";\nimport { DensityContext } from \"./components/rendition-img.js\";\nimport { MessagesContext } from \"./i18n/context.js\";\nimport { createTranslator, resolveMessages, type ContentKitUiMessageBundle, type ContentKitUiTranslate } from \"./i18n/messages.js\";\nimport { InlinePreviewContext } from \"./react/inline-preview.js\";\nimport { AppearanceContext } from \"./scope.js\";\n\n/** Built-in bundles besides English, loaded on demand. */\nconst BUNDLES: Record<string, () => Promise<ContentKitUiMessageBundle>> = {\n de: () => import(\"./locales/de.js\").then((m) => m.de),\n es: () => import(\"./locales/es.js\").then((m) => m.es),\n ja: () => import(\"./locales/ja.js\").then((m) => m.ja),\n ko: () => import(\"./locales/ko.js\").then((m) => m.ko),\n zh: () => import(\"./locales/zh.js\").then((m) => m.zh),\n};\n\n/** The built-in bundle's language for a BCP 47 tag (\"ja-JP\" → \"ja\"); undefined for English or one we lack. */\nexport function bundleLanguage(language: string | null | undefined): string | undefined {\n const primary = language?.toLowerCase().split(/[-_]/)[0];\n return primary && primary in BUNDLES ? primary : undefined;\n}\n\nexport interface ContentKitUiProviderProps {\n appearance?: ContentKitUiAppearance;\n /** BCP 47 tag; its built-in bundle loads under `messages`. English until it arrives. */\n language?: string;\n /** Bundle(s) layered over English and the language's bundle; later entries win. */\n messages?: ContentKitUiMessageBundle | readonly ContentKitUiMessageBundle[];\n /** Host translation hook, consulted before the bundles. */\n t?: ContentKitUiTranslate;\n /** Device-pixel density range images and covers are picked for. Default [2, 3]. */\n density?: DensityRange;\n /** Playable videos preview muted inline (hover, or in view on touch). Default true. */\n inlinePreview?: boolean;\n children?: ReactNode;\n}\n\n/** The translator for a language's bundle (loaded on demand) under the given bundles and host hook. */\nexport function useTranslator(language?: string, messages?: ContentKitUiMessageBundle | readonly ContentKitUiMessageBundle[], t?: ContentKitUiTranslate) {\n const lang = bundleLanguage(language);\n const [loaded, setLoaded] = useState<{ lang: string; bundle: ContentKitUiMessageBundle } | null>(null);\n useEffect(() => {\n if (!lang) return;\n let live = true;\n BUNDLES[lang]!().then(\n (bundle) => live && setLoaded({ lang, bundle }),\n () => {},\n );\n return () => {\n live = false;\n };\n }, [lang]);\n const bundle = lang && loaded?.lang === lang ? loaded.bundle : undefined;\n return useMemo(() => {\n const own = messages ? (Array.isArray(messages) ? messages : [messages]) : [];\n return createTranslator(resolveMessages(bundle ? [bundle, ...own] : own), t, language);\n }, [bundle, messages, t, language]);\n}\n\n/** Look and language for every component below. Renders no DOM; components create their own `.ckui` roots. */\nexport function ContentKitUiProvider({ appearance, language, messages, t, density = DEFAULT_DENSITY, inlinePreview = true, children }: ContentKitUiProviderProps) {\n const translator = useTranslator(language, messages, t);\n return (\n <AppearanceContext.Provider value={appearance}>\n <MessagesContext.Provider value={translator}>\n <DensityContext.Provider value={density}>\n <InlinePreviewContext.Provider value={inlinePreview}>{children}</InlinePreviewContext.Provider>\n </DensityContext.Provider>\n </MessagesContext.Provider>\n </AppearanceContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;;AAUA,IAAM,IAAoE;CACxE,UAAU,OAAO,kB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AC,EAAgB,UAAjB;GAA0B,OAAO;GAC/B,UAAA,kBAAC,EAAe,UAAhB;IAAyB,OAAO;IAC9B,UAAA,kBAAC,EAAqB,UAAtB;KAA+B,OAAO;KAAgB;IAAwC,CAAA;GACvE,CAAA;EACD,CAAA;CACA,CAAA;AAEhC"}
1
+ {"version":3,"file":"provider.js","names":[],"sources":["../src/provider.tsx"],"sourcesContent":["import { useEffect, useMemo, useState, type ReactNode } from \"react\";\nimport type { ContentKitUiAppearance } from \"./appearance.js\";\nimport { DEFAULT_DENSITY, type DensityRange } from \"./client/rendition.js\";\nimport { DensityContext } from \"./components/rendition-img.js\";\nimport { MessagesContext } from \"./i18n/context.js\";\nimport { createTranslator, resolveMessages, type ContentKitUiMessageBundle, type ContentKitUiTranslate } from \"./i18n/messages.js\";\nimport { InlinePreviewContext } from \"./react/inline-preview.js\";\nimport { AppearanceContext } from \"./scope.js\";\n\n/** Built-in bundles besides English, loaded on demand. */\nconst BUNDLES: Record<string, () => Promise<ContentKitUiMessageBundle>> = {\n de: () => import(\"./locales/de.js\").then((m) => m.de),\n es: () => import(\"./locales/es.js\").then((m) => m.es),\n ja: () => import(\"./locales/ja.js\").then((m) => m.ja),\n ko: () => import(\"./locales/ko.js\").then((m) => m.ko),\n zh: () => import(\"./locales/zh.js\").then((m) => m.zh),\n};\n\n/** The built-in bundle's language for a BCP 47 tag (\"ja-JP\" → \"ja\"); undefined for English or one we lack. */\nexport function bundleLanguage(language: string | null | undefined): string | undefined {\n const primary = language?.toLowerCase().split(/[-_]/)[0];\n return primary && primary in BUNDLES ? primary : undefined;\n}\n\nexport interface ContentKitUiProviderProps {\n appearance?: ContentKitUiAppearance;\n /** BCP 47 tag; its built-in bundle loads under `messages`. English until it arrives. */\n language?: string;\n /** Bundle(s) layered over English and the language's bundle; later entries win. */\n messages?: ContentKitUiMessageBundle | readonly ContentKitUiMessageBundle[];\n /** Host translation hook, consulted before the bundles. */\n t?: ContentKitUiTranslate;\n /** Device-pixel density range images and covers are picked for. Default [1, 3]. */\n density?: DensityRange;\n /** Playable videos preview muted inline (hover, or in view on touch). Default true. */\n inlinePreview?: boolean;\n children?: ReactNode;\n}\n\n/** The translator for a language's bundle (loaded on demand) under the given bundles and host hook. */\nexport function useTranslator(language?: string, messages?: ContentKitUiMessageBundle | readonly ContentKitUiMessageBundle[], t?: ContentKitUiTranslate) {\n const lang = bundleLanguage(language);\n const [loaded, setLoaded] = useState<{ lang: string; bundle: ContentKitUiMessageBundle } | null>(null);\n useEffect(() => {\n if (!lang) return;\n let live = true;\n BUNDLES[lang]!().then(\n (bundle) => live && setLoaded({ lang, bundle }),\n () => {},\n );\n return () => {\n live = false;\n };\n }, [lang]);\n const bundle = lang && loaded?.lang === lang ? loaded.bundle : undefined;\n return useMemo(() => {\n const own = messages ? (Array.isArray(messages) ? messages : [messages]) : [];\n return createTranslator(resolveMessages(bundle ? [bundle, ...own] : own), t, language);\n }, [bundle, messages, t, language]);\n}\n\n/** Look and language for every component below. Renders no DOM; components create their own `.ckui` roots. */\nexport function ContentKitUiProvider({ appearance, language, messages, t, density = DEFAULT_DENSITY, inlinePreview = true, children }: ContentKitUiProviderProps) {\n const translator = useTranslator(language, messages, t);\n return (\n <AppearanceContext.Provider value={appearance}>\n <MessagesContext.Provider value={translator}>\n <DensityContext.Provider value={density}>\n <InlinePreviewContext.Provider value={inlinePreview}>{children}</InlinePreviewContext.Provider>\n </DensityContext.Provider>\n </MessagesContext.Provider>\n </AppearanceContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;;AAUA,IAAM,IAAoE;CACxE,UAAU,OAAO,kBAAkB,CAAC,MAAM,MAAM,EAAE,EAAE;CACpD,UAAU,OAAO,kBAAkB,CAAC,MAAM,MAAM,EAAE,EAAE;CACpD,UAAU,OAAO,kBAAkB,CAAC,MAAM,MAAM,EAAE,EAAE;CACpD,UAAU,OAAO,kBAAkB,CAAC,MAAM,MAAM,EAAE,EAAE;CACpD,UAAU,OAAO,kBAAkB,CAAC,MAAM,MA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