aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/core')
-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
12 files changed, 85 insertions, 82 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
}