nuxt-seo-utils 8.4.0 → 8.4.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/cli.mjs CHANGED
@@ -9,7 +9,7 @@ import { p as pngToIco } from './shared/nuxt-seo-utils.NAV2YNQn.mjs';
9
9
  import 'node:buffer';
10
10
 
11
11
  const name = "nuxt-seo-utils";
12
- const version = "8.4.0";
12
+ const version = "8.4.2";
13
13
  const description = "SEO utilities to improve your Nuxt sites discoverability and shareability";
14
14
 
15
15
  const ICON_SIZES = [
package/dist/module.d.mts CHANGED
@@ -121,7 +121,7 @@ interface ModuleOptions {
121
121
  * **Build mode**: Minifies static `app.head` scripts/styles and prerendered route HTML using esbuild (JS) and lightningcss (CSS).
122
122
  * **Runtime mode**: Minifies all inline scripts/styles per SSR request via an Unhead `ssr:render` plugin using lightweight pure JS minifiers.
123
123
  *
124
- * @default true
124
+ * @default { build: true, runtime: false }
125
125
  */
126
126
  minify: boolean | {
127
127
  build?: boolean;
package/dist/module.d.ts CHANGED
@@ -121,7 +121,7 @@ interface ModuleOptions {
121
121
  * **Build mode**: Minifies static `app.head` scripts/styles and prerendered route HTML using esbuild (JS) and lightningcss (CSS).
122
122
  * **Runtime mode**: Minifies all inline scripts/styles per SSR request via an Unhead `ssr:render` plugin using lightweight pure JS minifiers.
123
123
  *
124
- * @default true
124
+ * @default { build: true, runtime: false }
125
125
  */
126
126
  minify: boolean | {
127
127
  build?: boolean;
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "8.4.0",
7
+ "version": "8.4.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -13,10 +13,9 @@ import { encodePath, joinURL } from 'ufo';
13
13
  import { c as classifyIconFilename, g as getIconRel, n as normalizeIconSizes, a as partitionColorModeIconLinks } from './shared/nuxt-seo-utils.NAV2YNQn.mjs';
14
14
  import escapeRE from 'escape-string-regexp';
15
15
  import { readFile, readdir } from 'node:fs/promises';
16
- import imageSize from 'image-size';
16
+ import { Buffer } from 'node:buffer';
17
17
  import { JSON_TYPES, SKIP_JS_TYPES } from '../dist/runtime/shared/minify.js';
18
18
  import { setupDevToolsUI as setupDevToolsUI$1 } from 'nuxtseo-shared/devtools';
19
- import 'node:buffer';
20
19
 
21
20
  function extendNuxtConfigAppHeadSeoMeta(nuxt = useNuxt()) {
22
21
  const seoMeta = nuxt.options.app?.seoMeta || nuxt.options.app?.head?.seoMeta || {};
@@ -28,9 +27,10 @@ function extendNuxtConfigAppHeadSeoMeta(nuxt = useNuxt()) {
28
27
  ...nuxt.options.app.head,
29
28
  meta: [
30
29
  ...nuxt.options.app.head.meta || [],
31
- // @ts-expect-error untyped
32
30
  ...unpackMeta(seoMeta),
33
31
  ...unpackMeta(configSeoMeta || {})
32
+ // Unhead accepts null and array content.
33
+ // Nuxt's static head type remains narrower.
34
34
  ]
35
35
  };
36
36
  delete nuxt.options.app.seoMeta;
@@ -187,6 +187,134 @@ function parseSegment(segment) {
187
187
  return tokens;
188
188
  }
189
189
 
190
+ const PNG_SIGNATURE = Buffer.from("89504e470d0a1a0a", "hex");
191
+ const SVG_ROOT_RE = /<svg(?:\s|>)/i;
192
+ const SVG_LENGTH_RE = /^((?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)(cm|em|ex|in|m|mm|pc|pt|px)?$/i;
193
+ const SVG_UNIT_PIXELS = {
194
+ cm: 96 / 2.54,
195
+ em: 16,
196
+ ex: 8,
197
+ in: 96,
198
+ m: 96 / 2.54 * 100,
199
+ mm: 96 / 2.54 / 10,
200
+ pc: 96 / 72 / 12,
201
+ pt: 96 / 72,
202
+ px: 1
203
+ };
204
+ function validDimensions(width, height) {
205
+ if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0)
206
+ return void 0;
207
+ return { width, height };
208
+ }
209
+ function parsePng(buffer) {
210
+ if (buffer.length < 24 || !buffer.subarray(0, 8).equals(PNG_SIGNATURE))
211
+ return void 0;
212
+ if (buffer.readUInt32BE(8) !== 13 || buffer.toString("ascii", 12, 16) !== "IHDR")
213
+ return void 0;
214
+ return validDimensions(buffer.readUInt32BE(16), buffer.readUInt32BE(20));
215
+ }
216
+ function parseGif(buffer) {
217
+ if (buffer.length < 10 || !["GIF87a", "GIF89a"].includes(buffer.toString("ascii", 0, 6)))
218
+ return void 0;
219
+ return validDimensions(buffer.readUInt16LE(6), buffer.readUInt16LE(8));
220
+ }
221
+ function isJpegSizeMarker(marker) {
222
+ return marker >= 192 && marker <= 207 && ![196, 200, 204].includes(marker);
223
+ }
224
+ function parseJpeg(buffer) {
225
+ if (buffer.length < 4 || buffer[0] !== 255 || buffer[1] !== 216)
226
+ return void 0;
227
+ let offset = 2;
228
+ while (offset < buffer.length) {
229
+ while (offset < buffer.length && buffer[offset] !== 255)
230
+ offset++;
231
+ while (offset < buffer.length && buffer[offset] === 255)
232
+ offset++;
233
+ if (offset >= buffer.length)
234
+ return void 0;
235
+ const marker = buffer[offset++];
236
+ if (marker === 217 || marker === 218)
237
+ return void 0;
238
+ if (marker >= 208 && marker <= 215 || marker === 1)
239
+ continue;
240
+ if (offset + 2 > buffer.length)
241
+ return void 0;
242
+ const segmentLength = buffer.readUInt16BE(offset);
243
+ if (segmentLength < 2 || offset + segmentLength > buffer.length)
244
+ return void 0;
245
+ if (isJpegSizeMarker(marker)) {
246
+ if (segmentLength < 11)
247
+ return void 0;
248
+ const componentCount = buffer[offset + 7];
249
+ if (componentCount === 0 || segmentLength !== 8 + componentCount * 3)
250
+ return void 0;
251
+ return validDimensions(buffer.readUInt16BE(offset + 5), buffer.readUInt16BE(offset + 3));
252
+ }
253
+ offset += segmentLength;
254
+ }
255
+ return void 0;
256
+ }
257
+ function parseIco(buffer) {
258
+ if (buffer.length < 6 || buffer.readUInt16LE(0) !== 0 || buffer.readUInt16LE(2) !== 1)
259
+ return void 0;
260
+ const count = buffer.readUInt16LE(4);
261
+ const directoryEnd = 6 + count * 16;
262
+ if (count === 0 || directoryEnd > buffer.length)
263
+ return void 0;
264
+ const images = Array.from({ length: count }, (_, index) => {
265
+ const offset = 6 + index * 16;
266
+ const payloadSize = buffer.readUInt32LE(offset + 8);
267
+ const payloadOffset = buffer.readUInt32LE(offset + 12);
268
+ if (payloadSize === 0 || payloadOffset < directoryEnd || payloadOffset > buffer.length - payloadSize)
269
+ return void 0;
270
+ return {
271
+ width: buffer[offset] || 256,
272
+ height: buffer[offset + 1] || 256
273
+ };
274
+ });
275
+ if (images.includes(void 0))
276
+ return void 0;
277
+ const validImages = images;
278
+ const largestImage = validImages.reduce((largest, image) => image.width * image.height > largest.width * largest.height ? image : largest);
279
+ return { ...largestImage, images: validImages };
280
+ }
281
+ function parseSvgLength(root, name) {
282
+ const value = root.match(new RegExp(`(?:^|\\s)${name}\\s*=\\s*["']([^"']+)["']`, "i"))?.[1]?.trim();
283
+ if (!value)
284
+ return void 0;
285
+ const match = SVG_LENGTH_RE.exec(value);
286
+ if (!match)
287
+ return void 0;
288
+ const parsed = Number(match[1]) * (SVG_UNIT_PIXELS[match[2]?.toLowerCase() || "px"] || 1);
289
+ return Number.isFinite(parsed) && parsed > 0 ? Math.round(parsed) : void 0;
290
+ }
291
+ function parseSvg(buffer) {
292
+ const source = buffer.toString("utf8", 0, Math.min(buffer.length, 4096));
293
+ const rootStart = source.search(SVG_ROOT_RE);
294
+ const rootEnd = source.indexOf(">", rootStart);
295
+ if (rootStart < 0 || rootEnd < 0)
296
+ return void 0;
297
+ const root = source.slice(rootStart, rootEnd + 1);
298
+ const width = parseSvgLength(root, "width");
299
+ const height = parseSvgLength(root, "height");
300
+ if (width && height)
301
+ return { width, height };
302
+ const viewBox = root.match(/(?:^|\s)viewBox\s*=\s*["']([^"']+)["']/i)?.[1]?.trim().split(/[\s,]+/).map(Number);
303
+ if (!viewBox || viewBox.length !== 4 || !viewBox.every((value) => Number.isFinite(value)))
304
+ return void 0;
305
+ const viewBoxDimensions = validDimensions(Math.round(viewBox[2]), Math.round(viewBox[3]));
306
+ if (!viewBoxDimensions)
307
+ return void 0;
308
+ if (width)
309
+ return { width, height: Math.floor(width * viewBoxDimensions.height / viewBoxDimensions.width) };
310
+ if (height)
311
+ return { width: Math.floor(height * viewBoxDimensions.width / viewBoxDimensions.height), height };
312
+ return viewBoxDimensions;
313
+ }
314
+ function parseImageDimensions(buffer) {
315
+ return parsePng(buffer) || parseGif(buffer) || parseJpeg(buffer) || parseIco(buffer) || parseSvg(buffer);
316
+ }
317
+
190
318
  function hasMetaProperty(input, property) {
191
319
  return input.meta?.some((meta) => meta.property === property);
192
320
  }
@@ -227,7 +355,14 @@ async function getImageMeta(base, path, isIcon = false) {
227
355
  }
228
356
  async function getImageDimensions(absolutePath) {
229
357
  const buffer = await readFile(absolutePath);
230
- return imageSize(buffer);
358
+ const dimensions = parseImageDimensions(buffer);
359
+ if (!dimensions)
360
+ throw new TypeError(`Unsupported image format: ${absolutePath}`);
361
+ return {
362
+ width: dimensions.width,
363
+ height: dimensions.height,
364
+ images: dimensions.images
365
+ };
231
366
  }
232
367
 
233
368
  const DIR_SUFFIX_RE = /\/_dir$/;
@@ -615,7 +750,7 @@ const module$1 = defineNuxtModule({
615
750
  automaticOgAndTwitterTags: true,
616
751
  canonicalLowercase: true,
617
752
  tagPriority: "low",
618
- minify: true
753
+ minify: { build: true, runtime: false }
619
754
  },
620
755
  async setup(config, nuxt) {
621
756
  const logger = useModuleLogger("nuxt-seo-utils", config, nuxt);
@@ -1,23 +1,32 @@
1
1
  export const JSON_TYPES = /* @__PURE__ */ new Set(["application/json", "application/ld+json"]);
2
2
  export const SKIP_JS_TYPES = /* @__PURE__ */ new Set(["application/json", "application/ld+json", "speculationrules", "importmap"]);
3
+ const JS_MINIFY_CANDIDATE_RE = /[\s/]/;
4
+ const CSS_MINIFY_CANDIDATE_RE = /[\s/]|;\}|0\.\d/;
3
5
  export function minifyJS(code) {
6
+ if (!JS_MINIFY_CANDIDATE_RE.test(code))
7
+ return code;
4
8
  let result = "";
9
+ let last = "";
5
10
  let i = 0;
6
11
  const len = code.length;
12
+ const append = (value) => {
13
+ result += value;
14
+ last = value;
15
+ };
7
16
  while (i < len) {
8
17
  const ch = code[i];
9
18
  if (ch === "'" || ch === '"' || ch === "`") {
10
19
  const quote = ch;
11
- result += ch;
20
+ append(ch);
12
21
  i++;
13
22
  while (i < len && code[i] !== quote) {
14
23
  if (code[i] === "\\") {
15
- result += code[i++];
24
+ append(code[i++]);
16
25
  }
17
- result += code[i++];
26
+ append(code[i++]);
18
27
  }
19
28
  if (i < len)
20
- result += code[i++];
29
+ append(code[i++]);
21
30
  } else if (ch === "/" && code[i + 1] === "/") {
22
31
  i += 2;
23
32
  while (i < len && code[i] !== "\n")
@@ -34,65 +43,70 @@ export function minifyJS(code) {
34
43
  hasNewline = true;
35
44
  i++;
36
45
  }
37
- const prev = result.at(-1);
38
46
  const next = code[i];
39
- if (hasNewline && prev && next && prev !== "{" && prev !== "}" && prev !== ";" && next !== "}" && next !== ";")
40
- result += "\n";
41
- else if (prev && next && isIdentChar(prev) && isIdentChar(next))
42
- result += " ";
43
- else if (prev && next && (prev === "+" && next === "+" || prev === "-" && next === "-"))
44
- result += " ";
47
+ if (hasNewline && last && next && last !== "{" && last !== "}" && last !== ";" && next !== "}" && next !== ";")
48
+ append("\n");
49
+ else if (last && next && isIdentChar(last) && isIdentChar(next))
50
+ append(" ");
51
+ else if (last && next && (last === "+" && next === "+" || last === "-" && next === "-"))
52
+ append(" ");
45
53
  } else {
46
- result += ch;
54
+ append(ch);
47
55
  i++;
48
56
  }
49
57
  }
50
58
  return result.trim();
51
59
  }
52
60
  export function minifyCSS(code) {
61
+ if (!CSS_MINIFY_CANDIDATE_RE.test(code))
62
+ return code;
53
63
  let result = "";
64
+ let last = "";
54
65
  let i = 0;
55
66
  const parenStack = [];
56
67
  const len = code.length;
68
+ const append = (value) => {
69
+ result += value;
70
+ last = value;
71
+ };
57
72
  while (i < len) {
58
73
  const ch = code[i];
59
74
  if (ch === "'" || ch === '"') {
60
75
  const quote = ch;
61
- result += ch;
76
+ append(ch);
62
77
  i++;
63
78
  while (i < len && code[i] !== quote) {
64
79
  if (code[i] === "\\")
65
- result += code[i++];
66
- result += code[i++];
80
+ append(code[i++]);
81
+ append(code[i++]);
67
82
  }
68
83
  if (i < len)
69
- result += code[i++];
84
+ append(code[i++]);
70
85
  } else if (ch === "/" && code[i + 1] === "*") {
71
86
  i += 2;
72
87
  while (i < len && !(code[i] === "*" && code[i + 1] === "/"))
73
88
  i++;
74
89
  i += 2;
75
90
  } else if (ch === "(") {
76
- parenStack.push(isSelectorFunctionParen(result));
77
- result += ch;
91
+ parenStack.push(isSelectorFunctionParen(code, i));
92
+ append(ch);
78
93
  i++;
79
94
  } else if (ch === ")") {
80
95
  parenStack.pop();
81
- result += ch;
96
+ append(ch);
82
97
  i++;
83
98
  } else if (ch === " " || ch === " " || ch === "\n" || ch === "\r") {
84
99
  while (i < len && (code[i] === " " || code[i] === " " || code[i] === "\n" || code[i] === "\r"))
85
100
  i++;
86
- const prev = result.at(-1);
87
101
  const next = code[i];
88
102
  if (next === "!")
89
103
  continue;
90
104
  if (parenStack.length > 0) {
91
105
  const isPunct = parenStack[parenStack.length - 1] ? isCSSPunctuation : isCSSCalcPunctuation;
92
- if (prev && next && !isPunct(prev) && !isPunct(next))
93
- result += " ";
94
- } else if (prev && next && !isCSSPunctuation(prev) && !isCSSPunctuation(next)) {
95
- result += " ";
106
+ if (last && next && !isPunct(last) && !isPunct(next))
107
+ append(" ");
108
+ } else if (last && next && !isCSSPunctuation(last) && !isCSSPunctuation(next)) {
109
+ append(" ");
96
110
  }
97
111
  } else if (ch === ";") {
98
112
  let j = i + 1;
@@ -101,19 +115,18 @@ export function minifyCSS(code) {
101
115
  if (code[j] === "}") {
102
116
  i++;
103
117
  } else {
104
- result += ch;
118
+ append(ch);
105
119
  i++;
106
120
  }
107
121
  } else if (ch === "0" && code[i + 1] === "." && (code[i + 2] ?? "") >= "0" && (code[i + 2] ?? "") <= "9") {
108
- const prev = result.at(-1);
109
- if (prev && prev >= "0" && prev <= "9") {
110
- result += ch;
122
+ if (last && last >= "0" && last <= "9") {
123
+ append(ch);
111
124
  i++;
112
125
  } else {
113
126
  i++;
114
127
  }
115
128
  } else {
116
- result += ch;
129
+ append(ch);
117
130
  i++;
118
131
  }
119
132
  }
@@ -134,13 +147,13 @@ function isCSSCalcPunctuation(ch) {
134
147
  function isCSSNameChar(ch) {
135
148
  return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch === "-";
136
149
  }
137
- function isSelectorFunctionParen(result) {
138
- let j = result.length - 1;
139
- while (j >= 0 && isCSSNameChar(result[j]))
150
+ function isSelectorFunctionParen(code, parenIndex) {
151
+ let j = parenIndex - 1;
152
+ while (j >= 0 && isCSSNameChar(code[j]))
140
153
  j--;
141
- if (result[j] !== ":")
154
+ if (code[j] !== ":")
142
155
  return false;
143
- const name = result.slice(j + 1).toLowerCase();
156
+ const name = code.slice(j + 1, parenIndex).toLowerCase();
144
157
  return name === "is" || name === "where" || name === "not" || name === "has" || name === "matches" || name === "host" || name === "host-context" || name === "slotted";
145
158
  }
146
159
  export function minifyJSON(code) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-seo-utils",
3
3
  "type": "module",
4
- "version": "8.4.0",
4
+ "version": "8.4.2",
5
5
  "description": "SEO utilities to improve your Nuxt sites discoverability and shareability",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -62,15 +62,14 @@
62
62
  }
63
63
  },
64
64
  "dependencies": {
65
- "@nuxt/kit": "^4.5.1",
65
+ "@nuxt/kit": "^4.5.2",
66
66
  "citty": "^0.2.2",
67
67
  "consola": "^3.4.2",
68
68
  "defu": "^6.1.7",
69
69
  "escape-string-regexp": "^5.0.0",
70
70
  "exsolve": "^1.1.1",
71
- "image-size": "^2.0.2",
72
- "nuxt-site-config": "^4.1.4",
73
- "nuxtseo-shared": "^5.3.11",
71
+ "nuxt-site-config": "^4.2.2",
72
+ "nuxtseo-shared": "^5.3.12",
74
73
  "pathe": "^2.0.3",
75
74
  "pkg-types": "^2.3.1",
76
75
  "scule": "^1.3.0",
@@ -81,36 +80,36 @@
81
80
  "sharp": "^0.35.3"
82
81
  },
83
82
  "devDependencies": {
84
- "@antfu/eslint-config": "^9.2.0",
83
+ "@antfu/eslint-config": "^9.3.0",
85
84
  "@nuxt/devtools-kit": "4.0.0-alpha.9",
86
85
  "@nuxt/module-builder": "^1.0.3",
87
- "@nuxt/schema": "^4.5.1",
86
+ "@nuxt/schema": "^4.5.2",
88
87
  "@nuxt/test-utils": "^4.1.0",
89
88
  "@nuxt/ui": "^4.10.0",
90
- "@nuxtjs/i18n": "^10.5.0",
91
- "@types/node": "^26.1.2",
89
+ "@nuxtjs/i18n": "^10.6.0",
90
+ "@types/node": "^26.2.0",
92
91
  "@unhead/vue": "3.2.3",
93
92
  "@vue/test-utils": "^2.4.11",
94
- "bumpp": "^12.0.0",
93
+ "bumpp": "^12.2.0",
95
94
  "case-police": "^2.2.1",
96
95
  "cheerio": "^1.2.0",
97
- "eslint": "^10.8.0",
96
+ "eslint": "^10.8.1",
98
97
  "eslint-plugin-harlanzw": "^0.17.1",
99
- "happy-dom": "^20.11.1",
100
- "lint-staged": "^17.2.0",
98
+ "happy-dom": "^20.11.2",
99
+ "lint-staged": "^17.3.0",
101
100
  "markdownlint-cli": "^0.49.1",
102
- "nuxt": "^4.5.1",
101
+ "nuxt": "^4.5.2",
103
102
  "nuxt-security": "^2.6.0",
104
- "nuxtseo-layer-devtools": "^5.3.6",
105
- "playwright-core": "^1.62.0",
103
+ "nuxtseo-layer-devtools": "^5.3.12",
104
+ "playwright-core": "^1.62.1",
106
105
  "sass": "^1.102.0",
107
106
  "typescript": "6.0.3",
108
107
  "ultrahtml": "^1.7.0",
109
108
  "unbuild": "^3.6.1",
110
109
  "unhead": "3.2.3",
111
110
  "vitest": "^4.1.10",
112
- "vue": "^3.5.40",
113
- "vue-tsc": "^3.3.8"
111
+ "vue": "^3.5.41",
112
+ "vue-tsc": "^3.3.9"
114
113
  },
115
114
  "scripts": {
116
115
  "client:build": "node -e \"require('fs').cpSync('devtools','dist/devtools',{recursive:true})\"",