@effing/canvas 0.25.1 → 0.26.1
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/LICENSE +17 -7
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright © 2026,
|
|
3
|
+
Copyright © 2026, Few Software BV.
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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,
|