Skip to content

Commit 3f1ee78

Browse files
committed
init
0 parents  commit 3f1ee78

21 files changed

+529
-0
lines changed

.eslintrc.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 5
4+
},
5+
"extends": "eslint:recommended",
6+
"env": {
7+
"commonjs": true,
8+
"browser": true
9+
},
10+
"rules": {
11+
"strict": [2, "global"],
12+
"block-scoped-var": 2,
13+
"consistent-return": 2,
14+
"eqeqeq": [2, "smart"],
15+
"guard-for-in": 2,
16+
"no-caller": 2,
17+
"no-extend-native": 2,
18+
"no-loop-func": 2,
19+
"no-new": 2,
20+
"no-param-reassign": 2,
21+
"no-return-assign": 2,
22+
"no-unused-expressions": 2,
23+
"no-use-before-define": 2,
24+
"radix": [2, "always"],
25+
"indent": [2, 2],
26+
"quotes": [2, "double"],
27+
"semi": [2, "always"]
28+
}
29+
}

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.pulp-cache
2+
/bower_components
3+
/node_modules
4+
/output
5+
/generated-docs

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 PureScript
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# purescript-web-cssom-view
2+
3+
Type definitions and low level interface implementations for the [W3C CSSOM View Module](https://www.w3.org/TR/cssom-view-1).
4+
5+
## Installation
6+
7+
```
8+
bower install purescript-web-cssom-view
9+
```
10+
11+
## Documentation
12+
13+
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-web-cssom-view).

bower.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "purescript-web-cssom-view",
3+
"homepage": "https://github.com/keijokapp/purescript-web-cssom-view",
4+
"license": "MIT",
5+
"repository": {
6+
"type": "git",
7+
"url": "git://github.com/keijokapp/purescript-web-cssom-view.git"
8+
},
9+
"ignore": [
10+
"**/.*",
11+
"bower_components",
12+
"node_modules",
13+
"output",
14+
"bower.json",
15+
"package.json"
16+
],
17+
"dependencies": {
18+
"purescript-web-events": "^2.0.1",
19+
"purescript-web-html": "^2.3.0",
20+
"purescript-web-geometry": "https://github.com/keijokapp/purescript-web-geometry.git"
21+
}
22+
}

package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "eslint src && pulp build -- --censor-lib --strict"
6+
},
7+
"devDependencies": {
8+
"eslint": "^6.0.1",
9+
"pulp": "^13.0.0",
10+
"purescript-psa": "^0.7.3",
11+
"rimraf": "^2.6.2"
12+
}
13+
}

src/Web/CSSOMView.purs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Web.CSSOMView (module CSSOMView, ScrollBehavior(..), ScrollToOptions,
2+
ScrollLogicalPosition(..), ScrollIntoViewOptions) where
3+
4+
import Web.CSSOMView.MediaQueryList (MediaQueryList) as CSSOMView
5+
import Web.CSSOMView.MediaQueryListEvent (MediaQueryListEvent) as CSSOMView
6+
import Web.CSSOMView.Screen (Screen) as CSSOMView
7+
8+
data ScrollBehavior = Auto | Smooth
9+
10+
type ScrollToOptions =
11+
{ left :: Number
12+
, top :: Number
13+
, behaviour :: ScrollBehavior
14+
}
15+
16+
data ScrollLogicalPosition = Start | Center | End | Nearest
17+
18+
type ScrollIntoViewOptions =
19+
{ block :: ScrollLogicalPosition
20+
, inline :: ScrollLogicalPosition
21+
, behavior :: ScrollBehavior
22+
}

