custom-electron-titlebar 3.2.5 → 3.2.9

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 (175) hide show
  1. package/.vscode/launch.json +49 -0
  2. package/.vscode/tasks.json +34 -0
  3. package/README.md +15 -24
  4. package/_config.yml +1 -0
  5. package/{lib → build}/browser/browser.d.ts +0 -0
  6. package/{lib → build}/browser/browser.js +1 -0
  7. package/build/browser/browser.js.map +1 -0
  8. package/{lib → build}/browser/event.d.ts +0 -0
  9. package/{lib → build}/browser/event.js +3 -1
  10. package/build/browser/event.js.map +1 -0
  11. package/{lib → build}/browser/iframe.d.ts +0 -0
  12. package/{lib/base → build}/browser/iframe.js +1 -0
  13. package/build/browser/iframe.js.map +1 -0
  14. package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
  15. package/{lib → build}/browser/keyboardEvent.js +1 -0
  16. package/build/browser/keyboardEvent.js.map +1 -0
  17. package/{lib → build}/browser/mouseEvent.d.ts +0 -0
  18. package/{lib → build}/browser/mouseEvent.js +1 -0
  19. package/build/browser/mouseEvent.js.map +1 -0
  20. package/{lib → build}/common/arrays.d.ts +0 -0
  21. package/{lib → build}/common/arrays.js +1 -0
  22. package/build/common/arrays.js.map +1 -0
  23. package/{lib → build}/common/async.d.ts +0 -0
  24. package/{lib → build}/common/async.js +1 -0
  25. package/build/common/async.js.map +1 -0
  26. package/{lib → build}/common/charCode.d.ts +0 -0
  27. package/{lib/base → build}/common/charCode.js +1 -0
  28. package/build/common/charCode.js.map +1 -0
  29. package/{lib → build}/common/color.d.ts +0 -0
  30. package/{lib → build}/common/color.js +1 -0
  31. package/build/common/color.js.map +1 -0
  32. package/{lib → build}/common/dom.d.ts +0 -0
  33. package/{lib → build}/common/dom.js +17 -14
  34. package/build/common/dom.js.map +1 -0
  35. package/{lib → build}/common/event.d.ts +0 -0
  36. package/{lib → build}/common/event.js +2 -1
  37. package/build/common/event.js.map +1 -0
  38. package/{lib → build}/common/iterator.d.ts +0 -0
  39. package/{lib → build}/common/iterator.js +1 -0
  40. package/build/common/iterator.js.map +1 -0
  41. package/{lib → build}/common/keyCodes.d.ts +0 -0
  42. package/{lib → build}/common/keyCodes.js +1 -0
  43. package/build/common/keyCodes.js.map +1 -0
  44. package/{lib → build}/common/lifecycle.d.ts +0 -0
  45. package/{lib → build}/common/lifecycle.js +1 -0
  46. package/build/common/lifecycle.js.map +1 -0
  47. package/{lib → build}/common/linkedList.d.ts +0 -0
  48. package/{lib → build}/common/linkedList.js +1 -0
  49. package/build/common/linkedList.js.map +1 -0
  50. package/{lib → build}/common/platform.d.ts +0 -0
  51. package/{lib → build}/common/platform.js +1 -0
  52. package/build/common/platform.js.map +1 -0
  53. package/{lib → build}/index.d.ts +0 -0
  54. package/{lib → build}/index.js +1 -0
  55. package/build/index.js.map +1 -0
  56. package/{lib → build}/menu/menu.d.ts +0 -0
  57. package/{lib → build}/menu/menu.js +39 -38
  58. package/build/menu/menu.js.map +1 -0
  59. package/{lib → build}/menu/menuitem.d.ts +10 -2
  60. package/{lib → build}/menu/menuitem.js +71 -29
  61. package/build/menu/menuitem.js.map +1 -0
  62. package/{lib → build}/menubar.d.ts +0 -0
  63. package/{lib → build}/menubar.js +38 -34
  64. package/build/menubar.js.map +1 -0
  65. package/{lib → build}/themebar.d.ts +0 -0
  66. package/{lib → build}/themebar.js +31 -2
  67. package/build/themebar.js.map +1 -0
  68. package/{lib → build}/titlebar.d.ts +0 -0
  69. package/{lib → build}/titlebar.js +72 -59
  70. package/build/titlebar.js.map +1 -0
  71. package/package.json +13 -7
  72. package/lib/base/browser/browser.d.ts +0 -25
  73. package/lib/base/browser/browser.js +0 -117
  74. package/lib/base/browser/canIUse.d.ts +0 -18
  75. package/lib/base/browser/canIUse.js +0 -63
  76. package/lib/base/browser/dom.d.ts +0 -230
  77. package/lib/base/browser/dom.js +0 -1080
  78. package/lib/base/browser/event.d.ts +0 -12
  79. package/lib/base/browser/event.js +0 -28
  80. package/lib/base/browser/iframe.d.ts +0 -33
  81. package/lib/base/browser/keyboardEvent.d.ts +0 -40
  82. package/lib/base/browser/keyboardEvent.js +0 -256
  83. package/lib/base/browser/mouseEvent.d.ts +0 -69
  84. package/lib/base/browser/mouseEvent.js +0 -146
  85. package/lib/base/common/arrays.d.ts +0 -149
  86. package/lib/base/common/arrays.js +0 -549
  87. package/lib/base/common/async.d.ts +0 -259
  88. package/lib/base/common/async.js +0 -728
  89. package/lib/base/common/cancellation.d.ts +0 -29
  90. package/lib/base/common/cancellation.js +0 -114
  91. package/lib/base/common/charCode.d.ts +0 -415
  92. package/lib/base/common/color.d.ts +0 -163
  93. package/lib/base/common/color.js +0 -495
  94. package/lib/base/common/errors.d.ts +0 -65
  95. package/lib/base/common/errors.js +0 -164
  96. package/lib/base/common/event.d.ts +0 -248
  97. package/lib/base/common/event.js +0 -703
  98. package/lib/base/common/functional.d.ts +0 -1
  99. package/lib/base/common/functional.js +0 -21
  100. package/lib/base/common/iterator.d.ts +0 -16
  101. package/lib/base/common/iterator.js +0 -82
  102. package/lib/base/common/keyCodes.d.ts +0 -268
  103. package/lib/base/common/keyCodes.js +0 -292
  104. package/lib/base/common/lifecycle.d.ts +0 -67
  105. package/lib/base/common/lifecycle.js +0 -234
  106. package/lib/base/common/linkedList.d.ts +0 -16
  107. package/lib/base/common/linkedList.js +0 -128
  108. package/lib/base/common/network.d.ts +0 -65
  109. package/lib/base/common/network.js +0 -124
  110. package/lib/base/common/path.d.ts +0 -39
  111. package/lib/base/common/path.js +0 -1407
  112. package/lib/base/common/platform.d.ts +0 -53
  113. package/lib/base/common/platform.js +0 -176
  114. package/lib/base/common/process.d.ts +0 -5
  115. package/lib/base/common/process.js +0 -18
  116. package/lib/base/common/sequence.d.ts +0 -27
  117. package/lib/base/common/sequence.js +0 -32
  118. package/lib/base/common/uri.d.ts +0 -153
  119. package/lib/base/common/uri.js +0 -612
  120. package/lib/browser/iframe.js +0 -109
  121. package/lib/common/charCode.js +0 -6
  122. package/lib/menu.d.ts +0 -53
  123. package/lib/menu.js +0 -532
  124. package/lib/menuitem.d.ts +0 -46
  125. package/lib/menuitem.js +0 -295
  126. package/lib/vs/base/browser/browser.d.ts +0 -25
  127. package/lib/vs/base/browser/browser.js +0 -117
  128. package/lib/vs/base/browser/canIUse.d.ts +0 -18
  129. package/lib/vs/base/browser/canIUse.js +0 -63
  130. package/lib/vs/base/browser/dom.d.ts +0 -230
  131. package/lib/vs/base/browser/dom.js +0 -1080
  132. package/lib/vs/base/browser/event.d.ts +0 -12
  133. package/lib/vs/base/browser/event.js +0 -28
  134. package/lib/vs/base/browser/iframe.d.ts +0 -33
  135. package/lib/vs/base/browser/iframe.js +0 -109
  136. package/lib/vs/base/browser/keyboardEvent.d.ts +0 -40
  137. package/lib/vs/base/browser/keyboardEvent.js +0 -256
  138. package/lib/vs/base/browser/mouseEvent.d.ts +0 -69
  139. package/lib/vs/base/browser/mouseEvent.js +0 -146
  140. package/lib/vs/base/common/arrays.d.ts +0 -149
  141. package/lib/vs/base/common/arrays.js +0 -549
  142. package/lib/vs/base/common/async.d.ts +0 -259
  143. package/lib/vs/base/common/async.js +0 -728
  144. package/lib/vs/base/common/cancellation.d.ts +0 -29
  145. package/lib/vs/base/common/cancellation.js +0 -114
  146. package/lib/vs/base/common/charCode.d.ts +0 -415
  147. package/lib/vs/base/common/charCode.js +0 -6
  148. package/lib/vs/base/common/color.d.ts +0 -163
  149. package/lib/vs/base/common/color.js +0 -495
  150. package/lib/vs/base/common/errors.d.ts +0 -65
  151. package/lib/vs/base/common/errors.js +0 -164
  152. package/lib/vs/base/common/event.d.ts +0 -248
  153. package/lib/vs/base/common/event.js +0 -703
  154. package/lib/vs/base/common/functional.d.ts +0 -1
  155. package/lib/vs/base/common/functional.js +0 -21
  156. package/lib/vs/base/common/iterator.d.ts +0 -16
  157. package/lib/vs/base/common/iterator.js +0 -82
  158. package/lib/vs/base/common/keyCodes.d.ts +0 -268
  159. package/lib/vs/base/common/keyCodes.js +0 -292
  160. package/lib/vs/base/common/lifecycle.d.ts +0 -67
  161. package/lib/vs/base/common/lifecycle.js +0 -234
  162. package/lib/vs/base/common/linkedList.d.ts +0 -16
  163. package/lib/vs/base/common/linkedList.js +0 -128
  164. package/lib/vs/base/common/network.d.ts +0 -65
  165. package/lib/vs/base/common/network.js +0 -124
  166. package/lib/vs/base/common/path.d.ts +0 -39
  167. package/lib/vs/base/common/path.js +0 -1407
  168. package/lib/vs/base/common/platform.d.ts +0 -53
  169. package/lib/vs/base/common/platform.js +0 -176
  170. package/lib/vs/base/common/process.d.ts +0 -5
  171. package/lib/vs/base/common/process.js +0 -18
  172. package/lib/vs/base/common/sequence.d.ts +0 -27
  173. package/lib/vs/base/common/sequence.js +0 -32
  174. package/lib/vs/base/common/uri.d.ts +0 -153
  175. package/lib/vs/base/common/uri.js +0 -612
