Skip to content

Commit

Permalink
fix: remove non-isomorphic and outdated dependency base64-to-uint8arr…
Browse files Browse the repository at this point in the history
…ay (#2023)
  • Loading branch information
carlobeltrame authored Nov 7, 2022
1 parent 0e7568d commit ce1c43c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-cameras-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@react-pdf/font': patch
---

Fix warning about 'buffer' dependency in CRA 5 and webpack 5
1 change: 0 additions & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"dependencies": {
"@babel/runtime": "^7.16.4",
"@react-pdf/types": "^2.0.9",
"base64-to-uint8array": "^1.0.0",
"cross-fetch": "^3.1.5",
"fontkit": "^2.0.2",
"is-url": "^1.2.4"
Expand Down
8 changes: 6 additions & 2 deletions packages/font/src/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import isUrl from 'is-url';
import fetch from 'cross-fetch';
import * as fontkit from 'fontkit';
import toUint8Array from 'base64-to-uint8array';

const FONT_WEIGHTS = {
thin: 100,
Expand Down Expand Up @@ -60,7 +59,12 @@ class FontSource {

if (isDataUrl(this.src)) {
const raw = this.src.split(',')[1];
this.data = fontkit.create(toUint8Array(raw), postscriptName);
const uint8Array = new Uint8Array(
atob(raw)
.split('')
.map(c => c.charCodeAt(0)),
);
this.data = fontkit.create(uint8Array, postscriptName);
} else if (BROWSER || isUrl(this.src)) {
const { headers, body, method = 'GET' } = this.options;
const data = await fetchFont(this.src, { method, body, headers });
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3268,11 +3268,6 @@ base64-js@^1.1.2, base64-js@^1.3.0, base64-js@^1.3.1:
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==

base64-to-uint8array@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/base64-to-uint8array/-/base64-to-uint8array-1.0.0.tgz#725f9e9886331b43785cadd807e76803d5494e05"
integrity sha512-drjWQcees55+XQSVHYxiUF05Fj6ko3XJUoxykZEXbm0BMmNz2ieWiZGJ+6TFWnjN2saucG6pI13LS92O4kaiAg==

base@^0.11.1:
version "0.11.2"
resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f"
Expand Down

0 comments on commit ce1c43c

Please sign in to comment.