ng-hub-ui-forms 22.31.0 → 22.32.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.
@@ -4,7 +4,7 @@ import * as i1 from '@angular/forms';
4
4
  import { FormControl, FormControlName, FormControlDirective, Validators, NgControl, ControlContainer, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
5
5
  import { Observable, Subject, takeUntil, tap, animationFrameScheduler, asapScheduler, fromEvent } from 'rxjs';
6
6
  import { NgTemplateOutlet, KeyValuePipe, isPlatformBrowser, DOCUMENT, formatDate } from '@angular/common';
7
- import { HubTooltipDirective, resolveHubAccent, OverlayService, HUB_DROPDOWN_POSITIONS } from 'ng-hub-ui-utils';
7
+ import { HubTooltipDirective, resolveHubAccent, OverlayService, HUB_DROPDOWN_POSITIONS, readableOn, toHex, parseColor } from 'ng-hub-ui-utils';
8
8
  import { auditTime, tap as tap$1, debounceTime, filter, map } from 'rxjs/operators';
9
9
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
10
10
  import { DomSanitizer } from '@angular/platform-browser';
@@ -9445,41 +9445,38 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImpor
9445
9445
  }], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], multiple: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiple", required: false }] }], accept: [{ type: i0.Input, args: [{ isSignal: true, alias: "accept", required: false }] }], maxSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxSize", required: false }] }], minSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "minSize", required: false }] }], maxTotalSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxTotalSize", required: false }] }], maxFiles: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxFiles", required: false }] }], dragDrop: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragDrop", required: false }] }], paste: [{ type: i0.Input, args: [{ isSignal: true, alias: "paste", required: false }] }], preview: [{ type: i0.Input, args: [{ isSignal: true, alias: "preview", required: false }] }], allowDuplicates: [{ type: i0.Input, args: [{ isSignal: true, alias: "allowDuplicates", required: false }] }], capture: [{ type: i0.Input, args: [{ isSignal: true, alias: "capture", required: false }] }], autoUpload: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoUpload", required: false }] }], buttonLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "buttonLabel", required: false }] }], dropText: [{ type: i0.Input, args: [{ isSignal: true, alias: "dropText", required: false }] }], dropSubtext: [{ type: i0.Input, args: [{ isSignal: true, alias: "dropSubtext", required: false }] }], hint: [{ type: i0.Input, args: [{ isSignal: true, alias: "hint", required: false }] }], classlist: [{ type: i0.Input, args: [{ isSignal: true, alias: "classlist", required: false }] }], valueChange: [{ type: i0.Output, args: ["valueChange"] }], rejected: [{ type: i0.Output, args: ["rejected"] }], fileRemoved: [{ type: i0.Output, args: ["fileRemoved"] }], uploadStateChange: [{ type: i0.Output, args: ["uploadStateChange"] }], nativeInput: [{ type: i0.ViewChild, args: ['nativeInput', { isSignal: true }] }], iconTpt: [{ type: i0.ContentChild, args: [i0.forwardRef(() => HubFileIconDirective), { isSignal: true }] }], previewTpt: [{ type: i0.ContentChild, args: [i0.forwardRef(() => HubFilePreviewDirective), { isSignal: true }] }], noticeTpt: [{ type: i0.ContentChild, args: [i0.forwardRef(() => HubFileDropzoneNoticeDirective), { isSignal: true }] }] } });
9446
9446
 
9447
9447
  /**
9448
- * Inverts a HEX color, or returns the best contrasting black/white when `bw` is enabled.
9448
+ * Inverts a colour, or returns the best contrasting black/white when `bw` is enabled.
9449
9449
  */
9450
9450
  class HubInvertColorPipe {
9451
9451
  /**
9452
- * @param hex - HEX color (`#rgb` or `#rrggbb`).
9453
- * @param bw - When `true`, returns `#000000` or `#FFFFFF` for maximum contrast.
9454
- * @returns The inverted (or contrasting) HEX color.
9455
- */
9456
- transform(hex, bw = false) {
9457
- if (!hex) {
9452
+ * @param color - Any CSS colour: hex (3/4/6/8 digits, `#` optional), `rgb()`, `hsl()`,
9453
+ * `oklch()`, `oklab()` or a named colour.
9454
+ * @param bw - When `true`, returns the black or white that reads best on `color`.
9455
+ * @param metric - How `bw` decides. `'lightness'` (default) matches the
9456
+ * `--hub-sys-color-*-on` design-system token; `'apca'` and `'wcag'` score the two
9457
+ * candidates instead.
9458
+ * @returns The inverted (or contrasting) colour as a hex string, or `#000000` when the
9459
+ * input is empty or is not a colour this can resolve.
9460
+ */
9461
+ transform(color, bw = false, metric = 'lightness') {
9462
+ const rgb = this.resolve(color);
9463
+ if (!rgb) {
9458
9464
  return '#000000';
9459
9465
  }
9460
- if (hex.indexOf('#') === 0) {
9461
- hex = hex.slice(1);
9462
- }
9463
- // Convert 3-digit hex to 6-digits.
9464
- if (hex.length === 3) {
9465
- hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
9466
+ if (bw) {
9467
+ return readableOn(rgb, metric);
9466
9468
  }
9467
- if (hex.length !== 6) {
9468
- throw new Error('Invalid HEX color.');
9469
+ return toHex({ r: 255 - rgb.r, g: 255 - rgb.g, b: 255 - rgb.b, a: rgb.a });
9470
+ }
9471
+ /**
9472
+ * Resolves the input, retrying with a `#` prefix so bare hex digits keep working — the
9473
+ * pipe has accepted `'336699'` since it shipped and consumers rely on it.
9474
+ */
9475
+ resolve(color) {
9476
+ if (!color) {
9477
+ return null;
9469
9478
  }
9470
- let r = parseInt(hex.slice(0, 2), 16);
9471
- let g = parseInt(hex.slice(2, 4), 16);
9472
- let b = parseInt(hex.slice(4, 6), 16);
9473
- if (bw) {
9474
- // http://stackoverflow.com/a/3943023/112731
9475
- return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? '#000000' : '#FFFFFF';
9476
- }
9477
- // Invert color components.
9478
- r = (255 - r).toString(16);
9479
- g = (255 - g).toString(16);
9480
- b = (255 - b).toString(16);
9481
- // Pad each with zeros and return.
9482
- return '#' + r.padStart(2, '0') + g.padStart(2, '0') + b.padStart(2, '0');
9479
+ return parseColor(color) ?? parseColor(`#${color}`);
9483
9480
  }
9484
9481
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: HubInvertColorPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
9485
9482
  static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.0.8", ngImport: i0, type: HubInvertColorPipe, isStandalone: true, name: "hubInvertColor" });