@rankcli/agent-runtime 0.0.15 → 0.0.16

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.
Files changed (202) hide show
  1. package/dist/index.d.mts +43 -393
  2. package/dist/index.d.ts +43 -393
  3. package/dist/index.js +306 -6526
  4. package/dist/index.mjs +202 -6412
  5. package/package.json +6 -1
  6. package/scripts/build-deno.ts +0 -134
  7. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  8. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  9. package/src/analyzers/geo-analyzer.test.ts +0 -310
  10. package/src/analyzers/geo-analyzer.ts +0 -814
  11. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  12. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  13. package/src/analyzers/index.ts +0 -233
  14. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  15. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  16. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  17. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  18. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  19. package/src/analyzers/security-headers-analyzer.ts +0 -318
  20. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  21. package/src/analyzers/structured-data-analyzer.ts +0 -590
  22. package/src/audit/ai/analyzer.ts +0 -347
  23. package/src/audit/ai/index.ts +0 -29
  24. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  25. package/src/audit/ai/types.ts +0 -179
  26. package/src/audit/checks/additional-checks.ts +0 -439
  27. package/src/audit/checks/agent-experience.ts +0 -108
  28. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  29. package/src/audit/checks/ai-content-structure.ts +0 -325
  30. package/src/audit/checks/ai-readiness.ts +0 -406
  31. package/src/audit/checks/anchor-text.ts +0 -179
  32. package/src/audit/checks/answer-conciseness.ts +0 -322
  33. package/src/audit/checks/asset-minification.ts +0 -270
  34. package/src/audit/checks/bing-optimization.ts +0 -206
  35. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  36. package/src/audit/checks/caching-headers.ts +0 -305
  37. package/src/audit/checks/canonical-advanced.ts +0 -150
  38. package/src/audit/checks/canonical-domain.ts +0 -196
  39. package/src/audit/checks/citation-quality.ts +0 -358
  40. package/src/audit/checks/client-rendering.ts +0 -542
  41. package/src/audit/checks/color-contrast.ts +0 -342
  42. package/src/audit/checks/content-freshness.ts +0 -170
  43. package/src/audit/checks/content-science.ts +0 -589
  44. package/src/audit/checks/conversion-elements.ts +0 -526
  45. package/src/audit/checks/crawlability.ts +0 -220
  46. package/src/audit/checks/directory-listing.ts +0 -172
  47. package/src/audit/checks/dom-analysis.ts +0 -191
  48. package/src/audit/checks/dom-size.ts +0 -246
  49. package/src/audit/checks/duplicate-content.ts +0 -194
  50. package/src/audit/checks/eeat-signals.ts +0 -990
  51. package/src/audit/checks/entity-seo.ts +0 -396
  52. package/src/audit/checks/featured-snippet.ts +0 -473
  53. package/src/audit/checks/freshness-signals.ts +0 -443
  54. package/src/audit/checks/funnel-intent.ts +0 -463
  55. package/src/audit/checks/hreflang.ts +0 -174
  56. package/src/audit/checks/html-compliance.ts +0 -302
  57. package/src/audit/checks/image-dimensions.ts +0 -167
  58. package/src/audit/checks/images.ts +0 -160
  59. package/src/audit/checks/indexnow.ts +0 -275
  60. package/src/audit/checks/interactive-tools.ts +0 -475
  61. package/src/audit/checks/internal-link-graph.ts +0 -436
  62. package/src/audit/checks/keyword-analysis.ts +0 -239
  63. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  64. package/src/audit/checks/keyword-placement.ts +0 -471
  65. package/src/audit/checks/links.ts +0 -273
  66. package/src/audit/checks/llms-txt.ts +0 -224
  67. package/src/audit/checks/local-seo.ts +0 -296
  68. package/src/audit/checks/mobile.ts +0 -167
  69. package/src/audit/checks/modern-images.ts +0 -226
  70. package/src/audit/checks/navboost-signals.ts +0 -395
  71. package/src/audit/checks/on-page.ts +0 -209
  72. package/src/audit/checks/page-resources.ts +0 -285
  73. package/src/audit/checks/pagination.ts +0 -180
  74. package/src/audit/checks/performance.ts +0 -153
  75. package/src/audit/checks/platform-presence.ts +0 -580
  76. package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
  77. package/src/audit/checks/rag-chunk-readiness.ts +0 -163
  78. package/src/audit/checks/redirect-analysis.ts +0 -153
  79. package/src/audit/checks/redirect-chain.ts +0 -389
  80. package/src/audit/checks/resource-hints.ts +0 -420
  81. package/src/audit/checks/responsive-css.ts +0 -247
  82. package/src/audit/checks/responsive-images.ts +0 -396
  83. package/src/audit/checks/review-ecosystem.ts +0 -415
  84. package/src/audit/checks/robots-validation.ts +0 -373
  85. package/src/audit/checks/security-headers.ts +0 -188
  86. package/src/audit/checks/security.ts +0 -144
  87. package/src/audit/checks/serp-preview.ts +0 -251
  88. package/src/audit/checks/site-maturity.ts +0 -453
  89. package/src/audit/checks/social-meta.test.ts +0 -275
  90. package/src/audit/checks/social-meta.ts +0 -134
  91. package/src/audit/checks/soft-404.ts +0 -151
  92. package/src/audit/checks/structured-data.ts +0 -238
  93. package/src/audit/checks/tech-detection.ts +0 -496
  94. package/src/audit/checks/topical-clusters.ts +0 -435
  95. package/src/audit/checks/tracker-bloat.ts +0 -462
  96. package/src/audit/checks/tracking-verification.test.ts +0 -371
  97. package/src/audit/checks/tracking-verification.ts +0 -636
  98. package/src/audit/checks/url-safety.ts +0 -682
  99. package/src/audit/deno-entry.ts +0 -66
  100. package/src/audit/discovery/index.ts +0 -15
  101. package/src/audit/discovery/link-crawler.ts +0 -233
  102. package/src/audit/discovery/repo-routes.ts +0 -347
  103. package/src/audit/engine.ts +0 -633
  104. package/src/audit/fixes/index.ts +0 -209
  105. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  106. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  107. package/src/audit/index.ts +0 -74
  108. package/src/audit/runner.test.ts +0 -299
  109. package/src/audit/runner.ts +0 -130
  110. package/src/audit/types.ts +0 -1987
  111. package/src/content/featured-snippet.ts +0 -367
  112. package/src/content/generator.test.ts +0 -534
  113. package/src/content/generator.ts +0 -501
  114. package/src/content/headline.ts +0 -317
  115. package/src/content/index.ts +0 -62
  116. package/src/content/intent.ts +0 -258
  117. package/src/content/keyword-density.ts +0 -349
  118. package/src/content/readability.ts +0 -262
  119. package/src/executor.ts +0 -336
  120. package/src/fixer/framework-fixes.test.ts +0 -489
  121. package/src/fixer/framework-fixes.ts +0 -5287
  122. package/src/fixer/index.ts +0 -6
  123. package/src/fixer/schemas.ts +0 -971
  124. package/src/fixer.ts +0 -642
  125. package/src/frameworks/detector.test.ts +0 -248
  126. package/src/frameworks/detector.ts +0 -899
  127. package/src/frameworks/index.ts +0 -68
  128. package/src/frameworks/recipes/angular.yaml +0 -171
  129. package/src/frameworks/recipes/astro.yaml +0 -206
  130. package/src/frameworks/recipes/django.yaml +0 -180
  131. package/src/frameworks/recipes/laravel.yaml +0 -137
  132. package/src/frameworks/recipes/nextjs.yaml +0 -268
  133. package/src/frameworks/recipes/nuxt.yaml +0 -175
  134. package/src/frameworks/recipes/rails.yaml +0 -188
  135. package/src/frameworks/recipes/react.yaml +0 -202
  136. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  137. package/src/frameworks/recipes/vue.yaml +0 -137
  138. package/src/frameworks/recipes/wordpress.yaml +0 -209
  139. package/src/frameworks/suggestion-engine.ts +0 -357
  140. package/src/geo/geo-content.test.ts +0 -305
  141. package/src/geo/geo-content.ts +0 -266
  142. package/src/geo/geo-history.test.ts +0 -473
  143. package/src/geo/geo-history.ts +0 -433
  144. package/src/geo/geo-tracker.test.ts +0 -359
  145. package/src/geo/geo-tracker.ts +0 -411
  146. package/src/geo/index.ts +0 -11
  147. package/src/geo/llm-citation-checker.ts +0 -188
  148. package/src/git/commit-helper.test.ts +0 -261
  149. package/src/git/commit-helper.ts +0 -329
  150. package/src/git/index.ts +0 -12
  151. package/src/git/pr-helper.test.ts +0 -284
  152. package/src/git/pr-helper.ts +0 -307
  153. package/src/index.ts +0 -76
  154. package/src/keywords/ai-keyword-engine.ts +0 -1062
  155. package/src/keywords/ai-summarizer.ts +0 -387
  156. package/src/keywords/ci-mode.ts +0 -555
  157. package/src/keywords/engine.ts +0 -359
  158. package/src/keywords/index.ts +0 -151
  159. package/src/keywords/llm-judge.ts +0 -357
  160. package/src/keywords/nlp-analysis.ts +0 -706
  161. package/src/keywords/prioritizer.ts +0 -295
  162. package/src/keywords/site-crawler.ts +0 -342
  163. package/src/keywords/sources/autocomplete.ts +0 -139
  164. package/src/keywords/sources/competitive-search.ts +0 -450
  165. package/src/keywords/sources/competitor-analysis.ts +0 -374
  166. package/src/keywords/sources/dataforseo.ts +0 -206
  167. package/src/keywords/sources/free-sources.ts +0 -294
  168. package/src/keywords/sources/gsc.ts +0 -123
  169. package/src/keywords/topic-grouping.ts +0 -327
  170. package/src/keywords/types.ts +0 -144
  171. package/src/keywords/wizard.ts +0 -457
  172. package/src/loader.ts +0 -40
  173. package/src/ranking/index.ts +0 -5
  174. package/src/ranking/serp-client.ts +0 -348
  175. package/src/ranking/tracker.ts +0 -380
  176. package/src/ranking/types.ts +0 -123
  177. package/src/reports/index.ts +0 -7
  178. package/src/reports/report-generator.test.ts +0 -293
  179. package/src/reports/report-generator.ts +0 -713
  180. package/src/scheduler/alerts.test.ts +0 -458
  181. package/src/scheduler/alerts.ts +0 -328
  182. package/src/scheduler/index.ts +0 -8
  183. package/src/scheduler/scheduled-audit.test.ts +0 -377
  184. package/src/scheduler/scheduled-audit.ts +0 -149
  185. package/src/test/integration-test.ts +0 -325
  186. package/src/tools/analyzer.ts +0 -373
  187. package/src/tools/crawl.ts +0 -293
  188. package/src/tools/files.ts +0 -301
  189. package/src/tools/h1-fixer.ts +0 -249
  190. package/src/tools/index.ts +0 -67
  191. package/src/tracking/github-action.ts +0 -326
  192. package/src/tracking/google-analytics.ts +0 -265
  193. package/src/tracking/index.ts +0 -45
  194. package/src/tracking/report-generator.ts +0 -386
  195. package/src/tracking/search-console.ts +0 -335
  196. package/src/types.ts +0 -148
  197. package/src/utils/http.ts +0 -302
  198. package/src/wasm-adapter.ts +0 -297
  199. package/src/wasm-entry.ts +0 -14
  200. package/tsconfig.json +0 -17
  201. package/tsup.wasm.config.ts +0 -26
  202. package/vitest.config.ts +0 -15
