aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/core/attr.js8
-rw-r--r--src/modules/core/circled.js28
-rw-r--r--src/modules/core/containerGeometry.js23
-rw-r--r--src/modules/core/defaults.js4
-rw-r--r--src/modules/core/event.js30
-rw-r--r--src/modules/core/gradiented.js4
-rw-r--r--src/modules/core/parser.js2
-rw-r--r--src/modules/core/pointed.js8
-rw-r--r--src/modules/core/poly.js19
-rw-r--r--src/modules/core/regex.js3
-rw-r--r--src/modules/core/selector.js14
-rw-r--r--src/modules/core/textable.js24
-rw-r--r--src/modules/optional/arrange.js24
-rw-r--r--src/modules/optional/class.js27
-rw-r--r--src/modules/optional/css.js24
-rw-r--r--src/modules/optional/data.js19
-rw-r--r--src/modules/optional/memory.js6
-rw-r--r--src/modules/optional/sugar.js55
-rw-r--r--src/modules/optional/transform.js32
19 files changed, 203 insertions, 151 deletions
diff --git a/src/modules/core/attr.js b/src/modules/core/attr.js
index d54b235..a96f706 100644
--- a/src/modules/core/attr.js
+++ b/src/modules/core/attr.js
@@ -5,12 +5,12 @@ import SVGArray from '../../types/SVGArray.js'
import SVGNumber from '../../types/SVGNumber.js'
const hooks = []
-export function registerAttrHook (fn) {
+export function registerAttrHook(fn) {
hooks.push(fn)
}
// Set svg element attribute
-export default function attr (attr, val, ns) {
+export default function attr(attr, val, ns) {
// act as full getter
if (attr == null) {
// get an object of attributes
@@ -42,8 +42,8 @@ export default function attr (attr, val, ns) {
return val == null
? defaults[attr]
: isNumber.test(val)
- ? parseFloat(val)
- : val
+ ? parseFloat(val)
+ : val
} else {
// Loop through hooks and execute them to convert value
val = hooks.reduce((_val, hook) => {
diff --git a/src/modules/core/circled.js b/src/modules/core/circled.js
index a03e29b..3c3a65f 100644
--- a/src/modules/core/circled.js
+++ b/src/modules/core/circled.js
@@ -1,48 +1,42 @@
import SVGNumber from '../../types/SVGNumber.js'
// Radius x value
-export function rx (rx) {
+export function rx(rx) {
return this.attr('rx', rx)
}
// Radius y value
-export function ry (ry) {
+export function ry(ry) {
return this.attr('ry', ry)
}
// Move over x-axis
-export function x (x) {
- return x == null
- ? this.cx() - this.rx()
- : this.cx(x + this.rx())
+export function x(x) {
+ return x == null ? this.cx() - this.rx() : this.cx(x + this.rx())
}
// Move over y-axis
-export function y (y) {
- return y == null
- ? this.cy() - this.ry()
- : this.cy(y + this.ry())
+export function y(y) {
+ return y == null ? this.cy() - this.ry() : this.cy(y + this.ry())
}
// Move by center over x-axis
-export function cx (x) {
+export function cx(x) {
return this.attr('cx', x)
}
// Move by center over y-axis
-export function cy (y) {
+export function cy(y) {
return this.attr('cy', y)
}
// Set width of element
-export function width (width) {
- return width == null
- ? this.rx() * 2
- : this.rx(new SVGNumber(width).divide(2))
+export function width(width) {
+ return width == null ? this.rx() * 2 : this.rx(new SVGNumber(width).divide(2))
}
// Set height of element
-export function height (height) {
+export function height(height) {
return height == null
? this.ry() * 2
: this.ry(new SVGNumber(height).divide(2))
diff --git a/src/modules/core/containerGeometry.js b/src/modules/core/containerGeometry.js
index 908bb27..21139e8 100644
--- a/src/modules/core/containerGeometry.js
+++ b/src/modules/core/containerGeometry.js
@@ -2,9 +2,8 @@ import Matrix from '../../types/Matrix.js'
import Point from '../../types/Point.js'
import { proportionalSize } from '../../utils/utils.js'
-export function dmove (dx, dy) {
- this.children().forEach((child, i) => {
-
+export function dmove(dx, dy) {
+ this.children().forEach((child) => {
let bbox
// We have to wrap this for elements that dont have a bbox
@@ -30,32 +29,32 @@ export function dmove (dx, dy) {
return this
}
-export function dx (dx) {
+export function dx(dx) {
return this.dmove(dx, 0)
}
-export function dy (dy) {
+export function dy(dy) {
return this.dmove(0, dy)
}
-export function height (height, box = this.bbox()) {
+export function height(height, box = this.bbox()) {
if (height == null) return box.height
return this.size(box.width, height, box)
}
-export function move (x = 0, y = 0, box = this.bbox()) {
+export function move(x = 0, y = 0, box = this.bbox()) {
const dx = x - box.x
const dy = y - box.y
return this.dmove(dx, dy)
}
-export function size (width, height, box = this.bbox()) {
+export function size(width, height, box = this.bbox()) {
const p = proportionalSize(this, width, height, box)
const scaleX = p.width / box.width
const scaleY = p.height / box.height
- this.children().forEach((child, i) => {
+ this.children().forEach((child) => {
const o = new Point(box).transform(new Matrix(child).inverse())
child.scale(scaleX, scaleY, o.x, o.y)
})
@@ -63,17 +62,17 @@ export function size (width, height, box = this.bbox()) {
return this
}
-export function width (width, box = this.bbox()) {
+export function width(width, box = this.bbox()) {
if (width == null) return box.width
return this.size(width, box.height, box)
}
-export function x (x, box = this.bbox()) {
+export function x(x, box = this.bbox()) {
if (x == null) return box.x
return this.move(x, box.y, box)
}
-export function y (y, box = this.bbox()) {
+export function y(y, box = this.bbox()) {
if (y == null) return box.y
return this.move(box.x, y, box)
}
diff --git a/src/modules/core/defaults.js b/src/modules/core/defaults.js
index e8e65b6..2c346a7 100644
--- a/src/modules/core/defaults.js
+++ b/src/modules/core/defaults.js
@@ -1,5 +1,4 @@
-
-export function noop () {}
+export function noop() {}
// Default animation values
export const timeline = {
@@ -10,7 +9,6 @@ export const timeline = {
// Default attribute values
export const attrs = {
-
// fill and stroke
'fill-opacity': 1,
'stroke-opacity': 1,
diff --git a/src/modules/core/event.js b/src/modules/core/event.js
index 3594fc4..8e08716 100644
--- a/src/modules/core/event.js
+++ b/src/modules/core/event.js
@@ -5,7 +5,7 @@ import { globals } from '../../utils/window.js'
let listenerId = 0
export const windowEvents = {}
-export function getEvents (instance) {
+export function getEvents(instance) {
let n = instance.getEventHolder()
// We dont want to save events in global space
@@ -14,18 +14,18 @@ export function getEvents (instance) {
return n.events
}
-export function getEventTarget (instance) {
+export function getEventTarget(instance) {
return instance.getEventTarget()
}
-export function clearEvents (instance) {
+export function clearEvents(instance) {
let n = instance.getEventHolder()
if (n === globals.window) n = windowEvents
if (n.events) n.events = {}
}
// Add event binder in the SVG namespace
-export function on (node, events, listener, binding, options) {
+export function on(node, events, listener, binding, options) {
const l = listener.bind(binding || node)
const instance = makeInstance(node)
const bag = getEvents(instance)
@@ -56,7 +56,7 @@ export function on (node, events, listener, binding, options) {
}
// Add event unbinder in the SVG namespace
-export function off (node, events, listener, options) {
+export function off(node, events, listener, options) {
const instance = makeInstance(node)
const bag = getEvents(instance)
const n = getEventTarget(instance)
@@ -79,7 +79,11 @@ export function off (node, events, listener, options) {
// remove listener reference
if (bag[ev] && bag[ev][ns || '*']) {
// removeListener
- n.removeEventListener(ev, bag[ev][ns || '*'][listener], options || false)
+ n.removeEventListener(
+ ev,
+ bag[ev][ns || '*'][listener],
+ options || false
+ )
delete bag[ev][ns || '*'][listener]
}
@@ -87,7 +91,7 @@ export function off (node, events, listener, options) {
// remove all listeners for a namespaced event
if (bag[ev] && bag[ev][ns]) {
for (l in bag[ev][ns]) {
- off(n, [ ev, ns ].join('.'), l)
+ off(n, [ev, ns].join('.'), l)
}
delete bag[ev][ns]
@@ -97,7 +101,7 @@ export function off (node, events, listener, options) {
for (event in bag) {
for (namespace in bag[event]) {
if (ns === namespace) {
- off(n, [ event, ns ].join('.'))
+ off(n, [event, ns].join('.'))
}
}
}
@@ -105,7 +109,7 @@ export function off (node, events, listener, options) {
// remove all listeners for the event
if (bag[ev]) {
for (namespace in bag[ev]) {
- off(n, [ ev, namespace ].join('.'))
+ off(n, [ev, namespace].join('.'))
}
delete bag[ev]
@@ -121,14 +125,18 @@ export function off (node, events, listener, options) {
})
}
-export function dispatch (node, event, data, options) {
+export function dispatch(node, event, data, options) {
const n = getEventTarget(node)
// Dispatch event
if (event instanceof globals.window.Event) {
n.dispatchEvent(event)
} else {
- event = new globals.window.CustomEvent(event, { detail: data, cancelable: true, ...options })
+ event = new globals.window.CustomEvent(event, {
+ detail: data,
+ cancelable: true,
+ ...options
+ })
n.dispatchEvent(event)
}
return event
diff --git a/src/modules/core/gradiented.js b/src/modules/core/gradiented.js
index 6c744e4..cd0a512 100644
--- a/src/modules/core/gradiented.js
+++ b/src/modules/core/gradiented.js
@@ -1,12 +1,12 @@
import SVGNumber from '../../types/SVGNumber.js'
-export function from (x, y) {
+export function from(x, y) {
return (this._element || this).type === 'radialGradient'
? this.attr({ fx: new SVGNumber(x), fy: new SVGNumber(y) })
: this.attr({ x1: new SVGNumber(x), y1: new SVGNumber(y) })
}
-export function to (x, y) {
+export function to(x, y) {
return (this._element || this).type === 'radialGradient'
? this.attr({ cx: new SVGNumber(x), cy: new SVGNumber(y) })
: this.attr({ x2: new SVGNumber(x), y2: new SVGNumber(y) })
diff --git a/src/modules/core/parser.js b/src/modules/core/parser.js
index 4f92657..fc48c3b 100644
--- a/src/modules/core/parser.js
+++ b/src/modules/core/parser.js
@@ -1,7 +1,7 @@
import { globals } from '../../utils/window.js'
import { makeInstance } from '../../utils/adopter.js'
-export default function parser () {
+export default function parser() {
// Reuse cached element if possible
if (!parser.nodes) {
const svg = makeInstance().size(2, 0)
diff --git a/src/modules/core/pointed.js b/src/modules/core/pointed.js
index 540e5f8..0d4ef7a 100644
--- a/src/modules/core/pointed.js
+++ b/src/modules/core/pointed.js
@@ -3,23 +3,23 @@ import PointArray from '../../types/PointArray.js'
export const MorphArray = PointArray
// Move by left top corner over x-axis
-export function x (x) {
+export function x(x) {
return x == null ? this.bbox().x : this.move(x, this.bbox().y)
}
// Move by left top corner over y-axis
-export function y (y) {
+export function y(y) {
return y == null ? this.bbox().y : this.move(this.bbox().x, y)
}
// Set width of element
-export function width (width) {
+export function width(width) {
const b = this.bbox()
return width == null ? b.width : this.size(width, b.height)
}
// Set height of element
-export function height (height) {
+export function height(height) {
const b = this.bbox()
return height == null ? b.height : this.size(b.width, height)
}
diff --git a/src/modules/core/poly.js b/src/modules/core/poly.js
index d422028..0640735 100644
--- a/src/modules/core/poly.js
+++ b/src/modules/core/poly.js
@@ -2,32 +2,33 @@ import { proportionalSize } from '../../utils/utils.js'
import PointArray from '../../types/PointArray.js'
// Get array
-export function array () {
+export function array() {
return this._array || (this._array = new PointArray(this.attr('points')))
}
// Clear array cache
-export function clear () {
+export function clear() {
delete this._array
return this
}
// Move by left top corner
-export function move (x, y) {
+export function move(x, y) {
return this.attr('points', this.array().move(x, y))
}
// Plot new path
-export function plot (p) {
- return (p == null)
+export function plot(p) {
+ return p == null
? this.array()
- : this.clear().attr('points', typeof p === 'string'
- ? p
- : (this._array = new PointArray(p)))
+ : this.clear().attr(
+ 'points',
+ typeof p === 'string' ? p : (this._array = new PointArray(p))
+ )
}
// Set element size to given width and height
-export function size (width, height) {
+export function size(width, height) {
const p = proportionalSize(this, width, height)
return this.attr('points', this.array().size(p.width, p.height))
}
diff --git a/src/modules/core/regex.js b/src/modules/core/regex.js
index a18c692..03d1fa3 100644
--- a/src/modules/core/regex.js
+++ b/src/modules/core/regex.js
@@ -1,5 +1,6 @@
// Parse unit value
-export const numberAndUnit = /^([+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)([a-z%]*)$/i
+export const numberAndUnit =
+ /^([+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)([a-z%]*)$/i
// Parse hex value
export const hex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i
diff --git a/src/modules/core/selector.js b/src/modules/core/selector.js
index 1667d4d..7dec4e4 100644
--- a/src/modules/core/selector.js
+++ b/src/modules/core/selector.js
@@ -3,17 +3,19 @@ import { globals } from '../../utils/window.js'
import { map } from '../../utils/utils.js'
import List from '../../types/List.js'
-export default function baseFind (query, parent) {
- return new List(map((parent || globals.document).querySelectorAll(query), function (node) {
- return adopt(node)
- }))
+export default function baseFind(query, parent) {
+ return new List(
+ map((parent || globals.document).querySelectorAll(query), function (node) {
+ return adopt(node)
+ })
+ )
}
// Scoped find method
-export function find (query) {
+export function find(query) {
return baseFind(query, this.node)
}
-export function findOne (query) {
+export function findOne(query) {
return adopt(this.node.querySelector(query))
}
diff --git a/src/modules/core/textable.js b/src/modules/core/textable.js
index 28b13cb..44a1ee5 100644
--- a/src/modules/core/textable.js
+++ b/src/modules/core/textable.js
@@ -1,7 +1,7 @@
import { globals } from '../../utils/window.js'
// Create plain text node
-export function plain (text) {
+export function plain(text) {
// clear if build mode is disabled
if (this._build === false) {
this.clear()
@@ -14,14 +14,14 @@ export function plain (text) {
}
// Get length of text element
-export function length () {
+export function length() {
return this.node.getComputedTextLength()
}
// Move over x-axis
// Text is moved by its bounding box
// text-anchor does NOT matter
-export function x (x, box = this.bbox()) {
+export function x(x, box = this.bbox()) {
if (x == null) {
return box.x
}
@@ -30,7 +30,7 @@ export function x (x, box = this.bbox()) {
}
// Move over y-axis
-export function y (y, box = this.bbox()) {
+export function y(y, box = this.bbox()) {
if (y == null) {
return box.y
}
@@ -38,12 +38,12 @@ export function y (y, box = this.bbox()) {
return this.attr('y', this.attr('y') + y - box.y)
}
-export function move (x, y, box = this.bbox()) {
+export function move(x, y, box = this.bbox()) {
return this.x(x, box).y(y, box)
}
// Move center over x-axis
-export function cx (x, box = this.bbox()) {
+export function cx(x, box = this.bbox()) {
if (x == null) {
return box.cx
}
@@ -52,7 +52,7 @@ export function cx (x, box = this.bbox()) {
}
// Move center over y-axis
-export function cy (y, box = this.bbox()) {
+export function cy(y, box = this.bbox()) {
if (y == null) {
return box.cy
}
@@ -60,24 +60,24 @@ export function cy (y, box = this.bbox()) {
return this.attr('y', this.attr('y') + y - box.cy)
}
-export function center (x, y, box = this.bbox()) {
+export function center(x, y, box = this.bbox()) {
return this.cx(x, box).cy(y, box)
}
-export function ax (x) {
+export function ax(x) {
return this.attr('x', x)
}
-export function ay (y) {
+export function ay(y) {
return this.attr('y', y)
}
-export function amove (x, y) {
+export function amove(x, y) {
return this.ax(x).ay(y)
}
// Enable / disable build mode
-export function build (build) {
+export function build(build) {
this._build = !!build
return this
}
diff --git a/src/modules/optional/arrange.js b/src/modules/optional/arrange.js
index 9aaeef1..292cd79 100644
--- a/src/modules/optional/arrange.js
+++ b/src/modules/optional/arrange.js
@@ -2,27 +2,27 @@ import { makeInstance } from '../../utils/adopter.js'
import { registerMethods } from '../../utils/methods.js'
// Get all siblings, including myself
-export function siblings () {
+export function siblings() {
return this.parent().children()
}
// Get the current position siblings
-export function position () {
+export function position() {
return this.parent().index(this)
}
// Get the next element (will return null if there is none)
-export function next () {
+export function next() {
return this.siblings()[this.position() + 1]
}
// Get the next element (will return null if there is none)
-export function prev () {
+export function prev() {
return this.siblings()[this.position() - 1]
}
// Send given element one step forward
-export function forward () {
+export function forward() {
const i = this.position()
const p = this.parent()
@@ -33,7 +33,7 @@ export function forward () {
}
// Send given element one step backward
-export function backward () {
+export function backward() {
const i = this.position()
const p = this.parent()
@@ -43,7 +43,7 @@ export function backward () {
}
// Send given element all the way to the front
-export function front () {
+export function front() {
const p = this.parent()
// Move node forward
@@ -53,7 +53,7 @@ export function front () {
}
// Send given element all the way to the back
-export function back () {
+export function back() {
const p = this.parent()
// Move node back
@@ -63,7 +63,7 @@ export function back () {
}
// Inserts a given element before the targeted element
-export function before (element) {
+export function before(element) {
element = makeInstance(element)
element.remove()
@@ -75,7 +75,7 @@ export function before (element) {
}
// Inserts a given element after the targeted element
-export function after (element) {
+export function after(element) {
element = makeInstance(element)
element.remove()
@@ -86,13 +86,13 @@ export function after (element) {
return this
}
-export function insertBefore (element) {
+export function insertBefore(element) {
element = makeInstance(element)
element.before(this)
return this
}
-export function insertAfter (element) {
+export function insertAfter(element) {
element = makeInstance(element)
element.after(this)
return this
diff --git a/src/modules/optional/class.js b/src/modules/optional/class.js
index 4e544be..3141644 100644
--- a/src/modules/optional/class.js
+++ b/src/modules/optional/class.js
@@ -2,18 +2,18 @@ import { delimiter } from '../core/regex.js'
import { registerMethods } from '../../utils/methods.js'
// Return array of classes on the node
-export function classes () {
+export function classes() {
const attr = this.attr('class')
return attr == null ? [] : attr.trim().split(delimiter)
}
// Return true if class exists on the node, false otherwise
-export function hasClass (name) {
+export function hasClass(name) {
return this.classes().indexOf(name) !== -1
}
// Add class to the node
-export function addClass (name) {
+export function addClass(name) {
if (!this.hasClass(name)) {
const array = this.classes()
array.push(name)
@@ -24,21 +24,30 @@ export function addClass (name) {
}
// Remove class from the node
-export function removeClass (name) {
+export function removeClass(name) {
if (this.hasClass(name)) {
- this.attr('class', this.classes().filter(function (c) {
- return c !== name
- }).join(' '))
+ this.attr(
+ 'class',
+ this.classes()
+ .filter(function (c) {
+ return c !== name
+ })
+ .join(' ')
+ )
}
return this
}
// Toggle the presence of a class on the node
-export function toggleClass (name) {
+export function toggleClass(name) {
return this.hasClass(name) ? this.removeClass(name) : this.addClass(name)
}
registerMethods('Dom', {
- classes, hasClass, addClass, removeClass, toggleClass
+ classes,
+ hasClass,
+ addClass,
+ removeClass,
+ toggleClass
})
diff --git a/src/modules/optional/css.js b/src/modules/optional/css.js
index ee93869..92f8c21 100644
--- a/src/modules/optional/css.js
+++ b/src/modules/optional/css.js
@@ -3,11 +3,12 @@ import { isBlank } from '../core/regex.js'
import { registerMethods } from '../../utils/methods.js'
// Dynamic style generator
-export function css (style, val) {
+export function css(style, val) {
const ret = {}
if (arguments.length === 0) {
// get full style as object
- this.node.style.cssText.split(/\s*;\s*/)
+ this.node.style.cssText
+ .split(/\s*;\s*/)
.filter(function (el) {
return !!el.length
})
@@ -37,36 +38,39 @@ export function css (style, val) {
if (typeof style === 'object') {
for (const name in style) {
// set empty string if null/undefined/'' was given
- this.node.style[camelCase(name)]
- = (style[name] == null || isBlank.test(style[name])) ? '' : style[name]
+ this.node.style[camelCase(name)] =
+ style[name] == null || isBlank.test(style[name]) ? '' : style[name]
}
}
}
// set style for property
if (arguments.length === 2) {
- this.node.style[camelCase(style)]
- = (val == null || isBlank.test(val)) ? '' : val
+ this.node.style[camelCase(style)] =
+ val == null || isBlank.test(val) ? '' : val
}
return this
}
// Show element
-export function show () {
+export function show() {
return this.css('display', '')
}
// Hide element
-export function hide () {
+export function hide() {
return this.css('display', 'none')
}
// Is element visible?
-export function visible () {
+export function visible() {
return this.css('display') !== 'none'
}
registerMethods('Dom', {
- css, show, hide, visible
+ css,
+ show,
+ hide,
+ visible
})
diff --git a/src/modules/optional/data.js b/src/modules/optional/data.js
index 00bb8ea..9655048 100644
--- a/src/modules/optional/data.js
+++ b/src/modules/optional/data.js
@@ -2,10 +2,18 @@ import { registerMethods } from '../../utils/methods.js'
import { filter, map } from '../../utils/utils.js'
// Store data values on svg nodes
-export function data (a, v, r) {
+export function data(a, v, r) {
if (a == null) {
// get an object of attributes
- return this.data(map(filter(this.node.attributes, (el) => el.nodeName.indexOf('data-') === 0), (el) => el.nodeName.slice(5)))
+ return this.data(
+ map(
+ filter(
+ this.node.attributes,
+ (el) => el.nodeName.indexOf('data-') === 0
+ ),
+ (el) => el.nodeName.slice(5)
+ )
+ )
} else if (a instanceof Array) {
const data = {}
for (const key of a) {
@@ -23,12 +31,13 @@ export function data (a, v, r) {
return this.attr('data-' + a)
}
} else {
- this.attr('data-' + a,
+ this.attr(
+ 'data-' + a,
v === null
? null
: r === true || typeof v === 'string' || typeof v === 'number'
- ? v
- : JSON.stringify(v)
+ ? v
+ : JSON.stringify(v)
)
}
diff --git a/src/modules/optional/memory.js b/src/modules/optional/memory.js
index 459dcf1..31058c3 100644
--- a/src/modules/optional/memory.js
+++ b/src/modules/optional/memory.js
@@ -1,7 +1,7 @@
import { registerMethods } from '../../utils/methods.js'
// Remember arbitrary data
-export function remember (k, v) {
+export function remember(k, v) {
// remember every item in an object individually
if (typeof arguments[0] === 'object') {
for (const key in k) {
@@ -19,7 +19,7 @@ export function remember (k, v) {
}
// Erase a given memory
-export function forget () {
+export function forget() {
if (arguments.length === 0) {
this._memory = {}
} else {
@@ -33,7 +33,7 @@ export function forget () {
// This triggers creation of a new hidden class which is not performant
// However, this function is not rarely used so it will not happen frequently
// Return local memory object
-export function memory () {
+export function memory() {
return (this._memory = this._memory || {})
}
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) {
diff --git a/src/modules/optional/transform.js b/src/modules/optional/transform.js
index d8e7381..7f950b3 100644
--- a/src/modules/optional/transform.js
+++ b/src/modules/optional/transform.js
@@ -4,22 +4,24 @@ import { registerMethods } from '../../utils/methods.js'
import Matrix from '../../types/Matrix.js'
// Reset all transformations
-export function untransform () {
+export function untransform() {
return this.attr('transform', null)
}
// merge the whole transformation chain into one matrix and returns it
-export function matrixify () {
+export function matrixify() {
const matrix = (this.attr('transform') || '')
// split transformations
- .split(transforms).slice(0, -1).map(function (str) {
+ .split(transforms)
+ .slice(0, -1)
+ .map(function (str) {
// generate key => value pairs
const kv = str.trim().split('(')
- return [ kv[0],
- kv[1].split(delimiter)
- .map(function (str) {
- return parseFloat(str)
- })
+ return [
+ kv[0],
+ kv[1].split(delimiter).map(function (str) {
+ return parseFloat(str)
+ })
]
})
.reverse()
@@ -35,7 +37,7 @@ export function matrixify () {
}
// add an element to another parent without changing the visual representation on the screen
-export function toParent (parent, i) {
+export function toParent(parent, i) {
if (this === parent) return this
const ctm = this.screenCTM()
const pCtm = parent.screenCTM().inverse()
@@ -46,12 +48,12 @@ export function toParent (parent, i) {
}
// same as above with parent equals root-svg
-export function toRoot (i) {
+export function toRoot(i) {
return this.toParent(this.root(), i)
}
// Add transformations
-export function transform (o, relative) {
+export function transform(o, relative) {
// Act as a getter if no object was passed
if (o == null || typeof o === 'string') {
const decomposed = new Matrix(this).decompose()
@@ -64,11 +66,15 @@ export function transform (o, relative) {
}
// The user can pass a boolean, an Element or an Matrix or nothing
- const cleanRelative = relative === true ? this : (relative || false)
+ const cleanRelative = relative === true ? this : relative || false
const result = new Matrix(cleanRelative).transform(o)
return this.attr('transform', result)
}
registerMethods('Element', {
- untransform, matrixify, toParent, toRoot, transform
+ untransform,
+ matrixify,
+ toParent,
+ toRoot,
+ transform
})