1
- module Web.CSSOMView.Element where
1
+ module Web.CSSOMView.Element
2
+ ( clientHeight
3
+ , clientLeft
4
+ , clientTop
5
+ , clientWidth
6
+ , getBoundingClientRect
7
+ , getClientRects
8
+ , scroll
9
+ , scrollBy
10
+ , scrollHeight
11
+ , scrollIntoView
12
+ , scrollLeft
13
+ , scrollTo
14
+ , scrollTop
15
+ , scrollWidth
16
+ )
17
+ where
2
18
3
- import Prelude ( Unit )
19
+ import Data.Maybe ( Maybe (..) )
4
20
import Effect (Effect )
5
- import Data.Maybe (Maybe )
21
+ import Prelude (Unit )
22
+ import Web.CSSOMView (ScrollBehavior (..), ScrollIntoViewOptions , ScrollLogicalPosition (..), ScrollToOptions )
6
23
import Web.DOM.Element (Element )
7
24
import Web.Geometry (DOMRectList , DOMRect )
8
- import Web.CSSOMView (ScrollIntoViewOptions , ScrollToOptions )
9
25
10
26
foreign import getClientRects :: Element -> Effect DOMRectList
11
27
foreign import getBoundingClientRect :: Element -> Effect DOMRect
12
- foreign import scrollIntoView :: Maybe ScrollIntoViewOptions -> Element -> Effect Unit
13
- foreign import scroll :: Maybe ScrollToOptions -> Element -> Effect Unit
14
- foreign import scrollTo :: Maybe ScrollToOptions -> Element -> Effect Unit
15
- foreign import scrollBy :: Maybe ScrollToOptions -> Element -> Effect Unit
28
+ foreign import _scrollIntoView :: PrimitiveScrollIntoViewOptions -> Element -> Effect Unit
29
+ foreign import _scroll :: PrimitiveScrollToOptions -> Element -> Effect Unit
30
+ foreign import _scrollTo :: PrimitiveScrollToOptions -> Element -> Effect Unit
31
+ foreign import _scrollBy :: PrimitiveScrollToOptions -> Element -> Effect Unit
16
32
foreign import scrollTop :: Element -> Effect Number
17
33
foreign import scrollLeft :: Element -> Effect Number
18
34
foreign import scrollWidth :: Element -> Effect Int
@@ -21,3 +37,51 @@ foreign import clientTop :: Element -> Effect Int
21
37
foreign import clientLeft :: Element -> Effect Int
22
38
foreign import clientWidth :: Element -> Effect Int
23
39
foreign import clientHeight :: Element -> Effect Int
40
+
41
+ scrollIntoView :: Maybe ScrollIntoViewOptions -> Element -> Effect Unit
42
+ scrollIntoView scrollIntoViewOptions = _scrollIntoView (primitiveScrollIntoViewOptions scrollIntoViewOptions)
43
+ scroll :: Maybe ScrollToOptions -> Element -> Effect Unit
44
+ scroll scrollToOptions = _scroll (primitiveScrollToOptions scrollToOptions)
45
+ scrollTo :: Maybe ScrollToOptions -> Element -> Effect Unit
46
+ scrollTo scrollToOptions = _scrollTo (primitiveScrollToOptions scrollToOptions)
47
+ scrollBy :: Maybe ScrollToOptions -> Element -> Effect Unit
48
+ scrollBy scrollToOptions = _scrollBy (primitiveScrollToOptions scrollToOptions)
49
+
50
+ type PrimitiveScrollToOptions =
51
+ { left :: Number
52
+ , top :: Number
53
+ , behavior :: String
54
+ }
55
+
56
+ primitiveBehavior :: ScrollBehavior -> String
57
+ primitiveBehavior Auto = " auto"
58
+ primitiveBehavior Instant = " instant"
59
+ primitiveBehavior Smooth = " smooth"
60
+
61
+ primitiveScrollToOptions :: Maybe ScrollToOptions -> PrimitiveScrollToOptions
62
+ primitiveScrollToOptions Nothing = { left: 0.0 , top: 0.0 , behavior: " auto" }
63
+ primitiveScrollToOptions (Just scrollToOptions) =
64
+ { left: scrollToOptions.left
65
+ , top: scrollToOptions.top
66
+ , behavior: primitiveBehavior scrollToOptions.behavior
67
+ }
68
+
69
+ type PrimitiveScrollIntoViewOptions =
70
+ { block :: String
71
+ , inline :: String
72
+ , behavior :: String
73
+ }
74
+
75
+ primitiveScrollLogicalPosition :: ScrollLogicalPosition -> String
76
+ primitiveScrollLogicalPosition Start = " start"
77
+ primitiveScrollLogicalPosition Center = " center"
78
+ primitiveScrollLogicalPosition End = " end"
79
+ primitiveScrollLogicalPosition Nearest = " nearest"
80
+
81
+ primitiveScrollIntoViewOptions :: Maybe ScrollIntoViewOptions -> PrimitiveScrollIntoViewOptions
82
+ primitiveScrollIntoViewOptions Nothing = { block: " start" , inline: " nearest" , behavior: " auto" }
83
+ primitiveScrollIntoViewOptions (Just scrollIntoViewOptions) =
84
+ { block: primitiveScrollLogicalPosition scrollIntoViewOptions.block
85
+ , inline: primitiveScrollLogicalPosition scrollIntoViewOptions.inline
86
+ , behavior: primitiveBehavior scrollIntoViewOptions.behavior
87
+ }
0 commit comments