@@ -1,163 +0,0 @@
1
- export declare class RGBA {
2
- _rgbaBrand: void;
3
- /**
4
- * Red: integer in [0-255]
5
- */
6
- readonly r: number;
7
- /**
8
- * Green: integer in [0-255]
9
- */
10
- readonly g: number;
11
- /**
12
- * Blue: integer in [0-255]
13
- */
14
- readonly b: number;
15
- /**
16
- * Alpha: float in [0-1]
17
- */
18
- readonly a: number;
19
- constructor(r: number, g: number, b: number, a?: number);
20
- static equals(a: RGBA, b: RGBA): boolean;
21
- }
22
- export declare class HSLA {
23
- _hslaBrand: void;
24
- /**
25
- * Hue: integer in [0, 360]
26
- */
27
- readonly h: number;
28
- /**
29
- * Saturation: float in [0, 1]
30
- */
31
- readonly s: number;
32
- /**
33
- * Luminosity: float in [0, 1]
34
- */
35
- readonly l: number;
36
- /**
37
- * Alpha: float in [0, 1]
38
- */
39
- readonly a: number;
40
- constructor(h: number, s: number, l: number, a: number);
41
- static equals(a: HSLA, b: HSLA): boolean;
42
- /**
43
- * Converts an RGB color value to HSL. Conversion formula
44
- * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
45
- * Assumes r, g, and b are contained in the set [0, 255] and
46
- * returns h in the set [0, 360], s, and l in the set [0, 1].
47
- */
48
- static fromRGBA(rgba: RGBA): HSLA;
49
- private static _hue2rgb;
50
- /**
51
- * Converts an HSL color value to RGB. Conversion formula
52
- * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
53
- * Assumes h in the set [0, 360] s, and l are contained in the set [0, 1] and
54
- * returns r, g, and b in the set [0, 255].
55
- */
56
- static toRGBA(hsla: HSLA): RGBA;
57
- }
58
- export declare class HSVA {
59
- _hsvaBrand: void;
60
- /**
61
- * Hue: integer in [0, 360]
62
- */
63
- readonly h: number;
64
- /**
65
- * Saturation: float in [0, 1]
66
- */
67
- readonly s: number;
68
- /**
69
- * Value: float in [0, 1]
70
- */
71
- readonly v: number;
72
- /**
73
- * Alpha: float in [0, 1]
74
- */
75
- readonly a: number;
76
- constructor(h: number, s: number, v: number, a: number);
77
- static equals(a: HSVA, b: HSVA): boolean;
78
- static fromRGBA(rgba: RGBA): HSVA;
79
- static toRGBA(hsva: HSVA): RGBA;
80
- }
81
- export declare class Color {
82
- static fromHex(hex: string): Color;
83
- readonly rgba: RGBA;
84
- private _hsla?;
85
- get hsla(): HSLA;
86
- private _hsva?;
87
- get hsva(): HSVA;
88
- constructor(arg: RGBA | HSLA | HSVA);
89
- equals(other: Color | null): boolean;
90
- /**
91
- * http://www.w3.org/TR/WCAG20/#relativeluminancedef
92
- * Returns the number in the set [0, 1]. O => Darkest Black. 1 => Lightest white.
93
- */
94
- getRelativeLuminance(): number;
95
- private static _relativeLuminanceForComponent;
96
- /**
97
- * http://www.w3.org/TR/WCAG20/#contrast-ratiodef
98
- * Returns the contrast ration number in the set [1, 21].
99
- */
100
- getContrastRatio(another: Color): number;
101
- /**
102
- * http://24ways.org/2010/calculating-color-contrast
103
- * Return 'true' if darker color otherwise 'false'
104
- */
105
- isDarker(): boolean;
106
- /**
107
- * http://24ways.org/2010/calculating-color-contrast
108
- * Return 'true' if lighter color otherwise 'false'
109
- */
110
- isLighter(): boolean;
111
- isLighterThan(another: Color): boolean;
112
- isDarkerThan(another: Color): boolean;
113
- lighten(factor: number): Color;
114
- darken(factor: number): Color;
115
- transparent(factor: number): Color;
116
- isTransparent(): boolean;
117
- isOpaque(): boolean;
118
- opposite(): Color;
119
- blend(c: Color): Color;
120
- makeOpaque(opaqueBackground: Color): Color;
121
- flatten(...backgrounds: Color[]): Color;
122
- private static _flatten;
123
- toString(): string;
124
- static getLighterColor(of: Color, relative: Color, factor?: number): Color;
125
- static getDarkerColor(of: Color, relative: Color, factor?: number): Color;
126
- static readonly white: Color;
127
- static readonly black: Color;
128
- static readonly red: Color;
129
- static readonly blue: Color;
130
- static readonly green: Color;
131
- static readonly cyan: Color;
132
- static readonly lightgrey: Color;
133
- static readonly transparent: Color;
134
- }
135
- export declare namespace Color {
136
- namespace Format {
137
- namespace CSS {
138
- function formatRGB(color: Color): string;
139
- function formatRGBA(color: Color): string;
140
- function formatHSL(color: Color): string;
141
- function formatHSLA(color: Color): string;
142
- /**
143
- * Formats the color as #RRGGBB
144
- */
145
- function formatHex(color: Color): string;
146
- /**
147
- * Formats the color as #RRGGBBAA
148
- * If 'compact' is set, colors without transparancy will be printed as #RRGGBB
149
- */
150
- function formatHexA(color: Color, compact?: boolean): string;
151
- /**
152
- * The default format will use HEX if opaque and RGBA otherwise.
153
- */
154
- function format(color: Color): string | null;
155
- /**
156
- * Converts an Hex color value to a Color.
157
- * returns r, g, and b are contained in the set [0, 255]
158
- * @param hex string (#RGB, #RGBA, #RRGGBB or #RRGGBBAA).
159
- */
160
- function parseHex(hex: string): Color | null;
161
- }
162
- }
163
- }
@@ -1,495 +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
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.Color = exports.HSVA = exports.HSLA = exports.RGBA = void 0;
8
- function roundFloat(number, decimalPoints) {
9
- const decimal = Math.pow(10, decimalPoints);
10
- return Math.round(number * decimal) / decimal;
11
- }
12
- class RGBA {
13
- constructor(r, g, b, a = 1) {
14
- this.r = Math.min(255, Math.max(0, r)) | 0;
15
- this.g = Math.min(255, Math.max(0, g)) | 0;
16
- this.b = Math.min(255, Math.max(0, b)) | 0;
17
- this.a = roundFloat(Math.max(Math.min(1, a), 0), 3);
18
- }
19
- static equals(a, b) {
20
- return a.r === b.r && a.g === b.g && a.b === b.b && a.a === b.a;
21
- }
22
- }
23
- exports.RGBA = RGBA;
24
- class HSLA {
25
- constructor(h, s, l, a) {
26
- this.h = Math.max(Math.min(360, h), 0) | 0;
27
- this.s = roundFloat(Math.max(Math.min(1, s), 0), 3);
28
- this.l = roundFloat(Math.max(Math.min(1, l), 0), 3);
29
- this.a = roundFloat(Math.max(Math.min(1, a), 0), 3);
30
- }
31
- static equals(a, b) {
32
- return a.h === b.h && a.s === b.s && a.l === b.l && a.a === b.a;
33
- }
34
- /**
35
- * Converts an RGB color value to HSL. Conversion formula
36
- * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
37
- * Assumes r, g, and b are contained in the set [0, 255] and
38
- * returns h in the set [0, 360], s, and l in the set [0, 1].
39
- */
40
- static fromRGBA(rgba) {
41
- const r = rgba.r / 255;
42
- const g = rgba.g / 255;
43
- const b = rgba.b / 255;
44
- const a = rgba.a;
45
- const max = Math.max(r, g, b);
46
- const min = Math.min(r, g, b);
47
- let h = 0;
48
- let s = 0;
49
- const l = (min + max) / 2;
50
- const chroma = max - min;
51
- if (chroma > 0) {
52
- s = Math.min((l <= 0.5 ? chroma / (2 * l) : chroma / (2 - (2 * l))), 1);
53
- switch (max) {
54
- case r:
55
- h = (g - b) / chroma + (g < b ? 6 : 0);
56
- break;
57
- case g:
58
- h = (b - r) / chroma + 2;
59
- break;
60
- case b:
61
- h = (r - g) / chroma + 4;
62
- break;
63
- }
64
- h *= 60;
65
- h = Math.round(h);
66
- }
67
- return new HSLA(h, s, l, a);
68
- }
69
- static _hue2rgb(p, q, t) {
70
- if (t < 0) {
71
- t += 1;
72
- }
73
- if (t > 1) {
74
- t -= 1;
75
- }
76
- if (t < 1 / 6) {
77
- return p + (q - p) * 6 * t;
78
- }
79
- if (t < 1 / 2) {
80
- return q;
81
- }
82
- if (t < 2 / 3) {
83
- return p + (q - p) * (2 / 3 - t) * 6;
84
- }
85
- return p;
86
- }
87
- /**
88
- * Converts an HSL color value to RGB. Conversion formula
89
- * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
90
- * Assumes h in the set [0, 360] s, and l are contained in the set [0, 1] and
91
- * returns r, g, and b in the set [0, 255].
92
- */
93
- static toRGBA(hsla) {
94
- const h = hsla.h / 360;
95
- const { s, l, a } = hsla;
96
- let r, g, b;
97
- if (s === 0) {
98
- r = g = b = l; // achromatic
99
- }
100
- else {
101
- const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
102
- const p = 2 * l - q;
103
- r = HSLA._hue2rgb(p, q, h + 1 / 3);
104
- g = HSLA._hue2rgb(p, q, h);
105
- b = HSLA._hue2rgb(p, q, h - 1 / 3);
106
- }
107
- return new RGBA(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
108
- }
109
- }
110
- exports.HSLA = HSLA;
111
- class HSVA {
112
- constructor(h, s, v, a) {
113
- this.h = Math.max(Math.min(360, h), 0) | 0;
114
- this.s = roundFloat(Math.max(Math.min(1, s), 0), 3);
115
- this.v = roundFloat(Math.max(Math.min(1, v), 0), 3);
116
- this.a = roundFloat(Math.max(Math.min(1, a), 0), 3);
117
- }
118
- static equals(a, b) {
119
- return a.h === b.h && a.s === b.s && a.v === b.v && a.a === b.a;
120
- }
121
- // from http://www.rapidtables.com/convert/color/rgb-to-hsv.htm
122
- static fromRGBA(rgba) {
123
- const r = rgba.r / 255;
124
- const g = rgba.g / 255;
125
- const b = rgba.b / 255;
126
- const cmax = Math.max(r, g, b);
127
- const cmin = Math.min(r, g, b);
128
- const delta = cmax - cmin;
129
- const s = cmax === 0 ? 0 : (delta / cmax);
130
- let m;
131
- if (delta === 0) {
132
- m = 0;
133
- }
134
- else if (cmax === r) {
135
- m = ((((g - b) / delta) % 6) + 6) % 6;
136
- }
137
- else if (cmax === g) {
138
- m = ((b - r) / delta) + 2;
139
- }
140
- else {
141
- m = ((r - g) / delta) + 4;
142
- }
143
- return new HSVA(Math.round(m * 60), s, cmax, rgba.a);
144
- }
145
- // from http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
146
- static toRGBA(hsva) {
147
- const { h, s, v, a } = hsva;
148
- const c = v * s;
149
- const x = c * (1 - Math.abs((h / 60) % 2 - 1));
150
- const m = v - c;
151
- let [r, g, b] = [0, 0, 0];
152
- if (h < 60) {
153
- r = c;
154
- g = x;
155
- }
156
- else if (h < 120) {
157
- r = x;
158
- g = c;
159
- }
160
- else if (h < 180) {
161
- g = c;
162
- b = x;
163
- }
164
- else if (h < 240) {
165
- g = x;
166
- b = c;
167
- }
168
- else if (h < 300) {
169
- r = x;
170
- b = c;
171
- }
172
- else if (h < 360) {
173
- r = c;
174
- b = x;
175
- }
176
- r = Math.round((r + m) * 255);
177
- g = Math.round((g + m) * 255);
178
- b = Math.round((b + m) * 255);
179
- return new RGBA(r, g, b, a);
180
- }
181
- }
182
- exports.HSVA = HSVA;
183
- class Color {
184
- constructor(arg) {
185
- if (!arg) {
186
- throw new Error('Color needs a value');
187
- }
188
- else if (arg instanceof RGBA) {
189
- this.rgba = arg;
190
- }
191
- else if (arg instanceof HSLA) {
192
- this._hsla = arg;
193
- this.rgba = HSLA.toRGBA(arg);
194
- }
195
- else if (arg instanceof HSVA) {
196
- this._hsva = arg;
197
- this.rgba = HSVA.toRGBA(arg);
198
- }
199
- else {
200
- throw new Error('Invalid color ctor argument');
201
- }
202
- }
203
- static fromHex(hex) {
204
- return Color.Format.CSS.parseHex(hex) || Color.red;
205
- }
206
- get hsla() {
207
- if (this._hsla) {
208
- return this._hsla;
209
- }
210
- else {
211
- return HSLA.fromRGBA(this.rgba);
212
- }
213
- }
214
- get hsva() {
215
- if (this._hsva) {
216
- return this._hsva;
217
- }
218
- return HSVA.fromRGBA(this.rgba);
219
- }
220
- equals(other) {
221
- return !!other && RGBA.equals(this.rgba, other.rgba) && HSLA.equals(this.hsla, other.hsla) && HSVA.equals(this.hsva, other.hsva);
222
- }
223
- /**
224
- * http://www.w3.org/TR/WCAG20/#relativeluminancedef
225
- * Returns the number in the set [0, 1]. O => Darkest Black. 1 => Lightest white.
226
- */
227
- getRelativeLuminance() {
228
- const R = Color._relativeLuminanceForComponent(this.rgba.r);
229
- const G = Color._relativeLuminanceForComponent(this.rgba.g);
230
- const B = Color._relativeLuminanceForComponent(this.rgba.b);
231
- const luminance = 0.2126 * R + 0.7152 * G + 0.0722 * B;
232
- return roundFloat(luminance, 4);
233
- }
234
- static _relativeLuminanceForComponent(color) {
235
- const c = color / 255;
236
- return (c <= 0.03928) ? c / 12.92 : Math.pow(((c + 0.055) / 1.055), 2.4);
237
- }
238
- /**
239
- * http://www.w3.org/TR/WCAG20/#contrast-ratiodef
240
- * Returns the contrast ration number in the set [1, 21].
241
- */
242
- getContrastRatio(another) {
243
- const lum1 = this.getRelativeLuminance();
244
- const lum2 = another.getRelativeLuminance();
245
- return lum1 > lum2 ? (lum1 + 0.05) / (lum2 + 0.05) : (lum2 + 0.05) / (lum1 + 0.05);
246
- }
247
- /**
248
- * http://24ways.org/2010/calculating-color-contrast
249
- * Return 'true' if darker color otherwise 'false'
250
- */
251
- isDarker() {
252
- const yiq = (this.rgba.r * 299 + this.rgba.g * 587 + this.rgba.b * 114) / 1000;
253
- return yiq < 128;
254
- }
255
- /**
256
- * http://24ways.org/2010/calculating-color-contrast
257
- * Return 'true' if lighter color otherwise 'false'
258
- */
259
- isLighter() {
260
- const yiq = (this.rgba.r * 299 + this.rgba.g * 587 + this.rgba.b * 114) / 1000;
261
- return yiq >= 128;
262
- }
263
- isLighterThan(another) {
264
- const lum1 = this.getRelativeLuminance();
265
- const lum2 = another.getRelativeLuminance();
266
- return lum1 > lum2;
267
- }
268
- isDarkerThan(another) {
269
- const lum1 = this.getRelativeLuminance();
270
- const lum2 = another.getRelativeLuminance();
271
- return lum1 < lum2;
272
- }
273
- lighten(factor) {
274
- return new Color(new HSLA(this.hsla.h, this.hsla.s, this.hsla.l + this.hsla.l * factor, this.hsla.a));
275
- }
276
- darken(factor) {
277
- return new Color(new HSLA(this.hsla.h, this.hsla.s, this.hsla.l - this.hsla.l * factor, this.hsla.a));
278
- }
279
- transparent(factor) {
280
- const { r, g, b, a } = this.rgba;
281
- return new Color(new RGBA(r, g, b, a * factor));
282
- }
283
- isTransparent() {
284
- return this.rgba.a === 0;
285
- }
286
- isOpaque() {
287
- return this.rgba.a === 1;
288
- }
289
- opposite() {
290
- return new Color(new RGBA(255 - this.rgba.r, 255 - this.rgba.g, 255 - this.rgba.b, this.rgba.a));
291
- }
292
- blend(c) {
293
- const rgba = c.rgba;
294
- // Convert to 0..1 opacity
295
- const thisA = this.rgba.a;
296
- const colorA = rgba.a;
297
- const a = thisA + colorA * (1 - thisA);
298
- if (a < 1e-6) {
299
- return Color.transparent;
300
- }
301
- const r = this.rgba.r * thisA / a + rgba.r * colorA * (1 - thisA) / a;
302
- const g = this.rgba.g * thisA / a + rgba.g * colorA * (1 - thisA) / a;
303
- const b = this.rgba.b * thisA / a + rgba.b * colorA * (1 - thisA) / a;
304
- return new Color(new RGBA(r, g, b, a));
305
- }
306
- makeOpaque(opaqueBackground) {
307
- if (this.isOpaque() || opaqueBackground.rgba.a !== 1) {
308
- // only allow to blend onto a non-opaque color onto a opaque color
309
- return this;
310
- }
311
- const { r, g, b, a } = this.rgba;
312
- // https://stackoverflow.com/questions/12228548/finding-equivalent-color-with-opacity
313
- 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));
314
- }
315
- flatten(...backgrounds) {
316
- const background = backgrounds.reduceRight((accumulator, color) => {
317
- return Color._flatten(color, accumulator);
318
- });
319
- return Color._flatten(this, background);
320
- }
321
- static _flatten(foreground, background) {
322
- const backgroundAlpha = 1 - foreground.rgba.a;
323
- 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));
324
- }
325
- toString() {
326
- return '' + Color.Format.CSS.format(this);
327
- }
328
- static getLighterColor(of, relative, factor) {
329
- if (of.isLighterThan(relative)) {
330
- return of;
331
- }
332
- factor = factor ? factor : 0.5;
333
- const lum1 = of.getRelativeLuminance();
334
- const lum2 = relative.getRelativeLuminance();
335
- factor = factor * (lum2 - lum1) / lum2;
336
- return of.lighten(factor);
337
- }
338
- static getDarkerColor(of, relative, factor) {
339
- if (of.isDarkerThan(relative)) {
340
- return of;
341
- }
342
- factor = factor ? factor : 0.5;
343
- const lum1 = of.getRelativeLuminance();
344
- const lum2 = relative.getRelativeLuminance();
345
- factor = factor * (lum1 - lum2) / lum1;
346
- return of.darken(factor);
347
- }
348
- }
349
- exports.Color = Color;
350
- Color.white = new Color(new RGBA(255, 255, 255, 1));
351
- Color.black = new Color(new RGBA(0, 0, 0, 1));
352
- Color.red = new Color(new RGBA(255, 0, 0, 1));
353
- Color.blue = new Color(new RGBA(0, 0, 255, 1));
354
- Color.green = new Color(new RGBA(0, 255, 0, 1));
355
- Color.cyan = new Color(new RGBA(0, 255, 255, 1));
356
- Color.lightgrey = new Color(new RGBA(211, 211, 211, 1));
357
- Color.transparent = new Color(new RGBA(0, 0, 0, 0));
358
- (function (Color) {
359
- let Format;
360
- (function (Format) {
361
- let CSS;
362
- (function (CSS) {
363
- function formatRGB(color) {
364
- if (color.rgba.a === 1) {
365
- return `rgb(${color.rgba.r}, ${color.rgba.g}, ${color.rgba.b})`;
366
- }
367
- return Color.Format.CSS.formatRGBA(color);
368
- }
369
- CSS.formatRGB = formatRGB;
370
- function formatRGBA(color) {
371
- return `rgba(${color.rgba.r}, ${color.rgba.g}, ${color.rgba.b}, ${+(color.rgba.a).toFixed(2)})`;
372
- }
373
- CSS.formatRGBA = formatRGBA;
374
- function formatHSL(color) {
375
- if (color.hsla.a === 1) {
376
- return `hsl(${color.hsla.h}, ${(color.hsla.s * 100).toFixed(2)}%, ${(color.hsla.l * 100).toFixed(2)}%)`;
377
- }
378
- return Color.Format.CSS.formatHSLA(color);
379
- }
380
- CSS.formatHSL = formatHSL;
381
- function formatHSLA(color) {
382
- return `hsla(${color.hsla.h}, ${(color.hsla.s * 100).toFixed(2)}%, ${(color.hsla.l * 100).toFixed(2)}%, ${color.hsla.a.toFixed(2)})`;
383
- }
384
- CSS.formatHSLA = formatHSLA;
385
- function _toTwoDigitHex(n) {
386
- const r = n.toString(16);
387
- return r.length !== 2 ? '0' + r : r;
388
- }
389
- /**
390
- * Formats the color as #RRGGBB
391
- */
392
- function formatHex(color) {
393
- return `#${_toTwoDigitHex(color.rgba.r)}${_toTwoDigitHex(color.rgba.g)}${_toTwoDigitHex(color.rgba.b)}`;
394
- }
395
- CSS.formatHex = formatHex;
396
- /**
397
- * Formats the color as #RRGGBBAA
398
- * If 'compact' is set, colors without transparancy will be printed as #RRGGBB
399
- */
400
- function formatHexA(color, compact = false) {
401
- if (compact && color.rgba.a === 1) {
402
- return Color.Format.CSS.formatHex(color);
403
- }
404
- return `#${_toTwoDigitHex(color.rgba.r)}${_toTwoDigitHex(color.rgba.g)}${_toTwoDigitHex(color.rgba.b)}${_toTwoDigitHex(Math.round(color.rgba.a * 255))}`;
405
- }
406
- CSS.formatHexA = formatHexA;
407
- /**
408
- * The default format will use HEX if opaque and RGBA otherwise.
409
- */
410
- function format(color) {
411
- if (color.isOpaque()) {
412
- return Color.Format.CSS.formatHex(color);
413
- }
414
- return Color.Format.CSS.formatRGBA(color);
415
- }
416
- CSS.format = format;
417
- /**
418
- * Converts an Hex color value to a Color.
419
- * returns r, g, and b are contained in the set [0, 255]
420
- * @param hex string (#RGB, #RGBA, #RRGGBB or #RRGGBBAA).
421
- */
422
- function parseHex(hex) {
423
- const length = hex.length;
424
- if (length === 0) {
425
- // Invalid color
426
- return null;
427
- }
428
- if (hex.charCodeAt(0) !== 35 /* Hash */) {
429
- // Does not begin with a #
430
- return null;
431
- }
432
- if (length === 7) {
433
- // #RRGGBB format
434
- const r = 16 * _parseHexDigit(hex.charCodeAt(1)) + _parseHexDigit(hex.charCodeAt(2));
435
- const g = 16 * _parseHexDigit(hex.charCodeAt(3)) + _parseHexDigit(hex.charCodeAt(4));
436
- const b = 16 * _parseHexDigit(hex.charCodeAt(5)) + _parseHexDigit(hex.charCodeAt(6));
437
- return new Color(new RGBA(r, g, b, 1));
438
- }
439
- if (length === 9) {
440
- // #RRGGBBAA format
441
- const r = 16 * _parseHexDigit(hex.charCodeAt(1)) + _parseHexDigit(hex.charCodeAt(2));
442
- const g = 16 * _parseHexDigit(hex.charCodeAt(3)) + _parseHexDigit(hex.charCodeAt(4));
443
- const b = 16 * _parseHexDigit(hex.charCodeAt(5)) + _parseHexDigit(hex.charCodeAt(6));
444
- const a = 16 * _parseHexDigit(hex.charCodeAt(7)) + _parseHexDigit(hex.charCodeAt(8));
445
- return new Color(new RGBA(r, g, b, a / 255));
446
- }
447
- if (length === 4) {
448
- // #RGB format
449
- const r = _parseHexDigit(hex.charCodeAt(1));
450
- const g = _parseHexDigit(hex.charCodeAt(2));
451
- const b = _parseHexDigit(hex.charCodeAt(3));
452
- return new Color(new RGBA(16 * r + r, 16 * g + g, 16 * b + b));
453
- }
454
- if (length === 5) {
455
- // #RGBA format
456
- const r = _parseHexDigit(hex.charCodeAt(1));
457
- const g = _parseHexDigit(hex.charCodeAt(2));
458
- const b = _parseHexDigit(hex.charCodeAt(3));
459
- const a = _parseHexDigit(hex.charCodeAt(4));
460
- return new Color(new RGBA(16 * r + r, 16 * g + g, 16 * b + b, (16 * a + a) / 255));
461
- }
462
- // Invalid color
463
- return null;
464
- }
465
- CSS.parseHex = parseHex;
466
- function _parseHexDigit(charCode) {
467
- switch (charCode) {
468
- case 48 /* Digit0 */: return 0;
469
- case 49 /* Digit1 */: return 1;
470
- case 50 /* Digit2 */: return 2;
471
- case 51 /* Digit3 */: return 3;
472
- case 52 /* Digit4 */: return 4;
473
- case 53 /* Digit5 */: return 5;
474
- case 54 /* Digit6 */: return 6;
475
- case 55 /* Digit7 */: return 7;
476
- case 56 /* Digit8 */: return 8;
477
- case 57 /* Digit9 */: return 9;
478
- case 97 /* a */: return 10;
479
- case 65 /* A */: return 10;
480
- case 98 /* b */: return 11;
481
- case 66 /* B */: return 11;
482
- case 99 /* c */: return 12;
483
- case 67 /* C */: return 12;
484
- case 100 /* d */: return 13;
485
- case 68 /* D */: return 13;
486
- case 101 /* e */: return 14;
487
- case 69 /* E */: return 14;
488
- case 102 /* f */: return 15;
489
- case 70 /* F */: return 15;
490
- }
491
- return 0;
492
- }
493
- })(CSS = Format.CSS || (Format.CSS = {}));
494
- })(Format = Color.Format || (Color.Format = {}));
495
- })(Color = exports.Color || (exports.Color = {}));