Permalink
Browse files

Improved targetting and

  • Loading branch information...
nvh committed Jan 16, 2018
1 parent e80c465 commit efbc233d9f8d1ef781d098016456949ed85c416e
Showing with 28 additions and 18 deletions.
  1. +15 −11 framer/SVG.coffee
  2. +6 −2 framer/SVGBaseLayer.coffee
  3. +7 −5 framer/SVGPath.coffee
View
@@ -38,28 +38,32 @@ class exports.SVG
if elements?
for element in elements
isTarget = element.id?
name = element.getAttribute("name")
if not name?
if element instanceof SVGGElement
defsResult = @constructSVGElements(root, element.childNodes, PathClass, GroupClass)
_.extend targets, defsResult.targets
children = children.concat(defsResult.children)
continue
continue
options = {}
options.name = element.id if isTarget
options.name = name
options.parent = root
if element instanceof SVGGElement
group = new GroupClass(element, options)
children.push(group)
_.extend(targets, group.elements)
if isTarget then targets[element.id] = group
if element.id? and element.id isnt ""
targets[element.id] = group
continue
if element instanceof SVGPathElement
if element instanceof SVGPathElement or element instanceof SVGUseElement
path = new PathClass(element, options)
children.push(path)
if isTarget then targets[element.id] = path
continue
if element instanceof SVGDefsElement
defsResult = @constructSVGElements(root, element.childNodes, PathClass, GroupClass)
_.extend targets, defsResult.targets
children = children.concat(defsResult.children)
if path._path.id? and path._path.id isnt ""
id = path._path.id
targets[id] = path
continue
return {targets, children}
@@ -72,17 +72,21 @@ class exports.SVGBaseLayer extends Layer
delete options.parent
delete options.element
pathProperties = ["fill", "stroke", "stroke-width", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-dasharray", "stroke-dashoffset"]
pathProperties = ["fill", "stroke", "stroke-width", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-dasharray", "stroke-dashoffset", "name"]
_.defaults options, @constructor.attributesFromElement(pathProperties, element)
super(options)
rect = @_element.getBoundingClientRect()
@_width = rect.width * @context.pixelMultiplier
@_height = rect.height * @context.pixelMultiplier
for parent in @ancestors()
if parent instanceof SVGLayer
@_svg = parent.svg
break
for prop in ["frame", "stroke", "strokeWidth", "strokeLinecap", "strokeLinejoin", "strokeMiterlimit", "strokeDasharray", "strokeDashoffset", "rotation"]
for prop in ["frame", "stroke", "strokeWidth", "strokeLinecap", "strokeLinejoin", "strokeMiterlimit", "strokeDasharray", "strokeDashoffset", "rotation", "scale"]
@on "change:#{prop}", @resetViewbox
@define "gradient",
View
@@ -22,10 +22,12 @@ class exports.SVGPath extends SVGBaseLayer
options.element = path
super(options)
@_length = @_element.getTotalLength()
rect = @_element.getBoundingClientRect()
@_width = rect.width
@_height = rect.height
if path instanceof SVGPathElement
@_path = path
else if path instanceof SVGUseElement
link = path.getAttribute("xlink:href").replace("#", '')
@_path = @_svg.getElementById(link)
@_length = @_path.getTotalLength()
# Custom properties
@define "fill", layerProperty(@, "fill", "fill", null, SVG.validFill, SVG.toFill)
@@ -50,7 +52,7 @@ class exports.SVGPath extends SVGBaseLayer
@define "end", get: -> @pointAtFraction(1)
pointAtFraction: (fraction) ->
@_element.getPointAtLength(@length * fraction)
@_path.getPointAtLength(@length * fraction)
valueUpdater: (axis, target, offset) =>
switch axis

0 comments on commit efbc233

Please sign in to comment.