medesign 1.4.0 → 1.6.1

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 (51) hide show
  1. package/README.md +90 -72
  2. package/bin/mebolder.js +4 -0
  3. package/bin/medesign.js +370 -35
  4. package/bin/melint.js +4 -0
  5. package/bin/mepolish.js +4 -0
  6. package/bin/mequiet.js +4 -0
  7. package/bin/mesearch.js +4 -0
  8. package/bin/mesnapshot.js +4 -0
  9. package/examples/cadastral-qaqc-slide.html +577 -0
  10. package/examples/executive-summary-report.html +597 -0
  11. package/examples/executive-summary-report.pdf +0 -0
  12. package/examples/geospatial-banner-1200x630.html +370 -0
  13. package/examples/geospatial-banner-1200x630.svg +149 -0
  14. package/examples/linear-issue-board.html +1273 -0
  15. package/examples/snapshots/cadastral-qaqc-slide-desktop-1440x900.png +0 -0
  16. package/examples/snapshots/cadastral-qaqc-slide-mobile-390x844.png +0 -0
  17. package/examples/snapshots/cadastral-qaqc-slide-tablet-820x1180.png +0 -0
  18. package/examples/snapshots/executive-summary-report-desktop-1440x900.png +0 -0
  19. package/examples/snapshots/executive-summary-report-mobile-390x844.png +0 -0
  20. package/examples/snapshots/executive-summary-report-tablet-820x1180.png +0 -0
  21. package/examples/snapshots/geospatial-banner-1200x630-og-banner-1200x630.png +0 -0
  22. package/examples/snapshots/linear-issue-board-desktop-1440x900.png +0 -0
  23. package/examples/snapshots/linear-issue-board-mobile-390x844.png +0 -0
  24. package/examples/snapshots/linear-issue-board-tablet-820x1180.png +0 -0
  25. package/examples/snapshots/spotify-web-player-desktop-1440x900.png +0 -0
  26. package/examples/snapshots/spotify-web-player-mobile-390x844.png +0 -0
  27. package/examples/snapshots/spotify-web-player-tablet-820x1180.png +0 -0
  28. package/examples/spotify-web-player.html +1446 -0
  29. package/package.json +16 -4
  30. package/presets/metha/guidelines.md +26 -17
  31. package/presets/metha/preset.json +16 -16
  32. package/references/ai-tells.md +9 -2
  33. package/references/brand-design-tokens.md +27 -28
  34. package/references/brief-intake.md +90 -0
  35. package/references/catalog.json +1031 -1023
  36. package/references/cli-architecture.md +1 -1
  37. package/references/compositor-smoothness.md +161 -0
  38. package/references/design-core.md +11 -4
  39. package/references/executive-reports.md +234 -0
  40. package/references/image-mockup-direction.md +53 -53
  41. package/references/image-to-code.md +46 -46
  42. package/references/modern-craft-invariants.md +55 -9
  43. package/references/prompt-templates.md +49 -0
  44. package/references/quality-gate.md +42 -12
  45. package/references/typography-thai-latin.md +206 -0
  46. package/references/view-transitions-engine.md +89 -0
  47. package/references/web-retrofit-protocol.md +103 -0
  48. package/scripts/export-tokens.js +419 -403
  49. package/tests/browser-audit.js +463 -442
  50. package/tests/linter.js +49 -4
  51. package/tests/snapshot.js +266 -0
package/tests/linter.js CHANGED
@@ -8,8 +8,26 @@
8
8
 
9
9
  const fs = require('fs');
10
10
  const path = require('path');
11
+ const pkg = require('../package.json');
11
12
 
12
13
  const args = process.argv.slice(2);
14
+
15
+ if (args.includes('--help') || args.includes('-h')) {
16
+ console.log(`
17
+ \x1b[1mME-DESIGN Linter (v${pkg.version})\x1b[0m
18
+ \x1b[90mStatic AST & semantic rule auditing for HTML/CSS/JSX\x1b[0m
19
+
20
+ \x1b[1mUsage:\x1b[0m
21
+ medesign lint <file> [options]
22
+ melint <file> [options]
23
+
24
+ \x1b[1mOptions:\x1b[0m
25
+ --format <text|json|sarif> Output format (default: text)
26
+ --preset <apple|tesla|metha> Target design preset
27
+ --config <path> Custom medesign.config.js path
28
+ `);
29
+ process.exit(0);
30
+ }
13
31
  let targetFile = null;
14
32
  let presetName = 'default';
15
33
  let format = 'text'; // 'text' | 'json' | 'sarif'
