From a594363fceefa276520e29ea6e8729e4b5abdd3a Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 24 Sep 2020 15:44:53 -0500 Subject: [PATCH 1/2] Add ElemmentCSSInlineStyle This is a mixin for HTMLElement and others from CSSOM to add the style attribute. --- src/Web/CSSOM/ElementCSSInlineStyle.js | 7 +++++++ src/Web/CSSOM/ElementCSSInlineStyle.purs | 16 ++++++++++++++++ src/Web/CSSOM/Internal/Types.purs | 2 ++ 3 files changed, 25 insertions(+) create mode 100644 src/Web/CSSOM/ElementCSSInlineStyle.js create mode 100644 src/Web/CSSOM/ElementCSSInlineStyle.purs diff --git a/src/Web/CSSOM/ElementCSSInlineStyle.js b/src/Web/CSSOM/ElementCSSInlineStyle.js new file mode 100644 index 0000000..c4f0a4d --- /dev/null +++ b/src/Web/CSSOM/ElementCSSInlineStyle.js @@ -0,0 +1,7 @@ +"use strict"; + +exports.style = function(el) { + return function() { + return el.style; + }; +}; diff --git a/src/Web/CSSOM/ElementCSSInlineStyle.purs b/src/Web/CSSOM/ElementCSSInlineStyle.purs new file mode 100644 index 0000000..59af769 --- /dev/null +++ b/src/Web/CSSOM/ElementCSSInlineStyle.purs @@ -0,0 +1,16 @@ +module Web.CSSOM.ElementCSSInlineStyle + ( module Exports + , style + , fromHTMLElement + ) where + +import Effect (Effect) +import Unsafe.Coerce (unsafeCoerce) +import Web.CSSOM.Internal.Types (ElementCSSInlineStyle) as Exports +import Web.CSSOM.Internal.Types (ElementCSSInlineStyle, CSSStyleDeclaration) +import Web.HTML.HTMLElement (HTMLElement) + +foreign import style :: ElementCSSInlineStyle -> Effect CSSStyleDeclaration + +fromHTMLElement :: HTMLElement -> ElementCSSInlineStyle +fromHTMLElement = unsafeCoerce diff --git a/src/Web/CSSOM/Internal/Types.purs b/src/Web/CSSOM/Internal/Types.purs index 8f97417..1bfc112 100644 --- a/src/Web/CSSOM/Internal/Types.purs +++ b/src/Web/CSSOM/Internal/Types.purs @@ -1,4 +1,6 @@ module Web.CSSOM.Internal.Types where +foreign import data CSSStyleDeclaration :: Type foreign import data CSSStyleSheet :: Type +foreign import data ElementCSSInlineStyle :: Type foreign import data StyleSheetList :: Type From 1df8cd13d0f55280286526ef7c28878369eb380a Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 24 Sep 2020 16:04:16 -0500 Subject: [PATCH 2/2] Add CSSSTyleDeclaration Adds all needed methods. There are also named properties for every CSS property, but those are redundant with getPropertyValue / setProperty. --- src/Web/CSSOM/CSSStyleDeclaration.js | 55 ++++++++++++++++++++++++++ src/Web/CSSOM/CSSStyleDeclaration.purs | 22 +++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/Web/CSSOM/CSSStyleDeclaration.js create mode 100644 src/Web/CSSOM/CSSStyleDeclaration.purs diff --git a/src/Web/CSSOM/CSSStyleDeclaration.js b/src/Web/CSSOM/CSSStyleDeclaration.js new file mode 100644 index 0000000..c43b49b --- /dev/null +++ b/src/Web/CSSOM/CSSStyleDeclaration.js @@ -0,0 +1,55 @@ +"use strict"; + +exports.cssText = function(style) { + return function() { + return style.cssText; + }; +}; + +exports.setCssText = function(style) { + return function(newCSS) { + return function() { + style.cssText = newCSS; + }; + }; +}; + +exports.length = function(style) { + return function() { + return style.length; + }; +}; + +exports.getPropertyPriority = function(style) { + return function(propName) { + return function() { + return style.getPropertyPriority(propName); + }; + }; +}; + +exports.getPropertyValue = function(style) { + return function(propName) { + return function() { + return style.getPropertyValue(propName); + }; + }; +}; + +exports.removeProperty = function(style) { + return function(propName) { + return function() { + style.removeProperty(propName); + }; + }; +}; + +exports.setProperty = function(style) { + return function(propName) { + return function(propValue) { + return function() { + style.setProperty(propName, propValue); + }; + }; + }; +}; diff --git a/src/Web/CSSOM/CSSStyleDeclaration.purs b/src/Web/CSSOM/CSSStyleDeclaration.purs new file mode 100644 index 0000000..f0bd516 --- /dev/null +++ b/src/Web/CSSOM/CSSStyleDeclaration.purs @@ -0,0 +1,22 @@ +module Web.CSSOM.CSSStyleDeclaration + ( module Exports + , length + , getPropertyPriority + , getPropertyValue + , removeProperty + , setProperty + ) where + +import Prelude +import Effect (Effect) +import Web.CSSOM.Internal.Types (CSSStyleDeclaration) as Exports +import Web.CSSOM.Internal.Types (CSSStyleDeclaration) + +foreign import cssText :: CSSStyleDeclaration -> Effect String +foreign import setCssText :: CSSStyleDeclaration -> String -> Effect Unit +foreign import length :: CSSStyleDeclaration -> Effect Number + +foreign import getPropertyPriority :: CSSStyleDeclaration -> String -> Effect String +foreign import getPropertyValue :: CSSStyleDeclaration -> String -> Effect String +foreign import removeProperty :: CSSStyleDeclaration -> String -> Effect Unit +foreign import setProperty :: CSSStyleDeclaration -> String -> String -> Effect Unit