@@ -1,296 +0,0 @@
1
- // Local SEO Checks
2
- // Checks for LocalBusiness schema, NAP consistency, address/phone detection
3
-
4
- import * as cheerio from 'cheerio';
5
- import type { AuditIssue } from '../types.js';
6
- import { ISSUE_DEFINITIONS } from '../types.js';
7
-
8
- // Phone number patterns
9
- const PHONE_PATTERNS = [
10
- /\+?1?[-.\s]?\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}/g, // US/Canada
11
- /\+?[0-9]{1,3}[-.\s]?[0-9]{2,4}[-.\s]?[0-9]{3,4}[-.\s]?[0-9]{3,4}/g, // International
12
- /\b[0-9]{3}[-.\s][0-9]{3}[-.\s][0-9]{4}\b/g, // Simple US format
13
- ];
14
-
15
- // Address patterns (simplified)
16
- const ADDRESS_PATTERNS = [
17
- /\d+\s+[\w\s]+(?:street|st|avenue|ave|road|rd|boulevard|blvd|drive|dr|lane|ln|way|court|ct|circle|cir|place|pl)[\s,]+[\w\s]+,?\s*(?:AL|AK|AZ|AR|CA|CO|CT|DE|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY)\s*\d{5}/gi,
18
- /\d+\s+[\w\s]+,\s*[\w\s]+,\s*[A-Z]{2}\s*\d{5}/gi, // Generic US address
19
- ];
20
-
21
- export interface LocalSEOData {
22
- hasLocalBusinessSchema: boolean;
23
- hasOrganizationSchema: boolean;
24
- detectedPhones: string[];
25
- detectedAddresses: string[];
26
- schemaData: {
27
- name?: string;
28
- address?: string;
29
- phone?: string;
30
- hours?: string[];
31
- geo?: { lat: number; lng: number };
32
- } | null;
33
- socialProfiles: string[];
34
- }
35
-
36
- /**
37
- * Extract and validate LocalBusiness/Organization schema
38
- */
39
- function extractSchema(html: string): {
40
- hasLocalBusiness: boolean;
41
- hasOrganization: boolean;
42
- schemaData: LocalSEOData['schemaData'];
43
- } {
44
- const $ = cheerio.load(html);
45
- let hasLocalBusiness = false;
46
- let hasOrganization = false;
47
- let schemaData: LocalSEOData['schemaData'] = null;
48
-
49
- // Find JSON-LD scripts
50
- $('script[type="application/ld+json"]').each((_, el) => {
51
- try {
52
- const content = $(el).html();
53
- if (!content) return;
54
-
55
- const jsonData = JSON.parse(content);
56
- const schemas = Array.isArray(jsonData) ? jsonData : [jsonData];
57
-
58
- for (const schema of schemas) {
59
- // Handle @graph structure
60
- const items = schema['@graph'] || [schema];
61
-
62
- for (const item of items) {
63
- const type = item['@type'];
64
-
65
- // Check for LocalBusiness and its subtypes
66
- const localBusinessTypes = [
67
- 'LocalBusiness',
68
- 'Restaurant',
69
- 'Store',
70
- 'MedicalBusiness',
71
- 'FinancialService',
72
- 'FoodEstablishment',
73
- 'HealthAndBeautyBusiness',
74
- 'HomeAndConstructionBusiness',
75
- 'LegalService',
76
- 'RealEstateAgent',
77
- 'SportsActivityLocation',
78
- ];
79
-
80
- if (localBusinessTypes.some((t) => type === t || (Array.isArray(type) && type.includes(t)))) {
81
- hasLocalBusiness = true;
82
- schemaData = {
83
- name: item.name,
84
- address: formatAddress(item.address),
85
- phone: item.telephone,
86
- hours: item.openingHours,
87
- geo: item.geo ? { lat: item.geo.latitude, lng: item.geo.longitude } : undefined,
88
- };
89
- }
90
-
91
- if (type === 'Organization' || type === 'Corporation' || type === 'Person') {
92
- hasOrganization = true;
93
- if (!schemaData) {
94
- schemaData = {
95
- name: item.name,
96
- address: formatAddress(item.address),
97
- phone: item.telephone,
98
- };
99
- }
100
- }
101
- }
102
- }
103
- } catch {
104
- // Invalid JSON-LD, skip
105
- }
106
- });
107
-
108
- return { hasLocalBusiness, hasOrganization, schemaData };
109
- }
110
-
111
- /**
112
- * Format address from schema
113
- */
114
- function formatAddress(address: unknown): string | undefined {
115
- if (!address) return undefined;
116
- if (typeof address === 'string') return address;
117
- if (typeof address === 'object' && address !== null) {
118
- const a = address as Record<string, string>;
119
- return [a.streetAddress, a.addressLocality, a.addressRegion, a.postalCode, a.addressCountry].filter(Boolean).join(', ');
120
- }
121
- return undefined;
122
- }
123
-
124
- /**
125
- * Detect phone numbers in page content
126
- */
127
- function detectPhones(html: string): string[] {
128
- const $ = cheerio.load(html);
129
- const text = $('body').text();
130
- const phones = new Set<string>();
131
-
132
- // Find tel: links
133
- $('a[href^="tel:"]').each((_, el) => {
134
- const href = $(el).attr('href');
135
- if (href) {
136
- phones.add(href.replace('tel:', '').trim());
137
- }
138
- });
139
-
140
- // Find phone patterns in text
141
- for (const pattern of PHONE_PATTERNS) {
142
- const matches = text.match(pattern);
143
- if (matches) {
144
- matches.forEach((m) => phones.add(m.trim()));
145
- }
146
- }
147
-
148
- // Filter out obviously invalid numbers
149
- return Array.from(phones).filter((phone) => {
150
- const digits = phone.replace(/\D/g, '');
151
- return digits.length >= 10 && digits.length <= 15;
152
- });
153
- }
154
-
155
- /**
156
- * Detect addresses in page content
157
- */
158
- function detectAddresses(html: string): string[] {
159
- const $ = cheerio.load(html);
160
- const text = $('body').text();
161
- const addresses = new Set<string>();
162
-
163
- // Find address patterns
164
- for (const pattern of ADDRESS_PATTERNS) {
165
- const matches = text.match(pattern);
166
- if (matches) {
167
- matches.forEach((m) => addresses.add(m.trim()));
168
- }
169
- }
170
-
171
- // Check for schema addresses
172
- $('[itemprop="address"]').each((_, el) => {
173
- const addr = $(el).text().trim();
174
- if (addr) addresses.add(addr);
175
- });
176
-
177
- return Array.from(addresses);
178
- }
179
-
180
- /**
181
- * Detect linked social profiles
182
- */
183
- function detectSocialProfiles(html: string): string[] {
184
- const $ = cheerio.load(html);
185
- const profiles: string[] = [];
186
-
187
- const socialDomains = [
188
- 'facebook.com',
189
- 'twitter.com',
190
- 'x.com',
191
- 'linkedin.com',
192
- 'instagram.com',
193
- 'youtube.com',
194
- 'tiktok.com',
195
- 'pinterest.com',
196
- 'github.com',
197
- ];
198
-
199
- $('a[href]').each((_, el) => {
200
- const href = $(el).attr('href');
201
- if (!href) return;
202
-
203
- for (const domain of socialDomains) {
204
- if (href.includes(domain)) {
205
- // Normalize the URL
206
- try {
207
- const url = new URL(href);
208
- if (!profiles.includes(url.href)) {
209
- profiles.push(url.href);
210
- }
211
- } catch {
212
- // Invalid URL, skip
213
- }
214
- break;
215
- }
216
- }
217
- });
218
-
219
- return profiles;
220
- }
221
-
222
- /**
223
- * Analyze local SEO elements
224
- */
225
- export function analyzeLocalSEO(html: string, url: string): { issues: AuditIssue[]; data: LocalSEOData } {
226
- const issues: AuditIssue[] = [];
227
-
228
- // Extract schema
229
- const { hasLocalBusiness, hasOrganization, schemaData } = extractSchema(html);
230
-
231
- // Detect phones and addresses
232
- const detectedPhones = detectPhones(html);
233
- const detectedAddresses = detectAddresses(html);
234
-
235
- // Detect social profiles
236
- const socialProfiles = detectSocialProfiles(html);
237
-
238
- // Generate issues
239
- if (!hasLocalBusiness) {
240
- issues.push({
241
- ...ISSUE_DEFINITIONS.LOCAL_BUSINESS_SCHEMA_MISSING,
242
- affectedUrls: [url],
243
- });
244
- }
245
-
246
- if (!hasOrganization && !hasLocalBusiness) {
247
- issues.push({
248
- ...ISSUE_DEFINITIONS.ORGANIZATION_SCHEMA_MISSING,
249
- affectedUrls: [url],
250
- });
251
- }
252
-
253
- // Only flag missing address/phone for pages that appear to be business pages
254
- const $ = cheerio.load(html);
255
- const isBusinessPage =
256
- $('a[href^="tel:"]').length > 0 ||
257
- $('a[href^="mailto:"]').length > 0 ||
258
- html.toLowerCase().includes('contact') ||
259
- html.toLowerCase().includes('about us');
260
-
261
- if (isBusinessPage) {
262
- if (detectedAddresses.length === 0 && !schemaData?.address) {
263
- issues.push({
264
- ...ISSUE_DEFINITIONS.ADDRESS_NOT_DETECTED,
265
- affectedUrls: [url],
266
- });
267
- }
268
-
269
- if (detectedPhones.length === 0 && !schemaData?.phone) {
270
- issues.push({
271
- ...ISSUE_DEFINITIONS.PHONE_NOT_DETECTED,
272
- affectedUrls: [url],
273
- });
274
- }
275
- }
276
-
277
- // Check for social profiles
278
- if (socialProfiles.length === 0) {
279
- issues.push({
280
- ...ISSUE_DEFINITIONS.SOCIAL_PROFILES_NOT_LINKED,
281
- affectedUrls: [url],
282
- });
283
- }
284
-
285
- return {
286
- issues,
287
- data: {
288
- hasLocalBusinessSchema: hasLocalBusiness,
289
- hasOrganizationSchema: hasOrganization,
290
- detectedPhones,
291
- detectedAddresses,
292
- schemaData,
293
- socialProfiles,
294
- },
295
- };
296
- }
@@ -1,167 +0,0 @@
1
- import * as cheerio from 'cheerio';
2
- import type { AuditIssue } from '../types.js';
3
- import { ISSUE_DEFINITIONS } from '../types.js';
4
-
5
- export interface MobileData {
6
- hasViewport: boolean;
7
- viewportContent?: string;
8
- isResponsive: boolean;
9
- tapTargetIssues: number;
10
- fontSizeIssues: number;
11
- }
12
-
13
- export function analyzeMobile(html: string, url: string): { issues: AuditIssue[]; data: MobileData } {
14
- const issues: AuditIssue[] = [];
15
- const $ = cheerio.load(html);
16
-
17
- // Check viewport meta tag
18
- const viewportMeta = $('meta[name="viewport"]');
19
- const hasViewport = viewportMeta.length > 0;
20
- const viewportContent = viewportMeta.attr('content');
21
-
22
- if (!hasViewport) {
23
- issues.push({
24
- ...ISSUE_DEFINITIONS.VIEWPORT_MISSING,
25
- affectedUrls: [url],
26
- });
27
- } else if (viewportContent) {
28
- // Check if viewport is responsive
29
- const isResponsive = viewportContent.includes('width=device-width');
30
-
31
- if (!isResponsive) {
32
- // Check for fixed width
33
- const widthMatch = viewportContent.match(/width=(\d+)/);
34
- if (widthMatch) {
35
- issues.push({
36
- ...ISSUE_DEFINITIONS.VIEWPORT_NOT_RESPONSIVE,
37
- affectedUrls: [url],
38
- details: {
39
- viewport: viewportContent,
40
- fixedWidth: widthMatch[1],
41
- },
42
- });
43
- }
44
- }
45
-
46
- // Check for user-scalable=no (bad for accessibility)
47
- if (viewportContent.includes('user-scalable=no') || viewportContent.includes('user-scalable=0')) {
48
- issues.push({
49
- code: 'VIEWPORT_NO_ZOOM',
50
- severity: 'warning',
51
- category: 'mobile',
52
- title: 'Viewport prevents zooming',
53
- description: 'The viewport meta tag disables user scaling.',
54
- impact: 'Users with visual impairments cannot zoom the page.',
55
- howToFix: 'Remove user-scalable=no from the viewport meta tag.',
56
- affectedUrls: [url],
57
- });
58
- }
59
- }
60
-
61
- // Check for tap target issues (basic heuristic)
62
- // In a real implementation, this would analyze CSS computed styles
63
- let tapTargetIssues = 0;
64
- $('a, button, input, select, textarea').each((_, el) => {
65
- const style = $(el).attr('style') || '';
66
- // Basic check for very small explicit sizes
67
- const heightMatch = style.match(/height:\s*(\d+)px/);
68
- const widthMatch = style.match(/width:\s*(\d+)px/);
69
-
70
- if (heightMatch && parseInt(heightMatch[1], 10) < 44) {
71
- tapTargetIssues++;
72
- }
73
- if (widthMatch && parseInt(widthMatch[1], 10) < 44) {
74
- tapTargetIssues++;
75
- }
76
- });
77
-
78
- if (tapTargetIssues > 0) {
79
- issues.push({
80
- ...ISSUE_DEFINITIONS.TAP_TARGETS_TOO_SMALL,
81
- affectedUrls: [url],
82
- details: { count: tapTargetIssues },
83
- });
84
- }
85
-
86
- // Check for font size issues (basic heuristic)
87
- let fontSizeIssues = 0;
88
- $('body *').each((_, el) => {
89
- const style = $(el).attr('style') || '';
90
- const fontSizeMatch = style.match(/font-size:\s*(\d+)px/);
91
- if (fontSizeMatch && parseInt(fontSizeMatch[1], 10) < 12) {
92
- fontSizeIssues++;
93
- }
94
- });
95
-
96
- return {
97
- issues,
98
- data: {
99
- hasViewport,
100
- viewportContent,
101
- isResponsive: hasViewport && (viewportContent?.includes('width=device-width') || false),
102
- tapTargetIssues,
103
- fontSizeIssues,
104
- }
105
- };
106
- }
107
-
108
- // Additional mobile-specific checks
109
- export function checkMobileResources(html: string, url: string): AuditIssue[] {
110
- const issues: AuditIssue[] = [];
111
- const $ = cheerio.load(html);
112
-
113
- // Check for Flash content (obsolete)
114
- if ($('object[type*="flash"], embed[type*="flash"]').length > 0) {
115
- issues.push({
116
- code: 'FLASH_CONTENT',
117
- severity: 'error',
118
- category: 'mobile',
119
- title: 'Flash content detected',
120
- description: 'Page contains Flash content which is not supported on mobile devices.',
121
- impact: 'Content is inaccessible on mobile devices and most modern browsers.',
122
- howToFix: 'Replace Flash content with HTML5 alternatives.',
123
- affectedUrls: [url],
124
- });
125
- }
126
-
127
- // Check for plugins
128
- if ($('object, embed, applet').length > 0) {
129
- issues.push({
130
- code: 'PLUGINS_DETECTED',
131
- severity: 'notice',
132
- category: 'mobile',
133
- title: 'Plugins detected',
134
- description: 'Page uses plugins which may not work on mobile devices.',
135
- impact: 'Some content may not be accessible on mobile.',
136
- howToFix: 'Consider replacing plugins with standard web technologies.',
137
- affectedUrls: [url],
138
- });
139
- }
140
-
141
- // Check for horizontal scroll (indication of non-responsive design)
142
- // This is a heuristic based on fixed-width elements
143
- let fixedWidthElements = 0;
144
- $('*').each((_, el) => {
145
- const style = $(el).attr('style') || '';
146
- const widthMatch = style.match(/width:\s*(\d+)px/);
147
- if (widthMatch && parseInt(widthMatch[1], 10) > 320) {
148
- fixedWidthElements++;
149
- }
150
- });
151
-
152
- if (fixedWidthElements > 5) {
153
- issues.push({
154
- code: 'POSSIBLE_HORIZONTAL_SCROLL',
155
- severity: 'notice',
156
- category: 'mobile',
157
- title: 'Possible horizontal scrolling',
158
- description: 'Multiple elements have fixed widths that may cause horizontal scrolling on mobile.',
159
- impact: 'Poor mobile user experience.',
160
- howToFix: 'Use responsive widths (percentages, max-width) instead of fixed pixel widths.',
161
- affectedUrls: [url],
162
- details: { count: fixedWidthElements },
163
- });
164
- }
165
-
166
- return issues;
167
- }
@@ -1,226 +0,0 @@
1
- // Modern Image Format Checks
2
- // Checks for WebP/AVIF usage and image optimization
3
-
4
- import * as cheerio from 'cheerio';
5
- import type { AuditIssue } from '../types.js';
6
- import { ISSUE_DEFINITIONS } from '../types.js';
7
-
8
- // File extensions for modern formats
9
- const MODERN_FORMATS = ['.webp', '.avif'];
10
- const LEGACY_FORMATS = ['.jpg', '.jpeg', '.png', '.gif', '.bmp'];
11
-
12
- export interface ImageInfo {
13
- src: string;
14
- alt: string | null;
15
- width: number | null;
16
- height: number | null;
17
- loading: string | null;
18
- format: string;
19
- isModernFormat: boolean;
20
- hasDimensions: boolean;
21
- isLazyLoaded: boolean;
22
- }
23
-
24
- export interface ModernImagesData {
25
- totalImages: number;
26
- modernFormatCount: number;
27
- legacyFormatCount: number;
28
- modernFormatPercentage: number;
29
- images: ImageInfo[];
30
- hasSourceSet: boolean;
31
- hasPictureElements: boolean;
32
- }
33
-
34
- /**
35
- * Extract format from URL
36
- */
37
- function getImageFormat(url: string): string {
38
- try {
39
- const pathname = new URL(url, 'https://example.com').pathname.toLowerCase();
40
-
41
- // Check for format in query string (common with CDNs)
42
- const formatMatch = url.match(/[?&](?:format|f)=(\w+)/i);
43
- if (formatMatch) {
44
- return '.' + formatMatch[1].toLowerCase();
45
- }
46
-
47
- // Check file extension
48
- const extMatch = pathname.match(/\.([a-z0-9]+)$/i);
49
- if (extMatch) {
50
- return '.' + extMatch[1].toLowerCase();
51
- }
52
-
53
- return 'unknown';
54
- } catch {
55
- return 'unknown';
56
- }
57
- }
58
-
59
- /**
60
- * Check if format is modern
61
- */
62
- function isModernFormat(format: string): boolean {
63
- return MODERN_FORMATS.includes(format.toLowerCase());
64
- }
65
-
66
- /**
67
- * Extract image information from HTML
68
- */
69
- function extractImages($: cheerio.CheerioAPI, baseUrl: string): ImageInfo[] {
70
- const images: ImageInfo[] = [];
71
-
72
- // Process img tags
73
- $('img').each((_, el) => {
74
- const src = $(el).attr('src') || $(el).attr('data-src') || '';
75
- const srcset = $(el).attr('srcset') || '';
76
- const alt = $(el).attr('alt') || null;
77
- const width = $(el).attr('width') ? parseInt($(el).attr('width')!, 10) : null;
78
- const height = $(el).attr('height') ? parseInt($(el).attr('height')!, 10) : null;
79
- const loading = $(el).attr('loading') || null;
80
-
81
- // Skip data URIs and empty sources
82
- if (!src || src.startsWith('data:')) return;
83
-
84
- // Resolve relative URLs
85
- let fullSrc = src;
86
- try {
87
- fullSrc = new URL(src, baseUrl).href;
88
- } catch {
89
- // Keep original if URL parsing fails
90
- }
91
-
92
- const format = getImageFormat(fullSrc);
93
-
94
- images.push({
95
- src: fullSrc,
96
- alt,
97
- width,
98
- height,
99
- loading,
100
- format,
101
- isModernFormat: isModernFormat(format),
102
- hasDimensions: width !== null && height !== null,
103
- isLazyLoaded: loading === 'lazy' || $(el).attr('data-src') !== undefined,
104
- });
105
-
106
- // Check srcset for modern formats
107
- if (srcset) {
108
- const srcsetUrls = srcset.split(',').map((s) => s.trim().split(' ')[0]);
109
- for (const srcsetUrl of srcsetUrls) {
110
- const srcsetFormat = getImageFormat(srcsetUrl);
111
- if (isModernFormat(srcsetFormat) && !images.some((img) => img.src === srcsetUrl)) {
112
- images.push({
113
- src: srcsetUrl,
114
- alt,
115
- width: null,
116
- height: null,
117
- loading,
118
- format: srcsetFormat,
119
- isModernFormat: true,
120
- hasDimensions: false,
121
- isLazyLoaded: loading === 'lazy',
122
- });
123
- }
124
- }
125
- }
126
- });
127
-
128
- // Check picture elements for modern format sources
129
- $('picture source').each((_, el) => {
130
- const srcset = $(el).attr('srcset') || '';
131
- const type = $(el).attr('type') || '';
132
-
133
- if (type.includes('webp') || type.includes('avif')) {
134
- const srcsetUrls = srcset.split(',').map((s) => s.trim().split(' ')[0]);
135
- for (const srcsetUrl of srcsetUrls) {
136
- if (!images.some((img) => img.src === srcsetUrl)) {
137
- images.push({
138
- src: srcsetUrl,
139
- alt: null,
140
- width: null,
141
- height: null,
142
- loading: null,
143
- format: type.includes('webp') ? '.webp' : '.avif',
144
- isModernFormat: true,
145
- hasDimensions: false,
146
- isLazyLoaded: false,
147
- });
148
- }
149
- }
150
- }
151
- });
152
-
153
- return images;
154
- }
155
-
156
- /**
157
- * Analyze image formats and optimization
158
- */
159
- export function analyzeModernImages(html: string, url: string): { issues: AuditIssue[]; data: ModernImagesData } {
160
- const issues: AuditIssue[] = [];
161
- const $ = cheerio.load(html);
162
-
163
- // Extract images
164
- const images = extractImages($, url);
165
-
166
- // Filter to unique images by src
167
- const uniqueImages = images.filter((img, idx, arr) => arr.findIndex((i) => i.src === img.src) === idx);
168
-
169
- // Count formats
170
- const modernFormatCount = uniqueImages.filter((img) => img.isModernFormat).length;
171
- const legacyFormatCount = uniqueImages.filter(
172
- (img) => !img.isModernFormat && LEGACY_FORMATS.includes(img.format)
173
- ).length;
174
-
175
- // Check for picture elements and srcset
176
- const hasPictureElements = $('picture').length > 0;
177
- const hasSourceSet = $('img[srcset]').length > 0 || $('picture source[srcset]').length > 0;
178
-
179
- // Calculate percentage
180
- const totalRelevantImages = modernFormatCount + legacyFormatCount;
181
- const modernFormatPercentage = totalRelevantImages > 0 ? Math.round((modernFormatCount / totalRelevantImages) * 100) : 100;
182
-
183
- // Generate issues
184
- if (legacyFormatCount > 0 && !hasPictureElements && !hasSourceSet) {
185
- const legacyImages = uniqueImages.filter((img) => !img.isModernFormat && LEGACY_FORMATS.includes(img.format));
186
-
187
- issues.push({
188
- ...ISSUE_DEFINITIONS.IMAGE_NOT_WEBP_AVIF,
189
- affectedUrls: legacyImages.slice(0, 10).map((img) => img.src),
190
- details: {
191
- legacyImageCount: legacyFormatCount,
192
- modernImageCount: modernFormatCount,
193
- modernFormatPercentage,
194
- recommendation: 'Convert images to WebP or AVIF format for 25-50% smaller file sizes',
195
- },
196
- });
197
- }
198
-
199
- // Check for images without dimensions (causes CLS)
200
- const imagesWithoutDimensions = uniqueImages.filter(
201
- (img) => !img.hasDimensions && !img.isLazyLoaded && LEGACY_FORMATS.includes(img.format)
202
- );
203
-
204
- if (imagesWithoutDimensions.length > 0) {
205
- issues.push({
206
- ...ISSUE_DEFINITIONS.IMG_NO_DIMENSIONS,
207
- affectedUrls: imagesWithoutDimensions.slice(0, 10).map((img) => img.src),
208
- details: {
209
- count: imagesWithoutDimensions.length,
210
- },
211
- });
212
- }
213
-
214
- return {
215
- issues,
216
- data: {
217
- totalImages: uniqueImages.length,
218
- modernFormatCount,
219
- legacyFormatCount,
220
- modernFormatPercentage,
221
- images: uniqueImages,
222
- hasSourceSet,
223
- hasPictureElements,
224
- },
225
- };
226
- }