Skip to content

Commit

Permalink
#66 fix: Update from Buffer.from to browser compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Dec 7, 2023
1 parent 1ffca5d commit bbe622f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import vars from './components/assets/styles/variables';
import nodeGreen from './components/assets/svg/node/green.svg';
import topSubArrow from './components/assets/svg/sub-top-arrow.svg';
import bottomSubArrow from './components/assets/svg/sub-bottom-arrow.svg';
import { base64Encode } from './utils';

type ThemeVars = {
[key: string]: any;
Expand Down Expand Up @@ -86,9 +87,9 @@ const applicationTheme = (params: ThemeVars) => {
content: "";
width: 0.5rem;
height: 0.5rem;
background: url(data:image/svg+xml;base64,${btoa(
topSubArrow
)});
background: url(data:image/svg+xml;base64,${base64Encode(
topSubArrow

Check failure on line 91 in src/theme.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest

Insert `··`
)});

Check failure on line 92 in src/theme.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest

Insert `····`
position: absolute;
background-size: 150%;
top: -0.5rem;
Expand All @@ -99,9 +100,9 @@ const applicationTheme = (params: ThemeVars) => {
content: "";
width: 0.5rem;
height: 0.5rem;
background: url(data:image/svg+xml;base64,${btoa(
bottomSubArrow
)});
background: url(data:image/svg+xml;base64,${base64Encode(
bottomSubArrow

Check failure on line 104 in src/theme.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest

Insert `··`
)});

Check failure on line 105 in src/theme.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest

Insert `····`
position: absolute;
background-size: 150%;
bottom: -0.45rem;
Expand Down Expand Up @@ -172,9 +173,9 @@ const applicationTheme = (params: ThemeVars) => {
width: 1.25rem;
height: 1.25rem;
margin: 0 auto 0.25rem;
background: url(data:image/svg+xml;base64,${Buffer.from(
nodeGreen
).toString('base64')});
background: url(data:image/svg+xml;base64,${base64Encode(
nodeGreen

Check failure on line 177 in src/theme.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest

Insert `··`
)});

Check failure on line 178 in src/theme.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest

Insert `····`
}
.primary-node .primary-node_header p {
Expand Down Expand Up @@ -493,7 +494,7 @@ export const subBarStyle = {
};

export default (customVariables: ThemeVars) =>
applicationTheme({
...vars,
...customVariables,
});
applicationTheme({

Check failure on line 497 in src/theme.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest

Delete `··`
...vars,

Check failure on line 498 in src/theme.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest

Delete `··`
...customVariables,

Check failure on line 499 in src/theme.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest

Replace `······` with `····`
});

Check failure on line 500 in src/theme.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest

Replace `··});` with `});⏎`
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ export function updateCanvasMouseCursor(cursor = CursorTypes.TEXT) {
// element.
});
}


export function base64Encode(input: string) {
// Check if Buffer is available (Node.js environment)
if (typeof Buffer !== 'undefined') {
return Buffer.from(input).toString('base64');
}
// Browser environment
else {
return btoa(input);
}
}

0 comments on commit bbe622f

Please sign in to comment.