-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (42 loc) · 995 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// viewbox helper library
'use strict'
module.exports = {
create: function createViewbox() {
return []
},
add: function addViewboxes(box, addend) {
if (!box.length) {
return addend
}
if (!addend.length) {
return box
}
var xMin = Math.min(box[0], addend[0])
var yMin = Math.min(box[1], addend[1])
var xMax = Math.max((box[0] + box[2]), (addend[0] + addend[2]))
var yMax = Math.max((box[1] + box[3]), (addend[1] + addend[3]))
return [xMin, yMin, (xMax - xMin), (yMax - yMin)]
},
scale: function scaleViewboxes(box, scale) {
return box.map(function(component) {
return component * scale
})
},
rect: function viewboxRect(box) {
box = box && box.length
? box
: [0, 0, 0, 0]
return {
x: box[0],
y: box[1],
width: box[2],
height: box[3]
}
},
asString: function(box) {
box = box && box.length
? box
: [0, 0, 0, 0]
return box.join(' ')
}
}