@ibragim-dev-org/ui-forge-library 1.1.9 → 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.
@@ -340,17 +340,25 @@ class SkeletonDirective {
340
340
  this.renderer = renderer;
341
341
  effect(() => {
342
342
  if (this.$isLoading()) {
343
+ this.applyHostSkeletonStyles();
343
344
  this.applySkeletonRecursive(this.el.nativeElement, 0);
344
345
  }
345
346
  else {
346
347
  this.removeSkeletonRecursive(this.el.nativeElement);
348
+ this.removeHostSkeletonStyles();
347
349
  }
348
350
  });
349
351
  }
350
352
  ngAfterViewInit() {
353
+ this.injectKeyframes();
354
+ }
355
+ applyHostSkeletonStyles() {
351
356
  this.renderer.setStyle(this.el.nativeElement, 'position', 'relative');
352
357
  this.renderer.setStyle(this.el.nativeElement, 'overflow', 'hidden');
353
- this.injectKeyframes();
358
+ }
359
+ removeHostSkeletonStyles() {
360
+ this.renderer.removeStyle(this.el.nativeElement, 'position');
361
+ this.renderer.removeStyle(this.el.nativeElement, 'overflow');
354
362
  }
355
363
  injectKeyframes() {
356
364
  const styleSheet = document.styleSheets[0];
@@ -434,14 +442,79 @@ function getAspectRatioFit(maxWidth, maxHeight, srcWidth, srcHeight) {
434
442
  return { width: maxWidth, height: maxHeight };
435
443
  }
436
444
 
437
- 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
438
490
  let hash = 0;
439
- for (let i = 0; i < string.length; i++) {
440
- hash = string.charCodeAt(i) + ((hash << 5) - hash);
441
- hash = hash & hash;
442
- }
443
- return `hsl(${hash % 360}, ${saturation}%, ${lightness}%)`;
444
- }
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
+ };
445
518
 
446
519
  class AppIconsLibrary {
447
520
  icons = new Map();
@@ -842,7 +915,6 @@ class UiAvatarDirective {
842
915
  $src = input.required(...(ngDevMode ? [{ debugName: "$src" }] : []));
843
916
  $acronym = input.required(...(ngDevMode ? [{ debugName: "$acronym" }] : []));
844
917
  $backgroundColor = signal('', ...(ngDevMode ? [{ debugName: "$backgroundColor" }] : []));
845
- $textColor = signal('', ...(ngDevMode ? [{ debugName: "$textColor" }] : []));
846
918
  $text = signal('', ...(ngDevMode ? [{ debugName: "$text" }] : []));
847
919
  $canShowAvatar = signal(true, ...(ngDevMode ? [{ debugName: "$canShowAvatar" }] : []));
848
920
  constructor() {
@@ -853,8 +925,7 @@ class UiAvatarDirective {
853
925
  .forEach((v) => {
854
926
  acronym = acronym + v[0];
855
927
  });
856
- this.$backgroundColor.set(stringToHslColor(this.$acronym(), 100, 85));
857
- this.$textColor.set(stringToHslColor(this.$acronym(), 100, 35));
928
+ this.$backgroundColor.set(stringToHslColor(acronym[0]));
858
929
  this.$text.set(acronym);
859
930
  });
860
931
  }
@@ -2908,18 +2979,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
2908
2979
  class UIInputDateDirective extends UiInputDirective {
2909
2980
  $isOpen = signal(false, ...(ngDevMode ? [{ debugName: "$isOpen" }] : []));
2910
2981
  $isRangeSelection = input(false, ...(ngDevMode ? [{ debugName: "$isRangeSelection" }] : []));
2982
+ $dividePattern = input('/', ...(ngDevMode ? [{ debugName: "$dividePattern" }] : []));
2911
2983
  $inputElement = viewChild('input', ...(ngDevMode ? [{ debugName: "$inputElement" }] : []));
2912
2984
  setDate(date) {
2913
2985
  const newDate = this.formatDate(date);
2914
2986
  this.onInput(newDate);
2915
2987
  }
2916
2988
  formatDate(date) {
2989
+ const pattern = this.$dividePattern();
2917
2990
  const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate().toString();
2918
2991
  const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1).toString();
2919
2992
  if (this.isUsaDateFormat()) {
2920
- return month + '/' + day + '/' + date.getFullYear();
2993
+ return month + pattern + day + pattern + date.getFullYear();
2921
2994
  }
2922
- return day + '/' + month + '/' + date.getFullYear();
2995
+ return day + pattern + month + pattern + date.getFullYear();
2923
2996
  }
2924
2997
  isUsaDateFormat() {
2925
2998
  return DateUtils.isUsaDateFormat();
@@ -2984,14 +3057,14 @@ class UIInputDateDirective extends UiInputDirective {
2984
3057
  return formatSingle(limited);
2985
3058
  }
2986
3059
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UIInputDateDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
2987
- 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 });
2988
3061
  }
2989
3062
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UIInputDateDirective, decorators: [{
2990
3063
  type: Directive,
2991
3064
  args: [{
2992
3065
  selector: 'app-ui-input-date',
2993
3066
  }]
2994
- }], 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 }] }] } });
2995
3068
 
2996
3069
  class UIPhoneNumberDirective extends UiInputDirective {
2997
3070
  $selectedCountry = signal(emptyCountry, ...(ngDevMode ? [{ debugName: "$selectedCountry" }] : []));