@simple-mark/canvas 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +5 -0
- package/index.js +6 -3
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -39,6 +39,11 @@ interface TextRun {
|
|
|
39
39
|
height: number;
|
|
40
40
|
textTop: number;
|
|
41
41
|
font: string;
|
|
42
|
+
/**
|
|
43
|
+
* The line's own font (without inline styles). Its metrics give the baseline every run on the
|
|
44
|
+
* line sits on, as in a browser, where inline code in another font shares the line's baseline.
|
|
45
|
+
*/
|
|
46
|
+
lineFont: string;
|
|
42
47
|
fontSize: number;
|
|
43
48
|
color: string;
|
|
44
49
|
/** Behind this text only (inline code). */
|
package/index.js
CHANGED
|
@@ -85,6 +85,7 @@ function layoutMarkdown(source, options) {
|
|
|
85
85
|
const lineHeight = style.lineHeight * style.fontSize * scale;
|
|
86
86
|
const textTop = (lineHeight - style.fontSize * scale) / 2;
|
|
87
87
|
const indent = lineLook.borderLeft ? EM.quoteIndent * style.fontSize : 0;
|
|
88
|
+
const lineFont = fontOf(resolveLook(styles, [], theme), style, theme, scale);
|
|
88
89
|
const table = styles.includes("table");
|
|
89
90
|
const available = wrapWidth - indent;
|
|
90
91
|
const pieces = [];
|
|
@@ -176,6 +177,7 @@ function layoutMarkdown(source, options) {
|
|
|
176
177
|
height: lineHeight,
|
|
177
178
|
textTop: y + textTop,
|
|
178
179
|
font,
|
|
180
|
+
lineFont,
|
|
179
181
|
fontSize: style.fontSize * scale,
|
|
180
182
|
color: look.color ?? style.color,
|
|
181
183
|
...look.background ? { background: look.background } : {},
|
|
@@ -361,11 +363,12 @@ function createMathImages(onReady) {
|
|
|
361
363
|
const PLACEHOLDER = "rgba(129, 139, 152, 0.15)";
|
|
362
364
|
/**
|
|
363
365
|
* Where text sits in its line, as a browser places it: the line's extra height (half-leading)
|
|
364
|
-
* split above and below the
|
|
365
|
-
* the layout's estimate where a browser doesn't give font metrics.
|
|
366
|
+
* split above and below the ascent + descent of the line's font, every run on that baseline.
|
|
367
|
+
* Falls back to the layout's estimate where a browser doesn't give font metrics.
|
|
366
368
|
*/
|
|
367
369
|
function baseline(ctx, run) {
|
|
368
370
|
ctx.textBaseline = "alphabetic";
|
|
371
|
+
ctx.font = run.lineFont;
|
|
369
372
|
const metrics = ctx.measureText("x");
|
|
370
373
|
const ascent = metrics.fontBoundingBoxAscent;
|
|
371
374
|
const descent = metrics.fontBoundingBoxDescent;
|
|
@@ -392,8 +395,8 @@ function paintMarkdown(ctx, layout, sources = {}, color = "#1f2328") {
|
|
|
392
395
|
}
|
|
393
396
|
}
|
|
394
397
|
for (const run of layout.runs) {
|
|
395
|
-
ctx.font = run.font;
|
|
396
398
|
const { y, alphabetic } = baseline(ctx, run);
|
|
399
|
+
ctx.font = run.font;
|
|
397
400
|
ctx.textBaseline = alphabetic ? "alphabetic" : "top";
|
|
398
401
|
if (run.background) {
|
|
399
402
|
ctx.fillStyle = run.background;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simple-mark/canvas",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Draws Markdown on a <canvas> without hiding its syntax: layout (no DOM) and Canvas 2D painting.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@simple-mark/math": "^0.3.
|
|
27
|
-
"@simple-mark/model": "^0.3.
|
|
26
|
+
"@simple-mark/math": "^0.3.3",
|
|
27
|
+
"@simple-mark/model": "^0.3.3"
|
|
28
28
|
}
|
|
29
29
|
}
|