forked from scala-js/scala-js-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.scala
More file actions
93 lines (70 loc) · 2.59 KB
/
package.scala
File metadata and controls
93 lines (70 loc) · 2.59 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package org.scalajs.dom
import scala.language.implicitConversions
import scala.collection.mutable
package object ext {
implicit class PimpedNodeList(nodes: NodeList)
extends EasySeq[Node](nodes.length, nodes.apply)
implicit class PimpedDOMTokenList(nodes: DOMTokenList)
extends EasySeq[String](nodes.length, nodes.apply)
implicit class PimpedTouchList(nodes: TouchList)
extends EasySeq[Touch](nodes.length, nodes.apply)
implicit class PimpedHtmlCollection(coll: html.Collection)
extends EasySeq[Element](coll.length, coll.apply)
implicit class PimpedSVGTransformList(coll: svg.TransformList)
extends EasySeq[svg.Transform](coll.numberOfItems, coll.getItem)
implicit class Castable(x: Any) {
def cast[T] = x.asInstanceOf[T]
}
implicit def pimpAnimatedNumber(x: svg.AnimatedNumber) = x.baseVal
implicit def pimpRichAnimatedNumber(x: svg.AnimatedNumber) =
x.baseVal: runtime.RichDouble
implicit def pimpAnimatedLength(x: svg.AnimatedLength) = x.baseVal.value
implicit def pimpRichAnimatedLength(x: svg.AnimatedLength) =
x.baseVal.value: runtime.RichDouble
implicit def color2String(c: Color) = c.toString
implicit class pimpedContext(val ctx: CanvasRenderingContext2D) {
def prepCircle(x: Double, y: Double, r: Double) = {
ctx.beginPath()
ctx.arc(x, y, r, 0, math.Pi * 2)
}
def fillCircle(x: Double, y: Double, r: Double) = {
prepCircle(x, y, r)
ctx.fill()
}
def strokeCircle(x: Double, y: Double, r: Double) = {
prepCircle(x, y, r)
ctx.stroke()
}
def prepPath(points: Seq[(Double, Double)], closed: Boolean = true) = {
ctx.beginPath()
if (closed) ctx.moveTo(points.last._1, points.last._2)
for (p <- points) {
ctx.lineTo(p._1, p._2)
}
}
def fillPath(points: (Double, Double)*) = {
prepPath(points)
ctx.fill()
}
def strokePath(points: (Double, Double)*) = {
prepPath(points)
ctx.stroke()
}
def strokePathOpen(points: (Double, Double)*) = {
prepPath(points, closed = false)
ctx.stroke()
}
}
implicit def pimpNamedNodeMap(namedNodeMap: NamedNodeMap): NamedNodeMapMap =
new NamedNodeMapMap(namedNodeMap)
/**
* Implicit class to deal with attributes as with normal mutable Map
* @param attributes
*/
@deprecated("Use NamedNodeMapMap instead.", "0.9.6")
class Attributes(attributes: NamedNodeMap)
extends NamedNodeMapMap(attributes)
@deprecated("Use pimpNamedNodeMap instead.", "0.9.6")
def Attributes(attributes: NamedNodeMap): Attributes =
new Attributes(attributes)
}