nuxt-og-image 3.0.0-beta.3 → 3.0.0-beta.30
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 +3 -3
- package/dist/client/200.html +5 -5
- package/dist/client/404.html +5 -5
- package/dist/client/_nuxt/{IconCSS.e8427024.js → IconCSS.157c2ef5.js} +1 -1
- package/dist/client/_nuxt/IconCSS.7e8f1f7b.css +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/2f3b82b2-c809-4818-a70e-0a9fa0dde8cb.json +1 -0
- package/dist/client/_nuxt/entry.74866e06.js +137 -0
- package/dist/client/_nuxt/entry.f47d0628.css +1 -0
- package/dist/client/_nuxt/{error-404.b1c8e4c8.js → error-404.d663cd65.js} +1 -1
- package/dist/client/_nuxt/{error-500.6b97e3ab.js → error-500.8c184504.js} +1 -1
- package/dist/client/index.html +5 -5
- package/dist/module.d.mts +43 -25
- package/dist/module.d.ts +43 -25
- package/dist/module.json +2 -2
- package/dist/module.mjs +146 -93
- package/dist/runtime/cache.d.ts +7 -10
- package/dist/runtime/cache.mjs +40 -27
- package/dist/runtime/components/OgImage/OgImage.d.ts +5 -0
- package/dist/runtime/components/OgImage/{index.mjs → OgImage.mjs} +1 -1
- package/dist/runtime/components/OgImage/OgImageScreenshot.d.ts +5 -0
- package/dist/runtime/components/OgImage/{Screenshot.mjs → OgImageScreenshot.mjs} +1 -1
- package/dist/runtime/components/Templates/{Official → Community}/BrandedLogo.vue +3 -2
- package/dist/runtime/components/Templates/Community/Nuxt.vue +6 -5
- package/dist/runtime/components/Templates/Community/NuxtSeo.vue +137 -0
- package/dist/runtime/components/Templates/{Official → Community}/SimpleBlog.vue +7 -5
- package/dist/runtime/components/Templates/Community/UnJs.vue +108 -0
- package/dist/runtime/components/Templates/{Official → Community}/Wave.vue +3 -2
- package/dist/runtime/components/Templates/{Official → Community}/WithEmoji.vue +3 -2
- package/dist/runtime/composables/defineOgImage.d.ts +2 -23
- package/dist/runtime/composables/defineOgImage.mjs +33 -116
- package/dist/runtime/composables/defineOgImageComponent.d.ts +3 -0
- package/dist/runtime/composables/defineOgImageComponent.mjs +8 -0
- package/dist/runtime/composables/defineOgImageScreenshot.d.ts +2 -0
- package/dist/runtime/composables/defineOgImageScreenshot.mjs +14 -0
- package/dist/runtime/core/bindings/css-inline/node.d.ts +2 -5
- package/dist/runtime/core/bindings/css-inline/node.mjs +2 -10
- package/dist/runtime/core/bindings/resvg/wasm.mjs +2 -3
- package/dist/runtime/core/bindings/satori/wasm.mjs +7 -0
- package/dist/runtime/core/cache/emojis.d.ts +1 -0
- package/dist/runtime/core/cache/emojis.mjs +5 -0
- package/dist/runtime/core/cache/htmlPayload.d.ts +5 -0
- package/dist/runtime/core/cache/htmlPayload.mjs +6 -0
- package/dist/runtime/core/cache/prerender.d.ts +1 -1
- package/dist/runtime/core/font/fetch.d.ts +2 -3
- package/dist/runtime/core/font/fetch.mjs +20 -8
- package/dist/runtime/core/html/applyEmojis.d.ts +3 -0
- package/dist/runtime/core/html/applyEmojis.mjs +37 -0
- package/dist/runtime/core/html/applyInlineCss.d.ts +3 -0
- package/dist/runtime/core/html/applyInlineCss.mjs +32 -0
- package/dist/runtime/core/html/devIframeTemplate.d.ts +2 -0
- package/dist/runtime/core/html/{fetch.mjs → devIframeTemplate.mjs} +33 -42
- package/dist/runtime/core/html/fetchIsland.d.ts +3 -0
- package/dist/runtime/core/html/fetchIsland.mjs +17 -0
- package/dist/runtime/core/options/fetch.d.ts +1 -1
- package/dist/runtime/core/options/fetch.mjs +10 -5
- package/dist/runtime/core/options/normalise.d.ts +2 -2
- package/dist/runtime/core/options/normalise.mjs +3 -2
- package/dist/runtime/core/renderers/chromium/index.mjs +6 -7
- package/dist/runtime/core/renderers/chromium/screenshot.d.ts +2 -3
- package/dist/runtime/core/renderers/chromium/screenshot.mjs +5 -4
- package/dist/runtime/core/renderers/satori/fonts.d.ts +2 -2
- package/dist/runtime/core/renderers/satori/fonts.mjs +2 -2
- package/dist/runtime/core/renderers/satori/index.d.ts +2 -3
- package/dist/runtime/core/renderers/satori/index.mjs +25 -22
- package/dist/runtime/core/renderers/satori/instances.d.ts +3 -0
- package/dist/runtime/core/renderers/satori/instances.mjs +15 -0
- package/dist/runtime/core/renderers/satori/plugins/emojis.mjs +15 -13
- package/dist/runtime/core/renderers/satori/plugins/imageSrc.mjs +8 -4
- package/dist/runtime/core/renderers/satori/plugins/unocss.d.ts +2 -0
- package/dist/runtime/core/renderers/satori/plugins/unocss.mjs +38 -0
- package/dist/runtime/core/renderers/satori/utils.d.ts +2 -3
- package/dist/runtime/core/renderers/satori/vnodes.d.ts +2 -3
- package/dist/runtime/core/renderers/satori/vnodes.mjs +16 -6
- package/dist/runtime/core/utils/resolveRendererContext.d.ts +2 -6
- package/dist/runtime/core/utils/resolveRendererContext.mjs +46 -23
- package/dist/runtime/core/utils/wasm.d.ts +1 -0
- package/dist/runtime/core/utils/wasm.mjs +10 -0
- package/dist/runtime/nitro/plugins/nuxt-content.mjs +3 -4
- package/dist/runtime/nitro/plugins/prerender.d.ts +1 -1
- package/dist/runtime/nitro/plugins/prerender.mjs +13 -5
- package/dist/runtime/nuxt/plugins/og-image-canonical-urls.server.mjs +31 -0
- package/dist/runtime/nuxt/plugins/route-rule-og-image.server.mjs +16 -50
- package/dist/runtime/nuxt/utils.d.ts +2 -0
- package/dist/runtime/nuxt/utils.mjs +53 -0
- package/dist/runtime/server/routes/__og-image__/debug.json.d.ts +1 -3
- package/dist/runtime/server/routes/__og-image__/debug.json.mjs +4 -8
- package/dist/runtime/server/routes/__og-image__/image.mjs +87 -0
- package/dist/runtime/types.d.ts +74 -25
- package/dist/runtime/utils.d.ts +4 -0
- package/dist/runtime/utils.mjs +11 -0
- package/dist/runtime/utils.pure.d.ts +5 -0
- package/dist/runtime/utils.pure.mjs +43 -0
- package/package.json +27 -29
- package/virtual.d.ts +49 -0
- package/dist/client/_nuxt/IconCSS.8f429b14.css +0 -1
- package/dist/client/_nuxt/builds/meta/af7b6f15-8224-4a19-bb3a-f685b2b145c3.json +0 -1
- package/dist/client/_nuxt/entry.434c2c45.css +0 -1
- package/dist/client/_nuxt/entry.8ea61ef1.js +0 -137
- package/dist/client/grid.png +0 -0
- package/dist/runtime/components/OgImage/Cached.d.ts +0 -5
- package/dist/runtime/components/OgImage/Cached.mjs +0 -10
- package/dist/runtime/components/OgImage/Dynamic.d.ts +0 -8
- package/dist/runtime/components/OgImage/Dynamic.mjs +0 -10
- package/dist/runtime/components/OgImage/Screenshot.d.ts +0 -6
- package/dist/runtime/components/OgImage/Static.d.ts +0 -8
- package/dist/runtime/components/OgImage/Static.mjs +0 -10
- package/dist/runtime/components/OgImage/WithoutCache.d.ts +0 -5
- package/dist/runtime/components/OgImage/WithoutCache.mjs +0 -10
- package/dist/runtime/components/OgImage/index.d.ts +0 -5
- package/dist/runtime/components/Templates/Official/Fallback.vue +0 -147
- package/dist/runtime/core/bindings/css-inline/mock.d.ts +0 -5
- package/dist/runtime/core/bindings/css-inline/mock.mjs +0 -3
- package/dist/runtime/core/bindings/satori/yoga-wasm.mjs +0 -7
- package/dist/runtime/core/bindings/sharp/wasm.d.ts +0 -2
- package/dist/runtime/core/bindings/sharp/wasm.mjs +0 -2
- package/dist/runtime/core/html/fetch.d.ts +0 -3
- package/dist/runtime/nuxt/plugins/nuxt-content-canonical-urls.mjs +0 -29
- package/dist/runtime/server/routes/__og-image__/image-[path]-og.[extension].mjs +0 -45
- package/dist/runtime/utilts.d.ts +0 -2
- package/dist/runtime/utilts.mjs +0 -8
- /package/dist/runtime/core/bindings/satori/{yoga-wasm.d.ts → wasm.d.ts} +0 -0
- /package/dist/runtime/nuxt/plugins/{nuxt-content-canonical-urls.d.ts → og-image-canonical-urls.server.d.ts} +0 -0
- /package/dist/runtime/server/routes/__og-image__/{image-[path]-og.[extension].d.ts → image.d.ts} +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
|
+
import { createError } from "h3";
|
|
2
3
|
import { base64ToArrayBuffer } from "../env/assets.mjs";
|
|
3
4
|
import { fontCache } from "./cache.mjs";
|
|
4
5
|
import { useNitroOrigin, useStorage } from "#imports";
|
|
5
|
-
export async function loadFont(e, font) {
|
|
6
|
+
export async function loadFont({ e }, font) {
|
|
6
7
|
const fontKey = `${font.name}:${font.weight}`;
|
|
7
8
|
const storageKey = `assets:nuxt-og-image:font:${fontKey}`;
|
|
8
9
|
if (fontCache[fontKey])
|
|
@@ -13,17 +14,28 @@ export async function loadFont(e, font) {
|
|
|
13
14
|
data = base64ToArrayBuffer(await useStorage().getItem(storageKey));
|
|
14
15
|
if (!data) {
|
|
15
16
|
if (font.path) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
if (import.meta.prerender) {
|
|
18
|
+
const key = `root:public${font.path.replace("./", ":").replace("/", ":")}`;
|
|
19
|
+
data = await useStorage().getItemRaw(key);
|
|
20
|
+
} else {
|
|
21
|
+
data = await e.$fetch(font.path, {
|
|
22
|
+
baseURL: useNitroOrigin(e),
|
|
23
|
+
responseType: "arrayBuffer"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
20
26
|
} else {
|
|
21
27
|
data = await e.$fetch(`/__og-image__/font/${name}/${weight}.ttf`, {
|
|
22
28
|
responseType: "arrayBuffer"
|
|
23
29
|
});
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
if (data) {
|
|
33
|
+
fontCache[fontKey] = { name, weight: Number(weight), data, style: "normal" };
|
|
34
|
+
await useStorage().setItem(storageKey, Buffer.from(data).toString("base64"));
|
|
35
|
+
return fontCache[fontKey];
|
|
36
|
+
}
|
|
37
|
+
return createError({
|
|
38
|
+
statusCode: 500,
|
|
39
|
+
statusMessage: `Failed to fetch font: ${fontKey}`
|
|
40
|
+
});
|
|
29
41
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import defaultCharMap from "@iconify-json/noto/chars.json";
|
|
2
|
+
import { emojiCache } from "../cache/emojis.mjs";
|
|
3
|
+
const RE_MATCH_EMOJIS = /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC2\uDECE-\uDEDB\uDEE0-\uDEE8]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
|
|
4
|
+
export async function applyEmojis(ctx, island) {
|
|
5
|
+
const html = island.html;
|
|
6
|
+
const matches = html.match(RE_MATCH_EMOJIS);
|
|
7
|
+
if (!matches)
|
|
8
|
+
return html;
|
|
9
|
+
const replacements = await Promise.all(matches.map(async (match) => {
|
|
10
|
+
const unicode = match.codePointAt(0).toString(16);
|
|
11
|
+
const emoji = defaultCharMap[unicode];
|
|
12
|
+
if (emoji) {
|
|
13
|
+
const key = ["1", ctx.options.emojis, emoji].join(":");
|
|
14
|
+
let svg;
|
|
15
|
+
if (await emojiCache.hasItem(key))
|
|
16
|
+
svg = await emojiCache.getItem(key);
|
|
17
|
+
if (!svg) {
|
|
18
|
+
svg = await ctx.e.$fetch(`https://api.iconify.design/${ctx.options.emojis}/${emoji}.svg`, {
|
|
19
|
+
responseType: "text"
|
|
20
|
+
});
|
|
21
|
+
if (svg === "404")
|
|
22
|
+
svg = void 0;
|
|
23
|
+
if (svg)
|
|
24
|
+
await emojiCache.setItem(key, svg);
|
|
25
|
+
}
|
|
26
|
+
if (svg)
|
|
27
|
+
return `
|
|
28
|
+
${svg.replace("<svg ", '<svg data-emoji style="margin: 0 .05em 0 .15em; vertical-align: -0.1em;" ')}
|
|
29
|
+
`;
|
|
30
|
+
return match;
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
const finalHtml = html.replace(RE_MATCH_EMOJIS, () => replacements.shift());
|
|
34
|
+
const modified = finalHtml !== island.html;
|
|
35
|
+
island.html = finalHtml;
|
|
36
|
+
return modified;
|
|
37
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useCssInline } from "../renderers/satori/instances.mjs";
|
|
2
|
+
import { useNitroOrigin } from "#imports";
|
|
3
|
+
import cssInline from "#nuxt-og-image/bindings/css-inline";
|
|
4
|
+
export async function applyInlineCss({ e }, island) {
|
|
5
|
+
let html = island.html;
|
|
6
|
+
const componentInlineStyles = island.head.link.filter((l) => l.href.startsWith("/_nuxt/components"));
|
|
7
|
+
const usingInlineCss = !!componentInlineStyles.length;
|
|
8
|
+
if (!cssInline.__unenv__ && componentInlineStyles.length) {
|
|
9
|
+
const css = island.head.style.map((s) => s.innerHTML).join("\n");
|
|
10
|
+
const linksToCss = (await Promise.all(
|
|
11
|
+
componentInlineStyles.map((l) => {
|
|
12
|
+
return e.$fetch(`${l.href}&hmr=false`, {
|
|
13
|
+
responseType: "text",
|
|
14
|
+
baseURL: useNitroOrigin(e)
|
|
15
|
+
}).then((res) => {
|
|
16
|
+
return res.trim().split("\n").filter((l2) => !l2.startsWith("//")).join("\n").trim();
|
|
17
|
+
});
|
|
18
|
+
})
|
|
19
|
+
)).join("\n");
|
|
20
|
+
const cssToInline = `${linksToCss}${css}`;
|
|
21
|
+
const cssInline2 = await useCssInline();
|
|
22
|
+
html = cssInline2.inline(island.html, {
|
|
23
|
+
load_remote_stylesheets: false,
|
|
24
|
+
extra_css: cssToInline
|
|
25
|
+
});
|
|
26
|
+
const classes = cssToInline.match(/\.([a-zA-Z0-9-_]+)/g)?.map((c) => c.replace(".", ""));
|
|
27
|
+
if (classes)
|
|
28
|
+
html = html.replace(new RegExp(`class="(${classes.join("|")})"`, "g"), "");
|
|
29
|
+
island.html = html;
|
|
30
|
+
}
|
|
31
|
+
return usingInlineCss;
|
|
32
|
+
}
|
|
@@ -1,37 +1,21 @@
|
|
|
1
|
-
import { createError } from "h3";
|
|
2
|
-
import { hash } from "ohash";
|
|
3
1
|
import { createHeadCore } from "@unhead/vue";
|
|
4
|
-
import twemoji from "twemoji";
|
|
5
2
|
import { renderSSRHead } from "@unhead/ssr";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
const hashId = hash([options.component, options, Math.random() * 100]);
|
|
16
|
-
const island = await e.$fetch(`/__nuxt_island/${options.component}_${hashId}.json`, {
|
|
17
|
-
params: {
|
|
18
|
-
props: JSON.stringify(options)
|
|
19
|
-
}
|
|
20
|
-
});
|
|
3
|
+
import { useOgImageRuntimeConfig } from "../../utils.mjs";
|
|
4
|
+
import { applyEmojis } from "./applyEmojis.mjs";
|
|
5
|
+
import { fetchIsland } from "./fetchIsland.mjs";
|
|
6
|
+
import { theme } from "#nuxt-og-image/unocss-config.mjs";
|
|
7
|
+
export async function devIframeTemplate(ctx) {
|
|
8
|
+
const { options } = ctx;
|
|
9
|
+
const { fonts } = useOgImageRuntimeConfig();
|
|
10
|
+
const island = await fetchIsland(ctx);
|
|
21
11
|
const head = createHeadCore();
|
|
22
12
|
head.push(island.head);
|
|
23
13
|
let defaultFontFamily = "sans-serif";
|
|
24
14
|
const firstFont = fonts[0];
|
|
25
15
|
if (firstFont)
|
|
26
16
|
defaultFontFamily = firstFont.name;
|
|
17
|
+
await applyEmojis(ctx, island);
|
|
27
18
|
let html = island.html;
|
|
28
|
-
try {
|
|
29
|
-
html = twemoji.parse(html, {
|
|
30
|
-
folder: "svg",
|
|
31
|
-
ext: ".svg"
|
|
32
|
-
});
|
|
33
|
-
} catch (e2) {
|
|
34
|
-
}
|
|
35
19
|
const googleFonts = {};
|
|
36
20
|
fonts.filter((font) => !font.path).forEach((font) => {
|
|
37
21
|
if (!googleFonts[font.name])
|
|
@@ -46,21 +30,23 @@ export async function fetchHTML(e, options) {
|
|
|
46
30
|
},
|
|
47
31
|
{
|
|
48
32
|
innerHTML: `body {
|
|
49
|
-
transform: scale(${options.scale || 1});
|
|
33
|
+
transform: scale(${options.props.scale || 1});
|
|
50
34
|
transform-origin: top left;
|
|
51
35
|
max-height: 100vh;
|
|
52
36
|
position: relative;
|
|
53
37
|
width: ${options.width}px;
|
|
54
38
|
height: ${options.height}px;
|
|
55
39
|
overflow: hidden;
|
|
56
|
-
background-color: ${options.
|
|
40
|
+
background-color: ${options.props.colorMode === "dark" ? "#1b1b1b" : "#fff"};
|
|
41
|
+
}
|
|
42
|
+
div {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
}
|
|
46
|
+
svg[data-emoji] {
|
|
47
|
+
display: inline-block;
|
|
57
48
|
}
|
|
58
|
-
|
|
59
|
-
height: 1em;
|
|
60
|
-
width: 1em;
|
|
61
|
-
margin: 0 .05em 0 .1em;
|
|
62
|
-
vertical-align: -0.1em;
|
|
63
|
-
}`
|
|
49
|
+
`
|
|
64
50
|
},
|
|
65
51
|
...fonts.filter((font) => font.path).map((font) => {
|
|
66
52
|
return `
|
|
@@ -80,15 +66,20 @@ img.emoji {
|
|
|
80
66
|
],
|
|
81
67
|
script: [
|
|
82
68
|
{
|
|
83
|
-
src: "https://cdn.
|
|
69
|
+
src: "https://cdn.jsdelivr.net/npm/@unocss/runtime/preset-wind.global.js"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
innerHTML: `
|
|
73
|
+
window.__unocss = {
|
|
74
|
+
theme: ${JSON.stringify(theme)},
|
|
75
|
+
presets: [
|
|
76
|
+
() => window.__unocss_runtime.presets.presetWind(),
|
|
77
|
+
],
|
|
78
|
+
}
|
|
79
|
+
`
|
|
84
80
|
},
|
|
85
81
|
{
|
|
86
|
-
|
|
87
|
-
corePlugins: {
|
|
88
|
-
preflight: false,
|
|
89
|
-
},
|
|
90
|
-
theme: ${JSON.stringify(satoriOptions?.tailwindConfig?.theme || {})}
|
|
91
|
-
}`
|
|
82
|
+
src: "https://cdn.jsdelivr.net/npm/@unocss/runtime/core.global.js"
|
|
92
83
|
}
|
|
93
84
|
],
|
|
94
85
|
link: [
|
|
@@ -98,6 +89,7 @@ img.emoji {
|
|
|
98
89
|
rel: "stylesheet"
|
|
99
90
|
},
|
|
100
91
|
// have to add each weight as their own stylesheet
|
|
92
|
+
// we should use the local font file no?
|
|
101
93
|
...Object.entries(googleFonts).map(([name, fonts2]) => {
|
|
102
94
|
return {
|
|
103
95
|
href: `https://fonts.googleapis.com/css2?family=${name}:wght@${fonts2.map((f) => f.weight).join(";")}&display=swap`,
|
|
@@ -108,10 +100,9 @@ img.emoji {
|
|
|
108
100
|
});
|
|
109
101
|
html = html.replaceAll(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "");
|
|
110
102
|
const headChunk = await renderSSRHead(head);
|
|
111
|
-
|
|
103
|
+
return `<!DOCTYPE html>
|
|
112
104
|
<html ${headChunk.htmlAttrs}>
|
|
113
105
|
<head>${headChunk.headTags}</head>
|
|
114
106
|
<body ${headChunk.bodyAttrs}>${headChunk.bodyTagsOpen}<div data-v-inspector-ignore="true" style="position: relative; display: flex; margin: 0 auto; width: ${options.width}px; height: ${options.height}px; overflow: hidden;">${html}</div>${headChunk.bodyTags}</body>
|
|
115
107
|
</html>`;
|
|
116
|
-
return htmlTemplate;
|
|
117
108
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createError } from "h3";
|
|
2
|
+
import { hash } from "ohash";
|
|
3
|
+
export function fetchIsland({ options, e }) {
|
|
4
|
+
if (!options.component) {
|
|
5
|
+
throw createError({
|
|
6
|
+
statusCode: 500,
|
|
7
|
+
statusMessage: `Nuxt OG Image trying to render an invalid component. Received options ${JSON.stringify(options)}`
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
const hashId = hash([options.component, options]);
|
|
11
|
+
const props = typeof options.props !== "undefined" ? options.props : options;
|
|
12
|
+
return e.$fetch(`/__nuxt_island/${options.component}_${hashId}.json`, {
|
|
13
|
+
params: {
|
|
14
|
+
props: JSON.stringify(props)
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type H3Error, type H3Event } from 'h3';
|
|
2
2
|
import type { OgImageOptions } from '../../types';
|
|
3
|
-
export declare function fetchPathHtmlAndExtractOptions(e: H3Event, path: string): Promise<H3Error | OgImageOptions>;
|
|
3
|
+
export declare function fetchPathHtmlAndExtractOptions(e: H3Event, path: string, key: string): Promise<H3Error | OgImageOptions>;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { createError } from "h3";
|
|
2
|
+
import { htmlPayloadCache } from "../cache/htmlPayload.mjs";
|
|
2
3
|
import { extractAndNormaliseOgImageOptions } from "./extract.mjs";
|
|
3
|
-
export async function fetchPathHtmlAndExtractOptions(e, path) {
|
|
4
|
+
export async function fetchPathHtmlAndExtractOptions(e, path, key) {
|
|
5
|
+
const cachedHtmlPayload = await htmlPayloadCache.getItem(key);
|
|
6
|
+
if (cachedHtmlPayload && cachedHtmlPayload.expiresAt < Date.now())
|
|
7
|
+
return cachedHtmlPayload.value;
|
|
4
8
|
let html;
|
|
5
9
|
try {
|
|
6
10
|
html = await e.$fetch(path);
|
|
@@ -11,10 +15,11 @@ export async function fetchPathHtmlAndExtractOptions(e, path) {
|
|
|
11
15
|
});
|
|
12
16
|
}
|
|
13
17
|
const payload = extractAndNormaliseOgImageOptions(html);
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
if (payload) {
|
|
19
|
+
await htmlPayloadCache.setItem(key, {
|
|
20
|
+
// 60 minutes for prerender, 10 seconds for runtime
|
|
21
|
+
expiresAt: Date.now() + 1e3 * (import.meta.prerender ? 60 * 60 : 10),
|
|
22
|
+
value: payload
|
|
18
23
|
});
|
|
19
24
|
}
|
|
20
25
|
return payload;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { OgImageOptions } from '../../types';
|
|
2
|
-
export declare function normaliseOptions(_options:
|
|
1
|
+
import type { DefineOgImageInput, OgImageOptions, OgImagePrebuilt } from '../../types';
|
|
2
|
+
export declare function normaliseOptions(_options: DefineOgImageInput): OgImageOptions | OgImagePrebuilt;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useOgImageRuntimeConfig } from "../../utils.mjs";
|
|
2
|
+
import { unref } from "#imports";
|
|
2
3
|
import { componentNames } from "#build/og-image-component-names.mjs";
|
|
3
4
|
export function normaliseOptions(_options) {
|
|
4
|
-
const { runtimeSatori } =
|
|
5
|
+
const { runtimeSatori } = useOgImageRuntimeConfig();
|
|
5
6
|
const options = { ...unref(_options) };
|
|
6
7
|
if (options.static)
|
|
7
8
|
options.cache = options.cache || options.static;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { getOgImagePath } from "../../../utilts.mjs";
|
|
2
1
|
import { prerenderChromiumContext } from "../../cache/prerender.mjs";
|
|
3
2
|
import { createScreenshot } from "./screenshot.mjs";
|
|
4
3
|
import { createBrowser } from "#nuxt-og-image/bindings/chromium";
|
|
5
4
|
const ChromiumRenderer = {
|
|
6
5
|
name: "chromium",
|
|
7
|
-
supportedFormats: ["png", "jpeg"],
|
|
8
|
-
async
|
|
6
|
+
supportedFormats: ["png", "jpeg", "jpg"],
|
|
7
|
+
async debug() {
|
|
8
|
+
return {};
|
|
9
|
+
},
|
|
10
|
+
async createImage(ctx) {
|
|
9
11
|
const browser = (import.meta.prerender ? prerenderChromiumContext.browser : null) || await createBrowser();
|
|
10
12
|
if (!browser) {
|
|
11
13
|
return createError({
|
|
@@ -15,10 +17,7 @@ const ChromiumRenderer = {
|
|
|
15
17
|
}
|
|
16
18
|
if (import.meta.prerender)
|
|
17
19
|
prerenderChromiumContext.browser = browser;
|
|
18
|
-
return createScreenshot(
|
|
19
|
-
...options,
|
|
20
|
-
path: options.component === "PageScreenshot" ? options.path : getOgImagePath(options.path, "html")
|
|
21
|
-
}).finally(async () => {
|
|
20
|
+
return createScreenshot(ctx, browser).finally(async () => {
|
|
22
21
|
await browser.close();
|
|
23
22
|
});
|
|
24
23
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Buffer } from 'node:buffer';
|
|
3
3
|
import type { Browser } from 'playwright-core';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
export declare function createScreenshot(e: H3Event, browser: Browser, options: RendererOptions): Promise<Buffer>;
|
|
4
|
+
import type { H3EventOgImageRender } from '../../../types';
|
|
5
|
+
export declare function createScreenshot({ basePath, e, options, extension }: H3EventOgImageRender, browser: Browser): Promise<Buffer>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { withQuery } from "ufo";
|
|
1
|
+
import { joinURL, withQuery } from "ufo";
|
|
2
2
|
import { useNitroOrigin } from "#imports";
|
|
3
|
-
export async function createScreenshot(e,
|
|
3
|
+
export async function createScreenshot({ basePath, e, options, extension }, browser) {
|
|
4
|
+
const path = options.component === "PageScreenshot" ? options.path : joinURL("/__og-image__/image", basePath, `og.html`);
|
|
4
5
|
const page = await browser.newPage({
|
|
5
6
|
colorScheme: options.colorScheme,
|
|
6
7
|
baseURL: useNitroOrigin(e)
|
|
@@ -23,7 +24,7 @@ export async function createScreenshot(e, browser, options) {
|
|
|
23
24
|
}, html);
|
|
24
25
|
await page.waitForLoadState("networkidle");
|
|
25
26
|
} else {
|
|
26
|
-
await page.goto(withQuery(
|
|
27
|
+
await page.goto(withQuery(path, options.props), {
|
|
27
28
|
timeout: 1e4,
|
|
28
29
|
waitUntil: "networkidle"
|
|
29
30
|
});
|
|
@@ -31,7 +32,7 @@ export async function createScreenshot(e, browser, options) {
|
|
|
31
32
|
const screenshotOptions = {
|
|
32
33
|
timeout: 1e4,
|
|
33
34
|
animations: "disabled",
|
|
34
|
-
type:
|
|
35
|
+
type: extension === "png" ? "png" : "jpeg"
|
|
35
36
|
};
|
|
36
37
|
if (options.mask) {
|
|
37
38
|
await page.evaluate((mask) => {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { FontConfig } from '../../../types';
|
|
1
|
+
import type { FontConfig, H3EventOgImageRender } from '../../../types';
|
|
2
2
|
export declare const satoriFonts: any[];
|
|
3
|
-
export declare function loadFonts(
|
|
3
|
+
export declare function loadFonts(e: H3EventOgImageRender, fonts: FontConfig[]): Promise<any>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { loadFont } from "../../font/fetch.mjs";
|
|
2
2
|
export const satoriFonts = [];
|
|
3
3
|
let fontLoadPromise = null;
|
|
4
|
-
export function loadFonts(
|
|
4
|
+
export function loadFonts(e, fonts) {
|
|
5
5
|
if (fontLoadPromise)
|
|
6
6
|
return fontLoadPromise;
|
|
7
|
-
return fontLoadPromise = Promise.all(fonts.map((font) => loadFont(
|
|
7
|
+
return fontLoadPromise = Promise.all(fonts.map((font) => loadFont(e, font)));
|
|
8
8
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare function createSvg(e: H3Event, options: RendererOptions): Promise<string>;
|
|
1
|
+
import type { H3EventOgImageRender, Renderer } from '../../../types';
|
|
2
|
+
export declare function createSvg(event: H3EventOgImageRender): Promise<string>;
|
|
4
3
|
declare const SatoriRenderer: Renderer;
|
|
5
4
|
export default SatoriRenderer;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
|
+
import { useOgImageRuntimeConfig } from "../../../utils.mjs";
|
|
2
3
|
import { createVNodes } from "./vnodes.mjs";
|
|
3
4
|
import { loadFonts, satoriFonts } from "./fonts.mjs";
|
|
4
5
|
import { useResvg, useSatori, useSharp } from "./instances.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const { fonts, satoriOptions } =
|
|
8
|
-
const vnodes = await createVNodes(
|
|
6
|
+
export async function createSvg(event) {
|
|
7
|
+
const { options } = event;
|
|
8
|
+
const { fonts, satoriOptions } = useOgImageRuntimeConfig();
|
|
9
|
+
const vnodes = await createVNodes(event);
|
|
9
10
|
if (!satoriFonts.length)
|
|
10
|
-
satoriFonts.push(...await loadFonts(
|
|
11
|
+
satoriFonts.push(...await loadFonts(event, fonts));
|
|
11
12
|
const satori = await useSatori();
|
|
12
13
|
return satori(vnodes, defu(options.satori, satoriOptions, {
|
|
13
14
|
fonts: satoriFonts,
|
|
@@ -16,38 +17,40 @@ export async function createSvg(e, options) {
|
|
|
16
17
|
height: options.height
|
|
17
18
|
}));
|
|
18
19
|
}
|
|
19
|
-
async function createPng(
|
|
20
|
-
const { resvgOptions } =
|
|
21
|
-
const svg = await createSvg(
|
|
20
|
+
async function createPng(event) {
|
|
21
|
+
const { resvgOptions } = useOgImageRuntimeConfig();
|
|
22
|
+
const svg = await createSvg(event);
|
|
22
23
|
const Resvg = await useResvg();
|
|
23
24
|
const resvg = new Resvg(svg, defu(
|
|
24
|
-
options.resvg,
|
|
25
|
+
event.options.resvg,
|
|
25
26
|
resvgOptions
|
|
26
27
|
));
|
|
27
28
|
const pngData = resvg.render();
|
|
28
29
|
return pngData.asPng();
|
|
29
30
|
}
|
|
30
|
-
async function createJpeg(
|
|
31
|
-
const { sharpOptions } =
|
|
32
|
-
const png = await createPng(
|
|
31
|
+
async function createJpeg(event) {
|
|
32
|
+
const { sharpOptions } = useOgImageRuntimeConfig();
|
|
33
|
+
const png = await createPng(event);
|
|
33
34
|
const sharp = await useSharp();
|
|
34
|
-
return sharp(png, defu(options.sharp, sharpOptions)).jpeg(
|
|
35
|
+
return sharp(png, defu(event.options.sharp, sharpOptions)).jpeg().toBuffer();
|
|
35
36
|
}
|
|
36
37
|
const SatoriRenderer = {
|
|
37
38
|
name: "satori",
|
|
38
|
-
supportedFormats: ["
|
|
39
|
-
async createImage(e
|
|
40
|
-
switch (
|
|
41
|
-
case "json":
|
|
42
|
-
return createVNodes(e, options);
|
|
43
|
-
case "svg":
|
|
44
|
-
return createSvg(e, options);
|
|
39
|
+
supportedFormats: ["png", "jpeg", "jpg", "json"],
|
|
40
|
+
async createImage(e) {
|
|
41
|
+
switch (e.extension) {
|
|
45
42
|
case "png":
|
|
46
|
-
return createPng(e
|
|
43
|
+
return createPng(e);
|
|
47
44
|
case "jpeg":
|
|
48
45
|
case "jpg":
|
|
49
|
-
return createJpeg(e
|
|
46
|
+
return createJpeg(e);
|
|
50
47
|
}
|
|
48
|
+
},
|
|
49
|
+
async debug(e) {
|
|
50
|
+
return {
|
|
51
|
+
vnodes: await createVNodes(e),
|
|
52
|
+
svg: await createSvg(e)
|
|
53
|
+
};
|
|
51
54
|
}
|
|
52
55
|
};
|
|
53
56
|
export default SatoriRenderer;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type _satori from 'satori';
|
|
2
|
+
export declare function useSatoriRenderer(): Promise<import("../../../types").Renderer>;
|
|
3
|
+
export declare function useChromiumRenderer(): Promise<import("../../../types").Renderer>;
|
|
2
4
|
export declare function useResvg(): Promise<new (svg: string | Uint8Array, options?: import("@resvg/resvg-wasm").ResvgRenderOptions | undefined) => {
|
|
3
5
|
free(): void;
|
|
4
6
|
render(): {
|
|
@@ -37,3 +39,4 @@ export declare function useResvg(): Promise<new (svg: string | Uint8Array, optio
|
|
|
37
39
|
}>;
|
|
38
40
|
export declare function useSatori(): Promise<typeof _satori>;
|
|
39
41
|
export declare function useSharp(): Promise<any>;
|
|
42
|
+
export declare function useCssInline(): Promise<any>;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
const cssInlineInstance = { instance: void 0 };
|
|
1
2
|
const sharpInstance = { instance: void 0 };
|
|
2
3
|
const resvgInstance = { instance: void 0 };
|
|
3
4
|
const satoriInstance = { instance: void 0 };
|
|
5
|
+
const satoriRendererInstance = { instance: void 0 };
|
|
6
|
+
const chromiumRendererInstance = { instance: void 0 };
|
|
7
|
+
export async function useSatoriRenderer() {
|
|
8
|
+
satoriRendererInstance.instance = satoriRendererInstance.instance || await import("#nuxt-og-image/renderers/satori").then((m) => m.default);
|
|
9
|
+
return satoriRendererInstance.instance;
|
|
10
|
+
}
|
|
11
|
+
export async function useChromiumRenderer() {
|
|
12
|
+
chromiumRendererInstance.instance = chromiumRendererInstance.instance || await import("#nuxt-og-image/renderers/chromium").then((m) => m.default);
|
|
13
|
+
return chromiumRendererInstance.instance;
|
|
14
|
+
}
|
|
4
15
|
export async function useResvg() {
|
|
5
16
|
resvgInstance.instance = resvgInstance.instance || await import("#nuxt-og-image/bindings/resvg").then((m) => m.default);
|
|
6
17
|
await resvgInstance.instance.initWasmPromise;
|
|
@@ -15,3 +26,7 @@ export async function useSharp() {
|
|
|
15
26
|
sharpInstance.instance = sharpInstance.instance || await import("#nuxt-og-image/bindings/sharp").then((m) => m.default);
|
|
16
27
|
return sharpInstance.instance;
|
|
17
28
|
}
|
|
29
|
+
export async function useCssInline() {
|
|
30
|
+
cssInlineInstance.instance = cssInlineInstance.instance || await import("#nuxt-og-image/bindings/css-inline").then((m) => m.default);
|
|
31
|
+
return cssInlineInstance.instance;
|
|
32
|
+
}
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { defineSatoriTransformer } from "../utils.mjs";
|
|
2
2
|
function isEmojiFilter(node) {
|
|
3
|
-
return node.type === "
|
|
3
|
+
return node.type === "svg" && typeof node.props?.["data-emoji"] !== "undefined";
|
|
4
4
|
}
|
|
5
5
|
export default defineSatoriTransformer([
|
|
6
6
|
// need to make sure parent div has flex for the emoji to render inline
|
|
7
7
|
{
|
|
8
|
-
filter: (node) => node.type
|
|
8
|
+
filter: (node) => ["div", "p"].includes(node.type) && Array.isArray(node.props?.children) && node.props.children.some(isEmojiFilter),
|
|
9
9
|
transform: async (node) => {
|
|
10
10
|
node.props.style = node.props.style || {};
|
|
11
11
|
node.props.style.display = "flex";
|
|
12
12
|
node.props.style.alignItems = "center";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
node.props.children = node.props.children.map((child) => {
|
|
14
|
+
if (typeof child === "string") {
|
|
15
|
+
return {
|
|
16
|
+
type: "div",
|
|
17
|
+
props: {
|
|
18
|
+
children: child
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (child.props.class?.includes("emoji"))
|
|
23
|
+
delete child.props.class;
|
|
24
|
+
return child;
|
|
25
|
+
});
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
]);
|