openpencil/scripts/probe-layout.ts
Kayshen-X 2ab2a86fdc
Some checks failed
Rust check (native) / macos-latest / 1.94 (push) Waiting to run
Rust check (native) / windows-latest / 1.94 (push) Waiting to run
Rust multi-platform build / linux-aarch64 (push) Waiting to run
Rust multi-platform build / macos-aarch64 (push) Waiting to run
Rust multi-platform build / windows-x86_64 (push) Waiting to run
Rust multi-platform build / macos-x86_64 (push) Waiting to run
Rust multi-platform build / windows-aarch64 (push) Waiting to run
Rust multi-platform build / ios-aarch64 (cargo check only) (push) Waiting to run
Rust multi-platform build / ios-aarch64-sim (cargo check only) (push) Waiting to run
Rust check (native) / ubuntu-latest / 1.94 (push) Failing after 2s
Rust check (native) / cargo-deny (native) (push) Failing after 1s
Rust check (native) / diagnostics golden drift (push) Failing after 2s
Rust multi-platform build / linux-x86_64 (push) Failing after 2s
Rust multi-platform build / wasm32-unknown-unknown / op-host-web (compile guard) (push) Failing after 1s
Rust multi-platform build / android-aarch64 (cargo check only) (push) Failing after 2s
Rust multi-platform build / android-x86_64 (cargo check only) (push) Failing after 1s
WASM bundle check (kickoff §1.2) / cargo check --target wasm32-unknown-unknown (push) Failing after 1s
WASM bundle check (kickoff §1.2) / cargo-deny --target wasm32-unknown-unknown check bans (push) Failing after 2s
fix(editor): improve rust parity and figma import performance
2026-05-27 21:51:57 +08:00

85 lines
2.7 KiB
TypeScript

/* eslint-disable no-console */
// Drive `computeLayoutPositions` directly on the 5-card horizontal
// frame from /tmp/op-figma-ts.json and print the children x/y AFTER
// layout, so we can compare with authored values.
import { readFileSync } from 'node:fs';
import { computeLayoutPositions } from '../packages/pen-core/src/layout/engine';
import type { PenNode } from '../packages/pen-types/src';
const doc = JSON.parse(readFileSync('/tmp/op-figma-ts.json', 'utf8'));
function find5CardFrame(node: PenNode): PenNode | null {
if (
node.type === 'frame' &&
(node as any).layout === 'horizontal' &&
Array.isArray((node as any).children)
) {
const flat: string[] = [];
function go(x: any): void {
if (x?.type === 'text') {
const t =
typeof x.content === 'string'
? x.content
: Array.isArray(x.content)
? x.content.map((s: any) => s.text).join('')
: '';
flat.push(t);
}
if (x?.children) for (const c of x.children) go(c);
}
for (const c of (node as any).children) go(c);
if (flat.includes('一级高风险') && flat.includes('其他')) return node;
}
if ('children' in (node as any)) {
for (const c of (node as any).children ?? []) {
const r = find5CardFrame(c);
if (r) return r;
}
}
return null;
}
let parent: PenNode | null = null;
for (const p of doc.pages ?? []) {
for (const c of p.children) {
if (!parent) parent = find5CardFrame(c);
}
}
if (!parent) {
console.error('not found');
process.exit(1);
}
const kids = (parent as any).children;
console.log('AUTHORED:');
kids.forEach((c: any, i: number) => {
const t = (() => {
const out: string[] = [];
function go(x: any): void {
if (x?.type === 'text') {
out.push(typeof x.content === 'string' ? x.content : Array.isArray(x.content) ? x.content.map((s: any) => s.text).join('') : '');
}
if (x?.children) for (const c of x.children) go(c);
}
go(c);
return out[0] ?? '';
})();
console.log(` [${i}] ${c.type} x=${c.x} y=${c.y} w=${JSON.stringify((c as any).width)} text=${JSON.stringify(t)}`);
});
console.log('\nAFTER computeLayoutPositions:');
const after = computeLayoutPositions(parent, kids);
after.forEach((c: any, i: number) => {
const t = (() => {
const out: string[] = [];
function go(x: any): void {
if (x?.type === 'text') {
out.push(typeof x.content === 'string' ? x.content : Array.isArray(x.content) ? x.content.map((s: any) => s.text).join('') : '');
}
if (x?.children) for (const c of x.children) go(c);
}
go(c);
return out[0] ?? '';
})();
console.log(` [${i}] ${c.type} x=${c.x} y=${c.y} w=${JSON.stringify((c as any).width)} text=${JSON.stringify(t)}`);
});