summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2023-09-03 12:20:46 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2023-09-03 12:20:46 +0200
commite70cdef7a5a21eda34f5f90260f9fd26099d274e (patch)
tree9e86cff57984c7badcde26de8098b7e0607d738f /src
parent9718677bcdec90f5587ef09322428720e4d4b9c9 (diff)
downloadsvg.js-e70cdef7a5a21eda34f5f90260f9fd26099d274e.tar.gz
svg.js-e70cdef7a5a21eda34f5f90260f9fd26099d274e.zip
fix css, dont throw when screenCtm fails (fixes #968)
Diffstat (limited to 'src')
-rw-r--r--src/modules/optional/css.js11
-rw-r--r--src/types/Matrix.js29
-rw-r--r--src/utils/utils.js7
3 files changed, 22 insertions, 25 deletions
diff --git a/src/modules/optional/css.js b/src/modules/optional/css.js
index 49a467b..1c5ed40 100644
--- a/src/modules/optional/css.js
+++ b/src/modules/optional/css.js
@@ -1,9 +1,6 @@
-import { camelCase } from '../../utils/utils.js'
import { isBlank } from '../core/regex.js'
import { registerMethods } from '../../utils/methods.js'
-const camelCaseWithVars = (str) => (str.startsWith('--') ? str : camelCase(str))
-
// Dynamic style generator
export function css(style, val) {
const ret = {}
@@ -25,7 +22,7 @@ export function css(style, val) {
// get style properties as array
if (Array.isArray(style)) {
for (const name of style) {
- const cased = camelCaseWithVars(name)
+ const cased = name
ret[name] = this.node.style.getPropertyValue(cased)
}
return ret
@@ -33,7 +30,7 @@ export function css(style, val) {
// get style for property
if (typeof style === 'string') {
- return this.node.style.getPropertyValue(camelCaseWithVars(style))
+ return this.node.style.getPropertyValue(style)
}
// set styles in object
@@ -41,7 +38,7 @@ export function css(style, val) {
for (const name in style) {
// set empty string if null/undefined/'' was given
this.node.style.setProperty(
- camelCaseWithVars(name),
+ name,
style[name] == null || isBlank.test(style[name]) ? '' : style[name]
)
}
@@ -51,7 +48,7 @@ export function css(style, val) {
// set style for property
if (arguments.length === 2) {
this.node.style.setProperty(
- camelCaseWithVars(style),
+ style,
val == null || isBlank.test(val) ? '' : val
)
}
diff --git a/src/types/Matrix.js b/src/types/Matrix.js
index 760f002..f409a50 100644
--- a/src/types/Matrix.js
+++ b/src/types/Matrix.js
@@ -520,17 +520,24 @@ export function ctm() {
}
export function screenCTM() {
- /* https://bugzilla.mozilla.org/show_bug.cgi?id=1344537
- This is needed because FF does not return the transformation matrix
- for the inner coordinate system when getScreenCTM() is called on nested svgs.
- However all other Browsers do that */
- if (typeof this.isRoot === 'function' && !this.isRoot()) {
- const rect = this.rect(1, 1)
- const m = rect.node.getScreenCTM()
- rect.remove()
- return new Matrix(m)
- }
- return new Matrix(this.node.getScreenCTM())
+ try {
+ /* https://bugzilla.mozilla.org/show_bug.cgi?id=1344537
+ This is needed because FF does not return the transformation matrix
+ for the inner coordinate system when getScreenCTM() is called on nested svgs.
+ However all other Browsers do that */
+ if (typeof this.isRoot === 'function' && !this.isRoot()) {
+ const rect = this.rect(1, 1)
+ const m = rect.node.getScreenCTM()
+ rect.remove()
+ return new Matrix(m)
+ }
+ return new Matrix(this.node.getScreenCTM())
+ } catch (e) {
+ console.warn(
+ `Cannot get CTM from SVG node ${this.node.nodeName}. Is the element rendered?`
+ )
+ return new Matrix()
+ }
}
register(Matrix, 'Matrix')
diff --git a/src/utils/utils.js b/src/utils/utils.js
index 90ef548..edd98b6 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -36,13 +36,6 @@ export function degrees(r) {
return ((r * 180) / Math.PI) % 360
}
-// Convert dash-separated-string to camelCase
-export function camelCase(s) {
- return s.toLowerCase().replace(/-(.)/g, function (m, g) {
- return g.toUpperCase()
- })
-}
-
// Convert camel cased string to dash separated
export function unCamelCase(s) {
return s.replace(/([A-Z])/g, function (m, g) {