INNER CODE UNIT · TypeScript
center
hyscaler/HyCanvas · packages/a11y/src/index.ts:95
const center = (n: Node) => {
const t = (n as { transform?: { x?: number; y?: number; scaleX?: number; scaleY?: number; rotation?: number } }).transform ?? {};
const s = (n as { size?: { width?: number; height?: number } }).size ?? {};
const rad = ((t.rotation ?? 0) * Math.PI) / 180;
const cos = Math.cos(rad);
const sin = Math.sin(rad);
const sx = t.scaleX ?? 1;
const sy = t.scaleY ?? 1;
const w = s.width ?? 0;
const h = s.height ?? 0;
let top = Infinity;
let cx = 0;
let cy = 0;
for (const [px, py] of [[0, 0], [w, 0], [w, h], [0, h]] as const) {
const x = (t.x ?? 0) + cos * sx * px - sin * sy * py;
const y = (t.y ?? 0) + sin * sx * px + cos * sy * py;
top = Math.min(top, y);
cx += x / 4;