@flourish/ui-styles 3.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 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,7 @@
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
+
1
5
  # 3.0.0
2
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
3
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flourish/ui-styles",
3
- "version": "3.0.0",
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.5.0",
17
+ "@flourish/pocket-knife": "^1.0.0",
18
18
  "d3-selection": "^1.4.0"
19
19
  },
20
20
  "devDependencies": {
@@ -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
 
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