Skip to content

Commit

Permalink
Merge pull request #67 from MetaCell/feature/66
Browse files Browse the repository at this point in the history
#66 fix: Update from Buffer.from to browser compatible
  • Loading branch information
afonsobspinto authored Dec 7, 2023
2 parents 1ffca5d + 1ee15ca commit e8562a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 5 additions & 4 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,7 +87,7 @@ const applicationTheme = (params: ThemeVars) => {
content: "";
width: 0.5rem;
height: 0.5rem;
background: url(data:image/svg+xml;base64,${btoa(
background: url(data:image/svg+xml;base64,${base64Encode(
topSubArrow
)});
position: absolute;
Expand All @@ -99,7 +100,7 @@ const applicationTheme = (params: ThemeVars) => {
content: "";
width: 0.5rem;
height: 0.5rem;
background: url(data:image/svg+xml;base64,${btoa(
background: url(data:image/svg+xml;base64,${base64Encode(
bottomSubArrow
)});
position: absolute;
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(
background: url(data:image/svg+xml;base64,${base64Encode(
nodeGreen
).toString('base64')});
)});
}
.primary-node .primary-node_header p {
Expand Down
11 changes: 11 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ 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 e8562a3

Please sign in to comment.