src/Web/CSSOMView/Element.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"use strict";
2+
3+
function convertScrollToOptions(options) {
4+
return options.value0 && Object.assign({}, options.value0, { behavior: options.value0.constructor.name.toLowerCase() });
5+
}
6+
7+
exports.getClientRects = function (element) {
8+
return function () {
9+
return element.getClientRects();
10+
};
11+
};
12+
13+
exports.getBoundingClientRect = function (element) {
14+
return function () {
15+
return element.getBoundingClientRect();
16+
};
17+
};
18+
19+
exports.scrollIntoView = function (element) {
20+
return function (scrollIntoViewOptions) {
21+
return function () {
22+
if (scrollIntoViewOptions.value0) {
23+
element.scrollIntoView({
24+
block: scrollIntoViewOptions.value0.block.constructor.name.toLowerCase(),
25+
inline: scrollIntoViewOptions.value0.inline.constructor.name.toLowerCase()
26+
});
27+
} else {
28+
element.scrollIntoView();
29+
}
30+
};
31+
};
32+
};
33+
34+
exports.scroll = function (element) {
35+
return function (scrollToOptions) {
36+
return function () {
37+
element.scrollIntoView(convertScrollToOptions(scrollToOptions));
38+
};
39+
};
40+
};
41+
42+
exports.scrollTo = function (element) {
43+
return function (scrollToOptions) {
44+
return function () {
45+
element.scrollTo(convertScrollToOptions(scrollToOptions));
46+
};
47+
};
48+
};
49+
50+
exports.scrollBy = function (element) {
51+
return function (scrollToOptions) {
52+
return function () {
53+
element.scrollBy(convertScrollToOptions(scrollToOptions));
54+
};
55+
};
56+
};
57+
58+
function getter(property) {
59+
return function (element) {
60+
return function () {
61+
return element[property];
62+
};
63+
};
64+
}
65+
66+
exports.scrollTop = getter("scrollTop");
67+
exports.scrollLeft = getter("scrollLeft");
68+
exports.scrollWidth = getter("scrollWidth");
69+
exports.scrollHeight = getter("scrollHeight");
70+
exports.clientTop = getter("clientTop");
71+
exports.clientLeft = getter("clientLeft");
72+
exports.clientWidth = getter("clientWidth");
73+
exports.clientHeight = getter("clientHeight");

src/Web/CSSOMView/Element.purs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Web.CSSOMView.Element where
2+
3+
import Prelude (Unit)
4+
import Effect (Effect)
5+
import Data.Maybe (Maybe)
6+
import Web.DOM.Element (Element)
7+
import Web.Geometry (DOMRectList, DOMRect)
8+
import Web.CSSOMView (ScrollIntoViewOptions, ScrollToOptions)
9+
10+
foreign import getClientRects :: Element -> Effect DOMRectList
11+
foreign import getBoundingClientRect :: Element -> Effect DOMRect
12+
foreign import scrollIntoView :: Element -> Maybe ScrollIntoViewOptions -> Effect Unit
13+
foreign import scroll :: Element -> Maybe ScrollToOptions -> Effect Unit
14+
foreign import scrollTo :: Element -> Maybe ScrollToOptions -> Effect Unit
15+
foreign import scrollBy :: Element -> Maybe ScrollToOptions -> Effect Unit
16+
foreign import scrollTop :: Element -> Effect Number
17+
foreign import scrollLeft :: Element -> Effect Number
18+
foreign import scrollWidth :: Element -> Effect Int
19+
foreign import scrollHeight :: Element -> Effect Int
20+
foreign import clientTop :: Element -> Effect Int
21+
foreign import clientLeft :: Element -> Effect Int
22+
foreign import clientWidth :: Element -> Effect Int
23+
foreign import clientHeight :: Element -> Effect Int

src/Web/CSSOMView/HTMLElement.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
3+
function getter(property) {
4+
return function (element) {
5+
return function () {
6+
return element[property];
7+
};
8+
};
9+
}
10+
11+
exports._offsetParent = getter("offsetParent");
12+
exports.offsetTop = getter("offsetTop");
13+
exports.offsetLeft = getter("offsetLeft");
14+
exports.offsetWidth = getter("offsetWodth");
15+
exports.offsetHeight = getter("offsetHeight");

src/Web/CSSOMView/HTMLElement.purs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Web.CSSOMView.HTMLElement where
2+
3+
import Prelude ((<<<), map)
4+
import Effect (Effect)
5+
import Data.Maybe (Maybe)
6+
import Data.Nullable (Nullable, toMaybe)
7+
import Web.DOM.Element (Element)
8+
import Web.HTML.HTMLElement (HTMLElement)
9+
10+
foreign import _offsetParent :: HTMLElement -> Effect (Nullable Element)
11+
foreign import offsetTop :: HTMLElement -> Effect Int
12+
foreign import offsetLeft :: HTMLElement -> Effect Int
13+
foreign import offsetWidth :: HTMLElement -> Effect Int
14+
foreign import offsetHeight :: HTMLElement -> Effect Int
15+
16+
offsetParent :: HTMLElement -> Effect (Maybe Element)
17+
offsetParent = map toMaybe <<< _offsetParent

