Skip to content

Commit

Permalink
build: update build
Browse files Browse the repository at this point in the history
  • Loading branch information
kmkzt committed May 28, 2019
1 parent 5eefde8 commit e8aac55
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/main.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/main.bundle.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion lib/SvgDrawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var __extends = (this && this.__extends) || (function () {
};
})();
import Two from 'two.js';
import { svgFormatting } from './utils/svgFormatting';
var SvgDrawing = (function (_super) {
__extends(SvgDrawing, _super);
function SvgDrawing(params) {
Expand Down Expand Up @@ -42,9 +43,10 @@ var SvgDrawing = (function (_super) {
}
SvgDrawing.prototype.toSvgXml = function () {
var domElement = this.renderer.domElement;
var svgElement = svgFormatting(domElement.outerHTML);
if (!domElement)
return null;
return "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"" + this.width + "\" height=\"" + this.height + "\" viewBox=\"0 0 " + this.width + " " + this.height + "\">" + domElement.innerHTML + "</svg>";
return "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"" + this.width + "\" height=\"" + this.height + "\" viewBox=\"0 0 " + this.width + " " + this.height + "\">" + svgElement.innerHTML + "</svg>";
};
SvgDrawing.prototype.toSvgBase64 = function () {
var svgXml = this.toSvgXml();
Expand Down
2 changes: 1 addition & 1 deletion lib/index.min.js

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

1 change: 1 addition & 0 deletions lib/utils/svgFormatting.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const svgFormatting: (svgString: string) => SVGSVGElement;
19 changes: 19 additions & 0 deletions lib/utils/svgFormatting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export var svgFormatting = function (svgString) {
var parser = new DOMParser();
var doc = parser.parseFromString(svgString, 'image/svg+xml');
var svgEle = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var originSvgEle = doc.querySelector('svg');
if (!originSvgEle)
return svgEle;
['width', 'height', 'viewBox'].map(function (attr) {
var attrValue = originSvgEle.getAttribute(attr);
if (attrValue)
svgEle.setAttribute(attr, attrValue);
});
var pathEle = doc.querySelectorAll('path');
pathEle.forEach(function (path) {
path.removeAttribute('transform');
svgEle.appendChild(path);
});
return svgEle;
};

0 comments on commit e8aac55

Please sign in to comment.