Skip to content

Commit

Permalink
Bring own multibyteBtoa to reduce deps
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbierner committed Jun 6, 2023
1 parent df045e2 commit eca31d5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 80 deletions.
1 change: 0 additions & 1 deletion build/web-extension.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = /** @type WebpackConfig */ {
process: "process/browser"
},
fallback: {
"path": require.resolve('path-browserify'),
"fs": false
}
},
Expand Down
77 changes: 8 additions & 69 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,8 @@
"package-web": "webpack --mode production --devtool hidden-source-map --config ./build/web-extension.webpack.config.js"
},
"devDependencies": {
"@types/base-64": "^1.0.0",
"@types/node": "^16",
"@types/utf8": "^3.0.0",
"@types/vscode": "^1.44.0",
"@types/vscode": "^1.75.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.42.0",
Expand All @@ -188,8 +186,6 @@
"webpack-cli": "^4.8.0"
},
"dependencies": {
"base-64": "^1.0.0",
"gemoji": "^8.1.0",
"utf8": "^3.0.0"
"gemoji": "^8.1.0"
}
}
21 changes: 17 additions & 4 deletions src/DecoratorProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import base64 from 'base-64';
import utf8 from 'utf8';
import * as vscode from "vscode";

import { TextEncoder } from 'util';
import * as vscode from 'vscode';
import { Configuration } from './configuration';
import { Emoji, EmojiProvider } from './emoji';

Expand Down Expand Up @@ -95,7 +95,20 @@ export default class DecoratorProvider extends vscode.Disposable {
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="${width}px" height="${height}px" viewBox="0 0 ${width} ${height}" xml:space="preserve">
<text x="50%" y="50%" text-anchor="middle" alignment-baseline="central" font-size="120">${emoji.emoji}</text>
</svg>`;
const dataUri = 'data:image/svg+xml;charset=UTF-8;base64,' + base64.encode(utf8.encode(src));
const dataUri = 'data:image/svg+xml;charset=UTF-8;base64,' + multibyteBtoa(src);
return `![](${dataUri})`;
}
}

/**
* From https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/btoa
*/
function multibyteBtoa(str: string): string {
const encoder = new TextEncoder();
let binary = '';
const uint8array = encoder.encode(str);
for (let i = 0; i < uint8array.length; i++) {
binary += String.fromCharCode(uint8array[i]);
}
return btoa(binary);
}

0 comments on commit eca31d5

Please sign in to comment.