medesign 1.2.0 → 1.6.0

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 +223 -129
  2. package/bin/mebolder.js +4 -0
  3. package/bin/medesign.js +992 -200
  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 +21 -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 +1024 -101
  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 +457 -412
  51. package/tests/snapshot.js +263 -0
@@ -0,0 +1,263 @@
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 < 30; 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
+ ]);
189
+
190
+ const allPresets = isOgOnly
191
+ ? [{ name: 'og-banner', width: 1200, height: 630, dpr: 2, isMobile: false }]
192
+ : [
193
+ { name: 'mobile', width: 390, height: 844, dpr: 2, isMobile: true },
194
+ { name: 'tablet', width: 820, height: 1180, dpr: 2, isMobile: true },
195
+ { name: 'desktop', width: 1440, height: 900, dpr: 2, isMobile: false }
196
+ ];
197
+
198
+ const viewports = customViewports
199
+ ? allPresets.filter(p => customViewports.includes(p.name))
200
+ : allPresets;
201
+
202
+ const fileUrl = 'file:///' + resolvedPath.replace(/\\/g, '/');
203
+ const captured = [];
204
+
205
+ console.log(`\n${ANSI_BOLD}ME-DESIGN Snapshot Engine${ANSI_RESET}`);
206
+ console.log(`${ANSI_CYAN}Renderer: Headless Chromium CDP (${path.basename(chromePath)})${ANSI_RESET}`);
207
+ console.log(`${ANSI_GRAY}────────────────────────────────────────────────────────────────────────${ANSI_RESET}`);
208
+ console.log(`Target: ${ANSI_BOLD}${path.basename(resolvedPath)}${ANSI_RESET}`);
209
+ console.log(`Output: ${ANSI_GRAY}${finalOutDir}${ANSI_RESET}\n`);
210
+
211
+ try {
212
+ const client = new CDPClient(cdpPort);
213
+ await client.connect();
214
+ await client.send('Page.enable');
215
+ await client.send('DOM.enable');
216
+
217
+ for (const vp of viewports) {
218
+ await client.send('Emulation.setDeviceMetricsOverride', {
219
+ width: vp.width,
220
+ height: vp.height,
221
+ deviceScaleFactor: vp.dpr,
222
+ mobile: vp.isMobile
223
+ });
224
+
225
+ await client.send('Page.navigate', { url: fileUrl });
226
+ await new Promise(r => setTimeout(r, 450)); // Allow CSS rendering & Chart.js animations to complete
227
+
228
+ const snap = await client.send('Page.captureScreenshot', {
229
+ format: 'png',
230
+ captureBeyondViewport: false
231
+ });
232
+
233
+ const fileName = `${targetName}-${vp.name}-${vp.width}x${vp.height}.png`;
234
+ const filePath = path.join(finalOutDir, fileName);
235
+ const buf = Buffer.from(snap.data, 'base64');
236
+ fs.writeFileSync(filePath, buf);
237
+
238
+ captured.push({
239
+ name: vp.name,
240
+ dimensions: `${vp.width}x${vp.height} @${vp.dpr}x`,
241
+ size: `${Math.round(buf.length / 1024)} KB`,
242
+ file: fileName
243
+ });
244
+ }
245
+
246
+ await client.close();
247
+ } finally {
248
+ chromeProcess.kill();
249
+ }
250
+
251
+ console.log(`${'VIEWPORT'.padEnd(12)} | ${'DIMENSIONS'.padEnd(18)} | ${'FILE SIZE'.padEnd(12)} | ${'ARTIFACT'}`);
252
+ console.log(`${ANSI_GRAY}------------------------------------------------------------------------${ANSI_RESET}`);
253
+ captured.forEach(c => {
254
+ console.log(`${ANSI_GREEN}${c.name.padEnd(12)}${ANSI_RESET} | ${c.dimensions.padEnd(18)} | ${c.size.padEnd(12)} | ${ANSI_BOLD}${c.file}${ANSI_RESET}`);
255
+ });
256
+ console.log(`${ANSI_GRAY}────────────────────────────────────────────────────────────────────────${ANSI_RESET}`);
257
+ console.log(`${ANSI_GREEN}SUCCESS:${ANSI_RESET} ${captured.length} snapshots saved to ${finalOutDir}\n`);
258
+ }
259
+
260
+ captureSnapshots().catch(err => {
261
+ console.error(`${ANSI_RED}Snapshot Failed:${ANSI_RESET}`, err);
262
+ process.exit(1);
263
+ });