custom-electron-titlebar 3.2.6 → 3.2.10

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 (239) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/README.md +15 -24
  3. package/_config.yml +1 -0
  4. package/{lib → build}/browser/browser.d.ts +0 -0
  5. package/{lib → build}/browser/browser.js +0 -0
  6. package/{lib → build}/browser/browser.js.map +0 -0
  7. package/{lib → build}/browser/event.d.ts +0 -0
  8. package/{lib → build}/browser/event.js +2 -1
  9. package/{lib → build}/browser/event.js.map +1 -1
  10. package/{lib → build}/browser/iframe.d.ts +0 -0
  11. package/{lib → build}/browser/iframe.js +0 -0
  12. package/{lib → build}/browser/iframe.js.map +0 -0
  13. package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
  14. package/{lib → build}/browser/keyboardEvent.js +0 -0
  15. package/{lib → build}/browser/keyboardEvent.js.map +0 -0
  16. package/{lib → build}/browser/mouseEvent.d.ts +0 -0
  17. package/{lib → build}/browser/mouseEvent.js +0 -0
  18. package/{lib → build}/browser/mouseEvent.js.map +0 -0
  19. package/{lib → build}/common/arrays.d.ts +0 -0
  20. package/{lib → build}/common/arrays.js +0 -0
  21. package/{lib → build}/common/arrays.js.map +0 -0
  22. package/{lib → build}/common/async.d.ts +0 -0
  23. package/{lib → build}/common/async.js +0 -0
  24. package/{lib → build}/common/async.js.map +0 -0
  25. package/{lib → build}/common/charCode.d.ts +0 -0
  26. package/{lib → build}/common/charCode.js +0 -0
  27. package/{lib → build}/common/charCode.js.map +0 -0
  28. package/{lib → build}/common/color.d.ts +0 -0
  29. package/{lib → build}/common/color.js +0 -0
  30. package/{lib → build}/common/color.js.map +0 -0
  31. package/{lib → build}/common/dom.d.ts +0 -0
  32. package/{lib → build}/common/dom.js +16 -14
  33. package/build/common/dom.js.map +1 -0
  34. package/{lib → build}/common/event.d.ts +0 -0
  35. package/{lib → build}/common/event.js +1 -1
  36. package/build/common/event.js.map +1 -0
  37. package/{lib → build}/common/iterator.d.ts +0 -0
  38. package/{lib → build}/common/iterator.js +0 -0
  39. package/{lib → build}/common/iterator.js.map +0 -0
  40. package/{lib → build}/common/keyCodes.d.ts +0 -0
  41. package/{lib → build}/common/keyCodes.js +0 -0
  42. package/{lib → build}/common/keyCodes.js.map +0 -0
  43. package/{lib → build}/common/lifecycle.d.ts +0 -0
  44. package/{lib → build}/common/lifecycle.js +0 -0
  45. package/{lib → build}/common/lifecycle.js.map +0 -0
  46. package/{lib → build}/common/linkedList.d.ts +0 -0
  47. package/{lib → build}/common/linkedList.js +0 -0
  48. package/{lib → build}/common/linkedList.js.map +0 -0
  49. package/{lib → build}/common/platform.d.ts +0 -0
  50. package/{lib → build}/common/platform.js +0 -0
  51. package/{lib → build}/common/platform.js.map +0 -0
  52. package/{lib → build}/index.d.ts +0 -0
  53. package/{lib → build}/index.js +0 -0
  54. package/{lib → build}/index.js.map +0 -0
  55. package/{lib → build}/menu/menu.d.ts +0 -0
  56. package/{lib → build}/menu/menu.js +38 -38
  57. package/build/menu/menu.js.map +1 -0
  58. package/{lib → build}/menu/menuitem.d.ts +10 -2
  59. package/{lib → build}/menu/menuitem.js +70 -34
  60. package/build/menu/menuitem.js.map +1 -0
  61. package/{lib → build}/menubar.d.ts +0 -0
  62. package/{lib → build}/menubar.js +29 -30
  63. package/build/menubar.js.map +1 -0
  64. package/{lib → build}/themebar.d.ts +0 -0
  65. package/{lib → build}/themebar.js +2 -2
  66. package/build/themebar.js.map +1 -0
  67. package/{lib → build}/titlebar.d.ts +0 -0
  68. package/{lib → build}/titlebar.js +61 -58
  69. package/build/titlebar.js.map +1 -0
  70. package/package.json +13 -7
  71. package/lib/common/dom.js.map +0 -1
  72. package/lib/common/enableNativeMenuCommands.d.ts +0 -1
  73. package/lib/common/enableNativeMenuCommands.js +0 -32
  74. package/lib/common/enableNativeMenuCommands.js.map +0 -1
  75. package/lib/common/event.js.map +0 -1
  76. package/lib/main.d.ts +0 -1
  77. package/lib/main.js +0 -14
  78. package/lib/main.js.map +0 -1
  79. package/lib/menu/menu.js.map +0 -1
  80. package/lib/menu/menuitem.js.map +0 -1
  81. package/lib/menubar.js.map +0 -1
  82. package/lib/themebar.js.map +0 -1
  83. package/lib/titlebar.js.map +0 -1
  84. package/lib/vs/base/browser/browser.js +0 -150
  85. package/lib/vs/base/browser/canIUse.js +0 -58
  86. package/lib/vs/base/browser/codicons.js +0 -37
  87. package/lib/vs/base/browser/contextmenu.js +0 -9
  88. package/lib/vs/base/browser/dnd.js +0 -113
  89. package/lib/vs/base/browser/dom.js +0 -1417
  90. package/lib/vs/base/browser/event.js +0 -36
  91. package/lib/vs/base/browser/fastDomNode.js +0 -265
  92. package/lib/vs/base/browser/formattedTextRenderer.js +0 -248
  93. package/lib/vs/base/browser/globalMouseMoveMonitor.js +0 -137
  94. package/lib/vs/base/browser/history.js +0 -9
  95. package/lib/vs/base/browser/iframe.js +0 -126
  96. package/lib/vs/base/browser/keyboardEvent.js +0 -599
  97. package/lib/vs/base/browser/mouseEvent.js +0 -155
  98. package/lib/vs/base/browser/touch.js +0 -315
  99. package/lib/vs/base/browser/ui/actionbar/actionViewItems.js +0 -397
  100. package/lib/vs/base/browser/ui/actionbar/actionbar.js +0 -583
  101. package/lib/vs/base/browser/ui/checkbox/checkbox.js +0 -251
  102. package/lib/vs/base/browser/ui/codicons/codiconLabel.js +0 -31
  103. package/lib/vs/base/browser/ui/codicons/codiconStyles.js +0 -47
  104. package/lib/vs/base/browser/ui/contextview/contextview.js +0 -367
  105. package/lib/vs/base/browser/ui/dropdown/dropdown.js +0 -256
  106. package/lib/vs/base/browser/ui/dropdown/dropdownActionViewItem.js +0 -120
  107. package/lib/vs/base/browser/ui/keybindingLabel/keybindingLabel.js +0 -118
  108. package/lib/vs/base/browser/ui/list/list.js +0 -54
  109. package/lib/vs/base/browser/ui/list/listPaging.js +0 -322
  110. package/lib/vs/base/browser/ui/list/listView.js +0 -1388
  111. package/lib/vs/base/browser/ui/list/listWidget.js +0 -1709
  112. package/lib/vs/base/browser/ui/list/rangeMap.js +0 -223
  113. package/lib/vs/base/browser/ui/list/rowCache.js +0 -113
  114. package/lib/vs/base/browser/ui/list/splice.js +0 -23
  115. package/lib/vs/base/browser/ui/menu/menu.js +0 -1371
  116. package/lib/vs/base/browser/ui/menu/menubar.js +0 -1139
  117. package/lib/vs/base/browser/ui/scrollbar/abstractScrollbar.js +0 -278
  118. package/lib/vs/base/browser/ui/scrollbar/horizontalScrollbar.js +0 -115
  119. package/lib/vs/base/browser/ui/scrollbar/scrollableElement.js +0 -646
  120. package/lib/vs/base/browser/ui/scrollbar/scrollableElementOptions.js +0 -9
  121. package/lib/vs/base/browser/ui/scrollbar/scrollbarArrow.js +0 -106
  122. package/lib/vs/base/browser/ui/scrollbar/scrollbarState.js +0 -184
  123. package/lib/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.js +0 -116
  124. package/lib/vs/base/browser/ui/scrollbar/verticalScrollbar.js +0 -114
  125. package/lib/vs/base/browser/ui/selectBox/selectBox.js +0 -85
  126. package/lib/vs/base/browser/ui/selectBox/selectBoxCustom.js +0 -985
  127. package/lib/vs/base/browser/ui/selectBox/selectBoxNative.js +0 -188
  128. package/lib/vs/base/browser/ui/toolbar/toolbar.js +0 -206
  129. package/lib/vs/base/browser/ui/widget.js +0 -69
  130. package/lib/vs/base/common/actions.js +0 -224
  131. package/lib/vs/base/common/amd.js +0 -31
  132. package/lib/vs/base/common/arrays.js +0 -641
  133. package/lib/vs/base/common/assert.js +0 -21
  134. package/lib/vs/base/common/async.js +0 -966
  135. package/lib/vs/base/common/buffer.js +0 -250
  136. package/lib/vs/base/common/cache.js +0 -40
  137. package/lib/vs/base/common/cancellation.js +0 -146
  138. package/lib/vs/base/common/charCode.js +0 -9
  139. package/lib/vs/base/common/codicon.js +0 -136
  140. package/lib/vs/base/common/codicons.js +0 -1378
  141. package/lib/vs/base/common/collections.js +0 -133
  142. package/lib/vs/base/common/color.js +0 -716
  143. package/lib/vs/base/common/comparers.js +0 -280
  144. package/lib/vs/base/common/console.js +0 -142
  145. package/lib/vs/base/common/date.js +0 -113
  146. package/lib/vs/base/common/decorators.js +0 -169
  147. package/lib/vs/base/common/errorMessage.js +0 -93
  148. package/lib/vs/base/common/errors.js +0 -213
  149. package/lib/vs/base/common/errorsWithActions.js +0 -28
  150. package/lib/vs/base/common/event.js +0 -873
  151. package/lib/vs/base/common/extpath.js +0 -401
  152. package/lib/vs/base/common/filters.js +0 -948
  153. package/lib/vs/base/common/functional.js +0 -28
  154. package/lib/vs/base/common/fuzzyScorer.js +0 -811
  155. package/lib/vs/base/common/glob.js +0 -696
  156. package/lib/vs/base/common/hash.js +0 -359
  157. package/lib/vs/base/common/history.js +0 -116
  158. package/lib/vs/base/common/htmlContent.js +0 -162
  159. package/lib/vs/base/common/idGenerator.js +0 -25
  160. package/lib/vs/base/common/iterator.js +0 -118
  161. package/lib/vs/base/common/json.js +0 -1624
  162. package/lib/vs/base/common/jsonEdit.js +0 -272
  163. package/lib/vs/base/common/jsonErrorMessages.js +0 -69
  164. package/lib/vs/base/common/jsonFormatter.js +0 -316
  165. package/lib/vs/base/common/jsonSchema.js +0 -9
  166. package/lib/vs/base/common/keyCodes.js +0 -591
  167. package/lib/vs/base/common/keybindingLabels.js +0 -231
  168. package/lib/vs/base/common/keybindingParser.js +0 -142
  169. package/lib/vs/base/common/labels.js +0 -430
  170. package/lib/vs/base/common/lazy.js +0 -71
  171. package/lib/vs/base/common/lifecycle.js +0 -308
  172. package/lib/vs/base/common/linkedList.js +0 -152
  173. package/lib/vs/base/common/linkedText.js +0 -73
  174. package/lib/vs/base/common/map.js +0 -1108
  175. package/lib/vs/base/common/marshalling.js +0 -80
  176. package/lib/vs/base/common/mime.js +0 -321
  177. package/lib/vs/base/common/navigator.js +0 -50
  178. package/lib/vs/base/common/network.js +0 -160
  179. package/lib/vs/base/common/normalization.js +0 -78
  180. package/lib/vs/base/common/numbers.js +0 -55
  181. package/lib/vs/base/common/objects.js +0 -268
  182. package/lib/vs/base/common/paging.js +0 -190
  183. package/lib/vs/base/common/parsers.js +0 -78
  184. package/lib/vs/base/common/path.js +0 -1550
  185. package/lib/vs/base/common/platform.js +0 -245
  186. package/lib/vs/base/common/process.js +0 -52
  187. package/lib/vs/base/common/processes.js +0 -32
  188. package/lib/vs/base/common/range.js +0 -79
  189. package/lib/vs/base/common/resourceTree.js +0 -185
  190. package/lib/vs/base/common/resources.js +0 -421
  191. package/lib/vs/base/common/scanCode.js +0 -1472
  192. package/lib/vs/base/common/scrollable.js +0 -397
  193. package/lib/vs/base/common/search.js +0 -55
  194. package/lib/vs/base/common/sequence.js +0 -64
  195. package/lib/vs/base/common/severity.js +0 -55
  196. package/lib/vs/base/common/skipList.js +0 -234
  197. package/lib/vs/base/common/stopwatch.js +0 -45
  198. package/lib/vs/base/common/stream.js +0 -418
  199. package/lib/vs/base/common/strings.js +0 -1283
  200. package/lib/vs/base/common/styler.js +0 -9
  201. package/lib/vs/base/common/types.js +0 -296
  202. package/lib/vs/base/common/uint.js +0 -46
  203. package/lib/vs/base/common/uri.js +0 -756
  204. package/lib/vs/base/common/uriIpc.js +0 -154
  205. package/lib/vs/base/common/uuid.js +0 -70
  206. package/lib/vs/nls.mock.js +0 -31
  207. package/lib/vs/platform/actions/browser/menuEntryActionViewItem.js +0 -342
  208. package/lib/vs/platform/actions/common/actions.js +0 -456
  209. package/lib/vs/platform/actions/common/menuService.js +0 -194
  210. package/lib/vs/platform/clipboard/browser/clipboardService.js +0 -99
  211. package/lib/vs/platform/clipboard/common/clipboardService.js +0 -14
  212. package/lib/vs/platform/contextkey/common/contextkey.js +0 -1210
  213. package/lib/vs/platform/contextkey/common/contextkeys.js +0 -23
  214. package/lib/vs/platform/contextview/browser/contextView.js +0 -15
  215. package/lib/vs/platform/contextview/browser/contextViewService.js +0 -96
  216. package/lib/vs/platform/environment/common/argv.js +0 -9
  217. package/lib/vs/platform/environment/common/environment.js +0 -15
  218. package/lib/vs/platform/instantiation/common/descriptors.js +0 -25
  219. package/lib/vs/platform/instantiation/common/extensions.js +0 -26
  220. package/lib/vs/platform/instantiation/common/graph.js +0 -93
  221. package/lib/vs/platform/instantiation/common/instantiation.js +0 -84
  222. package/lib/vs/platform/instantiation/common/instantiationService.js +0 -361
  223. package/lib/vs/platform/instantiation/common/serviceCollection.js +0 -39
  224. package/lib/vs/platform/keybinding/common/baseResolvedKeybinding.js +0 -73
  225. package/lib/vs/platform/keybinding/common/keybinding.js +0 -14
  226. package/lib/vs/platform/keybinding/common/keybindingResolver.js +0 -391
  227. package/lib/vs/platform/keybinding/common/keybindingsRegistry.js +0 -229
  228. package/lib/vs/platform/keybinding/common/resolvedKeybindingItem.js +0 -47
  229. package/lib/vs/platform/keybinding/common/usLayoutResolvedKeybinding.js +0 -160
  230. package/lib/vs/platform/layout/browser/layoutService.js +0 -14
  231. package/lib/vs/platform/menubar/common/menubar.js +0 -34
  232. package/lib/vs/platform/registry/common/platform.js +0 -38
  233. package/lib/vs/platform/theme/browser/checkbox.js +0 -32
  234. package/lib/vs/platform/theme/common/colorRegistry.js +0 -1154
  235. package/lib/vs/platform/theme/common/styler.js +0 -290
  236. package/lib/vs/platform/theme/common/theme.js +0 -21
  237. package/lib/vs/platform/theme/common/themeService.js +0 -176
  238. package/lib/vs/platform/theme/common/tokenClassificationRegistry.js +0 -540
  239. package/lib/vs/platform/theme/test/common/testThemeService.js +0 -98
