@ibragim-dev-org/ui-forge-library 1.2.0 → 1.2.2
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.
|
@@ -442,14 +442,79 @@ function getAspectRatioFit(maxWidth, maxHeight, srcWidth, srcHeight) {
|
|
|
442
442
|
return { width: maxWidth, height: maxHeight };
|
|
443
443
|
}
|
|
444
444
|
|
|
445
|
-
|
|
445
|
+
const stringToHslColor = (value) => {
|
|
446
|
+
const MIN_CONTRAST_WITH_WHITE_TEXT = 3;
|
|
447
|
+
const hslToRgb = (h, s, l) => {
|
|
448
|
+
const sn = s / 100;
|
|
449
|
+
const ln = l / 100;
|
|
450
|
+
const c = (1 - Math.abs(2 * ln - 1)) * sn;
|
|
451
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
452
|
+
const m = ln - c / 2;
|
|
453
|
+
let r1 = 0, g1 = 0, b1 = 0;
|
|
454
|
+
if (h < 60) {
|
|
455
|
+
r1 = c;
|
|
456
|
+
g1 = x;
|
|
457
|
+
}
|
|
458
|
+
else if (h < 120) {
|
|
459
|
+
r1 = x;
|
|
460
|
+
g1 = c;
|
|
461
|
+
}
|
|
462
|
+
else if (h < 180) {
|
|
463
|
+
g1 = c;
|
|
464
|
+
b1 = x;
|
|
465
|
+
}
|
|
466
|
+
else if (h < 240) {
|
|
467
|
+
g1 = x;
|
|
468
|
+
b1 = c;
|
|
469
|
+
}
|
|
470
|
+
else if (h < 300) {
|
|
471
|
+
r1 = x;
|
|
472
|
+
b1 = c;
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
r1 = c;
|
|
476
|
+
b1 = x;
|
|
477
|
+
}
|
|
478
|
+
return [Math.round((r1 + m) * 255), Math.round((g1 + m) * 255), Math.round((b1 + m) * 255)];
|
|
479
|
+
};
|
|
480
|
+
const linearize = (channel) => {
|
|
481
|
+
const normalized = channel / 255;
|
|
482
|
+
return normalized <= 0.03928 ? normalized / 12.92 : ((normalized + 0.055) / 1.055) ** 2.4;
|
|
483
|
+
};
|
|
484
|
+
const contrastWithWhiteText = (h, s, l) => {
|
|
485
|
+
const [r, g, b] = hslToRgb(h, s, l);
|
|
486
|
+
const luminance = 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);
|
|
487
|
+
return (1.05 + 0.05) / (luminance + 0.05);
|
|
488
|
+
};
|
|
489
|
+
// Hash the text → deterministic number
|
|
446
490
|
let hash = 0;
|
|
447
|
-
for (let i = 0; i <
|
|
448
|
-
hash =
|
|
449
|
-
hash
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
|
|
491
|
+
for (let i = 0; i < value.length; i++) {
|
|
492
|
+
hash = value.charCodeAt(i) + ((hash << 5) - hash);
|
|
493
|
+
hash &= hash;
|
|
494
|
+
}
|
|
495
|
+
const absHash = Math.abs(hash);
|
|
496
|
+
// Rainbow hue families: Red, Orange, Yellow, Green, Blue, Indigo, Violet
|
|
497
|
+
const HUE_RANGES = [
|
|
498
|
+
[0, 20], // Red
|
|
499
|
+
[25, 40], // Orange
|
|
500
|
+
[50, 65], // Yellow
|
|
501
|
+
[110, 140], // Green
|
|
502
|
+
[200, 230], // Blue
|
|
503
|
+
[240, 260], // Indigo
|
|
504
|
+
[270, 300], // Violet
|
|
505
|
+
];
|
|
506
|
+
const [minHue, maxHue] = HUE_RANGES[absHash % HUE_RANGES.length];
|
|
507
|
+
const hueSpan = maxHue - minHue;
|
|
508
|
+
const hue = minHue + ((absHash >> 3) % (hueSpan + 1));
|
|
509
|
+
// Vivid saturation/lightness
|
|
510
|
+
const saturation = 80; // fixed vivid
|
|
511
|
+
let lightness = 50; // balanced
|
|
512
|
+
// Adjust lightness until white text is readable
|
|
513
|
+
while (lightness > 30 && contrastWithWhiteText(hue, saturation, lightness) < MIN_CONTRAST_WITH_WHITE_TEXT) {
|
|
514
|
+
lightness -= 2;
|
|
515
|
+
}
|
|
516
|
+
return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
|
517
|
+
};
|
|
453
518
|
|
|
454
519
|
class AppIconsLibrary {
|
|
455
520
|
icons = new Map();
|
|
@@ -850,7 +915,6 @@ class UiAvatarDirective {
|
|
|
850
915
|
$src = input.required(...(ngDevMode ? [{ debugName: "$src" }] : []));
|
|
851
916
|
$acronym = input.required(...(ngDevMode ? [{ debugName: "$acronym" }] : []));
|
|
852
917
|
$backgroundColor = signal('', ...(ngDevMode ? [{ debugName: "$backgroundColor" }] : []));
|
|
853
|
-
$textColor = signal('', ...(ngDevMode ? [{ debugName: "$textColor" }] : []));
|
|
854
918
|
$text = signal('', ...(ngDevMode ? [{ debugName: "$text" }] : []));
|
|
855
919
|
$canShowAvatar = signal(true, ...(ngDevMode ? [{ debugName: "$canShowAvatar" }] : []));
|
|
856
920
|
constructor() {
|
|
@@ -861,8 +925,7 @@ class UiAvatarDirective {
|
|
|
861
925
|
.forEach((v) => {
|
|
862
926
|
acronym = acronym + v[0];
|
|
863
927
|
});
|
|
864
|
-
this.$backgroundColor.set(stringToHslColor(
|
|
865
|
-
this.$textColor.set(stringToHslColor(this.$acronym(), 100, 35));
|
|
928
|
+
this.$backgroundColor.set(stringToHslColor(acronym[0]));
|
|
866
929
|
this.$text.set(acronym);
|
|
867
930
|
});
|
|
868
931
|
}
|
|
@@ -2916,18 +2979,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
|
|
|
2916
2979
|
class UIInputDateDirective extends UiInputDirective {
|
|
2917
2980
|
$isOpen = signal(false, ...(ngDevMode ? [{ debugName: "$isOpen" }] : []));
|
|
2918
2981
|
$isRangeSelection = input(false, ...(ngDevMode ? [{ debugName: "$isRangeSelection" }] : []));
|
|
2982
|
+
$dividePattern = input('/', ...(ngDevMode ? [{ debugName: "$dividePattern" }] : []));
|
|
2919
2983
|
$inputElement = viewChild('input', ...(ngDevMode ? [{ debugName: "$inputElement" }] : []));
|
|
2920
2984
|
setDate(date) {
|
|
2921
2985
|
const newDate = this.formatDate(date);
|
|
2922
2986
|
this.onInput(newDate);
|
|
2923
2987
|
}
|
|
2924
2988
|
formatDate(date) {
|
|
2989
|
+
const pattern = this.$dividePattern();
|
|
2925
2990
|
const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate().toString();
|
|
2926
2991
|
const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1).toString();
|
|
2927
2992
|
if (this.isUsaDateFormat()) {
|
|
2928
|
-
return month +
|
|
2993
|
+
return month + pattern + day + pattern + date.getFullYear();
|
|
2929
2994
|
}
|
|
2930
|
-
return day +
|
|
2995
|
+
return day + pattern + month + pattern + date.getFullYear();
|
|
2931
2996
|
}
|
|
2932
2997
|
isUsaDateFormat() {
|
|
2933
2998
|
return DateUtils.isUsaDateFormat();
|
|
@@ -2949,15 +3014,15 @@ class UIInputDateDirective extends UiInputDirective {
|
|
|
2949
3014
|
const end = inputElement.selectionEnd;
|
|
2950
3015
|
const oldValue = value;
|
|
2951
3016
|
const newValue = this.maskDate(oldValue);
|
|
2952
|
-
const
|
|
2953
|
-
const
|
|
2954
|
-
const
|
|
2955
|
-
const
|
|
2956
|
-
const
|
|
2957
|
-
const
|
|
3017
|
+
const pattern = this.$dividePattern();
|
|
3018
|
+
const escapedPattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3019
|
+
const patternRegex = new RegExp(escapedPattern, 'g');
|
|
3020
|
+
const oldPatternCount = (oldValue.match(patternRegex) || []).length;
|
|
3021
|
+
const newPatternCount = (newValue.match(patternRegex) || []).length;
|
|
3022
|
+
const patternAdded = newPatternCount > oldPatternCount;
|
|
2958
3023
|
super.onInput(newValue);
|
|
2959
3024
|
inputElement.value = newValue;
|
|
2960
|
-
if (
|
|
3025
|
+
if (patternAdded) {
|
|
2961
3026
|
inputElement.setSelectionRange(newValue.length, newValue.length);
|
|
2962
3027
|
}
|
|
2963
3028
|
else {
|
|
@@ -2970,15 +3035,16 @@ class UIInputDateDirective extends UiInputDirective {
|
|
|
2970
3035
|
const limit = this.$isRangeSelection() ? 16 : 8;
|
|
2971
3036
|
const limited = digits.substring(0, limit);
|
|
2972
3037
|
const formatSingle = (str) => {
|
|
3038
|
+
const pattern = this.$dividePattern();
|
|
2973
3039
|
let res = '';
|
|
2974
3040
|
if (str.length > 0) {
|
|
2975
3041
|
res += str.substring(0, 2);
|
|
2976
3042
|
}
|
|
2977
3043
|
if (str.length >= 3) {
|
|
2978
|
-
res +=
|
|
3044
|
+
res += pattern + str.substring(2, 4);
|
|
2979
3045
|
}
|
|
2980
3046
|
if (str.length >= 5) {
|
|
2981
|
-
res +=
|
|
3047
|
+
res += pattern + str.substring(4, 8);
|
|
2982
3048
|
}
|
|
2983
3049
|
return res;
|
|
2984
3050
|
};
|
|
@@ -2992,14 +3058,14 @@ class UIInputDateDirective extends UiInputDirective {
|
|
|
2992
3058
|
return formatSingle(limited);
|
|
2993
3059
|
}
|
|
2994
3060
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UIInputDateDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
2995
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.1.1", type: UIInputDateDirective, isStandalone: true, selector: "app-ui-input-date", inputs: { $isRangeSelection: { classPropertyName: "$isRangeSelection", publicName: "$isRangeSelection", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "$inputElement", first: true, predicate: ["input"], descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0 });
|
|
3061
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.1.1", type: UIInputDateDirective, isStandalone: true, selector: "app-ui-input-date", inputs: { $isRangeSelection: { classPropertyName: "$isRangeSelection", publicName: "$isRangeSelection", isSignal: true, isRequired: false, transformFunction: null }, $dividePattern: { classPropertyName: "$dividePattern", publicName: "$dividePattern", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "$inputElement", first: true, predicate: ["input"], descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0 });
|
|
2996
3062
|
}
|
|
2997
3063
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UIInputDateDirective, decorators: [{
|
|
2998
3064
|
type: Directive,
|
|
2999
3065
|
args: [{
|
|
3000
3066
|
selector: 'app-ui-input-date',
|
|
3001
3067
|
}]
|
|
3002
|
-
}], propDecorators: { $isRangeSelection: [{ type: i0.Input, args: [{ isSignal: true, alias: "$isRangeSelection", required: false }] }], $inputElement: [{ type: i0.ViewChild, args: ['input', { isSignal: true }] }] } });
|
|
3068
|
+
}], propDecorators: { $isRangeSelection: [{ type: i0.Input, args: [{ isSignal: true, alias: "$isRangeSelection", required: false }] }], $dividePattern: [{ type: i0.Input, args: [{ isSignal: true, alias: "$dividePattern", required: false }] }], $inputElement: [{ type: i0.ViewChild, args: ['input', { isSignal: true }] }] } });
|
|
3003
3069
|
|
|
3004
3070
|
class UIPhoneNumberDirective extends UiInputDirective {
|
|
3005
3071
|
$selectedCountry = signal(emptyCountry, ...(ngDevMode ? [{ debugName: "$selectedCountry" }] : []));
|