Permalink
Browse files

Fixed perspective property for Layer

  • Loading branch information...
nvh committed Jul 14, 2017
1 parent 60674ee commit 32da80b89e3dcc45735db4cc9966cadc552b1bc0
Showing with 51 additions and 13 deletions.
  1. +2 −11 framer/Context.coffee
  2. +1 −1 framer/Layer.coffee
  3. +5 −1 framer/LayerStyle.coffee
  4. +8 −0 framer/Utils.coffee
  5. +35 −0 test/tests/LayerTest.coffee
View
@@ -31,15 +31,6 @@ these at any time.
###
webkitPerspectiveForValue = (value) ->
if value in ["none", null, 0]
return "none"
else if _.isNumber(value)
return value
else
return null
Contexts = []
class exports.Context extends BaseClass
@@ -302,7 +293,7 @@ class exports.Context extends BaseClass
@_element = document.createElement("div")
@_element.id = "FramerContextRoot-#{@_name}"
@_element.classList.add("framerContext")
webkitPerspective = webkitPerspectiveForValue(@perspective)
webkitPerspective = Utils.webkitPerspectiveForValue(@perspective)
if webkitPerspective?
@_element.style["webkitPerspective"] = webkitPerspective
@_element.style["backgroundColor"] = @backgroundColor
@@ -377,7 +368,7 @@ class exports.Context extends BaseClass
get: ->
return @_perspective
set: (value) ->
webkitPerspective = webkitPerspectiveForValue(value)
webkitPerspective = Utils.webkitPerspectiveForValue(value)
if webkitPerspective?
@_perspective = value
@_element?.style["webkitPerspective"] = webkitPerspective
View
@@ -308,7 +308,7 @@ class exports.Layer extends BaseClass
@define "originY", layerProperty(@, "originY", "webkitTransformOrigin", 0.5, _.isNumber)
@define "originZ", layerProperty(@, "originZ", null, 0, _.isNumber)
@define "perspective", layerProperty(@, "perspective", "webkitPerspective", 0, _.isNumber)
@define "perspective", layerProperty(@, "perspective", "webkitPerspective", 0, ((v) -> Utils.webkitPerspectiveForValue(v) isnt null))
@define "perspectiveOriginX", layerProperty(@, "perspectiveOriginX", "webkitPerspectiveOrigin", 0.5, _.isNumber)
@define "perspectiveOriginY", layerProperty(@, "perspectiveOriginY", "webkitPerspectiveOrigin", 0.5, _.isNumber)
View
@@ -152,7 +152,11 @@ exports.LayerStyle =
"#{layer._properties.originX * 100}% #{layer._properties.originY * 100}%"
webkitPerspective: (layer) ->
"#{layer._properties.perspective * Framer.CurrentContext.pixelMultiplier}"
value = Utils.webkitPerspectiveForValue(layer._properties.perspective) ? ""
if _.isNumber(value)
return "#{value * Framer.CurrentContext.pixelMultiplier}"
else
return value
webkitPerspectiveOrigin: (layer) ->
"#{layer._properties.perspectiveOriginX * 100}% #{layer._properties.perspectiveOriginY * 100}%"
View
@@ -51,6 +51,14 @@ Utils.arrayNext = (arr, item) ->
Utils.arrayPrev = (arr, item) ->
arr[arr.indexOf(item) - 1] or _.last arr
Utils.webkitPerspectiveForValue = (value) ->
if value in ["none", null, 0]
return "none"
else if _.isNumber(value)
return value
else
return null
######################################################
# MATH
@@ -462,6 +462,41 @@ describe "Layer", ->
layer.style["-webkit-perspective"].should.equal("500")
it "should have a default perspective of 0", ->
layer = new Layer
layer._element.style["webkitPerspective"].should.equal "none"
layer.perspective.should.equal 0
it "should allow the perspective to be changed", ->
layer = new Layer
layer.perspective = 800
layer.perspective.should.equal 800
layer._element.style["webkitPerspective"].should.equal "800"
it "should set the perspective to 'none' if set to 0", ->
layer = new Layer
layer.perspective = 0
layer.perspective.should.equal 0
layer._element.style["webkitPerspective"].should.equal "none"
it "should set the perspective to 'none' if set to none", ->
layer = new Layer
layer.perspective = "none"
layer.perspective.should.equal "none"
layer._element.style["webkitPerspective"].should.equal "none"
it "should set the perspective to 'none' if set to null", ->
layer = new Layer
layer.perspective = null
layer.perspective.should.equal 0
layer._element.style["webkitPerspective"].should.equal "none"
it "should not allow setting the perspective to random string", ->
layer = new Layer
(-> layer.perspective = "bla").should.throw("Layer.perspective: value 'bla' of type 'string' is not valid")
layer.perspective.should.equal 0
layer._element.style["webkitPerspective"].should.equal "none"
it "should have its backface visible by default", ->
layer = new Layer

0 comments on commit 32da80b

Please sign in to comment.