@osimatic/helpers-js 1.0.87 → 1.0.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/draw.js +53 -0
- package/index.js +2 -1
- package/package.json +1 -1
package/draw.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class HexColor {
|
|
2
|
+
static check(hexColor) {
|
|
3
|
+
return hexColor.match(/^[0-9a-fA-F]{6}$/).length;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
static convertToRgb(hexColor) {
|
|
7
|
+
if (hexColor.substring(0, 1) === '#') {
|
|
8
|
+
hexColor = hexColor.substring(1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (hexColor.length === 3) {
|
|
12
|
+
hexColor = hexColor+hexColor;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!HexColor.check(hexColor)) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let hexRed = hexColor.substring(0,2);
|
|
20
|
+
let hexGreen = hexColor.substring(2,4);
|
|
21
|
+
let hexBlue = hexColor.substring(4,6);
|
|
22
|
+
|
|
23
|
+
let red = parseInt(hexRed, 16);
|
|
24
|
+
let green = parseInt(hexGreen, 16);
|
|
25
|
+
let blue = parseInt(hexBlue, 16);
|
|
26
|
+
|
|
27
|
+
return [red, green, blue];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static isLight(hexColor) {
|
|
31
|
+
let rgb = HexColor.convertToRgb(hexColor);
|
|
32
|
+
if (rgb === null) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return RgbColor.isLight(rgb[0], rgb[1], rgb[2]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class RgbColor {
|
|
40
|
+
static isLight(red, green, blue) {
|
|
41
|
+
const PERCENT_RED = 0.2125;
|
|
42
|
+
const PERCENT_GREEN = 0.7154;
|
|
43
|
+
const PERCENT_BLUE = 0.0721;
|
|
44
|
+
// $percentageRed = 0.3;
|
|
45
|
+
// $percentageGreen = 0.59;
|
|
46
|
+
// $percentageBlue = 0.11;
|
|
47
|
+
|
|
48
|
+
let coeff = (PERCENT_RED*red) + (PERCENT_GREEN*green) + (PERCENT_BLUE*blue);
|
|
49
|
+
return coeff > 128;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { HexColor, RgbColor };
|
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@ const { Duration } = require('./duration');
|
|
|
16
16
|
const { File, CSV, Img } = require('./file');
|
|
17
17
|
const { FormHelper, EditValue } = require('./form_helper');
|
|
18
18
|
const { Country, PostalAddress, GeographicCoordinates } = require('./location');
|
|
19
|
+
const { HexColor, RgbColor } = require('./draw');
|
|
19
20
|
const { SocialNetwork } = require('./social_network');
|
|
20
21
|
const { sleep, refresh } = require('./util');
|
|
21
22
|
const { chr, ord, trim, empty } = require('./php.min');
|
|
@@ -46,7 +47,7 @@ const { WebSocket } = require('./web_socket');
|
|
|
46
47
|
|
|
47
48
|
module.exports = {
|
|
48
49
|
Array, Object, Number, String,
|
|
49
|
-
HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, SocialNetwork,
|
|
50
|
+
HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, HexColor, RgbColor, SocialNetwork,
|
|
50
51
|
Browser, DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, MultipleActionInDivList, EditValue, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ApiTokenSession, ListBox, WebRTC, WebSocket, EventBus,
|
|
51
52
|
sleep, refresh, chr, ord, trim, empty,
|
|
52
53
|
GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
|