Skip to content

Commit cca3d43

Browse files
committed
fix: btoa utf8 encode
1 parent 0460787 commit cca3d43

File tree

7 files changed

+34
-40
lines changed

7 files changed

+34
-40
lines changed

.stylelintrc.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
module.exports = {
2-
extends:[
3-
"stylelint-config-standard",
4-
],
2+
extends: ["stylelint-config-standard"],
53
ignoreFiles: [
6-
"**/node_modules/**/*.*",
7-
"**/dist/**/*.*",
8-
"**/build/**/*.*",
9-
"**/coverage/**/*.*",
10-
"**/public/**/*.*"
4+
"**/node_modules/**/*.*",
5+
"**/dist/**/*.*",
6+
"**/build/**/*.*",
7+
"**/coverage/**/*.*",
8+
"**/public/**/*.*",
119
],
12-
rules:{
10+
rules: {
1311
"no-descending-specificity": null,
1412
"color-function-notation": null,
1513
"alpha-value-notation": null,
1614
"no-empty-source": null,
1715
"max-nesting-depth": 6,
1816
"selector-max-compound-selectors": 6,
1917
"selector-class-pattern": null,
20-
"selector-pseudo-class-no-unknown": [true, {
21-
"ignorePseudoClasses": ["global"]
22-
}
18+
"selector-pseudo-class-no-unknown": [
19+
true,
20+
{
21+
"ignorePseudoClasses": ["global"],
22+
},
2323
],
24-
"selector-no-qualifying-type": null
25-
}
26-
}
24+
"selector-no-qualifying-type": null,
25+
},
26+
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "embed-drawio",
3-
"version": "0.1.5",
3+
"version": "0.1.10",
44
"files": [
55
"dist",
66
"pnpm-lock.yaml"
@@ -25,6 +25,7 @@
2525
"lint:circular": "madge --extensions js,jsx --circular ./dist"
2626
},
2727
"dependencies": {
28+
"js-base64": "3.7.7",
2829
"laser-utils": "0.0.5-alpha.10",
2930
"mxgraph": "4.2.2",
3031
"pako": "1.0.6",

pnpm-lock.yaml

Lines changed: 10 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

publish.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
npm version patch --no-git-tag-version
1+
# npm version patch --no-git-tag-version
22
npm run build:dist
33
npm publish --registry=https://registry.npmjs.org/

src/editor/utils/graph.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mxImage } from "../../core/mxgraph";
22
import { refreshTarget } from "../images/base64";
33
import { GRAPH } from "./constant";
4+
import { Base64 } from "js-base64";
45

56
export const createSvgImage = (
67
w: number,
@@ -18,7 +19,7 @@ export const createSvgImage = (
1819
}${w}px" height="${h}px" ${viewBox} version="1.1">${data}</svg>`
1920
)
2021
);
21-
return new mxImage(`data:image/svg+xml;base64,${btoa(tmp)}`, w, h);
22+
return new mxImage(`data:image/svg+xml;base64,${Base64.encode(tmp)}`, w, h);
2223
};
2324

2425
export const TRIANGLE_UP_IMAGE = createSvgImage(

src/utils/convert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const convertXMLToSVG = (
2929
svg.setAttribute("xmlns", XMLNS);
3030
svg.setAttribute("width", bounds.width.toString());
3131
svg.setAttribute("height", bounds.height.toString());
32-
svg.setAttribute("viewBox", "0 0 " + bounds.width + " " + bounds.height);
32+
svg.setAttribute("viewBox", `0 0 ${bounds.width} ${bounds.height}`);
3333
svg.setAttribute("version", "1.1");
3434
const canvas = new mxSvgCanvas2D(svg);
3535
canvas.translate(-bounds.x, -bounds.y);

src/utils/svg.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isString } from "laser-utils/dist/es/is";
22
import type { Func } from "laser-utils/dist/es/types";
3+
import { Base64 } from "js-base64";
34

45
export const svgToString = (svg: Node | null): string | null => {
56
if (!svg) return null;
@@ -24,7 +25,7 @@ export const stringToSvg = (str: string): SVGElement | null => {
2425

2526
export const base64ToSvgString = (base64: string): string | null => {
2627
try {
27-
const svg = atob(base64.replace("data:image/svg+xml;base64,", ""));
28+
const svg = Base64.decode(base64.replace("data:image/svg+xml;base64,", ""));
2829
return svg;
2930
} catch (error) {
3031
console.log("base64ToSvgString Error: ", error);
@@ -35,7 +36,7 @@ export const base64ToSvgString = (base64: string): string | null => {
3536
export const svgToBase64 = (svg: string | SVGElement): string | null => {
3637
const svgString = isString(svg) ? svg : svgToString(svg);
3738
if (svgString) {
38-
return `data:image/svg+xml;base64,${btoa(svgString)}`;
39+
return `data:image/svg+xml;base64,${Base64.encode(svgString)}`;
3940
}
4041
return null;
4142
};

0 commit comments

Comments
 (0)