aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/optional/sugar.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/optional/sugar.js')
-rw-r--r--src/modules/optional/sugar.js55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/modules/optional/sugar.js b/src/modules/optional/sugar.js
index d4c3da5..aa5fb82 100644
--- a/src/modules/optional/sugar.js
+++ b/src/modules/optional/sugar.js
@@ -7,15 +7,24 @@ import SVGNumber from '../../types/SVGNumber.js'
// Define list of available attributes for stroke and fill
const sugar = {
- stroke: [ 'color', 'width', 'opacity', 'linecap', 'linejoin', 'miterlimit', 'dasharray', 'dashoffset' ],
- fill: [ 'color', 'opacity', 'rule' ],
+ stroke: [
+ 'color',
+ 'width',
+ 'opacity',
+ 'linecap',
+ 'linejoin',
+ 'miterlimit',
+ 'dasharray',
+ 'dashoffset'
+ ],
+ fill: ['color', 'opacity', 'rule'],
prefix: function (t, a) {
return a === 'color' ? t : t + '-' + a
}
}
// Add sugar for fill and stroke
-;[ 'fill', 'stroke' ].forEach(function (m) {
+;['fill', 'stroke'].forEach(function (m) {
const extension = {}
let i
@@ -23,7 +32,12 @@ const sugar = {
if (typeof o === 'undefined') {
return this.attr(m)
}
- if (typeof o === 'string' || o instanceof Color || Color.isRgb(o) || (o instanceof Element)) {
+ if (
+ typeof o === 'string' ||
+ o instanceof Color ||
+ Color.isRgb(o) ||
+ o instanceof Element
+ ) {
this.attr(m, o)
} else {
// set all attributes from sugar.fill and sugar.stroke list
@@ -37,10 +51,10 @@ const sugar = {
return this
}
- registerMethods([ 'Element', 'Runner' ], extension)
+ registerMethods(['Element', 'Runner'], extension)
})
-registerMethods([ 'Element', 'Runner' ], {
+registerMethods(['Element', 'Runner'], {
// Let the user set the matrix directly
matrix: function (mat, b, c, d, e, f) {
// Act as a getter
@@ -61,7 +75,7 @@ registerMethods([ 'Element', 'Runner' ], {
skew: function (x, y, cx, cy) {
return arguments.length === 1 || arguments.length === 3
? this.transform({ skew: x, ox: y, oy: cx }, true)
- : this.transform({ skew: [ x, y ], ox: cx, oy: cy }, true)
+ : this.transform({ skew: [x, y], ox: cx, oy: cy }, true)
},
shear: function (lam, cx, cy) {
@@ -72,17 +86,17 @@ registerMethods([ 'Element', 'Runner' ], {
scale: function (x, y, cx, cy) {
return arguments.length === 1 || arguments.length === 3
? this.transform({ scale: x, ox: y, oy: cx }, true)
- : this.transform({ scale: [ x, y ], ox: cx, oy: cy }, true)
+ : this.transform({ scale: [x, y], ox: cx, oy: cy }, true)
},
// Map translate to transform
translate: function (x, y) {
- return this.transform({ translate: [ x, y ] }, true)
+ return this.transform({ translate: [x, y] }, true)
},
// Map relative translations to transform
relative: function (x, y) {
- return this.transform({ relative: [ x, y ] }, true)
+ return this.transform({ relative: [x, y] }, true)
},
// Map flip to transform
@@ -122,7 +136,7 @@ registerMethods('Path', {
}
})
-registerMethods([ 'Element', 'Runner' ], {
+registerMethods(['Element', 'Runner'], {
// Set font
font: function (a, v) {
if (typeof a === 'object') {
@@ -133,15 +147,21 @@ registerMethods([ 'Element', 'Runner' ], {
return a === 'leading'
? this.leading(v)
: a === 'anchor'
- ? this.attr('text-anchor', v)
- : a === 'size' || a === 'family' || a === 'weight' || a === 'stretch' || a === 'variant' || a === 'style'
- ? this.attr('font-' + a, v)
- : this.attr(a, v)
+ ? this.attr('text-anchor', v)
+ : a === 'size' ||
+ a === 'family' ||
+ a === 'weight' ||
+ a === 'stretch' ||
+ a === 'variant' ||
+ a === 'style'
+ ? this.attr('font-' + a, v)
+ : this.attr(a, v)
}
})
// Add events to elements
-const methods = [ 'click',
+const methods = [
+ 'click',
'dblclick',
'mousedown',
'mouseup',
@@ -154,7 +174,8 @@ const methods = [ 'click',
'touchmove',
'touchleave',
'touchend',
- 'touchcancel' ].reduce(function (last, event) {
+ 'touchcancel'
+].reduce(function (last, event) {
// add event to Element
const fn = function (f) {
if (f === null) {