nuxt-og-image 6.7.4 → 6.7.6
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/dist/chunks/tw4.cjs +2 -2
- package/dist/chunks/tw4.mjs +2 -2
- package/dist/chunks/uno.cjs +20 -5
- package/dist/chunks/uno.mjs +19 -5
- package/dist/cli.cjs +8 -2
- package/dist/cli.mjs +8 -2
- package/dist/devtools/lib/og-image/rpc.ts +4 -1
- package/dist/module.cjs +2 -2
- package/dist/module.json +2 -2
- package/dist/module.mjs +2 -2
- package/dist/runtime/app/plugins/og-image-canonical-urls.server.d.ts +2 -1
- package/dist/runtime/app/plugins/og-image-canonical-urls.server.js +3 -1
- package/dist/runtime/app/plugins/route-rule-og-image.server.d.ts +2 -1
- package/dist/runtime/app/plugins/route-rule-og-image.server.js +3 -1
- package/dist/runtime/app/utils/plugins.js +4 -10
- package/dist/runtime/logger.js +2 -6
- package/dist/runtime/pure.d.ts +0 -1
- package/dist/runtime/pure.js +0 -5
- package/dist/runtime/server/og-image/bindings/browser/chrome-launcher.d.ts +1 -1
- package/dist/runtime/server/og-image/bindings/browser/cloudflare.d.ts +1 -2
- package/dist/runtime/server/og-image/bindings/browser/cloudflare.js +2 -9
- package/dist/runtime/server/og-image/bindings/browser/on-demand.d.ts +1 -1
- package/dist/runtime/server/og-image/bindings/browser/playwright.d.ts +1 -1
- package/dist/runtime/server/og-image/bindings/font-assets/cloudflare.d.ts +1 -1
- package/dist/runtime/server/og-image/bindings/font-assets/cloudflare.js +1 -1
- package/dist/runtime/server/og-image/bindings/font-assets/dev-prerender.d.ts +1 -1
- package/dist/runtime/server/og-image/bindings/font-assets/dev-prerender.js +27 -13
- package/dist/runtime/server/og-image/bindings/font-assets/external-url.js +3 -1
- package/dist/runtime/server/og-image/bindings/font-assets/node.d.ts +1 -1
- package/dist/runtime/server/og-image/bindings/font-assets/node.js +4 -2
- package/dist/runtime/server/og-image/bindings/resvg/node-dev.js +18 -64
- package/dist/runtime/server/og-image/bindings/takumi/node-dev.js +26 -83
- package/dist/runtime/server/og-image/bindings/worker-queue.d.ts +34 -0
- package/dist/runtime/server/og-image/bindings/worker-queue.js +150 -0
- package/dist/runtime/server/og-image/browser/renderer.js +1 -1
- package/dist/runtime/server/og-image/context.d.ts +1 -1
- package/dist/runtime/server/og-image/context.js +2 -3
- package/dist/runtime/server/og-image/core/plugins/imageSrc.js +1 -1
- package/dist/runtime/server/og-image/core/transforms/emojis/local.d.ts +2 -17
- package/dist/runtime/server/og-image/core/transforms/emojis/local.js +1 -1
- package/dist/runtime/server/og-image/devtools.d.ts +1 -1
- package/dist/runtime/server/og-image/devtools.js +1 -1
- package/dist/runtime/server/og-image/fonts.d.ts +1 -1
- package/dist/runtime/server/og-image/fonts.js +3 -1
- package/dist/runtime/server/og-image/templates/html.js +1 -1
- package/dist/runtime/server/plugins/prerender.d.ts +1 -1
- package/dist/runtime/server/plugins/prerender.js +2 -2
- package/dist/runtime/server/routes/__zero-runtime/image.d.ts +1 -1
- package/dist/runtime/server/routes/__zero-runtime/image.js +1 -1
- package/dist/runtime/server/routes/debug.json.d.ts +1 -10
- package/dist/runtime/server/routes/debug.json.js +1 -1
- package/dist/runtime/server/routes/image.d.ts +1 -1
- package/dist/runtime/server/routes/image.js +1 -1
- package/dist/runtime/server/routes/resolve.d.ts +1 -1
- package/dist/runtime/server/routes/resolve.js +1 -1
- package/dist/runtime/server/util/cache.d.ts +1 -6
- package/dist/runtime/server/util/cache.js +2 -2
- package/dist/runtime/server/util/cloudflare.d.ts +3 -0
- package/dist/runtime/server/util/cloudflare.js +17 -0
- package/dist/runtime/server/util/cloudflareAssets.d.ts +1 -1
- package/dist/runtime/server/util/cloudflareAssets.js +8 -5
- package/dist/runtime/server/util/encoding.d.ts +0 -1
- package/dist/runtime/server/util/encoding.js +0 -7
- package/dist/runtime/server/util/eventHandlers.d.ts +1 -1
- package/dist/runtime/server/util/eventHandlers.js +1 -1
- package/dist/runtime/server/util/fetchLocalAsset.d.ts +1 -1
- package/dist/runtime/server/util/kit.d.ts +7 -4
- package/dist/runtime/server/util/kit.js +4 -19
- package/dist/runtime/server/util/logger.js +2 -6
- package/dist/runtime/server/util/options.js +1 -1
- package/dist/runtime/server/util/query.d.ts +1 -1
- package/dist/runtime/server/util/timings.d.ts +0 -3
- package/dist/runtime/server/util/timings.js +0 -3
- package/dist/runtime/server/utils.d.ts +1 -1
- package/dist/runtime/server/utils.js +7 -4
- package/dist/runtime/types.d.ts +11 -9
- package/dist/shared/{nuxt-og-image.Bv8VSGTj.mjs → nuxt-og-image.BIbfn5xQ.mjs} +146 -108
- package/dist/shared/{nuxt-og-image.BRBtdkUp.cjs → nuxt-og-image.CdpC3njh.cjs} +148 -107
- package/package.json +57 -48
- package/types/virtual.d.ts +15 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Worker } from "node:worker_threads";
|
|
2
|
+
import { createWorkerQueue, parseWorkerTimeout } from "../worker-queue.js";
|
|
2
3
|
const workerCode = `
|
|
3
4
|
const { createRequire } = require('node:module')
|
|
4
5
|
const _require = createRequire(process.cwd() + '/')
|
|
@@ -12,78 +13,31 @@ parentPort.on('message', ({ id, svg, options }) => {
|
|
|
12
13
|
// Always slice to create a standard ArrayBuffer \u2014 native addon buffers
|
|
13
14
|
// use external memory that can't be transferred via postMessage
|
|
14
15
|
const ab = png.buffer.slice(png.byteOffset, png.byteOffset + png.byteLength)
|
|
15
|
-
parentPort.postMessage({ id, png: ab }, [ab])
|
|
16
|
+
parentPort.postMessage({ _tag: 'response', id, payload: { _tag: 'success', png: ab } }, [ab])
|
|
16
17
|
} catch (err) {
|
|
17
|
-
parentPort.postMessage({ id, error: err?.message || String(err) })
|
|
18
|
+
parentPort.postMessage({ _tag: 'response', id, payload: { _tag: 'failure', error: err?.message || String(err) } })
|
|
18
19
|
}
|
|
19
20
|
})
|
|
21
|
+
parentPort.postMessage({ _tag: 'ready' })
|
|
20
22
|
`;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
23
|
+
const workerTimeout = parseWorkerTimeout(process.env.NUXT_OG_IMAGE_WORKER_TIMEOUT);
|
|
24
|
+
const workerQueue = createWorkerQueue({
|
|
25
|
+
createWorker: () => new Worker(workerCode, { eval: true }),
|
|
26
|
+
executionTimeout: workerTimeout,
|
|
27
|
+
startupTimeout: workerTimeout,
|
|
28
|
+
label: "resvg"
|
|
29
|
+
});
|
|
30
|
+
function renderPng(svg, options) {
|
|
31
|
+
return workerQueue.enqueue(({ id }) => ({ id, svg, options })).then((result) => {
|
|
32
|
+
if (result._tag === "failure")
|
|
33
|
+
throw new Error(result.error);
|
|
34
|
+
return Buffer.from(result.png);
|
|
35
|
+
});
|
|
34
36
|
}
|
|
35
37
|
const signalKey = Symbol.for("og-image:resvg-worker-cleanup");
|
|
36
38
|
if (!globalThis[signalKey]) {
|
|
37
39
|
globalThis[signalKey] = true;
|
|
38
|
-
process.on("exit",
|
|
39
|
-
}
|
|
40
|
-
function createWorker() {
|
|
41
|
-
const w = new Worker(workerCode, { eval: true });
|
|
42
|
-
w.on("message", ({ id, png, error }) => {
|
|
43
|
-
const p = pending.get(id);
|
|
44
|
-
if (p) {
|
|
45
|
-
clearTimeout(p.timer);
|
|
46
|
-
pending.delete(id);
|
|
47
|
-
if (error)
|
|
48
|
-
p.reject(new Error(error));
|
|
49
|
-
else
|
|
50
|
-
p.resolve(Buffer.from(png));
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
w.on("error", (err) => {
|
|
54
|
-
for (const [id, p] of pending) {
|
|
55
|
-
clearTimeout(p.timer);
|
|
56
|
-
pending.delete(id);
|
|
57
|
-
p.reject(err);
|
|
58
|
-
}
|
|
59
|
-
worker = null;
|
|
60
|
-
});
|
|
61
|
-
w.on("exit", (code) => {
|
|
62
|
-
if (code !== 0) {
|
|
63
|
-
for (const [id, p] of pending) {
|
|
64
|
-
clearTimeout(p.timer);
|
|
65
|
-
pending.delete(id);
|
|
66
|
-
p.reject(new Error(`Resvg worker exited with code ${code}`));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
worker = null;
|
|
70
|
-
});
|
|
71
|
-
w.unref();
|
|
72
|
-
return w;
|
|
73
|
-
}
|
|
74
|
-
function renderPng(svg, options) {
|
|
75
|
-
return new Promise((resolve, reject) => {
|
|
76
|
-
if (!worker)
|
|
77
|
-
worker = createWorker();
|
|
78
|
-
const id = ++requestId;
|
|
79
|
-
const timer = setTimeout(() => {
|
|
80
|
-
pending.delete(id);
|
|
81
|
-
reject(new Error("resvg worker timed out \u2014 killing worker"));
|
|
82
|
-
killWorker();
|
|
83
|
-
}, 3e4);
|
|
84
|
-
pending.set(id, { resolve, reject, timer });
|
|
85
|
-
worker.postMessage({ id, svg, options });
|
|
86
|
-
});
|
|
40
|
+
process.on("exit", workerQueue.shutdown);
|
|
87
41
|
}
|
|
88
42
|
class ResvgWorkerProxy {
|
|
89
43
|
svg;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Worker } from "node:worker_threads";
|
|
2
|
+
import { createWorkerQueue, parseWorkerTimeout } from "../worker-queue.js";
|
|
2
3
|
import { extractResourceUrls as extractTakumiResourceUrls } from "./resource-urls.js";
|
|
3
4
|
const workerCode = `
|
|
4
5
|
const { createRequire } = require('node:module')
|
|
@@ -30,85 +31,24 @@ parentPort.on('message', async ({ id, type, newFonts, nodes, options }) => {
|
|
|
30
31
|
// Always slice to create a standard ArrayBuffer \u2014 native addon buffers
|
|
31
32
|
// use external memory that can't be transferred via postMessage
|
|
32
33
|
const ab = image.buffer.slice(image.byteOffset, image.byteOffset + image.byteLength)
|
|
33
|
-
parentPort.postMessage({ id, image: ab, fontWarnings }, [ab])
|
|
34
|
+
parentPort.postMessage({ _tag: 'response', id, payload: { _tag: 'success', image: ab, fontWarnings } }, [ab])
|
|
34
35
|
} catch (err) {
|
|
35
|
-
parentPort.postMessage({ id, error: err?.message || String(err) })
|
|
36
|
+
parentPort.postMessage({ _tag: 'response', id, payload: { _tag: 'failure', error: err?.message || String(err) } })
|
|
36
37
|
}
|
|
37
38
|
})
|
|
39
|
+
parentPort.postMessage({ _tag: 'ready' })
|
|
38
40
|
`;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
worker.terminate();
|
|
47
|
-
worker = null;
|
|
48
|
-
for (const [id, p] of pending) {
|
|
49
|
-
clearTimeout(p.timer);
|
|
50
|
-
pending.delete(id);
|
|
51
|
-
p.reject(new Error("Takumi worker terminated"));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
41
|
+
const workerTimeout = parseWorkerTimeout(process.env.NUXT_OG_IMAGE_WORKER_TIMEOUT);
|
|
42
|
+
const workerQueue = createWorkerQueue({
|
|
43
|
+
createWorker: () => new Worker(workerCode, { eval: true }),
|
|
44
|
+
executionTimeout: workerTimeout,
|
|
45
|
+
startupTimeout: workerTimeout,
|
|
46
|
+
label: "takumi"
|
|
47
|
+
});
|
|
54
48
|
const signalKey = Symbol.for("og-image:takumi-worker-cleanup");
|
|
55
49
|
if (!globalThis[signalKey]) {
|
|
56
50
|
globalThis[signalKey] = true;
|
|
57
|
-
process.on("exit",
|
|
58
|
-
}
|
|
59
|
-
function createWorker() {
|
|
60
|
-
workerGeneration++;
|
|
61
|
-
const w = new Worker(workerCode, { eval: true });
|
|
62
|
-
w.on("message", ({ id, image, urls, error, fontWarnings }) => {
|
|
63
|
-
const p = pending.get(id);
|
|
64
|
-
if (p) {
|
|
65
|
-
clearTimeout(p.timer);
|
|
66
|
-
pending.delete(id);
|
|
67
|
-
if (error)
|
|
68
|
-
p.reject(new Error(error));
|
|
69
|
-
else if (urls !== void 0)
|
|
70
|
-
p.resolve(urls);
|
|
71
|
-
else
|
|
72
|
-
p.resolve({ image: Buffer.from(image), fontWarnings });
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
w.on("error", (err) => {
|
|
76
|
-
for (const [id, p] of pending) {
|
|
77
|
-
clearTimeout(p.timer);
|
|
78
|
-
pending.delete(id);
|
|
79
|
-
p.reject(err);
|
|
80
|
-
}
|
|
81
|
-
worker = null;
|
|
82
|
-
});
|
|
83
|
-
w.on("exit", (code) => {
|
|
84
|
-
if (code !== 0) {
|
|
85
|
-
for (const [id, p] of pending) {
|
|
86
|
-
clearTimeout(p.timer);
|
|
87
|
-
pending.delete(id);
|
|
88
|
-
p.reject(new Error(`Takumi worker exited with code ${code}`));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
worker = null;
|
|
92
|
-
});
|
|
93
|
-
w.unref();
|
|
94
|
-
return w;
|
|
95
|
-
}
|
|
96
|
-
function ensureWorker() {
|
|
97
|
-
if (!worker)
|
|
98
|
-
worker = createWorker();
|
|
99
|
-
}
|
|
100
|
-
function postToWorker(msg, timeoutMs = 3e4) {
|
|
101
|
-
return new Promise((resolve, reject) => {
|
|
102
|
-
ensureWorker();
|
|
103
|
-
const id = ++requestId;
|
|
104
|
-
const timer = setTimeout(() => {
|
|
105
|
-
pending.delete(id);
|
|
106
|
-
reject(new Error("takumi worker timed out \u2014 killing worker"));
|
|
107
|
-
killWorker();
|
|
108
|
-
}, timeoutMs);
|
|
109
|
-
pending.set(id, { resolve, reject, timer });
|
|
110
|
-
worker.postMessage({ id, ...msg });
|
|
111
|
-
});
|
|
51
|
+
process.on("exit", workerQueue.shutdown);
|
|
112
52
|
}
|
|
113
53
|
function extractResourceUrls(nodes) {
|
|
114
54
|
return Promise.resolve(extractTakumiResourceUrls(nodes));
|
|
@@ -130,21 +70,24 @@ class RendererWorkerProxy {
|
|
|
130
70
|
this.loadFont(font);
|
|
131
71
|
}
|
|
132
72
|
render(nodes, options) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
73
|
+
return workerQueue.enqueue(({ id, generation }) => {
|
|
74
|
+
let fontsToSend;
|
|
75
|
+
if (this.syncedGeneration !== generation) {
|
|
76
|
+
fontsToSend = [...this.allFonts];
|
|
77
|
+
this.pendingFonts = [];
|
|
78
|
+
} else {
|
|
79
|
+
fontsToSend = this.pendingFonts.splice(0);
|
|
80
|
+
}
|
|
81
|
+
this.syncedGeneration = generation;
|
|
82
|
+
return { id, type: "render", newFonts: fontsToSend, nodes, options };
|
|
83
|
+
}).then((result) => {
|
|
84
|
+
if (result._tag === "failure")
|
|
85
|
+
throw new Error(result.error);
|
|
143
86
|
if (result.fontWarnings?.length) {
|
|
144
87
|
for (const w of result.fontWarnings)
|
|
145
88
|
console.warn(`[nuxt-og-image] Failed to load font "${w.name}" (weight: ${w.weight}) into takumi renderer: ${w.error}`);
|
|
146
89
|
}
|
|
147
|
-
return result.image;
|
|
90
|
+
return Buffer.from(result.image);
|
|
148
91
|
});
|
|
149
92
|
}
|
|
150
93
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
interface WorkerHandle {
|
|
2
|
+
on: {
|
|
3
|
+
(event: 'message', listener: (message: unknown) => void): WorkerHandle;
|
|
4
|
+
(event: 'error', listener: (error: Error) => void): WorkerHandle;
|
|
5
|
+
(event: 'exit', listener: (code: number) => void): WorkerHandle;
|
|
6
|
+
};
|
|
7
|
+
postMessage: (message: unknown) => void;
|
|
8
|
+
removeAllListeners: () => WorkerHandle;
|
|
9
|
+
terminate: () => Promise<number>;
|
|
10
|
+
unref: () => void;
|
|
11
|
+
}
|
|
12
|
+
interface QueueOptions {
|
|
13
|
+
createWorker: () => WorkerHandle;
|
|
14
|
+
executionTimeout: number;
|
|
15
|
+
startupTimeout: number;
|
|
16
|
+
label: string;
|
|
17
|
+
maxAttempts?: number;
|
|
18
|
+
}
|
|
19
|
+
interface Job<TMessage, TResponse> {
|
|
20
|
+
id: number;
|
|
21
|
+
buildMessage: (context: {
|
|
22
|
+
id: number;
|
|
23
|
+
generation: number;
|
|
24
|
+
}) => TMessage;
|
|
25
|
+
resolve: (response: TResponse) => void;
|
|
26
|
+
reject: (error: Error) => void;
|
|
27
|
+
attempts: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function parseWorkerTimeout(value: string | undefined, fallback?: number): number;
|
|
30
|
+
export declare function createWorkerQueue<TMessage, TResponse>(options: QueueOptions): {
|
|
31
|
+
enqueue: (buildMessage: Job<TMessage, TResponse>["buildMessage"]) => Promise<TResponse>;
|
|
32
|
+
shutdown: () => void;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
function toError(reason) {
|
|
2
|
+
return reason instanceof Error ? reason : new Error(String(reason));
|
|
3
|
+
}
|
|
4
|
+
function parseWorkerEvent(message) {
|
|
5
|
+
if (!message || typeof message !== "object" || !("_tag" in message))
|
|
6
|
+
return;
|
|
7
|
+
if (message._tag === "ready")
|
|
8
|
+
return { _tag: "ready" };
|
|
9
|
+
if (message._tag !== "response" || !("id" in message) || typeof message.id !== "number" || !("payload" in message))
|
|
10
|
+
return;
|
|
11
|
+
return { _tag: "response", id: message.id, payload: message.payload };
|
|
12
|
+
}
|
|
13
|
+
export function parseWorkerTimeout(value, fallback = 3e4) {
|
|
14
|
+
const timeout = Number(value);
|
|
15
|
+
return Number.isSafeInteger(timeout) && timeout > 0 ? timeout : fallback;
|
|
16
|
+
}
|
|
17
|
+
export function createWorkerQueue(options) {
|
|
18
|
+
const maxAttempts = options.maxAttempts ?? 2;
|
|
19
|
+
const queue = [];
|
|
20
|
+
let active = { _tag: "idle" };
|
|
21
|
+
let workerState = { _tag: "stopped" };
|
|
22
|
+
let requestId = 0;
|
|
23
|
+
let workerGeneration = 0;
|
|
24
|
+
let stopped = false;
|
|
25
|
+
function stopWorker() {
|
|
26
|
+
if (workerState._tag === "stopped")
|
|
27
|
+
return;
|
|
28
|
+
const state = workerState;
|
|
29
|
+
workerState = { _tag: "stopped" };
|
|
30
|
+
if (state._tag === "starting")
|
|
31
|
+
clearTimeout(state.timer);
|
|
32
|
+
state.worker.removeAllListeners();
|
|
33
|
+
void state.worker.terminate().catch(() => {
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function takeActive() {
|
|
37
|
+
if (active._tag === "idle")
|
|
38
|
+
return;
|
|
39
|
+
const state = active;
|
|
40
|
+
active = { _tag: "idle" };
|
|
41
|
+
if (state._tag === "running")
|
|
42
|
+
clearTimeout(state.timer);
|
|
43
|
+
return state.job;
|
|
44
|
+
}
|
|
45
|
+
function continueQueue() {
|
|
46
|
+
queueMicrotask(processQueue);
|
|
47
|
+
}
|
|
48
|
+
function failWorker(reason, failedWorker) {
|
|
49
|
+
if (failedWorker && (workerState._tag === "stopped" || workerState.worker !== failedWorker))
|
|
50
|
+
return;
|
|
51
|
+
stopWorker();
|
|
52
|
+
const job = takeActive();
|
|
53
|
+
if (job) {
|
|
54
|
+
if (job.attempts < maxAttempts) {
|
|
55
|
+
job.attempts++;
|
|
56
|
+
queue.unshift(job);
|
|
57
|
+
} else {
|
|
58
|
+
job.reject(toError(reason));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
continueQueue();
|
|
62
|
+
}
|
|
63
|
+
function startWorker() {
|
|
64
|
+
let newWorker;
|
|
65
|
+
try {
|
|
66
|
+
newWorker = options.createWorker();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
failWorker(error);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const generation = ++workerGeneration;
|
|
72
|
+
const timer = setTimeout(() => {
|
|
73
|
+
failWorker(new Error(`${options.label} worker startup timed out after ${options.startupTimeout}ms`), newWorker);
|
|
74
|
+
}, options.startupTimeout);
|
|
75
|
+
workerState = { _tag: "starting", generation, timer, worker: newWorker };
|
|
76
|
+
newWorker.on("message", (value) => {
|
|
77
|
+
if (workerState._tag === "stopped" || workerState.worker !== newWorker)
|
|
78
|
+
return;
|
|
79
|
+
const message = parseWorkerEvent(value);
|
|
80
|
+
if (!message)
|
|
81
|
+
return;
|
|
82
|
+
if (message._tag === "ready") {
|
|
83
|
+
if (workerState._tag !== "starting")
|
|
84
|
+
return;
|
|
85
|
+
clearTimeout(workerState.timer);
|
|
86
|
+
workerState = { _tag: "ready", generation, worker: newWorker };
|
|
87
|
+
dispatchActive();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (active._tag !== "running" || active.job.id !== message.id)
|
|
91
|
+
return;
|
|
92
|
+
const job = takeActive();
|
|
93
|
+
job.resolve(message.payload);
|
|
94
|
+
processQueue();
|
|
95
|
+
});
|
|
96
|
+
newWorker.on("error", (error) => failWorker(error, newWorker));
|
|
97
|
+
newWorker.on("exit", (code) => failWorker(new Error(`${options.label} worker exited with code ${code}`), newWorker));
|
|
98
|
+
newWorker.unref();
|
|
99
|
+
}
|
|
100
|
+
function dispatchActive() {
|
|
101
|
+
if (active._tag !== "waiting" || workerState._tag !== "ready")
|
|
102
|
+
return;
|
|
103
|
+
const job = active.job;
|
|
104
|
+
const state = workerState;
|
|
105
|
+
const timer = setTimeout(() => {
|
|
106
|
+
if (active._tag !== "running" || active.job !== job)
|
|
107
|
+
return;
|
|
108
|
+
stopWorker();
|
|
109
|
+
takeActive().reject(new Error(`${options.label} render timed out after ${options.executionTimeout}ms`));
|
|
110
|
+
continueQueue();
|
|
111
|
+
}, options.executionTimeout);
|
|
112
|
+
active = { _tag: "running", job, timer };
|
|
113
|
+
try {
|
|
114
|
+
state.worker.postMessage(job.buildMessage({ id: job.id, generation: state.generation }));
|
|
115
|
+
} catch (error) {
|
|
116
|
+
stopWorker();
|
|
117
|
+
takeActive().reject(toError(error));
|
|
118
|
+
continueQueue();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function processQueue() {
|
|
122
|
+
if (stopped || active._tag !== "idle")
|
|
123
|
+
return;
|
|
124
|
+
const job = queue.shift();
|
|
125
|
+
if (!job)
|
|
126
|
+
return;
|
|
127
|
+
active = { _tag: "waiting", job };
|
|
128
|
+
if (workerState._tag === "stopped")
|
|
129
|
+
startWorker();
|
|
130
|
+
else if (workerState._tag === "ready")
|
|
131
|
+
dispatchActive();
|
|
132
|
+
}
|
|
133
|
+
function enqueue(buildMessage) {
|
|
134
|
+
if (stopped)
|
|
135
|
+
return Promise.reject(new Error(`${options.label} worker queue is shut down`));
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
queue.push({ id: ++requestId, buildMessage, resolve, reject, attempts: 1 });
|
|
138
|
+
processQueue();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function shutdown() {
|
|
142
|
+
stopped = true;
|
|
143
|
+
stopWorker();
|
|
144
|
+
const error = new Error(`${options.label} worker terminated`);
|
|
145
|
+
takeActive()?.reject(error);
|
|
146
|
+
for (const job of queue.splice(0))
|
|
147
|
+
job.reject(error);
|
|
148
|
+
}
|
|
149
|
+
return { enqueue, shutdown };
|
|
150
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { H3Error, H3Event } from 'h3';
|
|
1
|
+
import type { H3Error, H3Event } from '#nuxtseo/h3';
|
|
2
2
|
import type { OgImageRenderEventContext } from '../../types.js';
|
|
3
3
|
export declare function resolvePathCacheKey(e: H3Event, path: string, resolvedOptions?: Record<string, any>): string;
|
|
4
4
|
export declare function resolveContext(e: H3Event): Promise<H3Error | OgImageRenderEventContext>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
|
-
import { createError } from "h3";
|
|
3
|
-
import { useNitroApp } from "nitropack/runtime";
|
|
4
2
|
import { parseURL, withoutLeadingSlash, withoutTrailingSlash, withQuery } from "ufo";
|
|
5
3
|
import { normalizeKey } from "unstorage";
|
|
4
|
+
import { createError } from "#nuxtseo/h3";
|
|
5
|
+
import { useNitroApp } from "#nuxtseo/nitro";
|
|
6
6
|
import { prerenderOptionsCache } from "#og-image-cache";
|
|
7
7
|
import { getSiteConfig } from "#site-config/server/composables/getSiteConfig";
|
|
8
8
|
import { createSitePathResolver } from "#site-config/server/composables/utils";
|
|
@@ -202,7 +202,6 @@ export async function resolveContext(e) {
|
|
|
202
202
|
basePath,
|
|
203
203
|
options: normalised.options,
|
|
204
204
|
timings,
|
|
205
|
-
// @ts-expect-error hookable v6
|
|
206
205
|
_nitro: useNitroApp()
|
|
207
206
|
};
|
|
208
207
|
const hookTimeout = runtimeConfig.security?.renderTimeout ?? 15e3;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useStorage } from "nitropack/runtime";
|
|
2
1
|
import { withBase, withoutLeadingSlash } from "ufo";
|
|
2
|
+
import { useStorage } from "#nuxtseo/nitro";
|
|
3
3
|
import { getNitroOrigin } from "#site-config/server/composables/getNitroOrigin";
|
|
4
4
|
import { toBase64Image } from "../../../../shared.js";
|
|
5
5
|
import { decodeHtml } from "../../../util/encoding.js";
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
import type { OgImageRenderEventContext } from '../../../../../types.js';
|
|
2
|
-
interface IconsData {
|
|
3
|
-
icons: Record<string, {
|
|
4
|
-
body: string;
|
|
5
|
-
width?: number;
|
|
6
|
-
height?: number;
|
|
7
|
-
}>;
|
|
8
|
-
width: number;
|
|
9
|
-
height: number;
|
|
10
|
-
}
|
|
1
|
+
import type { OgImageIconsData, OgImageRenderEventContext } from '../../../../../types.js';
|
|
11
2
|
declare module '#og-image-virtual/iconify-json-icons.mjs' {
|
|
12
|
-
function loadIcons(): Promise<
|
|
13
|
-
}
|
|
14
|
-
declare module 'nitropack/types' {
|
|
15
|
-
interface NitroApp {
|
|
16
|
-
_ogImageIconsData?: IconsData;
|
|
17
|
-
}
|
|
3
|
+
function loadIcons(): Promise<OgImageIconsData>;
|
|
18
4
|
}
|
|
19
5
|
/**
|
|
20
6
|
* Service function to get emoji SVGs from local iconify JSON files
|
|
@@ -23,4 +9,3 @@ declare module 'nitropack/types' {
|
|
|
23
9
|
* Icons are loaded lazily on first use to avoid 24MB+ memory at startup
|
|
24
10
|
*/
|
|
25
11
|
export declare function getEmojiSvg(ctx: OgImageRenderEventContext, emojiChar: string): Promise<string | null>;
|
|
26
|
-
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useNitroApp } from "
|
|
1
|
+
import { useNitroApp } from "#nuxtseo/nitro";
|
|
2
2
|
import { getEmojiCodePoint, getEmojiIconNames } from "./emoji-utils.js";
|
|
3
3
|
function wrapDefsElements(body) {
|
|
4
4
|
const defsElements = ["linearGradient", "radialGradient", "filter", "clipPath", "mask", "pattern"];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parse } from "devalue";
|
|
2
|
-
import { createError } from "h3";
|
|
2
|
+
import { createError } from "#nuxtseo/h3";
|
|
3
3
|
import { htmlPayloadCache } from "#og-image-cache";
|
|
4
4
|
import { extractSocialPreviewTags } from "../../pure.js";
|
|
5
5
|
import { logger } from "../util/logger.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { H3Event } from 'h3';
|
|
1
|
+
import type { H3Event } from '#nuxtseo/h3';
|
|
2
2
|
import type { OgImageRenderEventContext, RuntimeFontConfig } from '../../types.js';
|
|
3
3
|
import type { FontFormat } from './font-source.js';
|
|
4
4
|
export { buildSubsetFamilyChain, renameSubsetFonts, resolveSubsetChain } from './font-subsets.js';
|
|
@@ -198,7 +198,9 @@ export async function loadDefinedFonts(event, fontDefs) {
|
|
|
198
198
|
const weight = normalizeFontWeight(def.weight);
|
|
199
199
|
const style = def.style === "italic" ? "italic" : "normal";
|
|
200
200
|
const fontConfig = { family: name, weight, style, src: path, localPath: path };
|
|
201
|
-
const data = await resolve(event.e, fontConfig).catch(() =>
|
|
201
|
+
const data = await resolve(event.e, fontConfig).catch(() => {
|
|
202
|
+
return null;
|
|
203
|
+
});
|
|
202
204
|
if (data) {
|
|
203
205
|
results.push({
|
|
204
206
|
...fontConfig,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHead, renderSSRHead } from "@unhead/vue/server";
|
|
2
|
-
import { createError } from "h3";
|
|
2
|
+
import { createError } from "#nuxtseo/h3";
|
|
3
3
|
import resolvedFonts from "#og-image/fonts";
|
|
4
4
|
import { fetchIsland } from "../../util/kit.js";
|
|
5
5
|
import { applyEmojis } from "../core/transforms/emojis/index.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: any;
|
|
2
2
|
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parse } from "devalue";
|
|
2
|
-
import { appendResponseHeader } from "h3";
|
|
3
|
-
import { defineNitroPlugin } from "nitropack/runtime";
|
|
4
2
|
import { parseURL } from "ufo";
|
|
3
|
+
import { appendResponseHeader } from "#nuxtseo/h3";
|
|
4
|
+
import { defineNitroPlugin } from "#nuxtseo/nitro";
|
|
5
5
|
import { prerenderOptionsCache } from "#og-image-cache";
|
|
6
6
|
import { createSitePathResolver } from "#site-config/server/composables/utils";
|
|
7
7
|
import { isInternalRoute } from "../../shared.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: any;
|
|
2
2
|
export default _default;
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
2
|
-
siteConfigUrl: string;
|
|
3
|
-
origin: string;
|
|
4
|
-
componentNames: any;
|
|
5
|
-
runtimeConfig: import("../../types.js").OgImageRuntimeConfig;
|
|
6
|
-
compatibility: any;
|
|
7
|
-
resolvedFonts: any;
|
|
8
|
-
availableFonts: any;
|
|
9
|
-
fontRequirements: any;
|
|
10
|
-
}>>;
|
|
1
|
+
declare const _default: any;
|
|
11
2
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineEventHandler, setHeader } from "h3";
|
|
1
|
+
import { defineEventHandler, setHeader } from "#nuxtseo/h3";
|
|
2
2
|
import { componentNames } from "#og-image-virtual/component-names.mjs";
|
|
3
3
|
import compatibility from "#og-image/compatibility";
|
|
4
4
|
import { fontRequirements } from "#og-image/font-requirements";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: any;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: any;
|
|
2
2
|
export default _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createError, defineEventHandler, getRequestHost, sendRedirect } from "h3";
|
|
2
1
|
import { parseURL, withLeadingSlash, withQuery } from "ufo";
|
|
2
|
+
import { createError, defineEventHandler, getRequestHost, sendRedirect } from "#nuxtseo/h3";
|
|
3
3
|
import { getSiteConfig } from "#site-config/server/composables/getSiteConfig";
|
|
4
4
|
import { isInternalRoute } from "../../shared.js";
|
|
5
5
|
import { getEventQuery } from "../util/query.js";
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import type { H3Error } from 'h3';
|
|
1
|
+
import type { H3Error } from '#nuxtseo/h3';
|
|
2
2
|
import type { OgImageRenderEventContext } from '../../types.js';
|
|
3
|
-
declare module 'nitropack/types' {
|
|
4
|
-
interface NitroApp {
|
|
5
|
-
_ogImageCacheBackendWarned?: boolean;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
3
|
export declare function useOgImageBufferCache(ctx: OgImageRenderEventContext, options: {
|
|
9
4
|
baseCacheKey: string | false;
|
|
10
5
|
cacheMaxAgeSeconds?: number;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { fnv1a64Base36 } from "fnv1a-64";
|
|
2
|
-
import { createError, handleCacheHeaders, setHeader, setHeaders } from "h3";
|
|
3
|
-
import { useStorage } from "nitropack/runtime";
|
|
4
2
|
import { withTrailingSlash } from "ufo";
|
|
5
3
|
import { prefixStorage } from "unstorage";
|
|
4
|
+
import { createError, handleCacheHeaders, setHeader, setHeaders } from "#nuxtseo/h3";
|
|
5
|
+
import { useStorage } from "#nuxtseo/nitro";
|
|
6
6
|
import { logger } from "../../logger.js";
|
|
7
7
|
import { getEventQuery } from "./query.js";
|
|
8
8
|
function safeCompare(a, b) {
|