Skip to content

Commit

Permalink
Improved targetting and
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Jan 16, 2018
1 parent e80c465 commit efbc233
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
26 changes: 15 additions & 11 deletions framer/SVG.coffee
Expand Up @@ -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}

Expand Down
8 changes: 6 additions & 2 deletions framer/SVGBaseLayer.coffee
Expand Up @@ -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",
Expand Down
12 changes: 7 additions & 5 deletions framer/SVGPath.coffee
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit efbc233

Please sign in to comment.