@@ -181,7 +199,7 @@ if (hasDenseGrid) {
181
199
 
182
200
  // 7. RULE MD102: Color Gamut Interpolation Space - Soft Heuristic (Warning)
183
201
  const hasGradient = /linear-gradient\(/i.test(cleanCode);
184
- const hasOklchOklab = /linear-gradient\(\s*in\s+(oklch|oklab)/i.test(cleanCode);
202
+ const hasOklchOklab = /linear-gradient\([^)]*\bin\s+(oklch|oklab)/i.test(cleanCode);
185
203
  if (hasGradient && !hasOklchOklab) {
186
204
  diagnostics.push({
187
205
  ruleId: 'MD102',
@@ -238,7 +256,33 @@ if (hasOrderReverse) {
238
256
  });
239
257
  }
240
258
 
241
- // 11. RULE MD201: Editorial Style: Em-Dash Punctuation - Soft Heuristic (Info)
259
+ // 11. RULE MD106: Container Optical Padding & Slider Boundary Clearance - Soft Heuristic (Warning)
260
+ // When an interactive slider or pill container has a rounded background, inner tracks must maintain >= 8px optical clearance.
261
+ const sliderPillBlocks = cleanCode.match(/(?:[a-zA-Z0-9_\-\.\#\:\*\,\[\]\="'>\s]+)?(?:slider|progress|scrubber|pill-track)\s*\{[^}]+\}/gi) || [];
262
+ let hasBoundaryCollision = false;
263
+ for (const block of sliderPillBlocks) {
264
+ const hasPillRadius = /border-radius\s*:\s*(?:var\(--radius-full\)|9999px|50%|[1-9]\d{1,}px)/i.test(block);
265
+ const hasVisibleBg = /background(?:-color)?\s*:\s*(?!none|transparent\b|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\))/i.test(block);
266
+ const hasMinHeightTarget = /(?:min-)?height\s*:\s*(?:[3-9]\dpx|44px)/i.test(block);
267
+ const hasOpticalPadding = /padding(?:-inline|-left|-right)?\s*:\s*(?:[^;}]*?(?:[8-9]px|[1-9]\d+px|var\(--padding))/i.test(block);
268
+ if (hasPillRadius && hasVisibleBg && hasMinHeightTarget && !hasOpticalPadding) {
269
+ hasBoundaryCollision = true;
270
+ break;
271
+ }
272
+ }
273
+ if (hasBoundaryCollision) {
274
+ diagnostics.push({
275
+ ruleId: 'MD106',
276
+ ruleName: 'ContainerBoundaryClearance',
277
+ category: 'G',
278
+ severity: config.rules.MD106 || 'warning',
279
+ hardInvariant: false,
280
+ message: 'Detected full-width slider/progress track inside a rounded container with background but zero optical padding, causing visual boundary collision.',
281
+ remediation: 'Isolate outer 44px hit-target with transparent background, or provide horizontal optical padding (padding: 0 12px) to prevent the track from slamming into the curved border.'
282
+ });
283
+ }
284
+
285
+ // 12. RULE MD201: Editorial Style: Em-Dash Punctuation - Soft Heuristic (Info)
242
286
  const visibleTextMatch = content.replace(/<script[\s\S]*?<\/script>/gi, '').replace(/<style[\s\S]*?<\/style>/gi, '');
243
287
  const hasEmDash = /[—–]/.test(visibleTextMatch);
244
288
  if (hasEmDash) {
@@ -296,6 +340,7 @@ if (format === 'sarif') {
296
340
  { id: 'MD103', name: 'ConcentricRadiusMath', desc: 'Concentric radius geometry', level: 'note' },
297
341
  { id: 'MD104', name: 'MobileViewportStability', desc: 'Mobile viewport dynamic unit stability (100dvh)', level: 'warning' },
298
342
  { id: 'MD105', name: 'VisualDomSequenceScramble', desc: 'Visual/DOM sequence synchronization (order / flex reverse)', level: 'warning' },
343
+ { id: 'MD106', name: 'ContainerBoundaryClearance', desc: 'Container boundary clearance and optical padding', level: 'warning' },
299
344
  { id: 'MD201', name: 'EditorialPunctuationHyphen', desc: 'Editorial style punctuation (hyphen vs em-dash)', level: 'note' }
300
345
  ];
301
346
 
@@ -309,7 +354,7 @@ if (format === 'sarif') {
309
354
  tool: {
310
355
  driver: {
311
356
  name: 'medesign',
312
- version: '1.4.0',
357
+ version: pkg.version,
313
358
  informationUri: 'https://github.com/methastrategy/medesign',
314
359
  rules: allRules.map(r => ({
315
360
  id: r.id,
@@ -371,7 +416,7 @@ console.log(`${ANSI_GRAY}──────────────────
371
416
  console.log(`Target ${path.basename(targetFile)}`);
372
417
  console.log(`Preset ${presetName.toUpperCase()}`);
373
418
  console.log(`Analysis Static AST & Semantic Rules`);
374
- console.log(`Ruleset medesign-standard@1.4.0\n`);
419
+ console.log(`Ruleset medesign-standard@${pkg.version}\n`);
375
420
 
376
421
  console.log(`${ANSI_BOLD}QUALITY SCORE (Q = ${w.H}H + ${w.I}I + ${w.G}G + ${w.R}R + ${w.V}V)${ANSI_RESET}`);
377
422
  console.log(` Hierarchy (H) ${H.toFixed(1)} / 100`);
@@ -0,0 +1,266 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * ME-DESIGN Visual Regression & Snapshot Engine
5
+ * Headless Chromium Chrome DevTools Protocol (CDP) client over native WebSocket.
6
+ * Zero external npm dependencies.
7
+ *
8
+ * Captures pixel-accurate high-DPI rendered screenshots across viewports:
9
+ * - Mobile (390x844, 2x DPR)
10
+ * - Tablet (820x1180, 2x DPR)
11
+ * - Desktop (1440x900, 2x DPR)
12
+ * - Custom / OG Banner (1200x630)
13
+ *
14
+ * Usage:
15
+ * node tests/snapshot.js <file> [--out <dir>] [--og] [--viewports mobile,tablet,desktop]
16
+ */
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+ const { spawn } = require('child_process');
21
+
22
+ const ANSI_RESET = '\x1b[0m';
23
+ const ANSI_BOLD = '\x1b[1m';
24
+ const ANSI_GREEN = '\x1b[32m';
25
+ const ANSI_RED = '\x1b[31m';
26
+ const ANSI_YELLOW = '\x1b[33m';
27
+ const ANSI_CYAN = '\x1b[36m';
28
+ const ANSI_GRAY = '\x1b[90m';
29
+
30
+ const args = process.argv.slice(2);
31
+ let targetFile = null;
32
+ let outDir = null;
33
+ let isOgOnly = false;
34
+ let customViewports = null;
35
+
36
+ for (let i = 0; i < args.length; i++) {
37
+ if (args[i] === '--out' && args[i + 1]) {
38
+ outDir = args[++i];
39
+ } else if (args[i] === '--og') {
40
+ isOgOnly = true;
41
+ } else if (args[i] === '--viewports' && args[i + 1]) {
42
+ customViewports = args[++i].toLowerCase().split(',');
43
+ } else if (!targetFile && !args[i].startsWith('--')) {
44
+ targetFile = args[i];
45
+ }
46
+ }
47
+
48
+ if (!targetFile) {
49
+ console.log(`
50
+ ${ANSI_BOLD}ME-DESIGN Snapshot Engine${ANSI_RESET}
51
+ ${ANSI_GRAY}Capture pixel-accurate rendered snapshots across responsive breakpoints${ANSI_RESET}
52
+
53
+ ${ANSI_BOLD}Usage:${ANSI_RESET}
54
+ node tests/snapshot.js <file> [options]
55
+
56
+ ${ANSI_BOLD}Options:${ANSI_RESET}
57
+ --out <dir> Output directory for PNG images (default: ./snapshots)
58
+ --og Capture at 1200x630 (OpenGraph / Social Banner)
59
+ --viewports <list> Comma-separated list (mobile,tablet,desktop)
60
+ `);
61
+ process.exit(1);
62
+ }
63
+
64
+ const resolvedPath = path.resolve(process.cwd(), targetFile);
65
+ if (!fs.existsSync(resolvedPath)) {
66
+ console.error(`${ANSI_RED}Error:${ANSI_RESET} File not found: ${resolvedPath}`);
67
+ process.exit(1);
68
+ }
69
+
70
+ const targetName = path.basename(resolvedPath, path.extname(resolvedPath));
71
+ const finalOutDir = path.resolve(process.cwd(), outDir || path.join(path.dirname(resolvedPath), 'snapshots'));
72
+ if (!fs.existsSync(finalOutDir)) {
73
+ fs.mkdirSync(finalOutDir, { recursive: true });
74
+ }
75
+
76
+ function findChromium() {
77
+ const envPath = process.env.CHROME_PATH || process.env.CHROME_BIN;
78
+ if (envPath && fs.existsSync(envPath)) return envPath;
79
+
80
+ const localApp = process.env.LOCALAPPDATA || '';
81
+ const pwDir = path.join(localApp, 'ms-playwright');
82
+ if (fs.existsSync(pwDir)) {
83
+ try {
84
+ const entries = fs.readdirSync(pwDir);
85
+ const chromiumDirs = entries.filter(e => e.startsWith('chromium-')).sort().reverse();
86
+ for (const cDir of chromiumDirs) {
87
+ const p = path.join(pwDir, cDir, 'chrome-win64', 'chrome.exe');
88
+ if (fs.existsSync(p)) return p;
89
+ }
90
+ } catch (e) {}
91
+ }
92
+
93
+ const programFiles = process.env['ProgramFiles'] || 'C:\\Program Files';
94
+ const programFilesX86 = process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)';
95
+
96
+ const alternatives = [
97
+ path.join(programFiles, 'Google', 'Chrome', 'Application', 'chrome.exe'),
98
+ path.join(programFilesX86, 'Google', 'Chrome', 'Application', 'chrome.exe'),
99
+ path.join(programFiles, 'Microsoft', 'Edge', 'Application', 'msedge.exe'),
100
+ path.join(programFilesX86, 'Microsoft', 'Edge', 'Application', 'msedge.exe'),
101
+ '/usr/bin/google-chrome',
102
+ '/usr/bin/google-chrome-stable',
103
+ '/usr/bin/chromium',
104
+ '/usr/bin/chromium-browser',
105
+ '/snap/bin/chromium',
106
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
107
+ '/Applications/Chromium.app/Contents/MacOS/Chromium'
108
+ ];
109
+
110
+ for (const p of alternatives) {
111
+ if (fs.existsSync(p)) return p;
112
+ }
113
+ return null;
114
+ }
115
+
116
+ const chromePath = findChromium();
117
+ if (!chromePath) {
118
+ console.error(`${ANSI_RED}Error:${ANSI_RESET} Chromium/Chrome binary not found on system.`);
119
+ process.exit(1);
120
+ }
121
+
122
+ class CDPClient {
123
+ constructor(port) {
124
+ this.port = port;
125
+ this.ws = null;
126
+ this.msgId = 0;
127
+ this.callbacks = new Map();
128
+ }
129
+
130
+ async connect() {
131
+ for (let i = 0; i < 60; i++) {
132
+ try {
133
+ const r = await fetch(`http://127.0.0.1:${this.port}/json/version`);
134
+ if (r.ok) break;
135
+ } catch (e) {}
136
+ await new Promise(res => setTimeout(res, 100));
137
+ }
138
+ const res = await fetch(`http://127.0.0.1:${this.port}/json/new`, { method: 'PUT' });
139
+ const target = await res.json();
140
+ this.targetId = target.id;
141
+ this.ws = new WebSocket(target.webSocketDebuggerUrl);
142
+
143
+ await new Promise((resolve, reject) => {
144
+ this.ws.onopen = resolve;
145
+ this.ws.onerror = reject;
146
+ });
147
+
148
+ this.ws.onmessage = (event) => {
149
+ const msg = JSON.parse(event.data);
150
+ if (msg.id && this.callbacks.has(msg.id)) {
151
+ const { resolve, reject } = this.callbacks.get(msg.id);
152
+ this.callbacks.delete(msg.id);
153
+ if (msg.error) reject(msg.error);
154
+ else resolve(msg.result);
155
+ }
156
+ };
157
+ }
158
+
159
+ send(method, params = {}) {
160
+ return new Promise((resolve, reject) => {
161
+ const id = ++this.msgId;
162
+ this.callbacks.set(id, { resolve, reject });
163
+ this.ws.send(JSON.stringify({ id, method, params }));
164
+ });
165
+ }
166
+
167
+ async close() {
168
+ if (this.ws) {
169
+ try { this.ws.close(); } catch (e) {}
170
+ }
171
+ try {
172
+ await fetch(`http://127.0.0.1:${this.port}/json/close/${this.targetId}`, { method: 'PUT' });
173
+ } catch (e) {}
174
+ }
175
+ }
176
+
177
+ async function captureSnapshots() {
178
+ const cdpPort = 9555 + Math.floor(Math.random() * 200);
179
+ const chromeProcess = spawn(chromePath, [
180
+ '--headless=new',
181
+ `--remote-debugging-port=${cdpPort}`,
182
+ '--no-first-run',
183
+ '--disable-gpu',
184
+ '--no-sandbox',
185
+ '--disable-extensions',
186
+ '--mute-audio',
187
+ '--hide-scrollbars',
188
+ '--disable-dev-shm-usage',
189
+ '--disable-setuid-sandbox',
190
+ '--no-zygote'
191
+ ]);
192
+
193
+ const allPresets = isOgOnly
194
+ ? [{ name: 'og-banner', width: 1200, height: 630, dpr: 2, isMobile: false }]
195
+ : [
196
+ { name: 'mobile', width: 390, height: 844, dpr: 2, isMobile: true },
197
+ { name: 'tablet', width: 820, height: 1180, dpr: 2, isMobile: true },
198
+ { name: 'desktop', width: 1440, height: 900, dpr: 2, isMobile: false }
199
+ ];
200
+
201
+ const viewports = customViewports
202
+ ? allPresets.filter(p => customViewports.includes(p.name))
203
+ : allPresets;
204
+
205
+ const fileUrl = 'file:///' + resolvedPath.replace(/\\/g, '/');
206
+ const captured = [];
207
+
208
+ console.log(`\n${ANSI_BOLD}ME-DESIGN Snapshot Engine${ANSI_RESET}`);
209
+ console.log(`${ANSI_CYAN}Renderer: Headless Chromium CDP (${path.basename(chromePath)})${ANSI_RESET}`);
210
+ console.log(`${ANSI_GRAY}────────────────────────────────────────────────────────────────────────${ANSI_RESET}`);
211
+ console.log(`Target: ${ANSI_BOLD}${path.basename(resolvedPath)}${ANSI_RESET}`);
212
+ console.log(`Output: ${ANSI_GRAY}${finalOutDir}${ANSI_RESET}\n`);
213
+
214
+ try {
215
+ const client = new CDPClient(cdpPort);
216
+ await client.connect();
217
+ await client.send('Page.enable');
218
+ await client.send('DOM.enable');
219
+
220
+ for (const vp of viewports) {
221
+ await client.send('Emulation.setDeviceMetricsOverride', {
222
+ width: vp.width,
223
+ height: vp.height,
224
+ deviceScaleFactor: vp.dpr,
225
+ mobile: vp.isMobile
226
+ });
227
+
228
+ await client.send('Page.navigate', { url: fileUrl });
229
+ await new Promise(r => setTimeout(r, 450)); // Allow CSS rendering & Chart.js animations to complete
230
+
231
+ const snap = await client.send('Page.captureScreenshot', {
232
+ format: 'png',
233
+ captureBeyondViewport: false
234
+ });
235
+
236
+ const fileName = `${targetName}-${vp.name}-${vp.width}x${vp.height}.png`;
237
+ const filePath = path.join(finalOutDir, fileName);
238
+ const buf = Buffer.from(snap.data, 'base64');
239
+ fs.writeFileSync(filePath, buf);
240
+
241
+ captured.push({
242
+ name: vp.name,
243
+ dimensions: `${vp.width}x${vp.height} @${vp.dpr}x`,
244
+ size: `${Math.round(buf.length / 1024)} KB`,
245
+ file: fileName
246
+ });
247
+ }
248
+
249
+ await client.close();
250
+ } finally {
251
+ chromeProcess.kill();
252
+ }
253
+
254
+ console.log(`${'VIEWPORT'.padEnd(12)} | ${'DIMENSIONS'.padEnd(18)} | ${'FILE SIZE'.padEnd(12)} | ${'ARTIFACT'}`);
255
+ console.log(`${ANSI_GRAY}------------------------------------------------------------------------${ANSI_RESET}`);
256
+ captured.forEach(c => {
257
+ console.log(`${ANSI_GREEN}${c.name.padEnd(12)}${ANSI_RESET} | ${c.dimensions.padEnd(18)} | ${c.size.padEnd(12)} | ${ANSI_BOLD}${c.file}${ANSI_RESET}`);
258
+ });
259
+ console.log(`${ANSI_GRAY}────────────────────────────────────────────────────────────────────────${ANSI_RESET}`);
260
+ console.log(`${ANSI_GREEN}SUCCESS:${ANSI_RESET} ${captured.length} snapshots saved to ${finalOutDir}\n`);
261
+ }
262
+
263
+ captureSnapshots().catch(err => {
264
+ console.error(`${ANSI_RED}Snapshot Failed:${ANSI_RESET}`, err);
265
+ process.exit(1);
266
+ });