@effing/canvas 0.42.0 → 0.44.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 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) instead, where `maxWidth` constrains the full line width:
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"`/`"pre"` for one line per paragraph), `minFontSize` (default 1), and `maxFontSize` (default 1000).
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,40 +245,51 @@ 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`, `break-word`, `keep-all` (inherited) |
261
- | `textOverflow` | `clip`, `ellipsis` (inherited) |
262
- | `lineClamp` | Number — max visible lines (adds ellipsis) |
263
- | `textBox` | Shorthand for `textBoxTrim` and `textBoxEdge` |
264
- | `textBoxTrim` | `none`, `trim-start`, `trim-end`, `trim-both` (inherited) |
265
- | `textBoxEdge` | e.g. `"cap alphabetic"` (inherited) |
266
- | `WebkitTextStroke` | Shorthand, e.g. `"2px red"` (inherited) |
267
- | `WebkitTextStrokeWidth` | CSS length (inherited) |
268
- | `WebkitTextStrokeColor` | Any CSS color (inherited) |
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 a forced line break in the run of text around it, under every `whiteSpace` (`nowrap` included), as in browsers: the text either side of it is one item, in a row as in a column, and the spaces before and after it are removed where spaces collapse. A `<br />` between two elements is an item of one empty line. A line or paragraph separator (U+2028, U+2029) is a space with a break opportunity after it, as in browsers, `letterSpacing` included. `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. Under `pre` and `pre-wrap`, a lone CR is drawn as nothing and doesn't break the line, as in browsers, but the letters either side of it don't kern or join; elsewhere it's a space.
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. 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.
276
+
277
+ ⁴ `normal` line boxes are sized as in Chrome on macOS: the font's hhea ascent, descent and line gap, each rounded to whole pixels, with the baseline at the rounded ascent plus half the line gap. They follow the first available font in `fontFamily` alone, where browsers also grow a line for a fallback font that draws some of its text.
269
278
 
270
279
  ### Effects
271
280
 
272
281
  | Property | Values / Notes |
273
282
  | ----------------- | ------------------------------------------------ |
274
- | `boxShadow` | CSS box-shadow string |
275
- | `textShadow` | CSS text-shadow string |
283
+ | `boxShadow` | CSS box-shadow list¹ |
284
+ | `textShadow` | CSS text-shadow list¹ (inherited) |
276
285
  | `transform` | `translate`, `scale`, `rotate`, `skewX`, `skewY` |
277
286
  | `transformOrigin` | CSS transform-origin string |
278
287
  | `filter` | CSS filter string |
279
288
  | `backdropFilter` | CSS filter string applied to the backdrop |
280
289
  | `clipPath` | Basic shapes, `shape()`, geometry boxes, `none` |
281
290
 
291
+ ¹ As in CSS: a comma-separated list of shadows, the first painted on top. A box shadow is `inset`, two to four lengths (x and y offsets, blur radius, spread) and a colour, in either order; a text shadow is two or three lengths (no spread or `inset`) and a colour. A shadow without a colour is cast in `currentColor`. A spread grows the shadow's shape (or, negative, shrinks it), and its corner radii with it; an `inset` shadow is cast inside the padding box, clipped to its rounded corners. Lengths are in px or any unit canvas resolves (`em`, `rem`, `vw`, `pt`, …; a bare number is read as px). An invalid value casts no shadow, as CSS ignores it.
292
+
282
293
  ### Image
283
294
 
284
295
  | Property | Values / Notes |
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, mirroring CSS. Use `"nowrap"` (or `"pre"`) to fit text
312
- * on one line (per newline-separated paragraph) instead of wrapping to
313
- * `maxWidth` (default: `"normal"`).
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 (per
329
- * newline-separated paragraph) instead, in which case `maxWidth` constrains the
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