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 29, 2019
1 parent e584fb3 commit 9b295ea
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
10 changes: 5 additions & 5 deletions 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.

2 changes: 2 additions & 0 deletions lib/SvgAnimation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export declare class SvgAnimation extends Two {
private el;
constructor(params: AnimationOption);
shaking(): () => void;
loadScene(scene: Two.Group): void;
loadSvgXml(svgXml: string | SVGSVGElement): void;
private animationStart;
initSvgXml(svgNode: SVGElement): void;
strokeAnimation(): () => this;
Expand Down
28 changes: 28 additions & 0 deletions lib/SvgAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var __spread = (this && this.__spread) || function () {
return ar;
};
import Two from 'two.js';
import { svgFormatting } from './utils/svgFormatting';
var SvgAnimation = (function (_super) {
__extends(SvgAnimation, _super);
function SvgAnimation(params) {
Expand All @@ -40,6 +41,8 @@ var SvgAnimation = (function (_super) {
_this.shaking = _this.shaking.bind(_this);
_this.initSvgXml = _this.initSvgXml.bind(_this);
_this.strokeAnimation = _this.strokeAnimation.bind(_this);
_this.loadScene = _this.loadScene.bind(_this);
_this.loadSvgXml = _this.loadSvgXml.bind(_this);
_this.shakingRange = params.shakingRange || 2;
_this.type = params.type || Two.Types.canvas;
_this.el = params.el;
Expand Down Expand Up @@ -89,6 +92,31 @@ var SvgAnimation = (function (_super) {
sceneChildrenRestore();
};
};
SvgAnimation.prototype.loadScene = function (scene) {
var _this = this;
this.clear();
scene.children.map(function (twoObj) {
_this.scene.add(twoObj.clone());
});
this.update();
};
SvgAnimation.prototype.loadSvgXml = function (svgXml) {
var _this = this;
var svgElement = svgFormatting(svgXml);
if (!svgElement)
return;
var svgTwo = this.interpret(svgElement);
this.clear();
document.body.appendChild(svgElement);
var originWidth = svgElement.clientWidth;
document.body.removeChild(svgElement);
this.scene.scale = this.width / originWidth;
svgTwo.children.map(function (twoObj) {
_this.scene.add(twoObj.clone());
});
this.scene.center().translation.set(this.width / 2, this.height / 2);
this.update();
};
SvgAnimation.prototype.animationStart = function () {
this.appendTo(this.el);
return this;
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.

2 changes: 1 addition & 1 deletion lib/utils/svgFormatting.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare const svgFormatting: (svgString: string) => SVGSVGElement;
export declare const svgFormatting: (svgXML: string | SVGSVGElement) => SVGSVGElement;
7 changes: 4 additions & 3 deletions lib/utils/svgFormatting.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export var svgFormatting = function (svgString) {
var parser = new DOMParser();
var doc = parser.parseFromString(svgString, 'image/svg+xml');
export var svgFormatting = function (svgXML) {
var doc = typeof svgXML === 'string'
? new DOMParser().parseFromString(svgXML, 'image/svg+xml')
: svgXML;
var svgEle = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var originSvgEle = doc.querySelector('svg');
if (!originSvgEle)
Expand Down

0 comments on commit 9b295ea

Please sign in to comment.