Skip to content

Commit 7d7f498

Browse files
committed
adts for some attrs + sizes exports
1 parent d3f263e commit 7d7f498

File tree

5 files changed

+150
-38
lines changed

5 files changed

+150
-38
lines changed

src/Web/HTML/HTMLImageElement.js

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,12 @@ exports.currentSrc = function (image) {
8989

9090
// ----------------------------------------------------------------------------
9191

92-
exports.crossOrigin = function (image) {
93-
return function () {
94-
return image.crossOrigin;
95-
};
92+
exports.crossOriginImpl = function (image) {
93+
return image.crossOrigin;
9694
};
9795

98-
exports.setCrossOrigin = function (crossOrigin) {
99-
return function (image) {
100-
return function () {
101-
image.crossOrigin = crossOrigin;
102-
};
103-
};
96+
exports.setCrossOrigin = function (crossOrigin, image) {
97+
image.crossOrigin = crossOrigin;
10498
};
10599

106100
// ----------------------------------------------------------------------------
@@ -200,34 +194,22 @@ exports.setReferrerPolicy = function (referrerPolicy) {
200194

201195
// ----------------------------------------------------------------------------
202196

203-
exports.decoding = function (image) {
204-
return function () {
205-
return image.decoding;
206-
};
197+
exports.decodingImpl = function (image) {
198+
return image.decoding;
207199
};
208200

209-
exports.setDecoding = function (decoding) {
210-
return function (image) {
211-
return function () {
212-
image.decoding = decoding;
213-
};
214-
};
201+
exports.setDecodingImpl = function (decoding, image) {
202+
image.decoding = decoding;
215203
};
216204

217205
// ----------------------------------------------------------------------------
218206

219-
exports.loading = function (image) {
220-
return function () {
221-
return image.loading;
222-
};
207+
exports.loadingImpl = function (image) {
208+
return image.loading;
223209
};
224210

225-
exports.setLoading = function (loading) {
226-
return function (image) {
227-
return function () {
228-
image.loading = loading;
229-
};
230-
};
211+
exports.setLoadingImpl = function (loading, image) {
212+
image.loading = loading;
231213
};
232214

233215
// ----------------------------------------------------------------------------

src/Web/HTML/HTMLImageElement.purs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module Web.HTML.HTMLImageElement
22
( HTMLImageElement
3+
, CORSMode(..)
4+
, DecodingHint(..)
5+
, Laziness(..)
36
, fromHTMLElement
47
, fromElement
58
, fromNode
@@ -23,6 +26,8 @@ module Web.HTML.HTMLImageElement
2326
, srcset
2427
, setSrcset
2528
, currentSrc
29+
, sizes
30+
, setSizes
2631
, crossOrigin
2732
, setCrossOrigin
2833
, useMap
@@ -44,13 +49,22 @@ module Web.HTML.HTMLImageElement
4449
, complete
4550
) where
4651

47-
import Data.Maybe (Maybe)
52+
import Data.Nullable (Nullable)
53+
import Data.Nullable as Nullable
54+
import Data.Maybe (Maybe, fromMaybe)
4855
import Effect (Effect)
49-
import Prelude (Unit)
56+
import Effect.Uncurried (EffectFn1, EffectFn2, runEffectFn1, runEffectFn2)
57+
import Prelude (Unit, map, (<<<), (<=<))
5058
import Unsafe.Coerce (unsafeCoerce)
5159
import Web.DOM (ChildNode, Element, Node, NonDocumentTypeChildNode, ParentNode)
5260
import Web.Event.EventTarget (EventTarget)
5361
import Web.HTML.HTMLElement (HTMLElement)
62+
import Web.HTML.HTMLImageElement.CORSMode (CORSMode)
63+
import Web.HTML.HTMLImageElement.CORSMode as CORSMode
64+
import Web.HTML.HTMLImageElement.DecodingHint (DecodingHint)
65+
import Web.HTML.HTMLImageElement.DecodingHint as DecodingHint
66+
import Web.HTML.HTMLImageElement.Laziness (Laziness)
67+
import Web.HTML.HTMLImageElement.Laziness as Laziness
5468
import Web.Internal.FFI (unsafeReadProtoTagged)
5569

5670
foreign import data HTMLImageElement :: Type
@@ -118,8 +132,15 @@ foreign import currentSrc :: HTMLImageElement -> Effect String
118132
foreign import sizes :: HTMLImageElement -> Effect String
119133
foreign import setSizes :: String -> HTMLImageElement -> Effect Unit
120134

121-
foreign import crossOrigin :: HTMLImageElement -> Effect String
122-
foreign import setCrossOrigin :: String -> HTMLImageElement -> Effect Unit
135+
foreign import crossOriginImpl :: EffectFn1 HTMLImageElement (Nullable String)
136+
137+
crossOrigin :: HTMLImageElement -> Effect (Maybe CORSMode)
138+
crossOrigin = map (CORSMode.parse <=< Nullable.toMaybe) (runEffectFn1 crossOriginImpl)
139+
140+
foreign import setCrossOriginImpl :: EffectFn2 String HTMLImageElement Unit
141+
142+
setCrossOrigin :: CORSMode -> HTMLImageElement -> Effect Unit
143+
setCrossOrigin mode = runEffectFn2 setCrossOriginImpl (CORSMode.print mode)
123144

124145
foreign import useMap :: HTMLImageElement -> Effect String
125146
foreign import setUseMap :: String -> HTMLImageElement -> Effect Unit
@@ -139,10 +160,24 @@ foreign import naturalHeight :: HTMLImageElement -> Effect Int
139160
foreign import referrerPolicy :: HTMLImageElement -> Effect String
140161
foreign import setReferrerPolicy :: String -> HTMLImageElement -> Effect Unit
141162

142-
foreign import decoding :: HTMLImageElement -> Effect String
143-
foreign import setDecoding :: String -> HTMLImageElement -> Effect Unit
163+
foreign import decodingImpl :: EffectFn1 HTMLImageElement DecodingHint
164+
165+
decoding :: HTMLImageElement -> Effect DecodingHint
166+
decoding = map (fromMaybe DecodingHint.Auto <<< DecodingHint.parse) (runEffectFn1 decodingImpl)
167+
168+
foreign import setDecodingImpl :: EffectFn2 String HTMLImageElement Unit
169+
170+
setDecoding :: DecodingHint -> HTMLImageElement -> Effect Unit
171+
setDecoding hint = runEffectFn2 setDecodingImpl (DecodingHint.print hint)
172+
173+
foreign import loadingImpl :: EffectFn1 HTMLImageElement String
174+
175+
loading :: HTMLImageElement -> Effect Laziness
176+
loading = map (fromMaybe Laziness.Eager <<< Laziness.parse) (runEffectFn1 loadingImpl)
177+
178+
foreign import setLoadingImpl :: EffectFn2 String HTMLImageElement Unit
144179

145-
foreign import loading :: HTMLImageElement -> Effect String
146-
foreign import setLoading :: String -> HTMLImageElement -> Effect Unit
180+
setLoading :: Laziness -> HTMLImageElement -> Effect Unit
181+
setLoading laziness = runEffectFn2 setLoadingImpl (Laziness.print laziness)
147182

148183
foreign import complete :: HTMLImageElement -> Effect Boolean
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module Web.HTML.HTMLImageElement.CORSMode
2+
( CORSMode(..)
3+
, parse
4+
, print
5+
) where
6+
7+
data CORSMode
8+
= Anonymous
9+
| UseCredentials
10+
11+
derive instance eqCORSMode :: Eq CORSMode
12+
derive instance ordCORSMode :: Ord CORSMode
13+
14+
instance showDecodingHint :: Show CORSMode where
15+
show = case _ of
16+
Anonymous -> "Anonymous"
17+
UseCredentials -> "UseCredentials"
18+
19+
parse :: String -> Maybe CORSMode
20+
parse = case _ of
21+
"" -> Just Anonymous
22+
"anonymous" -> Just Anonymous
23+
"use-credentials" -> Just UseCredentials
24+
_ -> Nothing
25+
26+
print :: CORSMode -> String
27+
print = case _ of
28+
Anonymous -> "anonymous"
29+
UseCredentials -> "use-credentials"
30+
Lines changed: 34 additions & 0 deletions
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+
Lines changed: 31 additions & 0 deletions
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)