@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.
@@ -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 rgba2Hex(rgba) {
98
- let rgbaVal = typeof rgba == 'string' ? rgba : `rgba(${rgba.r},${rgba.g},${rgba.b},${rgba.a ?? '1'})`;
99
- const rgbaArr = rgbaVal.replace(/^rgba?\(|\s+|\)$/g, '').split(',');
100
- const hex = `#${((1 << 24) + (parseInt(rgbaArr[0]) << 16) + (parseInt(rgbaArr[1]) << 8) + parseInt(rgbaArr[2])).toString(16).slice(1)}`;
101
- return hex == '#aN' ? null : hex;
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 hex2Rgb(hexColor) {
105
- let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hexColor);
106
- return result ? {
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.hex2Rgb(hexColor);
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(hexColor) {
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
  }