@flourish/ui-styles 2.0.0 → 3.1.0
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/README.md +11 -4
- package/RELEASE_NOTES.md +7 -0
- package/package.json +2 -2
- package/slider-style/settings.yml +45 -0
- package/src/button-style/index.js +8 -3
- package/src/dropdown-style/index.js +2 -1
- package/src/index.js +6 -1
- package/src/lib/remToPx.js +3 -0
- package/src/slider-style/index.js +103 -0
- package/ui-styles.js +237 -7
package/README.md
CHANGED
|
@@ -12,7 +12,8 @@ Add one or more control style objects to your template state:
|
|
|
12
12
|
export var state = {
|
|
13
13
|
controls_style: {},
|
|
14
14
|
button_style: {},
|
|
15
|
-
dropdown_style: {}
|
|
15
|
+
dropdown_style: {},
|
|
16
|
+
slider_style: {},
|
|
16
17
|
}
|
|
17
18
|
```
|
|
18
19
|
|
|
@@ -25,6 +26,8 @@ Import settings for controls styling in your `template.yml` settings.
|
|
|
25
26
|
import: "@flourish/ui-styles/dropdown-style"
|
|
26
27
|
- property: button_style
|
|
27
28
|
import: "@flourish/ui-styles/button-style"
|
|
29
|
+
- property: slider_style
|
|
30
|
+
import: "@flourish/ui-styles/slider-style"
|
|
28
31
|
```
|
|
29
32
|
|
|
30
33
|
## Basics
|
|
@@ -32,20 +35,24 @@ Import settings for controls styling in your `template.yml` settings.
|
|
|
32
35
|
Initialise the styling outside any function or in a special init function:
|
|
33
36
|
|
|
34
37
|
``` js
|
|
35
|
-
import { createGeneralControlsStyle, createButtonStyle, createDropdownStyle } from "@flourish/ui-styles";
|
|
38
|
+
import { createGeneralControlsStyle, createButtonStyle, createDropdownStyle, createSliderStyle } from "@flourish/ui-styles";
|
|
36
39
|
var controlsStyle = createGeneralControlsStyle(state.controls_style, ".fl-control"),
|
|
37
40
|
buttonStyle = createButtonStyle(state.button_style, ".fl-control-buttons"),
|
|
38
41
|
dropdownStyle = createDropdownStyle(state.dropdown_style, ".fl-control-dropdown");
|
|
42
|
+
sliderStyle = createSliderStyle(state.slider_style, ".fl-control-slider");
|
|
39
43
|
```
|
|
40
44
|
|
|
41
|
-
The init function takes the state object as a first argument. The second argument is the target container for styling. If you are using @flourish/controls you can just use the selectors in the code above.
|
|
45
|
+
The init function takes the state object as a first argument. The second argument is the target container for styling. If you are using @flourish/controls you can just use the selectors in the code above.
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
If you're using this on custom HTML, make sure to target the direct parent container of your controls, and make sure to give your controls a classname of `fl-control`. If you're using specifically the button styles with custom HTML make sure your buttons also have a `button` class and your selected elements a `selected` class.
|
|
48
|
+
|
|
49
|
+
Then in the update function, make sure to update the styles with `update()`. To ensure right-to-left read direction support works correctly call the style update functions after the read direction of the template has been updated (i.e. `layout.update()` has been called).
|
|
44
50
|
|
|
45
51
|
```js
|
|
46
52
|
controlsStyle.update();
|
|
47
53
|
buttonStyle.update();
|
|
48
54
|
dropdownStyle.update();
|
|
55
|
+
sliderStyle.update();
|
|
49
56
|
```
|
|
50
57
|
|
|
51
58
|
## Using defaults from @flourish/layout
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# 3.1.0
|
|
2
|
+
* Add support for right-to-left read direction to button border radius styles
|
|
3
|
+
* Update @flourish/pocket-knife to v1.0.0
|
|
4
|
+
|
|
5
|
+
# 3.0.0
|
|
6
|
+
* BREAKING: Move slider styles from @flourish/controls and change to reflect use of a `input` element for slider. For use with version 7.0.0+ of @flourish/controls
|
|
7
|
+
|
|
1
8
|
# 2.0.0
|
|
2
9
|
* BREAKING: Change styles to reflect use of a `select` element for the dropdown. For use with version 3.0.0+ of @flourish/controls
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flourish/ui-styles",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Flourish module for styling UI elements",
|
|
5
5
|
"main": "ui-styles.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"author": "Kiln Enterprises Ltd",
|
|
15
15
|
"license": "https://flourish.studio/terms/fcl/",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@flourish/pocket-knife": "^0.
|
|
17
|
+
"@flourish/pocket-knife": "^1.0.0",
|
|
18
18
|
"d3-selection": "^1.4.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
- property: track_color
|
|
2
|
+
name: Track
|
|
3
|
+
type: color
|
|
4
|
+
width: quarter
|
|
5
|
+
optional: true
|
|
6
|
+
- property: font_color
|
|
7
|
+
name: Text
|
|
8
|
+
type: color
|
|
9
|
+
width: quarter
|
|
10
|
+
optional: true
|
|
11
|
+
- property: handle_color
|
|
12
|
+
name: Handle
|
|
13
|
+
type: color
|
|
14
|
+
width: quarter
|
|
15
|
+
optional: true
|
|
16
|
+
- property: play_color
|
|
17
|
+
name: Play/pause
|
|
18
|
+
type: color
|
|
19
|
+
width: quarter
|
|
20
|
+
optional: true
|
|
21
|
+
show_if: play_button
|
|
22
|
+
- property: width
|
|
23
|
+
name: Slider width
|
|
24
|
+
type: number
|
|
25
|
+
min: 0
|
|
26
|
+
max: 100
|
|
27
|
+
width: quarter
|
|
28
|
+
- property: track_height
|
|
29
|
+
name: Track height
|
|
30
|
+
type: number
|
|
31
|
+
step: 0.1
|
|
32
|
+
min: 0
|
|
33
|
+
max: 1
|
|
34
|
+
width: quarter
|
|
35
|
+
- property: handle_height
|
|
36
|
+
name: Height
|
|
37
|
+
type: number
|
|
38
|
+
step: 0.1
|
|
39
|
+
min: 0
|
|
40
|
+
max: 10
|
|
41
|
+
width: quarter
|
|
42
|
+
- property: play_button
|
|
43
|
+
name: Play button
|
|
44
|
+
type: boolean
|
|
45
|
+
width: half
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hexToRgba } from "@flourish/pocket-knife";
|
|
1
|
+
import { hexToRgba, getTextDirection } from "@flourish/pocket-knife";
|
|
2
2
|
import Stylesheet from "../lib/js2css";
|
|
3
3
|
|
|
4
4
|
var DEFAULTS = Object.freeze({
|
|
@@ -42,6 +42,7 @@ ButtonStyle.prototype.update = function() {
|
|
|
42
42
|
var background_color = this._state.background || this._layout.background_color || "#ffffff";
|
|
43
43
|
var text_color = this._state.font_color || this._layout.font_color || "#333333";
|
|
44
44
|
var border_color = hexToRgba(this._state.border_color || text_color, this._state.border_transparency);
|
|
45
|
+
var read_direction = getTextDirection();
|
|
45
46
|
|
|
46
47
|
this._styles.select(this._selector + ".fl-control.hidden")
|
|
47
48
|
.style("display", "none");
|
|
@@ -68,10 +69,14 @@ ButtonStyle.prototype.update = function() {
|
|
|
68
69
|
.style("border-radius", "0")
|
|
69
70
|
.style("margin", "0");
|
|
70
71
|
|
|
71
|
-
|
|
72
|
+
var is_rtl = read_direction === "rtl";
|
|
73
|
+
var left_most_button_selector = is_rtl ? ":last-child" : ":first-child";
|
|
74
|
+
var right_most_button_selector = is_rtl ? ":first-child" : ":last-child";
|
|
75
|
+
|
|
76
|
+
this._styles.select(this._selector + ".grouped.fl-control .button" + left_most_button_selector)
|
|
72
77
|
.style("border-radius", this._state.border_radius + "px 0 0 " + this._state.border_radius + "px");
|
|
73
78
|
|
|
74
|
-
this._styles.select(this._selector + ".grouped.fl-control .button
|
|
79
|
+
this._styles.select(this._selector + ".grouped.fl-control .button" + right_most_button_selector)
|
|
75
80
|
.style("border-radius", "0 " + this._state.border_radius + "px " + this._state.border_radius + "px 0")
|
|
76
81
|
.style("border-right", this._state.border_width + "px solid " + border_color);
|
|
77
82
|
|
|
@@ -58,7 +58,8 @@ DropdownStyle.prototype.update = function() {
|
|
|
58
58
|
.style("border-radius", this._state.border_style == "bottom" ? null : this._state.border_radius + "px");
|
|
59
59
|
|
|
60
60
|
this._styles.select(this._selector + ":after")
|
|
61
|
-
.style("right", this._state.border_style == "bottom" ? null : this._state.border_width + 5 + "px")
|
|
61
|
+
.style("right", this._state.border_style == "bottom" ? null : this._state.border_width + 5 + "px")
|
|
62
|
+
.style("color", text_color);
|
|
62
63
|
|
|
63
64
|
this._styles.select(this._selector + " .main .current")
|
|
64
65
|
.style("line-height", "1em")
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import GeneralControlsStyle from "./general-controls-style";
|
|
2
2
|
import ButtonStyle from "./button-style";
|
|
3
3
|
import DropdownStyle from "./dropdown-style";
|
|
4
|
+
import SliderStyle from "./slider-style";
|
|
4
5
|
|
|
5
6
|
function createGeneralControlsStyle(state, selector, layout) {
|
|
6
7
|
return new GeneralControlsStyle(state, selector, layout);
|
|
@@ -14,4 +15,8 @@ function createDropdownStyle(state, selector, layout) {
|
|
|
14
15
|
return new DropdownStyle(state, selector, layout);
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
function createSliderStyle(state, selector, layout) {
|
|
19
|
+
return new SliderStyle(state, selector, layout);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { createGeneralControlsStyle, createButtonStyle, createDropdownStyle, createSliderStyle };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { remToPx } from "../lib/remToPx";
|
|
2
|
+
import Stylesheet from "../lib/js2css";
|
|
3
|
+
|
|
4
|
+
var DEFAULTS = Object.freeze({
|
|
5
|
+
width: 15,
|
|
6
|
+
play_color: null,
|
|
7
|
+
handle_color: null,
|
|
8
|
+
font_color: null,
|
|
9
|
+
track_color: null,
|
|
10
|
+
|
|
11
|
+
handle_height: 1,
|
|
12
|
+
track_height: 0.2,
|
|
13
|
+
margin: 4.5,
|
|
14
|
+
|
|
15
|
+
play_button: true
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
function SliderStyle(state_, selector_, layout_) {
|
|
19
|
+
this._state = state_;
|
|
20
|
+
for (var key in DEFAULTS) { if (this._state[key] === undefined) this._state[key] = DEFAULTS[key]; }
|
|
21
|
+
|
|
22
|
+
this._layout = layout_ || {};
|
|
23
|
+
|
|
24
|
+
this._styles = new Stylesheet();
|
|
25
|
+
this._selector = selector_;
|
|
26
|
+
this._createStylesheet();
|
|
27
|
+
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
SliderStyle.prototype._createStylesheet = function() {
|
|
32
|
+
this._stylesheet = document.createElement("style");
|
|
33
|
+
this._stylesheet.className = "fl-ui-styles-slider";
|
|
34
|
+
document.head.appendChild(this._stylesheet);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
SliderStyle.prototype.update = function() {
|
|
38
|
+
this._styles.clear();
|
|
39
|
+
|
|
40
|
+
var track_color = this._state.track_color || "#dddddd";
|
|
41
|
+
var text_color = this._state.font_color || this._layout.font_color || "currentColor";
|
|
42
|
+
var slider_color = "currentColor"; // So that handle can inherit layout text color via this parent
|
|
43
|
+
var handle_color = this._state.handle_color || this._layout.font_color || "currentColor";
|
|
44
|
+
var play_color = this._state.play_color || this._layout.font_color || "currentColor";
|
|
45
|
+
|
|
46
|
+
var slider_width = Math.round(remToPx(this._state.width));
|
|
47
|
+
var handle_radius = Math.round(remToPx(this._state.handle_height));
|
|
48
|
+
var track_height = remToPx(this._state.track_height);
|
|
49
|
+
|
|
50
|
+
this._styles.select(this._selector + " .fl-controls-slider")
|
|
51
|
+
.style("height", handle_radius * 2 + "px");
|
|
52
|
+
|
|
53
|
+
this._styles.select(this._selector + " .slider-play")
|
|
54
|
+
.style("fill", play_color)
|
|
55
|
+
.style("width", handle_radius + "px")
|
|
56
|
+
.style("height", handle_radius + "px")
|
|
57
|
+
.style("display", this._state.play_button ? null : "none");
|
|
58
|
+
|
|
59
|
+
this._styles.select(this._selector + " .slider-label")
|
|
60
|
+
.style("padding-inline-start", "0.3rem")
|
|
61
|
+
.style("color", text_color);
|
|
62
|
+
|
|
63
|
+
this._styles.select(this._selector + " input[type=range]")
|
|
64
|
+
.style("-webkit-appearance", "none")
|
|
65
|
+
.style("width", slider_width + "px")
|
|
66
|
+
.style("color", slider_color)
|
|
67
|
+
.style("background-color", "transparent");
|
|
68
|
+
|
|
69
|
+
// Chrome/Edge
|
|
70
|
+
this._styles.select(this._selector + " input[type=range]::-webkit-slider-runnable-track")
|
|
71
|
+
.style("-webkit-appearance", "none")
|
|
72
|
+
.style("background", track_color)
|
|
73
|
+
.style("border-radius", "100px")
|
|
74
|
+
.style("height", track_height + "px");
|
|
75
|
+
|
|
76
|
+
this._styles.select(this._selector + " input[type=range]::-webkit-slider-thumb")
|
|
77
|
+
.style("-webkit-appearance", "none")
|
|
78
|
+
.style("width", handle_radius + "px")
|
|
79
|
+
.style("height", handle_radius + "px")
|
|
80
|
+
.style("border-radius", "100px")
|
|
81
|
+
.style("background", handle_color)
|
|
82
|
+
.style("margin-top", -handle_radius/2 + track_height/2 + "px");
|
|
83
|
+
|
|
84
|
+
// Firefox
|
|
85
|
+
this._styles.select(this._selector + " input[type=range]::-moz-range-track")
|
|
86
|
+
.style("-webkit-appearance", "none")
|
|
87
|
+
.style("background", track_color)
|
|
88
|
+
.style("border-radius", "100px")
|
|
89
|
+
.style("height", track_height + "px");
|
|
90
|
+
|
|
91
|
+
this._styles.select(this._selector + " input[type=range]::-moz-range-thumb")
|
|
92
|
+
.style("-webkit-appearance", "none")
|
|
93
|
+
.style("width", handle_radius + "px")
|
|
94
|
+
.style("height", handle_radius + "px")
|
|
95
|
+
.style("border-radius", "100px")
|
|
96
|
+
.style("border", "none")
|
|
97
|
+
.style("background", handle_color);
|
|
98
|
+
|
|
99
|
+
this._stylesheet.innerHTML = this._styles.print();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
export default SliderStyle;
|
package/ui-styles.js
CHANGED
|
@@ -330,8 +330,8 @@
|
|
|
330
330
|
format = (format + "").trim().toLowerCase();
|
|
331
331
|
return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
|
|
332
332
|
: l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
|
|
333
|
-
: l === 8 ?
|
|
334
|
-
: l === 4 ?
|
|
333
|
+
: l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
|
|
334
|
+
: l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000
|
|
335
335
|
: null) // invalid hex
|
|
336
336
|
: (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
|
|
337
337
|
: (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
|
|
@@ -675,15 +675,132 @@
|
|
|
675
675
|
}
|
|
676
676
|
}));
|
|
677
677
|
|
|
678
|
-
var
|
|
678
|
+
var prefix = "$";
|
|
679
|
+
|
|
680
|
+
function Map() {}
|
|
681
|
+
|
|
682
|
+
Map.prototype = map.prototype = {
|
|
683
|
+
constructor: Map,
|
|
684
|
+
has: function(key) {
|
|
685
|
+
return (prefix + key) in this;
|
|
686
|
+
},
|
|
687
|
+
get: function(key) {
|
|
688
|
+
return this[prefix + key];
|
|
689
|
+
},
|
|
690
|
+
set: function(key, value) {
|
|
691
|
+
this[prefix + key] = value;
|
|
692
|
+
return this;
|
|
693
|
+
},
|
|
694
|
+
remove: function(key) {
|
|
695
|
+
var property = prefix + key;
|
|
696
|
+
return property in this && delete this[property];
|
|
697
|
+
},
|
|
698
|
+
clear: function() {
|
|
699
|
+
for (var property in this) if (property[0] === prefix) delete this[property];
|
|
700
|
+
},
|
|
701
|
+
keys: function() {
|
|
702
|
+
var keys = [];
|
|
703
|
+
for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
|
|
704
|
+
return keys;
|
|
705
|
+
},
|
|
706
|
+
values: function() {
|
|
707
|
+
var values = [];
|
|
708
|
+
for (var property in this) if (property[0] === prefix) values.push(this[property]);
|
|
709
|
+
return values;
|
|
710
|
+
},
|
|
711
|
+
entries: function() {
|
|
712
|
+
var entries = [];
|
|
713
|
+
for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
|
|
714
|
+
return entries;
|
|
715
|
+
},
|
|
716
|
+
size: function() {
|
|
717
|
+
var size = 0;
|
|
718
|
+
for (var property in this) if (property[0] === prefix) ++size;
|
|
719
|
+
return size;
|
|
720
|
+
},
|
|
721
|
+
empty: function() {
|
|
722
|
+
for (var property in this) if (property[0] === prefix) return false;
|
|
723
|
+
return true;
|
|
724
|
+
},
|
|
725
|
+
each: function(f) {
|
|
726
|
+
for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
function map(object, f) {
|
|
731
|
+
var map = new Map;
|
|
732
|
+
|
|
733
|
+
// Copy constructor.
|
|
734
|
+
if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
|
|
735
|
+
|
|
736
|
+
// Index array by numeric index or specified key function.
|
|
737
|
+
else if (Array.isArray(object)) {
|
|
738
|
+
var i = -1,
|
|
739
|
+
n = object.length,
|
|
740
|
+
o;
|
|
741
|
+
|
|
742
|
+
if (f == null) while (++i < n) map.set(i, object[i]);
|
|
743
|
+
else while (++i < n) map.set(f(o = object[i], i, object), o);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// Convert object to map.
|
|
747
|
+
else if (object) for (var key in object) map.set(key, object[key]);
|
|
748
|
+
|
|
749
|
+
return map;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
function Set() {}
|
|
753
|
+
|
|
754
|
+
var proto = map.prototype;
|
|
755
|
+
|
|
756
|
+
Set.prototype = set.prototype = {
|
|
757
|
+
constructor: Set,
|
|
758
|
+
has: proto.has,
|
|
759
|
+
add: function(value) {
|
|
760
|
+
value += "";
|
|
761
|
+
this[prefix + value] = value;
|
|
762
|
+
return this;
|
|
763
|
+
},
|
|
764
|
+
remove: proto.remove,
|
|
765
|
+
clear: proto.clear,
|
|
766
|
+
values: proto.keys,
|
|
767
|
+
size: proto.size,
|
|
768
|
+
empty: proto.empty,
|
|
769
|
+
each: proto.each
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
function set(object, f) {
|
|
773
|
+
var set = new Set;
|
|
774
|
+
|
|
775
|
+
// Copy constructor.
|
|
776
|
+
if (object instanceof Set) object.each(function(value) { set.add(value); });
|
|
777
|
+
|
|
778
|
+
// Otherwise, assume it’s an array.
|
|
779
|
+
else if (object) {
|
|
780
|
+
var i = -1, n = object.length;
|
|
781
|
+
if (f == null) while (++i < n) set.add(object[i]);
|
|
782
|
+
else while (++i < n) set.add(f(object[i], i, object));
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
return set;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
var getTextDimensions = (function() {
|
|
679
789
|
var context = document.createElement("canvas").getContext("2d");
|
|
680
790
|
return function(text, font) {
|
|
681
791
|
context.font = font || "10px sans-serif";
|
|
682
792
|
var metrics = context.measureText(text);
|
|
683
|
-
return
|
|
793
|
+
return {
|
|
794
|
+
width: metrics.width,
|
|
795
|
+
height: metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent
|
|
796
|
+
};
|
|
684
797
|
};
|
|
685
798
|
})();
|
|
686
799
|
|
|
800
|
+
function getTextDirection() {
|
|
801
|
+
return window.getComputedStyle(document.body).direction || "ltr";
|
|
802
|
+
}
|
|
803
|
+
|
|
687
804
|
function hexToColor(hex_string, opacity) {
|
|
688
805
|
if (typeof hex_string != "string") return false;
|
|
689
806
|
var c = color(hex_string);
|
|
@@ -738,6 +855,7 @@
|
|
|
738
855
|
var background_color = this._state.background || this._layout.background_color || "#ffffff";
|
|
739
856
|
var text_color = this._state.font_color || this._layout.font_color || "#333333";
|
|
740
857
|
var border_color = hexToRgba(this._state.border_color || text_color, this._state.border_transparency);
|
|
858
|
+
var read_direction = getTextDirection();
|
|
741
859
|
|
|
742
860
|
this._styles.select(this._selector + ".fl-control.hidden")
|
|
743
861
|
.style("display", "none");
|
|
@@ -764,10 +882,14 @@
|
|
|
764
882
|
.style("border-radius", "0")
|
|
765
883
|
.style("margin", "0");
|
|
766
884
|
|
|
767
|
-
|
|
885
|
+
var is_rtl = read_direction === "rtl";
|
|
886
|
+
var left_most_button_selector = is_rtl ? ":last-child" : ":first-child";
|
|
887
|
+
var right_most_button_selector = is_rtl ? ":first-child" : ":last-child";
|
|
888
|
+
|
|
889
|
+
this._styles.select(this._selector + ".grouped.fl-control .button" + left_most_button_selector)
|
|
768
890
|
.style("border-radius", this._state.border_radius + "px 0 0 " + this._state.border_radius + "px");
|
|
769
891
|
|
|
770
|
-
this._styles.select(this._selector + ".grouped.fl-control .button
|
|
892
|
+
this._styles.select(this._selector + ".grouped.fl-control .button" + right_most_button_selector)
|
|
771
893
|
.style("border-radius", "0 " + this._state.border_radius + "px " + this._state.border_radius + "px 0")
|
|
772
894
|
.style("border-right", this._state.border_width + "px solid " + border_color);
|
|
773
895
|
|
|
@@ -834,7 +956,8 @@
|
|
|
834
956
|
.style("border-radius", this._state.border_style == "bottom" ? null : this._state.border_radius + "px");
|
|
835
957
|
|
|
836
958
|
this._styles.select(this._selector + ":after")
|
|
837
|
-
.style("right", this._state.border_style == "bottom" ? null : this._state.border_width + 5 + "px")
|
|
959
|
+
.style("right", this._state.border_style == "bottom" ? null : this._state.border_width + 5 + "px")
|
|
960
|
+
.style("color", text_color);
|
|
838
961
|
|
|
839
962
|
this._styles.select(this._selector + " .main .current")
|
|
840
963
|
.style("line-height", "1em")
|
|
@@ -882,6 +1005,108 @@
|
|
|
882
1005
|
this._stylesheet.innerHTML = this._styles.print();
|
|
883
1006
|
};
|
|
884
1007
|
|
|
1008
|
+
function remToPx(rem) {
|
|
1009
|
+
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
var DEFAULTS$3 = Object.freeze({
|
|
1013
|
+
width: 15,
|
|
1014
|
+
play_color: null,
|
|
1015
|
+
handle_color: null,
|
|
1016
|
+
font_color: null,
|
|
1017
|
+
track_color: null,
|
|
1018
|
+
|
|
1019
|
+
handle_height: 1,
|
|
1020
|
+
track_height: 0.2,
|
|
1021
|
+
margin: 4.5,
|
|
1022
|
+
|
|
1023
|
+
play_button: true
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
function SliderStyle(state_, selector_, layout_) {
|
|
1027
|
+
this._state = state_;
|
|
1028
|
+
for (var key in DEFAULTS$3) { if (this._state[key] === undefined) this._state[key] = DEFAULTS$3[key]; }
|
|
1029
|
+
|
|
1030
|
+
this._layout = layout_ || {};
|
|
1031
|
+
|
|
1032
|
+
this._styles = new Stylesheet();
|
|
1033
|
+
this._selector = selector_;
|
|
1034
|
+
this._createStylesheet();
|
|
1035
|
+
|
|
1036
|
+
return this;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
SliderStyle.prototype._createStylesheet = function() {
|
|
1040
|
+
this._stylesheet = document.createElement("style");
|
|
1041
|
+
this._stylesheet.className = "fl-ui-styles-slider";
|
|
1042
|
+
document.head.appendChild(this._stylesheet);
|
|
1043
|
+
};
|
|
1044
|
+
|
|
1045
|
+
SliderStyle.prototype.update = function() {
|
|
1046
|
+
this._styles.clear();
|
|
1047
|
+
|
|
1048
|
+
var track_color = this._state.track_color || "#dddddd";
|
|
1049
|
+
var text_color = this._state.font_color || this._layout.font_color || "currentColor";
|
|
1050
|
+
var slider_color = "currentColor"; // So that handle can inherit layout text color via this parent
|
|
1051
|
+
var handle_color = this._state.handle_color || this._layout.font_color || "currentColor";
|
|
1052
|
+
var play_color = this._state.play_color || this._layout.font_color || "currentColor";
|
|
1053
|
+
|
|
1054
|
+
var slider_width = Math.round(remToPx(this._state.width));
|
|
1055
|
+
var handle_radius = Math.round(remToPx(this._state.handle_height));
|
|
1056
|
+
var track_height = remToPx(this._state.track_height);
|
|
1057
|
+
|
|
1058
|
+
this._styles.select(this._selector + " .fl-controls-slider")
|
|
1059
|
+
.style("height", handle_radius * 2 + "px");
|
|
1060
|
+
|
|
1061
|
+
this._styles.select(this._selector + " .slider-play")
|
|
1062
|
+
.style("fill", play_color)
|
|
1063
|
+
.style("width", handle_radius + "px")
|
|
1064
|
+
.style("height", handle_radius + "px")
|
|
1065
|
+
.style("display", this._state.play_button ? null : "none");
|
|
1066
|
+
|
|
1067
|
+
this._styles.select(this._selector + " .slider-label")
|
|
1068
|
+
.style("padding-inline-start", "0.3rem")
|
|
1069
|
+
.style("color", text_color);
|
|
1070
|
+
|
|
1071
|
+
this._styles.select(this._selector + " input[type=range]")
|
|
1072
|
+
.style("-webkit-appearance", "none")
|
|
1073
|
+
.style("width", slider_width + "px")
|
|
1074
|
+
.style("color", slider_color)
|
|
1075
|
+
.style("background-color", "transparent");
|
|
1076
|
+
|
|
1077
|
+
// Chrome/Edge
|
|
1078
|
+
this._styles.select(this._selector + " input[type=range]::-webkit-slider-runnable-track")
|
|
1079
|
+
.style("-webkit-appearance", "none")
|
|
1080
|
+
.style("background", track_color)
|
|
1081
|
+
.style("border-radius", "100px")
|
|
1082
|
+
.style("height", track_height + "px");
|
|
1083
|
+
|
|
1084
|
+
this._styles.select(this._selector + " input[type=range]::-webkit-slider-thumb")
|
|
1085
|
+
.style("-webkit-appearance", "none")
|
|
1086
|
+
.style("width", handle_radius + "px")
|
|
1087
|
+
.style("height", handle_radius + "px")
|
|
1088
|
+
.style("border-radius", "100px")
|
|
1089
|
+
.style("background", handle_color)
|
|
1090
|
+
.style("margin-top", -handle_radius/2 + track_height/2 + "px");
|
|
1091
|
+
|
|
1092
|
+
// Firefox
|
|
1093
|
+
this._styles.select(this._selector + " input[type=range]::-moz-range-track")
|
|
1094
|
+
.style("-webkit-appearance", "none")
|
|
1095
|
+
.style("background", track_color)
|
|
1096
|
+
.style("border-radius", "100px")
|
|
1097
|
+
.style("height", track_height + "px");
|
|
1098
|
+
|
|
1099
|
+
this._styles.select(this._selector + " input[type=range]::-moz-range-thumb")
|
|
1100
|
+
.style("-webkit-appearance", "none")
|
|
1101
|
+
.style("width", handle_radius + "px")
|
|
1102
|
+
.style("height", handle_radius + "px")
|
|
1103
|
+
.style("border-radius", "100px")
|
|
1104
|
+
.style("border", "none")
|
|
1105
|
+
.style("background", handle_color);
|
|
1106
|
+
|
|
1107
|
+
this._stylesheet.innerHTML = this._styles.print();
|
|
1108
|
+
};
|
|
1109
|
+
|
|
885
1110
|
function createGeneralControlsStyle(state, selector, layout) {
|
|
886
1111
|
return new GeneralControlsStyle(state, selector, layout);
|
|
887
1112
|
}
|
|
@@ -894,9 +1119,14 @@
|
|
|
894
1119
|
return new DropdownStyle(state, selector, layout);
|
|
895
1120
|
}
|
|
896
1121
|
|
|
1122
|
+
function createSliderStyle(state, selector, layout) {
|
|
1123
|
+
return new SliderStyle(state, selector, layout);
|
|
1124
|
+
}
|
|
1125
|
+
|
|
897
1126
|
exports.createButtonStyle = createButtonStyle;
|
|
898
1127
|
exports.createDropdownStyle = createDropdownStyle;
|
|
899
1128
|
exports.createGeneralControlsStyle = createGeneralControlsStyle;
|
|
1129
|
+
exports.createSliderStyle = createSliderStyle;
|
|
900
1130
|
|
|
901
1131
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
902
1132
|
|