Change name to Snap.svg. Added dr.js to grunt via grunt-exec

master
Dmitry Baranovskiy 2013-09-25 15:52:57 +10:00
parent a553d07b28
commit a27e4043a1
34 changed files with 2676 additions and 1876 deletions

View File

@ -40,11 +40,17 @@ module.exports = function(grunt) {
"./src/amd-footer.js", "./src/amd-footer.js",
] ]
} }
},
exec: {
dr: {
command: "node node_modules/dr.js/dr dr.json"
}
} }
}); });
grunt.loadNpmTasks("grunt-contrib-concat"); grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-uglify"); grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-exec");
grunt.registerTask("default", ["concat", "uglify"]); grunt.registerTask("default", ["concat", "uglify", "exec"]);
}; };

6
NOTICE
View File

@ -1,7 +1,7 @@
Savage is licensed under the Apache license version 2.0, January 2004 (see LICENSE file). Snap.svg is licensed under the Apache license version 2.0, January 2004 (see LICENSE file).
Savage uses the following third party libraries that may have licenses Snap.svg uses the following third party libraries that may have licenses
differing from that of Savage itself. You can find the libraries and their differing from that of Snap.svg itself. You can find the libraries and their
respective licenses below. respective licenses below.
- eve ./node_modules/eve - eve ./node_modules/eve

View File

