@acorex/core 5.3.4 → 5.6.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,59 @@ 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.toRgb();
107
+ case 'hsla':
108
+ return _color.toHsl();
109
+ case 'hsva':
110
+ return _color.toHsv();
111
+ default:
112
+ return _color.toHex();
113
+ }
114
+ }
115
+ ;
116
+ static toString(color, mode) {
117
+ const _color = tinycolor(color);
118
+ switch (mode) {
119
+ case 'rgba':
120
+ return _color.toRgbString();
121
+ case 'hsla':
122
+ return _color.toHslString();
123
+ case 'hsva':
124
+ return _color.toHsvString();
125
+ default:
126
+ return _color.toHexString();
127
+ }
102
128
  }
103
129
  ;
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;
130
+ static mix(baseColor, hex, percentage) {
131
+ return tinycolor.mix(baseColor, hex, percentage);
132
+ }
133
+ static multiply(rgb1, rgb2) {
134
+ rgb1.b = Math.floor(rgb1.b * rgb2.b / 255);
135
+ rgb1.g = Math.floor(rgb1.g * rgb2.g / 255);
136
+ rgb1.r = Math.floor(rgb1.r * rgb2.r / 255);
137
+ return tinycolor('rgb ' + rgb1.r + ' ' + rgb1.g + ' ' + rgb1.b);
138
+ }
139
+ static toHexSting(color) {
140
+ const _color = tinycolor(color);
141
+ return _color.toHexString();
142
+ }
143
+ ;
144
+ static toRGBString(color) {
145
+ const _color = tinycolor(color);
146
+ return _color.toRgbString();
111
147
  }
112
148
  ;
113
149
  static illuminance(hexColor) {
114
- let rgbColor = AXColorUtil.hex2Rgb(hexColor);
150
+ let rgbColor = AXColorUtil.toRGBString(hexColor);
115
151
  if (!rgbColor)
116
152
  return -1;
117
153
  let r = rgbColor.r, g = rgbColor.g, b = rgbColor.b;
@@ -124,12 +160,19 @@ class AXColorUtil {
124
160
  return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
125
161
  }
126
162
  ;
127
- static contrastToWhite(hexColor) {
128
- let whiteIlluminance = 1;
129
- let illuminance = AXColorUtil.illuminance(hexColor);
130
- return whiteIlluminance / illuminance;
163
+ static contrastToWhite(color) {
164
+ // let whiteIlluminance = 1;
165
+ // let illuminance = AXColorUtil.illuminance(hexColor);
166
+ // return whiteIlluminance / illuminance;
167
+ return tinycolor.readability("#fff", color);
131
168
  }
132
169
  ;
170
+ static lighten(hex, percentage) {
171
+ return tinycolor(hex).lighten(percentage);
172
+ }
173
+ static darken(hex, percentage) {
174
+ return tinycolor(hex).darken(percentage);
175
+ }
133
176
  }
134
177
 
135
178
  class AXSafePipe {
@@ -1171,8 +1214,9 @@ class AXTranslator {
1171
1214
  static use(lang) {
1172
1215
  AXTranslator.lang = lang;
1173
1216
  }
1174
- static get(key, lang, params) {
1175
- lang = lang || AXTranslator.lang;
1217
+ static get(key, arg1, arg2) {
1218
+ const lang = arg1 && typeof arg1 == 'string' ? arg1 : AXTranslator.lang;
1219
+ const params = arg1 && typeof arg1 == 'object' ? arg1 : arg2;
1176
1220
  let result = _.get(AXTranslator[`__data__${lang}`], key, key);
1177
1221
  const vars = typeof (result) == 'string' ? result?.match(this._varsRegx) : [];
1178
1222
  if (vars?.length) {
@@ -1195,8 +1239,8 @@ AXTranslator._varsRegx = /((\$\{[a-zA-Z_0-9\.]+\})+)/gm;
1195
1239
  AXTranslator._varNameRegx = /[a-zA-Z_0-9\.]+/gm;
1196
1240
 
1197
1241
  class AXTranslatorPipe {
1198
- transform(value, lang) {
1199
- return AXTranslator.get(value, lang);
1242
+ transform(value, arg1, arg2) {
1243
+ return AXTranslator.get(value, arg1, arg2);
1200
1244
  }
1201
1245
  }
1202
1246
  AXTranslatorPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.9", ngImport: i0, type: AXTranslatorPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });