58 lines
2.3 KiB
JavaScript
58 lines
2.3 KiB
JavaScript
import { chromium } from 'playwright';
|
|
import { readFileSync } from 'fs';
|
|
|
|
const perlerPath = '/Users/guchen/.hermes/workspace/pindou/src/data/palettes/compiled/perler.json';
|
|
const palette = JSON.parse(readFileSync(perlerPath, 'utf-8'));
|
|
|
|
const colors = [0, 4, 5, 16, 9].map(i => palette[i]).filter(Boolean);
|
|
const SIZE = 10;
|
|
const grid = [];
|
|
const legendMap = new Map();
|
|
for (let row = 0; row < SIZE; row++) {
|
|
const rowData = [];
|
|
for (let col = 0; col < SIZE; col++) {
|
|
const c = colors[(row + col) % colors.length];
|
|
rowData.push({ color: c, row, col });
|
|
if (!legendMap.has(c.id)) legendMap.set(c.id, { color: c, count: 0, symbol: String.fromCharCode(65 + legendMap.size) });
|
|
legendMap.get(c.id).count++;
|
|
}
|
|
grid.push(rowData);
|
|
}
|
|
const legend = Array.from(legendMap.values());
|
|
|
|
const BROWSER = await chromium.launch({ headless: true });
|
|
const PAGE = await BROWSER.newPage();
|
|
const errors = [];
|
|
PAGE.on('pageerror', err => errors.push(err.message));
|
|
|
|
const BASE = 'https://gch3n.online/pindou/';
|
|
|
|
// Inject test data and navigate to result
|
|
await PAGE.goto(BASE, { waitUntil: 'domcontentloaded', timeout: 15000 });
|
|
await PAGE.evaluate((data) => {
|
|
sessionStorage.setItem('bead-process-state', JSON.stringify(data));
|
|
}, { grid, legend, totalBeads: SIZE*SIZE, usedColors: legend.length, status: 'done', canvasWidth: SIZE, canvasHeight: SIZE, fitMode: 'fit', sourceImage: null, extractedImage: null });
|
|
|
|
await PAGE.goto(`${BASE}#/pages/result/result`, { waitUntil: 'networkidle', timeout: 15000 });
|
|
await PAGE.waitForTimeout(2000);
|
|
|
|
const state = await PAGE.evaluate(() => {
|
|
const canvasInner = document.querySelector('.canvas-inner');
|
|
const allCanvases = document.querySelectorAll('canvas');
|
|
const emptyState = document.querySelector('.empty-state');
|
|
const infoBar = document.querySelector('.info-bar');
|
|
return {
|
|
emptyVisible: !!emptyState && emptyState.offsetParent !== null,
|
|
infoBarText: infoBar?.textContent?.trim(),
|
|
canvasInnerHTML: canvasInner?.innerHTML?.substring(0, 200),
|
|
canvasCount: allCanvases.length,
|
|
canvasSizes: Array.from(allCanvases).map(c => `${c.width}x${c.height}`),
|
|
};
|
|
});
|
|
console.log('Page errors:', errors);
|
|
|
|
console.log(JSON.stringify(state, null, 2));
|
|
await PAGE.screenshot({ path: '/Users/guchen/.openclaw/workspace/pindou-online.png', fullPage: true });
|
|
console.log('Screenshot: pindou-online.png');
|
|
await BROWSER.close();
|