aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/optional/transform.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2023-06-13 01:43:37 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2023-06-13 01:43:37 +0200
commit03322672782a6318b019eff33fe44ec800d6f12c (patch)
tree9d807e1585cf28a1ea98e87b855932dba00f1880 /src/modules/optional/transform.js
parent8e18b4698edd00f83af0be05bb3374f92fecaeb9 (diff)
downloadsvg.js-03322672782a6318b019eff33fe44ec800d6f12c.tar.gz
svg.js-03322672782a6318b019eff33fe44ec800d6f12c.zip
dependency updates, easier formatting
Diffstat (limited to 'src/modules/optional/transform.js')
-rw-r--r--src/modules/optional/transform.js32
1 files changed, 19 insertions, 13 deletions
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
})