@acorex/core 5.3.4 → 5.4.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.
- package/config/ax-preset.js +16 -0
- package/esm2020/lib/utils/color-util.mjs +32 -18
- package/fesm2015/acorex-core.mjs +31 -18
- package/fesm2015/acorex-core.mjs.map +1 -1
- package/fesm2020/acorex-core.mjs +31 -17
- package/fesm2020/acorex-core.mjs.map +1 -1
- package/lib/utils/color-util.d.ts +6 -12
- package/package.json +3 -2
package/fesm2020/acorex-core.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Pipe, NgModule, Injectable, Inject } from '@angular/core';
|
|
3
|
+
import tinycolor from 'tinycolor2';
|
|
3
4
|
import * as i1 from '@angular/platform-browser';
|
|
4
5
|
import _ from 'lodash';
|
|
5
6
|
import { Subject, fromEvent } from 'rxjs';
|
|
@@ -94,24 +95,36 @@ class AXStringUtil {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
class AXColorUtil {
|
|
97
|
-
static
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
static testa(color) {
|
|
99
|
+
var _color = tinycolor(color);
|
|
100
|
+
console.log(_color);
|
|
101
|
+
}
|
|
102
|
+
static to(color, mode) {
|
|
103
|
+
const _color = tinycolor(color);
|
|
104
|
+
switch (mode) {
|
|
105
|
+
case 'rgba':
|
|
106
|
+
return _color.toRgbString();
|
|
107
|
+
case 'hsla':
|
|
108
|
+
return _color.toHslString();
|
|
109
|
+
case 'hsva':
|
|
110
|
+
return _color.toHsvString();
|
|
111
|
+
default:
|
|
112
|
+
return _color.toHexString();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
;
|
|
116
|
+
static toHex(color) {
|
|
117
|
+
const _color = tinycolor(color);
|
|
118
|
+
return _color.toHexString();
|
|
102
119
|
}
|
|
103
120
|
;
|
|
104
|
-
static
|
|
105
|
-
|
|
106
|
-
return
|
|
107
|
-
r: parseInt(result[1], 16),
|
|
108
|
-
g: parseInt(result[2], 16),
|
|
109
|
-
b: parseInt(result[3], 16)
|
|
110
|
-
} : null;
|
|
121
|
+
static toRGB(color) {
|
|
122
|
+
const _color = tinycolor(color);
|
|
123
|
+
return _color.toRgbString();
|
|
111
124
|
}
|
|
112
125
|
;
|
|
113
126
|
static illuminance(hexColor) {
|
|
114
|
-
let rgbColor = AXColorUtil.
|
|
127
|
+
let rgbColor = AXColorUtil.toRGB(hexColor);
|
|
115
128
|
if (!rgbColor)
|
|
116
129
|
return -1;
|
|
117
130
|
let r = rgbColor.r, g = rgbColor.g, b = rgbColor.b;
|
|
@@ -124,10 +137,11 @@ class AXColorUtil {
|
|
|
124
137
|
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
|
|
125
138
|
}
|
|
126
139
|
;
|
|
127
|
-
static contrastToWhite(
|
|
128
|
-
let whiteIlluminance = 1;
|
|
129
|
-
let illuminance = AXColorUtil.illuminance(hexColor);
|
|
130
|
-
return whiteIlluminance / illuminance;
|
|
140
|
+
static contrastToWhite(color) {
|
|
141
|
+
// let whiteIlluminance = 1;
|
|
142
|
+
// let illuminance = AXColorUtil.illuminance(hexColor);
|
|
143
|
+
// return whiteIlluminance / illuminance;
|
|
144
|
+
return tinycolor.readability("#fff", color);
|
|
131
145
|
}
|
|
132
146
|
;
|
|
133
147
|
}
|