@ibragim-dev-org/ui-forge-library 1.2.0 → 1.2.1

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
- function stringToHslColor(string, saturation = 100, lightness = 75) {
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 < string.length; i++) {
448
- hash = string.charCodeAt(i) + ((hash << 5) - hash);
449
- hash = hash & hash;
450
- }
451
- return `hsl(${hash % 360}, ${saturation}%, ${lightness}%)`;
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(this.$acronym(), 100, 85));
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 + '/' + day + '/' + date.getFullYear();
2993
+ return month + pattern + day + pattern + date.getFullYear();
2929
2994
  }
2930
- return day + '/' + month + '/' + date.getFullYear();
2995
+ return day + pattern + month + pattern + date.getFullYear();
2931
2996
  }
2932
2997
  isUsaDateFormat() {
2933
2998
  return DateUtils.isUsaDateFormat();
@@ -2992,14 +3057,14 @@ class UIInputDateDirective extends UiInputDirective {
2992
3057
  return formatSingle(limited);
2993
3058
  }
2994
3059
  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 });
3060
+ 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
3061
  }
2997
3062
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UIInputDateDirective, decorators: [{
2998
3063
  type: Directive,
2999
3064
  args: [{
3000
3065
  selector: 'app-ui-input-date',
3001
3066
  }]
3002
- }], propDecorators: { $isRangeSelection: [{ type: i0.Input, args: [{ isSignal: true, alias: "$isRangeSelection", required: false }] }], $inputElement: [{ type: i0.ViewChild, args: ['input', { isSignal: true }] }] } });
3067
+ }], 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
3068
 
3004
3069
  class UIPhoneNumberDirective extends UiInputDirective {
3005
3070
  $selectedCountry = signal(emptyCountry, ...(ngDevMode ? [{ debugName: "$selectedCountry" }] : []));