@effing/canvas 0.25.0 → 0.26.0
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/dist/index.d.ts +3 -3
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -61,8 +61,8 @@ type FontData = {
|
|
|
61
61
|
* Options for {@link renderReactElement}.
|
|
62
62
|
*/
|
|
63
63
|
type RenderReactElementOptions = {
|
|
64
|
-
/** Font data for text rendering */
|
|
65
|
-
fonts
|
|
64
|
+
/** Font data for text rendering. Defaults to `[]` (system fonts). */
|
|
65
|
+
fonts?: FontData[];
|
|
66
66
|
/** Layout width override. Defaults to `ctx.canvas.width`. */
|
|
67
67
|
width?: number;
|
|
68
68
|
/** Layout height override. Defaults to `ctx.canvas.height`. */
|
|
@@ -110,7 +110,7 @@ type RenderReactElementOptions = {
|
|
|
110
110
|
* });
|
|
111
111
|
* ```
|
|
112
112
|
*/
|
|
113
|
-
declare function renderReactElement(ctx: SKRSContext2D, element: ReactNode, options
|
|
113
|
+
declare function renderReactElement(ctx: SKRSContext2D, element: ReactNode, options?: RenderReactElementOptions): Promise<void>;
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* Register a font from a FontData buffer.
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ function cachedLoadImage(cache, src) {
|
|
|
34
34
|
|
|
35
35
|
// src/jsx/style/compute.ts
|
|
36
36
|
var ROOT_FONT_SIZE = 16;
|
|
37
|
+
var DEFAULT_FONT_FAMILY = "Helvetica, Arial, sans-serif";
|
|
37
38
|
var DEFAULT_STYLE = {
|
|
38
39
|
display: "flex",
|
|
39
40
|
flexDirection: "row",
|
|
@@ -46,6 +47,7 @@ var DEFAULT_STYLE = {
|
|
|
46
47
|
fontSize: ROOT_FONT_SIZE,
|
|
47
48
|
fontWeight: 400,
|
|
48
49
|
fontStyle: "normal",
|
|
50
|
+
fontFamily: DEFAULT_FONT_FAMILY,
|
|
49
51
|
color: "black",
|
|
50
52
|
lineHeight: "normal",
|
|
51
53
|
textAlign: "left",
|
|
@@ -588,7 +590,7 @@ function emojiAwareMeasureWord(word, fontSize, fontFamily, fontWeight, fontStyle
|
|
|
588
590
|
}
|
|
589
591
|
function layoutText(text, style, maxWidth, ctx, emojiEnabled) {
|
|
590
592
|
const fontSize = style.fontSize ?? 16;
|
|
591
|
-
const fontFamily = style.fontFamily ??
|
|
593
|
+
const fontFamily = style.fontFamily ?? DEFAULT_FONT_FAMILY;
|
|
592
594
|
const fontWeight = style.fontWeight ?? 400;
|
|
593
595
|
const fontStyle = style.fontStyle ?? "normal";
|
|
594
596
|
const color = style.color ?? "black";
|
|
@@ -3755,12 +3757,13 @@ function hasElementChildren(children) {
|
|
|
3755
3757
|
}
|
|
3756
3758
|
|
|
3757
3759
|
// src/jsx/index.ts
|
|
3758
|
-
async function renderReactElement(ctx, element, options) {
|
|
3759
|
-
|
|
3760
|
+
async function renderReactElement(ctx, element, options = {}) {
|
|
3761
|
+
const fonts = options.fonts ?? [];
|
|
3762
|
+
ensureFontsRegistered(fonts);
|
|
3760
3763
|
const width = options.width ?? ctx.canvas.width;
|
|
3761
3764
|
const height = options.height ?? ctx.canvas.height;
|
|
3762
3765
|
const emojiStyle = options.emoji === "none" ? void 0 : options.emoji ?? "twemoji";
|
|
3763
|
-
const fontFamilies = [...new Set(
|
|
3766
|
+
const fontFamilies = [...new Set(fonts.map((f) => f.name))];
|
|
3764
3767
|
const { tree: layoutTree, imageCache } = await buildLayoutTree(
|
|
3765
3768
|
element,
|
|
3766
3769
|
width,
|