@ -1,4 +1,4 @@
savage Snap.svg
====== ======
JavaScript library for SVG. JavaScript library for SVG.
@ -7,9 +7,9 @@ API Reference is in `dist/reference.html`
### Building ### Building
Savage uses [Grunt](http://gruntjs.com/) to build Snap.svg uses [Grunt](http://gruntjs.com/) to build
* Open the terminal from the Savage directory * Open the terminal from the Snap.svg directory
cd savage cd savage
@ -22,14 +22,8 @@ Savage uses [Grunt](http://gruntjs.com/) to build
npm install npm install
_*Savage uses Grunt 0.4.0. You might want to [read](http://gruntjs.com/getting-started) more on their website if you havent upgraded since a lot has changed._ _*Snap.svg uses Grunt 0.4.0. You might want to [read](http://gruntjs.com/getting-started) more on their website if you havent upgraded since a lot has changed._
* Type `grunt` in the command line to build the files. * Type `grunt` in the command line to build the files.
* The results will be built into the release folder. * The results will be built into the release folder.
* Alternatively type `grunt watch` to have the build run automatically when you make changes to source files. * Alternatively type `grunt watch` to have the build run automatically when you make changes to source files.
* For documentation generation use this command
cd node_modules/dr.js/; node dr ../../dr.json; cd ../../
_Its ugly at the moment. Somebody should port it to grunt. May be even me :)_

View File

@ -15,97 +15,97 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License."> limitations under the License.">
<title>Savage</title> <title>Snap</title>
<style media="screen"> <style media="screen">
body { body {
background: #030 url("bg.png"); background: #030 url("bg.png");
} }
</style> </style>
<script src="dist/savage-min.js"></script> <script src="dist/snap.svg-min.js"></script>
<script> <script>
window.onload = function () { window.onload = function () {
1; 1
var s = Savage("100%", 600); var s = Snap("100%", 600);
2; // 2
var c = s.circle(100, 100, 50); // var c = s.circle(100, 100, 50);
//
3; // 3
c.attr({ // c.attr({
fill: "#bada55", // fill: "#bada55",
stroke: "#000", // stroke: "#000",
"stroke-width": 5 // "stroke-width": 5
}); // });
//
4; // 4
var c2 = s.circle(70, 100, 40); // var c2 = s.circle(70, 100, 40);
var g = s.group(c2, s.circle(130, 100, 40)); // var g = s.group(c2, s.circle(130, 100, 40));
g.attr({ // g.attr({
fill: "#fff" // fill: "#fff"
}); // });
//
5; // 5
c.attr({ // c.attr({
mask: g // mask: g
}); // });
//
6; // 6
c2.animate({r: 25}, 1000); // c2.animate({r: 25}, 1000);
//
7; // 7
g.select("circle:nth-child(2)").animate({r: 25}, 1000); // g.select("circle:nth-child(2)").animate({r: 25}, 1000);
//
8; // 8
var p = s.path("M10-5-10,15M15,0,0,15M0-5-20,15").attr({ // var p = s.path("M10-5-10,15M15,0,0,15M0-5-20,15").attr({
fill: "none", // fill: "none",
stroke: "#bada55", // stroke: "#bada55",
strokeWidth: 5 // strokeWidth: 5
}).pattern(0, 0, 10, 10); // }).pattern(0, 0, 10, 10);
c.attr({ // c.attr({
fill: p // fill: p
}); // });
//
9; // 9
g.attr({ // g.attr({
fill: Savage(document.getElementById("pattern")) // fill: Snap(document.getElementById("pattern"))
}); // });
//
10; // 10
g.attr({fill: "r()#fff-#000"}); // g.attr({fill: "r()#fff-#000"});
//
11; // 11
g.attr({fill: "R(100, 100, 50)#fff-#000"}); // g.attr({fill: "R(100, 100, 50)#fff-#000"});
//
12; // 12
p.select("path").animate({stroke: "#f00"}, 1000); // p.select("path").animate({stroke: "#f00"}, 1000);
//
13; // 13
Savage.load("demo-card.svg", function (f) { // Snap.load("demo-card.svg", function (f) {
f.select("path[fill='#D40000']").attr({fill: "#bada55"}); // f.select("path[fill='#D40000']").attr({fill: "#bada55"});
g = s.group(f.selectAll("path")); // g = s.group(f.selectAll("path"));
s.append(g); // s.append(g);
//
14; // 14
g.attr({ // g.attr({
transform: "r45t100,0s.5" // transform: "r45t100,0s.5"
}); // });
//
15; // 15
console.log(g.attr("transform")); // console.log(g.attr("transform"));
//
16; // 16
g.drag(); // g.drag();
}); // });
//
17; // 17
s.text(200, 100, "SAVAGE"); // s.text(200, 100, "Snap.SVG");
//
18; // 18
var t = s.text(200, 120, ["S","A","V","A","G","E"]); // var t = s.text(200, 120, ["S","n","a","p",".","S","V","G"]);
t.selectAll("tspan:nth-child(odd)").attr({ // t.selectAll("tspan:nth-child(odd)").attr({
fill: "#900", // fill: "#900",
"font-size": "20px" // "font-size": "20px"
}); // });
}; };
</script> </script>
</head> </head>

View File

@ -15,22 +15,22 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License."> limitations under the License.">
<title>Savage</title> <title>Snap</title>
<style media="screen"> <style media="screen">
body { body {
background: #2c4e6b; background: #2c4e6b;
} }
</style> </style>
<script src="dist/savage-min.js"></script> <script src="dist/snap.svg-min.js"></script>
<script> <script>
window.onload = function () { window.onload = function () {
1; 1;
var g = Savage("100%", "100%"); var g = Snap("100%", "100%");
g.attr({ g.attr({
viewBox: [0, 0, 800, 600] viewBox: [0, 0, 800, 600]
}); });
Savage.load("map.svg", function (f) { Snap.load("map.svg", function (f) {
function getShift(dot) { function getShift(dot) {
pln.attr({ pln.attr({
transform: "t" + (dot.x) + "," + (dot.y) + "r" + (dot.alpha - 90) transform: "t" + (dot.x) + "," + (dot.y) + "r" + (dot.alpha - 90)
@ -83,7 +83,7 @@
click.attr({ click.attr({
display: "none" display: "none"
}); });
Savage.animate(0, pth.getTotalLength(), function (l) { Snap.animate(0, pth.getTotalLength(), function (l) {
var dot = pth.getPointAtLength(l); var dot = pth.getPointAtLength(l);
flight.attr({ flight.attr({
d: pth.getSubpath(0, l) d: pth.getSubpath(0, l)

View File

@ -19,7 +19,7 @@
.button-bar { .button-bar {
display: table; display: table;
table-layout: fixed; table-layout: fixed;
white-space: no-wrap; white-space: nowrap;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
@ -30,7 +30,7 @@
border-radius: 0; border-radius: 0;
} }
.button_bar__item > input { .button-bar__item > input {
position: absolute; position: absolute;
overflow: hidden; overflow: hidden;
padding: 0; padding: 0;
@ -278,7 +278,7 @@
.topcoat-button-bar { .topcoat-button-bar {
display: table; display: table;
table-layout: fixed; table-layout: fixed;
white-space: no-wrap; white-space: nowrap;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
@ -290,7 +290,7 @@
border-radius: 0; border-radius: 0;
} }
.button_bar__item > input, .button-bar__item > input,
.topcoat-button-bar__item > input { .topcoat-button-bar__item > input {
position: absolute; position: absolute;
overflow: hidden; overflow: hidden;
@ -1799,6 +1799,140 @@ input[type="checkbox"]:focus + .topcoat-checkbox__checkmark:before {
color: #000; color: #000;
} }
/*
Copyright 2012 Adobe Systems Inc.;
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
*
* Copyright 2012 Adobe Systems Inc.;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
.notification {
position: relative;
display: inline-block;
vertical-align: top;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
padding: 0;
margin: 0;
font: inherit;
color: inherit;
background: transparent;
border: none;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
text-decoration: none;
}
/*
Copyright 2012 Adobe Systems Inc.;
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
*
* Copyright 2012 Adobe Systems Inc.;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
.notification,
.topcoat-notification {
position: relative;
display: inline-block;
vertical-align: top;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
padding: 0;
margin: 0;
font: inherit;
color: inherit;
background: transparent;
border: none;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
text-decoration: none;
}
/* topdoc
name: Notification
description: Notification badge
markup:
<span class="topcoat-notification">1</span>
tags:
- desktop
- light
- mobile
- notification
*/
.topcoat-notification {
padding: 0.15em 0.5em 0.2em;
border-radius: 2px;
background-color: #ec514e;
color: #fff;
}
/** /**
* *
* Copyright 2012 Adobe Systems Inc.; * Copyright 2012 Adobe Systems Inc.;
@ -2098,6 +2232,193 @@ input[type="radio"]:focus + .topcoat-radio-button__checkmark:before {
box-shadow: 0 0 0 2px #6fb5f1; box-shadow: 0 0 0 2px #6fb5f1;
} }
/*
Copyright 2012 Adobe Systems Inc.;
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Copyright 2012 Adobe Systems Inc.;
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
.range {
padding: 0;
margin: 0;
font: inherit;
color: inherit;
background: transparent;
border: none;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
vertical-align: top;
outline: none;
-webkit-appearance: none;
}
.range__thumb {
cursor: pointer;
}
.range__thumb--webkit {
cursor: pointer;
-webkit-appearance: none;
}
.range:disabled {
opacity: 0.3;
cursor: default;
pointer-events: none;
}
/*
Copyright 2012 Adobe Systems Inc.;
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Copyright 2012 Adobe Systems Inc.;
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
.range,
.topcoat-range {
padding: 0;
margin: 0;
font: inherit;
color: inherit;
background: transparent;
border: none;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
vertical-align: top;
outline: none;
-webkit-appearance: none;
}
.range__thumb,
.topcoat-range::-moz-range-thumb {
cursor: pointer;
}
.range__thumb--webkit,
.topcoat-range::-webkit-slider-thumb {
cursor: pointer;
-webkit-appearance: none;
}
.range:disabled,
.topcoat-range:disabled {
opacity: 0.3;
cursor: default;
pointer-events: none;
}
/* topdoc
name: Range
description: Range input
modifiers:
:active: Active state
:disabled: Disabled state
:hover: Hover state
:focus: Focused
markup:
<input type="range" class="topcoat-range">
<input type="range" class="topcoat-range" disabled>
examples:
mobile range: http://codepen.io/Topcoat/pen/BskEn
tags:
- desktop
- mobile
- range
*/
.topcoat-range {
border-radius: 6px;
border: 1px solid #a5a8a8;
background-color: #d3d7d7;
height: 1rem;
border-radius: 30px;
}
.topcoat-range::-moz-range-track {
border-radius: 6px;
border: 1px solid #a5a8a8;
background-color: #d3d7d7;
height: 1rem;
border-radius: 30px;
}
.topcoat-range::-webkit-slider-thumb {
height: 3rem;
width: 2rem;
background-color: #e5e9e8;
border: 1px solid #a5a8a8;
border-radius: 6px;
box-shadow: inset 0 1px #fff;
}
.topcoat-range::-moz-range-thumb {
height: 3rem;
width: 2rem;
background-color: #e5e9e8;
border: 1px solid #a5a8a8;
border-radius: 6px;
box-shadow: inset 0 1px #fff;
}
.topcoat-range:focus::-webkit-slider-thumb {
border: 1px solid #0940fd;
box-shadow: 0 0 0 2px #6fb5f1;
}
.topcoat-range:focus::-moz-range-thumb {
border: 1px solid #0940fd;
box-shadow: 0 0 0 2px #6fb5f1;
}
/** /**
* *
* Copyright 2012 Adobe Systems Inc.; * Copyright 2012 Adobe Systems Inc.;
@ -2372,6 +2693,459 @@ input[type="search"]::-webkit-search-cancel-button {
* *
*/ */
.switch {
position: relative;
display: inline-block;
vertical-align: top;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
}
.switch__input {
position: absolute;
overflow: hidden;
padding: 0;
border: 0;
opacity: 0.001;
z-index: 1;
vertical-align: top;
outline: none;
}
.switch__toggle {
position: relative;
display: inline-block;
vertical-align: top;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
padding: 0;
margin: 0;
font: inherit;
color: inherit;
background: transparent;
border: none;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.switch__toggle:before,
.switch__toggle:after {
content: '';
position: absolute;
z-index: -1;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
}
.switch--disabled {
opacity: 0.3;
cursor: default;
pointer-events: none;
}
/**
*
* Copyright 2012 Adobe Systems Inc.;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
*
* Copyright 2012 Adobe Systems Inc.;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
.switch,
.topcoat-switch {
position: relative;
display: inline-block;
vertical-align: top;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
}
.switch__input,
.topcoat-switch__input {
position: absolute;
overflow: hidden;
padding: 0;
border: 0;
opacity: 0.001;
z-index: 1;
vertical-align: top;
outline: none;
}
.switch__toggle,
.topcoat-switch__toggle {
position: relative;
display: inline-block;
vertical-align: top;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
padding: 0;
margin: 0;
font: inherit;
color: inherit;
background: transparent;
border: none;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.switch__toggle:before,
.switch__toggle:after,
.topcoat-switch__toggle:before,
.topcoat-switch__toggle:after {
content: '';
position: absolute;
z-index: -1;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
}
.switch--disabled,
.topcoat-switch__input:disabled + .topcoat-switch__toggle {
opacity: 0.3;
cursor: default;
pointer-events: none;
}
/* topdoc
name: Switch
description: Default skin for Topcoat switch
modifiers:
:focus: Focus state
:disabled: Disabled state
markup:
<label class="topcoat-switch">
<input type="checkbox" class="topcoat-switch__input">
<div class="topcoat-switch__toggle"></div>
</label>
<br>
<br>
<label class="topcoat-switch">
<input type="checkbox" class="topcoat-switch__input" checked>
<div class="topcoat-switch__toggle"></div>
</label>
<br>
<br>
<label class="topcoat-switch">
<input type="checkbox" class="topcoat-switch__input" disabled>
<div class="topcoat-switch__toggle"></div>
</label>
examples:
mobile switch: http://codepen.io/Topcoat/pen/upxds
tags:
- desktop
- light
- mobile
- switch
*/
.topcoat-switch {
font-size: 16px;
padding: 0 1.25rem;
border-radius: 6px;
border: 1px solid #a5a8a8;
overflow: hidden;
width: 6rem;
}
.topcoat-switch__toggle:before,
.topcoat-switch__toggle:after {
top: -1px;
width: 5rem;
}
.topcoat-switch__toggle:before {
content: 'ON';
color: #0083e8;
background-color: #e0f0fa;
right: 1rem;
padding-left: 1.5rem;
}
.topcoat-switch__toggle {
line-height: 3rem;
height: 3rem;
width: 2rem;
border-radius: 6px;
color: #454545;
text-shadow: 0 1px #fff;
background-color: #e5e9e8;
border: 1px solid #a5a8a8;
margin-left: -1.3rem;
margin-bottom: -1px;
margin-top: -1px;
box-shadow: inset 0 1px #fff;
-webkit-transition: margin-left 0.05s ease-in-out;
transition: margin-left 0.05s ease-in-out;
}
.topcoat-switch__toggle:after {
content: 'OFF';
background-color: #d3d7d7;
left: 1rem;
padding-left: 2rem;
}
.topcoat-switch__input:checked + .topcoat-switch__toggle {
margin-left: 2.7rem;
}
.topcoat-switch__input:focus + .topcoat-switch__toggle {
border: 1px solid #0940fd;
box-shadow: 0 0 0 2px #6fb5f1;
}
.topcoat-switch__input:disabled + .topcoat-switch__toggle:after,
.topcoat-switch__input:disabled + .topcoat-switch__toggle:before {
background: transparent;
}
/**
*
* Copyright 2012 Adobe Systems Inc.;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
*
* Copyright 2012 Adobe Systems Inc.;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
.button,
.topcoat-tab-bar__button {
position: relative;
display: inline-block;
vertical-align: top;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
padding: 0;
margin: 0;
font: inherit;
color: inherit;
background: transparent;
border: none;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
text-decoration: none;
}
.button--quiet {
background: transparent;
border: 1px solid transparent;
box-shadow: none;
}
.button--disabled,
.topcoat-tab-bar__button:disabled {
opacity: 0.3;
cursor: default;
pointer-events: none;
}
.button-bar,
.topcoat-tab-bar {
display: table;
table-layout: fixed;
white-space: nowrap;
margin: 0;
padding: 0;
}
.button-bar__item,
.topcoat-tab-bar__item {
display: table-cell;
width: auto;
border-radius: 0;
}
.button-bar__item > input,
.topcoat-tab-bar__item > input {
position: absolute;
overflow: hidden;
padding: 0;
border: 0;
opacity: 0.001;
z-index: 1;
vertical-align: top;
outline: none;
}
.button-bar__button {
border-radius: inherit;
}
.button-bar__item:disabled {
opacity: 0.3;
cursor: default;
pointer-events: none;
}
/* topdoc
name: Tab Bar
description: Component of tab buttons
modifiers:
:disabled: Disabled state
markup:
<div class="topcoat-tab-bar">
<label class="topcoat-tab-bar__item">
<input type="radio" name="tab-bar">
<button class="topcoat-tab-bar__button">One</button>
</label>
<label class="topcoat-tab-bar__item">
<input type="radio" name="tab-bar">
<button class="topcoat-tab-bar__button">Two</button>
</label>
<label class="topcoat-tab-bar__item">
<input type="radio" name="tab-bar">
<button class="topcoat-tab-bar__button">Three</button>
</label>
</div>
examples:
mobile tab bar: http://codepen.io/Topcoat/pen/rJICF
tags:
- desktop
- light
- dark
- mobile
- tab
- group
- bar
*/
.topcoat-tab-bar__button {
padding: 0 1.25rem;
height: 3rem;
line-height: 3rem;
letter-spacing: 1px;
color: #454545;
text-shadow: 0 1px #fff;
vertical-align: top;
background-color: #e5e9e8;
box-shadow: inset 0 1px #fff;
border-top: 1px solid #a5a8a8;
}
.topcoat-tab-bar__button:active,
.topcoat-tab-bar__button--large:active,
:checked + .topcoat-tab-bar__button {
color: #0083e8;
background-color: #e0f0fa;
box-shadow: inset 0 0 2px #c0ced8;
}
.topcoat-tab-bar__button:focus,
.topcoat-tab-bar__button--large:focus {
z-index: 1;
}
/**
*
* Copyright 2012 Adobe Systems Inc.;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
*
* Copyright 2012 Adobe Systems Inc.;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
.input, .input,
.topcoat-text-input, .topcoat-text-input,
.topcoat-text-input--large { .topcoat-text-input--large {
@ -2399,11 +3173,18 @@ input[type="search"]::-webkit-search-cancel-button {
/* topdoc /* topdoc
name: Text input name: Text input
description: Topdoc text input description: Topdoc text input
modifiers:
:disabled: Disabled state
:focus: Focused
:invalid: Hover state
markup: markup:
<input type="text" class="topcoat-text-input" placeholder="text" value=""> <input type="text" class="topcoat-text-input" placeholder="text" value="">
<br> <br>
<br> <br>
<input type="text" class="topcoat-text-input" placeholder="text" value="" disabled> <input type="text" class="topcoat-text-input" placeholder="text" value="" disabled>
<br>
<br>
<input type="text" class="topcoat-text-input" placeholder="text" value="fail" pattern="not-fail">
tags: tags:
- desktop - desktop
- mobile - mobile
@ -2445,16 +3226,25 @@ input[type="search"]::-webkit-search-cancel-button {
color: #000; color: #000;
} }
.topcoat-text-input:invalid {
border: 1px solid #d83b75;
}
/* topdoc /* topdoc
name: Large Text Input name: Large Text Input
description: A bigger input, still for text. description: A bigger input, still for text.
modifiers: modifiers:
:disabled: Disabled state :disabled: Disabled state
:focus: Focused
:invalid: Hover state
markup: markup:
<input type="text" class="topcoat-text-input--large" value="" placeholder="text"> <input type="text" class="topcoat-text-input--large" value="" placeholder="text">
<br> <br>
<br> <br>
<input type="text" class="topcoat-text-input--large" value="" placeholder="text" disabled> <input type="text" class="topcoat-text-input--large" value="" placeholder="text" disabled>
<br>
<br>
<input type="text" class="topcoat-text-input--large" placeholder="text" value="fail" pattern="not-fail">
tags: tags:
- desktop - desktop
- light - light
@ -2485,6 +3275,10 @@ input[type="search"]::-webkit-search-cancel-button {
color: #000; color: #000;
} }
.topcoat-text-input--large:invalid {
border: 1px solid #d83b75;
}
/** /**
* *
* Copyright 2012 Adobe Systems Inc.; * Copyright 2012 Adobe Systems Inc.;
@ -2720,7 +3514,6 @@ body {
color: #000; color: #000;
font: 16px "Source Sans", helvetica, arial, sans-serif; font: 16px "Source Sans", helvetica, arial, sans-serif;
font-weight: 200; font-weight: 200;
text-rendering: optimizeLegibility;
} }
:focus { :focus {
@ -2792,6 +3585,8 @@ body {
overflow: hidden; overflow: hidden;
} }
/* This file should include color and image variables corresponding to the dark theme */
/* Call To Action */ /* Call To Action */
/* Icons */ /* Icons */
@ -2814,6 +3609,10 @@ body {
/* Radio Button */ /* Radio Button */
/* Tab bar */
/* Switch */
/* Icon Button */ /* Icon Button */
/* Navigation bar */ /* Navigation bar */
@ -2828,8 +3627,14 @@ body {
/* Radio */ /* Radio */
/* Range input */
/* Search Input */ /* Search Input */
/* Switch */
/* This file should include color and image variables corresponding to the light theme */
/* Call To Action */ /* Call To Action */
/* Icons */ /* Icons */
@ -2840,7 +3645,7 @@ body {
/* List */ /* List */
/*Overlay*/ /* Overlay */
/* Progress bar */ /* Progress bar */
@ -2848,6 +3653,12 @@ body {
/* Range input */ /* Range input */
/* Radio Button */
/* Tab bar */
/* Switch */
/* Containers */ /* Containers */
/* Icon Button */ /* Icon Button */
@ -2868,6 +3679,8 @@ body {
/* Search Input */ /* Search Input */
/* Switch */
/* Text Input */ /* Text Input */
/* Radio input */ /* Radio input */
@ -2880,4 +3693,8 @@ body {
/* Progress bar progress */ /* Progress bar progress */
/* Search input */ /* Search input */
/* Switch */
/* Notification */

1558
dist/reference.html vendored

File diff suppressed because one or more lines are too long

34
dist/savage-min.js vendored

File diff suppressed because one or more lines are too long

20
dist/snap.svg-min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{ {
"title": "Savage", "title": "Snap.svg",
"output": "dist/reference.html", "output": "dist/reference.html",
"scripts": ["savage-min.js", "reference.js"], "scripts": ["snap.svg-min.js", "reference.js"],
"files": [{ "files": [{
"url": "src/svg.js", "url": "src/svg.js",
"link": "https://github.com/adobe-webplatform/savage/blob/master/src/svg.js" "link": "https://github.com/adobe-webplatform/savage/blob/master/src/svg.js"

View File

@ -1,11 +1,11 @@
{ {
"name": "Savage", "name": "Snap.svg",
"version": "0.0.1", "version": "0.0.1",
"description": "JavaScript Vector Library", "description": "JavaScript Vector Library",
"main": "./dist/savage.js", "main": "Gruntfile.js",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/adobe-webplatform/savage.git" "url": "git@github.com:adobe-webplatform/Snap.svg.git"
}, },
"author": "Dmitry Baranovskiy", "author": "Dmitry Baranovskiy",
"license": "Apache License v2", "license": "Apache License v2",
@ -13,10 +13,11 @@
"grunt": "~0.4.1", "grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.0", "grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-concat": "~0.3.0", "grunt-contrib-concat": "~0.3.0",
"grunt-exec": "~0.4.2",
"mocha": "*", "mocha": "*",
"expect.js": "*", "expect.js": "*",
"eve": "*", "eve": "*",
"elemental.js": "~0.2.4", "elemental.js": "~0.2.4",
"dr.js": "*" "dr.js": "~0.0.9"
} }
} }

View File

@ -7,7 +7,7 @@
}); });
} else { } else {
// Browser globals (glob is window) // Browser globals (glob is window)
// Savage adds itself to window // Snap adds itself to window
factory(glob, glob.eve); factory(glob, glob.eve);
} }
}(this, function (window, eve) { }(this, function (window, eve) {

View File

@ -1,2 +1,2 @@
return Savage; return Snap;
})); }));

View File

@ -1,18 +1,4 @@
// .--.--. // Snap.svg @VERSION
// / / '.
// | : /`. /
// ; | |--` .---. ,----._,.
// | : ;_ ,--.--. /. ./| ,--.--. / / ' / ,---.
// \ \ `. / \ .-' . ' | / \ | : | / \
// `----. \.--. .-. /___/ \: | .--. .-. || | .\ . / / |
// __ \ \ | \__\/: . . \ ' . \__\/: . .. ; '; |. ' / |
// / /`--' / ," .--.; |\ \ ' ," .--.; |' . . |' ; /|
// '--'. / / / ,. | \ \ / / ,. | `---`-'| |' | / |
// `--'---' ; : .' \ \ \ |; : .' \.'__/\_: || : |
// | , .-./ '---" | , .-./| : : \ \ /
// `--`---' `--`---' \ \ / `----'
// `--`-'
// Savage @VERSION
// //
// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
// //

View File

@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
Savage.plugin(function (Savage, Element, Paper, glob) { Snap.plugin(function (Snap, Element, Paper, glob) {
var names = {}, var names = {},
reUnit = /[a-z]+$/i, reUnit = /[a-z]+$/i,
Str = String; Str = String;
@ -37,8 +37,8 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
} }
function equaliseTransform(t1, t2) { function equaliseTransform(t1, t2) {
t2 = Str(t2).replace(/\.{3}|\u2026/g, t1); t2 = Str(t2).replace(/\.{3}|\u2026/g, t1);
t1 = Savage.parseTransformString(t1) || []; t1 = Snap.parseTransformString(t1) || [];
t2 = Savage.parseTransformString(t2) || []; t2 = Snap.parseTransformString(t2) || [];
var maxlength = Math.max(t1.length, t2.length), var maxlength = Math.max(t1.length, t2.length),
from = [], from = [],
to = [], to = [],
@ -75,7 +75,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
}; };
} }
function getColour(clr) { function getColour(clr) {
return Savage.rgb(clr[0], clr[1], clr[2]); return Snap.rgb(clr[0], clr[1], clr[2]);
} }
function getPath(path) { function getPath(path) {
var k = 0, i, ii, j, jj, out, a, b = []; var k = 0, i, ii, j, jj, out, a, b = [];
@ -88,7 +88,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
out += a + "]"; out += a + "]";
b[i] = out; b[i] = out;
} }
return Function("val", "return Savage.path.toString.call([" + b + "])"); return Function("val", "return Snap.path.toString.call([" + b + "])");
} }
function path2array(path) { function path2array(path) {
var out = []; var out = [];
@ -109,8 +109,8 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
}; };
} }
if (names[name] == "colour") { if (names[name] == "colour") {
A = Savage.color(a); A = Snap.color(a);
B = Savage.color(b); B = Snap.color(b);
return { return {
from: [A.r, A.g, A.b, A.opacity], from: [A.r, A.g, A.b, A.opacity],
to: [B.r, B.g, B.b, B.opacity], to: [B.r, B.g, B.b, B.opacity],
@ -122,7 +122,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
return equaliseTransform(a, b); return equaliseTransform(a, b);
} }
if (name == "d" || name == "path") { if (name == "d" || name == "path") {
A = Savage.path.toCubic(a, b); A = Snap.path.toCubic(a, b);
return { return {
from: path2array(A[0]), from: path2array(A[0]),
to: path2array(A[1]), to: path2array(A[1]),

View File

@ -11,13 +11,13 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
Savage.plugin(function (Savage, Element, Paper, glob) { Snap.plugin(function (Snap, Element, Paper, glob) {
var elproto = Element.prototype, var elproto = Element.prototype,
pproto = Paper.prototype, pproto = Paper.prototype,
rgurl = /^\s*url\((.+)\)/, rgurl = /^\s*url\((.+)\)/,
Str = String, Str = String,
$ = Savage._.$; $ = Snap._.$;
Savage.filter = {}; Snap.filter = {};
/*\ /*\
* Paper.filter * Paper.filter
[ method ] [ method ]
@ -34,10 +34,14 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
| }); | });
\*/ \*/
pproto.filter = function (filstr) { pproto.filter = function (filstr) {
var f = Savage.parse(Str(filstr)), var paper = this;
id = Savage._.id(), if (paper.type != "svg") {
width = this.node.offsetWidth, paper = paper.paper;
height = this.node.offsetHeight, }
var f = Snap.parse(Str(filstr)),
id = Snap._.id(),
width = paper.node.offsetWidth,
height = paper.node.offsetHeight,
filter = $("filter"); filter = $("filter");
$(filter, { $(filter, {
id: id, id: id,
@ -48,19 +52,19 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
height: height height: height
}); });
filter.appendChild(f.node); filter.appendChild(f.node);
this.defs.appendChild(filter); paper.defs.appendChild(filter);
return new Element(filter); return new Element(filter);
}; };
eve.on("savage.util.getattr.filter", function () { eve.on("snap.util.getattr.filter", function () {
eve.stop(); eve.stop();
var p = $(this.node, "filter"); var p = $(this.node, "filter");
if (p) { if (p) {
var match = Str(p).match(rgurl); var match = Str(p).match(rgurl);
return match && Savage.select(match[1]); return match && Snap.select(match[1]);
} }
}); });
eve.on("savage.util.attr.filter", function (value) { eve.on("snap.util.attr.filter", function (value) {
if (value instanceof Element && value.type == "filter") { if (value instanceof Element && value.type == "filter") {
eve.stop(); eve.stop();
var id = value.node.id; var id = value.node.id;
@ -79,7 +83,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
}); });
/*\ /*\
* Savage.filter.blur * Snap.filter.blur
[ method ] [ method ]
** **
* Returns string of the blur filter. * Returns string of the blur filter.
@ -88,25 +92,25 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- y (number) #optional amount of vertical blur in px. - y (number) #optional amount of vertical blur in px.
= (string) filter representation = (string) filter representation
> Usage > Usage
| var f = paper.filter(Savage.filter.blur(5, 10)), | var f = paper.filter(Snap.filter.blur(5, 10)),
| c = paper.circle(10, 10, 10).attr({ | c = paper.circle(10, 10, 10).attr({
| filter: f | filter: f
| }); | });
\*/ \*/
Savage.filter.blur = function (x, y) { Snap.filter.blur = function (x, y) {
if (x == null) { if (x == null) {
x = 2; x = 2;
} }
var def = y == null ? x : [x, y]; var def = y == null ? x : [x, y];
return Savage.format('\<feGaussianBlur stdDeviation="{def}"/>', { return Snap.format('\<feGaussianBlur stdDeviation="{def}"/>', {
def: def def: def
}); });
}; };
Savage.filter.blur.toString = function () { Snap.filter.blur.toString = function () {
return this(); return this();
}; };
/*\ /*\
* Savage.filter.shadow * Snap.filter.shadow
[ method ] [ method ]
** **
* Returns string of the shadow filter. * Returns string of the shadow filter.
@ -117,12 +121,12 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- color (string) #optional color of the shadow. - color (string) #optional color of the shadow.
= (string) filter representation = (string) filter representation
> Usage > Usage
| var f = paper.filter(Savage.filter.shadow(0, 2, 3)), | var f = paper.filter(Snap.filter.shadow(0, 2, 3)),
| c = paper.circle(10, 10, 10).attr({ | c = paper.circle(10, 10, 10).attr({
| filter: f | filter: f
| }); | });
\*/ \*/
Savage.filter.shadow = function (dx, dy, blur, color) { Snap.filter.shadow = function (dx, dy, blur, color) {
color = color || "#000"; color = color || "#000";
if (blur == null) { if (blur == null) {
blur = 4; blur = 4;
@ -138,19 +142,19 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
if (dy == null) { if (dy == null) {
dy = dx; dy = dx;
} }
color = Savage.color(color); color = Snap.color(color);
return Savage.format('<feGaussianBlur in="SourceAlpha" stdDeviation="{blur}"/><feOffset dx="{dx}" dy="{dy}" result="offsetblur"/><feFlood flood-color="{color}"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>', { return Snap.format('<feGaussianBlur in="SourceAlpha" stdDeviation="{blur}"/><feOffset dx="{dx}" dy="{dy}" result="offsetblur"/><feFlood flood-color="{color}"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>', {
color: color, color: color,
dx: dx, dx: dx,
dy: dy, dy: dy,
blur: blur blur: blur
}); });
}; };
Savage.filter.shadow.toString = function () { Snap.filter.shadow.toString = function () {
return this(); return this();
}; };
/*\ /*\
* Savage.filter.grayscale * Snap.filter.grayscale
[ method ] [ method ]
** **
* Returns string of the grayscale filter. * Returns string of the grayscale filter.
@ -158,11 +162,11 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- amount (number) amount of filter (`0..1`). - amount (number) amount of filter (`0..1`).
= (string) filter representation = (string) filter representation
\*/ \*/
Savage.filter.grayscale = function (amount) { Snap.filter.grayscale = function (amount) {
if (amount == null) { if (amount == null) {
amount = 1; amount = 1;
} }
return Savage.format('<feColorMatrix type="matrix" values="{a} {b} {c} 0 0 {d} {e} {f} 0 0 {g} {b} {h} 0 0 0 0 0 1 0"/>', { return Snap.format('<feColorMatrix type="matrix" values="{a} {b} {c} 0 0 {d} {e} {f} 0 0 {g} {b} {h} 0 0 0 0 0 1 0"/>', {
a: 0.2126 + 0.7874 * (1 - amount), a: 0.2126 + 0.7874 * (1 - amount),
b: 0.7152 - 0.7152 * (1 - amount), b: 0.7152 - 0.7152 * (1 - amount),
c: 0.0722 - 0.0722 * (1 - amount), c: 0.0722 - 0.0722 * (1 - amount),
@ -173,11 +177,11 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
h: 0.0722 + 0.9278 * (1 - amount) h: 0.0722 + 0.9278 * (1 - amount)
}); });
}; };
Savage.filter.grayscale.toString = function () { Snap.filter.grayscale.toString = function () {
return this(); return this();
}; };
/*\ /*\
* Savage.filter.sepia * Snap.filter.sepia
[ method ] [ method ]
** **
* Returns string of the sepia filter. * Returns string of the sepia filter.
@ -185,11 +189,11 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- amount (number) amount of filter (`0..1`). - amount (number) amount of filter (`0..1`).
= (string) filter representation = (string) filter representation
\*/ \*/
Savage.filter.sepia = function (amount) { Snap.filter.sepia = function (amount) {
if (amount == null) { if (amount == null) {
amount = 1; amount = 1;
} }
return Savage.format('<feColorMatrix type="matrix" values="{a} {b} {c} 0 0 {d} {e} {f} 0 0 {g} {h} {i} 0 0 0 0 0 1 0"/>', { return Snap.format('<feColorMatrix type="matrix" values="{a} {b} {c} 0 0 {d} {e} {f} 0 0 {g} {h} {i} 0 0 0 0 0 1 0"/>', {
a: 0.393 + 0.607 * (1 - amount), a: 0.393 + 0.607 * (1 - amount),
b: 0.769 - 0.769 * (1 - amount), b: 0.769 - 0.769 * (1 - amount),
c: 0.189 - 0.189 * (1 - amount), c: 0.189 - 0.189 * (1 - amount),
@ -201,11 +205,11 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
i: 0.131 + 0.869 * (1 - amount) i: 0.131 + 0.869 * (1 - amount)
}); });
}; };
Savage.filter.sepia.toString = function () { Snap.filter.sepia.toString = function () {
return this(); return this();
}; };
/*\ /*\
* Savage.filter.saturate * Snap.filter.saturate
[ method ] [ method ]
** **
* Returns string of the saturate filter. * Returns string of the saturate filter.
@ -213,19 +217,19 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- amount (number) amount of filter (`0..1`). - amount (number) amount of filter (`0..1`).
= (string) filter representation = (string) filter representation
\*/ \*/
Savage.filter.saturate = function (amount) { Snap.filter.saturate = function (amount) {
if (amount == null) { if (amount == null) {
amount = 1; amount = 1;
} }
return Savage.format('<feColorMatrix type="saturate" values="{amount}"/>', { return Snap.format('<feColorMatrix type="saturate" values="{amount}"/>', {
amount: 1 - amount amount: 1 - amount
}); });
}; };
Savage.filter.saturate.toString = function () { Snap.filter.saturate.toString = function () {
return this(); return this();
}; };
/*\ /*\
* Savage.filter.hueRotate * Snap.filter.hueRotate
[ method ] [ method ]
** **
* Returns string of the hue-rotate filter. * Returns string of the hue-rotate filter.
@ -233,17 +237,17 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- angle (number) angle of rotation. - angle (number) angle of rotation.
= (string) filter representation = (string) filter representation
\*/ \*/
Savage.filter.hueRotate = function (angle) { Snap.filter.hueRotate = function (angle) {
angle = angle || 0; angle = angle || 0;
return Savage.format('<feColorMatrix type="hueRotate" values="{angle}"/>', { return Snap.format('<feColorMatrix type="hueRotate" values="{angle}"/>', {
angle: angle angle: angle
}); });
}; };
Savage.filter.hueRotate.toString = function () { Snap.filter.hueRotate.toString = function () {
return this(); return this();
}; };
/*\ /*\
* Savage.filter.invert * Snap.filter.invert
[ method ] [ method ]
** **
* Returns string of the invert filter. * Returns string of the invert filter.
@ -251,20 +255,20 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- amount (number) amount of filter (`0..1`). - amount (number) amount of filter (`0..1`).
= (string) filter representation = (string) filter representation
\*/ \*/
Savage.filter.invert = function (amount) { Snap.filter.invert = function (amount) {
if (amount == null) { if (amount == null) {
amount = 1; amount = 1;
} }
return Savage.format('<feComponentTransfer><feFuncR type="table" tableValues="{amount} {amount2}"/><feFuncG type="table" tableValues="{amount} {amount2}"/><feFuncB type="table" tableValues="{amount} {amount2}"/></feComponentTransfer>', { return Snap.format('<feComponentTransfer><feFuncR type="table" tableValues="{amount} {amount2}"/><feFuncG type="table" tableValues="{amount} {amount2}"/><feFuncB type="table" tableValues="{amount} {amount2}"/></feComponentTransfer>', {
amount: amount, amount: amount,
amount2: 1 - amount amount2: 1 - amount
}); });
}; };
Savage.filter.invert.toString = function () { Snap.filter.invert.toString = function () {
return this(); return this();
}; };
/*\ /*\
* Savage.filter.brightness * Snap.filter.brightness
[ method ] [ method ]
** **
* Returns string of the brightness filter. * Returns string of the brightness filter.
@ -272,19 +276,19 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- amount (number) amount of filter (`0..1`). - amount (number) amount of filter (`0..1`).
= (string) filter representation = (string) filter representation
\*/ \*/
Savage.filter.brightness = function (amount) { Snap.filter.brightness = function (amount) {
if (amount == null) { if (amount == null) {
amount = 1; amount = 1;
} }
return Savage.format('<feComponentTransfer><feFuncR type="linear" slope="{amount}"/><feFuncG type="linear" slope="{amount}"/><feFuncB type="linear" slope="{amount}"/></feComponentTransfer>', { return Snap.format('<feComponentTransfer><feFuncR type="linear" slope="{amount}"/><feFuncG type="linear" slope="{amount}"/><feFuncB type="linear" slope="{amount}"/></feComponentTransfer>', {
amount: amount amount: amount
}); });
}; };
Savage.filter.brightness.toString = function () { Snap.filter.brightness.toString = function () {
return this(); return this();
}; };
/*\ /*\
* Savage.filter.contrast * Snap.filter.contrast
[ method ] [ method ]
** **
* Returns string of the contrast filter. * Returns string of the contrast filter.
@ -292,16 +296,16 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- amount (number) amount of filter (`0..1`). - amount (number) amount of filter (`0..1`).
= (string) filter representation = (string) filter representation
\*/ \*/
Savage.filter.contrast = function (amount) { Snap.filter.contrast = function (amount) {
if (amount == null) { if (amount == null) {
amount = 1; amount = 1;
} }
return Savage.format('<feComponentTransfer><feFuncR type="linear" slope="{amount}" intercept="{amount2}"/><feFuncG type="linear" slope="{amount}" intercept="{amount2}"/><feFuncB type="linear" slope="{amount}" intercept="{amount2}"/></feComponentTransfer>', { return Snap.format('<feComponentTransfer><feFuncR type="linear" slope="{amount}" intercept="{amount2}"/><feFuncG type="linear" slope="{amount}" intercept="{amount2}"/><feFuncB type="linear" slope="{amount}" intercept="{amount2}"/></feComponentTransfer>', {
amount: amount, amount: amount,
amount2: .5 - amount / 2 amount2: .5 - amount / 2
}); });
}; };
Savage.filter.contrast.toString = function () { Snap.filter.contrast.toString = function () {
return this(); return this();
}; };
}); });

View File

@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
Savage.plugin(function (Savage, Element, Paper, glob) { Snap.plugin(function (Snap, Element, Paper, glob) {
var elproto = Element.prototype, var elproto = Element.prototype,
has = "hasOwnProperty", has = "hasOwnProperty",
supportsTouch = "createTouch" in glob.doc, supportsTouch = "createTouch" in glob.doc,
@ -118,7 +118,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
} }
var node = dragi.el.node, var node = dragi.el.node,
o, o,
glob = Savage._.glob, glob = Snap._.glob,
next = node.nextSibling, next = node.nextSibling,
parent = node.parentNode, parent = node.parentNode,
display = node.style.display; display = node.style.display;
@ -127,20 +127,20 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
// o = dragi.el.paper.getElementByPoint(x, y); // o = dragi.el.paper.getElementByPoint(x, y);
// node.style.display = display; // node.style.display = display;
// glob.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node)); // glob.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node));
// o && eve("savage.drag.over." + dragi.el.id, dragi.el, o); // o && eve("snap.drag.over." + dragi.el.id, dragi.el, o);
x += scrollX; x += scrollX;
y += scrollY; y += scrollY;
eve("savage.drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e); eve("snap.drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
} }
}, },
dragUp = function (e) { dragUp = function (e) {
Savage.unmousemove(dragMove).unmouseup(dragUp); Snap.unmousemove(dragMove).unmouseup(dragUp);
var i = drag.length, var i = drag.length,
dragi; dragi;
while (i--) { while (i--) {
dragi = drag[i]; dragi = drag[i];
dragi.el._drag = {}; dragi.el._drag = {};
eve("savage.drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e); eve("snap.drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
} }
drag = []; drag = [];
}; };
@ -332,8 +332,8 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
\*/ \*/
for (var i = events.length; i--;) { for (var i = events.length; i--;) {
(function (eventName) { (function (eventName) {
Savage[eventName] = elproto[eventName] = function (fn, scope) { Snap[eventName] = elproto[eventName] = function (fn, scope) {
if (Savage.is(fn, "function")) { if (Snap.is(fn, "function")) {
this.events = this.events || []; this.events = this.events || [];
this.events.push({ this.events.push({
name: eventName, name: eventName,
@ -343,7 +343,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
} }
return this; return this;
}; };
Savage["un" + eventName] = Snap["un" + eventName] =
elproto["un" + eventName] = function (fn) { elproto["un" + eventName] = function (fn) {
var events = this.events || [], var events = this.events || [],
l = events.length; l = events.length;
@ -432,12 +432,12 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
this._drag.x = e.clientX + scrollX; this._drag.x = e.clientX + scrollX;
this._drag.y = e.clientY + scrollY; this._drag.y = e.clientY + scrollY;
this._drag.id = e.identifier; this._drag.id = e.identifier;
!drag.length && Savage.mousemove(dragMove).mouseup(dragUp); !drag.length && Snap.mousemove(dragMove).mouseup(dragUp);
drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope}); drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
onstart && eve.on("savage.drag.start." + this.id, onstart); onstart && eve.on("snap.drag.start." + this.id, onstart);
onmove && eve.on("savage.drag.move." + this.id, onmove); onmove && eve.on("snap.drag.move." + this.id, onmove);
onend && eve.on("savage.drag.end." + this.id, onend); onend && eve.on("snap.drag.end." + this.id, onend);
eve("savage.drag.start." + this.id, start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e); eve("snap.drag.start." + this.id, start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e);
} }
this._drag = {}; this._drag = {};
draggable.push({el: this, start: start}); draggable.push({el: this, start: start});
@ -452,7 +452,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- f (function) handler for event, first argument would be the element you are dragging over - f (function) handler for event, first argument would be the element you are dragging over
\*/ \*/
// elproto.onDragOver = function (f) { // elproto.onDragOver = function (f) {
// f ? eve.on("savage.drag.over." + this.id, f) : eve.unbind("savage.drag.over." + this.id); // f ? eve.on("snap.drag.over." + this.id, f) : eve.unbind("snap.drag.over." + this.id);
// }; // };
/*\ /*\
* Element.undrag * Element.undrag
@ -465,9 +465,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
while (i--) if (draggable[i].el == this) { while (i--) if (draggable[i].el == this) {
this.unmousedown(draggable[i].start); this.unmousedown(draggable[i].start);
draggable.splice(i, 1); draggable.splice(i, 1);
eve.unbind("savage.drag.*." + this.id); eve.unbind("snap.drag.*." + this.id);
} }
!draggable.length && Savage.unmousemove(dragMove).unmouseup(dragUp); !draggable.length && Snap.unmousemove(dragMove).unmouseup(dragUp);
return this; return this;
}; };
}); });

View File

@ -11,10 +11,10 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
Savage.plugin(function (Savage, Element, Paper, glob) { Snap.plugin(function (Snap, Element, Paper, glob) {
var elproto = Element.prototype, var elproto = Element.prototype,
is = Savage.is, is = Snap.is,
clone = Savage._.clone, clone = Snap._.clone,
has = "hasOwnProperty", has = "hasOwnProperty",
p2s = /,?([a-z]),?/gi, p2s = /,?([a-z]),?/gi,
toFloat = parseFloat, toFloat = parseFloat,
@ -89,7 +89,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
function O(val) { function O(val) {
return +(+val).toFixed(3); return +(+val).toFixed(3);
} }
return Savage._.cacher(function (path, length, onlystart) { return Snap._.cacher(function (path, length, onlystart) {
if (path instanceof Element) { if (path instanceof Element) {
path = path.attr("d"); path = path.attr("d");
} }
@ -144,7 +144,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
subpaths.end = sp; subpaths.end = sp;
point = istotal ? len : subpath ? subpaths : findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1); point = istotal ? len : subpath ? subpaths : findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1);
return point; return point;
}, null, Savage._.clone); }, null, Snap._.clone);
} }
var getTotalLength = getLengthFactory(1), var getTotalLength = getLengthFactory(1),
getPointAtLength = getLengthFactory(), getPointAtLength = getLengthFactory(),
@ -178,7 +178,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
}; };
} }
function bezierBBox(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) { function bezierBBox(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
if (!Savage.is(p1x, "array")) { if (!Snap.is(p1x, "array")) {
p1x = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y]; p1x = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y];
} }
var bbox = curveDim.apply(null, p1x); var bbox = curveDim.apply(null, p1x);
@ -490,7 +490,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
res.toString = toString; res.toString = toString;
return res; return res;
} }
var unit2px = Savage._unit2px, var unit2px = Snap._unit2px,
getPath = { getPath = {
path: function (el) { path: function (el) {
return el.attr("path"); return el.attr("path");
@ -530,8 +530,8 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
if (pth.rel) { if (pth.rel) {
return pathClone(pth.rel); return pathClone(pth.rel);
} }
if (!Savage.is(pathArray, "array") || !Savage.is(pathArray && pathArray[0], "array")) { if (!Snap.is(pathArray, "array") || !Snap.is(pathArray && pathArray[0], "array")) {
pathArray = Savage.parsePathString(pathArray); pathArray = Snap.parsePathString(pathArray);
} }
var res = [], var res = [],
x = 0, x = 0,
@ -610,7 +610,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
return pathClone(pth.abs); return pathClone(pth.abs);
} }
if (!is(pathArray, "array") || !is(pathArray && pathArray[0], "array")) { // rough assumption if (!is(pathArray, "array") || !is(pathArray && pathArray[0], "array")) { // rough assumption
pathArray = Savage.parsePathString(pathArray); pathArray = Snap.parsePathString(pathArray);
} }
if (!pathArray || !pathArray.length) { if (!pathArray || !pathArray.length) {
return [["M", 0, 0]]; return [["M", 0, 0]];
@ -751,7 +751,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
rad = PI / 180 * (+angle || 0), rad = PI / 180 * (+angle || 0),
res = [], res = [],
xy, xy,
rotate = Savage._.cacher(function (x, y, rad) { rotate = Snap._.cacher(function (x, y, rad) {
var X = x * math.cos(rad) - y * math.sin(rad), var X = x * math.cos(rad) - y * math.sin(rad),
Y = x * math.sin(rad) + y * math.cos(rad); Y = x * math.sin(rad) + y * math.cos(rad);
return {x: X, y: Y}; return {x: X, y: Y};
@ -1040,10 +1040,10 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
} }
// export // export
Savage.path = paths; Snap.path = paths;
/*\ /*\
* Savage.path.getTotalLength * Snap.path.getTotalLength
[ method ] [ method ]
** **
* Returns length of the given path in pixels. * Returns length of the given path in pixels.
@ -1052,9 +1052,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
** **
= (number) length. = (number) length.
\*/ \*/
Savage.path.getTotalLength = getTotalLength; Snap.path.getTotalLength = getTotalLength;
/*\ /*\
* Savage.path.getPointAtLength * Snap.path.getPointAtLength
[ method ] [ method ]
** **
* Return coordinates of the point located at the given length on the given path. * Return coordinates of the point located at the given length on the given path.
@ -1069,9 +1069,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
o alpha: (number) angle of derivative o alpha: (number) angle of derivative
o } o }
\*/ \*/
Savage.path.getPointAtLength = getPointAtLength; Snap.path.getPointAtLength = getPointAtLength;
/*\ /*\
* Savage.path.getSubpath * Snap.path.getSubpath
[ method ] [ method ]
** **
* Return subpath of a given path from given length to given length. * Return subpath of a given path from given length to given length.
@ -1082,7 +1082,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
** **
= (string) pathstring for the segment = (string) pathstring for the segment
\*/ \*/
Savage.path.getSubpath = function (path, from, to) { Snap.path.getSubpath = function (path, from, to) {
if (this.getTotalLength(path) - to < 1e-6) { if (this.getTotalLength(path) - to < 1e-6) {
return getSubpathsAtLength(path, from).end; return getSubpathsAtLength(path, from).end;
} }
@ -1131,11 +1131,11 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
= (string) pathstring for the segment = (string) pathstring for the segment
\*/ \*/
elproto.getSubpath = function (from, to) { elproto.getSubpath = function (from, to) {
return Savage.path.getSubpath(this.attr("d"), from, to); return Snap.path.getSubpath(this.attr("d"), from, to);
}; };
Savage._.box = box; Snap._.box = box;
/*\ /*\
* Savage.path.findDotsAtSegment * Snap.path.findDotsAtSegment
[ method ] [ method ]
** **
* Utility method * Utility method
@ -1173,9 +1173,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
o alpha: (number) angle of the curve derivative at the point o alpha: (number) angle of the curve derivative at the point
o } o }
\*/ \*/
Savage.path.findDotsAtSegment = findDotsAtSegment; Snap.path.findDotsAtSegment = findDotsAtSegment;
/*\ /*\
* Savage.path.bezierBBox * Snap.path.bezierBBox
[ method ] [ method ]
** **
* Utility method * Utility method
@ -1203,9 +1203,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
o } o }
o } o }
\*/ \*/
Savage.path.bezierBBox = bezierBBox; Snap.path.bezierBBox = bezierBBox;
/*\ /*\
* Savage.path.isPointInsideBBox * Snap.path.isPointInsideBBox
[ method ] [ method ]
** **
* Utility method * Utility method
@ -1216,9 +1216,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- y (string) y coordinate of the point - y (string) y coordinate of the point
= (boolean) `true` if point inside = (boolean) `true` if point inside
\*/ \*/
Savage.path.isPointInsideBBox = isPointInsideBBox; Snap.path.isPointInsideBBox = isPointInsideBBox;
/*\ /*\
* Savage.path.isBBoxIntersect * Snap.path.isBBoxIntersect
[ method ] [ method ]
** **
* Utility method * Utility method
@ -1228,9 +1228,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- bbox2 (string) second bounding box - bbox2 (string) second bounding box
= (boolean) `true` if they intersect = (boolean) `true` if they intersect
\*/ \*/
Savage.path.isBBoxIntersect = isBBoxIntersect; Snap.path.isBBoxIntersect = isBBoxIntersect;
/*\ /*\
* Savage.path.intersection * Snap.path.intersection
[ method ] [ method ]
** **
* Utility method * Utility method
@ -1252,10 +1252,10 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
o } o }
o ] o ]
\*/ \*/
Savage.path.intersection = pathIntersection; Snap.path.intersection = pathIntersection;
Savage.path.intersectionNumber = pathIntersectionNumber; Snap.path.intersectionNumber = pathIntersectionNumber;
/*\ /*\
* Savage.path.isPointInside * Snap.path.isPointInside
[ method ] [ method ]
** **
* Utility method * Utility method
@ -1266,9 +1266,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- y (number) y of the point - y (number) y of the point
= (boolean) true, if point is inside the path = (boolean) true, if point is inside the path
\*/ \*/
Savage.path.isPointInside = isPointInsidePath; Snap.path.isPointInside = isPointInsidePath;
/*\ /*\
* Savage.path.getBBox * Snap.path.getBBox
[ method ] [ method ]
** **
* Utility method * Utility method
@ -1285,10 +1285,10 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
o height: (number) height of the box o height: (number) height of the box
o } o }
\*/ \*/
Savage.path.getBBox = pathBBox; Snap.path.getBBox = pathBBox;
Savage.path.get = getPath; Snap.path.get = getPath;
/*\ /*\
* Savage.path.toRelative * Snap.path.toRelative
[ method ] [ method ]
** **
* Utility method * Utility method
@ -1297,9 +1297,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- path (string) path string - path (string) path string
= (array) path string = (array) path string
\*/ \*/
Savage.path.toRelative = pathToRelative; Snap.path.toRelative = pathToRelative;
/*\ /*\
* Savage.path.toAbsolute * Snap.path.toAbsolute
[ method ] [ method ]
** **
* Utility method * Utility method
@ -1308,9 +1308,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- path (string) path string - path (string) path string
= (array) path string = (array) path string
\*/ \*/
Savage.path.toAbsolute = pathToAbsolute; Snap.path.toAbsolute = pathToAbsolute;
/*\ /*\
* Savage.path.toCubic * Snap.path.toCubic
[ method ] [ method ]
** **
* Utility method * Utility method
@ -1319,9 +1319,9 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- pathString (string|array) path string or array of segments - pathString (string|array) path string or array of segments
= (array) array of segments. = (array) array of segments.
\*/ \*/
Savage.path.toCubic = path2curve; Snap.path.toCubic = path2curve;
/*\ /*\
* Savage.path.map * Snap.path.map
[ method ] [ method ]
** **
* Transform the path string with given matrix. * Transform the path string with given matrix.
@ -1329,7 +1329,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
- matrix (object) see @Matrix - matrix (object) see @Matrix
= (string) transformed path string = (string) transformed path string
\*/ \*/
Savage.path.map = mapPath; Snap.path.map = mapPath;
Savage.path.toString = toString; Snap.path.toString = toString;
Savage.path.clone = pathClone; Snap.path.clone = pathClone;
}); });

View File

@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
Savage.plugin(function (Savage, Element, Paper, glob) { Snap.plugin(function (Snap, Element, Paper, glob) {
var mmax = Math.max, var mmax = Math.max,
mmin = Math.min; mmin = Math.min;
@ -193,11 +193,11 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
return s; return s;
}; };
setproto.toString = function () { setproto.toString = function () {
return "Savage\u2018s set"; return "Snap\u2018s set";
}; };
setproto.type = "set"; setproto.type = "set";
// export // export
Savage.set = function () { Snap.set = function () {
var set = new Set; var set = new Set;
if (arguments.length) { if (arguments.length) {
set.push.apply(set, Array.prototype.slice.call(arguments, 0)); set.push.apply(set, Array.prototype.slice.call(arguments, 0));

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
describe("Attributes", function () { describe("Attributes", function () {
var s, r; var s, r;
beforeEach(function () { beforeEach(function () {
s = Savage(100, 100); s = Snap(100, 100);
r = s.rect(10, 10, 50, 50); r = s.rect(10, 10, 50, 50);
}); });
afterEach(function () { afterEach(function () {
@ -37,7 +37,7 @@ describe("Attributes", function () {
var o = {}; var o = {};
return function () { return function () {
function val() { function val() {
return Savage.color(r.node.getAttribute(key)).hex; return Snap.color(r.node.getAttribute(key)).hex;
} }
o[key] = "#fc0"; o[key] = "#fc0";
r.attr(o); r.attr(o);

View File

@ -1,51 +1,51 @@
describe("Colours", function () { describe("Colours", function () {
it("parses hex colour", function () { it("parses hex colour", function () {
expect(Savage.color("#fC0").hex).to.be("#ffcc00"); expect(Snap.color("#fC0").hex).to.be("#ffcc00");
}); });
it("parses RGB", function () { it("parses RGB", function () {
var c = Savage.color("rgb(255, 204, 0)"); var c = Snap.color("rgb(255, 204, 0)");
expect(c.hex).to.be("#ffcc00"); expect(c.hex).to.be("#ffcc00");
expect(c.r).to.be(255); expect(c.r).to.be(255);
expect(c.g).to.be(204); expect(c.g).to.be(204);
expect(c.b).to.be(0); expect(c.b).to.be(0);
}); });
it("parses RGB - %", function () { it("parses RGB - %", function () {
var c = Savage.color("rgb(100%, 80%, 0%)"); var c = Snap.color("rgb(100%, 80%, 0%)");
expect(c.hex).to.be("#ffcc00"); expect(c.hex).to.be("#ffcc00");
expect(c.r).to.be(255); expect(c.r).to.be(255);
expect(c.g).to.be(204); expect(c.g).to.be(204);
expect(c.b).to.be(0); expect(c.b).to.be(0);
}); });
it("parses HSL", function () { it("parses HSL", function () {
var c = Savage.color("hsl(0.1333, 1, .5)"); var c = Snap.color("hsl(0.1333, 1, .5)");
expect(c.hex).to.be("#ffcc00"); expect(c.hex).to.be("#ffcc00");
expect(c.h.toFixed(3)).to.be("0.133"); expect(c.h.toFixed(3)).to.be("0.133");
expect(c.s).to.be(1); expect(c.s).to.be(1);
expect(c.l).to.be(.5); expect(c.l).to.be(.5);
}); });
it("parses HSL - %", function () { it("parses HSL - %", function () {
var c = Savage.color("hsl(13.33%, 100%, 50%)"); var c = Snap.color("hsl(13.33%, 100%, 50%)");
expect(c.hex).to.be("#ffcc00"); expect(c.hex).to.be("#ffcc00");
expect(c.h.toFixed(3)).to.be("0.133"); expect(c.h.toFixed(3)).to.be("0.133");
expect(c.s).to.be(1); expect(c.s).to.be(1);
expect(c.l).to.be(.5); expect(c.l).to.be(.5);
}); });
it("parses HSB", function () { it("parses HSB", function () {
var c = Savage.color("hsb(0.1333, 1, 1)"); var c = Snap.color("hsb(0.1333, 1, 1)");
expect(c.hex).to.be("#ffcc00"); expect(c.hex).to.be("#ffcc00");
expect(c.h.toFixed(3)).to.be("0.133"); expect(c.h.toFixed(3)).to.be("0.133");
expect(c.s).to.be(1); expect(c.s).to.be(1);
expect(c.v).to.be(1); expect(c.v).to.be(1);
}); });
it("parses HSB - %", function () { it("parses HSB - %", function () {
var c = Savage.color("hsb(13.33%, 100%, 100%)"); var c = Snap.color("hsb(13.33%, 100%, 100%)");
expect(c.hex).to.be("#ffcc00"); expect(c.hex).to.be("#ffcc00");
expect(c.h.toFixed(3)).to.be("0.133"); expect(c.h.toFixed(3)).to.be("0.133");
expect(c.s).to.be(1); expect(c.s).to.be(1);
expect(c.v).to.be(1); expect(c.v).to.be(1);
}); });
it("parses RGBA", function () { it("parses RGBA", function () {
var c = Savage.color("rgba(255, 204, 0, .75)"); var c = Snap.color("rgba(255, 204, 0, .75)");
expect(c.hex).to.be("#ffcc00"); expect(c.hex).to.be("#ffcc00");
expect(c.r).to.be(255); expect(c.r).to.be(255);
expect(c.g).to.be(204); expect(c.g).to.be(204);
@ -53,7 +53,7 @@ describe("Colours", function () {
expect(c.opacity).to.be(.75); expect(c.opacity).to.be(.75);
}); });
it("parses HSLA", function () { it("parses HSLA", function () {
var c = Savage.color("hsla(0.1333, 1, .5, .5)"); var c = Snap.color("hsla(0.1333, 1, .5, .5)");
expect(c.hex).to.be("#ffcc00"); expect(c.hex).to.be("#ffcc00");
expect(c.r).to.be(255); expect(c.r).to.be(255);
expect(c.g).to.be(204); expect(c.g).to.be(204);
@ -61,7 +61,7 @@ describe("Colours", function () {
expect(c.opacity).to.be(.5); expect(c.opacity).to.be(.5);
}); });
it("parses HSBA", function () { it("parses HSBA", function () {
var c = Savage.color("hsba(0.1333, 1, 1, .5)"); var c = Snap.color("hsba(0.1333, 1, 1, .5)");
expect(c.hex).to.be("#ffcc00"); expect(c.hex).to.be("#ffcc00");
expect(c.r).to.be(255); expect(c.r).to.be(255);
expect(c.g).to.be(204); expect(c.g).to.be(204);
@ -69,16 +69,16 @@ describe("Colours", function () {
expect(c.opacity).to.be(.5); expect(c.opacity).to.be(.5);
}); });
it("parses names", function () { it("parses names", function () {
var c = Savage.color("DodgerBlue"); var c = Snap.color("DodgerBlue");
expect(c.hex).to.be("#1e90ff"); expect(c.hex).to.be("#1e90ff");
c = Savage.color("FireBrick"); c = Snap.color("FireBrick");
expect(c.hex).to.be("#b22222"); expect(c.hex).to.be("#b22222");
c = Savage.color("MintCream"); c = Snap.color("MintCream");
expect(c.hex).to.be("#f5fffa"); expect(c.hex).to.be("#f5fffa");
}); });
it("parses to RGB", function() { it("parses to RGB", function() {
var expectRGB = function(str) { var expectRGB = function(str) {
var c = Savage.getRGB(str); var c = Snap.getRGB(str);
expect(c.hex).to.be("#ffcc00"); expect(c.hex).to.be("#ffcc00");
expect(c.r).to.be(255); expect(c.r).to.be(255);
expect(c.g).to.be(204); expect(c.g).to.be(204);
@ -97,81 +97,81 @@ describe("Colours", function () {
expectRGB("rgba(255, 204, 0, .75)"); expectRGB("rgba(255, 204, 0, .75)");
expectRGB("hsla(0.1333, 1, .5, .5)"); expectRGB("hsla(0.1333, 1, .5, .5)");
expectRGB("hsba(0.1333, 1, 1, .5)"); expectRGB("hsba(0.1333, 1, 1, .5)");
var c = Savage.getRGB("DodgerBlue"); var c = Snap.getRGB("DodgerBlue");
expect(c.hex).to.be("#1e90ff"); expect(c.hex).to.be("#1e90ff");
expect(c.r).to.be(30); expect(c.r).to.be(30);
expect(c.g).to.be(144); expect(c.g).to.be(144);
expect(c.b).to.be(255); expect(c.b).to.be(255);
expect(c.error).to.not.be(true); expect(c.error).to.not.be(true);
c = Savage.getRGB("foobar"); c = Snap.getRGB("foobar");
expect(!!c.error).to.be(true); expect(!!c.error).to.be(true);
c = Savage.getRGB("#zzz"); c = Snap.getRGB("#zzz");
expect(!!c.error).to.be(true); expect(!!c.error).to.be(true);
c = Savage.getRGB("rgb(255)"); c = Snap.getRGB("rgb(255)");
expect(!!c.error).to.be(true); expect(!!c.error).to.be(true);
c = Savage.getRGB("hsl(0, 0, 0"); c = Snap.getRGB("hsl(0, 0, 0");
expect(!!c.error).to.be(true); expect(!!c.error).to.be(true);
c = Savage.getRGB("rab(0, 0, 0)"); c = Snap.getRGB("rab(0, 0, 0)");
expect(!!c.error).to.be(true); expect(!!c.error).to.be(true);
}); });
it("creates hsb", function() { it("creates hsb", function() {
var str = Savage.hsb(0.13333, 1, 1); var str = Snap.hsb(0.13333, 1, 1);
expect(str).to.be("#ffcc00"); expect(str).to.be("#ffcc00");
str = Savage.hsb(0, 0.5, 0.5); str = Snap.hsb(0, 0.5, 0.5);
expect(str).to.be("#804040"); expect(str).to.be("#804040");
}); });
it("creates rgb from hsb", function() { it("creates rgb from hsb", function() {
var rgb = Savage.hsb2rgb(0.13333, 1, 1); var rgb = Snap.hsb2rgb(0.13333, 1, 1);
expect(rgb.r).to.be(255); expect(rgb.r).to.be(255);
expect(rgb.g).to.be(204); expect(rgb.g).to.be(204);
expect(rgb.b).to.be(0); expect(rgb.b).to.be(0);
expect(rgb.hex).to.be("#ffcc00"); expect(rgb.hex).to.be("#ffcc00");
rgb = Savage.hsb2rgb(0, 0.5, 0.5); rgb = Snap.hsb2rgb(0, 0.5, 0.5);
expect(rgb.r).to.be(128); expect(rgb.r).to.be(128);
expect(rgb.g).to.be(64); expect(rgb.g).to.be(64);
expect(rgb.b).to.be(64); expect(rgb.b).to.be(64);
expect(rgb.hex).to.be("#804040"); expect(rgb.hex).to.be("#804040");
}); });
it("creates hsl", function() { it("creates hsl", function() {
var str = Savage.hsl(0.13333, 1, 0.5); var str = Snap.hsl(0.13333, 1, 0.5);
expect(str).to.be("#ffcc00"); expect(str).to.be("#ffcc00");
str = Savage.hsl(0, 1, 0.75); str = Snap.hsl(0, 1, 0.75);
expect(str).to.be("#ff8080"); expect(str).to.be("#ff8080");
}); });
it("creates rgb from hsl", function() { it("creates rgb from hsl", function() {
var rgb = Savage.hsl2rgb(0.13333, 1, 0.5); var rgb = Snap.hsl2rgb(0.13333, 1, 0.5);
expect(rgb.r).to.be(255); expect(rgb.r).to.be(255);
expect(rgb.g).to.be(204); expect(rgb.g).to.be(204);
expect(rgb.b).to.be(0); expect(rgb.b).to.be(0);
expect(rgb.hex).to.be("#ffcc00"); expect(rgb.hex).to.be("#ffcc00");
rgb = Savage.hsl2rgb(0, 1, 0.75); rgb = Snap.hsl2rgb(0, 1, 0.75);
expect(rgb.r).to.be(255); expect(rgb.r).to.be(255);
expect(rgb.g).to.be(128); expect(rgb.g).to.be(128);
expect(rgb.b).to.be(128); expect(rgb.b).to.be(128);
expect(rgb.hex).to.be("#ff8080"); expect(rgb.hex).to.be("#ff8080");
}); });
it("creates rgb", function() { it("creates rgb", function() {
var str = Savage.rgb(255, 204, 0); var str = Snap.rgb(255, 204, 0);
expect(str).to.be("#ffcc00"); expect(str).to.be("#ffcc00");
str = Savage.rgb(64, 128, 255); str = Snap.rgb(64, 128, 255);
expect(str).to.be("#4080ff"); expect(str).to.be("#4080ff");
}); });
it("creates hsb from rgb", function() { it("creates hsb from rgb", function() {
var hsb = Savage.rgb2hsb(255, 204, 0); var hsb = Snap.rgb2hsb(255, 204, 0);
expect(hsb.h.toFixed(3)).to.be("0.133"); expect(hsb.h.toFixed(3)).to.be("0.133");
expect(hsb.s).to.be(1); expect(hsb.s).to.be(1);
expect(hsb.b).to.be(1); expect(hsb.b).to.be(1);
hsb = Savage.rgb2hsb(128, 64, 64); hsb = Snap.rgb2hsb(128, 64, 64);
expect(hsb.h).to.be(0); expect(hsb.h).to.be(0);
expect(hsb.s.toFixed(1)).to.be("0.5"); expect(hsb.s.toFixed(1)).to.be("0.5");
expect(hsb.b.toFixed(1)).to.be("0.5"); expect(hsb.b.toFixed(1)).to.be("0.5");
}); });
it("creates hsl from rgb", function() { it("creates hsl from rgb", function() {
var hsl = Savage.rgb2hsl(255, 204, 0); var hsl = Snap.rgb2hsl(255, 204, 0);
expect(hsl.h.toFixed(3)).to.be("0.133"); expect(hsl.h.toFixed(3)).to.be("0.133");
expect(hsl.s).to.be(1); expect(hsl.s).to.be(1);
expect(hsl.l).to.be(0.5); expect(hsl.l).to.be(0.5);
hsl = Savage.rgb2hsl(255, 128, 128); hsl = Snap.rgb2hsl(255, 128, 128);
expect(hsl.h).to.be(0); expect(hsl.h).to.be(0);
expect(hsl.s).to.be(1); expect(hsl.s).to.be(1);
expect(hsl.l.toFixed(2)).to.be("0.75"); expect(hsl.l.toFixed(2)).to.be("0.75");

View File

@ -1,7 +1,7 @@
describe("Element methods", function () { describe("Element methods", function () {
var s; var s;
beforeEach(function () { beforeEach(function () {
s = Savage(100, 100); s = Snap(100, 100);
}); });
afterEach(function () { afterEach(function () {
s.remove(); s.remove();
@ -29,7 +29,7 @@ describe("Element methods", function () {
it("Element.add (for Set)", function () { it("Element.add (for Set)", function () {
var rect1 = s.rect(10, 20, 30, 40); var rect1 = s.rect(10, 20, 30, 40);
var rect2 = s.rect(10, 20, 30, 40); var rect2 = s.rect(10, 20, 30, 40);
var set = Savage.set(rect1, rect2); var set = Snap.set(rect1, rect2);
var result = s.add(set); var result = s.add(set);
expect(rect1.node.parentNode).to.be(s.node); expect(rect1.node.parentNode).to.be(s.node);
expect(rect2.node.parentNode).to.be(s.node); expect(rect2.node.parentNode).to.be(s.node);
@ -45,7 +45,7 @@ describe("Element methods", function () {
it("Element.append (for Set)", function () { it("Element.append (for Set)", function () {
var rect1 = s.rect(10, 20, 30, 40); var rect1 = s.rect(10, 20, 30, 40);
var rect2 = s.rect(10, 20, 30, 40); var rect2 = s.rect(10, 20, 30, 40);
var set = Savage.set(rect1, rect2); var set = Snap.set(rect1, rect2);
var result = s.append(set); var result = s.append(set);
expect(rect1.node.parentNode).to.be(s.node); expect(rect1.node.parentNode).to.be(s.node);
expect(rect2.node.parentNode).to.be(s.node); expect(rect2.node.parentNode).to.be(s.node);

View File

@ -1,81 +1,81 @@
describe("Filter methods", function () { describe("Filter methods", function () {
it("Savage.filter.blur", function() { it("Snap.filter.blur", function() {
var str = Savage.filter.blur(3); var str = Snap.filter.blur(3);
expect(str).to.be('<feGaussianBlur stdDeviation="3"/>'); expect(str).to.be('<feGaussianBlur stdDeviation="3"/>');
str = Savage.filter.blur(0.123, 8); str = Snap.filter.blur(0.123, 8);
expect(str).to.be('<feGaussianBlur stdDeviation="0.123,8"/>'); expect(str).to.be('<feGaussianBlur stdDeviation="0.123,8"/>');
}); });
it("Savage.filter.brightness", function() { it("Snap.filter.brightness", function() {
var str = Savage.filter.brightness(0.3); var str = Snap.filter.brightness(0.3);
expect(str).to.be('<feComponentTransfer><feFuncR type="linear" slope="0.3"/><feFuncG type="linear" slope="0.3"/><feFuncB type="linear" slope="0.3"/></feComponentTransfer>'); expect(str).to.be('<feComponentTransfer><feFuncR type="linear" slope="0.3"/><feFuncG type="linear" slope="0.3"/><feFuncB type="linear" slope="0.3"/></feComponentTransfer>');
str = Savage.filter.brightness(1); str = Snap.filter.brightness(1);
expect(str).to.be('<feComponentTransfer><feFuncR type="linear" slope="1"/><feFuncG type="linear" slope="1"/><feFuncB type="linear" slope="1"/></feComponentTransfer>'); expect(str).to.be('<feComponentTransfer><feFuncR type="linear" slope="1"/><feFuncG type="linear" slope="1"/><feFuncB type="linear" slope="1"/></feComponentTransfer>');
}); });
it("Savage.filter.contrast", function() { it("Snap.filter.contrast", function() {
var str = Savage.filter.contrast(0.1); var str = Snap.filter.contrast(0.1);
expect(str).to.be('<feComponentTransfer><feFuncR type="linear" slope="0.1" intercept="0.45"/><feFuncG type="linear" slope="0.1" intercept="0.45"/><feFuncB type="linear" slope="0.1" intercept="0.45"/></feComponentTransfer>'); expect(str).to.be('<feComponentTransfer><feFuncR type="linear" slope="0.1" intercept="0.45"/><feFuncG type="linear" slope="0.1" intercept="0.45"/><feFuncB type="linear" slope="0.1" intercept="0.45"/></feComponentTransfer>');
str = Savage.filter.contrast(3); str = Snap.filter.contrast(3);
expect(str).to.be('<feComponentTransfer><feFuncR type="linear" slope="3" intercept="-1"/><feFuncG type="linear" slope="3" intercept="-1"/><feFuncB type="linear" slope="3" intercept="-1"/></feComponentTransfer>'); expect(str).to.be('<feComponentTransfer><feFuncR type="linear" slope="3" intercept="-1"/><feFuncG type="linear" slope="3" intercept="-1"/><feFuncB type="linear" slope="3" intercept="-1"/></feComponentTransfer>');
}); });
it("Savage.filter.grayscale", function() { it("Snap.filter.grayscale", function() {
var str = Savage.filter.grayscale(0.5); var str = Snap.filter.grayscale(0.5);
expect(str).to.be('<feColorMatrix type="matrix" values="0.6063000000000001 0.3576 0.0361 0 0 0.1063 0.8575999999999999 0.0361 0 0 0.1063 0.3576 0.5361 0 0 0 0 0 1 0"/>'); expect(str).to.be('<feColorMatrix type="matrix" values="0.6063000000000001 0.3576 0.0361 0 0 0.1063 0.8575999999999999 0.0361 0 0 0.1063 0.3576 0.5361 0 0 0 0 0 1 0"/>');
str = Savage.filter.grayscale(1); str = Snap.filter.grayscale(1);
expect(str).to.be('<feColorMatrix type="matrix" values="0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"/>'); expect(str).to.be('<feColorMatrix type="matrix" values="0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"/>');
}); });
it("Savage.filter.hueRotate", function() { it("Snap.filter.hueRotate", function() {
var str = Savage.filter.hueRotate(180); var str = Snap.filter.hueRotate(180);
expect(str).to.be('<feColorMatrix type="hueRotate" values="180"/>'); expect(str).to.be('<feColorMatrix type="hueRotate" values="180"/>');
str = Savage.filter.hueRotate(90); str = Snap.filter.hueRotate(90);
expect(str).to.be('<feColorMatrix type="hueRotate" values="90"/>'); expect(str).to.be('<feColorMatrix type="hueRotate" values="90"/>');
}); });
it("Savage.filter.hueRotate", function() { it("Snap.filter.hueRotate", function() {
var str = Savage.filter.hueRotate(180); var str = Snap.filter.hueRotate(180);
expect(str).to.be('<feColorMatrix type="hueRotate" values="180"/>'); expect(str).to.be('<feColorMatrix type="hueRotate" values="180"/>');
str = Savage.filter.hueRotate(90); str = Snap.filter.hueRotate(90);
expect(str).to.be('<feColorMatrix type="hueRotate" values="90"/>'); expect(str).to.be('<feColorMatrix type="hueRotate" values="90"/>');
}); });
it("Savage.filter.invert", function() { it("Snap.filter.invert", function() {
var str = Savage.filter.invert(0.6); var str = Snap.filter.invert(0.6);
expect(str).to.be('<feComponentTransfer><feFuncR type="table" tableValues="0.6 0.4"/><feFuncG type="table" tableValues="0.6 0.4"/><feFuncB type="table" tableValues="0.6 0.4"/></feComponentTransfer>'); expect(str).to.be('<feComponentTransfer><feFuncR type="table" tableValues="0.6 0.4"/><feFuncG type="table" tableValues="0.6 0.4"/><feFuncB type="table" tableValues="0.6 0.4"/></feComponentTransfer>');
str = Savage.filter.invert(1); str = Snap.filter.invert(1);
expect(str).to.be('<feComponentTransfer><feFuncR type="table" tableValues="1 0"/><feFuncG type="table" tableValues="1 0"/><feFuncB type="table" tableValues="1 0"/></feComponentTransfer>'); expect(str).to.be('<feComponentTransfer><feFuncR type="table" tableValues="1 0"/><feFuncG type="table" tableValues="1 0"/><feFuncB type="table" tableValues="1 0"/></feComponentTransfer>');
}); });
it("Savage.filter.saturate", function() { it("Snap.filter.saturate", function() {
var str = Savage.filter.saturate(0.3); var str = Snap.filter.saturate(0.3);
expect(str).to.be('<feColorMatrix type="saturate" values="0.7"/>'); expect(str).to.be('<feColorMatrix type="saturate" values="0.7"/>');
str = Savage.filter.saturate(1); str = Snap.filter.saturate(1);
expect(str).to.be('<feColorMatrix type="saturate" values="0"/>'); expect(str).to.be('<feColorMatrix type="saturate" values="0"/>');
}); });
it("Savage.filter.sepia", function() { it("Snap.filter.sepia", function() {
var str = Savage.filter.sepia(0.3); var str = Snap.filter.sepia(0.3);
expect(str).to.be('<feColorMatrix type="matrix" values="0.8179 0.23070000000000002 0.0567 0 0 0.10470000000000002 0.9058 0.050400000000000014 0 0 0.0816 0.1602 0.7393 0 0 0 0 0 1 0"/>'); expect(str).to.be('<feColorMatrix type="matrix" values="0.8179 0.23070000000000002 0.0567 0 0 0.10470000000000002 0.9058 0.050400000000000014 0 0 0.0816 0.1602 0.7393 0 0 0 0 0 1 0"/>');
str = Savage.filter.sepia(1); str = Snap.filter.sepia(1);
expect(str).to.be('<feColorMatrix type="matrix" values="0.393 0.769 0.189 0 0 0.349 0.686 0.168 0 0 0.272 0.534 0.131 0 0 0 0 0 1 0"/>'); expect(str).to.be('<feColorMatrix type="matrix" values="0.393 0.769 0.189 0 0 0.349 0.686 0.168 0 0 0.272 0.534 0.131 0 0 0 0 0 1 0"/>');
}); });
it("Savage.filter.shadow - dx & dy", function() { it("Snap.filter.shadow - dx & dy", function() {
var str = Savage.filter.shadow(5, 5); var str = Snap.filter.shadow(5, 5);
expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="4"/><feOffset dx="5" dy="5" result="offsetblur"/><feFlood flood-color="#000000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>'); expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="4"/><feOffset dx="5" dy="5" result="offsetblur"/><feFlood flood-color="#000000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>');
str = Savage.filter.shadow(-1, 3); str = Snap.filter.shadow(-1, 3);
expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="4"/><feOffset dx="-1" dy="3" result="offsetblur"/><feFlood flood-color="#000000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>'); expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="4"/><feOffset dx="-1" dy="3" result="offsetblur"/><feFlood flood-color="#000000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>');
}); });
it("Savage.filter.shadow - dx & dy, blur", function() { it("Snap.filter.shadow - dx & dy, blur", function() {
var str = Savage.filter.shadow(5, 5, 5); var str = Snap.filter.shadow(5, 5, 5);
expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="5"/><feOffset dx="5" dy="5" result="offsetblur"/><feFlood flood-color="#000000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>'); expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="5"/><feOffset dx="5" dy="5" result="offsetblur"/><feFlood flood-color="#000000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>');
str = Savage.filter.shadow(-1, 3, 10); str = Snap.filter.shadow(-1, 3, 10);
expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="10"/><feOffset dx="-1" dy="3" result="offsetblur"/><feFlood flood-color="#000000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>'); expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="10"/><feOffset dx="-1" dy="3" result="offsetblur"/><feFlood flood-color="#000000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>');
}); });
it("Savage.filter.shadow - dx & dy, color", function() { it("Snap.filter.shadow - dx & dy, color", function() {
var str = Savage.filter.shadow(5, 5, '#F00'); var str = Snap.filter.shadow(5, 5, '#F00');
expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="4"/><feOffset dx="5" dy="5" result="offsetblur"/><feFlood flood-color="#ff0000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>'); expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="4"/><feOffset dx="5" dy="5" result="offsetblur"/><feFlood flood-color="#ff0000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>');
str = Savage.filter.shadow(-1, 3, 'hsla(128deg, 50%, 50%, 0.8)'); str = Snap.filter.shadow(-1, 3, 'hsla(128deg, 50%, 50%, 0.8)');
expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="4"/><feOffset dx="-1" dy="3" result="offsetblur"/><feFlood flood-color="rgba(64,191,81,0.8)"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>'); expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="4"/><feOffset dx="-1" dy="3" result="offsetblur"/><feFlood flood-color="rgba(64,191,81,0.8)"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>');
}); });
it("Savage.filter.shadow - dx & dy, blur & color", function() { it("Snap.filter.shadow - dx & dy, blur & color", function() {
var str = Savage.filter.shadow(5, 5, 5, '#F00'); var str = Snap.filter.shadow(5, 5, 5, '#F00');
expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="5"/><feOffset dx="5" dy="5" result="offsetblur"/><feFlood flood-color="#ff0000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>'); expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="5"/><feOffset dx="5" dy="5" result="offsetblur"/><feFlood flood-color="#ff0000"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>');
str = Savage.filter.shadow(-1, 3, 10, 'hsla(128deg, 50%, 50%, 0.8)'); str = Snap.filter.shadow(-1, 3, 10, 'hsla(128deg, 50%, 50%, 0.8)');
expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="10"/><feOffset dx="-1" dy="3" result="offsetblur"/><feFlood flood-color="rgba(64,191,81,0.8)"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>'); expect(str).to.be('<feGaussianBlur in="SourceAlpha" stdDeviation="10"/><feOffset dx="-1" dy="3" result="offsetblur"/><feFlood flood-color="rgba(64,191,81,0.8)"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>');
}); });

View File

@ -1,7 +1,7 @@
describe("Matrix methods", function () { describe("Matrix methods", function () {
it("Matrix.add - matrix", function() { it("Matrix.add - matrix", function() {
var matrix1 = new Savage.Matrix(1, 0, 0, 1, 5, 5); var matrix1 = new Snap.Matrix(1, 0, 0, 1, 5, 5);
var matrix2 = new Savage.Matrix(1, 0, 0, 1, 10, 10); var matrix2 = new Snap.Matrix(1, 0, 0, 1, 10, 10);
var result = matrix1.add(matrix2); var result = matrix1.add(matrix2);
expect(result).to.eql({ expect(result).to.eql({
a: 1, a: 1,
@ -12,8 +12,8 @@ describe("Matrix methods", function () {
f: 15 f: 15
}); });
// add two 90 degree rotations // add two 90 degree rotations
var matrix3 = new Savage.Matrix(0, 1, -1, 0, 0, 0); var matrix3 = new Snap.Matrix(0, 1, -1, 0, 0, 0);
var matrix4 = new Savage.Matrix(0, 1, -1, 0, 0, 0); var matrix4 = new Snap.Matrix(0, 1, -1, 0, 0, 0);
result = matrix3.add(matrix4); result = matrix3.add(matrix4);
expect(result).to.eql({ expect(result).to.eql({
a: -1, a: -1,
@ -25,7 +25,7 @@ describe("Matrix methods", function () {
}); });
}); });
it("Matrix.add - numbers", function() { it("Matrix.add - numbers", function() {
var matrix1 = new Savage.Matrix(1, 0, 0, 1, 5, 5); var matrix1 = new Snap.Matrix(1, 0, 0, 1, 5, 5);
var result = matrix1.add(1, 0, 0, 1, 10, 10); var result = matrix1.add(1, 0, 0, 1, 10, 10);
expect(result).to.eql({ expect(result).to.eql({
a: 1, a: 1,
@ -37,7 +37,7 @@ describe("Matrix methods", function () {
}); });
}); });
it("Matrix.clone", function() { it("Matrix.clone", function() {
var matrix1 = new Savage.Matrix(1, 2, 3, 4, 5, 6); var matrix1 = new Snap.Matrix(1, 2, 3, 4, 5, 6);
var clone = matrix1.clone(); var clone = matrix1.clone();
expect(clone).to.not.be(matrix1); expect(clone).to.not.be(matrix1);
expect(clone).to.eql({ expect(clone).to.eql({
@ -50,7 +50,7 @@ describe("Matrix methods", function () {
}); });
}); });
it("Matrix.invert", function() { it("Matrix.invert", function() {
var matrix1 = new Savage.Matrix(1, 2, 3, 4, 5, 6); var matrix1 = new Snap.Matrix(1, 2, 3, 4, 5, 6);
var inverse = matrix1.invert(); var inverse = matrix1.invert();
expect(inverse).to.eql({ expect(inverse).to.eql({
a: -2, a: -2,
@ -62,7 +62,7 @@ describe("Matrix methods", function () {
}); });
}); });
it("Matrix.rotate", function() { it("Matrix.rotate", function() {
var matrix = new Savage.Matrix(1, 0, 0, 1, 0, 0); var matrix = new Snap.Matrix(1, 0, 0, 1, 0, 0);
matrix.rotate(45, 0, 0); matrix.rotate(45, 0, 0);
expect(+matrix.a.toFixed(3)).to.be(0.707); expect(+matrix.a.toFixed(3)).to.be(0.707);
expect(+matrix.b.toFixed(3)).to.be(0.707); expect(+matrix.b.toFixed(3)).to.be(0.707);
@ -72,7 +72,7 @@ describe("Matrix methods", function () {
expect(+matrix.f.toFixed(3)).to.be(0); expect(+matrix.f.toFixed(3)).to.be(0);
}); });
it("Matrix.scale - x", function() { it("Matrix.scale - x", function() {
var matrix = new Savage.Matrix(1, 0, 0, 1, 20, 30); var matrix = new Snap.Matrix(1, 0, 0, 1, 20, 30);
matrix.scale(2); matrix.scale(2);
expect(matrix).to.eql({ expect(matrix).to.eql({
a: 2, a: 2,
@ -93,7 +93,7 @@ describe("Matrix methods", function () {
}); });
}); });
it("Matrix.scale - x, y", function() { it("Matrix.scale - x, y", function() {
var matrix = new Savage.Matrix(1, 0, 0, 1, 20, 30); var matrix = new Snap.Matrix(1, 0, 0, 1, 20, 30);
matrix.scale(2, 3); matrix.scale(2, 3);
expect(matrix).to.eql({ expect(matrix).to.eql({
a: 2, a: 2,
@ -114,7 +114,7 @@ describe("Matrix methods", function () {
}); });
}); });
it("Matrix.scale - x, y, cx, cy", function() { it("Matrix.scale - x, y, cx, cy", function() {
var matrix = new Savage.Matrix(1, 0, 0, 1, 20, 30); var matrix = new Snap.Matrix(1, 0, 0, 1, 20, 30);
matrix.scale(2, 3, 5, -5); matrix.scale(2, 3, 5, -5);
expect(matrix).to.eql({ expect(matrix).to.eql({
a: 2, a: 2,
@ -126,7 +126,7 @@ describe("Matrix methods", function () {
}); });
}); });
it("Matrix.split", function() { it("Matrix.split", function() {
var matrix = new Savage.Matrix(1, 0, 0, 1, 0, 0); var matrix = new Snap.Matrix(1, 0, 0, 1, 0, 0);
var result = matrix.split(); var result = matrix.split();
expect(result.dx).to.be(0); expect(result.dx).to.be(0);
expect(result.dy).to.be(0); expect(result.dy).to.be(0);
@ -136,7 +136,7 @@ describe("Matrix methods", function () {
expect(result.rotate).to.be(0); expect(result.rotate).to.be(0);
expect(result.isSimple).to.be(true); expect(result.isSimple).to.be(true);
matrix = new Savage.Matrix(1.5, 0, 0, 0.5, 20, 25); matrix = new Snap.Matrix(1.5, 0, 0, 0.5, 20, 25);
result = matrix.split(); result = matrix.split();
expect(result.dx).to.be(20); expect(result.dx).to.be(20);
expect(result.dy).to.be(25); expect(result.dy).to.be(25);
@ -147,9 +147,9 @@ describe("Matrix methods", function () {
expect(result.isSimple).to.be(true); expect(result.isSimple).to.be(true);
}); });
it("Matrix.toTransformString", function() { it("Matrix.toTransformString", function() {
var matrix = new Savage.Matrix(1.5, 0, 0, 0.5, 20, 25); var matrix = new Snap.Matrix(1.5, 0, 0, 0.5, 20, 25);
var str = matrix.toTransformString(); var str = matrix.toTransformString();
var s = Savage(10, 10); var s = Snap(10, 10);
var rect = s.rect(0, 0, 10, 20); var rect = s.rect(0, 0, 10, 20);
rect.transform(str); rect.transform(str);
var transform = rect.transform(); var transform = rect.transform();
@ -163,7 +163,7 @@ describe("Matrix methods", function () {
}); });
}); });
it("Matrix.translate", function() { it("Matrix.translate", function() {
var matrix = new Savage.Matrix(1, 0, 0, 1, 20, 30); var matrix = new Snap.Matrix(1, 0, 0, 1, 20, 30);
matrix.translate(10, -10); matrix.translate(10, -10);
expect(matrix).to.eql({ expect(matrix).to.eql({
a: 1, a: 1,
@ -184,12 +184,12 @@ describe("Matrix methods", function () {
}); });
}); });
it("Matrix.x", function() { it("Matrix.x", function() {
var matrix = new Savage.Matrix(1, 0, 0, 1, 20, 30); var matrix = new Snap.Matrix(1, 0, 0, 1, 20, 30);
var result = matrix.x(10, -10); var result = matrix.x(10, -10);
expect(result).to.be(30); expect(result).to.be(30);
}); });
it("Matrix.y", function() { it("Matrix.y", function() {
var matrix = new Savage.Matrix(1, 0, 0, 1, 20, 30); var matrix = new Snap.Matrix(1, 0, 0, 1, 20, 30);
var result = matrix.y(10, -10); var result = matrix.y(10, -10);
expect(result).to.be(20); expect(result).to.be(20);
}); });

View File

@ -1,7 +1,7 @@
describe("Mina methods", function () { describe("Mina methods", function () {
var s; var s;
beforeEach(function () { beforeEach(function () {
s = Savage(100, 100); s = Snap(100, 100);
}); });
afterEach(function () { afterEach(function () {
s.remove(); s.remove();

View File

@ -1,6 +1,6 @@
describe("Check for Paper Creation", function () { describe("Check for Paper Creation", function () {
it("creates simple paper 20 × 10", function () { it("creates simple paper 20 × 10", function () {
var s = Savage(20, 10); var s = Snap(20, 10);
var S = s.node; var S = s.node;
expect(S).to.not.be(null); expect(S).to.not.be(null);
expect(S.getAttribute("width")).to.be("20"); expect(S.getAttribute("width")).to.be("20");
@ -8,7 +8,7 @@ describe("Check for Paper Creation", function () {
s.remove(); s.remove();
}); });
it("removal of paper", function () { it("removal of paper", function () {
var s = Savage(20, 10); var s = Snap(20, 10);
var S = s.node; var S = s.node;
expect(S).to.not.be(null); expect(S).to.not.be(null);
s.remove(); s.remove();
@ -16,7 +16,7 @@ describe("Check for Paper Creation", function () {
expect(S).to.be(1); expect(S).to.be(1);
}); });
it("creates simple paper 20% × 10em", function () { it("creates simple paper 20% × 10em", function () {
var s = Savage("20%", "10em"); var s = Snap("20%", "10em");
var S = s.node; var S = s.node;
expect(S).to.not.be(null); expect(S).to.not.be(null);
expect(S.getAttribute("width")).to.be("20%"); expect(S.getAttribute("width")).to.be("20%");
@ -25,7 +25,7 @@ describe("Check for Paper Creation", function () {
}); });
it("converts existing SVG element to paper", function () { it("converts existing SVG element to paper", function () {
var S = document.getElementById("svgroot"); var S = document.getElementById("svgroot");
var s = Savage(S); var s = Snap(S);
expect(document.querySelector("#svgroot circle")).to.be(null); expect(document.querySelector("#svgroot circle")).to.be(null);
var c = s.circle(10, 20, 5); var c = s.circle(10, 20, 5);
expect(document.querySelectorAll("#svgroot circle").length).to.be(1); expect(document.querySelectorAll("#svgroot circle").length).to.be(1);
@ -33,7 +33,7 @@ describe("Check for Paper Creation", function () {
}); });
it("converts existing SVG element to paper (as query)", function () { it("converts existing SVG element to paper (as query)", function () {
var S = document.getElementById("svgroot"); var S = document.getElementById("svgroot");
var s = Savage("#svgroot"); var s = Snap("#svgroot");
expect(document.querySelector("#svgroot circle")).to.be(null); expect(document.querySelector("#svgroot circle")).to.be(null);
var c = s.circle(10, 20, 5); var c = s.circle(10, 20, 5);
expect(document.querySelectorAll("#svgroot circle").length).to.be(1); expect(document.querySelectorAll("#svgroot circle").length).to.be(1);
@ -51,7 +51,7 @@ describe("Paper methods", function () {
*/ */
var paper; var paper;
beforeEach(function () { beforeEach(function () {
paper = Savage(100, 100); paper = Snap(100, 100);
}); });
afterEach(function () { afterEach(function () {
paper.remove(); paper.remove();

View File

@ -1,9 +1,9 @@
describe("Path methods", function () { describe("Path methods", function () {
it("Savage.path.getTotalLength", function () { it("Snap.path.getTotalLength", function () {
expect(+Savage.path.getTotalLength("M0,0 100,0").toFixed(2)).to.be(100); expect(+Snap.path.getTotalLength("M0,0 100,0").toFixed(2)).to.be(100);
}); });
it("Savage.path.getPointAtLength", function () { it("Snap.path.getPointAtLength", function () {
expect(Savage.path.getPointAtLength("M0,0 100,0", 50)).to.eql({ expect(Snap.path.getPointAtLength("M0,0 100,0", 50)).to.eql({
x: 50, x: 50,
y: 0, y: 0,
m: { m: {
@ -25,13 +25,13 @@ describe("Path methods", function () {
alpha: 180 alpha: 180
}); });
}); });
it("Savage.path.getSubpath", function () { it("Snap.path.getSubpath", function () {
expect(Savage.path.getSubpath("M0,0 100,0", 10, 90)).to.be("M9.995,0C29.153,0,70.839,0,90,0"); expect(Snap.path.getSubpath("M0,0 100,0", 10, 90)).to.be("M9.995,0C29.153,0,70.839,0,90,0");
expect(Savage.path.getSubpath("M0,0 100,0", 0, 90)).to.be("M0,0C0,0,64.674,0,90,0"); expect(Snap.path.getSubpath("M0,0 100,0", 0, 90)).to.be("M0,0C0,0,64.674,0,90,0");
expect(Savage.path.getSubpath("M0,0 100,0", 10, 120)).to.be("M10,0C35.326,0,100,0,100,0"); expect(Snap.path.getSubpath("M0,0 100,0", 10, 120)).to.be("M10,0C35.326,0,100,0,100,0");
}); });
it("Savage.path.findDotsAtSegment", function () { it("Snap.path.findDotsAtSegment", function () {
expect(Savage.path.findDotsAtSegment(0,0,0,0,100,0,100,0,.5)).to.eql({ expect(Snap.path.findDotsAtSegment(0,0,0,0,100,0,100,0,.5)).to.eql({
x: 50, x: 50,
y: 0, y: 0,
m: { m: {
@ -53,8 +53,8 @@ describe("Path methods", function () {
alpha: 180 alpha: 180
}); });
}); });
it("Savage.path.bezierBBox - params", function () { it("Snap.path.bezierBBox - params", function () {
var bbox = Savage.path.bezierBBox(10, 10, 10, 20, 110, 0, 110, 10); var bbox = Snap.path.bezierBBox(10, 10, 10, 20, 110, 0, 110, 10);
expect(bbox.cx).to.be(60); expect(bbox.cx).to.be(60);
expect(bbox.cy).to.be(10); expect(bbox.cy).to.be(10);
expect(bbox.x).to.be(10); expect(bbox.x).to.be(10);
@ -62,8 +62,8 @@ describe("Path methods", function () {
expect(bbox.width).to.be(100); expect(bbox.width).to.be(100);
expect(bbox.x2).to.be(110); expect(bbox.x2).to.be(110);
}); });
it("Savage.path.bezierBBox - array", function () { it("Snap.path.bezierBBox - array", function () {
var bbox = Savage.path.bezierBBox([10, 10, 10, 20, 110, 0, 110, 10]); var bbox = Snap.path.bezierBBox([10, 10, 10, 20, 110, 0, 110, 10]);
expect(bbox.cx).to.be(60); expect(bbox.cx).to.be(60);
expect(bbox.cy).to.be(10); expect(bbox.cy).to.be(10);
expect(bbox.x).to.be(10); expect(bbox.x).to.be(10);
@ -71,9 +71,9 @@ describe("Path methods", function () {
expect(bbox.width).to.be(100); expect(bbox.width).to.be(100);
expect(bbox.x2).to.be(110); expect(bbox.x2).to.be(110);
}); });
it("Savage.path.getBBox", function() { it("Snap.path.getBBox", function() {
// same as 10,20,30,40 rect // same as 10,20,30,40 rect
var bbox = Savage.path.getBBox("M10,20h30v40h-30z"); var bbox = Snap.path.getBBox("M10,20h30v40h-30z");
expect(bbox.x).to.eql(10); expect(bbox.x).to.eql(10);
expect(bbox.y).to.eql(20); expect(bbox.y).to.eql(20);
expect(bbox.width).to.eql(30); expect(bbox.width).to.eql(30);
@ -81,13 +81,13 @@ describe("Path methods", function () {
expect(bbox.x2).to.eql(10 + 30); expect(bbox.x2).to.eql(10 + 30);
expect(bbox.y2).to.eql(20 + 40); expect(bbox.y2).to.eql(20 + 40);
}); });
it("Savage.path.isPointInsideBBox", function () { it("Snap.path.isPointInsideBBox", function () {
expect(Savage.path.isPointInsideBBox({x: 0, y: 0, width: 10, height: 10}, 5, 5)).to.be(true); expect(Snap.path.isPointInsideBBox({x: 0, y: 0, width: 10, height: 10}, 5, 5)).to.be(true);
expect(Savage.path.isPointInsideBBox({x: 0, y: 0, width: 10, height: 10}, 10, 5)).to.be(true); expect(Snap.path.isPointInsideBBox({x: 0, y: 0, width: 10, height: 10}, 10, 5)).to.be(true);
expect(Savage.path.isPointInsideBBox({x: 0, y: 0, width: 10, height: 10}, 10, 10)).to.be(true); expect(Snap.path.isPointInsideBBox({x: 0, y: 0, width: 10, height: 10}, 10, 10)).to.be(true);
}); });
it("Savage.path.isBBoxIntersect", function () { it("Snap.path.isBBoxIntersect", function () {
expect(Savage.path.isBBoxIntersect({ expect(Snap.path.isBBoxIntersect({
x: 0, x: 0,
y: 0, y: 0,
width: 10, width: 10,
@ -98,7 +98,7 @@ describe("Path methods", function () {
width: 15, width: 15,
height: 15 height: 15
})).to.be(true); })).to.be(true);
expect(Savage.path.isBBoxIntersect({ expect(Snap.path.isBBoxIntersect({
x: 0, x: 0,
y: 0, y: 0,
width: 10, width: 10,
@ -109,7 +109,7 @@ describe("Path methods", function () {
width: 7, width: 7,
height: 7 height: 7
})).to.be(true); })).to.be(true);
expect(Savage.path.isBBoxIntersect({ expect(Snap.path.isBBoxIntersect({
x: 0, x: 0,
y: 0, y: 0,
width: 10, width: 10,
@ -121,7 +121,7 @@ describe("Path methods", function () {
height: 10 height: 10
})).to.be(false); })).to.be(false);
}); });
it("Savage.path.toAbsolute", function() { it("Snap.path.toAbsolute", function() {
var relPath = "M 10 10" + var relPath = "M 10 10" +
"h 40" + "h 40" +
"v 30" + "v 30" +
@ -143,7 +143,7 @@ describe("Path methods", function () {
"t 20 0" + "t 20 0" +
"m -40 30" + "m -40 30" +
"a 10 10 0 0 0 40 0"; "a 10 10 0 0 0 40 0";
var absPath = Savage.path.toAbsolute(relPath); var absPath = Snap.path.toAbsolute(relPath);
var i = 0; var i = 0;
var checkNext = function(arr) { var checkNext = function(arr) {
expect(absPath[i++]).to.eql(arr); expect(absPath[i++]).to.eql(arr);
@ -170,7 +170,7 @@ describe("Path methods", function () {
checkNext(['M', 80, 80]); checkNext(['M', 80, 80]);
checkNext(['A', 10, 10, 0, 0, 0, 120, 80]); checkNext(['A', 10, 10, 0, 0, 0, 120, 80]);
}); });
it("Savage.path.toRelative", function() { it("Snap.path.toRelative", function() {
var absPath = "M10 10 H 50 V 40 H 10 L 10 10" + var absPath = "M10 10 H 50 V 40 H 10 L 10 10" +
"M10 50 L 40 50 L 40 90 L 10 90" + "M10 50 L 40 50 L 40 90 L 10 90" +
"M10 100 C 30 120, 50 120, 50 100" + "M10 100 C 30 120, 50 120, 50 100" +
@ -178,7 +178,7 @@ describe("Path methods", function () {
"M80 10 Q 110 40, 140 10" + "M80 10 Q 110 40, 140 10" +
"M80 50 Q 90 70, 100 50 T 120 50" + "M80 50 Q 90 70, 100 50 T 120 50" +
"M80 80 A 10 10 0 0 0 120 80"; "M80 80 A 10 10 0 0 0 120 80";
var relPath = Savage.path.toRelative(absPath); var relPath = Snap.path.toRelative(absPath);
var i = 0; var i = 0;
var checkNext = function(arr) { var checkNext = function(arr) {
expect(relPath[i++]).to.eql(arr); expect(relPath[i++]).to.eql(arr);
@ -206,7 +206,7 @@ describe("Path methods", function () {
checkNext(['m', -40, 30]); checkNext(['m', -40, 30]);
checkNext(['a', 10, 10, 0, 0, 0, 40, 0]); checkNext(['a', 10, 10, 0, 0, 0, 40, 0]);
}); });
it("Savage.path.toCubic", function() { it("Snap.path.toCubic", function() {
var absPath = "M10 10 H 50 V 40 H 10 L 10 10" + var absPath = "M10 10 H 50 V 40 H 10 L 10 10" +
"M10 50 L 40 50 L 40 90 L 10 90" + "M10 50 L 40 50 L 40 90 L 10 90" +
"M10 100 C 30 120, 50 120, 50 100" + "M10 100 C 30 120, 50 120, 50 100" +
@ -235,8 +235,8 @@ describe("Path methods", function () {
"t 20 0" + "t 20 0" +
"m -40 30" + "m -40 30" +
"a 10 10 0 0 0 40 0"; "a 10 10 0 0 0 40 0";
var cubicPathFromAbs = Savage.path.toCubic(absPath); var cubicPathFromAbs = Snap.path.toCubic(absPath);
var cubicPathFromRel = Savage.path.toCubic(relPath); var cubicPathFromRel = Snap.path.toCubic(relPath);
var i = 0; var i = 0;
var checkNext = function(arr) { var checkNext = function(arr) {
expect(cubicPathFromAbs[i]).to.eql(arr); expect(cubicPathFromAbs[i]).to.eql(arr);
@ -268,7 +268,7 @@ describe("Path methods", function () {
checkNext(['C', 116.18802153517007, 93.74785217660714, 120, 87.14531179816328, 120, 80]); checkNext(['C', 116.18802153517007, 93.74785217660714, 120, 87.14531179816328, 120, 80]);
}); });
it("Savage.path.map", function() { it("Snap.path.map", function() {
var absPath = "M10 10 H 50 V 40 H 10 L 10 10" + var absPath = "M10 10 H 50 V 40 H 10 L 10 10" +
"M10 50 L 40 50 L 40 90 L 10 90" + "M10 50 L 40 50 L 40 90 L 10 90" +
"M10 100 C 30 120, 50 120, 50 100" + "M10 100 C 30 120, 50 120, 50 100" +
@ -276,8 +276,8 @@ describe("Path methods", function () {
"M80 10 Q 110 40, 140 10" + "M80 10 Q 110 40, 140 10" +
"M80 50 Q 90 70, 100 50 T 120 50" + "M80 50 Q 90 70, 100 50 T 120 50" +
"M80 80 A 10 10 0 0 0 120 80"; "M80 80 A 10 10 0 0 0 120 80";
var matrix = new Savage.Matrix(1, 0, 0, 1, 1000, 0); var matrix = new Snap.Matrix(1, 0, 0, 1, 1000, 0);
var transformedPath = Savage.path.map(absPath, matrix); var transformedPath = Snap.path.map(absPath, matrix);
var i = 0; var i = 0;
var checkNext = function(arr) { var checkNext = function(arr) {
@ -306,7 +306,7 @@ describe("Path methods", function () {
checkNext(['C', 1080, 95.39600717839002, 1096.66666666666667, 105.01851166488379, 1110, 97.32050807568878]); checkNext(['C', 1080, 95.39600717839002, 1096.66666666666667, 105.01851166488379, 1110, 97.32050807568878]);
checkNext(['C', 1116.18802153517007, 93.74785217660714, 1120, 87.14531179816328, 1120, 80]); checkNext(['C', 1116.18802153517007, 93.74785217660714, 1120, 87.14531179816328, 1120, 80]);
}); });
it("Savage.path.isPointInside", function () { it("Snap.path.isPointInside", function () {
var path = "M10 10 H 50 V 40 H 10 L 10 10 Z" + var path = "M10 10 H 50 V 40 H 10 L 10 10 Z" +
"M10 50 L 40 50 L 40 90 L 10 90 Z" + "M10 50 L 40 50 L 40 90 L 10 90 Z" +
"M10 100 C 30 120, 50 120, 50 100 Z" + "M10 100 C 30 120, 50 120, 50 100 Z" +
@ -315,37 +315,37 @@ describe("Path methods", function () {
"M80 50 Q 90 70, 100 50 T 120 50 Z" + "M80 50 Q 90 70, 100 50 T 120 50 Z" +
"M80 80 A 10 10 0 0 0 120 80 Z"; "M80 80 A 10 10 0 0 0 120 80 Z";
expect(Savage.path.isPointInside(path, 15, 35)).to.be(true); expect(Snap.path.isPointInside(path, 15, 35)).to.be(true);
expect(Savage.path.isPointInside(path, 35, 75)).to.be(true); expect(Snap.path.isPointInside(path, 35, 75)).to.be(true);
expect(Savage.path.isPointInside(path, 15, 102)).to.be(true); expect(Snap.path.isPointInside(path, 15, 102)).to.be(true);
expect(Savage.path.isPointInside(path, 15, 135)).to.be(true); expect(Snap.path.isPointInside(path, 15, 135)).to.be(true);
expect(Savage.path.isPointInside(path, 50, 145)).to.be(true); expect(Snap.path.isPointInside(path, 50, 145)).to.be(true);
expect(Savage.path.isPointInside(path, 130, 15)).to.be(true); expect(Snap.path.isPointInside(path, 130, 15)).to.be(true);
expect(Savage.path.isPointInside(path, 110, 45)).to.be(true); expect(Snap.path.isPointInside(path, 110, 45)).to.be(true);
expect(Savage.path.isPointInside(path, 85, 55)).to.be(true); expect(Snap.path.isPointInside(path, 85, 55)).to.be(true);
expect(Savage.path.isPointInside(path, 115, 82)).to.be(true); expect(Snap.path.isPointInside(path, 115, 82)).to.be(true);
expect(Savage.path.isPointInside(path, 95, 98)).to.be(true); expect(Snap.path.isPointInside(path, 95, 98)).to.be(true);
expect(Savage.path.isPointInside(path, 5, 5)).to.be(false); expect(Snap.path.isPointInside(path, 5, 5)).to.be(false);
expect(Savage.path.isPointInside(path, 25, 48)).to.be(false); expect(Snap.path.isPointInside(path, 25, 48)).to.be(false);
expect(Savage.path.isPointInside(path, 42, 87)).to.be(false); expect(Snap.path.isPointInside(path, 42, 87)).to.be(false);
expect(Savage.path.isPointInside(path, 12, 105)).to.be(false); expect(Snap.path.isPointInside(path, 12, 105)).to.be(false);
expect(Savage.path.isPointInside(path, 47, 113)).to.be(false); expect(Snap.path.isPointInside(path, 47, 113)).to.be(false);
expect(Savage.path.isPointInside(path, 47, 135)).to.be(false); expect(Snap.path.isPointInside(path, 47, 135)).to.be(false);
expect(Savage.path.isPointInside(path, 25, 142)).to.be(false); expect(Snap.path.isPointInside(path, 25, 142)).to.be(false);
expect(Savage.path.isPointInside(path, 15, 125)).to.be(false); expect(Snap.path.isPointInside(path, 15, 125)).to.be(false);
expect(Savage.path.isPointInside(path, 43, 152)).to.be(false); expect(Snap.path.isPointInside(path, 43, 152)).to.be(false);
expect(Savage.path.isPointInside(path, 58, 152)).to.be(false); expect(Snap.path.isPointInside(path, 58, 152)).to.be(false);
expect(Savage.path.isPointInside(path, 90, 21)).to.be(false); expect(Snap.path.isPointInside(path, 90, 21)).to.be(false);
expect(Savage.path.isPointInside(path, 130, 21)).to.be(false); expect(Snap.path.isPointInside(path, 130, 21)).to.be(false);
expect(Savage.path.isPointInside(path, 95, 48)).to.be(false); expect(Snap.path.isPointInside(path, 95, 48)).to.be(false);
expect(Savage.path.isPointInside(path, 110, 55)).to.be(false); expect(Snap.path.isPointInside(path, 110, 55)).to.be(false);
expect(Savage.path.isPointInside(path, 100, 70)).to.be(false); expect(Snap.path.isPointInside(path, 100, 70)).to.be(false);
expect(Savage.path.isPointInside(path, 115, 96)).to.be(false); expect(Snap.path.isPointInside(path, 115, 96)).to.be(false);
expect(Savage.path.isPointInside(path, 85, 96)).to.be(false); expect(Snap.path.isPointInside(path, 85, 96)).to.be(false);
}); });
it("Savage.path.intersection", function () { it("Snap.path.intersection", function () {
var path1 = "M10 10 H 50 V 40 H 10 L 10 10 Z" + var path1 = "M10 10 H 50 V 40 H 10 L 10 10 Z" +
"M10 50 L 40 50 L 40 90 L 10 90 Z" + "M10 50 L 40 50 L 40 90 L 10 90 Z" +
"M10 100 C 30 120, 50 120, 50 100 Z" + "M10 100 C 30 120, 50 120, 50 100 Z" +
@ -354,7 +354,7 @@ describe("Path methods", function () {
"M80 50 Q 90 70, 100 50 T 120 50 Z" + "M80 50 Q 90 70, 100 50 T 120 50 Z" +
"M80 80 A 10 10 0 0 0 120 80 Z"; "M80 80 A 10 10 0 0 0 120 80 Z";
var path2 = "M10,0 L80,200 L20, 200 L30, 0 L110, 15 L90, 150"; var path2 = "M10,0 L80,200 L20, 200 L30, 0 L110, 15 L90, 150";
var intersection = Savage.path.intersection(path1, path2); var intersection = Snap.path.intersection(path1, path2);
expect(intersection.length).to.be(22); expect(intersection.length).to.be(22);
var first = intersection[0]; var first = intersection[0];
expect(first.x).to.be.a('number'); expect(first.x).to.be.a('number');

View File

@ -1,7 +1,7 @@
describe("Primitives creation", function () { describe("Primitives creation", function () {
var s; var s;
beforeEach(function () { beforeEach(function () {
s = Savage(100, 100); s = Snap(100, 100);
}); });
afterEach(function () { afterEach(function () {
s.remove(); s.remove();

View File

@ -1,7 +1,7 @@
describe("Set methods", function () { describe("Set methods", function () {
var s; var s;
beforeEach(function () { beforeEach(function () {
s = Savage(100, 100); s = Snap(100, 100);
}); });
afterEach(function () { afterEach(function () {
s.remove(); s.remove();
@ -9,7 +9,7 @@ describe("Set methods", function () {
it("Set.clear", function() { it("Set.clear", function() {
var rect1 = s.rect(10, 20, 30, 40); var rect1 = s.rect(10, 20, 30, 40);
var rect2 = s.rect(10, 20, 30, 40); var rect2 = s.rect(10, 20, 30, 40);
var set = Savage.set(rect1, rect2); var set = Snap.set(rect1, rect2);
expect(set.length).to.be(2); expect(set.length).to.be(2);
set.clear(); set.clear();
expect(set.length).to.be(0); expect(set.length).to.be(0);
@ -18,7 +18,7 @@ describe("Set methods", function () {
var rect1 = s.rect(10, 20, 30, 40); var rect1 = s.rect(10, 20, 30, 40);
var rect2 = s.rect(10, 20, 30, 40); var rect2 = s.rect(10, 20, 30, 40);
var rect3 = s.rect(10, 20, 30, 40); var rect3 = s.rect(10, 20, 30, 40);
var set = Savage.set(rect1, rect2, rect3); var set = Snap.set(rect1, rect2, rect3);
expect(set.length).to.be(3); expect(set.length).to.be(3);
var excluded = set.exclude(rect2); var excluded = set.exclude(rect2);
expect(set.length).to.be(2); expect(set.length).to.be(2);
@ -31,7 +31,7 @@ describe("Set methods", function () {
var rect1 = s.rect(10, 20, 30, 40); var rect1 = s.rect(10, 20, 30, 40);
var rect2 = s.rect(10, 20, 30, 40); var rect2 = s.rect(10, 20, 30, 40);
var rect3 = s.rect(10, 20, 30, 40); var rect3 = s.rect(10, 20, 30, 40);
var set = Savage.set(rect1, rect2, rect3); var set = Snap.set(rect1, rect2, rect3);
var i = 0; var i = 0;
var arr = [rect1, rect2, rect3]; var arr = [rect1, rect2, rect3];
var result = set.forEach(function(item) { var result = set.forEach(function(item) {
@ -46,7 +46,7 @@ describe("Set methods", function () {
var rect1 = s.rect(10, 20, 30, 40); var rect1 = s.rect(10, 20, 30, 40);
var rect2 = s.rect(10, 20, 30, 40); var rect2 = s.rect(10, 20, 30, 40);
var rect3 = s.rect(10, 20, 30, 40); var rect3 = s.rect(10, 20, 30, 40);
var set = Savage.set(rect1, rect2, rect3); var set = Snap.set(rect1, rect2, rect3);
expect(set.length).to.be(3); expect(set.length).to.be(3);
var result = set.pop(); var result = set.pop();
expect(set.length).to.be(2); expect(set.length).to.be(2);
@ -62,7 +62,7 @@ describe("Set methods", function () {
var rect1 = s.rect(10, 20, 30, 40); var rect1 = s.rect(10, 20, 30, 40);
var rect2 = s.rect(10, 20, 30, 40); var rect2 = s.rect(10, 20, 30, 40);
var rect3 = s.rect(10, 20, 30, 40); var rect3 = s.rect(10, 20, 30, 40);
var set = Savage.set(rect1, rect2); var set = Snap.set(rect1, rect2);
expect(set.length).to.be(2); expect(set.length).to.be(2);
set.push(rect3); set.push(rect3);
expect(set.length).to.be(3); expect(set.length).to.be(3);
@ -75,7 +75,7 @@ describe("Set methods", function () {
var rect2 = s.rect(10, 20, 30, 40); var rect2 = s.rect(10, 20, 30, 40);
var rect3 = s.rect(10, 20, 30, 40); var rect3 = s.rect(10, 20, 30, 40);
var rect4 = s.rect(10, 20, 30, 40); var rect4 = s.rect(10, 20, 30, 40);
var set = Savage.set(rect1, rect2, rect3, rect4); var set = Snap.set(rect1, rect2, rect3, rect4);
var removedSet = set.splice(1, 2); var removedSet = set.splice(1, 2);
expect(set.length).to.be(2); expect(set.length).to.be(2);
expect(set[0]).to.be(rect1); expect(set[0]).to.be(rect1);
@ -92,7 +92,7 @@ describe("Set methods", function () {
var rect2 = s.rect(10, 20, 30, 40); var rect2 = s.rect(10, 20, 30, 40);
var rect3 = s.rect(10, 20, 30, 40); var rect3 = s.rect(10, 20, 30, 40);
var rect4 = s.rect(10, 20, 30, 40); var rect4 = s.rect(10, 20, 30, 40);
var set = Savage.set(rect1, rect2, rect3); var set = Snap.set(rect1, rect2, rect3);
var removedSet = set.splice(2, 1, rect4); var removedSet = set.splice(2, 1, rect4);
expect(set.length).to.be(3); expect(set.length).to.be(3);
expect(set[0]).to.be(rect1); expect(set[0]).to.be(rect1);

View File

@ -1,6 +1,6 @@
describe("Savage methods", function () { describe("Snap methods", function () {
it("Savage.Matrix - six params", function () { it("Snap.Matrix - six params", function () {
var matrix = new Savage.Matrix(1, 2, 3, 4, 5, 6); var matrix = new Snap.Matrix(1, 2, 3, 4, 5, 6);
expect(matrix).to.eql({ expect(matrix).to.eql({
a: 1, a: 1,
b: 2, b: 2,
@ -10,9 +10,9 @@ describe("Savage methods", function () {
f: 6 f: 6
}); });
}); });
it("Savage.Matrix - SVGMatrix param", function () { it("Snap.Matrix - SVGMatrix param", function () {
var svgMatrix = new Savage(10, 10).node.createSVGMatrix(); var svgMatrix = new Snap(10, 10).node.createSVGMatrix();
var matrix = new Savage.Matrix(svgMatrix); var matrix = new Snap.Matrix(svgMatrix);
expect(matrix).to.eql({ expect(matrix).to.eql({
a: 1, a: 1,
b: 0, b: 0,
@ -22,8 +22,8 @@ describe("Savage methods", function () {
f: 0 f: 0
}); });
}); });
it("Savage.ajax - no postData", function(done) { it("Snap.ajax - no postData", function(done) {
var xhr = Savage.ajax('./res/file-for-ajax.txt', function(xhr) { var xhr = Snap.ajax('./res/file-for-ajax.txt', function(xhr) {
var responseText = xhr.responseText; var responseText = xhr.responseText;
expect(responseText).to.be('success'); expect(responseText).to.be('success');
expect(this.isContext).to.be(true); expect(this.isContext).to.be(true);
@ -31,8 +31,8 @@ describe("Savage methods", function () {
}, {'isContext': true}); }, {'isContext': true});
expect(xhr).to.be.an('object'); expect(xhr).to.be.an('object');
}); });
it("Savage.ajax - with object postData", function(done) { it("Snap.ajax - with object postData", function(done) {
var xhr = Savage.ajax('./res/file-for-ajax.txt', {foo: 'bar'}, function(xhr) { var xhr = Snap.ajax('./res/file-for-ajax.txt', {foo: 'bar'}, function(xhr) {
var responseText = xhr.responseText; var responseText = xhr.responseText;
expect(responseText).to.be('success'); expect(responseText).to.be('success');
expect(this.isContext).to.be(true); expect(this.isContext).to.be(true);
@ -40,8 +40,8 @@ describe("Savage methods", function () {
}, {'isContext': true}); }, {'isContext': true});
expect(xhr).to.be.an('object'); expect(xhr).to.be.an('object');
}); });
it("Savage.ajax - with string postData", function(done) { it("Snap.ajax - with string postData", function(done) {
var xhr = Savage.ajax('./res/file-for-ajax.txt', 'foo=bar', function(xhr) { var xhr = Snap.ajax('./res/file-for-ajax.txt', 'foo=bar', function(xhr) {
var responseText = xhr.responseText; var responseText = xhr.responseText;
expect(responseText).to.be('success'); expect(responseText).to.be('success');
expect(this.isContext).to.be(true); expect(this.isContext).to.be(true);
@ -60,43 +60,43 @@ describe("Savage methods", function () {
expect(minaObj.stop).to.be.a('function'); expect(minaObj.stop).to.be.a('function');
}; };
it("Savage.animate - numbers, no easing or callback", function(done) { it("Snap.animate - numbers, no easing or callback", function(done) {
var n; var n;
var minaObj = Savage.animate(10, 20, function(newN) { n = newN; }, 50); var minaObj = Snap.animate(10, 20, function(newN) { n = newN; }, 50);
setTimeout(function() { setTimeout(function() {
expect(n).to.be(20); expect(n).to.be(20);
done(); done();
}, 100); }, 100);
validateMina(minaObj); validateMina(minaObj);
}); });
it("Savage.animate - numbers, callback", function(done) { it("Snap.animate - numbers, callback", function(done) {
var n; var n;
var minaObj = Savage.animate(10, 20, function(newN) { n = newN; }, 50, function() { var minaObj = Snap.animate(10, 20, function(newN) { n = newN; }, 50, function() {
expect(n).to.be(20); expect(n).to.be(20);
done(); done();
}); });
validateMina(minaObj); validateMina(minaObj);
}); });
it("Savage.animate - numbers, easing", function(done) { it("Snap.animate - numbers, easing", function(done) {
var n; var n;
var minaObj = Savage.animate(10, 20, function(newN) { n = newN; }, 50, mina.easeinout); var minaObj = Snap.animate(10, 20, function(newN) { n = newN; }, 50, mina.easeinout);
setTimeout(function() { setTimeout(function() {
expect(n).to.be(20); expect(n).to.be(20);
done(); done();
}, 100); }, 100);
validateMina(minaObj); validateMina(minaObj);
}); });
it("Savage.animate - numbers, easing & callback", function(done) { it("Snap.animate - numbers, easing & callback", function(done) {
var n; var n;
var minaObj = Savage.animate(10, 20, function(newN) { n = newN; }, 50, mina.bounce, function() { var minaObj = Snap.animate(10, 20, function(newN) { n = newN; }, 50, mina.bounce, function() {
expect(n).to.be(20); expect(n).to.be(20);
done(); done();
}); });
validateMina(minaObj); validateMina(minaObj);
}); });
it("Savage.animate - arrays, no easing or callback", function(done) { it("Snap.animate - arrays, no easing or callback", function(done) {
var n1, n2; var n1, n2;
var minaObj = Savage.animate([5, 10], [10, 20], function(nArr) { n1 = nArr[0]; n2 = nArr[1]; }, 50); var minaObj = Snap.animate([5, 10], [10, 20], function(nArr) { n1 = nArr[0]; n2 = nArr[1]; }, 50);
setTimeout(function() { setTimeout(function() {
expect(n1).to.be(10); expect(n1).to.be(10);
expect(n2).to.be(20); expect(n2).to.be(20);
@ -104,18 +104,18 @@ describe("Savage methods", function () {
}, 100); }, 100);
validateMina(minaObj); validateMina(minaObj);
}); });
it("Savage.animate - arrays, callback", function(done) { it("Snap.animate - arrays, callback", function(done) {
var n1, n2; var n1, n2;
var minaObj = Savage.animate([5, 10], [10, 20], function(nArr) {n1 = nArr[0]; n2 = nArr[1]; }, 50, function() { var minaObj = Snap.animate([5, 10], [10, 20], function(nArr) {n1 = nArr[0]; n2 = nArr[1]; }, 50, function() {
expect(n1).to.be(10); expect(n1).to.be(10);
expect(n2).to.be(20); expect(n2).to.be(20);
done(); done();
}); });
validateMina(minaObj); validateMina(minaObj);
}); });
it("Savage.animate - arrays, easing", function(done) { it("Snap.animate - arrays, easing", function(done) {
var n1, n2; var n1, n2;
var minaObj = Savage.animate([5, 10], [10, 20], function(nArr) { n1 = nArr[0]; n2 = nArr[1]; }, 50, mina.easeinout); var minaObj = Snap.animate([5, 10], [10, 20], function(nArr) { n1 = nArr[0]; n2 = nArr[1]; }, 50, mina.easeinout);
setTimeout(function() { setTimeout(function() {
expect(n1).to.be(10); expect(n1).to.be(10);
expect(n2).to.be(20); expect(n2).to.be(20);
@ -123,39 +123,39 @@ describe("Savage methods", function () {
}, 100); }, 100);
validateMina(minaObj); validateMina(minaObj);
}); });
it("Savage.animate - arrays, easing & callback", function(done) { it("Snap.animate - arrays, easing & callback", function(done) {
var n1, n2; var n1, n2;
var minaObj = Savage.animate([5, 10], [10, 20], function(nArr) { n1 = nArr[0]; n2 = nArr[1]; }, 50, mina.backin, function() { var minaObj = Snap.animate([5, 10], [10, 20], function(nArr) { n1 = nArr[0]; n2 = nArr[1]; }, 50, mina.backin, function() {
expect(n1).to.be(10); expect(n1).to.be(10);
expect(n2).to.be(20); expect(n2).to.be(20);
done(); done();
}); });
validateMina(minaObj); validateMina(minaObj);
}); });
it("Savage.animation - no easing or callback", function() { it("Snap.animation - no easing or callback", function() {
var anim = Savage.animation({ foo: "bar" }, 100); var anim = Snap.animation({ foo: "bar" }, 100);
expect(anim).to.be.an("object"); expect(anim).to.be.an("object");
expect(anim.dur).to.be(100); expect(anim.dur).to.be(100);
expect(anim.attr.foo).to.be("bar"); expect(anim.attr.foo).to.be("bar");
}); });
it("Savage.animation - with easing", function() { it("Snap.animation - with easing", function() {
var anim = Savage.animation({ foo: "bar" }, 100, mina.easein); var anim = Snap.animation({ foo: "bar" }, 100, mina.easein);
expect(anim).to.be.an("object"); expect(anim).to.be.an("object");
expect(anim.dur).to.be(100); expect(anim.dur).to.be(100);
expect(anim.attr.foo).to.be("bar"); expect(anim.attr.foo).to.be("bar");
expect(anim.easing).to.be.a("function"); expect(anim.easing).to.be.a("function");
}); });
it("Savage.animation - with callback", function() { it("Snap.animation - with callback", function() {
var cb = function(){}; var cb = function(){};
var anim = Savage.animation({ foo: "bar" }, 100, cb); var anim = Snap.animation({ foo: "bar" }, 100, cb);
expect(anim).to.be.an("object"); expect(anim).to.be.an("object");
expect(anim.dur).to.be(100); expect(anim.dur).to.be(100);
expect(anim.attr.foo).to.be("bar"); expect(anim.attr.foo).to.be("bar");
expect(anim.callback).to.be.a("function"); expect(anim.callback).to.be.a("function");
}); });
it("Savage.animation - with easing & callback", function() { it("Snap.animation - with easing & callback", function() {
var cb = function(){}; var cb = function(){};
var anim = Savage.animation({ foo: "bar" }, 100, mina.linear, cb); var anim = Snap.animation({ foo: "bar" }, 100, mina.linear, cb);
expect(anim).to.be.an("object"); expect(anim).to.be.an("object");
expect(anim.dur).to.be(100); expect(anim.dur).to.be(100);
expect(anim.attr.foo).to.be("bar"); expect(anim.attr.foo).to.be("bar");
@ -163,29 +163,29 @@ describe("Savage methods", function () {
expect(anim.callback).to.be.a("function"); expect(anim.callback).to.be.a("function");
expect(anim.easing).to.not.be(anim.callback); expect(anim.easing).to.not.be(anim.callback);
}); });
it("Savage.deg", function() { it("Snap.deg", function() {
expect(Savage.deg(Math.PI)).to.be(180); expect(Snap.deg(Math.PI)).to.be(180);
expect(Savage.deg(Math.PI / 2)).to.be(90); expect(Snap.deg(Math.PI / 2)).to.be(90);
expect(Savage.deg(Math.PI / 4)).to.be(45); expect(Snap.deg(Math.PI / 4)).to.be(45);
expect(Savage.deg(Math.PI * 2)).to.be(0); expect(Snap.deg(Math.PI * 2)).to.be(0);
}); });
it("Savage.rad", function() { it("Snap.rad", function() {
expect(Savage.rad(180)).to.be(Math.PI); expect(Snap.rad(180)).to.be(Math.PI);
expect(Savage.rad(90)).to.be(Math.PI / 2); expect(Snap.rad(90)).to.be(Math.PI / 2);
expect(Savage.rad(45)).to.be(Math.PI / 4); expect(Snap.rad(45)).to.be(Math.PI / 4);
expect(Savage.rad(0)).to.be(0); expect(Snap.rad(0)).to.be(0);
}); });
it("Savage.format", function() { it("Snap.format", function() {
var outputStr; var outputStr;
outputStr = Savage.format("{x}", {x: 1}); outputStr = Snap.format("{x}", {x: 1});
expect(outputStr).to.be("1"); expect(outputStr).to.be("1");
outputStr = Savage.format("{a['foo']}", { outputStr = Snap.format("{a['foo']}", {
a: { a: {
foo: 'bar' foo: 'bar'
} }
}); });
expect(outputStr).to.be("bar"); expect(outputStr).to.be("bar");
outputStr = Savage.format("M{x},{y}h{dim.width}v{dim.height}h{dim['negative width']}z", { outputStr = Snap.format("M{x},{y}h{dim.width}v{dim.height}h{dim['negative width']}z", {
x: 10, x: 10,
y: 20, y: 20,
dim: { dim: {
@ -196,55 +196,55 @@ describe("Savage methods", function () {
}); });
expect(outputStr).to.be("M10,20h40v50h-40z"); expect(outputStr).to.be("M10,20h40v50h-40z");
}); });
it("Savage.fragment", function() { it("Snap.fragment", function() {
var frag = Savage.fragment('<g class="foo"></g>', '<g class="foo2"></g>'); var frag = Snap.fragment('<g class="foo"></g>', '<g class="foo2"></g>');
expect(frag).to.be.an("object"); expect(frag).to.be.an("object");
expect(frag.node.childNodes.length).to.be(2); expect(frag.node.childNodes.length).to.be(2);
expect(frag.node.firstChild.nodeName).to.be("g"); expect(frag.node.firstChild.nodeName).to.be("g");
expect(frag.node.firstChild.getAttribute("class")).to.be("foo"); expect(frag.node.firstChild.getAttribute("class")).to.be("foo");
expect(frag.node.lastChild.getAttribute("class")).to.be("foo2"); expect(frag.node.lastChild.getAttribute("class")).to.be("foo2");
frag = Savage.fragment('<g class="foo"><rect x="0" y="0" width="10" height="10"/></g>'); frag = Snap.fragment('<g class="foo"><rect x="0" y="0" width="10" height="10"/></g>');
var rectWidth = frag.select('rect').attr('width'); var rectWidth = frag.select('rect').attr('width');
expect(rectWidth).to.be("10"); expect(rectWidth).to.be("10");
}); });
it("Savage.is", function() { it("Snap.is", function() {
var undef; var undef;
expect(Savage.is("foo", "string")).to.be.ok(); expect(Snap.is("foo", "string")).to.be.ok();
expect(Savage.is(123, "number")).to.be.ok(); expect(Snap.is(123, "number")).to.be.ok();
expect(Savage.is({}, "object")).to.be.ok(); expect(Snap.is({}, "object")).to.be.ok();
expect(Savage.is([], "array")).to.be.ok(); expect(Snap.is([], "array")).to.be.ok();
expect(Savage.is([], "object")).to.be.ok(); expect(Snap.is([], "object")).to.be.ok();
expect(Savage.is(null, "null")).to.be.ok(); expect(Snap.is(null, "null")).to.be.ok();
expect(Savage.is(false, "boolean")).to.be.ok(); expect(Snap.is(false, "boolean")).to.be.ok();
expect(Savage.is(undef, "undefined")).to.be.ok(); expect(Snap.is(undef, "undefined")).to.be.ok();
expect(Savage.is(function(){}, "function")).to.be.ok(); expect(Snap.is(function(){}, "function")).to.be.ok();
expect(Savage.is(function(){}, "object")).to.be.ok(); expect(Snap.is(function(){}, "object")).to.be.ok();
}); });
it("Savage.load - with context", function(done) { it("Snap.load - with context", function(done) {
Savage.load('./res/external-svg.svg', function(fragment) { Snap.load('./res/external-svg.svg', function(fragment) {
expect(fragment.node.querySelector("svg")).to.not.be(null); expect(fragment.node.querySelector("svg")).to.not.be(null);
expect(this.myContext).to.be(true); expect(this.myContext).to.be(true);
done(); done();
}, {myContext: true}); }, {myContext: true});
}); });
it("Savage.load - without context", function(done) { it("Snap.load - without context", function(done) {
Savage.load('./res/external-svg.svg', function(fragment) { Snap.load('./res/external-svg.svg', function(fragment) {
expect(fragment.node.querySelector("svg")).to.not.be(null); expect(fragment.node.querySelector("svg")).to.not.be(null);
done(); done();
}); });
}); });
it("Savage.parse", function() { it("Snap.parse", function() {
var frag = Savage.parse('<g class="foo"></g>'); var frag = Snap.parse('<g class="foo"></g>');
expect(frag).to.be.an("object"); expect(frag).to.be.an("object");
expect(frag.node.childNodes.length).to.be(1); expect(frag.node.childNodes.length).to.be(1);
expect(frag.node.firstChild.nodeName).to.be("g"); expect(frag.node.firstChild.nodeName).to.be("g");
expect(frag.node.firstChild.getAttribute("class")).to.be("foo"); expect(frag.node.firstChild.getAttribute("class")).to.be("foo");
frag = Savage.parse('<g class="foo"><rect x="0" y="0" width="10" height="10"/></g>'); frag = Snap.parse('<g class="foo"><rect x="0" y="0" width="10" height="10"/></g>');
var rectWidth = frag.select('rect').attr('width'); var rectWidth = frag.select('rect').attr('width');
expect(rectWidth).to.be("10"); expect(rectWidth).to.be("10");
}); });
it("Savage.parsePathString - string", function() { it("Snap.parsePathString - string", function() {
var pathArrs = Savage.parsePathString( var pathArrs = Snap.parsePathString(
"M1 2" + "M1 2" +
"m3 4" + "m3 4" +
"L 5, 6" + "L 5, 6" +
@ -284,22 +284,22 @@ describe("Savage methods", function () {
expect(pathArrs[17]).to.eql(["a", 50, 51, 52, 1, 0, 53, 54]); expect(pathArrs[17]).to.eql(["a", 50, 51, 52, 1, 0, 53, 54]);
expect(pathArrs[18]).to.eql(["Z"]); expect(pathArrs[18]).to.eql(["Z"]);
}); });
it("Savage.parsePathString - array", function() { it("Snap.parsePathString - array", function() {
var pathArrs = Savage.parsePathString(["M1 2"]); var pathArrs = Snap.parsePathString(["M1 2"]);
expect(pathArrs[0]).to.eql(["M", 1, 2]); expect(pathArrs[0]).to.eql(["M", 1, 2]);
}); });
it("Savage.parseTransformString - string", function() { it("Snap.parseTransformString - string", function() {
var matrix = new Savage.Matrix(1, 0, 0, 2, 0, 0); var matrix = new Snap.Matrix(1, 0, 0, 2, 0, 0);
var str = matrix.toTransformString(); var str = matrix.toTransformString();
var output = Savage.parseTransformString(str); var output = Snap.parseTransformString(str);
expect(output[0]).to.eql(['s', 1, 2, 0, 0]); expect(output[0]).to.eql(['s', 1, 2, 0, 0]);
}); });
it("Savage.parseTransformString - array", function() { it("Snap.parseTransformString - array", function() {
var output = Savage.parseTransformString(['s', 1, 2, 0, 0]); var output = Snap.parseTransformString(['s', 1, 2, 0, 0]);
expect(output[0]).to.eql(['s', 1, 2, 0, 0]); expect(output[0]).to.eql(['s', 1, 2, 0, 0]);
}); });
it("Savage.select", function() { it("Snap.select", function() {
var s = Savage(10, 10); var s = Snap(10, 10);
var group1 = s.group(); var group1 = s.group();
var group2 = s.group(); var group2 = s.group();
var group3 = s.group(); var group3 = s.group();
@ -313,14 +313,14 @@ describe("Savage methods", function () {
group2.add(group3); group2.add(group3);
group2.add(circle1); group2.add(circle1);
group3.add(circle2); group3.add(circle2);
var c1 = Savage.select('.circle-one'); var c1 = Snap.select('.circle-one');
expect(circle1).to.be(c1); expect(circle1).to.be(c1);
var c2 = Savage.select('.circle-two'); var c2 = Snap.select('.circle-two');
expect(circle2).to.be(c2); expect(circle2).to.be(c2);
s.remove(); s.remove();
}); });
it("Savage.selectAll", function() { it("Snap.selectAll", function() {
var s = Savage(10, 10); var s = Snap(10, 10);
var group1 = s.group(); var group1 = s.group();
var group2 = s.group(); var group2 = s.group();
var group3 = s.group(); var group3 = s.group();
@ -334,61 +334,61 @@ describe("Savage methods", function () {
group2.add(group3); group2.add(group3);
group2.add(circle1); group2.add(circle1);
group3.add(circle2); group3.add(circle2);
var circles = Savage.selectAll('circle'); var circles = Snap.selectAll('circle');
expect(circles.length).to.be(2); expect(circles.length).to.be(2);
expect(circles).to.contain(circle1); expect(circles).to.contain(circle1);
expect(circles).to.contain(circle2); expect(circles).to.contain(circle2);
s.remove(); s.remove();
}); });
it("Savage.snapTo - number, no tolerance", function() { it("Snap.snapTo - number, no tolerance", function() {
expect(Savage.snapTo(100, -5)).to.be(0); expect(Snap.snapTo(100, -5)).to.be(0);
expect(Savage.snapTo(100, 0.0001)).to.be(0); expect(Snap.snapTo(100, 0.0001)).to.be(0);
expect(Savage.snapTo(100, 9)).to.be(0); expect(Snap.snapTo(100, 9)).to.be(0);
expect(Savage.snapTo(100, 50)).to.be(50); expect(Snap.snapTo(100, 50)).to.be(50);
expect(Savage.snapTo(100, 75)).to.be(75); expect(Snap.snapTo(100, 75)).to.be(75);
expect(Savage.snapTo(100, 90)).to.be(90); expect(Snap.snapTo(100, 90)).to.be(90);
expect(Savage.snapTo(100, 91)).to.be(100); expect(Snap.snapTo(100, 91)).to.be(100);
expect(Savage.snapTo(100, 95)).to.be(100); expect(Snap.snapTo(100, 95)).to.be(100);
expect(Savage.snapTo(100, 1204)).to.be(1200); expect(Snap.snapTo(100, 1204)).to.be(1200);
}); });
it("Savage.snapTo - array, no tolerance", function() { it("Snap.snapTo - array, no tolerance", function() {
var grid = [0, 55, 200]; var grid = [0, 55, 200];
expect(Savage.snapTo(grid, -5)).to.be(0); expect(Snap.snapTo(grid, -5)).to.be(0);
expect(Savage.snapTo(grid, 0.0001)).to.be(0); expect(Snap.snapTo(grid, 0.0001)).to.be(0);
expect(Savage.snapTo(grid, 9)).to.be(0); expect(Snap.snapTo(grid, 9)).to.be(0);
expect(Savage.snapTo(grid, 50)).to.be(55); expect(Snap.snapTo(grid, 50)).to.be(55);
expect(Savage.snapTo(grid, 75)).to.be(75); expect(Snap.snapTo(grid, 75)).to.be(75);
expect(Savage.snapTo(grid, 90)).to.be(90); expect(Snap.snapTo(grid, 90)).to.be(90);
expect(Savage.snapTo(grid, 91)).to.be(91); expect(Snap.snapTo(grid, 91)).to.be(91);
expect(Savage.snapTo(grid, 195)).to.be(200); expect(Snap.snapTo(grid, 195)).to.be(200);
expect(Savage.snapTo(grid, 1204)).to.be(1204); expect(Snap.snapTo(grid, 1204)).to.be(1204);
}); });
it("Savage.snapTo - number, with tolerance", function() { it("Snap.snapTo - number, with tolerance", function() {
expect(Savage.snapTo(100, 95, 0)).to.be(95); expect(Snap.snapTo(100, 95, 0)).to.be(95);
expect(Savage.snapTo(100, 95, 5)).to.be(95); expect(Snap.snapTo(100, 95, 5)).to.be(95);
expect(Savage.snapTo(100, 95, 6)).to.be(100); expect(Snap.snapTo(100, 95, 6)).to.be(100);
expect(Savage.snapTo(100, 105, 6)).to.be(100); expect(Snap.snapTo(100, 105, 6)).to.be(100);
expect(Savage.snapTo(100, 105, 5)).to.be(105); expect(Snap.snapTo(100, 105, 5)).to.be(105);
expect(Savage.snapTo(100, 105, 0)).to.be(105); expect(Snap.snapTo(100, 105, 0)).to.be(105);
// expect(Savage.snapTo(10, 19, 50)).to.be(20); // TODO: Find out what tolerance > grid should do // expect(Snap.snapTo(10, 19, 50)).to.be(20); // TODO: Find out what tolerance > grid should do
}); });
it("Savage.snapTo - array, with tolerance", function() { it("Snap.snapTo - array, with tolerance", function() {
var grid = [0, 55, 200]; var grid = [0, 55, 200];
expect(Savage.snapTo(grid, -5, 20)).to.be(0); expect(Snap.snapTo(grid, -5, 20)).to.be(0);
expect(Savage.snapTo(grid, -5, 3)).to.be(-5); expect(Snap.snapTo(grid, -5, 3)).to.be(-5);
expect(Savage.snapTo(grid, 0.0001, 0.00001)).to.be(0.0001); expect(Snap.snapTo(grid, 0.0001, 0.00001)).to.be(0.0001);
expect(Savage.snapTo(grid, 0.0001, 1)).to.be(0); expect(Snap.snapTo(grid, 0.0001, 1)).to.be(0);
expect(Savage.snapTo(grid, 9, 9)).to.be(0); expect(Snap.snapTo(grid, 9, 9)).to.be(0);
expect(Savage.snapTo(grid, 9, 10.5)).to.be(0); expect(Snap.snapTo(grid, 9, 10.5)).to.be(0);
expect(Savage.snapTo(grid, 50, 6)).to.be(55); expect(Snap.snapTo(grid, 50, 6)).to.be(55);
expect(Savage.snapTo(grid, 50, 1)).to.be(50); expect(Snap.snapTo(grid, 50, 1)).to.be(50);
expect(Savage.snapTo(grid, 201, 0.5)).to.be(201); expect(Snap.snapTo(grid, 201, 0.5)).to.be(201);
expect(Savage.snapTo(grid, 199, 1)).to.be(200); expect(Snap.snapTo(grid, 199, 1)).to.be(200);
expect(Savage.snapTo(grid, 299, 100)).to.be(200); expect(Snap.snapTo(grid, 299, 100)).to.be(200);
}); });
it("Savage.path.getBBox", function() { it("Snap.path.getBBox", function() {
// same as 10,20,30,40 rect // same as 10,20,30,40 rect
var bbox = Savage.path.getBBox("M10,20h30v40h-30z"); var bbox = Snap.path.getBBox("M10,20h30v40h-30z");
expect(bbox.x).to.eql(10); expect(bbox.x).to.eql(10);
expect(bbox.y).to.eql(20); expect(bbox.y).to.eql(20);
expect(bbox.width).to.eql(30); expect(bbox.width).to.eql(30);
@ -396,18 +396,18 @@ describe("Savage methods", function () {
expect(bbox.x2).to.eql(10 + 30); expect(bbox.x2).to.eql(10 + 30);
expect(bbox.y2).to.eql(20 + 40); expect(bbox.y2).to.eql(20 + 40);
}); });
it("Savage.angle - 2 points", function() { it("Snap.angle - 2 points", function() {
var angle = Savage.angle(0, 0, 10, 10); var angle = Snap.angle(0, 0, 10, 10);
expect(angle).to.not.be(0); expect(angle).to.not.be(0);
expect(angle % 45).to.be(0); expect(angle % 45).to.be(0);
angle = Savage.angle(0, 0, 10, 0); angle = Snap.angle(0, 0, 10, 0);
expect(angle % 90).to.be(0); expect(angle % 90).to.be(0);
}); });
it("Savage.angle - 3 points", function() { it("Snap.angle - 3 points", function() {
var angle = Savage.angle(10, 0, 0, 10, 0, 0); var angle = Snap.angle(10, 0, 0, 10, 0, 0);
expect(angle).to.not.be(0); expect(angle).to.not.be(0);
expect(angle % 45).to.be(0); expect(angle % 45).to.be(0);
angle = Savage.angle(10, 0, 0, 10, 0, 0); angle = Snap.angle(10, 0, 0, 10, 0, 0);
expect(Math.abs(angle)).to.be(90); expect(Math.abs(angle)).to.be(90);
}); });
}); });

View File

@ -1,6 +1,6 @@
describe("System check", function () { describe("System check", function () {
it("Savage exists", function () { it("Snap exists", function () {
expect(Savage).to.be.a("function"); expect(Snap).to.be.a("function");
}); });
it("eve exists", function () { it("eve exists", function () {
expect(eve).to.be.a("function"); expect(eve).to.be.a("function");

View File

@ -24,7 +24,7 @@
} }
</style> </style>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css"> <link rel="stylesheet" href="../node_modules/mocha/mocha.css">
<script src="../dist/savage.js"></script> <script src="../dist/snap.svg.js"></script>
</head> </head>
<body> <body>
<div id="mocha"></div> <div id="mocha"></div>
@ -33,7 +33,7 @@
<script>mocha.setup("bdd");</script> <script>mocha.setup("bdd");</script>
<script src="system.js"></script> <script src="system.js"></script>
<script src="paper.js"></script> <script src="paper.js"></script>
<script src="savage-tests.js"></script> <script src="snap-tests.js"></script>
<script src="primitives.js"></script> <script src="primitives.js"></script>
<script src="colors.js"></script> <script src="colors.js"></script>
<script src="attrs.js"></script> <script src="attrs.js"></script>