@@ -1,716 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.Color = exports.HSVA = exports.HSLA = exports.RGBA = void 0;
11
-
12
- function roundFloat(number, decimalPoints) {
13
- const decimal = Math.pow(10, decimalPoints);
14
- return Math.round(number * decimal) / decimal;
15
- }
16
-
17
- class RGBA {
18
- constructor(r, g, b, a = 1) {
19
- this.r = Math.min(255, Math.max(0, r)) | 0;
20
- this.g = Math.min(255, Math.max(0, g)) | 0;
21
- this.b = Math.min(255, Math.max(0, b)) | 0;
22
- this.a = roundFloat(Math.max(Math.min(1, a), 0), 3);
23
- }
24
-
25
- static equals(a, b) {
26
- return a.r === b.r && a.g === b.g && a.b === b.b && a.a === b.a;
27
- }
28
-
29
- }
30
-
31
- exports.RGBA = RGBA;
32
-
33
- class HSLA {
34
- constructor(h, s, l, a) {
35
- this.h = Math.max(Math.min(360, h), 0) | 0;
36
- this.s = roundFloat(Math.max(Math.min(1, s), 0), 3);
37
- this.l = roundFloat(Math.max(Math.min(1, l), 0), 3);
38
- this.a = roundFloat(Math.max(Math.min(1, a), 0), 3);
39
- }
40
-
41
- static equals(a, b) {
42
- return a.h === b.h && a.s === b.s && a.l === b.l && a.a === b.a;
43
- }
44
- /**
45
- * Converts an RGB color value to HSL. Conversion formula
46
- * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
47
- * Assumes r, g, and b are contained in the set [0, 255] and
48
- * returns h in the set [0, 360], s, and l in the set [0, 1].
49
- */
50
-
51
-
52
- static fromRGBA(rgba) {
53
- const r = rgba.r / 255;
54
- const g = rgba.g / 255;
55
- const b = rgba.b / 255;
56
- const a = rgba.a;
57
- const max = Math.max(r, g, b);
58
- const min = Math.min(r, g, b);
59
- let h = 0;
60
- let s = 0;
61
- const l = (min + max) / 2;
62
- const chroma = max - min;
63
-
64
- if (chroma > 0) {
65
- s = Math.min(l <= 0.5 ? chroma / (2 * l) : chroma / (2 - 2 * l), 1);
66
-
67
- switch (max) {
68
- case r:
69
- h = (g - b) / chroma + (g < b ? 6 : 0);
70
- break;
71
-
72
- case g:
73
- h = (b - r) / chroma + 2;
74
- break;
75
-
76
- case b:
77
- h = (r - g) / chroma + 4;
78
- break;
79
- }
80
-
81
- h *= 60;
82
- h = Math.round(h);
83
- }
84
-
85
- return new HSLA(h, s, l, a);
86
- }
87
-
88
- static _hue2rgb(p, q, t) {
89
- if (t < 0) {
90
- t += 1;
91
- }
92
-
93
- if (t > 1) {
94
- t -= 1;
95
- }
96
-
97
- if (t < 1 / 6) {
98
- return p + (q - p) * 6 * t;
99
- }
100
-
101
- if (t < 1 / 2) {
102
- return q;
103
- }
104
-
105
- if (t < 2 / 3) {
106
- return p + (q - p) * (2 / 3 - t) * 6;
107
- }
108
-
109
- return p;
110
- }
111
- /**
112
- * Converts an HSL color value to RGB. Conversion formula
113
- * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
114
- * Assumes h in the set [0, 360] s, and l are contained in the set [0, 1] and
115
- * returns r, g, and b in the set [0, 255].
116
- */
117
-
118
-
119
- static toRGBA(hsla) {
120
- const h = hsla.h / 360;
121
- const {
122
- s,
123
- l,
124
- a
125
- } = hsla;
126
- let r, g, b;
127
-
128
- if (s === 0) {
129
- r = g = b = l; // achromatic
130
- } else {
131
- const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
132
- const p = 2 * l - q;
133
- r = HSLA._hue2rgb(p, q, h + 1 / 3);
134
- g = HSLA._hue2rgb(p, q, h);
135
- b = HSLA._hue2rgb(p, q, h - 1 / 3);
136
- }
137
-
138
- return new RGBA(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
139
- }
140
-
141
- }
142
-
143
- exports.HSLA = HSLA;
144
-
145
- class HSVA {
146
- constructor(h, s, v, a) {
147
- this.h = Math.max(Math.min(360, h), 0) | 0;
148
- this.s = roundFloat(Math.max(Math.min(1, s), 0), 3);
149
- this.v = roundFloat(Math.max(Math.min(1, v), 0), 3);
150
- this.a = roundFloat(Math.max(Math.min(1, a), 0), 3);
151
- }
152
-
153
- static equals(a, b) {
154
- return a.h === b.h && a.s === b.s && a.v === b.v && a.a === b.a;
155
- } // from http://www.rapidtables.com/convert/color/rgb-to-hsv.htm
156
-
157
-
158
- static fromRGBA(rgba) {
159
- const r = rgba.r / 255;
160
- const g = rgba.g / 255;
161
- const b = rgba.b / 255;
162
- const cmax = Math.max(r, g, b);
163
- const cmin = Math.min(r, g, b);
164
- const delta = cmax - cmin;
165
- const s = cmax === 0 ? 0 : delta / cmax;
166
- let m;
167
-
168
- if (delta === 0) {
169
- m = 0;
170
- } else if (cmax === r) {
171
- m = ((g - b) / delta % 6 + 6) % 6;
172
- } else if (cmax === g) {
173
- m = (b - r) / delta + 2;
174
- } else {
175
- m = (r - g) / delta + 4;
176
- }
177
-
178
- return new HSVA(Math.round(m * 60), s, cmax, rgba.a);
179
- } // from http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
180
-
181
-
182
- static toRGBA(hsva) {
183
- const {
184
- h,
185
- s,
186
- v,
187
- a
188
- } = hsva;
189
- const c = v * s;
190
- const x = c * (1 - Math.abs(h / 60 % 2 - 1));
191
- const m = v - c;
192
- let [r, g, b] = [0, 0, 0];
193
-
194
- if (h < 60) {
195
- r = c;
196
- g = x;
197
- } else if (h < 120) {
198
- r = x;
199
- g = c;
200
- } else if (h < 180) {
201
- g = c;
202
- b = x;
203
- } else if (h < 240) {
204
- g = x;
205
- b = c;
206
- } else if (h < 300) {
207
- r = x;
208
- b = c;
209
- } else if (h <= 360) {
210
- r = c;
211
- b = x;
212
- }
213
-
214
- r = Math.round((r + m) * 255);
215
- g = Math.round((g + m) * 255);
216
- b = Math.round((b + m) * 255);
217
- return new RGBA(r, g, b, a);
218
- }
219
-
220
- }
221
-
222
- exports.HSVA = HSVA;
223
-
224
- class Color {
225
- constructor(arg) {
226
- if (!arg) {
227
- throw new Error('Color needs a value');
228
- } else if (arg instanceof RGBA) {
229
- this.rgba = arg;
230
- } else if (arg instanceof HSLA) {
231
- this._hsla = arg;
232
- this.rgba = HSLA.toRGBA(arg);
233
- } else if (arg instanceof HSVA) {
234
- this._hsva = arg;
235
- this.rgba = HSVA.toRGBA(arg);
236
- } else {
237
- throw new Error('Invalid color ctor argument');
238
- }
239
- }
240
-
241
- static fromHex(hex) {
242
- return Color.Format.CSS.parseHex(hex) || Color.red;
243
- }
244
-
245
- get hsla() {
246
- if (this._hsla) {
247
- return this._hsla;
248
- } else {
249
- return HSLA.fromRGBA(this.rgba);
250
- }
251
- }
252
-
253
- get hsva() {
254
- if (this._hsva) {
255
- return this._hsva;
256
- }
257
-
258
- return HSVA.fromRGBA(this.rgba);
259
- }
260
-
261
- equals(other) {
262
- return !!other && RGBA.equals(this.rgba, other.rgba) && HSLA.equals(this.hsla, other.hsla) && HSVA.equals(this.hsva, other.hsva);
263
- }
264
- /**
265
- * http://www.w3.org/TR/WCAG20/#relativeluminancedef
266
- * Returns the number in the set [0, 1]. O => Darkest Black. 1 => Lightest white.
267
- */
268
-
269
-
270
- getRelativeLuminance() {
271
- const R = Color._relativeLuminanceForComponent(this.rgba.r);
272
-
273
- const G = Color._relativeLuminanceForComponent(this.rgba.g);
274
-
275
- const B = Color._relativeLuminanceForComponent(this.rgba.b);
276
-
277
- const luminance = 0.2126 * R + 0.7152 * G + 0.0722 * B;
278
- return roundFloat(luminance, 4);
279
- }
280
-
281
- static _relativeLuminanceForComponent(color) {
282
- const c = color / 255;
283
- return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
284
- }
285
- /**
286
- * http://www.w3.org/TR/WCAG20/#contrast-ratiodef
287
- * Returns the contrast ration number in the set [1, 21].
288
- */
289
-
290
-
291
- getContrastRatio(another) {
292
- const lum1 = this.getRelativeLuminance();
293
- const lum2 = another.getRelativeLuminance();
294
- return lum1 > lum2 ? (lum1 + 0.05) / (lum2 + 0.05) : (lum2 + 0.05) / (lum1 + 0.05);
295
- }
296
- /**
297
- * http://24ways.org/2010/calculating-color-contrast
298
- * Return 'true' if darker color otherwise 'false'
299
- */
300
-
301
-
302
- isDarker() {
303
- const yiq = (this.rgba.r * 299 + this.rgba.g * 587 + this.rgba.b * 114) / 1000;
304
- return yiq < 128;
305
- }
306
- /**
307
- * http://24ways.org/2010/calculating-color-contrast
308
- * Return 'true' if lighter color otherwise 'false'
309
- */
310
-
311
-
312
- isLighter() {
313
- const yiq = (this.rgba.r * 299 + this.rgba.g * 587 + this.rgba.b * 114) / 1000;
314
- return yiq >= 128;
315
- }
316
-
317
- isLighterThan(another) {
318
- const lum1 = this.getRelativeLuminance();
319
- const lum2 = another.getRelativeLuminance();
320
- return lum1 > lum2;
321
- }
322
-
323
- isDarkerThan(another) {
324
- const lum1 = this.getRelativeLuminance();
325
- const lum2 = another.getRelativeLuminance();
326
- return lum1 < lum2;
327
- }
328
-
329
- lighten(factor) {
330
- return new Color(new HSLA(this.hsla.h, this.hsla.s, this.hsla.l + this.hsla.l * factor, this.hsla.a));
331
- }
332
-
333
- darken(factor) {
334
- return new Color(new HSLA(this.hsla.h, this.hsla.s, this.hsla.l - this.hsla.l * factor, this.hsla.a));
335
- }
336
-
337
- transparent(factor) {
338
- const {
339
- r,
340
- g,
341
- b,
342
- a
343
- } = this.rgba;
344
- return new Color(new RGBA(r, g, b, a * factor));
345
- }
346
-
347
- isTransparent() {
348
- return this.rgba.a === 0;
349
- }
350
-
351
- isOpaque() {
352
- return this.rgba.a === 1;
353
- }
354
-
355
- opposite() {
356
- return new Color(new RGBA(255 - this.rgba.r, 255 - this.rgba.g, 255 - this.rgba.b, this.rgba.a));
357
- }
358
-
359
- blend(c) {
360
- const rgba = c.rgba; // Convert to 0..1 opacity
361
-
362
- const thisA = this.rgba.a;
363
- const colorA = rgba.a;
364
- const a = thisA + colorA * (1 - thisA);
365
-
366
- if (a < 1e-6) {
367
- return Color.transparent;
368
- }
369
-
370
- const r = this.rgba.r * thisA / a + rgba.r * colorA * (1 - thisA) / a;
371
- const g = this.rgba.g * thisA / a + rgba.g * colorA * (1 - thisA) / a;
372
- const b = this.rgba.b * thisA / a + rgba.b * colorA * (1 - thisA) / a;
373
- return new Color(new RGBA(r, g, b, a));
374
- }
375
-
376
- makeOpaque(opaqueBackground) {
377
- if (this.isOpaque() || opaqueBackground.rgba.a !== 1) {
378
- // only allow to blend onto a non-opaque color onto a opaque color
379
- return this;
380
- }
381
-
382
- const {
383
- r,
384
- g,
385
- b,
386
- a
387
- } = this.rgba; // https://stackoverflow.com/questions/12228548/finding-equivalent-color-with-opacity
388
-
389
- return new Color(new RGBA(opaqueBackground.rgba.r - a * (opaqueBackground.rgba.r - r), opaqueBackground.rgba.g - a * (opaqueBackground.rgba.g - g), opaqueBackground.rgba.b - a * (opaqueBackground.rgba.b - b), 1));
390
- }
391
-
392
- flatten(...backgrounds) {
393
- const background = backgrounds.reduceRight((accumulator, color) => {
394
- return Color._flatten(color, accumulator);
395
- });
396
- return Color._flatten(this, background);
397
- }
398
-
399
- static _flatten(foreground, background) {
400
- const backgroundAlpha = 1 - foreground.rgba.a;
401
- return new Color(new RGBA(backgroundAlpha * background.rgba.r + foreground.rgba.a * foreground.rgba.r, backgroundAlpha * background.rgba.g + foreground.rgba.a * foreground.rgba.g, backgroundAlpha * background.rgba.b + foreground.rgba.a * foreground.rgba.b));
402
- }
403
-
404
- toString() {
405
- return '' + Color.Format.CSS.format(this);
406
- }
407
-
408
- static getLighterColor(of, relative, factor) {
409
- if (of.isLighterThan(relative)) {
410
- return of;
411
- }
412
-
413
- factor = factor ? factor : 0.5;
414
- const lum1 = of.getRelativeLuminance();
415
- const lum2 = relative.getRelativeLuminance();
416
- factor = factor * (lum2 - lum1) / lum2;
417
- return of.lighten(factor);
418
- }
419
-
420
- static getDarkerColor(of, relative, factor) {
421
- if (of.isDarkerThan(relative)) {
422
- return of;
423
- }
424
-
425
- factor = factor ? factor : 0.5;
426
- const lum1 = of.getRelativeLuminance();
427
- const lum2 = relative.getRelativeLuminance();
428
- factor = factor * (lum1 - lum2) / lum1;
429
- return of.darken(factor);
430
- }
431
-
432
- }
433
-
434
- exports.Color = Color;
435
- Color.white = new Color(new RGBA(255, 255, 255, 1));
436
- Color.black = new Color(new RGBA(0, 0, 0, 1));
437
- Color.red = new Color(new RGBA(255, 0, 0, 1));
438
- Color.blue = new Color(new RGBA(0, 0, 255, 1));
439
- Color.green = new Color(new RGBA(0, 255, 0, 1));
440
- Color.cyan = new Color(new RGBA(0, 255, 255, 1));
441
- Color.lightgrey = new Color(new RGBA(211, 211, 211, 1));
442
- Color.transparent = new Color(new RGBA(0, 0, 0, 0));
443
-
444
- (function (Color) {
445
- let Format;
446
-
447
- (function (Format) {
448
- let CSS;
449
-
450
- (function (CSS) {
451
- function formatRGB(color) {
452
- if (color.rgba.a === 1) {
453
- return `rgb(${color.rgba.r}, ${color.rgba.g}, ${color.rgba.b})`;
454
- }
455
-
456
- return Color.Format.CSS.formatRGBA(color);
457
- }
458
-
459
- CSS.formatRGB = formatRGB;
460
-
461
- function formatRGBA(color) {
462
- return `rgba(${color.rgba.r}, ${color.rgba.g}, ${color.rgba.b}, ${+color.rgba.a.toFixed(2)})`;
463
- }
464
-
465
- CSS.formatRGBA = formatRGBA;
466
-
467
- function formatHSL(color) {
468
- if (color.hsla.a === 1) {
469
- return `hsl(${color.hsla.h}, ${(color.hsla.s * 100).toFixed(2)}%, ${(color.hsla.l * 100).toFixed(2)}%)`;
470
- }
471
-
472
- return Color.Format.CSS.formatHSLA(color);
473
- }
474
-
475
- CSS.formatHSL = formatHSL;
476
-
477
- function formatHSLA(color) {
478
- return `hsla(${color.hsla.h}, ${(color.hsla.s * 100).toFixed(2)}%, ${(color.hsla.l * 100).toFixed(2)}%, ${color.hsla.a.toFixed(2)})`;
479
- }
480
-
481
- CSS.formatHSLA = formatHSLA;
482
-
483
- function _toTwoDigitHex(n) {
484
- const r = n.toString(16);
485
- return r.length !== 2 ? '0' + r : r;
486
- }
487
- /**
488
- * Formats the color as #RRGGBB
489
- */
490
-
491
-
492
- function formatHex(color) {
493
- return `#${_toTwoDigitHex(color.rgba.r)}${_toTwoDigitHex(color.rgba.g)}${_toTwoDigitHex(color.rgba.b)}`;
494
- }
495
-
496
- CSS.formatHex = formatHex;
497
- /**
498
- * Formats the color as #RRGGBBAA
499
- * If 'compact' is set, colors without transparancy will be printed as #RRGGBB
500
- */
501
-
502
- function formatHexA(color, compact = false) {
503
- if (compact && color.rgba.a === 1) {
504
- return Color.Format.CSS.formatHex(color);
505
- }
506
-
507
- return `#${_toTwoDigitHex(color.rgba.r)}${_toTwoDigitHex(color.rgba.g)}${_toTwoDigitHex(color.rgba.b)}${_toTwoDigitHex(Math.round(color.rgba.a * 255))}`;
508
- }
509
-
510
- CSS.formatHexA = formatHexA;
511
- /**
512
- * The default format will use HEX if opaque and RGBA otherwise.
513
- */
514
-
515
- function format(color) {
516
- if (color.isOpaque()) {
517
- return Color.Format.CSS.formatHex(color);
518
- }
519
-
520
- return Color.Format.CSS.formatRGBA(color);
521
- }
522
-
523
- CSS.format = format;
524
- /**
525
- * Converts an Hex color value to a Color.
526
- * returns r, g, and b are contained in the set [0, 255]
527
- * @param hex string (#RGB, #RGBA, #RRGGBB or #RRGGBBAA).
528
- */
529
-
530
- function parseHex(hex) {
531
- const length = hex.length;
532
-
533
- if (length === 0) {
534
- // Invalid color
535
- return null;
536
- }
537
-
538
- if (hex.charCodeAt(0) !== 35
539
- /* Hash */
540
- ) {
541
- // Does not begin with a #
542
- return null;
543
- }
544
-
545
- if (length === 7) {
546
- // #RRGGBB format
547
- const r = 16 * _parseHexDigit(hex.charCodeAt(1)) + _parseHexDigit(hex.charCodeAt(2));
548
-
549
- const g = 16 * _parseHexDigit(hex.charCodeAt(3)) + _parseHexDigit(hex.charCodeAt(4));
550
-
551
- const b = 16 * _parseHexDigit(hex.charCodeAt(5)) + _parseHexDigit(hex.charCodeAt(6));
552
-
553
- return new Color(new RGBA(r, g, b, 1));
554
- }
555
-
556
- if (length === 9) {
557
- // #RRGGBBAA format
558
- const r = 16 * _parseHexDigit(hex.charCodeAt(1)) + _parseHexDigit(hex.charCodeAt(2));
559
-
560
- const g = 16 * _parseHexDigit(hex.charCodeAt(3)) + _parseHexDigit(hex.charCodeAt(4));
561
-
562
- const b = 16 * _parseHexDigit(hex.charCodeAt(5)) + _parseHexDigit(hex.charCodeAt(6));
563
-
564
- const a = 16 * _parseHexDigit(hex.charCodeAt(7)) + _parseHexDigit(hex.charCodeAt(8));
565
-
566
- return new Color(new RGBA(r, g, b, a / 255));
567
- }
568
-
569
- if (length === 4) {
570
- // #RGB format
571
- const r = _parseHexDigit(hex.charCodeAt(1));
572
-
573
- const g = _parseHexDigit(hex.charCodeAt(2));
574
-
575
- const b = _parseHexDigit(hex.charCodeAt(3));
576
-
577
- return new Color(new RGBA(16 * r + r, 16 * g + g, 16 * b + b));
578
- }
579
-
580
- if (length === 5) {
581
- // #RGBA format
582
- const r = _parseHexDigit(hex.charCodeAt(1));
583
-
584
- const g = _parseHexDigit(hex.charCodeAt(2));
585
-
586
- const b = _parseHexDigit(hex.charCodeAt(3));
587
-
588
- const a = _parseHexDigit(hex.charCodeAt(4));
589
-
590
- return new Color(new RGBA(16 * r + r, 16 * g + g, 16 * b + b, (16 * a + a) / 255));
591
- } // Invalid color
592
-
593
-
594
- return null;
595
- }
596
-
597
- CSS.parseHex = parseHex;
598
-
599
- function _parseHexDigit(charCode) {
600
- switch (charCode) {
601
- case 48
602
- /* Digit0 */
603
- :
604
- return 0;
605
-
606
- case 49
607
- /* Digit1 */
608
- :
609
- return 1;
610
-
611
- case 50
612
- /* Digit2 */
613
- :
614
- return 2;
615
-
616
- case 51
617
- /* Digit3 */
618
- :
619
- return 3;
620
-
621
- case 52
622
- /* Digit4 */
623
- :
624
- return 4;
625
-
626
- case 53
627
- /* Digit5 */
628
- :
629
- return 5;
630
-
631
- case 54
632
- /* Digit6 */
633
- :
634
- return 6;
635
-
636
- case 55
637
- /* Digit7 */
638
- :
639
- return 7;
640
-
641
- case 56
642
- /* Digit8 */
643
- :
644
- return 8;
645
-
646
- case 57
647
- /* Digit9 */
648
- :
649
- return 9;
650
-
651
- case 97
652
- /* a */
653
- :
654
- return 10;
655
-
656
- case 65
657
- /* A */
658
- :
659
- return 10;
660
-
661
- case 98
662
- /* b */
663
- :
664
- return 11;
665
-
666
- case 66
667
- /* B */
668
- :
669
- return 11;
670
-
671
- case 99
672
- /* c */
673
- :
674
- return 12;
675
-
676
- case 67
677
- /* C */
678
- :
679
- return 12;
680
-
681
- case 100
682
- /* d */
683
- :
684
- return 13;
685
-
686
- case 68
687
- /* D */
688
- :
689
- return 13;
690
-
691
- case 101
692
- /* e */
693
- :
694
- return 14;
695
-
696
- case 69
697
- /* E */
698
- :
699
- return 14;
700
-
701
- case 102
702
- /* f */
703
- :
704
- return 15;
705
-
706
- case 70
707
- /* F */
708
- :
709
- return 15;
710
- }
711
-
712
- return 0;
713
- }
714
- })(CSS = Format.CSS || (Format.CSS = {}));
715
- })(Format = Color.Format || (Color.Format = {}));
716
- })(Color = exports.Color || (exports.Color = {}));