summaryrefslogtreecommitdiffstats
path: root/src/elements
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-08 10:05:28 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-08 10:05:28 +0100
commit4702522137dac17a6312c521f3c1974eb839c5eb (patch)
tree97c158c2c4e8005d3e56e037eab16dfffcf3da42 /src/elements
parentdec70426b32ccf3979046e1637174b66bfdd1a8d (diff)
downloadsvg.js-4702522137dac17a6312c521f3c1974eb839c5eb.tar.gz
svg.js-4702522137dac17a6312c521f3c1974eb839c5eb.zip
added insertAfter/Before, introduce attrHooks, move few methods, SVG.Text.textPath returns first textPath child now
Diffstat (limited to 'src/elements')
-rw-r--r--src/elements/Image.js21
-rw-r--r--src/elements/TextPath.js17
2 files changed, 27 insertions, 11 deletions
diff --git a/src/elements/Image.js b/src/elements/Image.js
index 5e672f4..ec9459f 100644
--- a/src/elements/Image.js
+++ b/src/elements/Image.js
@@ -1,5 +1,7 @@
+import { isImage } from '../modules/core/regex.js'
import { nodeOrNew, register } from '../utils/adopter.js'
import { off, on } from '../modules/core/event.js'
+import { registerAttrHook } from '../modules/core/attr.js'
import { registerMethods } from '../utils/methods.js'
import { xlink } from '../modules/core/namespaces.js'
import Pattern from './Pattern.js'
@@ -48,13 +50,24 @@ export default class Image extends Shape {
return this.attr('href', (img.src = url), xlink)
}
+}
+
+registerAttrHook(function (attr, val, _this) {
+ // convert image fill and stroke to patterns
+ if (attr === 'fill' || attr === 'stroke') {
+ if (isImage.test(val)) {
+ val = _this.doc().defs().image(val)
+ }
+ }
- attrHook (obj) {
- return obj.doc().defs().pattern(0, 0, (pattern) => {
- pattern.add(this)
+ if (val instanceof Image) {
+ val = _this.doc().defs().pattern(0, 0, (pattern) => {
+ pattern.add(val)
})
}
-}
+
+ return val
+})
registerMethods({
Container: {
diff --git a/src/elements/TextPath.js b/src/elements/TextPath.js
index 04146bc..480eca2 100644
--- a/src/elements/TextPath.js
+++ b/src/elements/TextPath.js
@@ -1,6 +1,7 @@
import { nodeOrNew, register } from '../utils/adopter.js'
import { registerMethods } from '../utils/methods.js'
import { xlink } from '../modules/core/namespaces.js'
+import baseFind from '../modules/core/selector.js'
import Path from './Path.js'
import PathArray from '../types/PathArray.js'
import Text from './Text.js'
@@ -44,10 +45,10 @@ registerMethods({
},
Text: {
// Create path for text to run on
- path: function (track) {
+ path (track) {
var path = new TextPath()
- // if d is a path, reuse it
+ // if track is a path, reuse it
if (!(track instanceof Path)) {
// create path element
track = this.doc().defs().path(track)
@@ -60,22 +61,24 @@ registerMethods({
return this.put(path)
},
- // FIXME: make this plural?
// Get the textPath children
- textPath: function () {
- return this.find('textPath')
+ textPath () {
+ return this.find('textPath')[0]
}
},
Path: {
// creates a textPath from this path
- text: function (text) {
+ text (text) {
if (text instanceof Text) {
var txt = text.text()
return text.clear().path(this).text(txt)
}
return this.parent().put(new Text()).path(this).text(text)
+ },
+
+ targets () {
+ return baseFind('svg [href*="' + this.id() + '"]')
}
- // FIXME: Maybe add `targets` to get all textPaths associated with this path
}
})