nuxt-og-image 5.1.13 → 6.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/cli.mjs +2 -0
- package/dist/chunks/tw4-classes.cjs +116 -0
- package/dist/chunks/tw4-classes.mjs +113 -0
- package/dist/chunks/tw4-generator.cjs +118 -0
- package/dist/chunks/tw4-generator.mjs +110 -0
- package/dist/cli.cjs +433 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +416 -0
- package/dist/client/200.html +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_fonts/0xp3SbCWC1OhX7q1-uF6kilMZFm-alJNkUtkLTPCy_A-tN9KwPUWhhXvtqh74sU9FIkI4W6hsbm85r0X24hjOfM.woff2 +0 -0
- package/dist/client/_fonts/1ZTlEDqU4DtwDJiND8f6qaugUpa0RIDvQl-v7iM6l54-D6hedAgqRfOCLZzaShnyeAvlEnMzk4Wm7g9WDKWFHIc.woff +0 -0
- package/dist/client/_fonts/4HA9tc4y8BVQeLXvLn3JgQqilAj1xrAnUSprQGHIPSw-ZPswEL_UDOYaxTLQDUySPjoOHDxhD83pD19HMfKfK9s.woff2 +0 -0
- package/dist/client/_fonts/Bmul3LaKlc7BUKqJHE_UmEoF40Sg_2ga52yJjwyDcKs-TnYmYl1DNYkiWMu0Vx49DakCPBuiCCj9zoLIuQjUdKY.woff2 +0 -0
- package/dist/client/_fonts/DfgmjWGpWte3Q3a54Nevr_BYmMM5YEJXRI1CdI2VwO0-ox5RadQfCyVTmKl_hubTaIJjtRw9oaQz2GDBeZR6l1M.woff2 +0 -0
- package/dist/client/_fonts/Lc_5lWuBuZcZ166p1-s-mnGkMJwIYJE_QDCkws8iCkI-r45Qbm2hCykrfOZ0kowz__uTTTUOPDN9hz34QcRNTY4.woff2 +0 -0
- package/dist/client/_fonts/iEvApgDRmzKzNqOYocBTrmcHZmuGAJloawKDP1S0nyE-T3oc_9We24QGwfw5naik4cM0g7VxylWVaQwKm4dy3cw.woff2 +0 -0
- package/dist/client/_nuxt/0kYTU2a7.js +2 -0
- package/dist/client/_nuxt/B0QDx5EE.js +2 -0
- package/dist/client/_nuxt/BKqzYw6x.js +3 -0
- package/dist/client/_nuxt/C-Ivr2Rl.js +1 -0
- package/dist/client/_nuxt/CLgn8DCr.js +1 -0
- package/dist/client/_nuxt/CwWm-XE3.js +1 -0
- package/dist/client/_nuxt/D9eL2h5z.js +1 -0
- package/dist/client/_nuxt/DJXHIJSq.js +1 -0
- package/dist/client/_nuxt/DVnX3Z-O.js +1 -0
- package/dist/client/_nuxt/DXObZt09.js +184 -0
- package/dist/client/_nuxt/Dxi6QG7I.js +1 -0
- package/dist/client/_nuxt/E8AZ6HoH.js +1 -0
- package/dist/client/_nuxt/IFrameLoader.CGrV1TpP.css +1 -0
- package/dist/client/_nuxt/JAMwWy1K.js +3864 -0
- package/dist/client/_nuxt/OSectionBlock.BVHnMsIr.css +1 -0
- package/dist/client/_nuxt/PONEy9N-.js +1 -0
- package/dist/client/_nuxt/UdkqSAsD.js +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/8e2df3bd-1df7-4172-a3c9-b46cdb9070e5.json +1 -0
- package/dist/client/_nuxt/entry.BEExJd9R.css +2 -0
- package/dist/client/_nuxt/error-404.B79WD2X-.css +1 -0
- package/dist/client/_nuxt/error-500.DT3Sd0Wu.css +1 -0
- package/dist/client/_nuxt/pages.eW3hi7XF.css +1 -0
- package/dist/client/_nuxt/templates.dUiUBaip.css +1 -0
- package/dist/client/_payload.json +1 -0
- package/dist/client/debug/_payload.json +1 -0
- package/dist/client/debug/index.html +1 -0
- package/dist/client/docs/_payload.json +1 -0
- package/dist/client/docs/index.html +1 -0
- package/dist/client/fonts/HubotSans-Regular.woff2 +0 -0
- package/dist/client/index.html +1 -1
- package/dist/client/templates/_payload.json +1 -0
- package/dist/client/templates/index.html +1 -0
- package/dist/module.cjs +36 -1027
- package/dist/module.d.cts +63 -25
- package/dist/module.d.mts +63 -25
- package/dist/module.d.ts +63 -25
- package/dist/module.json +1 -1
- package/dist/module.mjs +32 -1009
- package/dist/runtime/app/components/Templates/Community/Brutalist.satori.d.vue.ts +14 -0
- package/dist/runtime/app/components/Templates/Community/Brutalist.satori.vue +51 -0
- package/dist/runtime/app/components/Templates/Community/Brutalist.satori.vue.d.ts +14 -0
- package/dist/runtime/app/components/Templates/Community/{Frame.vue.d.ts → Frame.satori.d.vue.ts} +2 -2
- package/dist/runtime/app/components/Templates/Community/Frame.satori.vue +71 -0
- package/dist/runtime/app/components/Templates/Community/{Frame.d.vue.ts → Frame.satori.vue.d.ts} +2 -2
- package/dist/runtime/app/components/Templates/Community/Newspaper.satori.d.vue.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/Newspaper.satori.vue +70 -0
- package/dist/runtime/app/components/Templates/Community/Newspaper.satori.vue.d.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/Nuxt.satori.d.vue.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/{Nuxt.vue → Nuxt.satori.vue} +3 -3
- package/dist/runtime/app/components/Templates/Community/Nuxt.satori.vue.d.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/NuxtSeo.satori.d.vue.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/NuxtSeo.satori.vue +69 -0
- package/dist/runtime/app/components/Templates/Community/NuxtSeo.satori.vue.d.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/Pergel.satori.d.vue.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/{Pergel.vue → Pergel.satori.vue} +14 -11
- package/dist/runtime/app/components/Templates/Community/Pergel.satori.vue.d.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/Retro.satori.d.vue.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/Retro.satori.vue +64 -0
- package/dist/runtime/app/components/Templates/Community/Retro.satori.vue.d.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/SaaS.satori.d.vue.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/SaaS.satori.vue +60 -0
- package/dist/runtime/app/components/Templates/Community/SaaS.satori.vue.d.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/SimpleBlog.satori.d.vue.ts +9 -0
- package/dist/runtime/app/components/Templates/Community/SimpleBlog.satori.vue +38 -0
- package/dist/runtime/app/components/Templates/Community/SimpleBlog.satori.vue.d.ts +9 -0
- package/dist/runtime/app/components/Templates/Community/{UnJs.d.vue.ts → UnJs.satori.d.vue.ts} +2 -2
- package/dist/runtime/app/components/Templates/Community/{UnJs.vue → UnJs.satori.vue} +41 -33
- package/dist/runtime/app/components/Templates/Community/{UnJs.vue.d.ts → UnJs.satori.vue.d.ts} +2 -2
- package/dist/runtime/app/components/Templates/Community/WithEmoji.satori.d.vue.ts +13 -0
- package/dist/runtime/app/components/Templates/Community/WithEmoji.satori.vue +27 -0
- package/dist/runtime/app/components/Templates/Community/WithEmoji.satori.vue.d.ts +13 -0
- package/dist/runtime/app/composables/_defineOgImageRaw.d.ts +6 -0
- package/dist/runtime/app/composables/_defineOgImageRaw.js +70 -0
- package/dist/runtime/app/composables/defineOgImage.d.ts +14 -2
- package/dist/runtime/app/composables/defineOgImage.js +13 -42
- package/dist/runtime/app/composables/defineOgImageComponent.d.ts +5 -1
- package/dist/runtime/app/composables/defineOgImageComponent.js +4 -5
- package/dist/runtime/app/composables/defineOgImageScreenshot.d.ts +1 -1
- package/dist/runtime/app/composables/defineOgImageScreenshot.js +2 -2
- package/dist/runtime/app/composables/mock.d.ts +7 -4
- package/dist/runtime/app/composables/mock.js +4 -4
- package/dist/runtime/app/utils/plugins.js +22 -28
- package/dist/runtime/app/utils.d.ts +15 -1
- package/dist/runtime/app/utils.js +74 -46
- package/dist/runtime/pure.d.ts +7 -0
- package/dist/runtime/pure.js +105 -0
- package/dist/runtime/server/og-image/bindings/css-inline/wasm-fs.d.ts +3 -2
- package/dist/runtime/server/og-image/bindings/css-inline/wasm.d.ts +3 -2
- package/dist/runtime/server/og-image/bindings/font-assets/cloudflare.d.ts +3 -0
- package/dist/runtime/server/og-image/bindings/font-assets/cloudflare.js +22 -0
- package/dist/runtime/server/og-image/bindings/font-assets/dev-prerender.d.ts +3 -0
- package/dist/runtime/server/og-image/bindings/font-assets/dev-prerender.js +49 -0
- package/dist/runtime/server/og-image/bindings/font-assets/node.d.ts +3 -0
- package/dist/runtime/server/og-image/bindings/font-assets/node.js +14 -0
- package/dist/runtime/server/og-image/bindings/resvg/node-dev.d.ts +5 -0
- package/dist/runtime/server/og-image/bindings/resvg/node-dev.js +70 -0
- package/dist/runtime/server/og-image/bindings/takumi/node.d.ts +6 -0
- package/dist/runtime/server/og-image/bindings/takumi/node.js +5 -0
- package/dist/runtime/server/og-image/bindings/takumi/wasm.d.ts +6 -0
- package/dist/runtime/server/og-image/bindings/takumi/wasm.js +6 -0
- package/dist/runtime/server/og-image/cache/buildCache.d.ts +16 -0
- package/dist/runtime/server/og-image/cache/buildCache.js +48 -0
- package/dist/runtime/server/og-image/cache/lru.d.ts +2 -2
- package/dist/runtime/server/og-image/cache/lru.js +3 -3
- package/dist/runtime/server/og-image/cache/mock.d.ts +1 -2
- package/dist/runtime/server/og-image/cache/mock.js +0 -1
- package/dist/runtime/server/og-image/chromium/screenshot.js +4 -3
- package/dist/runtime/server/og-image/context.d.ts +2 -3
- package/dist/runtime/server/og-image/context.js +55 -193
- package/dist/runtime/server/og-image/devtools.d.ts +10 -0
- package/dist/runtime/server/og-image/devtools.js +74 -0
- package/dist/runtime/server/og-image/fonts.d.ts +6 -0
- package/dist/runtime/server/og-image/fonts.js +41 -0
- package/dist/runtime/server/og-image/instances.d.ts +1 -0
- package/dist/runtime/server/og-image/instances.js +5 -0
- package/dist/runtime/server/og-image/satori/instances.d.ts +1 -36
- package/dist/runtime/server/og-image/satori/plugins/emojis.js +83 -4
- package/dist/runtime/server/og-image/satori/plugins/encoding.js +11 -1
- package/dist/runtime/server/og-image/satori/plugins/imageSrc.js +5 -1
- package/dist/runtime/server/og-image/satori/plugins/twClasses.js +35 -0
- package/dist/runtime/server/og-image/satori/renderer.js +16 -53
- package/dist/runtime/server/og-image/satori/transforms/emojis/emoji-names-minimal.d.ts +1 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis/emoji-names-minimal.js +223 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis/emoji-utils.d.ts +45 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis/emoji-utils.js +13 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis/fetch.d.ts +6 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis/fetch.js +38 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis/index.d.ts +7 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis/index.js +64 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis/local.d.ts +7 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis/local.js +32 -0
- package/dist/runtime/server/og-image/satori/utils.js +5 -4
- package/dist/runtime/server/og-image/satori/vnodes.js +7 -6
- package/dist/runtime/server/og-image/takumi/instances.d.ts +1 -0
- package/dist/runtime/server/og-image/takumi/instances.js +6 -0
- package/dist/runtime/server/og-image/takumi/nodes.d.ts +12 -0
- package/dist/runtime/server/og-image/takumi/nodes.js +86 -0
- package/dist/runtime/server/og-image/takumi/renderer.d.ts +3 -0
- package/dist/runtime/server/og-image/takumi/renderer.js +45 -0
- package/dist/runtime/server/og-image/templates/html.js +32 -23
- package/dist/runtime/server/plugins/prerender.d.ts +1 -1
- package/dist/runtime/server/plugins/prerender.js +17 -7
- package/dist/runtime/server/util/auto-eject.d.ts +2 -0
- package/dist/runtime/server/util/auto-eject.js +30 -0
- package/dist/runtime/server/util/eventHandlers.d.ts +0 -1
- package/dist/runtime/server/util/eventHandlers.js +15 -85
- package/dist/runtime/server/util/options.d.ts +7 -2
- package/dist/runtime/server/util/options.js +40 -6
- package/dist/runtime/server/utils.d.ts +6 -2
- package/dist/runtime/server/utils.js +12 -8
- package/dist/runtime/shared/urlEncoding.d.ts +64 -0
- package/dist/runtime/shared/urlEncoding.js +194 -0
- package/dist/runtime/shared.d.ts +4 -9
- package/dist/runtime/shared.js +31 -50
- package/dist/runtime/types.d.ts +71 -25
- package/dist/shared/nuxt-og-image.D-QhzI76.mjs +2831 -0
- package/dist/shared/nuxt-og-image.iluFGbPR.cjs +2858 -0
- package/dist/types.d.mts +2 -0
- package/package.json +108 -44
- package/types/virtual.d.ts +7 -1
- package/dist/client/_nuxt/B3LgXoKV.js +0 -2
- package/dist/client/_nuxt/B8PEiB0p.js +0 -1
- package/dist/client/_nuxt/CPsbVDfV.js +0 -1
- package/dist/client/_nuxt/CVO1_9PV.js +0 -1
- package/dist/client/_nuxt/CjQm5wk3.js +0 -4029
- package/dist/client/_nuxt/Cp-IABpG.js +0 -1
- package/dist/client/_nuxt/D0TMZt8T.js +0 -1
- package/dist/client/_nuxt/D0r3Knsf.js +0 -1
- package/dist/client/_nuxt/builds/meta/eb2c0390-3125-4af7-b189-e76a7dfe3017.json +0 -1
- package/dist/client/_nuxt/entry.cdy4VsCK.css +0 -1
- package/dist/client/_nuxt/error-404.Cu4JbXd7.css +0 -1
- package/dist/client/_nuxt/error-500.B79uceR7.css +0 -1
- package/dist/runtime/app/components/OgImage/OgImage.d.ts +0 -3
- package/dist/runtime/app/components/OgImage/OgImage.js +0 -10
- package/dist/runtime/app/components/Templates/Community/BrandedLogo.d.vue.ts +0 -13
- package/dist/runtime/app/components/Templates/Community/BrandedLogo.vue +0 -22
- package/dist/runtime/app/components/Templates/Community/BrandedLogo.vue.d.ts +0 -13
- package/dist/runtime/app/components/Templates/Community/Frame.vue +0 -58
- package/dist/runtime/app/components/Templates/Community/Nuxt.d.vue.ts +0 -12
- package/dist/runtime/app/components/Templates/Community/Nuxt.vue.d.ts +0 -12
- package/dist/runtime/app/components/Templates/Community/NuxtSeo.d.vue.ts +0 -15
- package/dist/runtime/app/components/Templates/Community/NuxtSeo.vue +0 -103
- package/dist/runtime/app/components/Templates/Community/NuxtSeo.vue.d.ts +0 -15
- package/dist/runtime/app/components/Templates/Community/Pergel.d.vue.ts +0 -12
- package/dist/runtime/app/components/Templates/Community/Pergel.vue.d.ts +0 -12
- package/dist/runtime/app/components/Templates/Community/SimpleBlog.d.vue.ts +0 -9
- package/dist/runtime/app/components/Templates/Community/SimpleBlog.vue +0 -27
- package/dist/runtime/app/components/Templates/Community/SimpleBlog.vue.d.ts +0 -9
- package/dist/runtime/app/components/Templates/Community/Wave.d.vue.ts +0 -11
- package/dist/runtime/app/components/Templates/Community/Wave.vue +0 -28
- package/dist/runtime/app/components/Templates/Community/Wave.vue.d.ts +0 -11
- package/dist/runtime/app/components/Templates/Community/WithEmoji.d.vue.ts +0 -13
- package/dist/runtime/app/components/Templates/Community/WithEmoji.vue +0 -21
- package/dist/runtime/app/components/Templates/Community/WithEmoji.vue.d.ts +0 -13
- package/dist/runtime/assets/Inter-normal-400.ttf.base64 +0 -1
- package/dist/runtime/assets/Inter-normal-700.ttf.base64 +0 -1
- package/dist/runtime/server/og-image/satori/font.d.ts +0 -3
- package/dist/runtime/server/og-image/satori/font.js +0 -40
- package/dist/runtime/server/og-image/satori/plugins/unocss.js +0 -55
- package/dist/runtime/server/og-image/satori/transforms/emojis.d.ts +0 -3
- package/dist/runtime/server/og-image/satori/transforms/emojis.js +0 -3595
- package/dist/runtime/server/plugins/__zero-runtime/nuxt-content-v2.d.ts +0 -2
- package/dist/runtime/server/plugins/__zero-runtime/nuxt-content-v2.js +0 -9
- package/dist/runtime/server/plugins/nuxt-content-v2.d.ts +0 -2
- package/dist/runtime/server/plugins/nuxt-content-v2.js +0 -5
- package/dist/runtime/server/routes/__zero-runtime/font.d.ts +0 -2
- package/dist/runtime/server/routes/__zero-runtime/font.js +0 -8
- package/dist/runtime/server/routes/font.d.ts +0 -2
- package/dist/runtime/server/routes/font.js +0 -3
- package/dist/runtime/server/util/plugins.d.ts +0 -2
- package/dist/runtime/server/util/plugins.js +0 -56
- /package/dist/runtime/server/og-image/satori/plugins/{unocss.d.ts → twClasses.d.ts} +0 -0
|
@@ -2,13 +2,11 @@ import { useRequestEvent } from "#app";
|
|
|
2
2
|
import { withSiteUrl } from "#site-config/app/composables";
|
|
3
3
|
import { TemplateParamsPlugin } from "@unhead/vue/plugins";
|
|
4
4
|
import { defu } from "defu";
|
|
5
|
-
import { parse, stringify } from "devalue";
|
|
6
5
|
import { createRouter as createRadixRouter, toRouteMatcher } from "radix3";
|
|
7
6
|
import { parseURL, withoutBase } from "ufo";
|
|
8
7
|
import { toValue } from "vue";
|
|
9
|
-
import { createOgImageMeta } from "../../app/utils.js";
|
|
10
|
-
import { isInternalRoute
|
|
11
|
-
import { getOgImagePath } from "../utils.js";
|
|
8
|
+
import { createOgImageMeta, getOgImagePath } from "../../app/utils.js";
|
|
9
|
+
import { isInternalRoute } from "../../shared.js";
|
|
12
10
|
export function ogImageCanonicalUrls(nuxtApp) {
|
|
13
11
|
nuxtApp.hooks.hook("app:rendered", async (ctx) => {
|
|
14
12
|
const { ssrContext } = ctx;
|
|
@@ -20,38 +18,33 @@ export function ogImageCanonicalUrls(nuxtApp) {
|
|
|
20
18
|
ssrContext?.head.use({
|
|
21
19
|
key: "nuxt-og-image:overrides-and-canonical-urls",
|
|
22
20
|
hooks: {
|
|
23
|
-
"tags:
|
|
24
|
-
|
|
25
|
-
let
|
|
21
|
+
"tags:afterResolve": async (ctx2) => {
|
|
22
|
+
let title = "";
|
|
23
|
+
let description = "";
|
|
26
24
|
for (const tag of ctx2.tags) {
|
|
27
|
-
if (tag.tag === "
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} else {
|
|
32
|
-
tag.props.id = "nuxt-og-image-options";
|
|
33
|
-
tag.innerHTML = stringify(separateProps(parse(tag.innerHTML || "{}")));
|
|
34
|
-
tag._d = "script:id:nuxt-og-image-options";
|
|
35
|
-
}
|
|
36
|
-
break;
|
|
25
|
+
if (tag.tag === "title" && tag.textContent) {
|
|
26
|
+
title = tag.textContent;
|
|
27
|
+
} else if (tag.tag === "meta" && tag.props.name === "description") {
|
|
28
|
+
description = tag.props.content || "";
|
|
37
29
|
}
|
|
30
|
+
if (title && description)
|
|
31
|
+
break;
|
|
38
32
|
}
|
|
39
|
-
ctx2.tags = ctx2.tags.filter(Boolean);
|
|
40
33
|
for (const tag of ctx2.tags) {
|
|
41
34
|
if (tag.tag === "meta" && (tag.props.property === "og:image" || ["twitter:image:src", "twitter:image"].includes(tag.props.name || ""))) {
|
|
42
35
|
if (!tag.props.content) {
|
|
43
36
|
tag.props = {};
|
|
44
37
|
continue;
|
|
45
38
|
}
|
|
39
|
+
tag.props.content = tag.props.content.replaceAll("%title", title).replaceAll("%description", description).replaceAll(" ", "+");
|
|
46
40
|
if (!tag.props.content?.startsWith("https")) {
|
|
47
41
|
await nuxtApp.runWithContext(() => {
|
|
48
42
|
tag.props.content = toValue(withSiteUrl(tag.props.content || "", {
|
|
49
|
-
withBase: true
|
|
43
|
+
withBase: true,
|
|
44
|
+
canonical: !import.meta.dev
|
|
50
45
|
}));
|
|
51
46
|
});
|
|
52
47
|
}
|
|
53
|
-
} else if (overrides && tag.tag === "script" && tag.props.id === "nuxt-og-image-options") {
|
|
54
|
-
tag.innerHTML = stringify(defu(overrides, parse(tag.innerHTML || "{}")));
|
|
55
48
|
}
|
|
56
49
|
}
|
|
57
50
|
}
|
|
@@ -76,17 +69,18 @@ export function routeRuleOgImage(nuxtApp) {
|
|
|
76
69
|
let routeRules = combinedRules?.ogImage;
|
|
77
70
|
if (typeof routeRules === "undefined")
|
|
78
71
|
return;
|
|
79
|
-
const ogImageInstances = nuxtApp.ssrContext._ogImageInstances || [];
|
|
80
72
|
if (routeRules === false) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
nuxtApp.ssrContext.
|
|
85
|
-
nuxtApp.ssrContext._ogImageInstances = void 0;
|
|
73
|
+
nuxtApp.ssrContext._ogImageInstance?.dispose();
|
|
74
|
+
nuxtApp.ssrContext._ogImageDevtoolsInstance?.dispose();
|
|
75
|
+
nuxtApp.ssrContext._ogImageInstance = void 0;
|
|
76
|
+
nuxtApp.ssrContext._ogImagePayloads = [];
|
|
86
77
|
return;
|
|
87
78
|
}
|
|
88
79
|
routeRules = defu(nuxtApp.ssrContext?.event?.context._nitro?.routeRules?.ogImage, routeRules);
|
|
89
|
-
const src = getOgImagePath(ssrContext.url, routeRules);
|
|
80
|
+
const { path: src, hash } = getOgImagePath(ssrContext.url, routeRules);
|
|
81
|
+
if (hash) {
|
|
82
|
+
routeRules._hash = hash;
|
|
83
|
+
}
|
|
90
84
|
createOgImageMeta(src, routeRules, nuxtApp.ssrContext);
|
|
91
85
|
});
|
|
92
86
|
}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
import type { ActiveHeadEntry, Head } from '@unhead/vue';
|
|
1
2
|
import type { NuxtSSRContext } from 'nuxt/app';
|
|
2
3
|
import type { OgImageOptions, OgImagePrebuilt, OgImageRuntimeConfig } from '../types.js';
|
|
4
|
+
type OgImagePayload = [string, OgImageOptions, Required<Head>['meta']];
|
|
5
|
+
declare module 'nuxt/app' {
|
|
6
|
+
interface NuxtSSRContext {
|
|
7
|
+
_ogImagePayloads?: OgImagePayload[];
|
|
8
|
+
_ogImageInstance?: ActiveHeadEntry<Head>;
|
|
9
|
+
_ogImageDevtoolsInstance?: ActiveHeadEntry<Head>;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
3
12
|
export declare function setHeadOgImagePrebuilt(input: OgImagePrebuilt): void;
|
|
4
13
|
export declare function createOgImageMeta(src: string, input: OgImageOptions | OgImagePrebuilt, ssrContext: NuxtSSRContext): void;
|
|
5
14
|
export declare function resolveComponentName(component: OgImageOptions['component'], fallback: string): OgImageOptions['component'];
|
|
6
|
-
export
|
|
15
|
+
export interface GetOgImagePathResult {
|
|
16
|
+
path: string;
|
|
17
|
+
hash?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function getOgImagePath(_pagePath: string, _options?: Partial<OgImageOptions>): GetOgImagePathResult;
|
|
7
20
|
export declare function useOgImageRuntimeConfig(): OgImageRuntimeConfig;
|
|
21
|
+
export {};
|
|
@@ -4,7 +4,7 @@ import { defu } from "defu";
|
|
|
4
4
|
import { stringify } from "devalue";
|
|
5
5
|
import { useHead, useRuntimeConfig } from "nuxt/app";
|
|
6
6
|
import { joinURL, withQuery } from "ufo";
|
|
7
|
-
import { generateMeta, separateProps } from "../shared.js";
|
|
7
|
+
import { buildOgImageUrl, generateMeta, separateProps } from "../shared.js";
|
|
8
8
|
export function setHeadOgImagePrebuilt(input) {
|
|
9
9
|
if (import.meta.client) {
|
|
10
10
|
return;
|
|
@@ -20,67 +20,95 @@ export function createOgImageMeta(src, input, ssrContext) {
|
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
const { defaults } = useOgImageRuntimeConfig();
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
payload.component = resolveComponentName(input.component, defaults.component || "");
|
|
39
|
-
delete payload.url;
|
|
40
|
-
if (payload._query && Object.keys(payload._query).length === 0) {
|
|
41
|
-
delete payload._query;
|
|
42
|
-
}
|
|
43
|
-
const final = {};
|
|
44
|
-
for (const k in payload) {
|
|
45
|
-
if (payload[k] !== defaults[k]) {
|
|
46
|
-
final[k] = payload[k];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return stringify(final);
|
|
50
|
-
},
|
|
51
|
-
// we want this to be last in our head
|
|
52
|
-
tagPosition: "bodyClose"
|
|
53
|
-
});
|
|
23
|
+
const resolvedOptions = separateProps(defu(input, defaults));
|
|
24
|
+
resolvedOptions.key = resolvedOptions.key || "og";
|
|
25
|
+
const payloads = ssrContext._ogImagePayloads || [];
|
|
26
|
+
const currentPayloadIdx = payloads.findIndex(([k]) => k === resolvedOptions.key);
|
|
27
|
+
const _input = separateProps(defu(input, currentPayloadIdx >= 0 ? payloads[currentPayloadIdx][1] : {}));
|
|
28
|
+
let url = src || input.url || resolvedOptions.url;
|
|
29
|
+
if (!url)
|
|
30
|
+
return;
|
|
31
|
+
if (input._query && Object.keys(input._query).length && url)
|
|
32
|
+
url = withQuery(url, { _query: input._query });
|
|
33
|
+
const meta = generateMeta(url, resolvedOptions);
|
|
34
|
+
if (currentPayloadIdx === -1) {
|
|
35
|
+
payloads.push([resolvedOptions.key, _input, meta]);
|
|
36
|
+
} else {
|
|
37
|
+
payloads[currentPayloadIdx] = [resolvedOptions.key, _input, meta];
|
|
54
38
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
meta
|
|
39
|
+
ssrContext._ogImageInstance?.dispose();
|
|
40
|
+
ssrContext._ogImageInstance = useHead({
|
|
41
|
+
meta() {
|
|
42
|
+
const finalPayload = ssrContext._ogImagePayloads || [];
|
|
43
|
+
return finalPayload.flatMap(([_, __, meta2]) => meta2);
|
|
44
|
+
}
|
|
58
45
|
}, {
|
|
59
|
-
|
|
46
|
+
processTemplateParams: true,
|
|
47
|
+
tagPriority: 35
|
|
60
48
|
});
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
if (import.meta.dev || import.meta.prerender) {
|
|
50
|
+
ssrContext._ogImageDevtoolsInstance?.dispose();
|
|
51
|
+
ssrContext._ogImageDevtoolsInstance = useHead({
|
|
52
|
+
script: [{
|
|
53
|
+
id: "nuxt-og-image-options",
|
|
54
|
+
type: "application/json",
|
|
55
|
+
processTemplateParams: true,
|
|
56
|
+
innerHTML: () => {
|
|
57
|
+
const devtoolsPayload = (ssrContext._ogImagePayloads || []).map(([key, options]) => {
|
|
58
|
+
const payload = resolveUnrefHeadInput(options);
|
|
59
|
+
if (payload.props && typeof payload.props.title === "undefined")
|
|
60
|
+
payload.props.title = "%s";
|
|
61
|
+
payload.component = resolveComponentName(options.component, defaults.component || "");
|
|
62
|
+
payload.key = key;
|
|
63
|
+
delete payload.url;
|
|
64
|
+
if (payload._query && Object.keys(payload._query).length === 0) {
|
|
65
|
+
delete payload._query;
|
|
66
|
+
}
|
|
67
|
+
const final = {};
|
|
68
|
+
for (const k in payload) {
|
|
69
|
+
if (payload[k] !== defaults[k]) {
|
|
70
|
+
final[k] = payload[k];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return final;
|
|
74
|
+
});
|
|
75
|
+
return stringify(devtoolsPayload);
|
|
76
|
+
},
|
|
77
|
+
tagPosition: "bodyClose"
|
|
78
|
+
}]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
ssrContext._ogImagePayloads = payloads;
|
|
63
82
|
}
|
|
64
83
|
export function resolveComponentName(component, fallback) {
|
|
65
84
|
component = component || fallback || componentNames?.[0]?.pascalName;
|
|
66
85
|
if (component && componentNames) {
|
|
67
86
|
const originalName = component;
|
|
68
87
|
for (const component2 of componentNames) {
|
|
69
|
-
|
|
88
|
+
const basePascalName = component2.pascalName.replace(/(Satori|Chromium|Takumi)$/, "");
|
|
89
|
+
const baseKebabName = component2.kebabName.replace(/-(satori|chromium|takumi)$/, "");
|
|
90
|
+
if (basePascalName.endsWith(originalName) || baseKebabName.endsWith(originalName)) {
|
|
70
91
|
return component2.pascalName;
|
|
71
92
|
}
|
|
72
93
|
}
|
|
73
94
|
}
|
|
74
95
|
return component;
|
|
75
96
|
}
|
|
76
|
-
export function getOgImagePath(
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
97
|
+
export function getOgImagePath(_pagePath, _options) {
|
|
98
|
+
const runtimeConfig = useRuntimeConfig();
|
|
99
|
+
const baseURL = runtimeConfig.app.baseURL;
|
|
100
|
+
const { defaults } = useOgImageRuntimeConfig();
|
|
101
|
+
const extension = _options?.extension || defaults?.extension || "png";
|
|
102
|
+
const isStatic = import.meta.prerender;
|
|
103
|
+
const result = buildOgImageUrl({ ..._options, _path: _pagePath }, extension, isStatic, defaults);
|
|
104
|
+
let path = joinURL("/", baseURL, result.url);
|
|
105
|
+
if (!isStatic && runtimeConfig.app.buildId) {
|
|
106
|
+
path = withQuery(path, { _v: runtimeConfig.app.buildId });
|
|
82
107
|
}
|
|
83
|
-
return
|
|
108
|
+
return {
|
|
109
|
+
path,
|
|
110
|
+
hash: result.hash
|
|
111
|
+
};
|
|
84
112
|
}
|
|
85
113
|
export function useOgImageRuntimeConfig() {
|
|
86
114
|
const c = useRuntimeConfig();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DevToolsMetaDataExtraction, OgImageOptions } from './types.js';
|
|
2
|
+
export declare function extractSocialPreviewTags(html: string): [Record<string, string>, DevToolsMetaDataExtraction[]];
|
|
3
|
+
export declare function toBase64Image(data: string | ArrayBuffer): string;
|
|
4
|
+
export declare function isInternalRoute(path: string): boolean;
|
|
5
|
+
export declare function separateProps(options: OgImageOptions | undefined, ignoreKeys?: string[]): OgImageOptions;
|
|
6
|
+
export declare function withoutQuery(path: string): string | undefined;
|
|
7
|
+
export declare function getExtension(path: string): string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { defu } from "defu";
|
|
2
|
+
export function extractSocialPreviewTags(html) {
|
|
3
|
+
const data = [];
|
|
4
|
+
const rootData = {};
|
|
5
|
+
const socialMetaTags = html.match(/<meta[^>]+(property|name)="(twitter|og):([^"]+)"[^>]*>/g) || [];
|
|
6
|
+
let currentArrayIdx = -1;
|
|
7
|
+
socialMetaTags.forEach((tag) => {
|
|
8
|
+
const [, , type, key] = tag.match(/(property|name)="(twitter|og):([^"]+)"/);
|
|
9
|
+
const value = tag.match(/content="([^"]+)"/)?.[1];
|
|
10
|
+
if (!value) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (key === "title" || key === "description") {
|
|
14
|
+
rootData[`${type}:${key}`] = value;
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (type === "og" && key === "image") {
|
|
18
|
+
currentArrayIdx++;
|
|
19
|
+
}
|
|
20
|
+
if (!data[currentArrayIdx])
|
|
21
|
+
data[currentArrayIdx] = {};
|
|
22
|
+
if (!data[currentArrayIdx][type])
|
|
23
|
+
data[currentArrayIdx][type] = {};
|
|
24
|
+
data[currentArrayIdx][type][key] = value;
|
|
25
|
+
});
|
|
26
|
+
data.forEach((preview) => {
|
|
27
|
+
if (preview.og?.image && preview.og?.image.includes("/_og/")) {
|
|
28
|
+
const url = withoutQuery(preview.og.image);
|
|
29
|
+
const keyMatch = url.match(/[,/]k_([^,./]+)/);
|
|
30
|
+
preview.key = keyMatch?.[1] || "og";
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return [rootData, data];
|
|
34
|
+
}
|
|
35
|
+
function detectBase64MimeType(data) {
|
|
36
|
+
const signatures = {
|
|
37
|
+
"R0lGODdh": "image/gif",
|
|
38
|
+
"R0lGODlh": "image/gif",
|
|
39
|
+
"iVBORw0KGgo": "image/png",
|
|
40
|
+
"/9j/": "image/jpeg",
|
|
41
|
+
"UklGR": "image/webp",
|
|
42
|
+
"AAABAA": "image/x-icon"
|
|
43
|
+
};
|
|
44
|
+
for (const s in signatures) {
|
|
45
|
+
if (data.startsWith(s)) {
|
|
46
|
+
return signatures[s];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return "image/svg+xml";
|
|
50
|
+
}
|
|
51
|
+
export function toBase64Image(data) {
|
|
52
|
+
const base64 = typeof data === "string" ? data : Buffer.from(data).toString("base64");
|
|
53
|
+
const type = detectBase64MimeType(base64);
|
|
54
|
+
return `data:${type};base64,${base64}`;
|
|
55
|
+
}
|
|
56
|
+
export function isInternalRoute(path) {
|
|
57
|
+
return path.startsWith("/_") || path.startsWith("@");
|
|
58
|
+
}
|
|
59
|
+
function filterIsOgImageOption(key) {
|
|
60
|
+
const keys = [
|
|
61
|
+
"url",
|
|
62
|
+
"extension",
|
|
63
|
+
"width",
|
|
64
|
+
"height",
|
|
65
|
+
"alt",
|
|
66
|
+
"props",
|
|
67
|
+
"renderer",
|
|
68
|
+
// internal use only (screenshots)
|
|
69
|
+
"html",
|
|
70
|
+
"component",
|
|
71
|
+
"emojis",
|
|
72
|
+
"_query",
|
|
73
|
+
"satori",
|
|
74
|
+
"resvg",
|
|
75
|
+
"sharp",
|
|
76
|
+
"screenshot",
|
|
77
|
+
"cacheMaxAgeSeconds",
|
|
78
|
+
"key"
|
|
79
|
+
];
|
|
80
|
+
return keys.includes(key);
|
|
81
|
+
}
|
|
82
|
+
export function separateProps(options, ignoreKeys = []) {
|
|
83
|
+
options = options || {};
|
|
84
|
+
const _props = defu(options.props, Object.fromEntries(
|
|
85
|
+
Object.entries({ ...options }).filter(([k]) => !filterIsOgImageOption(k) && !ignoreKeys.includes(k))
|
|
86
|
+
));
|
|
87
|
+
const props = {};
|
|
88
|
+
Object.entries(_props).forEach(([key, val]) => {
|
|
89
|
+
props[key.replace(/-([a-z])/g, (g) => g[1].toUpperCase())] = val;
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
...Object.fromEntries(
|
|
93
|
+
Object.entries({ ...options }).filter(([k]) => filterIsOgImageOption(k) || ignoreKeys.includes(k))
|
|
94
|
+
),
|
|
95
|
+
props
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function withoutQuery(path) {
|
|
99
|
+
return path.split("?")[0];
|
|
100
|
+
}
|
|
101
|
+
export function getExtension(path) {
|
|
102
|
+
path = withoutQuery(path);
|
|
103
|
+
const lastSegment = path.split("/").pop() || path;
|
|
104
|
+
return lastSegment.split(".").pop() || lastSegment;
|
|
105
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getNitroOrigin } from "#site-config/server/composables";
|
|
2
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
+
import { withBase } from "ufo";
|
|
4
|
+
export async function resolve(event, font) {
|
|
5
|
+
const path = font.src || font.localPath;
|
|
6
|
+
const assets = event.context.cloudflare?.env?.ASSETS || event.context.ASSETS;
|
|
7
|
+
if (!assets) {
|
|
8
|
+
throw new Error("Cloudflare ASSETS binding not available");
|
|
9
|
+
}
|
|
10
|
+
const { app } = useRuntimeConfig();
|
|
11
|
+
const fullPath = withBase(path, app.baseURL);
|
|
12
|
+
const origin = getNitroOrigin(event);
|
|
13
|
+
const res = await assets.fetch(new URL(fullPath, origin).href).catch(() => null);
|
|
14
|
+
if (res?.ok) {
|
|
15
|
+
return Buffer.from(await res.arrayBuffer());
|
|
16
|
+
}
|
|
17
|
+
const publicRes = await fetch(new URL(fullPath, origin).href);
|
|
18
|
+
if (publicRes.ok) {
|
|
19
|
+
return Buffer.from(await publicRes.arrayBuffer());
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`[Nuxt OG Image] Failed to resolve public assets: ${path}`);
|
|
22
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { buildDir } from "#og-image-virtual/build-dir.mjs";
|
|
4
|
+
import { getNitroOrigin } from "#site-config/server/composables";
|
|
5
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
6
|
+
import { withBase } from "ufo";
|
|
7
|
+
let fontUrlMapping;
|
|
8
|
+
async function loadFontUrlMapping() {
|
|
9
|
+
if (fontUrlMapping)
|
|
10
|
+
return fontUrlMapping;
|
|
11
|
+
const content = await readFile(join(buildDir, "cache", "og-image", "font-urls.json"), "utf-8").catch(() => null);
|
|
12
|
+
fontUrlMapping = content ? JSON.parse(content) : {};
|
|
13
|
+
return fontUrlMapping;
|
|
14
|
+
}
|
|
15
|
+
function getRootDir() {
|
|
16
|
+
const idx = buildDir.indexOf("/.nuxt");
|
|
17
|
+
return idx !== -1 ? buildDir.slice(0, idx) : process.cwd();
|
|
18
|
+
}
|
|
19
|
+
export async function resolve(event, font) {
|
|
20
|
+
const path = font.src || font.localPath;
|
|
21
|
+
const rootDir = getRootDir();
|
|
22
|
+
if (import.meta.prerender) {
|
|
23
|
+
if (path.startsWith("/_fonts/")) {
|
|
24
|
+
const filename2 = path.slice("/_fonts/".length);
|
|
25
|
+
const cached = await readFile(join(buildDir, "cache", "fonts", filename2)).catch(() => null) || await readFile(join(rootDir, ".output", "public", "_fonts", filename2)).catch(() => null);
|
|
26
|
+
if (cached?.length)
|
|
27
|
+
return cached;
|
|
28
|
+
const mapping = await loadFontUrlMapping();
|
|
29
|
+
if (mapping[filename2]) {
|
|
30
|
+
const res = await fetch(mapping[filename2]).catch(() => null);
|
|
31
|
+
if (res?.ok)
|
|
32
|
+
return Buffer.from(await res.arrayBuffer());
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`Font ${filename2} not found in mapping or cache`);
|
|
35
|
+
}
|
|
36
|
+
const filename = path.slice(1);
|
|
37
|
+
const data = await readFile(join(rootDir, "public", filename)).catch(() => null) || await readFile(join(rootDir, ".output", "public", filename)).catch(() => null);
|
|
38
|
+
if (data?.length)
|
|
39
|
+
return data;
|
|
40
|
+
throw new Error(`Font ${filename} not found in public directory`);
|
|
41
|
+
}
|
|
42
|
+
const { app } = useRuntimeConfig();
|
|
43
|
+
const fullPath = withBase(path, app.baseURL);
|
|
44
|
+
const arrayBuffer = await $fetch(fullPath, {
|
|
45
|
+
responseType: "arrayBuffer",
|
|
46
|
+
baseURL: getNitroOrigin(event)
|
|
47
|
+
});
|
|
48
|
+
return Buffer.from(arrayBuffer);
|
|
49
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getNitroOrigin } from "#site-config/server/composables";
|
|
2
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
+
import { withBase } from "ufo";
|
|
4
|
+
export async function resolve(event, font) {
|
|
5
|
+
const path = font.src || font.localPath;
|
|
6
|
+
const { app } = useRuntimeConfig();
|
|
7
|
+
const fullPath = withBase(path, app.baseURL);
|
|
8
|
+
const origin = getNitroOrigin(event);
|
|
9
|
+
const res = await fetch(new URL(fullPath, origin).href);
|
|
10
|
+
if (res.ok) {
|
|
11
|
+
return Buffer.from(await res.arrayBuffer());
|
|
12
|
+
}
|
|
13
|
+
throw new Error(`[Nuxt OG Image] Failed to resolve font: ${path}`);
|
|
14
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Worker } from "node:worker_threads";
|
|
2
|
+
const workerCode = `
|
|
3
|
+
const { parentPort } = require('node:worker_threads')
|
|
4
|
+
const { Resvg } = require('@resvg/resvg-js')
|
|
5
|
+
|
|
6
|
+
parentPort.on('message', ({ id, svg, options }) => {
|
|
7
|
+
const resvg = new Resvg(svg, options)
|
|
8
|
+
const png = resvg.render().asPng()
|
|
9
|
+
parentPort.postMessage({ id, png })
|
|
10
|
+
})
|
|
11
|
+
`;
|
|
12
|
+
let worker = null;
|
|
13
|
+
let requestId = 0;
|
|
14
|
+
const pending = /* @__PURE__ */ new Map();
|
|
15
|
+
function createWorker() {
|
|
16
|
+
const w = new Worker(workerCode, { eval: true });
|
|
17
|
+
w.on("message", ({ id, png }) => {
|
|
18
|
+
const p = pending.get(id);
|
|
19
|
+
if (p) {
|
|
20
|
+
pending.delete(id);
|
|
21
|
+
p.resolve(Buffer.from(png));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
w.on("error", (err) => {
|
|
25
|
+
for (const [id, p] of pending) {
|
|
26
|
+
pending.delete(id);
|
|
27
|
+
p.reject(err);
|
|
28
|
+
}
|
|
29
|
+
worker = null;
|
|
30
|
+
});
|
|
31
|
+
w.on("exit", (code) => {
|
|
32
|
+
if (code !== 0) {
|
|
33
|
+
for (const [id, p] of pending) {
|
|
34
|
+
pending.delete(id);
|
|
35
|
+
p.reject(new Error(`Resvg worker exited with code ${code}`));
|
|
36
|
+
}
|
|
37
|
+
worker = null;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return w;
|
|
41
|
+
}
|
|
42
|
+
function renderPng(svg, options) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
if (!worker)
|
|
45
|
+
worker = createWorker();
|
|
46
|
+
const id = ++requestId;
|
|
47
|
+
pending.set(id, { resolve, reject });
|
|
48
|
+
worker.postMessage({ id, svg, options });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
class ResvgWorkerProxy {
|
|
52
|
+
svg;
|
|
53
|
+
options;
|
|
54
|
+
pngPromise = null;
|
|
55
|
+
constructor(svg, options) {
|
|
56
|
+
this.svg = svg;
|
|
57
|
+
this.options = options;
|
|
58
|
+
}
|
|
59
|
+
render() {
|
|
60
|
+
if (!this.pngPromise)
|
|
61
|
+
this.pngPromise = renderPng(this.svg, this.options);
|
|
62
|
+
return {
|
|
63
|
+
asPng: () => this.pngPromise
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export default {
|
|
68
|
+
initWasmPromise: Promise.resolve(),
|
|
69
|
+
Resvg: ResvgWorkerProxy
|
|
70
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the component hash for a given component name
|
|
3
|
+
*/
|
|
4
|
+
export declare function getComponentHash(componentName: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Generate a cache key that includes options, component hash, and version
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateBuildCacheKey(options: Record<string, any>, extension: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Check if an image exists in the build cache
|
|
11
|
+
*/
|
|
12
|
+
export declare function getBuildCachedImage(options: Record<string, any>, extension: string): Buffer | null;
|
|
13
|
+
/**
|
|
14
|
+
* Save an image to the build cache
|
|
15
|
+
*/
|
|
16
|
+
export declare function setBuildCachedImage(options: Record<string, any>, extension: string, data: Buffer | Uint8Array, maxAgeSeconds: number): void;
|