src/Web/CSSOMView/HTMLImageElement.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
exports.x = function (imageElement) {
4+
return function () {
5+
return imageElement.x;
6+
};
7+
};
8+
9+
exports.y = function (imageElement) {
10+
return function () {
11+
return imageElement.y;
12+
};
13+
};
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module HTMLImageElement where
2+
3+
import Effect (Effect)
4+
import Web.HTML.HTMLImageElement (HTMLImageElement)
5+
6+
foreign import x :: HTMLImageElement -> Effect Int
7+
foreign import y :: HTMLImageElement -> Effect Int

src/Web/CSSOMView/MediaQueryList.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
exports.media = function (mediaQueryList) {
4+
return function () {
5+
return mediaQueryList.media;
6+
};
7+
};
8+
9+
exports.matches = function (mediaQueryList) {
10+
return function () {
11+
return mediaQueryList.matches;
12+
};
13+
};
14+
15+
exports.addListener = function (mediaQueryList) {
16+
return function (callback) {
17+
return function () {
18+
mediaQueryList.addListener(callback);
19+
};
20+
};
21+
};
22+
23+
exports.removeListener = function (mediaQueryList) {
24+
return function (callback) {
25+
return function () {
26+
mediaQueryList.removeListener(callback);
27+
};
28+
};
29+
};

src/Web/CSSOMView/MediaQueryList.purs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Web.CSSOMView.MediaQueryList where
2+
3+
import Prelude (Unit)
4+
import Effect (Effect)
5+
import Unsafe.Coerce (unsafeCoerce)
6+
import Web.Event.EventTarget (EventTarget, EventListener)
7+
8+
foreign import data MediaQueryList :: Type
9+
10+
foreign import media :: MediaQueryList -> Effect String
11+
foreign import matches :: MediaQueryList -> Effect Boolean
12+
foreign import addListener :: MediaQueryList -> EventListener -> Effect Unit
13+
foreign import removeListener :: MediaQueryList -> EventListener -> Effect Unit
14+
15+
toEventTarget :: MediaQueryList -> EventTarget
16+
toEventTarget = unsafeCoerce
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
exports.media = function (mediaQueryListEvent) {
4+
return mediaQueryListEvent.media;
5+
};
6+
7+
exports.matches = function (mediaQueryListEvent) {
8+
return mediaQueryListEvent.matches;
9+
};
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Web.CSSOMView.MediaQueryListEvent where
2+
3+
import Data.Maybe (Maybe)
4+
import Unsafe.Coerce (unsafeCoerce)
5+
import Web.Event.Event (Event)
6+
import Web.Internal.FFI (unsafeReadProtoTagged)
7+
8+
foreign import data MediaQueryListEvent :: Type
9+
10+
fromEvent :: Event -> Maybe MediaQueryListEvent
11+
fromEvent = unsafeReadProtoTagged "MediaQueryListEvent"
12+
13+
toEvent :: MediaQueryListEvent -> Event
14+
toEvent = unsafeCoerce
15+
16+
foreign import media :: MediaQueryListEvent -> String
17+
18+
foreign import matches :: MediaQueryListEvent -> Boolean
19+
20+
-- TODO: fromEvent/toEvent

src/Web/CSSOMView/Screen.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
3+
function getter(property) {
4+
return function (screen) {
5+
return function () {
6+
return screen[property];
7+
};
8+
};
9+
}
10+
11+
exports.availWidth = getter("availWidth");
12+
exports.availHeight = getter("availHeight");
13+
exports.width = getter("width");
14+
exports.height = getter("height");
15+
exports.colorDepth = getter("colorDepth");
16+
exports.pixelDepth = getter("pixelDepth");

src/Web/CSSOMView/Screen.purs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Web.CSSOMView.Screen where
2+
3+
import Effect (Effect)
4+
5+
foreign import data Screen :: Type
6+
7+
foreign import availWidth :: Effect Int
8+
foreign import availHeight :: Effect Int
9+
foreign import width :: Effect Int
10+
foreign import height :: Effect Int
11+
foreign import colorDepth :: Effect Int
12+
foreign import pixelDepth :: Effect Int

0 commit comments

Comments
 (0)