| 1 | /* |
| 2 | Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/ |
| 3 | |
| 4 | This program is free software; |
| 5 | you can redistribute it and/or modify it under the terms of the |
| 6 | GNU General Public License as published by the Free Software Foundation; |
| 7 | either version 3 of the License, or any later version. |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | You should have received a copy of the GNU General Public License |
| 13 | along with this program; if not, write to the Free Software |
| 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 15 | */ |
| 16 | /* |
| 17 | Changes: |
| 18 | - v4.0.0: |
| 19 | - created from v3.6.0 |
| 20 | Doc reviewed 202208 |
| 21 | */ |
| 22 | |
| 23 | import theHTMLSanitizer from '../core/htmlSanitizer/HTMLSanitizer.js'; |
| 24 | |
| 25 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 26 | /** |
| 27 | A simple container for the layer toolbar buttons properties |
| 28 | */ |
| 29 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 30 | |
| 31 | class LayerToolbarButtonData { |
| 32 | |
| 33 | /** |
| 34 | The text displayed in the button |
| 35 | @type {String} |
| 36 | */ |
| 37 | |
| 38 | #text; |
| 39 | |
| 40 | /** |
| 41 | The button text color |
| 42 | @type {String} |
| 43 | */ |
| 44 | |
| 45 | #color; |
| 46 | |
| 47 | /** |
| 48 | The button background color |
| 49 | @type {String} |
| 50 | */ |
| 51 | |
| 52 | #backgroundColor; |
| 53 | |
| 54 | /** |
| 55 | The constructor |
| 56 | @param {JsonObject} jsonToolbarData a json object with the data for the button |
| 57 | */ |
| 58 | |
| 59 | constructor ( jsonToolbarData ) { |
| 60 | if ( |
| 61 | 'string' !== typeof ( jsonToolbarData?.text ) |
| 62 | || |
| 63 | 'string' !== typeof ( jsonToolbarData?.color ) |
| 64 | || |
| 65 | 'string' !== typeof ( jsonToolbarData?.backgroundColor ) |
| 66 | ) { |
| 67 | throw new Error ( 'invalid toolbar for layer' ); |
| 68 | } |
| 69 | Object.freeze ( this ); |
| 70 | this.#text = theHTMLSanitizer.sanitizeToJsString ( jsonToolbarData.text ); |
| 71 | this.#color = theHTMLSanitizer.sanitizeToColor ( jsonToolbarData.color ); |
| 72 | this.#backgroundColor = theHTMLSanitizer.sanitizeToColor ( jsonToolbarData.backgroundColor ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | The text displayed in the button |
| 77 | @type {String} |
| 78 | */ |
| 79 | |
| 80 | get text ( ) { return this.#text; } |
| 81 | |
| 82 | /** |
| 83 | The button text color |
| 84 | @type {String} |
| 85 | */ |
| 86 | |
| 87 | get color ( ) { return this.#color; } |
| 88 | |
| 89 | /** |
| 90 | The button background color |
| 91 | @type {String} |
| 92 | */ |
| 93 | |
| 94 | get backgroundColor ( ) { return this.#backgroundColor; } |
| 95 | |
| 96 | } |
| 97 | |
| 98 | export default LayerToolbarButtonData; |
| 99 | |
| 100 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
| 101 |