nuxt-og-image 6.7.1 → 6.7.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/dist/module.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Node } from '@takumi-rs/helpers';
|
|
2
|
-
import type { OgImageRenderEventContext } from '../../../types.js';
|
|
2
|
+
import type { OgImageRenderEventContext, VNode } from '../../../types.js';
|
|
3
3
|
export declare function createTakumiNodes(ctx: OgImageRenderEventContext): Promise<Node>;
|
|
4
|
+
export declare function vnodeToTakumiNode(vnode: VNode, inheritedFontSize: number, inheritedColor?: string): Promise<Node>;
|
|
@@ -43,8 +43,13 @@ function extractFontSize(props, style) {
|
|
|
43
43
|
}
|
|
44
44
|
return void 0;
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
function extractColor(style) {
|
|
47
|
+
const color = style?.color;
|
|
48
|
+
return typeof color === "string" && color ? color : void 0;
|
|
49
|
+
}
|
|
50
|
+
export async function vnodeToTakumiNode(vnode, inheritedFontSize, inheritedColor) {
|
|
47
51
|
const { style, children, class: cls, tw, src, ...rest } = vnode.props;
|
|
52
|
+
const nodeColor = extractColor(style) ?? inheritedColor;
|
|
48
53
|
const baseMetadata = {
|
|
49
54
|
tw: tw || cls || void 0,
|
|
50
55
|
style
|
|
@@ -56,7 +61,7 @@ async function vnodeToTakumiNode(vnode, inheritedFontSize) {
|
|
|
56
61
|
return {
|
|
57
62
|
...baseMetadata,
|
|
58
63
|
type: "image",
|
|
59
|
-
src: vnodeToHtmlString(vnode),
|
|
64
|
+
src: vnodeToHtmlString(vnode, nodeColor),
|
|
60
65
|
// When em/rem + explicit parent font size → resolve to px.
|
|
61
66
|
// When em/rem + default font size → leave undefined (takumi handles natively).
|
|
62
67
|
// Otherwise → use standard resolution chain (numeric attrs → style → viewBox).
|
|
@@ -99,7 +104,7 @@ async function vnodeToTakumiNode(vnode, inheritedFontSize) {
|
|
|
99
104
|
const takumiChildren = [];
|
|
100
105
|
for (const child of children) {
|
|
101
106
|
if (child && typeof child === "object")
|
|
102
|
-
takumiChildren.push(await vnodeToTakumiNode(child, childFontSize));
|
|
107
|
+
takumiChildren.push(await vnodeToTakumiNode(child, childFontSize, nodeColor));
|
|
103
108
|
else if (typeof child === "string" && child.trim())
|
|
104
109
|
takumiChildren.push({ type: "text", text: child.trim() });
|
|
105
110
|
}
|
|
@@ -114,9 +119,13 @@ async function vnodeToTakumiNode(vnode, inheritedFontSize) {
|
|
|
114
119
|
type: "container"
|
|
115
120
|
};
|
|
116
121
|
}
|
|
117
|
-
function
|
|
122
|
+
function resolveCurrentColor(value, color) {
|
|
123
|
+
return color && typeof value === "string" && value.toLowerCase() === "currentcolor" ? color : value;
|
|
124
|
+
}
|
|
125
|
+
function vnodeToHtmlString(vnode, inheritedColor) {
|
|
118
126
|
const { style, children, ...attrs } = vnode.props;
|
|
119
127
|
const attrParts = [];
|
|
128
|
+
const nodeColor = extractColor(style) ?? inheritedColor;
|
|
120
129
|
const kebabCase = (str) => str.replace(RE_UPPERCASE, (m) => `-${m.toLowerCase()}`);
|
|
121
130
|
if (vnode.type === "svg") {
|
|
122
131
|
if (!attrs.xmlns)
|
|
@@ -138,7 +147,7 @@ function vnodeToHtmlString(vnode) {
|
|
|
138
147
|
return val;
|
|
139
148
|
};
|
|
140
149
|
if (style && typeof style === "object") {
|
|
141
|
-
const styleStr = Object.entries(style).filter(([_, v]) => v !== void 0 && v !== null && v !== "").map(([k, v]) => `${kebabCase(k)}:${resolveValue(v)}`).join(";");
|
|
150
|
+
const styleStr = Object.entries(style).filter(([_, v]) => v !== void 0 && v !== null && v !== "").map(([k, v]) => `${kebabCase(k)}:${resolveValue(resolveCurrentColor(v, nodeColor))}`).join(";");
|
|
142
151
|
if (styleStr)
|
|
143
152
|
attrParts.push(`style="${styleStr.replace(RE_DQUOTE, """)}"`);
|
|
144
153
|
} else if (typeof style === "string") {
|
|
@@ -148,14 +157,14 @@ function vnodeToHtmlString(vnode) {
|
|
|
148
157
|
if (key === "tw" || key === "class" || val == null)
|
|
149
158
|
continue;
|
|
150
159
|
const finalKey = SVG_CAMEL_ATTR_VALUES.has(key) ? key : kebabCase(key);
|
|
151
|
-
attrParts.push(`${finalKey}="${String(resolveValue(val)).replace(RE_DQUOTE, """)}"`);
|
|
160
|
+
attrParts.push(`${finalKey}="${String(resolveValue(resolveCurrentColor(val, nodeColor))).replace(RE_DQUOTE, """)}"`);
|
|
152
161
|
}
|
|
153
162
|
const open = attrParts.length ? `<${vnode.type} ${attrParts.join(" ")}>` : `<${vnode.type}>`;
|
|
154
163
|
const inner = Array.isArray(children) ? children.map((c) => {
|
|
155
164
|
if (typeof c === "string")
|
|
156
165
|
return c.replace(RE_AMP, "&").replace(RE_LT, "<").replace(RE_GT, ">");
|
|
157
166
|
if (c && typeof c === "object")
|
|
158
|
-
return vnodeToHtmlString(c);
|
|
167
|
+
return vnodeToHtmlString(c, nodeColor);
|
|
159
168
|
return "";
|
|
160
169
|
}).join("") : typeof children === "string" ? children.replace(RE_AMP, "&").replace(RE_LT, "<").replace(RE_GT, ">") : "";
|
|
161
170
|
return `${open}${inner}</${vnode.type}>`;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-og-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.7.
|
|
4
|
+
"version": "6.7.2",
|
|
5
5
|
"description": "Enlightened OG Image generation for Nuxt.",
|
|
6
6
|
"author": {
|
|
7
7
|
"website": "https://harlanzw.com",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"magicast": "^0.5.3",
|
|
119
119
|
"mocked-exports": "^0.1.1",
|
|
120
120
|
"nuxt-site-config": "^4.1.1",
|
|
121
|
-
"nuxtseo-shared": "^5.3.
|
|
121
|
+
"nuxtseo-shared": "^5.3.2",
|
|
122
122
|
"nypm": "^0.6.8",
|
|
123
123
|
"ofetch": "^1.5.1",
|
|
124
124
|
"ohash": "^2.0.11",
|
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
"lightningcss": "^1.32.0",
|
|
188
188
|
"nitropack": "^2.13.4",
|
|
189
189
|
"nuxt": "^4.4.8",
|
|
190
|
-
"nuxtseo-layer-devtools": "^5.3.
|
|
190
|
+
"nuxtseo-layer-devtools": "^5.3.2",
|
|
191
191
|
"playwright": "^1.61.1",
|
|
192
192
|
"playwright-core": "^1.61.1",
|
|
193
193
|
"sass": "^1.101.0",
|