diff --git a/src/Web/HTML/HTMLImageElement.js b/src/Web/HTML/HTMLImageElement.js index ef9c36b..1c80158 100644 --- a/src/Web/HTML/HTMLImageElement.js +++ b/src/Web/HTML/HTMLImageElement.js @@ -49,22 +49,56 @@ exports.setSrc = function (src) { // ---------------------------------------------------------------------------- -exports.crossOrigin = function (image) { +exports.srcset = function (image) { return function () { - return image.crossOrigin; + return image.srcset; }; }; -exports.setCrossOrigin = function (crossOrigin) { +exports.setSrcset = function (srcset) { return function (image) { return function () { - image.crossOrigin = crossOrigin; + image.srcset = srcset; }; }; }; // ---------------------------------------------------------------------------- +exports.sizes = function (image) { + return function () { + return image.sizes; + }; +}; + +exports.setSizes = function (sizes) { + return function (image) { + return function () { + image.sizes = sizes; + }; + }; +}; + +// ---------------------------------------------------------------------------- + +exports.currentSrc = function (image) { + return function () { + return image.currentSrc; + }; +}; + +// ---------------------------------------------------------------------------- + +exports._crossOrigin = function (image) { + return image.crossOrigin; +}; + +exports._setCrossOrigin = function (crossOrigin, image) { + image.crossOrigin = crossOrigin; +}; + +// ---------------------------------------------------------------------------- + exports.useMap = function (image) { return function () { return image.useMap; @@ -143,6 +177,43 @@ exports.naturalHeight = function (image) { // ---------------------------------------------------------------------------- +exports.referrerPolicy = function (image) { + return function () { + return image.referrerPolicy; + }; +}; + +exports.setReferrerPolicy = function (referrerPolicy) { + return function (image) { + return function () { + image.referrerPolicy = referrerPolicy; + }; + }; +}; + + +// ---------------------------------------------------------------------------- + +exports._decoding = function (image) { + return image.decoding; +}; + +exports._setDecoding = function (decoding, image) { + image.decoding = decoding; +}; + +// ---------------------------------------------------------------------------- + +exports._loading = function (image) { + return image.loading; +}; + +exports._setLoading = function (loading, image) { + image.loading = loading; +}; + +// ---------------------------------------------------------------------------- + exports.complete = function (image) { return function () { return image.complete; diff --git a/src/Web/HTML/HTMLImageElement.purs b/src/Web/HTML/HTMLImageElement.purs index 1b330d2..c049d4a 100644 --- a/src/Web/HTML/HTMLImageElement.purs +++ b/src/Web/HTML/HTMLImageElement.purs @@ -20,6 +20,11 @@ module Web.HTML.HTMLImageElement , setAlt , src , setSrc + , srcset + , setSrcset + , currentSrc + , sizes + , setSizes , crossOrigin , setCrossOrigin , useMap @@ -32,16 +37,31 @@ module Web.HTML.HTMLImageElement , setHeight , naturalWidth , naturalHeight + , referrerPolicy + , setReferrerPolicy + , decoding + , setDecoding + , loading + , setLoading , complete ) where -import Data.Maybe (Maybe) +import Data.Nullable (Nullable) +import Data.Nullable as Nullable +import Data.Maybe (Maybe, fromMaybe) import Effect (Effect) -import Prelude (Unit) +import Effect.Uncurried (EffectFn1, EffectFn2, runEffectFn1, runEffectFn2) +import Prelude (Unit, map, (<<<), (<=<)) import Unsafe.Coerce (unsafeCoerce) import Web.DOM (ChildNode, Element, Node, NonDocumentTypeChildNode, ParentNode) import Web.Event.EventTarget (EventTarget) import Web.HTML.HTMLElement (HTMLElement) +import Web.HTML.HTMLImageElement.CORSMode (CORSMode) +import Web.HTML.HTMLImageElement.CORSMode as CORSMode +import Web.HTML.HTMLImageElement.DecodingHint (DecodingHint) +import Web.HTML.HTMLImageElement.DecodingHint as DecodingHint +import Web.HTML.HTMLImageElement.Laziness (Laziness) +import Web.HTML.HTMLImageElement.Laziness as Laziness import Web.Internal.FFI (unsafeReadProtoTagged) foreign import data HTMLImageElement :: Type @@ -101,8 +121,23 @@ foreign import setAlt :: String -> HTMLImageElement -> Effect Unit foreign import src :: HTMLImageElement -> Effect String foreign import setSrc :: String -> HTMLImageElement -> Effect Unit -foreign import crossOrigin :: HTMLImageElement -> Effect String -foreign import setCrossOrigin :: String -> HTMLImageElement -> Effect Unit +foreign import srcset :: HTMLImageElement -> Effect String +foreign import setSrcset :: String -> HTMLImageElement -> Effect Unit + +foreign import currentSrc :: HTMLImageElement -> Effect String + +foreign import sizes :: HTMLImageElement -> Effect String +foreign import setSizes :: String -> HTMLImageElement -> Effect Unit + +foreign import _crossOrigin :: EffectFn1 HTMLImageElement (Nullable String) + +crossOrigin :: HTMLImageElement -> Effect (Maybe CORSMode) +crossOrigin = map (CORSMode.parse <=< Nullable.toMaybe) <<< runEffectFn1 _crossOrigin + +foreign import _setCrossOrigin :: EffectFn2 String HTMLImageElement Unit + +setCrossOrigin :: CORSMode -> HTMLImageElement -> Effect Unit +setCrossOrigin mode = runEffectFn2 _setCrossOrigin (CORSMode.print mode) foreign import useMap :: HTMLImageElement -> Effect String foreign import setUseMap :: String -> HTMLImageElement -> Effect Unit @@ -118,4 +153,28 @@ foreign import setHeight :: Int -> HTMLImageElement -> Effect Unit foreign import naturalWidth :: HTMLImageElement -> Effect Int foreign import naturalHeight :: HTMLImageElement -> Effect Int + +foreign import referrerPolicy :: HTMLImageElement -> Effect String +foreign import setReferrerPolicy :: String -> HTMLImageElement -> Effect Unit + +foreign import _decoding :: EffectFn1 HTMLImageElement String + +decoding :: HTMLImageElement -> Effect DecodingHint +decoding = map (fromMaybe DecodingHint.Auto <<< DecodingHint.parse) <<< runEffectFn1 _decoding + +foreign import _setDecoding :: EffectFn2 String HTMLImageElement Unit + +setDecoding :: DecodingHint -> HTMLImageElement -> Effect Unit +setDecoding hint = runEffectFn2 _setDecoding (DecodingHint.print hint) + +foreign import _loading :: EffectFn1 HTMLImageElement String + +loading :: HTMLImageElement -> Effect Laziness +loading = map (fromMaybe Laziness.Eager <<< Laziness.parse) <<< runEffectFn1 _loading + +foreign import _setLoading :: EffectFn2 String HTMLImageElement Unit + +setLoading :: Laziness -> HTMLImageElement -> Effect Unit +setLoading laziness = runEffectFn2 _setLoading (Laziness.print laziness) + foreign import complete :: HTMLImageElement -> Effect Boolean diff --git a/src/Web/HTML/HTMLImageElement/CORSMode.purs b/src/Web/HTML/HTMLImageElement/CORSMode.purs new file mode 100644 index 0000000..a6ae4d7 --- /dev/null +++ b/src/Web/HTML/HTMLImageElement/CORSMode.purs @@ -0,0 +1,32 @@ +module Web.HTML.HTMLImageElement.CORSMode + ( CORSMode(..) + , parse + , print + ) where + +import Data.Maybe (Maybe(..)) +import Prelude (class Eq, class Ord, class Show) + +data CORSMode + = Anonymous + | UseCredentials + +derive instance eqCORSMode :: Eq CORSMode +derive instance ordCORSMode :: Ord CORSMode + +instance showDecodingHint :: Show CORSMode where + show = case _ of + Anonymous -> "Anonymous" + UseCredentials -> "UseCredentials" + +parse :: String -> Maybe CORSMode +parse = case _ of + "" -> Just Anonymous + "anonymous" -> Just Anonymous + "use-credentials" -> Just UseCredentials + _ -> Nothing + +print :: CORSMode -> String +print = case _ of + Anonymous -> "anonymous" + UseCredentials -> "use-credentials" diff --git a/src/Web/HTML/HTMLImageElement/DecodingHint.purs b/src/Web/HTML/HTMLImageElement/DecodingHint.purs new file mode 100644 index 0000000..f7f9b85 --- /dev/null +++ b/src/Web/HTML/HTMLImageElement/DecodingHint.purs @@ -0,0 +1,36 @@ +module Web.HTML.HTMLImageElement.DecodingHint + ( DecodingHint(..) + , parse + , print + ) where + +import Data.Maybe (Maybe(..)) +import Prelude (class Eq, class Ord, class Show) + +data DecodingHint + = Sync + | Async + | Auto + +derive instance eqDecodingHint :: Eq DecodingHint +derive instance ordDecodingHint :: Ord DecodingHint + +instance showDecodingHint :: Show DecodingHint where + show = case _ of + Sync -> "Sync" + Async -> "Async" + Auto -> "Auto" + +parse :: String -> Maybe DecodingHint +parse = case _ of + "" -> Just Auto + "sync" -> Just Sync + "async" -> Just Async + "auto" -> Just Auto + _ -> Nothing + +print :: DecodingHint -> String +print = case _ of + Sync -> "sync" + Async -> "async" + Auto -> "auto" diff --git a/src/Web/HTML/HTMLImageElement/Laziness.purs b/src/Web/HTML/HTMLImageElement/Laziness.purs new file mode 100644 index 0000000..bb8b1a5 --- /dev/null +++ b/src/Web/HTML/HTMLImageElement/Laziness.purs @@ -0,0 +1,33 @@ +module Web.HTML.HTMLImageElement.Laziness + ( Laziness(..) + , parse + , print + ) where + +import Data.Maybe (Maybe(..)) +import Prelude (class Eq, class Ord, class Show) + +data Laziness + = Eager + | Lazy + +derive instance eqDecodingHint :: Eq Laziness +derive instance ordDecodingHint :: Ord Laziness + +instance showDecodingHint :: Show Laziness where + show = case _ of + Eager -> "Eager" + Lazy -> "Lazy" + +parse :: String -> Maybe Laziness +parse = case _ of + "" -> Just Eager + "eager" -> Just Eager + "lazy" -> Just Lazy + _ -> Nothing + + +print :: Laziness -> String +print = case _ of + Eager -> "eager" + Lazy -> "lazy"
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: