Oregami
Repositories/oxedyne/daimond

oxedyne/daimond/dev/probe_madeby.mjs

1.9 KiB, 1 run

created by r2519314175:53, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1// playwright-core lives outside the repo and is resolved by path, exactly as
2// dev/harness.mjs resolves it.
3import os from 'node:os';
4import path from 'node:path';
5const { chromium } = await import(process.env.PW_CORE
6 || path.join(os.homedir(), '.red-pw/node_modules/playwright-core/index.mjs'));
7const b = await chromium.launch({ executablePath: process.env.PW_CHROME
8 || `${process.env.HOME}/.cache/ms-playwright/chromium-1229/chrome-linux64/chrome` });
9const p = await b.newPage();
10const svg = await import('node:fs').then(m => m.readFileSync(
11 '/home/jason/usr/code/web/apps/oxedyne/daimond/www/assets/made_by_oxedyne.svg', 'utf8'));
12await p.setContent(`<body style="margin:0">${svg}</body>`);
13const out = await p.evaluate(() => {
14 // RENDERED pixels, not user units: getBBox() ignores every ancestor transform,
15 // and this artwork is built from transformed groups, so its numbers land far
16 // outside the viewBox and mean nothing. getBoundingClientRect() is what the
17 // eye sees.
18 const svg = document.querySelector('svg');
19 svg.setAttribute('height', '100');
20 svg.removeAttribute('width');
21 const plate = svg.getBoundingClientRect();
22 const mid = plate.x + plate.width / 2;
23 const union = (pred) => {
24 let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity, n = 0;
25 for (const el of svg.querySelectorAll('path,rect,circle,polygon,ellipse,line')) {
26 const r = el.getBoundingClientRect();
27 if (r.width < 0.2 && r.height < 0.2) continue;
28 if (!pred(r)) continue;
29 n++;
30 x0 = Math.min(x0, r.x); y0 = Math.min(y0, r.y);
31 x1 = Math.max(x1, r.right); y1 = Math.max(y1, r.bottom);
32 }
33 return { n, w: +(x1 - x0).toFixed(1), h: +(y1 - y0).toFixed(1) };
34 };
35 return {
36 plate: { w: +plate.width.toFixed(1), h: +plate.height.toFixed(1) },
37 ai: union(r => r.x + r.width / 2 > mid),
38 ox: union(r => r.x + r.width / 2 <= mid),
39 };
40});
41console.log(JSON.stringify(out, null, 1));
42await b.close();