@flourish/ui-styles 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +7 -0
- package/README.md +1 -0
- package/RELEASE_NOTES.md +0 -0
- package/button-style/settings.yml +39 -0
- package/controls-style/settings.yml +22 -0
- package/dropdown-style/settings.yml +41 -0
- package/package.json +40 -0
- package/rollup.config.js +25 -0
- package/src/button-style/index.js +76 -0
- package/src/dropdown-style/index.js +94 -0
- package/src/general-controls-style/index.js +52 -0
- package/src/index.js +17 -0
- package/src/lib/js2css.js +53 -0
- package/ui-styles.js +288 -0
package/.eslintrc.json
ADDED
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Flourish UI Styles
|
package/RELEASE_NOTES.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
- property: background
|
|
2
|
+
name: Background
|
|
3
|
+
type: color
|
|
4
|
+
width: quarter
|
|
5
|
+
- property: font_color
|
|
6
|
+
name: Text color
|
|
7
|
+
type: color
|
|
8
|
+
width: quarter
|
|
9
|
+
- property: button_styles_advanced
|
|
10
|
+
name: Advanced
|
|
11
|
+
width: half
|
|
12
|
+
type: boolean
|
|
13
|
+
- property: background_selected
|
|
14
|
+
name: Selected background
|
|
15
|
+
type: color
|
|
16
|
+
width: quarter
|
|
17
|
+
show_if: button_styles_advanced
|
|
18
|
+
- property: font_color_selected
|
|
19
|
+
name: Selected text color
|
|
20
|
+
type: color
|
|
21
|
+
width: quarter
|
|
22
|
+
show_if: button_styles_advanced
|
|
23
|
+
- property: border_color
|
|
24
|
+
name: Border
|
|
25
|
+
type: color
|
|
26
|
+
width: quarter
|
|
27
|
+
show_if: button_styles_advanced
|
|
28
|
+
- property: border_width
|
|
29
|
+
name: Width
|
|
30
|
+
type: number
|
|
31
|
+
width: quarter
|
|
32
|
+
min: 0
|
|
33
|
+
show_if: button_styles_advanced
|
|
34
|
+
- property: border_radius
|
|
35
|
+
name: Radius
|
|
36
|
+
type: number
|
|
37
|
+
width: quarter
|
|
38
|
+
min: 0
|
|
39
|
+
show_if: button_styles_advanced
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
- property: font_size
|
|
2
|
+
name: Text size
|
|
3
|
+
type: number
|
|
4
|
+
width: quarter
|
|
5
|
+
min: 0
|
|
6
|
+
step: 0.1
|
|
7
|
+
- property: font_weight
|
|
8
|
+
name: Text weight
|
|
9
|
+
type: string
|
|
10
|
+
width: half
|
|
11
|
+
min: 0
|
|
12
|
+
step: 0.1
|
|
13
|
+
style: buttons
|
|
14
|
+
choices:
|
|
15
|
+
- [ Bold, bold ]
|
|
16
|
+
- [ Normal, normal ]
|
|
17
|
+
- property: padding
|
|
18
|
+
name: Height
|
|
19
|
+
type: number
|
|
20
|
+
width: quarter
|
|
21
|
+
min: 0
|
|
22
|
+
step: 0.1
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
- property: background
|
|
2
|
+
name: Background
|
|
3
|
+
type: color
|
|
4
|
+
width: quarter
|
|
5
|
+
- property: font_color
|
|
6
|
+
name: Text color
|
|
7
|
+
type: color
|
|
8
|
+
width: quarter
|
|
9
|
+
- property: border_styles_advanced
|
|
10
|
+
name: Advanced
|
|
11
|
+
width: half
|
|
12
|
+
type: boolean
|
|
13
|
+
- property: border_style
|
|
14
|
+
name: Border style
|
|
15
|
+
type: string
|
|
16
|
+
width: half
|
|
17
|
+
style: buttons
|
|
18
|
+
show_if: border_styles_advanced
|
|
19
|
+
choices:
|
|
20
|
+
- [All, all]
|
|
21
|
+
- [Bottom, bottom]
|
|
22
|
+
- property: border_width
|
|
23
|
+
name: Width
|
|
24
|
+
type: number
|
|
25
|
+
width: quarter
|
|
26
|
+
min: 0
|
|
27
|
+
show_if: border_styles_advanced
|
|
28
|
+
- property: border_color
|
|
29
|
+
name: Color
|
|
30
|
+
type: number
|
|
31
|
+
width: quarter
|
|
32
|
+
min: 0
|
|
33
|
+
show_if: border_styles_advanced
|
|
34
|
+
- property: border_radius
|
|
35
|
+
name: Radius
|
|
36
|
+
type: number
|
|
37
|
+
width: quarter
|
|
38
|
+
min: 0
|
|
39
|
+
show_if:
|
|
40
|
+
border_styles_advanced: true
|
|
41
|
+
border_style: all
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flourish/ui-styles",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Flourish module for styling UI elements",
|
|
5
|
+
"main": "ui-styles.js",
|
|
6
|
+
"module": "src/index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint": "eslint src",
|
|
9
|
+
"build": "rollup -c",
|
|
10
|
+
"prepare": "npm run build && npm run minify",
|
|
11
|
+
"minify": "uglifyjs -m -o ui-styles.min.js ui-styles.js",
|
|
12
|
+
"precommit": "lint-staged"
|
|
13
|
+
},
|
|
14
|
+
"author": "Kiln Enterprises Ltd",
|
|
15
|
+
"license": "UNLICENSED",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"d3-selection": "^1.4.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@flourish/eslint-plugin-flourish": "^0.7.2",
|
|
21
|
+
"eslint": "^5.16.0",
|
|
22
|
+
"husky": "^1.3.1",
|
|
23
|
+
"lint-staged": "^8.1.3",
|
|
24
|
+
"rollup": "^1.1.2",
|
|
25
|
+
"rollup-plugin-node-resolve": "^4.0.0",
|
|
26
|
+
"uglify-js": "^3.4.9"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git://github.com/kiln/flourish-ui-styles.git"
|
|
31
|
+
},
|
|
32
|
+
"lint-staged": {
|
|
33
|
+
"*.js": "npm run lint --"
|
|
34
|
+
},
|
|
35
|
+
"husky": {
|
|
36
|
+
"hooks": {
|
|
37
|
+
"pre-commit": "lint-staged"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import nodeResolve from "rollup-plugin-node-resolve";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
input: "src/index.js",
|
|
5
|
+
output: {
|
|
6
|
+
file: "ui-styles.js",
|
|
7
|
+
format: "umd",
|
|
8
|
+
name: "ui-styles"
|
|
9
|
+
},
|
|
10
|
+
plugins: [
|
|
11
|
+
nodeResolve()
|
|
12
|
+
],
|
|
13
|
+
onwarn: function (warning, warn) {
|
|
14
|
+
if (warning.code === "CIRCULAR_DEPENDENCY") return;
|
|
15
|
+
if (warning.code === "UNRESOLVED_IMPORT") {
|
|
16
|
+
throw new Error(
|
|
17
|
+
"Couldn't resolve the dependency " + warning.source +
|
|
18
|
+
" (from " + warning.importer + "): sometimes you can" +
|
|
19
|
+
" fix this with 'npm install', or add '" + warning.source +
|
|
20
|
+
" to 'external'. See: " + warning.url
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
warn(warning);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import Stylesheet from "../lib/js2css";
|
|
2
|
+
|
|
3
|
+
var DEFAULTS = Object.freeze({
|
|
4
|
+
background: "#ffffff",
|
|
5
|
+
background_selected: "#ff0033",
|
|
6
|
+
|
|
7
|
+
font_color: "#333333",
|
|
8
|
+
font_color_selected: "#ffffff",
|
|
9
|
+
|
|
10
|
+
border_width: 1,
|
|
11
|
+
border_color: "0.25",
|
|
12
|
+
border_radius: 3
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
function ButtonStyle(state_, selector_) {
|
|
16
|
+
this._state = state_;
|
|
17
|
+
for (var key in DEFAULTS) { if (this._state[key] === undefined) this._state[key] = DEFAULTS[key]; }
|
|
18
|
+
|
|
19
|
+
this._styles = new Stylesheet();
|
|
20
|
+
this._selector = selector_;
|
|
21
|
+
this._createStylesheet();
|
|
22
|
+
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
ButtonStyle.prototype._createStylesheet = function() {
|
|
27
|
+
this._stylesheet = document.createElement("style");
|
|
28
|
+
document.head.appendChild(this._stylesheet);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
ButtonStyle.prototype.update = function() {
|
|
32
|
+
this._styles.clear();
|
|
33
|
+
|
|
34
|
+
this._styles.select(this._selector + ".hidden")
|
|
35
|
+
.style("display", "none");
|
|
36
|
+
|
|
37
|
+
this._styles.select(this._selector + " .button")
|
|
38
|
+
.style("display", "inline-block")
|
|
39
|
+
.style("cursor", "pointer")
|
|
40
|
+
.style("text-align", "center")
|
|
41
|
+
.style("overflow", "hidden")
|
|
42
|
+
.style("white-space", "nowrap")
|
|
43
|
+
.style("box-sizing", "content-box")
|
|
44
|
+
.style("margin", "0 2px 0 0")
|
|
45
|
+
.style("background-color", this._state.background)
|
|
46
|
+
.style("color", this._state.font_color)
|
|
47
|
+
.style("border", this._state.border_width + "px solid rgba(0,0,0," + this._state.border_color + ")")
|
|
48
|
+
.style("border-radius", this._state.border_radius + "px");
|
|
49
|
+
|
|
50
|
+
this._styles.select(this._selector + " .button.selected")
|
|
51
|
+
.style("background-color", this._state.background_selected)
|
|
52
|
+
.style("color", this._state.font_color_selected);
|
|
53
|
+
|
|
54
|
+
this._styles.select(this._selector + ".grouped .button")
|
|
55
|
+
.style("border-right", "none")
|
|
56
|
+
.style("border-radius", "0")
|
|
57
|
+
.style("margin", "0");
|
|
58
|
+
|
|
59
|
+
this._styles.select(this._selector + ".grouped .button:first-child")
|
|
60
|
+
.style("border-radius", this._state.border_radius + "px 0 0 " + this._state.border_radius + "px");
|
|
61
|
+
|
|
62
|
+
this._styles.select(this._selector + ".grouped .button:last-child")
|
|
63
|
+
.style("border-radius", "0 " + this._state.border_radius + "px " + this._state.border_radius + "px 0")
|
|
64
|
+
.style("border-right", this._state.border_width + "px solid rgba(0,0,0," + this._state.border_color + ")");
|
|
65
|
+
|
|
66
|
+
this._styles.select(this._selector + ".grouped.fixed-width:not(.hidden)")
|
|
67
|
+
.style("display", "table")
|
|
68
|
+
.style("table-layout", "fixed")
|
|
69
|
+
.style("width", this._state.grouped_width + "%")
|
|
70
|
+
.select(".button")
|
|
71
|
+
.style("display", "table-cell");
|
|
72
|
+
|
|
73
|
+
this._stylesheet.innerHTML = this._styles.print();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default ButtonStyle;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import Stylesheet from "../lib/js2css";
|
|
2
|
+
|
|
3
|
+
var DEFAULTS = Object.freeze({
|
|
4
|
+
background: "#ffffff",
|
|
5
|
+
font_color: "#333333",
|
|
6
|
+
|
|
7
|
+
border_style: "all",
|
|
8
|
+
border_width: 1,
|
|
9
|
+
border_color: "0.25",
|
|
10
|
+
border_radius: 3
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function DropdownStyle(state_, selector_) {
|
|
14
|
+
this._state = state_;
|
|
15
|
+
for (var key in DEFAULTS) { if (this._state[key] === undefined) this._state[key] = DEFAULTS[key]; }
|
|
16
|
+
|
|
17
|
+
this._styles = new Stylesheet();
|
|
18
|
+
this._selector = selector_;
|
|
19
|
+
this._createStylesheet();
|
|
20
|
+
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
DropdownStyle.prototype._createStylesheet = function() {
|
|
25
|
+
this._stylesheet = document.createElement("style");
|
|
26
|
+
document.head.appendChild(this._stylesheet);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
DropdownStyle.prototype.update = function() {
|
|
30
|
+
this._styles.clear();
|
|
31
|
+
|
|
32
|
+
this._styles.select(this._selector + " .heading")
|
|
33
|
+
.style("margin-bottom", "0.4em");
|
|
34
|
+
|
|
35
|
+
this._styles.select(this._selector)
|
|
36
|
+
.style("pointer-events", "all");
|
|
37
|
+
|
|
38
|
+
this._styles.select(this._selector + " .main")
|
|
39
|
+
.style("display", "inline-block")
|
|
40
|
+
.style("cursor", "pointer")
|
|
41
|
+
.style("overflow", "hidden")
|
|
42
|
+
.style("white-space", "nowrap")
|
|
43
|
+
.style("background-color", this._state.background)
|
|
44
|
+
.style("color", this._state.font_color)
|
|
45
|
+
.style("border", this._state.border_style == "bottom" ? null : this._state.border_width + "px solid rgba(0,0,0," + this._state.border_color + ")")
|
|
46
|
+
.style("border-bottom", this._state.border_style == "bottom" ? this._state.border_width + "px solid rgba(0,0,0," + this._state.border_color + ")" : null)
|
|
47
|
+
.style("border-radius", this._state.border_style == "bottom" ? null : this._state.border_radius + "px");
|
|
48
|
+
|
|
49
|
+
this._styles.select(this._selector + " .main .symbol div")
|
|
50
|
+
.style("border-top-color", this._state.font_color + " !important");
|
|
51
|
+
|
|
52
|
+
this._styles.select(this._selector + " .main .current")
|
|
53
|
+
.style("line-height", "1em")
|
|
54
|
+
.style("height", "100%")
|
|
55
|
+
.style("width", "100%")
|
|
56
|
+
.style("display", "inline-block")
|
|
57
|
+
.style("padding", "0.2em 0 0")
|
|
58
|
+
.style("vertical-align", "top");
|
|
59
|
+
|
|
60
|
+
this._styles.select(this._selector + " .list")
|
|
61
|
+
.style("border", this._state.border_width + "px solid rgba(0,0,0," + this._state.border_color + ")")
|
|
62
|
+
.style("background-color", this._state.background)
|
|
63
|
+
.style("position", "absolute")
|
|
64
|
+
.style("top", "2px")
|
|
65
|
+
.style("min-width", "100%")
|
|
66
|
+
.style("padding", "2px")
|
|
67
|
+
.style("display", "none")
|
|
68
|
+
.style("max-height", "200px")
|
|
69
|
+
.style("overflow-y", "scroll")
|
|
70
|
+
.style("box-shadow", "0 1px 4px rgba(0, 0, 0, .1)")
|
|
71
|
+
.style("margin-top", "2px")
|
|
72
|
+
.select(".list-item")
|
|
73
|
+
.style("line-height", "1em")
|
|
74
|
+
.style("cursor", "pointer")
|
|
75
|
+
.style("color", this._state.font_color);
|
|
76
|
+
|
|
77
|
+
this._styles.select(this._selector + ".open .list")
|
|
78
|
+
.style("display", "block")
|
|
79
|
+
.style("z-index", "1")
|
|
80
|
+
.style("animation", "dropdown-out 200ms");
|
|
81
|
+
|
|
82
|
+
this._styles.select(this._selector + " .list-item:hover")
|
|
83
|
+
.style("opacity", "0.6");
|
|
84
|
+
|
|
85
|
+
this._styles.select(this._selector + " .list-item.selected, " + this._selector + " .list-item.selected:hover")
|
|
86
|
+
.style("opacity", "1")
|
|
87
|
+
.style("cursor", "default");
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
this._stylesheet.innerHTML = this._styles.print();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
export default DropdownStyle;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Stylesheet from "../lib/js2css";
|
|
2
|
+
|
|
3
|
+
var DEFAULTS = Object.freeze({
|
|
4
|
+
font_size: 1,
|
|
5
|
+
font_weight: "bold",
|
|
6
|
+
padding: 0.5,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
function GeneralControlsStyle(state_, selector_) {
|
|
10
|
+
this._state = state_;
|
|
11
|
+
for (var key in DEFAULTS) { if (this._state[key] === undefined) this._state[key] = DEFAULTS[key]; }
|
|
12
|
+
|
|
13
|
+
this._styles = new Stylesheet();
|
|
14
|
+
this._selector = selector_;
|
|
15
|
+
this._createStylesheet();
|
|
16
|
+
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
GeneralControlsStyle.prototype._createStylesheet = function() {
|
|
21
|
+
this._stylesheet = document.createElement("style");
|
|
22
|
+
document.head.appendChild(this._stylesheet);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
GeneralControlsStyle.prototype.update = function() {
|
|
26
|
+
this._styles.clear();
|
|
27
|
+
|
|
28
|
+
this._styles.select(this._selector + ".hidden")
|
|
29
|
+
.style("display", "none");
|
|
30
|
+
|
|
31
|
+
this._styles.select(this._selector)
|
|
32
|
+
.style("position", "relative")
|
|
33
|
+
.style("font-size", this._state.font_size + "rem")
|
|
34
|
+
.style("font-weight", this._state.font_weight);
|
|
35
|
+
|
|
36
|
+
this._styles.select(this._selector + " .button")
|
|
37
|
+
.style("padding", this._state.padding + "rem");
|
|
38
|
+
|
|
39
|
+
this._styles.select(this._selector + " .list-item")
|
|
40
|
+
.style("padding", this._state.padding + "rem");
|
|
41
|
+
|
|
42
|
+
this._styles.select(this._selector + "-dropdown .main")
|
|
43
|
+
.style("padding", this._state.padding + "rem");
|
|
44
|
+
|
|
45
|
+
// Some additional styling for slider controls
|
|
46
|
+
// TODO: should move this somewhere else at some point
|
|
47
|
+
|
|
48
|
+
this._stylesheet.innerHTML = this._styles.print();
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
export default GeneralControlsStyle;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import GeneralControlsStyle from "./general-controls-style";
|
|
2
|
+
import ButtonStyle from "./button-style";
|
|
3
|
+
import DropdownStyle from "./dropdown-style";
|
|
4
|
+
|
|
5
|
+
function createGeneralControlsStyle(state, selector) {
|
|
6
|
+
return new GeneralControlsStyle(state, selector);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function createButtonStyle(state, selector) {
|
|
10
|
+
return new ButtonStyle(state, selector);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function createDropdownStyle(state, selector) {
|
|
14
|
+
return new DropdownStyle(state, selector);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { createGeneralControlsStyle, createButtonStyle, createDropdownStyle };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
function Stylesheet() {
|
|
2
|
+
this.declarations = [];
|
|
3
|
+
return this;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
Stylesheet.prototype.select = function(selector) {
|
|
7
|
+
if (!selector) return this;
|
|
8
|
+
var declaration = new Declaration(selector, this);
|
|
9
|
+
declaration.parent = this;
|
|
10
|
+
this.addDeclaration(declaration);
|
|
11
|
+
|
|
12
|
+
return declaration;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
Stylesheet.prototype.addDeclaration = function(declaration) {
|
|
16
|
+
this.declarations.push(declaration);
|
|
17
|
+
return this;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
Stylesheet.prototype.print = function() {
|
|
21
|
+
var text = "";
|
|
22
|
+
this.declarations.forEach(function(declaration) {
|
|
23
|
+
text += declaration.selector + " {\n";
|
|
24
|
+
declaration.styles.forEach(function(style) {
|
|
25
|
+
text += "\t" + style[0] + ": " + style[1] + ";\n";
|
|
26
|
+
});
|
|
27
|
+
text += "}\n\n";
|
|
28
|
+
});
|
|
29
|
+
return text;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
Stylesheet.prototype.clear = function() {
|
|
33
|
+
this.declarations = [];
|
|
34
|
+
return this;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function Declaration(selector) {
|
|
38
|
+
this.selector = selector;
|
|
39
|
+
this.styles = [];
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
Declaration.prototype.style = function(property, _value) {
|
|
44
|
+
var value = typeof value_ == "function" ? _value() : _value;
|
|
45
|
+
if (value !== "" && value !== null && value !== undefined) this.styles.push([property, value]);
|
|
46
|
+
return this;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
Declaration.prototype.select = function(selector) {
|
|
50
|
+
return this.parent.select(this.selector + " " + selector);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default Stylesheet;
|
package/ui-styles.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = global || self, factory(global['ui-styles'] = {}));
|
|
5
|
+
}(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function Stylesheet() {
|
|
8
|
+
this.declarations = [];
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Stylesheet.prototype.select = function(selector) {
|
|
13
|
+
if (!selector) return this;
|
|
14
|
+
var declaration = new Declaration(selector, this);
|
|
15
|
+
declaration.parent = this;
|
|
16
|
+
this.addDeclaration(declaration);
|
|
17
|
+
|
|
18
|
+
return declaration;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
Stylesheet.prototype.addDeclaration = function(declaration) {
|
|
22
|
+
this.declarations.push(declaration);
|
|
23
|
+
return this;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
Stylesheet.prototype.print = function() {
|
|
27
|
+
var text = "";
|
|
28
|
+
this.declarations.forEach(function(declaration) {
|
|
29
|
+
text += declaration.selector + " {\n";
|
|
30
|
+
declaration.styles.forEach(function(style) {
|
|
31
|
+
text += "\t" + style[0] + ": " + style[1] + ";\n";
|
|
32
|
+
});
|
|
33
|
+
text += "}\n\n";
|
|
34
|
+
});
|
|
35
|
+
return text;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
Stylesheet.prototype.clear = function() {
|
|
39
|
+
this.declarations = [];
|
|
40
|
+
return this;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function Declaration(selector) {
|
|
44
|
+
this.selector = selector;
|
|
45
|
+
this.styles = [];
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Declaration.prototype.style = function(property, _value) {
|
|
50
|
+
var value = typeof value_ == "function" ? _value() : _value;
|
|
51
|
+
if (value !== "" && value !== null && value !== undefined) this.styles.push([property, value]);
|
|
52
|
+
return this;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
Declaration.prototype.select = function(selector) {
|
|
56
|
+
return this.parent.select(this.selector + " " + selector);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var DEFAULTS = Object.freeze({
|
|
60
|
+
font_size: 1,
|
|
61
|
+
font_weight: "bold",
|
|
62
|
+
padding: 0.5,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
function GeneralControlsStyle(state_, selector_) {
|
|
66
|
+
this._state = state_;
|
|
67
|
+
for (var key in DEFAULTS) { if (this._state[key] === undefined) this._state[key] = DEFAULTS[key]; }
|
|
68
|
+
|
|
69
|
+
this._styles = new Stylesheet();
|
|
70
|
+
this._selector = selector_;
|
|
71
|
+
this._createStylesheet();
|
|
72
|
+
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
GeneralControlsStyle.prototype._createStylesheet = function() {
|
|
77
|
+
this._stylesheet = document.createElement("style");
|
|
78
|
+
document.head.appendChild(this._stylesheet);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
GeneralControlsStyle.prototype.update = function() {
|
|
82
|
+
this._styles.clear();
|
|
83
|
+
|
|
84
|
+
this._styles.select(this._selector + ".hidden")
|
|
85
|
+
.style("display", "none");
|
|
86
|
+
|
|
87
|
+
this._styles.select(this._selector)
|
|
88
|
+
.style("position", "relative")
|
|
89
|
+
.style("font-size", this._state.font_size + "rem")
|
|
90
|
+
.style("font-weight", this._state.font_weight);
|
|
91
|
+
|
|
92
|
+
this._styles.select(this._selector + " .button")
|
|
93
|
+
.style("padding", this._state.padding + "rem");
|
|
94
|
+
|
|
95
|
+
this._styles.select(this._selector + " .list-item")
|
|
96
|
+
.style("padding", this._state.padding + "rem");
|
|
97
|
+
|
|
98
|
+
this._styles.select(this._selector + "-dropdown .main")
|
|
99
|
+
.style("padding", this._state.padding + "rem");
|
|
100
|
+
|
|
101
|
+
// Some additional styling for slider controls
|
|
102
|
+
// TODO: should move this somewhere else at some point
|
|
103
|
+
|
|
104
|
+
this._stylesheet.innerHTML = this._styles.print();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
var DEFAULTS$1 = Object.freeze({
|
|
108
|
+
background: "#ffffff",
|
|
109
|
+
background_selected: "#ff0033",
|
|
110
|
+
|
|
111
|
+
font_color: "#333333",
|
|
112
|
+
font_color_selected: "#ffffff",
|
|
113
|
+
|
|
114
|
+
border_width: 1,
|
|
115
|
+
border_color: "0.25",
|
|
116
|
+
border_radius: 3
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
function ButtonStyle(state_, selector_) {
|
|
120
|
+
this._state = state_;
|
|
121
|
+
for (var key in DEFAULTS$1) { if (this._state[key] === undefined) this._state[key] = DEFAULTS$1[key]; }
|
|
122
|
+
|
|
123
|
+
this._styles = new Stylesheet();
|
|
124
|
+
this._selector = selector_;
|
|
125
|
+
this._createStylesheet();
|
|
126
|
+
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
ButtonStyle.prototype._createStylesheet = function() {
|
|
131
|
+
this._stylesheet = document.createElement("style");
|
|
132
|
+
document.head.appendChild(this._stylesheet);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
ButtonStyle.prototype.update = function() {
|
|
136
|
+
this._styles.clear();
|
|
137
|
+
|
|
138
|
+
this._styles.select(this._selector + ".hidden")
|
|
139
|
+
.style("display", "none");
|
|
140
|
+
|
|
141
|
+
this._styles.select(this._selector + " .button")
|
|
142
|
+
.style("display", "inline-block")
|
|
143
|
+
.style("cursor", "pointer")
|
|
144
|
+
.style("text-align", "center")
|
|
145
|
+
.style("overflow", "hidden")
|
|
146
|
+
.style("white-space", "nowrap")
|
|
147
|
+
.style("box-sizing", "content-box")
|
|
148
|
+
.style("margin", "0 2px 0 0")
|
|
149
|
+
.style("background-color", this._state.background)
|
|
150
|
+
.style("color", this._state.font_color)
|
|
151
|
+
.style("border", this._state.border_width + "px solid rgba(0,0,0," + this._state.border_color + ")")
|
|
152
|
+
.style("border-radius", this._state.border_radius + "px");
|
|
153
|
+
|
|
154
|
+
this._styles.select(this._selector + " .button.selected")
|
|
155
|
+
.style("background-color", this._state.background_selected)
|
|
156
|
+
.style("color", this._state.font_color_selected);
|
|
157
|
+
|
|
158
|
+
this._styles.select(this._selector + ".grouped .button")
|
|
159
|
+
.style("border-right", "none")
|
|
160
|
+
.style("border-radius", "0")
|
|
161
|
+
.style("margin", "0");
|
|
162
|
+
|
|
163
|
+
this._styles.select(this._selector + ".grouped .button:first-child")
|
|
164
|
+
.style("border-radius", this._state.border_radius + "px 0 0 " + this._state.border_radius + "px");
|
|
165
|
+
|
|
166
|
+
this._styles.select(this._selector + ".grouped .button:last-child")
|
|
167
|
+
.style("border-radius", "0 " + this._state.border_radius + "px " + this._state.border_radius + "px 0")
|
|
168
|
+
.style("border-right", this._state.border_width + "px solid rgba(0,0,0," + this._state.border_color + ")");
|
|
169
|
+
|
|
170
|
+
this._styles.select(this._selector + ".grouped.fixed-width:not(.hidden)")
|
|
171
|
+
.style("display", "table")
|
|
172
|
+
.style("table-layout", "fixed")
|
|
173
|
+
.style("width", this._state.grouped_width + "%")
|
|
174
|
+
.select(".button")
|
|
175
|
+
.style("display", "table-cell");
|
|
176
|
+
|
|
177
|
+
this._stylesheet.innerHTML = this._styles.print();
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
var DEFAULTS$2 = Object.freeze({
|
|
181
|
+
background: "#ffffff",
|
|
182
|
+
font_color: "#333333",
|
|
183
|
+
|
|
184
|
+
border_style: "all",
|
|
185
|
+
border_width: 1,
|
|
186
|
+
border_color: "0.25",
|
|
187
|
+
border_radius: 3
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
function DropdownStyle(state_, selector_) {
|
|
191
|
+
this._state = state_;
|
|
192
|
+
for (var key in DEFAULTS$2) { if (this._state[key] === undefined) this._state[key] = DEFAULTS$2[key]; }
|
|
193
|
+
|
|
194
|
+
this._styles = new Stylesheet();
|
|
195
|
+
this._selector = selector_;
|
|
196
|
+
this._createStylesheet();
|
|
197
|
+
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
DropdownStyle.prototype._createStylesheet = function() {
|
|
202
|
+
this._stylesheet = document.createElement("style");
|
|
203
|
+
document.head.appendChild(this._stylesheet);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
DropdownStyle.prototype.update = function() {
|
|
207
|
+
this._styles.clear();
|
|
208
|
+
|
|
209
|
+
this._styles.select(this._selector + " .heading")
|
|
210
|
+
.style("margin-bottom", "0.4em");
|
|
211
|
+
|
|
212
|
+
this._styles.select(this._selector)
|
|
213
|
+
.style("pointer-events", "all");
|
|
214
|
+
|
|
215
|
+
this._styles.select(this._selector + " .main")
|
|
216
|
+
.style("display", "inline-block")
|
|
217
|
+
.style("cursor", "pointer")
|
|
218
|
+
.style("overflow", "hidden")
|
|
219
|
+
.style("white-space", "nowrap")
|
|
220
|
+
.style("background-color", this._state.background)
|
|
221
|
+
.style("color", this._state.font_color)
|
|
222
|
+
.style("border", this._state.border_style == "bottom" ? null : this._state.border_width + "px solid rgba(0,0,0," + this._state.border_color + ")")
|
|
223
|
+
.style("border-bottom", this._state.border_style == "bottom" ? this._state.border_width + "px solid rgba(0,0,0," + this._state.border_color + ")" : null)
|
|
224
|
+
.style("border-radius", this._state.border_style == "bottom" ? null : this._state.border_radius + "px");
|
|
225
|
+
|
|
226
|
+
this._styles.select(this._selector + " .main .symbol div")
|
|
227
|
+
.style("border-top-color", this._state.font_color + " !important");
|
|
228
|
+
|
|
229
|
+
this._styles.select(this._selector + " .main .current")
|
|
230
|
+
.style("line-height", "1em")
|
|
231
|
+
.style("height", "100%")
|
|
232
|
+
.style("width", "100%")
|
|
233
|
+
.style("display", "inline-block")
|
|
234
|
+
.style("padding", "0.2em 0 0")
|
|
235
|
+
.style("vertical-align", "top");
|
|
236
|
+
|
|
237
|
+
this._styles.select(this._selector + " .list")
|
|
238
|
+
.style("border", this._state.border_width + "px solid rgba(0,0,0," + this._state.border_color + ")")
|
|
239
|
+
.style("background-color", this._state.background)
|
|
240
|
+
.style("position", "absolute")
|
|
241
|
+
.style("top", "2px")
|
|
242
|
+
.style("min-width", "100%")
|
|
243
|
+
.style("padding", "2px")
|
|
244
|
+
.style("display", "none")
|
|
245
|
+
.style("max-height", "200px")
|
|
246
|
+
.style("overflow-y", "scroll")
|
|
247
|
+
.style("box-shadow", "0 1px 4px rgba(0, 0, 0, .1)")
|
|
248
|
+
.style("margin-top", "2px")
|
|
249
|
+
.select(".list-item")
|
|
250
|
+
.style("line-height", "1em")
|
|
251
|
+
.style("cursor", "pointer")
|
|
252
|
+
.style("color", this._state.font_color);
|
|
253
|
+
|
|
254
|
+
this._styles.select(this._selector + ".open .list")
|
|
255
|
+
.style("display", "block")
|
|
256
|
+
.style("z-index", "1")
|
|
257
|
+
.style("animation", "dropdown-out 200ms");
|
|
258
|
+
|
|
259
|
+
this._styles.select(this._selector + " .list-item:hover")
|
|
260
|
+
.style("opacity", "0.6");
|
|
261
|
+
|
|
262
|
+
this._styles.select(this._selector + " .list-item.selected, " + this._selector + " .list-item.selected:hover")
|
|
263
|
+
.style("opacity", "1")
|
|
264
|
+
.style("cursor", "default");
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
this._stylesheet.innerHTML = this._styles.print();
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
function createGeneralControlsStyle(state, selector) {
|
|
271
|
+
return new GeneralControlsStyle(state, selector);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function createButtonStyle(state, selector) {
|
|
275
|
+
return new ButtonStyle(state, selector);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function createDropdownStyle(state, selector) {
|
|
279
|
+
return new DropdownStyle(state, selector);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
exports.createButtonStyle = createButtonStyle;
|
|
283
|
+
exports.createDropdownStyle = createDropdownStyle;
|
|
284
|
+
exports.createGeneralControlsStyle = createGeneralControlsStyle;
|
|
285
|
+
|
|
286
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
287
|
+
|
|
288
|
+
})));
|