chore(memory): V1-2.2 three MEDIUM evidence, lot B patch, contract, TODO, journal

This commit is contained in:
bchanot committed 2026-10-31 23:39:40 +01:00
1 parent 9e49ed1b4d
commit f1bb19b30b
9 files changed
+1652

No files matched your search

@@ -0,0 +1,47 @@
// THROWAWAY: pixel proof of composed views, old (958228a) vs new, three engines; metrics in page.
import { createRequire } from 'node:module'
import { readFileSync, readdirSync } from 'node:fs'
const require = createRequire(process.argv[2] + '/apps/app/package.json')
const pw = require('@playwright/test')
const DIR = process.argv[3]
const engines = process.argv[4].split(',')
const variants = [...new Set(readdirSync(DIR + '/new').map((f) => f.split('.')[0]))].sort()
const read = (side, v, form, part) => readFileSync(`${DIR}/${side}/${v}.${form}.${part}.svg`, 'utf8')
const LIB = `
window.store = {}
window.keep = async (key, img) => { const c = document.createElement('canvas'); c.width = img.width; c.height = img.height; const x = c.getContext('2d'); x.fillStyle='#fff'; x.fillRect(0,0,c.width,c.height); x.drawImage(img, 0, 0, c.width, c.height); window.store[key] = x.getImageData(0, 0, c.width, c.height).data }
window.pdf = async (key, svg) => { const root = new DOMParser().parseFromString(svg, 'image/svg+xml').documentElement; const vb = root.getAttribute('viewBox').split(/[\\s,]+/).map(Number); const w = 1200, h = Math.round(1200 * vb[3] / vb[2]); root.setAttribute('width', String(w)); root.setAttribute('height', String(h)); const url = URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(root)], { type: 'image/svg+xml;charset=utf-8' })); const img = new Image(); img.width = w; img.height = h; img.src = url; await img.decode(); await window.keep(key, img) }
window.png = async (key, b64) => { const img = new Image(); img.src = 'data:image/png;base64,' + b64; await img.decode(); await window.keep(key, img) }
window.diff = (a, b) => { a = window.store[a]; b = window.store[b]; let n = 0; for (let i = 0; i < a.length; i += 4) if (a[i] !== b[i] || a[i+1] !== b[i+1] || a[i+2] !== b[i+2]) n++; return n }
window.ink = (a) => { a = window.store[a]; let n = 0; for (let i = 0; i < a.length; i += 4) if (a[i] < 250 || a[i+1] < 250 || a[i+2] < 250) n++; return n }
window.hl = (a) => { a = window.store[a]; let n = 0; for (let i = 0; i < a.length; i += 4) if (Math.abs(a[i]-0xb8) <= 24 && Math.abs(a[i+1]-0x5a) <= 24 && Math.abs(a[i+2]-0x3f) <= 24) n++; return n }
`
for (const name of engines) {
const browser = await pw[name].launch()
const work = await browser.newPage()
const shot = await browser.newPage({ viewport: { width: 1100, height: 900 } })
await work.setContent('<html><body></body></html>'); await work.addScriptTag({ content: LIB })
console.log(`== ${name} ${browser.version()}`)
const load = async (key, form, svg) => {
if (form === 'pdf') return work.evaluate(([k, s]) => window.pdf(k, s), [key, svg])
await shot.setContent(`<html><body style="margin:0;background:#fff"><div id="h" style="width:1000px;height:786px">${svg.replace(/^<svg /, '<svg width="1000" height="786" ')}</div></body></html>`)
const b64 = (await shot.locator('#h').screenshot()).toString('base64')
return work.evaluate(([k, b]) => window.png(k, b), [key, b64])
}
for (const form of ['pdf', 'canvas']) {
await load('base', form, read('new', 'plain', form, 'layer'))
for (const v of variants) {
for (const side of ['old', 'new']) for (const part of ['full', 'layer']) await load(`${side}.${part}`, form, read(side, v, form, part))
const row = await work.evaluate(() => ({
full_old_vs_new: window.diff('old.full', 'new.full'),
markers_old_vs_plain: window.diff('old.layer', 'base'),
markers_new_vs_plain: window.diff('new.layer', 'base'),
marker_ink_old: window.ink('old.layer'), marker_ink_new: window.ink('new.layer'),
highlight_old: window.hl('old.full'), highlight_new: window.hl('new.full'),
}))
console.log(form.padEnd(6), v.padEnd(15), JSON.stringify(row))
}
}
await browser.close()
}
@@ -0,0 +1,44 @@
// THROWAWAY (never committed): capture of each visible shape under three layer orders.
import { test } from '../support/browser'
test('junction options @phone', async ({ page }, info) => {
await page.goto('/e2e/harness/canvas.html?drawing=plain')
await page.locator('[data-anno-id="hock"]').first().waitFor({ state: 'attached' })
for (const option of ['current', 'points-above-zones', 'visible-wins']) {
const out = await page.evaluate((option) => {
const svg = document.querySelector('[data-testid="anatomy-canvas"] svg') as SVGSVGElement
const layer = svg.lastElementChild as SVGGElement
const kids = Array.from(layer.children) as SVGGeometryElement[]
const hit = kids.filter((k) => k.getAttribute('fill') === 'transparent')
const twins = kids.filter((k) => k.getAttribute('pointer-events') === 'none')
const shapes = kids.filter((k) => !hit.includes(k) && !twins.includes(k))
if (option === 'points-above-zones') {
const points = kids.filter((k) => hit.includes(k) || twins.includes(k))
layer.replaceChildren(...shapes, ...points)
}
if (option === 'visible-wins') {
twins.forEach((t) => t.setAttribute('pointer-events', 'visibleFill'))
layer.replaceChildren(...hit, ...shapes, ...twins)
}
const ctm = svg.getScreenCTM()!
const who = (x: number, y: number) => { const p = new DOMPoint(x, y).matrixTransform(ctm); return document.elementFromPoint(p.x, p.y)?.closest('[data-anno-id]')?.getAttribute('data-anno-id') ?? '-' }
const rows: Record<string, string> = {}
for (const t of twins) {
const id = t.getAttribute('data-anno-id')!
const cx = +t.getAttribute('cx')!, cy = +t.getAttribute('cy')!, r = +t.getAttribute('r')!
let n = 0, own = 0
for (let dx = -r; dx <= r; dx += 2) for (let dy = -r; dy <= r; dy += 2) { if (Math.hypot(dx, dy) > r) continue; n++; if (who(cx + dx, cy + dy) === id) own++ }
if (own < n) rows[id] = `disc ${own}/${n}`
}
for (const z of shapes) {
const id = z.getAttribute('data-anno-id')!
const b = z.getBBox()
let n = 0, own = 0
for (let x = b.x; x <= b.x + b.width; x += 6) for (let y = b.y; y <= b.y + b.height; y += 6) { if (!z.isPointInFill(new DOMPoint(x, y))) continue; n++; if (who(x, y) === id) own++ }
if (own < n) rows[id] = `area ${own}/${n}`
}
return rows
}, option)
console.log(`JUNCTION ${info.project.name} ${option} ${JSON.stringify(out)}`)
await page.reload(); await page.locator('[data-anno-id="hock"]').first().waitFor({ state: 'attached' })
}
})
@@ -0,0 +1,59 @@
// THROWAWAY (never committed): a real PDF export, every view rasterised by Chromium as
// apps/app/src/pdf/browserRasterizer.ts does, written to REAL_PDF_OUT.
import { createRequire } from 'node:module'
import { readFileSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { openExportSession } from '../src/index'
import { nodeCoreRuntime } from '../src/node'
import { readAttachedDocument } from './n-1/scanner/attachment/read'
const ROOT = fileURLToPath(new URL('../../../', import.meta.url))
const FIXTURES = join(ROOT, 'apps/app/tests/fixtures')
const OUT = process.env.REAL_PDF_OUT
function unwrap<T>(o: { ok: true; value: T } | { ok: false; kind: string; detail?: string }, what: string): T {
if (!o.ok) throw new Error(`${what}: ${o.kind} ${o.detail ?? ''}`)
return o.value
}
it.runIf(OUT)('real pdf', async () => {
const require = createRequire(join(ROOT, 'apps/app/package.json'))
const { chromium } = require('@playwright/test')
const browser = await chromium.launch()
const page = await browser.newPage()
await page.setContent('<html><body></body></html>')
const runtime = await nodeCoreRuntime('pkg')
for (const name of ['demo.fr.logos', 'v2full.fr.logos', 'v2unresolved.fr.nologos']) {
const env = (await readAttachedDocument(new Uint8Array(readFileSync(join(FIXTURES, `pdf/r3/${name}.pdf`))))) as Record<string, unknown>
const input = JSON.stringify({ report: env.report, sheetSnapshot: env.sheetSnapshot, branding: env.branding, labels: env.labels, locale: env.locale, exportedAt: env.exportedAt })
const session = unwrap(openExportSession(runtime, input), name)
const svgs: string[] = []
try {
for (;;) {
const step = unwrap(session.next(), 'next')
if (step.step === 'done') break
for (const r of step.requests) {
svgs.push(r.svg)
const b64: string = await page.evaluate(async ([svg, w, h]: [string, number, number]) => {
const root = new DOMParser().parseFromString(svg, 'image/svg+xml').documentElement
if (root.namespaceURI !== 'http://www.w3.org/2000/svg') root.setAttribute('xmlns', 'http://www.w3.org/2000/svg')
root.setAttribute('width', String(w)); root.setAttribute('height', String(h))
const url = URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(root)], { type: 'image/svg+xml;charset=utf-8' }))
const img = new Image(); img.decoding = 'sync'; img.src = url; await img.decode()
const c = document.createElement('canvas'); c.width = w; c.height = h
const ctx = c.getContext('2d')!; ctx.fillStyle = '#ffffff'; ctx.fillRect(0, 0, w, h); ctx.drawImage(img, 0, 0, w, h)
return c.toDataURL('image/png').split(',')[1]
}, [r.svg, r.widthPx, r.heightPx])
unwrap(session.addRaster(r.key, new Uint8Array(Buffer.from(b64, 'base64'))), r.key)
}
}
const parts = unwrap(session.finish(), 'finish')
writeFileSync(join(OUT!, `${name}.pdf`), Buffer.concat(parts))
writeFileSync(join(OUT!, `${name}.views.json`), JSON.stringify(svgs.length))
} finally {
session.free()
}
}
await browser.close()
}, 600_000)