plotboilerplate 1.24.0 → 1.26.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.
Files changed (222) hide show
  1. package/README.md +14 -1
  2. package/dist/index.esm.js +433 -162
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +12312 -12041
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +9 -5
  11. package/src/cjs/Bounds.d.ts +79 -25
  12. package/src/cjs/Bounds.js +102 -29
  13. package/src/cjs/Bounds.js.map +1 -1
  14. package/src/cjs/CircleSector.d.ts +3 -0
  15. package/src/cjs/CircleSector.js +28 -1
  16. package/src/cjs/CircleSector.js.map +1 -1
  17. package/src/cjs/PlotBoilerplate.d.ts +37 -6
  18. package/src/cjs/PlotBoilerplate.js +222 -116
  19. package/src/cjs/PlotBoilerplate.js.map +1 -1
  20. package/src/cjs/Polygon.d.ts +26 -7
  21. package/src/cjs/Polygon.js +56 -10
  22. package/src/cjs/Polygon.js.map +1 -1
  23. package/src/cjs/Triangle.js +2 -2
  24. package/src/cjs/Triangle.js.map +1 -1
  25. package/src/cjs/Vertex.d.ts +15 -3
  26. package/src/cjs/Vertex.js +18 -1
  27. package/src/cjs/Vertex.js.map +1 -1
  28. package/src/cjs/drawutilssvg.d.ts +2 -1
  29. package/src/cjs/drawutilssvg.js +9 -3
  30. package/src/cjs/drawutilssvg.js.map +1 -1
  31. package/src/cjs/interfaces/core.d.ts +28 -0
  32. package/src/cjs/interfaces/core.js +2 -0
  33. package/src/cjs/interfaces/core.js.map +1 -1
  34. package/src/cjs/utils/LissajousFigure.d.ts +34 -0
  35. package/src/cjs/utils/LissajousFigure.js +100 -0
  36. package/src/cjs/utils/LissajousFigure.js.map +1 -0
  37. package/src/cjs/utils/PerlinNoise.d.ts +19 -0
  38. package/src/cjs/utils/PerlinNoise.js +352 -0
  39. package/src/cjs/utils/PerlinNoise.js.map +1 -0
  40. package/src/cjs/utils/SVGPathUtils.d.ts +22 -0
  41. package/src/cjs/utils/SVGPathUtils.js +45 -0
  42. package/src/cjs/utils/SVGPathUtils.js.map +1 -0
  43. package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.d.ts +23 -0
  44. package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.js +270 -0
  45. package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.js.map +1 -0
  46. package/src/cjs/utils/datastructures/Color.d.ts +147 -1
  47. package/src/cjs/utils/datastructures/Color.js +385 -41
  48. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  49. package/src/cjs/utils/datastructures/ColorGradient.d.ts +79 -0
  50. package/src/cjs/utils/datastructures/ColorGradient.js +171 -0
  51. package/src/cjs/utils/datastructures/ColorGradient.js.map +1 -0
  52. package/src/cjs/utils/datastructures/DataGrid2d.d.ts +6 -0
  53. package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.d.ts +88 -0
  54. package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.js +155 -0
  55. package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.js.map +1 -0
  56. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +1 -7
  57. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +3 -3
  58. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
  59. package/src/cjs/utils/datastructures/GeometryMesh.d.ts +49 -0
  60. package/src/cjs/utils/datastructures/GeometryMesh.js +58 -0
  61. package/src/cjs/utils/datastructures/GeometryMesh.js.map +1 -0
  62. package/src/cjs/utils/detectDarkMode.js +16 -7
  63. package/src/cjs/utils/detectDarkMode.js.map +1 -1
  64. package/src/cjs/utils/dom/components/ColorGradientPicker.d.ts +246 -0
  65. package/src/cjs/utils/dom/components/ColorGradientPicker.js +667 -0
  66. package/src/cjs/utils/dom/components/ColorGradientPicker.js.map +1 -0
  67. package/src/cjs/utils/dom/components/ColorGradientPickerJSX.d.ts +129 -0
  68. package/src/cjs/utils/dom/components/ColorGradientPickerJSX.js +520 -0
  69. package/src/cjs/utils/dom/components/ColorGradientPickerJSX.js.map +1 -0
  70. package/src/cjs/utils/dom/components/ColorGradientSelector.d.ts +118 -0
  71. package/src/cjs/utils/dom/components/ColorGradientSelector.js +327 -0
  72. package/src/cjs/utils/dom/components/ColorGradientSelector.js.map +1 -0
  73. package/src/cjs/utils/dom/components/Test.d.ts +7 -0
  74. package/src/cjs/utils/dom/components/Test.js +30 -0
  75. package/src/cjs/utils/dom/components/Test.js.map +1 -0
  76. package/src/cjs/utils/dom/guiSizeToggler.js +1 -1
  77. package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
  78. package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +9 -3
  79. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +20 -13
  80. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  81. package/src/cjs/utils/helpers/CircleHelper.d.ts +10 -1
  82. package/src/cjs/utils/helpers/CircleHelper.js +13 -2
  83. package/src/cjs/utils/helpers/CircleHelper.js.map +1 -1
  84. package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +2 -2
  85. package/src/cjs/utils/helpers/CircleSectorHelper.js +1 -0
  86. package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
  87. package/src/cjs/utils/helpers/TriangleHelper.d.ts +57 -0
  88. package/src/cjs/utils/helpers/TriangleHelper.js +83 -0
  89. package/src/cjs/utils/helpers/TriangleHelper.js.map +1 -0
  90. package/src/cjs/utils/helpers/VEllipseHelper.d.ts +6 -4
  91. package/src/cjs/utils/helpers/VEllipseHelper.js +4 -2
  92. package/src/cjs/utils/helpers/VEllipseHelper.js.map +1 -1
  93. package/src/cjs/utils/helpers/VEllipseSectorHelper.d.ts +3 -2
  94. package/src/cjs/utils/helpers/VEllipseSectorHelper.js +1 -0
  95. package/src/cjs/utils/helpers/VEllipseSectorHelper.js.map +1 -1
  96. package/src/cjs/utils/parsers/LinearColorGradientParser.d.ts +78 -0
  97. package/src/cjs/utils/parsers/LinearColorGradientParser.js +224 -0
  98. package/src/cjs/utils/parsers/LinearColorGradientParser.js.map +1 -0
  99. package/src/cjs/utils/parsers/svg/types.d.ts +8 -8
  100. package/src/createDemoDrawables.js +1 -0
  101. package/src/esm/Bounds.d.ts +79 -25
  102. package/src/esm/Bounds.js +102 -29
  103. package/src/esm/Bounds.js.map +1 -1
  104. package/src/esm/CircleSector.d.ts +3 -0
  105. package/src/esm/CircleSector.js +28 -1
  106. package/src/esm/CircleSector.js.map +1 -1
  107. package/src/esm/PlotBoilerplate.d.ts +37 -6
  108. package/src/esm/PlotBoilerplate.js +222 -116
  109. package/src/esm/PlotBoilerplate.js.map +1 -1
  110. package/src/esm/Polygon.d.ts +26 -7
  111. package/src/esm/Polygon.js +53 -10
  112. package/src/esm/Polygon.js.map +1 -1
  113. package/src/esm/Triangle.js +2 -2
  114. package/src/esm/Triangle.js.map +1 -1
  115. package/src/esm/Vertex.d.ts +15 -3
  116. package/src/esm/Vertex.js +18 -1
  117. package/src/esm/Vertex.js.map +1 -1
  118. package/src/esm/drawutilssvg.d.ts +2 -1
  119. package/src/esm/drawutilssvg.js +9 -3
  120. package/src/esm/drawutilssvg.js.map +1 -1
  121. package/src/esm/interfaces/core.d.ts +28 -0
  122. package/src/esm/interfaces/core.js +2 -0
  123. package/src/esm/interfaces/core.js.map +1 -1
  124. package/src/esm/utils/LissajousFigure.d.ts +34 -0
  125. package/src/esm/utils/LissajousFigure.js +95 -0
  126. package/src/esm/utils/LissajousFigure.js.map +1 -0
  127. package/src/esm/utils/PerlinNoise.d.ts +19 -0
  128. package/src/esm/utils/PerlinNoise.js +346 -0
  129. package/src/esm/utils/PerlinNoise.js.map +1 -0
  130. package/src/esm/utils/SVGPathUtils.d.ts +22 -0
  131. package/src/esm/utils/SVGPathUtils.js +42 -0
  132. package/src/esm/utils/SVGPathUtils.js.map +1 -0
  133. package/src/esm/utils/algorithms/pixelCornersToRoundPaths.d.ts +23 -0
  134. package/src/esm/utils/algorithms/pixelCornersToRoundPaths.js +266 -0
  135. package/src/esm/utils/algorithms/pixelCornersToRoundPaths.js.map +1 -0
  136. package/src/esm/utils/datastructures/Color.d.ts +147 -1
  137. package/src/esm/utils/datastructures/Color.js +386 -42
  138. package/src/esm/utils/datastructures/Color.js.map +1 -1
  139. package/src/esm/utils/datastructures/ColorGradient.d.ts +79 -0
  140. package/src/esm/utils/datastructures/ColorGradient.js +166 -0
  141. package/src/esm/utils/datastructures/ColorGradient.js.map +1 -0
  142. package/src/esm/utils/datastructures/DataGrid2d.d.ts +6 -0
  143. package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.d.ts +88 -0
  144. package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.js +150 -0
  145. package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.js.map +1 -0
  146. package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +1 -7
  147. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js +3 -3
  148. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
  149. package/src/esm/utils/datastructures/GeometryMesh.d.ts +49 -0
  150. package/src/esm/utils/datastructures/GeometryMesh.js +53 -0
  151. package/src/esm/utils/datastructures/GeometryMesh.js.map +1 -0
  152. package/src/esm/utils/detectDarkMode.js +16 -7
  153. package/src/esm/utils/detectDarkMode.js.map +1 -1
  154. package/src/esm/utils/dom/components/ColorGradientPicker.d.ts +246 -0
  155. package/src/esm/utils/dom/components/ColorGradientPicker.js +743 -0
  156. package/src/esm/utils/dom/components/ColorGradientPicker.js.map +1 -0
  157. package/src/esm/utils/dom/components/ColorGradientPickerJSX.d.ts +129 -0
  158. package/src/esm/utils/dom/components/ColorGradientPickerJSX.js +582 -0
  159. package/src/esm/utils/dom/components/ColorGradientPickerJSX.js.map +1 -0
  160. package/src/esm/utils/dom/components/ColorGradientSelector.d.ts +118 -0
  161. package/src/esm/utils/dom/components/ColorGradientSelector.js +339 -0
  162. package/src/esm/utils/dom/components/ColorGradientSelector.js.map +1 -0
  163. package/src/esm/utils/dom/components/Test.d.ts +7 -0
  164. package/src/esm/utils/dom/components/Test.js +26 -0
  165. package/src/esm/utils/dom/components/Test.js.map +1 -0
  166. package/src/esm/utils/dom/guiSizeToggler.js +1 -1
  167. package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
  168. package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +9 -3
  169. package/src/esm/utils/helpers/BezierPathInteractionHelper.js +20 -13
  170. package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  171. package/src/esm/utils/helpers/CircleHelper.d.ts +10 -1
  172. package/src/esm/utils/helpers/CircleHelper.js +13 -2
  173. package/src/esm/utils/helpers/CircleHelper.js.map +1 -1
  174. package/src/esm/utils/helpers/CircleSectorHelper.d.ts +2 -2
  175. package/src/esm/utils/helpers/CircleSectorHelper.js +1 -0
  176. package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
  177. package/src/esm/utils/helpers/TriangleHelper.d.ts +57 -0
  178. package/src/esm/utils/helpers/TriangleHelper.js +78 -0
  179. package/src/esm/utils/helpers/TriangleHelper.js.map +1 -0
  180. package/src/esm/utils/helpers/VEllipseHelper.d.ts +6 -4
  181. package/src/esm/utils/helpers/VEllipseHelper.js +4 -2
  182. package/src/esm/utils/helpers/VEllipseHelper.js.map +1 -1
  183. package/src/esm/utils/helpers/VEllipseSectorHelper.d.ts +3 -2
  184. package/src/esm/utils/helpers/VEllipseSectorHelper.js +1 -0
  185. package/src/esm/utils/helpers/VEllipseSectorHelper.js.map +1 -1
  186. package/src/esm/utils/parsers/LinearColorGradientParser.d.ts +78 -0
  187. package/src/esm/utils/parsers/LinearColorGradientParser.js +217 -0
  188. package/src/esm/utils/parsers/LinearColorGradientParser.js.map +1 -0
  189. package/src/esm/utils/parsers/svg/types.d.ts +8 -8
  190. package/src/external.d.ts +9 -0
  191. package/src/ts/Bounds.ts +107 -22
  192. package/src/ts/CircleSector.ts +39 -6
  193. package/src/ts/PlotBoilerplate.ts +233 -105
  194. package/src/ts/Polygon.ts +68 -14
  195. package/src/ts/Triangle.ts +2 -2
  196. package/src/ts/Vertex.ts +21 -3
  197. package/src/ts/drawutilssvg.ts +8 -3
  198. package/src/ts/interfaces/core.ts +31 -0
  199. package/src/ts/utils/LissajousFigure.ts +110 -0
  200. package/src/ts/utils/PerlinNoise.ts +368 -0
  201. package/src/ts/utils/SVGPathUtils.ts +55 -0
  202. package/src/ts/utils/algorithms/pixelCornersToRoundPaths.ts +379 -0
  203. package/src/ts/utils/datastructures/Color.ts +423 -44
  204. package/src/ts/utils/datastructures/ColorGradient.ts +196 -0
  205. package/src/ts/utils/datastructures/DataGrid2d.ts +7 -0
  206. package/src/ts/utils/datastructures/DataGrid2dArrayMatrix.ts +182 -0
  207. package/src/ts/utils/datastructures/DataGrid2dListAdapter.ts +4 -11
  208. package/src/ts/utils/datastructures/GeometryMesh.ts +79 -0
  209. package/src/ts/utils/detectDarkMode.ts +17 -8
  210. package/src/ts/utils/dom/components/ColorGradientPicker.tsx +889 -0
  211. package/src/ts/utils/dom/components/ColorGradientSelector.tsx +452 -0
  212. package/src/ts/utils/dom/components/Test.tsx +44 -0
  213. package/src/ts/utils/dom/components/_ColorGradientPicker_raw.ts_ +392 -0
  214. package/src/ts/utils/dom/guiSizeToggler.ts +1 -1
  215. package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +25 -15
  216. package/src/ts/utils/helpers/CircleHelper.ts +17 -3
  217. package/src/ts/utils/helpers/CircleSectorHelper.ts +4 -2
  218. package/src/ts/utils/helpers/TriangleHelper.ts +102 -0
  219. package/src/ts/utils/helpers/VEllipseHelper.ts +6 -4
  220. package/src/ts/utils/helpers/VEllipseSectorHelper.ts +3 -2
  221. package/src/ts/utils/parsers/LinearColorGradientParser.ts +297 -0
  222. package/src/ts/utils/parsers/svg/types.ts +8 -8
