diff --git a/package.json b/package.json index 0efa68b2..43316a4c 100644 --- a/package.json +++ b/package.json @@ -129,7 +129,7 @@ "h3", "nitropack", "@vue/runtime-core", - "#nuxt-og-image/components", + "#og-image/components", "sharp", "unstorage", "unstorage/drivers/fs", diff --git a/src/compatibility.ts b/src/compatibility.ts index c5dd14f0..2a429c4c 100644 --- a/src/compatibility.ts +++ b/src/compatibility.ts @@ -140,8 +140,8 @@ export async function applyNitroPresetCompatibility(nitroConfig: NitroConfig, op const satoriEnabled = typeof options.compatibility?.satori !== 'undefined' ? !!options.compatibility.satori : !!compatibility.satori const chromiumEnabled = typeof options.compatibility?.chromium !== 'undefined' ? !!options.compatibility.chromium : !!compatibility.chromium // renderers - nitroConfig.alias!['#nuxt-og-image/renderers/satori'] = satoriEnabled ? resolve('./runtime/nitro/og-image/satori/renderer') : 'unenv/runtime/mock/empty' - nitroConfig.alias!['#nuxt-og-image/renderers/chromium'] = chromiumEnabled ? resolve('./runtime/nitro/og-image/chromium/renderer') : 'unenv/runtime/mock/empty' + nitroConfig.alias!['#og-image/renderers/satori'] = satoriEnabled ? resolve('./runtime/nitro/og-image/satori/renderer') : 'unenv/runtime/mock/empty' + nitroConfig.alias!['#og-image/renderers/chromium'] = chromiumEnabled ? resolve('./runtime/nitro/og-image/chromium/renderer') : 'unenv/runtime/mock/empty' const resolvedCompatibility: Partial> = {} function applyBinding(key: keyof Omit) { @@ -159,7 +159,7 @@ export async function applyNitroPresetCompatibility(nitroConfig: NitroConfig, op // @ts-expect-error untyped resolvedCompatibility[key] = binding return { - [`#nuxt-og-image/bindings/${key}`]: binding === false ? 'unenv/runtime/mock/empty' : resolve(`./runtime/nitro/og-image/bindings/${key}/${binding}`), + [`#og-image/bindings/${key}`]: binding === false ? 'unenv/runtime/mock/empty' : resolve(`./runtime/nitro/og-image/bindings/${key}/${binding}`), } } nitroConfig.alias = defu( @@ -178,7 +178,7 @@ export async function applyNitroPresetCompatibility(nitroConfig: NitroConfig, op nitroConfig.rollupConfig = nitroConfig.rollupConfig || {} nitroConfig.wasm = defu(compatibility.wasm, nitroConfig.wasm) - nitroConfig.virtual!['#nuxt-og-image/compatibility'] = () => `export default ${JSON.stringify(resolvedCompatibility)}` + nitroConfig.virtual!['#og-image/compatibility'] = () => `export default ${JSON.stringify(resolvedCompatibility)}` addTemplate({ filename: 'nuxt-og-image/compatibility.mjs', getContents() { diff --git a/src/module.ts b/src/module.ts index 90cb8475..cd3222de 100644 --- a/src/module.ts +++ b/src/module.ts @@ -199,8 +199,8 @@ export default defineNuxtModule({ logger.warn('Nuxt OG Image is enabled but SSR is disabled.\n\nYou should enable SSR (`ssr: true`) or disable the module (`ogImage: { enabled: false }`).') return } - nuxt.options.alias['#nuxt-og-image'] = resolve('./runtime') - nuxt.options.alias['#nuxt-og-image-cache'] = resolve('./runtime/nitro/og-image/cache/lru') + nuxt.options.alias['#og-image'] = resolve('./runtime') + nuxt.options.alias['#og-image-cache'] = resolve('./runtime/nitro/og-image/cache/lru') const preset = resolveNitroPreset(nuxt.options.nitro) const targetCompatibility = getPresetNitroPresetCompatibility(preset) @@ -215,7 +215,7 @@ export default defineNuxtModule({ if (!nuxt.options.dev) { addBuildPlugin(TreeShakeComposablesPlugin, { server: true, client: true, build: true }) - nuxt.options.alias['#nuxt-og-image-cache'] = resolve('./runtime/nitro/og-image/cache/mock') + nuxt.options.alias['#og-image-cache'] = resolve('./runtime/nitro/og-image/cache/mock') } } @@ -491,7 +491,7 @@ export default defineNuxtModule({ options: { mode: 'server' }, }) nuxt.options.nitro.virtual = nuxt.options.nitro.virtual || {} - nuxt.options.nitro.virtual['#nuxt-og-image-virtual/component-names.mjs'] = () => { + nuxt.options.nitro.virtual['#og-image-virtual/component-names.mjs'] = () => { return `export const componentNames = ${JSON.stringify(ogImageComponentCtx.components)}` } @@ -505,7 +505,7 @@ export default defineNuxtModule({ nuxt.hook('unocss:config', (_unoCssConfig) => { unoCssConfig = { ..._unoCssConfig.theme } }) - nuxt.options.nitro.virtual['#nuxt-og-image-virtual/unocss-config.mjs'] = () => { + nuxt.options.nitro.virtual['#og-image-virtual/unocss-config.mjs'] = () => { return `export const theme = ${JSON.stringify(unoCssConfig)}` } @@ -537,12 +537,12 @@ declare module 'nitropack' { } } -declare module '#nuxt-og-image/components' { +declare module '#og-image/components' { export interface OgImageComponents { ${componentImports} } } -declare module '#nuxt-og-image/unocss-config' { +declare module '#og-image/unocss-config' { export type theme = any } ` diff --git a/src/runtime/nitro/og-image/chromium/renderer.ts b/src/runtime/nitro/og-image/chromium/renderer.ts index ed18f9eb..c52871dc 100644 --- a/src/runtime/nitro/og-image/chromium/renderer.ts +++ b/src/runtime/nitro/og-image/chromium/renderer.ts @@ -1,6 +1,6 @@ import type { Browser } from 'playwright-core' import type { Renderer } from '../../../types' -import { createBrowser } from '#nuxt-og-image/bindings/chromium' +import { createBrowser } from '#og-image/bindings/chromium' import { createError } from 'h3' import { createScreenshot } from './screenshot' diff --git a/src/runtime/nitro/og-image/context.ts b/src/runtime/nitro/og-image/context.ts index 4a78e7c5..cf703c59 100644 --- a/src/runtime/nitro/og-image/context.ts +++ b/src/runtime/nitro/og-image/context.ts @@ -7,7 +7,7 @@ import type { import type ChromiumRenderer from './chromium/renderer' import type SatoriRenderer from './satori/renderer' import { useNitroApp } from '#imports' -import { htmlPayloadCache, prerenderOptionsCache } from '#nuxt-og-image-cache' +import { htmlPayloadCache, prerenderOptionsCache } from '#og-image-cache' import { defu } from 'defu' import { parse } from 'devalue' import { createError, getQuery } from 'h3' diff --git a/src/runtime/nitro/og-image/instances.ts b/src/runtime/nitro/og-image/instances.ts index 3c1afec6..f0cf789a 100644 --- a/src/runtime/nitro/og-image/instances.ts +++ b/src/runtime/nitro/og-image/instances.ts @@ -7,11 +7,11 @@ const satoriRendererInstance: { instance?: typeof SatoriRenderer } = { instance: const chromiumRendererInstance: { instance?: typeof ChromiumRenderer } = { instance: undefined } export async function useSatoriRenderer() { - satoriRendererInstance.instance = satoriRendererInstance.instance || await import('#nuxt-og-image/renderers/satori').then(m => m.default) + satoriRendererInstance.instance = satoriRendererInstance.instance || await import('#og-image/renderers/satori').then(m => m.default) return satoriRendererInstance.instance! } export async function useChromiumRenderer() { - chromiumRendererInstance.instance = chromiumRendererInstance.instance || await import('#nuxt-og-image/renderers/chromium').then(m => m.default) + chromiumRendererInstance.instance = chromiumRendererInstance.instance || await import('#og-image/renderers/chromium').then(m => m.default) return chromiumRendererInstance.instance! } diff --git a/src/runtime/nitro/og-image/satori/instances.ts b/src/runtime/nitro/og-image/satori/instances.ts index 0ae72267..4d25593d 100644 --- a/src/runtime/nitro/og-image/satori/instances.ts +++ b/src/runtime/nitro/og-image/satori/instances.ts @@ -11,24 +11,24 @@ const resvgInstance: { instance?: { initWasmPromise: Promise, Resvg: typeo const satoriInstance: { instance?: { initWasmPromise: Promise, satori: typeof _satori } } = { instance: undefined } export async function useResvg() { - resvgInstance.instance = resvgInstance.instance || await import('#nuxt-og-image/bindings/resvg').then(m => m.default) + resvgInstance.instance = resvgInstance.instance || await import('#og-image/bindings/resvg').then(m => m.default) await resvgInstance.instance!.initWasmPromise return resvgInstance.instance!.Resvg } export async function useSatori() { - satoriInstance.instance = satoriInstance.instance || await import('#nuxt-og-image/bindings/satori').then(m => m.default) + satoriInstance.instance = satoriInstance.instance || await import('#og-image/bindings/satori').then(m => m.default) await satoriInstance.instance!.initWasmPromise return satoriInstance.instance!.satori } export async function useSharp() { - sharpInstance.instance = sharpInstance.instance || await import('#nuxt-og-image/bindings/sharp').then(m => m.default) + sharpInstance.instance = sharpInstance.instance || await import('#og-image/bindings/sharp').then(m => m.default) return sharpInstance.instance! } export async function useCssInline() { - cssInlineInstance.instance = cssInlineInstance.instance || await import('#nuxt-og-image/bindings/css-inline').then(m => m.default) + cssInlineInstance.instance = cssInlineInstance.instance || await import('#og-image/bindings/css-inline').then(m => m.default) await cssInlineInstance.instance!.initWasmPromise return cssInlineInstance.instance!.cssInline } diff --git a/src/runtime/nitro/og-image/satori/plugins/unocss.ts b/src/runtime/nitro/og-image/satori/plugins/unocss.ts index 2ed88091..47cd495e 100644 --- a/src/runtime/nitro/og-image/satori/plugins/unocss.ts +++ b/src/runtime/nitro/og-image/satori/plugins/unocss.ts @@ -1,5 +1,5 @@ import type { VNode } from '../../../../types' -import { theme } from '#nuxt-og-image/virtual/unocss-config.mjs' +import { theme } from '#og-image-virtual/unocss-config.mjs' import { createGenerator } from '@unocss/core' import presetWind from '@unocss/preset-wind' import { defineSatoriTransformer } from '../utils' diff --git a/src/runtime/nitro/og-image/satori/renderer.ts b/src/runtime/nitro/og-image/satori/renderer.ts index 06abbee2..db6cc2a8 100644 --- a/src/runtime/nitro/og-image/satori/renderer.ts +++ b/src/runtime/nitro/og-image/satori/renderer.ts @@ -1,7 +1,7 @@ import type { SatoriOptions } from 'satori' import type { OgImageRenderEventContext, Renderer, ResolvedFontConfig } from '../../../types' -import { theme } from '#nuxt-og-image/virtual/unocss-config.mjs' -import { fontCache } from '#nuxt-og-image-cache' +import { fontCache } from '#og-image-cache' +import { theme } from '#og-image-virtual/unocss-config.mjs' import { defu } from 'defu' import { normaliseFontInput, useOgImageRuntimeConfig } from '../../../shared' import { loadFont } from './font' @@ -15,20 +15,21 @@ async function resolveFonts(event: OgImageRenderEventContext) { const normalisedFonts = normaliseFontInput([...event.options.fonts || [], ...fonts]) const localFontPromises: Promise[] = [] const preloadedFonts: ResolvedFontConfig[] = [] - for (const font of normalisedFonts) { - if (await fontCache.hasItem(font.cacheKey)) { - font.data = await fontCache.getItemRaw(font.cacheKey) - preloadedFonts.push(font) - } - else { - if (!fontPromises[font.cacheKey]) { - fontPromises[font.cacheKey] = loadFont(event, font).then(async (_font) => { - if (_font?.data) - await fontCache.setItemRaw(_font.cacheKey, _font.data) - return _font - }) + if (fontCache) { + for (const font of normalisedFonts) { + if (await fontCache.hasItem(font.cacheKey)) { + font.data = await fontCache.getItemRaw(font.cacheKey) + preloadedFonts.push(font) + } else { + if (!fontPromises[font.cacheKey]) { + fontPromises[font.cacheKey] = loadFont(event, font).then(async (_font) => { + if (_font?.data) + await fontCache?.setItemRaw(_font.cacheKey, _font.data) + return _font + }) + } + localFontPromises.push(fontPromises[font.cacheKey]) } - localFontPromises.push(fontPromises[font.cacheKey]) } } const awaitedFonts = await Promise.all(localFontPromises) diff --git a/src/runtime/nitro/og-image/satori/transforms/emojis.ts b/src/runtime/nitro/og-image/satori/transforms/emojis.ts index 8e0fec37..8fef2ea5 100644 --- a/src/runtime/nitro/og-image/satori/transforms/emojis.ts +++ b/src/runtime/nitro/og-image/satori/transforms/emojis.ts @@ -1,6 +1,6 @@ import type { NuxtIslandResponse } from 'nuxt/dist/core/runtime/nitro/renderer' import type { OgImageRenderEventContext } from '../../../../types' -import { emojiCache } from '#nuxt-og-image-cache' +import { emojiCache } from '#og-image-cache' const charMap = { '2049': 'exclamation-question-mark', diff --git a/src/runtime/nitro/og-image/templates/html.ts b/src/runtime/nitro/og-image/templates/html.ts index 36f74cb8..aaa6c28c 100644 --- a/src/runtime/nitro/og-image/templates/html.ts +++ b/src/runtime/nitro/og-image/templates/html.ts @@ -1,5 +1,5 @@ import type { FontConfig, OgImageRenderEventContext } from '../../../types' -import { theme } from '#nuxt-og-image/virtual/unocss-config.mjs' +import { theme } from '#og-image-virtual/unocss-config.mjs' import { renderSSRHead } from '@unhead/ssr' import { createHeadCore } from '@unhead/vue' import { createError } from 'h3' diff --git a/src/runtime/nitro/plugins/prerender.ts b/src/runtime/nitro/plugins/prerender.ts index 1e18065a..3ac1df8b 100644 --- a/src/runtime/nitro/plugins/prerender.ts +++ b/src/runtime/nitro/plugins/prerender.ts @@ -1,5 +1,5 @@ import { defineNitroPlugin } from '#imports' -import { prerenderOptionsCache } from '#nuxt-og-image-cache' +import { prerenderOptionsCache } from '#og-image-cache' import { parseURL } from 'ufo' import { isInternalRoute } from '../../pure' import { extractAndNormaliseOgImageOptions, resolvePathCacheKey } from '../og-image/context' diff --git a/src/runtime/nitro/routes/debug.json.ts b/src/runtime/nitro/routes/debug.json.ts index 17348e86..11295808 100644 --- a/src/runtime/nitro/routes/debug.json.ts +++ b/src/runtime/nitro/routes/debug.json.ts @@ -1,7 +1,7 @@ // @ts-expect-error virtual module -import compatibility from '#nuxt-og-image/compatibility' +import compatibility from '#og-image/compatibility' // @ts-expect-error untyped -import { componentNames } from '#nuxt-og-image-virtual/component-names.mjs' +import { componentNames } from '#og-image-virtual/component-names.mjs' import { defineEventHandler, setHeader } from 'h3' diff --git a/src/runtime/nitro/util/options.ts b/src/runtime/nitro/util/options.ts index ef87a2c8..ddf734be 100644 --- a/src/runtime/nitro/util/options.ts +++ b/src/runtime/nitro/util/options.ts @@ -1,6 +1,6 @@ import type { DefineOgImageInput, OgImageOptions, OgImagePrebuilt } from '../../types' // @ts-expect-error untyped -import { componentNames } from '#nuxt-og-image-virtual/component-names.mjs' +import { componentNames } from '#og-image-virtual/component-names.mjs' export function normaliseOptions(_options: DefineOgImageInput): OgImageOptions | OgImagePrebuilt { const options = { ..._options } as OgImageOptions diff --git a/src/runtime/nuxt/components/Templates/Community/NuxtSeo.vue b/src/runtime/nuxt/components/Templates/Community/NuxtSeo.vue index 9a868ae5..9e6ea25c 100644 --- a/src/runtime/nuxt/components/Templates/Community/NuxtSeo.vue +++ b/src/runtime/nuxt/components/Templates/Community/NuxtSeo.vue @@ -4,7 +4,7 @@ */ import { useSiteConfig } from '#imports' -import { useOgImageRuntimeConfig } from '#nuxt-og-image/shared' +import { useOgImageRuntimeConfig } from '#og-image/shared' import { computed, defineComponent, h, resolveComponent } from 'vue' // convert to typescript props diff --git a/src/runtime/nuxt/composables/defineOgImageComponent.ts b/src/runtime/nuxt/composables/defineOgImageComponent.ts index 0fbc0a3e..1388851c 100644 --- a/src/runtime/nuxt/composables/defineOgImageComponent.ts +++ b/src/runtime/nuxt/composables/defineOgImageComponent.ts @@ -1,4 +1,4 @@ -import type { OgImageComponents } from '#nuxt-og-image/components' +import type { OgImageComponents } from '#og-image/components' import type { ExtractComponentProps, OgImageOptions } from '../../types' import { defineOgImage } from './defineOgImage' diff --git a/src/runtime/nuxt/composables/mock.ts b/src/runtime/nuxt/composables/mock.ts index 2b9e3594..3f38ef6f 100644 --- a/src/runtime/nuxt/composables/mock.ts +++ b/src/runtime/nuxt/composables/mock.ts @@ -1,4 +1,4 @@ -import type { OgImageComponents } from '#nuxt-og-image/components' +import type { OgImageComponents } from '#og-image/components' import type { DefineOgImageInput, ExtractComponentProps, OgImageOptions, OgImagePageScreenshotOptions } from '../../types' export function defineOgImage(_options: DefineOgImageInput = {}) {} diff --git a/src/runtime/types.ts b/src/runtime/types.ts index 6d42adef..5f3874ca 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -1,4 +1,4 @@ -import type { OgImageComponents } from '#nuxt-og-image/components' +import type { OgImageComponents } from '#og-image/components' import type { ResvgRenderOptions } from '@resvg/resvg-js' import type { AllowedComponentProps, Component, ComponentCustomProps, VNodeProps } from '@vue/runtime-core' import type { H3Error, H3Event } from 'h3' diff --git a/test/fixtures/zero-runtime/components/OgImage/0.NuxtSeo.vue b/test/fixtures/zero-runtime/components/OgImage/0.NuxtSeo.vue index 9a868ae5..9e6ea25c 100644 --- a/test/fixtures/zero-runtime/components/OgImage/0.NuxtSeo.vue +++ b/test/fixtures/zero-runtime/components/OgImage/0.NuxtSeo.vue @@ -4,7 +4,7 @@ */ import { useSiteConfig } from '#imports' -import { useOgImageRuntimeConfig } from '#nuxt-og-image/shared' +import { useOgImageRuntimeConfig } from '#og-image/shared' import { computed, defineComponent, h, resolveComponent } from 'vue' // convert to typescript props diff --git a/virtual.d.ts b/virtual.d.ts index 7f23a022..e377f90f 100644 --- a/virtual.d.ts +++ b/virtual.d.ts @@ -1,28 +1,28 @@ -declare module '#nuxt-og-image/components' { +declare module '#og-image/components' { import type { Component } from 'vue' const components: Record export default components } -declare module '#nuxt-og-image/renderers/satori' { +declare module '#og-image/renderers/satori' { import type Renderer from './src/runtime/types' const renderer: Renderer | { __unenv__: true } | undefined export default renderer } -declare module '#nuxt-og-image/renderers/chromium' { +declare module '#og-image/renderers/chromium' { import type Renderer from './src/runtime/types' const renderer: Renderer | { __unenv__: true } | undefined export default renderer } -declare module '#nuxt-og-image/bindings/satori' { +declare module '#og-image/bindings/satori' { const satori: typeof import('satori').satori export default satori } -declare module '#nuxt-og-image/bindings/resvg' { +declare module '#og-image/bindings/resvg' { interface WasmResvg { initWasmPromise: Promise Resvg: import('resvg').Resvg @@ -30,36 +30,35 @@ declare module '#nuxt-og-image/bindings/resvg' { const instance: WasmResvg export default instance } -declare module '#nuxt-og-image/bindings/chromium' { +declare module '#og-image/bindings/chromium' { export const createBrowser: () => Promise } -declare module '#nuxt-og-image/bindings/css-inline' { +declare module '#og-image/bindings/css-inline' { import type _CssInline from 'css-inline' const cssInline: _CssInline export default cssInline } -declare module '#nuxt-og-image/bindings/sharp' { +declare module '#og-image/bindings/sharp' { import type _sharp from 'sharp' const sharp: _sharp export default sharp } -declare module '#nuxt-og-image-virtual/component-names.mjs' { +declare module '#og-image-virtual/component-names.mjs' { const componentNames: string[] export default componentNames } -declare module '#nuxt-og-image-virtual/unocss-config.mjs' { - const theme: Record - export default theme +declare module '#og-image-virtual/unocss-config.mjs' { + export const theme: Record } -declare module '#nuxt-og-image-cache' { - import type { OgImageOptions } from '#nuxt-og-image/types' +declare module '#og-image-cache' { + import type { OgImageOptions } from '#og-image/types' import type { Storage } from 'unstorage' export const htmlPayloadCache: Storage<{ expiresAt: number, value: OgImageOptions }>