Classic now renders through buildRenderModel, computeFrame, the template and renderCore, with S.No and HSN/SAC columns, GST slots only through checked Slot components, taxable value, reverse-charge line, cancelled tag, continuation band and Page n of N. Letter absorbs its height deficit in elastic gaps. A harness runs 15 fixtures on A4 and Letter plus an item sweep and asserts zero audit errors, repeated headers, no split blocks, rupee extraction and deterministic output. The legacy InvoiceDocument is removed.
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { getMeasurer, measureToken } from "../engine/measure";
|
|
import { resolveFace, roleToken } from "../fonts/roles";
|
|
import { useAvailableWidth } from "./AvailableWidth";
|
|
import { IdText } from "./IdText";
|
|
import { Txt, type TxtProps } from "./Txt";
|
|
|
|
export interface SafeTxtProps extends Omit<TxtProps, "children" | "width" | "maxLines" | "grow"> {
|
|
children: string;
|
|
/** Width of the box; defaults to the available width of the enclosing cell. */
|
|
width?: number;
|
|
}
|
|
|
|
/**
|
|
* Free text (addresses, names, notes) that cannot overflow: normal text wraps at spaces in a box of the
|
|
* cell's width; a value with a single token wider than the cell (a long URL or an unbroken string) goes
|
|
* through IdText, which shrinks it or splits it at "@ . / - _". textkit never breaks inside a word,
|
|
* so without this such a token would run out of its box.
|
|
*/
|
|
export function SafeTxt({ children, width, align, ...rest }: SafeTxtProps) {
|
|
const avail = useAvailableWidth();
|
|
const w = width ?? avail;
|
|
const token = roleToken(rest.role);
|
|
const m = getMeasurer();
|
|
const family = resolveFace(token.face, rest.faceOverrides);
|
|
const widest = Math.max(
|
|
0,
|
|
...children.split(" ").map((word) => measureToken(m, token, word, { weight: rest.weight, italic: rest.italic, family })),
|
|
);
|
|
if (widest > w + 1e-6) {
|
|
return (
|
|
<IdText {...rest} width={w}>
|
|
{children}
|
|
</IdText>
|
|
);
|
|
}
|
|
return (
|
|
<Txt {...rest} align={align} width={w}>
|
|
{children}
|
|
</Txt>
|
|
);
|
|
}
|