@@ -0,0 +1,667 @@
1
+ "use strict";
2
+ /**
3
+ * Approach for a 'simple' color gradient picker for my PlotBoilerplate library.
4
+ *
5
+ * As it turned out a bit more complex in the end – due to the fact that color gradient
6
+ * picking is not a super simple task – so I used JSX here. Thus a JSX library is required
7
+ * to get this running: NoReact.
8
+ *
9
+ *
10
+ * @author Ikaros Kappler
11
+ * @date 2025-06-27
12
+ * @modified 2025-09-10 Fixing a color select bug on MacOS.
13
+ * @version 1.0.0
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.ColorGradientPicker = void 0;
17
+ var NoReact = require("noreact");
18
+ var Color_1 = require("../../datastructures/Color");
19
+ var ColorGradient_1 = require("../../datastructures/ColorGradient");
20
+ var ColorGradientPicker = /** @class */ (function () {
21
+ /**
22
+ * The constructor: creates a new color gradient picker in the given container.
23
+ * If no container or ID is given then a new unbound `container` will be created (DIV).
24
+ *
25
+ * Pass a container ID or nothing – in the latter case the constructor will create
26
+ * a new DIV element.
27
+ *
28
+ * @param {string?} containerID - (optional) If you want to use an existing container (should be a DIV).
29
+ * @param {boolean?} isMobileMode - (optional) If `true` then the elements are rendered in double size.
30
+ */
31
+ function ColorGradientPicker(containerID, isMobileMode) {
32
+ var _this = this;
33
+ this._sliderElementRefs = [];
34
+ this.sliderMin = 0;
35
+ this.sliderMax = 100;
36
+ // Only used during initialization!
37
+ this.isMobileMode = false;
38
+ this.css_indicatorWidth_num = 1.0;
39
+ this.css_indicatorWidth = "1em";
40
+ this.css_indicatorHeight = "1em";
41
+ this.css_thumbWidth = "0.5em";
42
+ this.css_thumbHeight = "1.333em";
43
+ this.css_containerHeight = "20px";
44
+ this.installedChangeListeners = [];
45
+ this.__mouseDownPosition = null;
46
+ /**
47
+ * Creates a callback function for range slider.
48
+ *
49
+ * @returns
50
+ */
51
+ this.__createSliderChangeHandler = function () {
52
+ var _self = _this;
53
+ return function (e) {
54
+ var targetSlider = e.target;
55
+ // console.log("Clicked", targetSlider ? targetSlider.getAttribute("id") : null);
56
+ if (!targetSlider) {
57
+ return false;
58
+ }
59
+ var currentSliderValue = Number.parseFloat(targetSlider.value);
60
+ var rangeSliderIndexRaw = targetSlider.dataset["rangeSliderIndex"];
61
+ // console.log("rangeSliderIndexRaw", rangeSliderIndexRaw);
62
+ if (!rangeSliderIndexRaw) {
63
+ return false;
64
+ }
65
+ var rangeSliderIndex = Number.parseInt(rangeSliderIndexRaw);
66
+ var leftSliderValue = _this.__getSliderValue(rangeSliderIndex - 1, _self.sliderMin);
67
+ var rightSliderValue = _this.__getSliderValue(rangeSliderIndex + 1, _self.sliderMax);
68
+ if (leftSliderValue >= currentSliderValue) {
69
+ targetSlider.value = "".concat(leftSliderValue);
70
+ _self.__updateBackgroundGradient();
71
+ _self.__updateColorIndicator(rangeSliderIndex);
72
+ return false;
73
+ }
74
+ else if (rightSliderValue <= currentSliderValue) {
75
+ targetSlider.value = "".concat(rightSliderValue);
76
+ _self.__updateBackgroundGradient();
77
+ _self.__updateColorIndicator(rangeSliderIndex);
78
+ return false;
79
+ }
80
+ else {
81
+ _self.__updateBackgroundGradient();
82
+ _self.__updateColorIndicator(rangeSliderIndex);
83
+ return true;
84
+ }
85
+ };
86
+ };
87
+ /**
88
+ * Adds custom styles (global STYLE tag).
89
+ *
90
+ * @private
91
+ */
92
+ this.__createCustomStylesElement = function () {
93
+ // Thanks to Ana Tudor
94
+ // https://css-tricks.com/multi-thumb-sliders-particular-two-thumb-case/
95
+ return (NoReact.createElement("style", null, "\n #".concat(_this.elementID, " {\n margin-top: 1em;\n }\n\n #").concat(_this.elementID, " input[type='range'] {\n\n -webkit-appearance: none;\n\n grid-column: 1;\n grid-row: 2;\n \n /* same as before */\n background: none; /* get rid of white Chrome background */\n color: #000;\n font: inherit; /* fix too small font-size in both Chrome & Firefox */\n margin: 0;\n pointer-events: none; /* let clicks pass through */\n }\n\n #").concat(_this.elementID, " input[type='range']::-webkit-slider-runnable-track {\n -webkit-appearance: none;\n\n background: none; /* get rid of Firefox track background */\n height: 100%;\n width: 100%;\n\n pointer-events: none;\n }\n\n #").concat(_this.elementID, " input[type='range']::-webkit-slider-thumb {\n -webkit-appearance: none;\n background: currentcolor;\n border: none; /* get rid of Firefox thumb border */\n border-radius: 6px; /* get rid of Firefox corner rounding */\n pointer-events: auto; /* catch clicks */\n width: ").concat(_this.css_thumbWidth, "; \n height: ").concat(_this.css_thumbHeight, ";\n }\n\n #").concat(_this.elementID, " input[type='range']:focus::-webkit-slider-thumb {\n border: 2px solid white;\n }\n\n #").concat(_this.elementID, " input[type='range']::-moz-range-track {\n -webkit-appearance: none;\n background: none; /* get rid of Firefox track background */\n height: 100%;\n width: 100%;\n pointer-events: none;\n }\n\n #").concat(_this.elementID, " input[type='range']::-moz-range-thumb {\n /* -webkit-appearance: none; */\n background: currentcolor;\n border: none; /* get rid of Firefox thumb border */\n border-radius: 6px; /* get rid of Firefox corner rounding */\n pointer-events: auto; /* catch clicks */\n width: ").concat(_this.css_thumbWidth, "; \n height: ").concat(_this.css_thumbHeight, ";\n }\n\n #").concat(_this.elementID, " input[type='range']:focus::-moz-range-thumb {\n border: 2px solid white;\n }\n\n #").concat(_this.elementID, " input[type='range'] {\n /* same as before */\n z-index: 1;\n }\n \n #").concat(_this.elementID, " input[type='range']:focus {\n z-index: 2;\n /* outline: dotted 1px orange; */\n color: darkorange;\n }\n\n body.darkmode #").concat(_this.elementID, " .color-remove-button { \n background-color: #1e2937;\n color: grey;\n }\n\n body.darkmode #").concat(_this.elementID, " .color-remove-button:hover,\n body.darkmode #").concat(_this.elementID, " .color-remove-button:active { \n background-color: rgba(216,216,216,0.9);\n }\n\n ")));
96
+ };
97
+ if (containerID) {
98
+ var cont = document.getElementById(containerID);
99
+ if (!cont) {
100
+ throw "Cannot create ColorGradientPicker. Component ID does not exist.";
101
+ }
102
+ this.container = cont;
103
+ }
104
+ else {
105
+ this.container = document.createElement("div");
106
+ }
107
+ this.baseID = Math.floor(Math.random() * 65535);
108
+ this.elementID = "color-gradient-picker-".concat(this.baseID);
109
+ this.colorGradient = ColorGradient_1.ColorGradient.createDefault();
110
+ this.isMobileMode = Boolean(isMobileMode);
111
+ if (isMobileMode) {
112
+ // Double size :)
113
+ this.css_indicatorWidth_num = 2.0;
114
+ this.css_indicatorWidth = "2em";
115
+ this.css_indicatorHeight = "2em";
116
+ this.css_thumbWidth = "1.0em";
117
+ this.css_thumbHeight = "2.666em";
118
+ this.css_containerHeight = "40px";
119
+ }
120
+ document.head.appendChild(this.__createCustomStylesElement());
121
+ this.container.append(this._render());
122
+ this.__initializeDataSets();
123
+ this.__updateColorIndicator(0);
124
+ this.__updateBackgroundGradient();
125
+ } // END constructor
126
+ ColorGradientPicker.prototype.setGradient = function (gradient, fireChangeEvent) {
127
+ // We are lazy: just throw away everything and rebuild all.
128
+ this.__removeAllChildNodes(this.container);
129
+ this.colorGradient = gradient;
130
+ this.container.append(this._render());
131
+ this.__initializeDataSets();
132
+ this.__updateColorIndicator(0);
133
+ this.__updateBackgroundGradient();
134
+ if (fireChangeEvent) {
135
+ this.__fireChangeEvent();
136
+ }
137
+ };
138
+ // +---------------------------------------------------------------------------------
139
+ // | A helper function to remove all child nodes.
140
+ // +-------------------------------
141
+ ColorGradientPicker.prototype.__removeAllChildNodes = function (node) {
142
+ while (node.lastChild) {
143
+ node.removeChild(node.lastChild);
144
+ }
145
+ };
146
+ // +---------------------------------------------------------------------------------
147
+ // | Used during initialization: define dataset values for each slider.
148
+ // +-------------------------------
149
+ ColorGradientPicker.prototype.__initializeDataSets = function () {
150
+ for (var i = 0; i < this._sliderElementRefs.length; i++) {
151
+ var sliderColor = this.colorGradient.values[i].color;
152
+ // console.log("Setting up slider color data set", i, sliderColor, sliderColor.cssRGB(), sliderColor.cssHEX());
153
+ this._sliderElementRefs[i].current.dataset.colorValue = sliderColor.cssRGB();
154
+ this._sliderElementRefs[i].current.dataset.colorValueHEX = sliderColor.cssHEX();
155
+ }
156
+ };
157
+ /**
158
+ * Adds a new color gradient change listener to this ColorGradientPicker.
159
+ *
160
+ * @param {ColorGradientChangeListener} listener - The listener to add.
161
+ * @returns {boolean} True, if the listener was added and did not exist before.
162
+ */
163
+ ColorGradientPicker.prototype.addChangeListener = function (listener) {
164
+ for (var i = 0; i < this.installedChangeListeners.length; i++) {
165
+ if (this.installedChangeListeners[i] === listener) {
166
+ return false;
167
+ }
168
+ }
169
+ this.installedChangeListeners.push(listener);
170
+ return true;
171
+ };
172
+ /**
173
+ *
174
+ * @param {ColorGradientChangeListener} listener The listener to remove.
175
+ * @returns {boolean} True, if the listener existed and has been removed.
176
+ */
177
+ ColorGradientPicker.prototype.removeChangeListener = function (listener) {
178
+ for (var i = 0; i < this.installedChangeListeners.length; i++) {
179
+ if (this.installedChangeListeners[i] === listener) {
180
+ this.installedChangeListeners.splice(i, 1);
181
+ return true;
182
+ }
183
+ }
184
+ return false;
185
+ };
186
+ /**
187
+ * Fires a change event to all installed listeners.
188
+ */
189
+ ColorGradientPicker.prototype.__fireChangeEvent = function () {
190
+ var newColorGradient = this.getColorGradient();
191
+ for (var i = 0; i < this.installedChangeListeners.length; i++) {
192
+ this.installedChangeListeners[i](newColorGradient, this);
193
+ }
194
+ };
195
+ /**
196
+ * Creates a new color range input element.
197
+ *
198
+ * @private
199
+ * @param {number} baseID
200
+ * @param index
201
+ * @param sliderMin
202
+ * @param sliderMax
203
+ * @param initialValue
204
+ * @param initialColor
205
+ * @returns
206
+ */
207
+ ColorGradientPicker.prototype.__createColorRangeInput = function (index, sliderMin, sliderMax, initialValue, initialColor) {
208
+ var sliderHandler = this.__createSliderChangeHandler();
209
+ var ref = NoReact.useRef();
210
+ // this._sliderElementRefs.push(ref);
211
+ this._sliderElementRefs.splice(index, 0, ref);
212
+ // console.log("new _sliderElementRefs", this._sliderElementRefs);
213
+ // Update all elements to the right of the new elelemt
214
+ this.__updateSliderDataSetIndices(index + 1);
215
+ return (NoReact.createElement("input", { id: "rage-slider-".concat(this.baseID, "-").concat(index), type: "range", min: sliderMin, max: sliderMax, value: initialValue, style: { pos: "absolute", l: "0px", t: "0px", w: "100%", h: "60%" }, "data-range-slider-index": "".concat(index), "data-colorValue": initialColor.cssRGB(), "data-colorValueHEX": initialColor.cssHEX(), onChange: sliderHandler, onClick: sliderHandler, ref: ref }));
216
+ };
217
+ /**
218
+ * Get the absolute length of this range, in slider units.
219
+ * @returns
220
+ */
221
+ ColorGradientPicker.prototype.getRangeLength = function () {
222
+ return this.sliderMax - this.sliderMin;
223
+ };
224
+ /**
225
+ * Handles color value changes.
226
+ *
227
+ * @returns
228
+ */
229
+ ColorGradientPicker.prototype.__colorChangeHandler = function () {
230
+ var _this = this;
231
+ var _self = this;
232
+ return function (_evt) {
233
+ // console.log("__colorChangeHandler");
234
+ var activeSliderIndex_raw = _this.colorInputRef.current.dataset.activeSliderIndex;
235
+ if (!activeSliderIndex_raw) {
236
+ console.warn("Cannot update color indicator; no active range slider set. This is likely a program error and should not happen.");
237
+ return false;
238
+ }
239
+ var activeSliderIndex = Number.parseInt(activeSliderIndex_raw);
240
+ if (Number.isNaN(activeSliderIndex) || activeSliderIndex < 0 || activeSliderIndex >= _self._sliderElementRefs.length) {
241
+ console.warn("Cannot update color indicator; active index invalid or out of bounds. This is likely a program error and should not happen.", activeSliderIndex);
242
+ return false;
243
+ }
244
+ var newColor = _self.colorInputRef.current.value;
245
+ var rangeSlider = _self._sliderElementRefs[activeSliderIndex].current;
246
+ rangeSlider.dataset.colorValue = newColor;
247
+ // rangeSlider.dataset["colorValue"] = newColor;
248
+ _this.colorIndicatorColorButtonRef.current.style["background-color"] = newColor;
249
+ _self.__updateBackgroundGradient();
250
+ _self.__fireChangeEvent();
251
+ return true;
252
+ };
253
+ };
254
+ /**
255
+ * Removed the current color slider from the DOM and highlights the left neighbour.
256
+ *
257
+ * @returns {boolean} True if the element could be successfully removed.
258
+ */
259
+ ColorGradientPicker.prototype.__handleRemoveColor = function () {
260
+ // const colorInput : HTMLInputElement | null = evt.target;
261
+ // console.log("__colorChangeHandler");
262
+ var activeSliderIndex_raw = this.colorInputRef.current.dataset.activeSliderIndex;
263
+ if (!activeSliderIndex_raw) {
264
+ console.warn("Cannot remove color indicator; no active range slider set.");
265
+ return false;
266
+ }
267
+ var activeSliderIndex = Number.parseInt(activeSliderIndex_raw);
268
+ if (Number.isNaN(activeSliderIndex) || activeSliderIndex < 0 || activeSliderIndex >= this._sliderElementRefs.length) {
269
+ console.warn("Cannot remove color indicator; active index invalid or out of bounds.", activeSliderIndex);
270
+ return false;
271
+ }
272
+ if (activeSliderIndex === 0 || activeSliderIndex + 1 === this.getRangeLength()) {
273
+ console.warn("Cannot remove color indicator; leftmost and rightmost slider must not be removed.", activeSliderIndex);
274
+ return false;
275
+ }
276
+ var sliderElementRef = this._sliderElementRefs[activeSliderIndex];
277
+ sliderElementRef.current.remove();
278
+ this._sliderElementRefs.splice(activeSliderIndex, 1);
279
+ // Update all elements to the right of the removed elelemt
280
+ this.__updateSliderDataSetIndices(activeSliderIndex);
281
+ // Set left element active
282
+ this.__updateColorIndicator(activeSliderIndex - 1);
283
+ this.__updateBackgroundGradient();
284
+ this.__fireChangeEvent();
285
+ return true;
286
+ };
287
+ /**
288
+ * Once a slider element was added or removed then the following indices must be updated.
289
+ *
290
+ * @param {number} startIndex - The slider index to start updating at.
291
+ */
292
+ ColorGradientPicker.prototype.__updateSliderDataSetIndices = function (startIndex) {
293
+ // Update all elements to the right of the new elelemt
294
+ for (var i = startIndex; i < this._sliderElementRefs.length; i++) {
295
+ this._sliderElementRefs[i].current.setAttribute("data-range-slider-index", "".concat(i));
296
+ this._sliderElementRefs[i].current.setAttribute("id", "rage-slider-".concat(this.baseID, "-").concat(i));
297
+ }
298
+ };
299
+ /**
300
+ * To avoid too many sliders added on each click, check if the mouse was moved in the meantime (detect drag event).
301
+ *
302
+ * @returns
303
+ */
304
+ ColorGradientPicker.prototype.__containerMouseDownHandler = function () {
305
+ var _self = this;
306
+ return function (event) {
307
+ _self.__mouseDownPosition = { x: event.clientX, y: event.clientY };
308
+ // console.log("__containerMouseDownHandler _self.__mouseDownPosition", _self.__mouseDownPosition);
309
+ };
310
+ };
311
+ /**
312
+ * Creates a handler for click events on the container. If the click event is far
313
+ * enough from existing sliders, then it can be added.
314
+ *
315
+ * @returns
316
+ */
317
+ ColorGradientPicker.prototype.__containerClickHandler = function () {
318
+ var _this = this;
319
+ var _self = this;
320
+ var maxDifference = _self.getRangeLength() * 0.03;
321
+ return function (evt) {
322
+ // console.log("Container click handler");
323
+ var relativeValue = _self.__clickEventToRelativeValue(evt);
324
+ if (relativeValue < 0 || relativeValue > 1.0) {
325
+ // Clicked somewhere outside the range
326
+ return;
327
+ }
328
+ // Check if element was moved in the meantime
329
+ if (_self.__mouseDownPosition && Math.abs(_self.__mouseDownPosition.x - evt.clientX) >= 10.0) {
330
+ // Ignore event if mouse was moved more than 10 pixels between down- and up-event
331
+ // console.log("Mouse was moved more than 10 px. Cancelling.");
332
+ _self.__mouseDownPosition = null;
333
+ return;
334
+ }
335
+ var absoluteValue = _this.__relativeToAbsolute(relativeValue);
336
+ // console.log("click", "relativeValue", relativeValue, "absoluteValue", absoluteValue);
337
+ // Check if click position (ratio) is far enough away from any slider
338
+ var _a = _self.__locateClosestSliderValue(absoluteValue), leftSliderIndex = _a[0], closestSliderValue = _a[1];
339
+ var diff = Math.abs(closestSliderValue - absoluteValue);
340
+ if (diff >= maxDifference) {
341
+ // console.log("Add slider here");
342
+ _self.__addSliderAt(absoluteValue, leftSliderIndex);
343
+ }
344
+ else {
345
+ // console.debug("Don't add slider here.");
346
+ }
347
+ // Finally clear mousedown-position
348
+ _self.__mouseDownPosition = null;
349
+ };
350
+ };
351
+ /**
352
+ * Find that slider (index) that's value is closest to the given absolute value. The function will return
353
+ * the closest value and the left index, indicating the containing interval index.
354
+ *
355
+ * @param {number} absoluteValue - The value to look for.
356
+ * @returns {[number,number]} A pair of left slider index and closest value.
357
+ */
358
+ ColorGradientPicker.prototype.__locateClosestSliderValue = function (absoluteValue) {
359
+ // As the colorGradient always reflects the slider values we can just ust the color gradient itself to search.
360
+ var relativeValue = this.__absoluteToRelative(absoluteValue);
361
+ var colorGradientEntry = this.colorGradient.locateClosestRatio(relativeValue);
362
+ return [colorGradientEntry[0], this.__relativeToAbsolute(colorGradientEntry[1].ratio)];
363
+ };
364
+ /**
365
+ * Convert the click event to the relative x value in [0..1].
366
+ *
367
+ * @param {MouseEvent} evt - The mouse event.
368
+ * @returns {number} The relative x value.
369
+ */
370
+ ColorGradientPicker.prototype.__clickEventToRelativeValue = function (evt) {
371
+ var target = evt.target;
372
+ var rect = target.getBoundingClientRect();
373
+ var x = evt.clientX - rect.left; //x position within the element.
374
+ var width = rect.width; // target.clientWidth;
375
+ var relativeValue = x / width;
376
+ // console.log("width", width, "x", x, "relativeValue", relativeValue);
377
+ return relativeValue;
378
+ };
379
+ /**
380
+ * Adds a slider at the given interval index.
381
+ *
382
+ * @param {number} absoluteValue - The absolute new slider value.
383
+ * @param {number} leftSliderIndex - The new slider's position (interval index).
384
+ */
385
+ ColorGradientPicker.prototype.__addSliderAt = function (absoluteValue, leftSliderIndex) {
386
+ // console.log("__addSliderAt", "absoluteValue", absoluteValue, "leftSliderIndex", leftSliderIndex);
387
+ var leftSlider = this._sliderElementRefs[leftSliderIndex].current;
388
+ // const colorAtPosition = this.__getSliderColorAt(relativeValue);
389
+ var newColor = this.__getSliderColorAt(absoluteValue);
390
+ var newSliderIndex = leftSliderIndex + 1;
391
+ var _newSlider = this.__createColorRangeInput(newSliderIndex, this.sliderMin, this.sliderMax, absoluteValue, newColor // initialColor: string
392
+ );
393
+ var sliderRef = this._sliderElementRefs[newSliderIndex];
394
+ leftSlider.after(sliderRef.current);
395
+ sliderRef.current.dataset.colorValue = newColor.cssRGB();
396
+ sliderRef.current.dataset.colorValueHEX = newColor.cssHEX();
397
+ // No visible change, but let's reflect this in the output gradient anyway
398
+ this.__updateBackgroundGradient();
399
+ // Highlight the newly added range slider
400
+ this.__updateColorIndicator(newSliderIndex);
401
+ this.__fireChangeEvent();
402
+ };
403
+ /**
404
+ * Get the slider color at the given absolute value. That value must be inside the [MIN_VALUE, MAX_VALUE] interval.
405
+ * @param absoluteValue
406
+ * @returns
407
+ */
408
+ ColorGradientPicker.prototype.__getSliderColorAt = function (absoluteValue) {
409
+ // console.log("__getSliderColorAt", "absoluteValue", absoluteValue);
410
+ // Locate interval
411
+ var leftIndex = this.__locateIntervalAt(absoluteValue);
412
+ var leftSliderValue = this.__getSliderValue(leftIndex, NaN);
413
+ var rightSliderValue = this.__getSliderValue(leftIndex + 1, NaN);
414
+ if (Number.isNaN(leftSliderValue) || Number.isNaN(rightSliderValue)) {
415
+ console.warn("[Warn] Failed to determine left/right slider values at indices ".concat(leftIndex, " or ").concat(rightSliderValue, ". Cannot proceed for absolute value ").concat(absoluteValue, "."));
416
+ return null;
417
+ }
418
+ var leftColorString = this.__getSliderColorString(leftIndex, null);
419
+ var rightColorString = this.__getSliderColorString(leftIndex + 1, null);
420
+ if (!leftColorString || !rightColorString) {
421
+ console.warn("[Warn] Failed to determine left/right color string values at indices ".concat(leftIndex, " or ").concat(rightSliderValue, ". Cannot proceed for absolute value ").concat(absoluteValue, "."));
422
+ return null;
423
+ }
424
+ var positionInsideInterval = (absoluteValue - leftSliderValue) / (rightSliderValue - leftSliderValue);
425
+ // console.log("leftColorString", leftColorString, "rightColorString", rightColorString);
426
+ var leftColorObject = Color_1.Color.parse(leftColorString);
427
+ var rightColorObject = Color_1.Color.parse(rightColorString);
428
+ var newColor = leftColorObject.interpolate(rightColorObject, positionInsideInterval);
429
+ return newColor;
430
+ };
431
+ /**
432
+ * Locate the slider interval that contains the given (absolute) slider value. The given value must be
433
+ * somewhere between MIN_VALUE and MAX_VALUE (usually between 0 and 100 in the default configuraion.).
434
+ *
435
+ * @param {number} absoluteValue - The absolute value to search for.
436
+ * @returns {number} The left slider inder the containing interval is starting with – or -1 if out of bounds.
437
+ */
438
+ ColorGradientPicker.prototype.__locateIntervalAt = function (absoluteValue) {
439
+ for (var i = 0; i + 1 < this._sliderElementRefs.length; i++) {
440
+ if (this.__getSliderValue(i, this.sliderMin) <= absoluteValue &&
441
+ absoluteValue < this.__getSliderValue(i + 1, this.sliderMax)) {
442
+ return i;
443
+ }
444
+ }
445
+ return -1;
446
+ };
447
+ /**
448
+ * Converts a relative value in [0..1] to [min..max].
449
+ * @param relativeValue
450
+ */
451
+ ColorGradientPicker.prototype.__relativeToAbsolute = function (relativeValue) {
452
+ return this.sliderMin + (this.sliderMax - this.sliderMin) * relativeValue;
453
+ };
454
+ /**
455
+ * Converts a relative value in [0..1] to [min..max].
456
+ * @param relativeValue
457
+ */
458
+ ColorGradientPicker.prototype.__absoluteToRelative = function (absolute) {
459
+ return (absolute - this.sliderMin) / (this.sliderMax - this.sliderMin);
460
+ };
461
+ /**
462
+ * Get the value of the n-th rangel slider.
463
+ *
464
+ * @param {number} sliderIndex
465
+ * @param {number} fallback
466
+ * @returns
467
+ */
468
+ ColorGradientPicker.prototype.__getSliderValue = function (sliderIndex, fallback) {
469
+ if (sliderIndex < 0 || sliderIndex >= this._sliderElementRefs.length) {
470
+ return fallback;
471
+ }
472
+ return Number.parseFloat(this._sliderElementRefs[sliderIndex].current.value);
473
+ };
474
+ /**
475
+ * Get all current slider values as an array.
476
+ * @returns
477
+ */
478
+ ColorGradientPicker.prototype.__getAllSliderValues = function () {
479
+ var _this = this;
480
+ return this._sliderElementRefs.map(function (ref, index) { return _this.__getSliderValue(index, NaN); });
481
+ };
482
+ /**
483
+ * Updates the container's background to display the configured color gradient.
484
+ *
485
+ * @private
486
+ */
487
+ ColorGradientPicker.prototype.__updateBackgroundGradient = function () {
488
+ var _this = this;
489
+ // const colorGradient = this.getColorGradient();
490
+ this.colorGradient = new ColorGradient_1.ColorGradient(this.__getAllSliderValues().map(function (sliderValue, sliderIndex) { return ({
491
+ color: _this.__getSliderColor(sliderIndex, null),
492
+ ratio: _this.__absoluteToRelative(sliderValue)
493
+ }); }), this.colorGradient.angle);
494
+ this.containerRef.current.style["background"] = this.colorGradient.toColorGradientString();
495
+ };
496
+ /**
497
+ * After changes this function updates the color indicator button.
498
+ *
499
+ * @param {number} rangeSliderIndex - The new active slider index.
500
+ */
501
+ ColorGradientPicker.prototype.__updateColorIndicator = function (rangeSliderIndex) {
502
+ var colorValue = this.__getSliderColorHEXString(rangeSliderIndex, "#808080");
503
+ var ratio = this.__getSliderPercentage(rangeSliderIndex);
504
+ // Set left offset of color input container
505
+ this.colorInputContainerRef.current.style["left"] = "calc( ".concat(ratio * 100, "% + ").concat((1.0 - ratio) * this.css_indicatorWidth_num * 0.5, "em - ").concat(ratio * this.css_indicatorWidth_num * 0.5, "em)");
506
+ // Also set offset of colot input element (safari will open the native color dialog at this position)
507
+ this.colorInputRef.current.style["left"] = "calc( ".concat(ratio * 100, "% + ").concat((1.0 - ratio) * this.css_indicatorWidth_num * 0.5, "em - ").concat(ratio * this.css_indicatorWidth_num * 0.5, "em)");
508
+ this.colorIndicatorColorButtonRef.current.style["background-color"] = colorValue;
509
+ this.colorInputRef.current.value = colorValue;
510
+ // console.log("Setting new color value", this.colorInputRef.current.value, colorValue);
511
+ this.colorInputRef.current.dataset.activeSliderIndex = "".concat(rangeSliderIndex);
512
+ if (rangeSliderIndex <= 0 || rangeSliderIndex + 1 >= this._sliderElementRefs.length) {
513
+ this.colorIndicatorRemoveButtonRef.current.style["visibility"] = "hidden";
514
+ }
515
+ else {
516
+ this.colorIndicatorRemoveButtonRef.current.style["visibility"] = "visible";
517
+ }
518
+ };
519
+ /**
520
+ * Get a color gradient CSS value string from the current editor settings.
521
+ *
522
+ * @instance
523
+ * @memberof ColorGradientPicker
524
+ * @returns {ColorGradient}
525
+ */
526
+ ColorGradientPicker.prototype.getColorGradient = function () {
527
+ return this.colorGradient;
528
+ };
529
+ /**
530
+ * Get the configured color value of the n-th rangel slider.
531
+ *
532
+ * @param {number} sliderIndex
533
+ * @param {string} fallback
534
+ * @returns
535
+ */
536
+ ColorGradientPicker.prototype.__getSliderColorString = function (sliderIndex, fallback) {
537
+ if (sliderIndex < 0 || sliderIndex >= this._sliderElementRefs.length) {
538
+ return fallback;
539
+ }
540
+ var colorValue = this._sliderElementRefs[sliderIndex].current.dataset.colorValue;
541
+ return colorValue ? colorValue : fallback;
542
+ };
543
+ /**
544
+ * Get the configured color value of the n-th rangel slider.
545
+ *
546
+ * @param {number} sliderIndex
547
+ * @param {string} fallback
548
+ * @returns
549
+ */
550
+ ColorGradientPicker.prototype.__getSliderColorHEXString = function (sliderIndex, fallback) {
551
+ if (sliderIndex < 0 || sliderIndex >= this._sliderElementRefs.length) {
552
+ return fallback;
553
+ }
554
+ var colorValue = this._sliderElementRefs[sliderIndex].current.dataset.colorValueHEX;
555
+ return colorValue ? colorValue : fallback;
556
+ };
557
+ /**
558
+ * Get get color of this gradient picker at the given slider index.
559
+ *
560
+ * @param {number} sliderIndex - The index to get the slider color from. Something between 0 and _sliderElementRefs.length.
561
+ * @param {Color} fallback
562
+ * @returns
563
+ */
564
+ ColorGradientPicker.prototype.__getSliderColor = function (sliderIndex, fallback) {
565
+ if (sliderIndex < 0 || sliderIndex >= this._sliderElementRefs.length) {
566
+ return fallback;
567
+ }
568
+ var colorValueString = this._sliderElementRefs[sliderIndex].current.dataset["colorValue"];
569
+ var colorValue = Color_1.Color.parse(colorValueString);
570
+ return colorValue ? colorValue : fallback;
571
+ };
572
+ /**
573
+ * Get the slider's value in a mapped range of 0.0 ... 1.0.
574
+ *
575
+ * @param sliderIndex
576
+ * @returns
577
+ */
578
+ ColorGradientPicker.prototype.__getSliderPercentage = function (sliderIndex) {
579
+ var sliderValue = this.__getSliderValue(sliderIndex, 0.0);
580
+ var percentage = (this.sliderMin + sliderValue) / (this.sliderMax - this.sliderMin);
581
+ return percentage;
582
+ };
583
+ /**
584
+ * Init the container contents.
585
+ *
586
+ * @private
587
+ */
588
+ ColorGradientPicker.prototype._render = function () {
589
+ var _this = this;
590
+ var _self = this;
591
+ // console.log("Rendering ...", NoReact);
592
+ this._sliderElementRefs = [];
593
+ this.colorIndicatorColorButtonRef = NoReact.useRef();
594
+ this.colorIndicatorRemoveButtonRef = NoReact.useRef();
595
+ this.colorInputRef = NoReact.useRef();
596
+ this.colorInputContainerRef = NoReact.useRef();
597
+ this.containerRef = NoReact.useRef();
598
+ /**
599
+ * This helper method is called when the tiny color button below the active slider is clicked. The method
600
+ * triggers the colorInput dialog to be triggered.
601
+ *
602
+ * @param {Event} evt
603
+ */
604
+ var handleIndicatorButtonClick = function (evt) {
605
+ evt.preventDefault(); // Prevent other inputs to react to this event.
606
+ evt.stopPropagation();
607
+ // But fake a click on the input element
608
+ // console.log("Current selected color: " + _self.colorInputRef.current.value);
609
+ _self.colorInputRef.current.click();
610
+ };
611
+ /**
612
+ * This helper method is called when the remove-color button is clicked. It removes the
613
+ * currently active color slider – if possible (leftmost and rightmost slider cannot be removed).
614
+ * @param evt
615
+ */
616
+ var handleRemoveColorButtonClick = function (evt) {
617
+ evt.preventDefault(); // Prevent other inputs to react to this event.
618
+ evt.stopPropagation();
619
+ _self.__handleRemoveColor();
620
+ };
621
+ return (NoReact.createElement("div", { id: this.elementID, style: {
622
+ d: "flex",
623
+ fd: "column",
624
+ w: "100%",
625
+ h: this.css_containerHeight,
626
+ pos: "relative",
627
+ mb: this.isMobileMode ? "5em" : "3em"
628
+ }, ref: this.containerRef, onMouseDown: this.__containerMouseDownHandler(), onClick: this.__containerClickHandler() },
629
+ this.colorGradient.values.map(function (colorGradientItem, index) {
630
+ var initialValue = _self.__relativeToAbsolute(colorGradientItem.ratio);
631
+ return _this.__createColorRangeInput(index, _this.sliderMin, _this.sliderMax, initialValue, colorGradientItem.color);
632
+ }),
633
+ NoReact.createElement("div", { style: { w: "100%" } },
634
+ NoReact.createElement("input", { id: "color-indicator-input-".concat(this.baseID), type: "color", style: { v: "hidden", pos: "absolute", l: 0 },
635
+ // data-active-slider-index=""
636
+ ref: this.colorInputRef, onInput: this.__colorChangeHandler() }),
637
+ NoReact.createElement("div", { ref: this.colorInputContainerRef, style: {
638
+ pos: "absolute",
639
+ b: "0px",
640
+ l: "0%",
641
+ d: "flex",
642
+ fd: "column",
643
+ transform: "translate(0%, 100%)"
644
+ } },
645
+ NoReact.createElement("button", { id: "color-indicator-button-".concat(this.baseID), className: "color-indicator-button", style: {
646
+ backgroundColor: "grey",
647
+ borderRadius: "50%",
648
+ border: "1px solid grey",
649
+ w: this.css_indicatorWidth, // "1em",
650
+ h: this.css_indicatorHeight, // "1em",
651
+ transform: "translate(-50%, 0%)"
652
+ }, onClick: handleIndicatorButtonClick, ref: this.colorIndicatorColorButtonRef }),
653
+ NoReact.createElement("button", { id: "color-remove-button-".concat(this.baseID), className: "color-remove-button", style: {
654
+ borderRadius: "10%",
655
+ border: "1px solid grey",
656
+ w: this.css_indicatorWidth, // "1em",
657
+ h: this.css_indicatorHeight, // "1em",
658
+ transform: "translate(-50%, 50%)",
659
+ lineHeight: "0.5em",
660
+ p: 0
661
+ }, onClick: handleRemoveColorButtonClick, ref: this.colorIndicatorRemoveButtonRef },
662
+ NoReact.createElement("span", { style: { fontSize: this.isMobileMode ? "1.0em" : "0.5em" } }, "\uD83D\uDDD1"))))));
663
+ }; // END function render()
664
+ return ColorGradientPicker;
665
+ }());
666
+ exports.ColorGradientPicker = ColorGradientPicker;
667
+ //# sourceMappingURL=ColorGradientPicker.js.map