Add hr
This commit is contained in:
parent
3adf3bf76d
commit
e786943d16
@ -5,6 +5,7 @@ export type Piece =
|
||||
| { type: "text"; text: string; isBold?: boolean; isItalic?: boolean }
|
||||
| { type: "space" }
|
||||
| { type: "break" }
|
||||
| { type: "hr" }
|
||||
| {
|
||||
type: "symbol";
|
||||
symbol: "coin" | "debt" | "potion" | "vp" | "vp-token";
|
||||
@ -127,6 +128,28 @@ const breakPiece = pieceDef({
|
||||
render() {},
|
||||
});
|
||||
|
||||
const hrPiece = pieceDef({
|
||||
type: "hr",
|
||||
measure(context, _piece) {
|
||||
const metrics = context.measureText(" ");
|
||||
return {
|
||||
type: "content",
|
||||
width: 750,
|
||||
ascent: metrics.fontBoundingBoxAscent / 3,
|
||||
descent: metrics.fontBoundingBoxDescent / 3,
|
||||
};
|
||||
},
|
||||
render(context, _piece, x, y, measure) {
|
||||
context.save();
|
||||
context.beginPath();
|
||||
context.moveTo(x, y);
|
||||
context.lineTo(x + measure.width, y);
|
||||
context.lineWidth = 8;
|
||||
context.stroke();
|
||||
context.restore();
|
||||
},
|
||||
});
|
||||
|
||||
const symbolPiece = pieceDef({
|
||||
type: "symbol",
|
||||
measure(context, piece) {
|
||||
@ -168,7 +191,7 @@ const symbolPiece = pieceDef({
|
||||
},
|
||||
});
|
||||
|
||||
const pieceDefs = [textPiece, spacePiece, breakPiece, symbolPiece];
|
||||
const pieceDefs = [textPiece, spacePiece, breakPiece, symbolPiece, hrPiece];
|
||||
|
||||
const tools: PieceTools = {} as any;
|
||||
|
||||
@ -360,6 +383,12 @@ export const parse = (text: string): Piece[] => {
|
||||
text: "+",
|
||||
});
|
||||
}
|
||||
} else if (
|
||||
char === "-" &&
|
||||
text[i - 1] === "\n" &&
|
||||
text[i + 1] === "\n"
|
||||
) {
|
||||
pieces.push({ type: "hr" });
|
||||
} else {
|
||||
const end = text.slice(i).match(/[^$ \n]+/)![0].length;
|
||||
pieces.push({ type: "text", text: text.slice(i, i + end) });
|
||||
|
Loading…
x
Reference in New Issue
Block a user