@altano/satori-fit-text 0.1.1 → 0.1.2

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
@@ -15,13 +15,13 @@ yarn add @altano/satori-fit-text
15
15
  pnpm add @altano/satori-fit-text
16
16
  ```
17
17
 
18
- ## Example Usage
18
+ ## Basic Example
19
19
 
20
20
  ```ts
21
21
  import { findLargestUsableFontSize, type Font } from "@altano/satori-fit-text";
22
22
 
23
23
  async function getInter(): Promise<Font> {
24
- const interSemiBoldBuffer = await fetch(`https://rsms.me/inter/font-files/Inter-SemiBold.woff`).then((res) => res.arrayBuffer());
24
+ const interSemiBoldBuffer = await fetch(`https://files.terriblefish.com/fonts/Inter/v4/extras/otf/Inter-SemiBold.otf`).then((res) => res.arrayBuffer());
25
25
 
26
26
  const font = {
27
27
  name: "Inter",
@@ -41,9 +41,12 @@ const largestUsableFontSize = await findLargestUsableFontSize({
41
41
  console.log(largestUsableFontSize);
42
42
  ```
43
43
 
44
- ## Potential Uses
44
+ ## Example Uses
45
45
 
46
- Because this measures the maximum font size using Satori, the ideal use of this library is to determine the largest possible font size in something like an [Open Graph card](https://ogp.me/). If you dynamically generate Open Graph cards with text (e.g. the title of your blog post) you may want the text to fill the card's area as best as possible without overflowing. This library can help you achieve that.
46
+ - [React Component (sandbox)](https://codesandbox.io/s/altano-satori-fit-text-browser-example-j2gvk6)
47
+ - [Next.js Open Graph Card - Simple (codesandbox)](https://codesandbox.io/p/sandbox/altano-satori-fit-text-next-js-demo-sv4flc)
48
+ - [Next.js Open Graph Card - Complex](https://github.com/altano/alan.norbauer.com/blob/main/src/components/opengraph/image.tsx#L29-L35)
49
+ - [Node.js CLI App (codesandbox)](https://codesandbox.io/p/sandbox/github/altano/npm-packages/tree/main/codesandboxes/satori-fit-text-node-cli?file=%2Fpackage.json%3A1%2C1)
47
50
 
48
51
  ## Implementation
49
52
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,47 @@
1
- export * from "./fitText";
2
- export * from "./types";
3
- //# sourceMappingURL=index.d.ts.map
1
+ import { Font as Font$1 } from 'satori';
2
+
3
+ type Font = Font$1;
4
+
5
+ type FindOptions = {
6
+ /**
7
+ * The text you want to fit
8
+ */
9
+ text: string;
10
+ /**
11
+ * The font of your text. Options are the same as [those taken by
12
+ * Satori](https://github.com/vercel/satori#fonts), but only one font and not
13
+ * an array of fonts is accepted here.
14
+ */
15
+ font: Font;
16
+ /**
17
+ * The max width the text must be contained in
18
+ */
19
+ maxWidth: number;
20
+ /**
21
+ * The max height the text must be contained in
22
+ */
23
+ maxHeight: number;
24
+ /**
25
+ * Optional: the CSS line height factor to use, e.g. 1.1
26
+ */
27
+ lineHeight?: number | "normal";
28
+ /**
29
+ * The minimum font size that should be returned, even if smaller fonts fit
30
+ */
31
+ minFontSize?: number;
32
+ /**
33
+ * The maximum font size that should be returned, even if larger fonts fit
34
+ */
35
+ maxFontSize?: number;
36
+ /**
37
+ * The maximum number of font sizes to try before giving up. Defaults to 1000.
38
+ */
39
+ maxTries?: number;
40
+ };
41
+ /**
42
+ * Given text, dimensions, and some options, returns the largest font size that
43
+ * would keep the text contained within the dimensions.
44
+ */
45
+ declare function findLargestUsableFontSize({ text, font, maxWidth, maxHeight, lineHeight, minFontSize, maxFontSize, maxTries, }: FindOptions): Promise<number>;
46
+
47
+ export { type FindOptions, type Font, findLargestUsableFontSize };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altano/satori-fit-text",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Fit text to a bounding box in Node or the browser",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -36,31 +36,32 @@
36
36
  "@svgdotjs/svg.js": "^3.2.0",
37
37
  "debug": "^4.3.4",
38
38
  "he": "^1.2.0",
39
- "satori": "^0.10.3",
39
+ "satori": "^0.10.13",
40
40
  "satori-html": "^0.3.2",
41
- "svgdom": "^0.1.14"
41
+ "svgdom": "^0.1.19"
42
42
  },
43
43
  "devDependencies": {
44
- "@resvg/resvg-js": "^2.4.1",
45
- "@types/debug": "^4.1.8",
46
- "@types/he": "^1.2.0",
47
- "@types/jest-image-snapshot": "^6.2.0",
48
- "@types/react": "^18.2.21",
49
- "@types/react-dom": "^18.2.7",
50
- "@types/svgdom": "^0.1.0",
51
- "@vitest/coverage-v8": "^0.34.3",
52
- "@vitest/ui": "^0.30.1",
53
- "jest-image-snapshot": "^6.2.0",
44
+ "@resvg/resvg-js": "^2.6.0",
45
+ "@types/debug": "^4.1.12",
46
+ "@types/he": "^1.2.3",
47
+ "@types/jest-image-snapshot": "^6.4.0",
48
+ "@types/react": "^18.2.64",
49
+ "@types/react-dom": "^18.2.21",
50
+ "@types/svgdom": "^0.1.2",
51
+ "@vitest/coverage-v8": "^1.3.1",
52
+ "@vitest/ui": "^1.3.1",
53
+ "jest-image-snapshot": "^6.4.0",
54
54
  "npm-run-all": "^4.1.5",
55
- "react": "^18",
56
- "react-dom": "^18",
57
- "tsup": "^7.2.0",
58
- "typescript": "^5.1.6",
59
- "vite": "^4.4.9",
60
- "vitest": "^0.34.3",
55
+ "prettier": "^3.2.5",
56
+ "react": "^18.2.0",
57
+ "react-dom": "^18.2.0",
58
+ "tsup": "^8.0.2",
59
+ "typescript": "^5.4.2",
60
+ "vite": "^5.1.5",
61
+ "vitest": "^1.3.1",
61
62
  "@altano/assets": "0.0.0",
62
- "@altano/tsconfig": "0.0.0",
63
- "@altano/tiny-async-pool": "1.0.2"
63
+ "@altano/tiny-async-pool": "1.0.3",
64
+ "@altano/tsconfig": "0.0.0"
64
65
  },
65
66
  "scripts": {
66
67
  "build": "tsup",
@@ -69,7 +70,8 @@
69
70
  "lint": "eslint src/**/*.ts*",
70
71
  "lint:timing": "TIMING=1 eslint src/**/*.ts*",
71
72
  "lint:fix": "TIMING=1 eslint src/**/*.ts* --fix",
72
- "format": "prettier --write src",
73
+ "format": "prettier --check src",
74
+ "format:fix": "prettier --write src",
73
75
  "clean": "rm -rf .turbo && rm -rf .tsbuildinfo && rm -rf node_modules && rm -rf dist",
74
76
  "test": "run-s test:unit test:benchmark",
75
77
  "test:unit": "vitest --run",