Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Collect changed files
run: |
mkdir ~/tmp/
git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }} --diff-filter=ACM --name-only --relative '*src/**/*.ts' > ~/tmp/changed_files
git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }} --diff-filter=ACM --name-only --relative '*src/*.ts' '*src/**/*.ts' > ~/tmp/changed_files
echo -e "Changed files: \n$(cat ~/tmp/changed_files)"
- name: Lint
Expand Down
11 changes: 5 additions & 6 deletions src/svg/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import { MatrixArray } from '../core/matrix';
import Transformable, { TransformProp } from '../core/Transformable';
import { RADIAN_TO_DEGREE, retrieve2, logError, isFunction } from '../core/util';
import { RADIAN_TO_DEGREE, retrieve2, logError } from '../core/util';
import Displayable from '../graphic/Displayable';
import { GradientObject } from '../graphic/Gradient';
import { LinearGradientObject } from '../graphic/LinearGradient';
import Path from '../graphic/Path';
import { ImagePatternObject, PatternObject, SVGPatternObject } from '../graphic/Pattern';
import { RadialGradientObject } from '../graphic/RadialGradient';
import { parse } from '../tool/color';
import env from '../core/env';

const mathRound = Math.round;

Expand Down Expand Up @@ -173,14 +172,14 @@ export function getSRTTransformString(
}

export const encodeBase64 = (function () {
if (env.hasGlobalWindow && isFunction(window.btoa)) {
if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') {
return function (str: string) {
return window.btoa(unescape(encodeURIComponent(str)));
return Buffer.from(str).toString('base64');
};
}
if (typeof Buffer !== 'undefined') {
if (typeof btoa === 'function' && typeof unescape === 'function' && typeof encodeURIComponent === 'function') {
return function (str: string) {
return Buffer.from(str).toString('base64');
return btoa(unescape(encodeURIComponent(str)));
};
}
return function (str: string): string {
Expand Down
32 changes: 32 additions & 0 deletions test/svg-ssr.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,38 @@
document.getElementById('main').innerHTML = svg;
console.timeEnd('render');

// base64
console.log('window SSR base64:');
console.log(zr.painter.toDataURL(true));

// worker base64
const workerSource = `
importScripts('${location.origin}/dist/zrender.js')
const zr = zrender.init(null, {
renderer: 'svg',
ssr: true,
width: 1200,
height: 1200
});
const el = new zrender.Circle({
x: 50,
y: 50,
shape: {
cx: 0,
cy: 0,
r: 25
},
style: {
fill: 'red'
}
});
zr.add(el);
console.log('worker SSR base64:');
console.log(zr.painter.toDataURL(true));
zr.dispose();
`;
new Worker(URL.createObjectURL(new Blob([workerSource], { type: 'application/javascript' })));

// var blob = new Blob([svg], { type: 'image/svg+xml' });
// var a = document.createElement('a');
// a.download = 'aaa.svg';
Expand Down
Loading