@effing/canvas 0.42.0 โ 0.43.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/README.md +31 -24
- package/dist/index.d.ts +8 -6
- package/dist/index.js +500 -1035
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ Emoji characters are automatically rendered as images from CDNs. Supported style
|
|
|
87
87
|
| `fluent` | Microsoft Fluent Emoji (color) |
|
|
88
88
|
| `fluentFlat` | Microsoft Fluent Emoji (flat) |
|
|
89
89
|
|
|
90
|
-
Pass `emoji: "none"` to disable emoji image rendering.
|
|
90
|
+
An emoji is an emoji character ([UTS #51](https://www.unicode.org/reports/tr51/)), with or without U+FE0F (`๐`, `โค`, `โค๏ธ`, `๐ต`), a keycap (`1๏ธโฃ`), a flag (`๐ง๐ช`, `๐ด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ`), a skin-tone sequence (`๐๐ฝ`) or a ZWJ sequence of emoji (`๐จโ๐ฉโ๐ง`). Emoji characters are drawn as images even when Unicode presents them as text by default, except `ยฉ`, `ยฎ` and `โข`, which stay text unless U+FE0F follows them, and digits, `#` and `*`, which stay text unless a keycap follows them, as browsers draw them; U+FE0E keeps any emoji character text. For text-default emoji in the Basic Multilingual Plane, such as `โค` or `โ`, this differs from browsers, which draw them as monochrome text through the system's fallback fonts: canvas has no such fallback, so an image beats a missing glyph. Text-default emoji outside it, such as `๐ต` or `๐ณ`, are colour emoji in browsers too. Characters with no emoji form, such as `โ` or `โ`, are text. Each emoji takes an inline box of 1em on its line, with its bottom 0.1em below the baseline, about where browsers draw an emoji glyph. Lines break around it as browsers break them around an emoji, so it stays with the punctuation next to it (`๐!`, `(๐)`). Pass `emoji: "none"` to disable emoji image rendering. An emoji drawn without an image โ with `emoji: "none"`, one the style has no image for (the Fluent styles have no flags), or one whose image failed to load โ is drawn as text, so it needs a font that covers it among the text's font families (every font given to `renderReactElement` is one), as do text symbols.
|
|
91
91
|
|
|
92
92
|
## Fit Text
|
|
93
93
|
|
|
@@ -104,7 +104,7 @@ const fontSize = findLargestUsableFontSize({
|
|
|
104
104
|
});
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
By default the text wraps to `maxWidth` and is fit into the `maxWidth` ร `maxHeight` box. Pass `whiteSpace: "nowrap"` to fit the text on one line (per newline-separated paragraph)
|
|
107
|
+
By default the text wraps to `maxWidth` and is fit into the `maxWidth` ร `maxHeight` box. Pass `whiteSpace: "nowrap"` to fit the text on one line instead (or `"pre"` for one line per newline-separated paragraph), where `maxWidth` constrains the full line width:
|
|
108
108
|
|
|
109
109
|
```typescript
|
|
110
110
|
const fontSize = findLargestUsableFontSize({
|
|
@@ -116,7 +116,7 @@ const fontSize = findLargestUsableFontSize({
|
|
|
116
116
|
});
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
Supports optional `lineHeight` (`"normal"` or a numeric multiplier), `whiteSpace` (`"normal"` by default; `"nowrap"
|
|
119
|
+
Supports optional `lineHeight` (`"normal"` or a numeric multiplier), `whiteSpace` (`"normal"` by default; `"nowrap"` for one line, `"pre"` for one line per paragraph), `minFontSize` (default 1), and `maxFontSize` (default 1000).
|
|
120
120
|
|
|
121
121
|
## Inline SVG
|
|
122
122
|
|
|
@@ -245,27 +245,34 @@ const png = canvas.encodeSync("png");
|
|
|
245
245
|
|
|
246
246
|
### Typography
|
|
247
247
|
|
|
248
|
-
| Property | Values / Notes
|
|
249
|
-
| ----------------------- |
|
|
250
|
-
| `fontFamily` | Font name (inherited)
|
|
251
|
-
| `fontSize` | Number or CSS length (inherited)
|
|
252
|
-
| `fontWeight` | Numeric weight (inherited)
|
|
253
|
-
| `fontStyle` | `normal`, `italic` (inherited)
|
|
254
|
-
| `textAlign` | `left`, `center`, `right`, `justify` (inherited)
|
|
255
|
-
| `textDecoration` | String (inherited)
|
|
256
|
-
| `textTransform` | `none`, `uppercase`, `lowercase`, `capitalize` (inherited)
|
|
257
|
-
| `lineHeight` | Number or string (inherited)
|
|
258
|
-
| `letterSpacing` | Number or CSS length (inherited)
|
|
259
|
-
| `whiteSpace` | `normal`, `nowrap`, `pre`, `pre-wrap`, `pre-line` (inherited) |
|
|
260
|
-
| `wordBreak` | `normal`, `break-all`, `
|
|
261
|
-
| `
|
|
262
|
-
| `
|
|
263
|
-
| `
|
|
264
|
-
| `
|
|
265
|
-
| `
|
|
266
|
-
| `
|
|
267
|
-
| `
|
|
268
|
-
| `
|
|
248
|
+
| Property | Values / Notes |
|
|
249
|
+
| ----------------------- | -------------------------------------------------------------- |
|
|
250
|
+
| `fontFamily` | Font name (inherited) |
|
|
251
|
+
| `fontSize` | Number or CSS length (inherited) |
|
|
252
|
+
| `fontWeight` | Numeric weight (inherited) |
|
|
253
|
+
| `fontStyle` | `normal`, `italic` (inherited) |
|
|
254
|
+
| `textAlign` | `left`, `center`, `right`, `justify` (inherited) |
|
|
255
|
+
| `textDecoration` | String (inherited) |
|
|
256
|
+
| `textTransform` | `none`, `uppercase`, `lowercase`, `capitalize` (inherited) |
|
|
257
|
+
| `lineHeight` | Number or string (inherited) |
|
|
258
|
+
| `letterSpacing` | Number or CSS length (inherited) |
|
|
259
|
+
| `whiteSpace` | `normal`, `nowrap`, `pre`, `pre-wrap`, `pre-line` (inherited)ยน |
|
|
260
|
+
| `wordBreak` | `normal`, `break-all`, `keep-all`, `break-word`ยฒ (inherited) |
|
|
261
|
+
| `overflowWrap` | `normal`, `break-word`, `anywhere`ยฒ (inherited) |
|
|
262
|
+
| `textOverflow` | `clip`, `ellipsis` (inherited) |
|
|
263
|
+
| `lineClamp` | Number โ max visible lines (adds ellipsis)ยณ |
|
|
264
|
+
| `textBox` | Shorthand for `textBoxTrim` and `textBoxEdge` |
|
|
265
|
+
| `textBoxTrim` | `none`, `trim-start`, `trim-end`, `trim-both` (inherited) |
|
|
266
|
+
| `textBoxEdge` | e.g. `"cap alphabetic"` (inherited) |
|
|
267
|
+
| `WebkitTextStroke` | Shorthand, e.g. `"2px red"` (inherited) |
|
|
268
|
+
| `WebkitTextStrokeWidth` | CSS length (inherited) |
|
|
269
|
+
| `WebkitTextStrokeColor` | Any CSS color (inherited) |
|
|
270
|
+
|
|
271
|
+
ยน White space is processed as in CSS: under `normal`, `nowrap` and `pre-line`, a run of spaces and tabs collapses to one space, the spaces at the start and end of the text and around a newline are removed, and a newline becomes a space (`pre-line` keeps it as a line break). Adjacent strings, as `Hello {name}` gives, are one run of text, and each run of text between elements is laid out as a flex item of its own, as browsers lay out text in a flex container: a run of nothing but white space, such as `{" "}` between two elements, isn't rendered, and an element whose only text is empty or white space has no line box. Fragments, arrays and function components are unwrapped first, as the DOM has no trace of them. A `<br />` is an item of its own, not a forced break inside a run of text: in a column it puts the text after it on the next line, but in a row (the default `flexDirection`) the text either side of it sits side by side, where browsers stack it. A line or paragraph separator (U+2028, U+2029) is a space with a break opportunity after it, as in browsers, but with `letterSpacing` it gets the spacing twice where browsers add it once. `pre` and `pre-wrap` keep the spaces before a line break in the line's width and alignment, as browsers do; a tab is one space wide. A CRLF counts as one newline, and `pre` and `pre-wrap` drop a lone CR, which browsers draw as nothing.
|
|
272
|
+
|
|
273
|
+
ยฒ A word wider than its line overflows it, as in CSS, unless `overflowWrap` is `break-word` or `anywhere` (or `wordBreak` the deprecated `break-word`): the word then starts a line of its own and is broken between grapheme clusters where that line is full. `anywhere` breaks as `break-word` does.
|
|
274
|
+
|
|
275
|
+
ยณ The last line shown is its own text with an ellipsis after it, cut to fit, as in browsers. Under `whiteSpace: "pre"`, a clamped line that ends at a newline gets no ellipsis, where browsers add one. Canvas aligns the clamped line with its ellipsis, where browsers align its text alone and let the ellipsis overflow (hidden by `overflow: hidden`): right-aligned, `"ab\ncd"` clamped to one line is "abโฆ" at the right edge, where browsers show "ab" there.
|
|
269
276
|
|
|
270
277
|
### Effects
|
|
271
278
|
|
package/dist/index.d.ts
CHANGED
|
@@ -277,6 +277,7 @@ type ComputedStyle = {
|
|
|
277
277
|
letterSpacing?: number | string;
|
|
278
278
|
whiteSpace?: "normal" | "nowrap" | "pre" | "pre-wrap" | "pre-line";
|
|
279
279
|
wordBreak?: "normal" | "break-all" | "break-word" | "keep-all";
|
|
280
|
+
overflowWrap?: "normal" | "break-word" | "anywhere";
|
|
280
281
|
textOverflow?: "clip" | "ellipsis";
|
|
281
282
|
lineClamp?: number;
|
|
282
283
|
boxShadow?: string;
|
|
@@ -308,9 +309,10 @@ type FindLargestUsableFontSizeOptions = {
|
|
|
308
309
|
/** Line height โ `"normal"` uses font metrics, numeric values are CSS multipliers */
|
|
309
310
|
lineHeight?: number | "normal";
|
|
310
311
|
/**
|
|
311
|
-
* Whitespace handling,
|
|
312
|
-
* on one line
|
|
313
|
-
*
|
|
312
|
+
* Whitespace handling, as in CSS (default: `"normal"`). Use `"nowrap"` to
|
|
313
|
+
* fit the text on one line instead of wrapping to `maxWidth`, its newlines
|
|
314
|
+
* collapsing to spaces, or `"pre"` to fit each newline-separated paragraph
|
|
315
|
+
* on a line of its own.
|
|
314
316
|
*/
|
|
315
317
|
whiteSpace?: ComputedStyle["whiteSpace"];
|
|
316
318
|
/** Minimum font size to consider (default: 1) */
|
|
@@ -325,9 +327,9 @@ type FindLargestUsableFontSizeOptions = {
|
|
|
325
327
|
* at each step. Returns `minFontSize` if even the smallest size overflows.
|
|
326
328
|
*
|
|
327
329
|
* By default text wraps to `maxWidth` and is fit into the `maxWidth` ร `maxHeight`
|
|
328
|
-
* box. Set `whiteSpace: "nowrap"` to fit the text on one line (
|
|
329
|
-
* newline-separated paragraph)
|
|
330
|
-
* full line width.
|
|
330
|
+
* box. Set `whiteSpace: "nowrap"` to fit the text on one line instead (or
|
|
331
|
+
* `"pre"` for one line per newline-separated paragraph), in which case
|
|
332
|
+
* `maxWidth` constrains the full line width.
|
|
331
333
|
*/
|
|
332
334
|
declare function findLargestUsableFontSize(options: FindLargestUsableFontSizeOptions): number;
|
|
333
335
|
|