@effing/canvas 0.38.4 → 0.39.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 +13 -1
- package/dist/index.d.ts +97 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -108,7 +108,19 @@ const fontSize = findLargestUsableFontSize({
|
|
|
108
108
|
});
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
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:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const fontSize = findLargestUsableFontSize({
|
|
115
|
+
text: "Hello World",
|
|
116
|
+
font,
|
|
117
|
+
maxWidth: 500,
|
|
118
|
+
maxHeight: 100,
|
|
119
|
+
whiteSpace: "nowrap",
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
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).
|
|
112
124
|
|
|
113
125
|
## Inline SVG
|
|
114
126
|
|
package/dist/index.d.ts
CHANGED
|
@@ -205,6 +205,92 @@ declare function registerFontFromPath(path: string, nameAlias?: string): void;
|
|
|
205
205
|
*/
|
|
206
206
|
declare function registeredFamilies(): string[];
|
|
207
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Normalized, computed CSS style after shorthand expansion.
|
|
210
|
+
* All dimension values are numbers (pixels) or percentage strings.
|
|
211
|
+
*/
|
|
212
|
+
type ComputedStyle = {
|
|
213
|
+
display?: "flex" | "none";
|
|
214
|
+
flexDirection?: "row" | "column" | "row-reverse" | "column-reverse";
|
|
215
|
+
justifyContent?: "flex-start" | "flex-end" | "center" | "space-between" | "space-around" | "space-evenly";
|
|
216
|
+
alignItems?: "flex-start" | "flex-end" | "center" | "stretch" | "baseline";
|
|
217
|
+
alignSelf?: "auto" | "flex-start" | "flex-end" | "center" | "stretch" | "baseline";
|
|
218
|
+
alignContent?: "flex-start" | "flex-end" | "center" | "stretch" | "space-between" | "space-around";
|
|
219
|
+
flexWrap?: "nowrap" | "wrap" | "wrap-reverse";
|
|
220
|
+
flexGrow?: number;
|
|
221
|
+
flexShrink?: number;
|
|
222
|
+
flexBasis?: number | string;
|
|
223
|
+
width?: number | string;
|
|
224
|
+
height?: number | string;
|
|
225
|
+
minWidth?: number | string;
|
|
226
|
+
minHeight?: number | string;
|
|
227
|
+
maxWidth?: number | string;
|
|
228
|
+
maxHeight?: number | string;
|
|
229
|
+
position?: "relative" | "absolute";
|
|
230
|
+
top?: number | string;
|
|
231
|
+
right?: number | string;
|
|
232
|
+
bottom?: number | string;
|
|
233
|
+
left?: number | string;
|
|
234
|
+
marginTop?: number | string;
|
|
235
|
+
marginRight?: number | string;
|
|
236
|
+
marginBottom?: number | string;
|
|
237
|
+
marginLeft?: number | string;
|
|
238
|
+
paddingTop?: number | string;
|
|
239
|
+
paddingRight?: number | string;
|
|
240
|
+
paddingBottom?: number | string;
|
|
241
|
+
paddingLeft?: number | string;
|
|
242
|
+
borderTopWidth?: number | string;
|
|
243
|
+
borderRightWidth?: number | string;
|
|
244
|
+
borderBottomWidth?: number | string;
|
|
245
|
+
borderLeftWidth?: number | string;
|
|
246
|
+
borderTopColor?: string;
|
|
247
|
+
borderRightColor?: string;
|
|
248
|
+
borderBottomColor?: string;
|
|
249
|
+
borderLeftColor?: string;
|
|
250
|
+
borderTopStyle?: string;
|
|
251
|
+
borderRightStyle?: string;
|
|
252
|
+
borderBottomStyle?: string;
|
|
253
|
+
borderLeftStyle?: string;
|
|
254
|
+
borderTopLeftRadius?: number | string;
|
|
255
|
+
borderTopRightRadius?: number | string;
|
|
256
|
+
borderBottomRightRadius?: number | string;
|
|
257
|
+
borderBottomLeftRadius?: number | string;
|
|
258
|
+
rowGap?: number;
|
|
259
|
+
columnGap?: number;
|
|
260
|
+
overflow?: string;
|
|
261
|
+
overflowX?: string;
|
|
262
|
+
overflowY?: string;
|
|
263
|
+
backgroundColor?: string;
|
|
264
|
+
color?: string;
|
|
265
|
+
opacity?: number;
|
|
266
|
+
backgroundImage?: string;
|
|
267
|
+
backgroundSize?: string;
|
|
268
|
+
backgroundRepeat?: "repeat" | "no-repeat" | "repeat-x" | "repeat-y" | "space" | "round";
|
|
269
|
+
fontSize?: number;
|
|
270
|
+
fontFamily?: string;
|
|
271
|
+
fontWeight?: number | string;
|
|
272
|
+
fontStyle?: "normal" | "italic";
|
|
273
|
+
textAlign?: "left" | "center" | "right" | "justify";
|
|
274
|
+
textDecoration?: string;
|
|
275
|
+
textTransform?: "none" | "uppercase" | "lowercase" | "capitalize";
|
|
276
|
+
lineHeight?: number | string;
|
|
277
|
+
letterSpacing?: number | string;
|
|
278
|
+
whiteSpace?: "normal" | "nowrap" | "pre" | "pre-wrap" | "pre-line";
|
|
279
|
+
wordBreak?: "normal" | "break-all" | "break-word" | "keep-all";
|
|
280
|
+
textOverflow?: "clip" | "ellipsis";
|
|
281
|
+
lineClamp?: number;
|
|
282
|
+
boxShadow?: string;
|
|
283
|
+
textShadow?: string;
|
|
284
|
+
transform?: string;
|
|
285
|
+
transformOrigin?: string;
|
|
286
|
+
objectFit?: "contain" | "cover" | "fill" | "none" | "scale-down";
|
|
287
|
+
filter?: string;
|
|
288
|
+
textBoxTrim?: "none" | "trim-start" | "trim-end" | "trim-both";
|
|
289
|
+
textBoxEdge?: string;
|
|
290
|
+
WebkitTextStrokeWidth?: number | string;
|
|
291
|
+
WebkitTextStrokeColor?: string;
|
|
292
|
+
};
|
|
293
|
+
|
|
208
294
|
/**
|
|
209
295
|
* Options for {@link findLargestUsableFontSize}.
|
|
210
296
|
*/
|
|
@@ -219,6 +305,12 @@ type FindLargestUsableFontSizeOptions = {
|
|
|
219
305
|
maxHeight: number;
|
|
220
306
|
/** Line height — `"normal"` uses font metrics, numeric values are CSS multipliers */
|
|
221
307
|
lineHeight?: number | "normal";
|
|
308
|
+
/**
|
|
309
|
+
* Whitespace handling, mirroring CSS. Use `"nowrap"` (or `"pre"`) to fit text
|
|
310
|
+
* on one line (per newline-separated paragraph) instead of wrapping to
|
|
311
|
+
* `maxWidth` (default: `"normal"`).
|
|
312
|
+
*/
|
|
313
|
+
whiteSpace?: ComputedStyle["whiteSpace"];
|
|
222
314
|
/** Minimum font size to consider (default: 1) */
|
|
223
315
|
minFontSize?: number;
|
|
224
316
|
/** Maximum font size to consider (default: 1000) */
|
|
@@ -229,6 +321,11 @@ type FindLargestUsableFontSizeOptions = {
|
|
|
229
321
|
*
|
|
230
322
|
* Uses binary search over integer font sizes, measuring with {@link layoutText}
|
|
231
323
|
* at each step. Returns `minFontSize` if even the smallest size overflows.
|
|
324
|
+
*
|
|
325
|
+
* By default text wraps to `maxWidth` and is fit into the `maxWidth` × `maxHeight`
|
|
326
|
+
* box. Set `whiteSpace: "nowrap"` to fit the text on one line (per
|
|
327
|
+
* newline-separated paragraph) instead, in which case `maxWidth` constrains the
|
|
328
|
+
* full line width.
|
|
232
329
|
*/
|
|
233
330
|
declare function findLargestUsableFontSize(options: FindLargestUsableFontSizeOptions): number;
|
|
234
331
|
|
package/dist/index.js
CHANGED
|
@@ -4049,6 +4049,7 @@ function findLargestUsableFontSize(options) {
|
|
|
4049
4049
|
maxWidth,
|
|
4050
4050
|
maxHeight,
|
|
4051
4051
|
lineHeight = "normal",
|
|
4052
|
+
whiteSpace,
|
|
4052
4053
|
minFontSize = 1,
|
|
4053
4054
|
maxFontSize = 1e3
|
|
4054
4055
|
} = options;
|
|
@@ -4063,7 +4064,8 @@ function findLargestUsableFontSize(options) {
|
|
|
4063
4064
|
fontFamily: font.name,
|
|
4064
4065
|
fontWeight: font.weight,
|
|
4065
4066
|
fontStyle: font.style,
|
|
4066
|
-
lineHeight: lineHeight === "normal" ? void 0 : lineHeight
|
|
4067
|
+
lineHeight: lineHeight === "normal" ? void 0 : lineHeight,
|
|
4068
|
+
whiteSpace
|
|
4067
4069
|
};
|
|
4068
4070
|
const result = layoutText(text, style, maxWidth);
|
|
4069
4071
|
if (result.width <= maxWidth && result.height <= maxHeight) {
|