Skip to content

Commit 878dd8d

Browse files
committed
adts for some attrs + sizes exports
1 parent d3f263e commit 878dd8d

File tree

4 files changed

+99
-26
lines changed

4 files changed

+99
-26
lines changed

src/Web/HTML/HTMLImageElement.js

+8-20
Original file line numberDiff line numberDiff line change
@@ -200,34 +200,22 @@ exports.setReferrerPolicy = function (referrerPolicy) {
200200

201201
// ----------------------------------------------------------------------------
202202

203-
exports.decoding = function (image) {
204-
return function () {
205-
return image.decoding;
206-
};
203+
exports.decodingImpl = function (image) {
204+
return image.decoding;
207205
};
208206

209-
exports.setDecoding = function (decoding) {
210-
return function (image) {
211-
return function () {
212-
image.decoding = decoding;
213-
};
214-
};
207+
exports.setDecodingImpl = function (decoding, image) {
208+
image.decoding = decoding;
215209
};
216210

217211
// ----------------------------------------------------------------------------
218212

219-
exports.loading = function (image) {
220-
return function () {
221-
return image.loading;
222-
};
213+
exports.loadingImpl = function (image) {
214+
return image.loading;
223215
};
224216

225-
exports.setLoading = function (loading) {
226-
return function (image) {
227-
return function () {
228-
image.loading = loading;
229-
};
230-
};
217+
exports.setLoadingImpl = function (loading, image) {
218+
image.loading = loading;
231219
};
232220

233221
// ----------------------------------------------------------------------------

src/Web/HTML/HTMLImageElement.purs

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Web.HTML.HTMLImageElement
22
( HTMLImageElement
3+
, DecodingHint(..)
34
, fromHTMLElement
45
, fromElement
56
, fromNode
@@ -23,6 +24,8 @@ module Web.HTML.HTMLImageElement
2324
, srcset
2425
, setSrcset
2526
, currentSrc
27+
, sizes
28+
, setSizes
2629
, crossOrigin
2730
, setCrossOrigin
2831
, useMap
@@ -44,13 +47,16 @@ module Web.HTML.HTMLImageElement
4447
, complete
4548
) where
4649

47-
import Data.Maybe (Maybe)
50+
import Data.Maybe (Maybe, fromMaybe)
4851
import Effect (Effect)
49-
import Prelude (Unit)
52+
import Effect.Uncurried (EffectFn1, EffectFn2, runEffectFn1, runEffectFn2)
53+
import Prelude (Unit, map, (<<<))
5054
import Unsafe.Coerce (unsafeCoerce)
5155
import Web.DOM (ChildNode, Element, Node, NonDocumentTypeChildNode, ParentNode)
5256
import Web.Event.EventTarget (EventTarget)
5357
import Web.HTML.HTMLElement (HTMLElement)
58+
import Web.HTML.HTMLImageElement.DecodingHint (DecodingHint)
59+
import Web.HTML.HTMLImageElement.DecodingHint as DecodingHint
5460
import Web.Internal.FFI (unsafeReadProtoTagged)
5561

5662
foreign import data HTMLImageElement :: Type
@@ -139,10 +145,24 @@ foreign import naturalHeight :: HTMLImageElement -> Effect Int
139145
foreign import referrerPolicy :: HTMLImageElement -> Effect String
140146
foreign import setReferrerPolicy :: String -> HTMLImageElement -> Effect Unit
141147

142-
foreign import decoding :: HTMLImageElement -> Effect String
143-
foreign import setDecoding :: String -> HTMLImageElement -> Effect Unit
148+
foreign import decodingImpl :: EffectFn1 HTMLImageElement DecodingHint
144149

145-
foreign import loading :: HTMLImageElement -> Effect String
146-
foreign import setLoading :: String -> HTMLImageElement -> Effect Unit
150+
decoding :: HTMLImageElement -> Effect DecodingHint
151+
decoding = map (fromMaybe DecodingHint.Auto <<< DecodingHint.parse) (runEffectFn1 decodingImpl)
152+
153+
foreign import setDecodingImpl :: EffectFn2 String HTMLImageElement Unit
154+
155+
setDecoding :: DecodingHint -> HTMLImageElement -> Effect Unit
156+
setDecoding hint = runEffectFn2 setDecodingImpl (DecodingHint.print hint)
157+
158+
foreign import loadingImpl :: EffectFn1 HTMLImageElement String
159+
160+
loading :: HTMLImageElement -> Effect Laziness
161+
loading = map (fromMaybe Laziness.Eager <<< Laziness.parse) (runEffectFn1 loadingImpl)
162+
163+
foreign import setLoading :: EffectFn2 String HTMLImageElement Unit
164+
165+
setLoading :: Laziness -> HTMLImageElement -> Effect Unit
166+
setLoading laziness = runEffectFn2 setDecodingImpl (Laziness.print laziness)
147167

148168
foreign import complete :: HTMLImageElement -> Effect Boolean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Web.HTML.HTMLImageElement.DecodingHint
2+
( DecodingHint(..)
3+
, parse
4+
, print
5+
) where
6+
7+
data DecodingHint
8+
= Sync
9+
| Async
10+
| Auto
11+
12+
derive instance eqDecodingHint :: Eq DecodingHint
13+
derive instance ordDecodingHint :: Ord DecodingHint
14+
15+
instance showDecodingHint :: Show DecodingHint where
16+
show = case _ of
17+
Sync -> "Sync"
18+
Async -> "Async"
19+
Auto -> "Auto"
20+
21+
parse :: String -> Maybe DecodingHint
22+
parse = case _ of
23+
"" -> Just Auto
24+
"sync" -> Just Sync
25+
"async" -> Just Async
26+
"auto" -> Just Auto
27+
_ -> Nothing
28+
29+
print :: DecodingHint -> String
30+
print = case _ of
31+
Sync -> "sync"
32+
Async -> "async"
33+
Auto -> "auto"
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Web.HTML.HTMLImageElement.Laziness
2+
( Laziness(..)
3+
, parse
4+
, print
5+
) where
6+
7+
data Laziness
8+
= Eager
9+
| Lazy
10+
11+
derive instance eqDecodingHint :: Eq Laziness
12+
derive instance ordDecodingHint :: Ord Laziness
13+
14+
instance showDecodingHint :: Show Laziness where
15+
show = case _ of
16+
Eager -> "Eager"
17+
Lazy -> "Lazy"
18+
19+
parse :: String -> Maybe Laziness
20+
parse = case _ of
21+
"" -> Just Eager
22+
"eager" -> Just Eager
23+
"lazy" -> Just Lazy
24+
_ -> Nothing
25+
26+
27+
print :: Laziness -> String
28+
print = case _ of
29+
Eager -> "eager"
30+
Lazy -> "lazy"
31+

0 commit comments

Comments
 (0)