@flourish/ui-styles 3.0.0 → 4.0.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 CHANGED
@@ -46,7 +46,7 @@ The init function takes the state object as a first argument. The second argumen
46
46
 
47
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
48
 
49
- Then in the update function, make sure to update the styles with `update()`.
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).
50
50
 
51
51
  ```js
52
52
  controlsStyle.update();
package/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 4.0.0
2
+ * Move slider width setting from @flourish/ui-styles to @flourish/controls [BREAKING] For use with version 8.0.0+ of @flourish/controls
3
+
4
+ # 3.1.0
5
+ * Add support for right-to-left read direction to button border radius styles
6
+ * Update @flourish/pocket-knife to v1.0.0
7
+
1
8
  # 3.0.0
2
9
  * 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
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flourish/ui-styles",
3
- "version": "3.0.0",
3
+ "version": "4.0.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.5.0",
17
+ "@flourish/pocket-knife": "^1.0.0",
18
18
  "d3-selection": "^1.4.0"
19
19
  },
20
20
  "devDependencies": {
@@ -19,12 +19,6 @@
19
19
  width: quarter
20
20
  optional: true
21
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
22
  - property: track_height
29
23
  name: Track height
30
24
  type: number
@@ -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
- this._styles.select(this._selector + ".grouped.fl-control .button:first-child")
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:last-child")
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
 
@@ -2,7 +2,6 @@ import { remToPx } from "../lib/remToPx";
2
2
  import Stylesheet from "../lib/js2css";
3
3
 
4
4
  var DEFAULTS = Object.freeze({
5
- width: 15,
6
5
  play_color: null,
7
6
  handle_color: null,
8
7
  font_color: null,
@@ -43,7 +42,6 @@ SliderStyle.prototype.update = function() {
43
42
  var handle_color = this._state.handle_color || this._layout.font_color || "currentColor";
44
43
  var play_color = this._state.play_color || this._layout.font_color || "currentColor";
45
44
 
46
- var slider_width = Math.round(remToPx(this._state.width));
47
45
  var handle_radius = Math.round(remToPx(this._state.handle_height));
48
46
  var track_height = remToPx(this._state.track_height);
49
47
 
@@ -62,7 +60,6 @@ SliderStyle.prototype.update = function() {
62
60
 
63
61
  this._styles.select(this._selector + " input[type=range]")
64
62
  .style("-webkit-appearance", "none")
65
- .style("width", slider_width + "px")
66
63
  .style("color", slider_color)
67
64
  .style("background-color", "transparent");
68
65
 
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 ? new Rgb(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
334
- : l === 4 ? new Rgb((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000
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 getTextWidth = (function() {
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 metrics.width;
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
- this._styles.select(this._selector + ".grouped.fl-control .button:first-child")
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:last-child")
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
 
@@ -888,7 +1010,6 @@
888
1010
  }
889
1011
 
890
1012
  var DEFAULTS$3 = Object.freeze({
891
- width: 15,
892
1013
  play_color: null,
893
1014
  handle_color: null,
894
1015
  font_color: null,
@@ -929,7 +1050,6 @@
929
1050
  var handle_color = this._state.handle_color || this._layout.font_color || "currentColor";
930
1051
  var play_color = this._state.play_color || this._layout.font_color || "currentColor";
931
1052
 
932
- var slider_width = Math.round(remToPx(this._state.width));
933
1053
  var handle_radius = Math.round(remToPx(this._state.handle_height));
934
1054
  var track_height = remToPx(this._state.track_height);
935
1055
 
@@ -948,7 +1068,6 @@
948
1068
 
949
1069
  this._styles.select(this._selector + " input[type=range]")
950
1070
  .style("-webkit-appearance", "none")
951
- .style("width", slider_width + "px")
952
1071
  .style("color", slider_color)
953
1072
  .style("background-color", "transparent");
954
1073