@skyux/colorpicker 5.5.0 → 5.6.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.
Files changed (25) hide show
  1. package/bundles/skyux-colorpicker.umd.js +391 -392
  2. package/documentation.json +88 -110
  3. package/esm2015/lib/modules/colorpicker/colorpicker-input.directive.js +9 -9
  4. package/esm2015/lib/modules/colorpicker/colorpicker-input.directive.js.map +1 -1
  5. package/esm2015/lib/modules/colorpicker/colorpicker-slider.directive.js +5 -5
  6. package/esm2015/lib/modules/colorpicker/colorpicker-slider.directive.js.map +1 -1
  7. package/esm2015/lib/modules/colorpicker/colorpicker-text.directive.js +3 -3
  8. package/esm2015/lib/modules/colorpicker/colorpicker-text.directive.js.map +1 -1
  9. package/esm2015/lib/modules/colorpicker/colorpicker.component.js +13 -13
  10. package/esm2015/lib/modules/colorpicker/colorpicker.component.js.map +1 -1
  11. package/esm2015/lib/modules/colorpicker/colorpicker.module.js +1 -1
  12. package/esm2015/lib/modules/colorpicker/colorpicker.module.js.map +1 -1
  13. package/esm2015/lib/modules/colorpicker/colorpicker.service.js +22 -24
  14. package/esm2015/lib/modules/colorpicker/colorpicker.service.js.map +1 -1
  15. package/esm2015/lib/modules/colorpicker/types/colorpicker-result.js.map +1 -1
  16. package/esm2015/lib/modules/shared/sky-colorpicker-resources.module.js +2 -2
  17. package/esm2015/lib/modules/shared/sky-colorpicker-resources.module.js.map +1 -1
  18. package/esm2015/testing/colorpicker-fixture.js.map +1 -1
  19. package/fesm2015/skyux-colorpicker-testing.js.map +1 -1
  20. package/fesm2015/skyux-colorpicker.js +86 -88
  21. package/fesm2015/skyux-colorpicker.js.map +1 -1
  22. package/lib/modules/colorpicker/colorpicker-input.directive.d.ts +1 -1
  23. package/lib/modules/colorpicker/colorpicker.component.d.ts +4 -4
  24. package/lib/modules/colorpicker/colorpicker.service.d.ts +1 -2
  25. package/package.json +16 -14
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@skyux/core'), require('@skyux/forms'), require('@skyux/i18n'), require('@skyux/indicators'), require('@skyux/theme'), require('rxjs'), require('rxjs/operators'), require('@angular/forms')) :
3
- typeof define === 'function' && define.amd ? define('@skyux/colorpicker', ['exports', '@angular/common', '@angular/core', '@skyux/core', '@skyux/forms', '@skyux/i18n', '@skyux/indicators', '@skyux/theme', 'rxjs', 'rxjs/operators', '@angular/forms'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.skyux = global.skyux || {}, global.skyux.colorpicker = {}), global.ng.common, global.ng.core, global.i1, global.i5, global.i2, global.i4, global.i3, global.rxjs, global.rxjs.operators, global.ng.forms));
5
- })(this, (function (exports, i6, i0, i1, i5, i2, i4, i3, rxjs, operators, forms) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@skyux/core'), require('@skyux/forms'), require('@skyux/i18n'), require('@skyux/indicators'), require('@skyux/theme'), require('@angular/forms'), require('rxjs'), require('rxjs/operators')) :
3
+ typeof define === 'function' && define.amd ? define('@skyux/colorpicker', ['exports', '@angular/common', '@angular/core', '@skyux/core', '@skyux/forms', '@skyux/i18n', '@skyux/indicators', '@skyux/theme', '@angular/forms', 'rxjs', 'rxjs/operators'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.skyux = global.skyux || {}, global.skyux.colorpicker = {}), global.ng.common, global.ng.core, global.i1, global.i5, global.i2, global.i4, global.i3, global.ng.forms, global.rxjs, global.rxjs.operators));
5
+ })(this, (function (exports, i6, i0, i1, i5, i2, i4, i3, forms, rxjs, operators) { 'use strict';
6
6
 
7
7
  function _interopNamespace(e) {
8
8
  if (e && e.__esModule) return e;
@@ -102,29 +102,6 @@
102
102
  }]
103
103
  }] });
104
104
 
105
- /**
106
- * Specifies the commands to provide the colorpicker.
107
- */
108
- exports.SkyColorpickerMessageType = void 0;
109
- (function (SkyColorpickerMessageType) {
110
- /**
111
- * Opens the colorpicker.
112
- */
113
- SkyColorpickerMessageType[SkyColorpickerMessageType["Open"] = 0] = "Open";
114
- /**
115
- * Resets the selection in the colorpicker.
116
- */
117
- SkyColorpickerMessageType[SkyColorpickerMessageType["Reset"] = 1] = "Reset";
118
- /**
119
- * Toggles whether to display a reset button beside the colorpicker.
120
- */
121
- SkyColorpickerMessageType[SkyColorpickerMessageType["ToggleResetButton"] = 2] = "ToggleResetButton";
122
- /**
123
- * Closes the colorpicker.
124
- */
125
- SkyColorpickerMessageType[SkyColorpickerMessageType["Close"] = 3] = "Close";
126
- })(exports.SkyColorpickerMessageType || (exports.SkyColorpickerMessageType = {}));
127
-
128
105
  // spell-checker:ignore hsva, hsla, cmyk, denormalize, colorpicker,Injectable
129
106
  /**
130
107
  * @internal
@@ -344,7 +321,7 @@
344
321
  var hsva = undefined;
345
322
  for (var key in stringParsers) {
346
323
  /* istanbul ignore else */ /* for in must be filtered by an if */
347
- if (stringParsers.hasOwnProperty(key)) {
324
+ if (Object.prototype.hasOwnProperty.call(stringParsers, key)) {
348
325
  var parser = stringParsers[key];
349
326
  var match = parser.re.exec(colorString);
350
327
  var color = match && parser.parse(match);
@@ -386,7 +363,6 @@
386
363
  return color[outputFormat]();
387
364
  };
388
365
  SkyColorpickerService.prototype.skyColorpickerOut = function (color) {
389
- var formatColor;
390
366
  var cmykText = this.outputFormat(color, 'cmyk', true);
391
367
  var hslaText = this.outputFormat(color, 'hsla', true);
392
368
  var rgbaText = this.outputFormat(color, 'rgba', true);
@@ -394,7 +370,7 @@
394
370
  var hsla = this.hsva2hsla(color);
395
371
  var cmyk = this.rgbaToCmyk(rgba);
396
372
  var hex = this.outputFormat(color, 'hex', false);
397
- formatColor = {
373
+ var formatColor = {
398
374
  cmykText: cmykText,
399
375
  hslaText: hslaText,
400
376
  rgbaText: rgbaText,
@@ -469,121 +445,357 @@
469
445
  SkyColorpickerService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyColorpickerService });
470
446
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyColorpickerService, decorators: [{
471
447
  type: i0.Injectable
472
- }], ctorParameters: function () { return []; } });
448
+ }] });
473
449
 
474
- // spell-checker:ignore colorpicker
475
- /**
476
- * @internal
477
- */
478
- var SliderPosition = /** @class */ (function () {
479
- function SliderPosition(hue, saturation, value, alpha) {
480
- this.hue = hue;
481
- this.saturation = saturation;
482
- this.value = value;
483
- this.alpha = alpha;
484
- }
485
- return SliderPosition;
486
- }());
450
+ // tslint:disable:no-forward-ref no-use-before-declare
451
+ var SKY_COLORPICKER_VALUE_ACCESSOR = {
452
+ provide: forms.NG_VALUE_ACCESSOR,
453
+ useExisting: i0.forwardRef(function () { return SkyColorpickerInputDirective; }),
454
+ multi: true,
455
+ };
456
+ var SKY_COLORPICKER_VALIDATOR = {
457
+ provide: forms.NG_VALIDATORS,
458
+ useExisting: i0.forwardRef(function () { return SkyColorpickerInputDirective; }),
459
+ multi: true,
460
+ };
461
+ // tslint:enable
462
+ var SKY_COLORPICKER_DEFAULT_COLOR = '#FFFFFF';
487
463
  /**
488
- * @internal
464
+ * Creates the colorpicker element and dropdown.
489
465
  */
490
- var SliderDimension = /** @class */ (function () {
491
- function SliderDimension(hue, saturation, value, alpha) {
492
- this.hue = hue;
493
- this.saturation = saturation;
494
- this.value = value;
495
- this.alpha = alpha;
466
+ var SkyColorpickerInputDirective = /** @class */ (function () {
467
+ function SkyColorpickerInputDirective(elementRef, renderer, service, resourcesService, injector) {
468
+ this.elementRef = elementRef;
469
+ this.renderer = renderer;
470
+ this.service = service;
471
+ this.resourcesService = resourcesService;
472
+ this.injector = injector;
473
+ /**
474
+ * This property is deprecated and does not affect the colorpicker.
475
+ * We recommend against using it.
476
+ * @deprecated
477
+ * @default "rgba"
478
+ */
479
+ this.returnFormat = 'rgba';
480
+ /**
481
+ * Specifies the format to use for the color when the colorpicker uses a native input
482
+ * element such as a standard text input or a button. This property accepts `rgba`, `hex`,
483
+ * or `hsla`, but we do not recommend using it because users never see or use its value.
484
+ * Instead, if you need to access this format value, see the demo for an example.
485
+ *@default "rgba"
486
+ */
487
+ this.outputFormat = 'rgba';
488
+ /**
489
+ * Specifies an array of colors to load as preset choices. The colorpicker displays the
490
+ * colors in a series of 12 boxes for users to select.
491
+ */
492
+ this.presetColors = ['#333', '#888', '#EFEFEF', '#FFF'];
493
+ /**
494
+ * Specifies the type of transparency to use in the transparency slider.
495
+ *@default "hex6"
496
+ */
497
+ this.alphaChannel = 'hex6';
498
+ /**
499
+ * Indicates whether to display a transparency slider for users to select transparency
500
+ * levels.
501
+ */
502
+ this.allowTransparency = true;
503
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
504
+ this._onChange = function (_) { };
505
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
506
+ this._onTouched = function () { };
507
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
508
+ this._validatorChange = function () { };
496
509
  }
497
- return SliderDimension;
498
- }());
499
-
500
- // spell-checker:ignore Colorpicker
501
- /**
502
- * @internal
503
- */
504
- var SkyColorpickerSliderDirective = /** @class */ (function () {
505
- function SkyColorpickerSliderDirective(el) {
510
+ Object.defineProperty(SkyColorpickerInputDirective.prototype, "initialColor", {
511
+ get: function () {
512
+ return this._initialColor || SKY_COLORPICKER_DEFAULT_COLOR;
513
+ },
514
+ /**
515
+ * Specifies an initial color to load in the colorpicker. Use a reactive or
516
+ * template-driven form to set this value. This property is deprecated. As an alternative,
517
+ * we recommend the `formControlName` property on reactive forms or `ngModel` on
518
+ * template-driven forms. See the demo for examples.
519
+ * @deprecated
520
+ */
521
+ set: function (value) {
522
+ /* istanbul ignore else */
523
+ if (!this._initialColor && !this.modelValue) {
524
+ this.writeValue(value);
525
+ }
526
+ this._initialColor = value;
527
+ },
528
+ enumerable: false,
529
+ configurable: true
530
+ });
531
+ SkyColorpickerInputDirective.prototype.changeInput = function (event) {
532
+ var value = event.target.value;
533
+ this.skyColorpickerInput.updatePickerValues(value);
534
+ this.skyColorpickerInput.backgroundColorForDisplay = value;
535
+ };
536
+ SkyColorpickerInputDirective.prototype.onChange = function (event) {
537
+ var newValue = event.target.value;
538
+ this.modelValue = this.formatter(newValue);
539
+ this._validatorChange();
540
+ this._onChange(this.modelValue);
541
+ this.writeModelValue(this.modelValue);
542
+ };
543
+ /* istanbul ignore next */
544
+ SkyColorpickerInputDirective.prototype.onBlur = function () {
545
+ /*istanbul ignore next */
546
+ this._onTouched();
547
+ };
548
+ SkyColorpickerInputDirective.prototype.ngOnInit = function () {
506
549
  var _this = this;
507
- this.el = el;
508
- this.newColorContrast = new i0.EventEmitter();
509
- this.listenerMove = function (event) {
510
- _this.move(event);
511
- };
512
- this.listenerStop = function () {
513
- _this.stop();
514
- };
515
- }
516
- SkyColorpickerSliderDirective.prototype.setCursor = function (event) {
517
- var height = this.el.nativeElement.offsetHeight;
518
- var width = this.el.nativeElement.offsetWidth;
519
- var xAxis = Math.max(0, Math.min(this.getX(event), width));
520
- var yAxis = Math.max(0, Math.min(this.getY(event), height));
521
- if (this.xAxis !== undefined && this.yAxis !== undefined) {
522
- this.newColorContrast.emit({
523
- xCoordinate: xAxis / width,
524
- yCoordinate: 1 - yAxis / height,
525
- xAxis: this.xAxis,
526
- yAxis: this.yAxis,
550
+ var element = this.elementRef.nativeElement;
551
+ this.renderer.addClass(element, 'sky-form-control');
552
+ this.skyColorpickerInput.initialColor = this.initialColor;
553
+ this.skyColorpickerInput.returnFormat = this.returnFormat;
554
+ this.pickerChangedSubscription =
555
+ this.skyColorpickerInput.selectedColorChanged.subscribe(function (newColor) {
556
+ /* istanbul ignore else */
557
+ if (newColor) {
558
+ _this.modelValue = _this.formatter(newColor);
559
+ _this.writeModelValue(_this.modelValue);
560
+ }
561
+ _this._onChange(newColor);
527
562
  });
563
+ this.skyColorpickerInput.updatePickerValues(this.initialColor);
564
+ /* Sanity check */
565
+ /* istanbul ignore else */
566
+ if (!this._disabled) {
567
+ this.skyColorpickerInput.backgroundColorForDisplay = this.initialColor;
568
+ }
569
+ /// Set aria-label as default, if not set
570
+ if (!element.getAttribute('aria-label')) {
571
+ this.renderer.setAttribute(element, 'aria-label', this.getString('skyux_colorpicker_input_default_label'));
572
+ }
573
+ var typeAttr = element.getAttribute('type');
574
+ if (typeAttr && typeAttr === 'hidden') {
575
+ this.skyColorpickerInput.isVisible = false;
528
576
  }
529
577
  else {
530
- this.newColorContrast.emit({
531
- xCoordinate: xAxis / width,
532
- maxRange: this.xAxis,
533
- });
578
+ this.skyColorpickerInput.isVisible = true;
534
579
  }
535
- /* // No vertical bars
536
- if (this.xAxis === undefined && this.yAxis !== undefined) {
537
- this.newColorContrast.emit({ yCoordinate: yAxis / height, maxRange: this.yAxis });
538
- } */
580
+ element.setAttribute('readonly', 'true');
581
+ this.renderer.addClass(element, 'sky-colorpicker-input');
539
582
  };
540
- SkyColorpickerSliderDirective.prototype.move = function (event) {
541
- event.preventDefault();
542
- this.setCursor(event);
583
+ SkyColorpickerInputDirective.prototype.ngOnDestroy = function () {
584
+ this.pickerChangedSubscription.unsubscribe();
543
585
  };
544
- SkyColorpickerSliderDirective.prototype.start = function (event) {
545
- this.setCursor(event);
546
- document.addEventListener('mousemove', this.listenerMove);
547
- document.addEventListener('touchmove', this.listenerMove);
548
- document.addEventListener('mouseup', this.listenerStop);
549
- document.addEventListener('touchend', this.listenerStop);
586
+ SkyColorpickerInputDirective.prototype.setColorPickerDefaults = function () {
587
+ this.skyColorpickerInput.setDialog(this, this.elementRef, this.initialColor, this.outputFormat, this.presetColors, this.alphaChannel, this.allowTransparency);
550
588
  };
551
- SkyColorpickerSliderDirective.prototype.stop = function () {
552
- document.removeEventListener('mousemove', this.listenerMove);
553
- document.removeEventListener('touchmove', this.listenerMove);
554
- document.removeEventListener('mouseup', this.listenerStop);
555
- document.removeEventListener('touchend', this.listenerStop);
589
+ SkyColorpickerInputDirective.prototype.ngOnChanges = function () {
590
+ this._validatorChange();
591
+ this.skyColorpickerInput.returnFormat = this.returnFormat;
592
+ this.setColorPickerDefaults();
556
593
  };
557
- SkyColorpickerSliderDirective.prototype.getX = function (event) {
558
- /* Ignoring event.touches as tests are not run on a touch device. */
559
- /* istanbul ignore next */
560
- return ((event.pageX !== undefined ? event.pageX : event.touches[0].pageX) -
561
- this.el.nativeElement.getBoundingClientRect().left -
562
- window.pageXOffset);
594
+ SkyColorpickerInputDirective.prototype.registerOnChange = function (fn) {
595
+ this._onChange = fn;
563
596
  };
564
- SkyColorpickerSliderDirective.prototype.getY = function (event) {
565
- /* Ignoring event.touches as tests are not run on a touch device. */
566
- /* istanbul ignore next */
567
- return ((event.pageY !== undefined ? event.pageY : event.touches[0].pageY) -
568
- this.el.nativeElement.getBoundingClientRect().top -
569
- window.pageYOffset);
597
+ SkyColorpickerInputDirective.prototype.registerOnTouched = function (fn) {
598
+ this._onTouched = fn;
570
599
  };
571
- return SkyColorpickerSliderDirective;
572
- }());
573
- SkyColorpickerSliderDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyColorpickerSliderDirective, deps: [{ token: i0__namespace.ElementRef }], target: i0__namespace.ɵɵFactoryTarget.Directive });
574
- SkyColorpickerSliderDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyColorpickerSliderDirective, selector: "[skyColorpickerSlider]", inputs: { skyColorpickerSlider: "skyColorpickerSlider", color: "color", xAxis: "xAxis", yAxis: "yAxis" }, outputs: { newColorContrast: "newColorContrast" }, host: { listeners: { "touchstart": "start($event)", "mousedown": "start($event)" } }, ngImport: i0__namespace });
575
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyColorpickerSliderDirective, decorators: [{
576
- type: i0.Directive,
577
- args: [{
578
- selector: '[skyColorpickerSlider]',
579
- }]
580
- }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }]; }, propDecorators: { newColorContrast: [{
581
- type: i0.Output
582
- }], skyColorpickerSlider: [{
583
- type: i0.Input
584
- }], color: [{
585
- type: i0.Input
586
- }], xAxis: [{
600
+ SkyColorpickerInputDirective.prototype.registerOnValidatorChange = function (fn) {
601
+ this._validatorChange = fn;
602
+ };
603
+ SkyColorpickerInputDirective.prototype.writeValue = function (value) {
604
+ if (this.skyColorpickerInput &&
605
+ value &&
606
+ value !== this.skyColorpickerInput.lastAppliedColor) {
607
+ this.modelValue = this.formatter(value);
608
+ this.writeModelValue(this.modelValue);
609
+ if (!this._initialColor) {
610
+ this._initialColor = value;
611
+ this.skyColorpickerInput.initialColor = value;
612
+ }
613
+ this.skyColorpickerInput.lastAppliedColor = value;
614
+ var control = this.injector.get(forms.NgControl)
615
+ .control;
616
+ if (control) {
617
+ control.setValue(this.modelValue, { emitEvent: false });
618
+ }
619
+ }
620
+ };
621
+ SkyColorpickerInputDirective.prototype.validate = function (control) {
622
+ var value = control.value;
623
+ if (!value) {
624
+ return;
625
+ }
626
+ // Validation
627
+ };
628
+ /**
629
+ * Implemented as part of ControlValueAccessor.
630
+ */
631
+ SkyColorpickerInputDirective.prototype.setDisabledState = function (isDisabled) {
632
+ this._disabled = isDisabled;
633
+ this.skyColorpickerInput.disabled = isDisabled;
634
+ if (this._disabled) {
635
+ this.skyColorpickerInput.backgroundColorForDisplay = '#fff';
636
+ }
637
+ else {
638
+ this.skyColorpickerInput.backgroundColorForDisplay = this.modelValue.hex;
639
+ }
640
+ };
641
+ SkyColorpickerInputDirective.prototype.writeModelValue = function (model) {
642
+ var setElementValue = model.rgbaText;
643
+ var element = this.elementRef.nativeElement;
644
+ var output;
645
+ // tslint:disable-next-line:switch-default
646
+ switch (this.outputFormat) {
647
+ case 'rgba':
648
+ output = model.rgbaText;
649
+ break;
650
+ case 'hsla':
651
+ output = model.hslaText;
652
+ break;
653
+ case 'cmyk':
654
+ output = model.cmykText;
655
+ break;
656
+ case 'hex':
657
+ output = model.hex;
658
+ break;
659
+ }
660
+ this.skyColorpickerInput.updatePickerValues(output);
661
+ this.skyColorpickerInput.backgroundColorForDisplay = output;
662
+ this.renderer.setStyle(element, 'background-color', setElementValue);
663
+ this.renderer.setProperty(element, 'value', output);
664
+ };
665
+ SkyColorpickerInputDirective.prototype.formatter = function (color) {
666
+ if (color && typeof color !== 'string') {
667
+ return color;
668
+ }
669
+ var hsva = this.service.stringToHsva(color, this.alphaChannel === 'hex8');
670
+ var formatColor = this.service.skyColorpickerOut(hsva);
671
+ return formatColor;
672
+ };
673
+ SkyColorpickerInputDirective.prototype.getString = function (key) {
674
+ // TODO: Need to implement the async `getString` method in a breaking change.
675
+ return this.resourcesService.getStringForLocale({ locale: 'en-US' }, key);
676
+ };
677
+ return SkyColorpickerInputDirective;
678
+ }());
679
+ SkyColorpickerInputDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyColorpickerInputDirective, deps: [{ token: i0__namespace.ElementRef }, { token: i0__namespace.Renderer2 }, { token: SkyColorpickerService }, { token: i2__namespace.SkyLibResourcesService }, { token: i0__namespace.Injector }], target: i0__namespace.ɵɵFactoryTarget.Directive });
680
+ SkyColorpickerInputDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyColorpickerInputDirective, selector: "[skyColorpickerInput]", inputs: { skyColorpickerInput: "skyColorpickerInput", initialColor: "initialColor", returnFormat: "returnFormat", outputFormat: "outputFormat", presetColors: "presetColors", alphaChannel: "alphaChannel", allowTransparency: "allowTransparency" }, host: { listeners: { "input": "changeInput($event)", "change": "onChange($event)", "blur": "onBlur()" } }, providers: [SKY_COLORPICKER_VALUE_ACCESSOR, SKY_COLORPICKER_VALIDATOR], usesOnChanges: true, ngImport: i0__namespace });
681
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyColorpickerInputDirective, decorators: [{
682
+ type: i0.Directive,
683
+ args: [{
684
+ selector: '[skyColorpickerInput]',
685
+ providers: [SKY_COLORPICKER_VALUE_ACCESSOR, SKY_COLORPICKER_VALIDATOR],
686
+ }]
687
+ }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }, { type: i0__namespace.Renderer2 }, { type: SkyColorpickerService }, { type: i2__namespace.SkyLibResourcesService }, { type: i0__namespace.Injector }]; }, propDecorators: { skyColorpickerInput: [{
688
+ type: i0.Input
689
+ }], initialColor: [{
690
+ type: i0.Input
691
+ }], returnFormat: [{
692
+ type: i0.Input
693
+ }], outputFormat: [{
694
+ type: i0.Input
695
+ }], presetColors: [{
696
+ type: i0.Input
697
+ }], alphaChannel: [{
698
+ type: i0.Input
699
+ }], allowTransparency: [{
700
+ type: i0.Input
701
+ }], changeInput: [{
702
+ type: i0.HostListener,
703
+ args: ['input', ['$event']]
704
+ }], onChange: [{
705
+ type: i0.HostListener,
706
+ args: ['change', ['$event']]
707
+ }], onBlur: [{
708
+ type: i0.HostListener,
709
+ args: ['blur']
710
+ }] } });
711
+
712
+ // spell-checker:ignore Colorpicker
713
+ /**
714
+ * @internal
715
+ */
716
+ var SkyColorpickerSliderDirective = /** @class */ (function () {
717
+ function SkyColorpickerSliderDirective(el) {
718
+ var _this = this;
719
+ this.el = el;
720
+ this.newColorContrast = new i0.EventEmitter();
721
+ this.listenerMove = function (event) {
722
+ _this.move(event);
723
+ };
724
+ this.listenerStop = function () {
725
+ _this.stop();
726
+ };
727
+ }
728
+ SkyColorpickerSliderDirective.prototype.setCursor = function (event) {
729
+ var height = this.el.nativeElement.offsetHeight;
730
+ var width = this.el.nativeElement.offsetWidth;
731
+ var xAxis = Math.max(0, Math.min(this.getX(event), width));
732
+ var yAxis = Math.max(0, Math.min(this.getY(event), height));
733
+ if (this.xAxis !== undefined && this.yAxis !== undefined) {
734
+ this.newColorContrast.emit({
735
+ xCoordinate: xAxis / width,
736
+ yCoordinate: 1 - yAxis / height,
737
+ xAxis: this.xAxis,
738
+ yAxis: this.yAxis,
739
+ });
740
+ }
741
+ else {
742
+ this.newColorContrast.emit({
743
+ xCoordinate: xAxis / width,
744
+ maxRange: this.xAxis,
745
+ });
746
+ }
747
+ /* // No vertical bars
748
+ if (this.xAxis === undefined && this.yAxis !== undefined) {
749
+ this.newColorContrast.emit({ yCoordinate: yAxis / height, maxRange: this.yAxis });
750
+ } */
751
+ };
752
+ SkyColorpickerSliderDirective.prototype.move = function (event) {
753
+ event.preventDefault();
754
+ this.setCursor(event);
755
+ };
756
+ SkyColorpickerSliderDirective.prototype.start = function (event) {
757
+ this.setCursor(event);
758
+ document.addEventListener('mousemove', this.listenerMove);
759
+ document.addEventListener('touchmove', this.listenerMove);
760
+ document.addEventListener('mouseup', this.listenerStop);
761
+ document.addEventListener('touchend', this.listenerStop);
762
+ };
763
+ SkyColorpickerSliderDirective.prototype.stop = function () {
764
+ document.removeEventListener('mousemove', this.listenerMove);
765
+ document.removeEventListener('touchmove', this.listenerMove);
766
+ document.removeEventListener('mouseup', this.listenerStop);
767
+ document.removeEventListener('touchend', this.listenerStop);
768
+ };
769
+ SkyColorpickerSliderDirective.prototype.getX = function (event) {
770
+ /* Ignoring event.touches as tests are not run on a touch device. */
771
+ /* istanbul ignore next */
772
+ return ((event.pageX !== undefined ? event.pageX : event.touches[0].pageX) -
773
+ this.el.nativeElement.getBoundingClientRect().left -
774
+ window.pageXOffset);
775
+ };
776
+ SkyColorpickerSliderDirective.prototype.getY = function (event) {
777
+ /* Ignoring event.touches as tests are not run on a touch device. */
778
+ /* istanbul ignore next */
779
+ return ((event.pageY !== undefined ? event.pageY : event.touches[0].pageY) -
780
+ this.el.nativeElement.getBoundingClientRect().top -
781
+ window.pageYOffset);
782
+ };
783
+ return SkyColorpickerSliderDirective;
784
+ }());
785
+ SkyColorpickerSliderDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyColorpickerSliderDirective, deps: [{ token: i0__namespace.ElementRef }], target: i0__namespace.ɵɵFactoryTarget.Directive });
786
+ SkyColorpickerSliderDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyColorpickerSliderDirective, selector: "[skyColorpickerSlider]", inputs: { skyColorpickerSlider: "skyColorpickerSlider", color: "color", xAxis: "xAxis", yAxis: "yAxis" }, outputs: { newColorContrast: "newColorContrast" }, host: { listeners: { "touchstart": "start($event)", "mousedown": "start($event)" } }, ngImport: i0__namespace });
787
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyColorpickerSliderDirective, decorators: [{
788
+ type: i0.Directive,
789
+ args: [{
790
+ selector: '[skyColorpickerSlider]',
791
+ }]
792
+ }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }]; }, propDecorators: { newColorContrast: [{
793
+ type: i0.Output
794
+ }], skyColorpickerSlider: [{
795
+ type: i0.Input
796
+ }], color: [{
797
+ type: i0.Input
798
+ }], xAxis: [{
587
799
  type: i0.Input
588
800
  }], yAxis: [{
589
801
  type: i0.Input
@@ -645,6 +857,55 @@
645
857
  args: ['input', ['$event']]
646
858
  }] } });
647
859
 
860
+ // spell-checker:ignore colorpicker
861
+ /**
862
+ * @internal
863
+ */
864
+ var SliderPosition = /** @class */ (function () {
865
+ function SliderPosition(hue, saturation, value, alpha) {
866
+ this.hue = hue;
867
+ this.saturation = saturation;
868
+ this.value = value;
869
+ this.alpha = alpha;
870
+ }
871
+ return SliderPosition;
872
+ }());
873
+ /**
874
+ * @internal
875
+ */
876
+ var SliderDimension = /** @class */ (function () {
877
+ function SliderDimension(hue, saturation, value, alpha) {
878
+ this.hue = hue;
879
+ this.saturation = saturation;
880
+ this.value = value;
881
+ this.alpha = alpha;
882
+ }
883
+ return SliderDimension;
884
+ }());
885
+
886
+ /**
887
+ * Specifies the commands to provide the colorpicker.
888
+ */
889
+ exports.SkyColorpickerMessageType = void 0;
890
+ (function (SkyColorpickerMessageType) {
891
+ /**
892
+ * Opens the colorpicker.
893
+ */
894
+ SkyColorpickerMessageType[SkyColorpickerMessageType["Open"] = 0] = "Open";
895
+ /**
896
+ * Resets the selection in the colorpicker.
897
+ */
898
+ SkyColorpickerMessageType[SkyColorpickerMessageType["Reset"] = 1] = "Reset";
899
+ /**
900
+ * Toggles whether to display a reset button beside the colorpicker.
901
+ */
902
+ SkyColorpickerMessageType[SkyColorpickerMessageType["ToggleResetButton"] = 2] = "ToggleResetButton";
903
+ /**
904
+ * Closes the colorpicker.
905
+ */
906
+ SkyColorpickerMessageType[SkyColorpickerMessageType["Close"] = 3] = "Close";
907
+ })(exports.SkyColorpickerMessageType || (exports.SkyColorpickerMessageType = {}));
908
+
648
909
  var componentIdIndex = 0;
649
910
  /**
650
911
  * Provides a SKY UX-themed replacement for the HTML `input` element with `type="color"`.
@@ -1099,268 +1360,6 @@
1099
1360
  }]
1100
1361
  }] } });
1101
1362
 
1102
- // tslint:disable:no-forward-ref no-use-before-declare
1103
- var SKY_COLORPICKER_VALUE_ACCESSOR = {
1104
- provide: forms.NG_VALUE_ACCESSOR,
1105
- useExisting: i0.forwardRef(function () { return SkyColorpickerInputDirective; }),
1106
- multi: true,
1107
- };
1108
- var SKY_COLORPICKER_VALIDATOR = {
1109
- provide: forms.NG_VALIDATORS,
1110
- useExisting: i0.forwardRef(function () { return SkyColorpickerInputDirective; }),
1111
- multi: true,
1112
- };
1113
- // tslint:enable
1114
- var SKY_COLORPICKER_DEFAULT_COLOR = '#FFFFFF';
1115
- /**
1116
- * Creates the colorpicker element and dropdown.
1117
- */
1118
- var SkyColorpickerInputDirective = /** @class */ (function () {
1119
- function SkyColorpickerInputDirective(elementRef, renderer, service, resourcesService, injector) {
1120
- this.elementRef = elementRef;
1121
- this.renderer = renderer;
1122
- this.service = service;
1123
- this.resourcesService = resourcesService;
1124
- this.injector = injector;
1125
- /**
1126
- * This property is deprecated and does not affect the colorpicker.
1127
- * We recommend against using it.
1128
- * @deprecated
1129
- * @default "rgba"
1130
- */
1131
- this.returnFormat = 'rgba';
1132
- /**
1133
- * Specifies the format to use for the color when the colorpicker uses a native input
1134
- * element such as a standard text input or a button. This property accepts `rgba`, `hex`,
1135
- * or `hsla`, but we do not recommend using it because users never see or use its value.
1136
- * Instead, if you need to access this format value, see the demo for an example.
1137
- *@default "rgba"
1138
- */
1139
- this.outputFormat = 'rgba';
1140
- /**
1141
- * Specifies an array of colors to load as preset choices. The colorpicker displays the
1142
- * colors in a series of 12 boxes for users to select.
1143
- */
1144
- this.presetColors = ['#333', '#888', '#EFEFEF', '#FFF'];
1145
- /**
1146
- * Specifies the type of transparency to use in the transparency slider.
1147
- *@default "hex6"
1148
- */
1149
- this.alphaChannel = 'hex6';
1150
- /**
1151
- * Indicates whether to display a transparency slider for users to select transparency
1152
- * levels.
1153
- */
1154
- this.allowTransparency = true;
1155
- /*istanbul ignore next */
1156
- this._onChange = function (_) { };
1157
- /*istanbul ignore next */
1158
- this._onTouched = function () { };
1159
- this._validatorChange = function () { };
1160
- }
1161
- Object.defineProperty(SkyColorpickerInputDirective.prototype, "initialColor", {
1162
- get: function () {
1163
- return this._initialColor || SKY_COLORPICKER_DEFAULT_COLOR;
1164
- },
1165
- /**
1166
- * Specifies an initial color to load in the colorpicker. Use a reactive or
1167
- * template-driven form to set this value. This property is deprecated. As an alternative,
1168
- * we recommend the `formControlName` property on reactive forms or `ngModel` on
1169
- * template-driven forms. See the demo for examples.
1170
- * @deprecated
1171
- */
1172
- set: function (value) {
1173
- /* istanbul ignore else */
1174
- if (!this._initialColor && !this.modelValue) {
1175
- this.writeValue(value);
1176
- }
1177
- this._initialColor = value;
1178
- },
1179
- enumerable: false,
1180
- configurable: true
1181
- });
1182
- SkyColorpickerInputDirective.prototype.changeInput = function (event) {
1183
- var value = event.target.value;
1184
- this.skyColorpickerInput.updatePickerValues(value);
1185
- this.skyColorpickerInput.backgroundColorForDisplay = value;
1186
- };
1187
- SkyColorpickerInputDirective.prototype.onChange = function (event) {
1188
- var newValue = event.target.value;
1189
- this.modelValue = this.formatter(newValue);
1190
- this._validatorChange();
1191
- this._onChange(this.modelValue);
1192
- this.writeModelValue(this.modelValue);
1193
- };
1194
- /* istanbul ignore next */
1195
- SkyColorpickerInputDirective.prototype.onBlur = function () {
1196
- /*istanbul ignore next */
1197
- this._onTouched();
1198
- };
1199
- SkyColorpickerInputDirective.prototype.ngOnInit = function () {
1200
- var _this = this;
1201
- var element = this.elementRef.nativeElement;
1202
- this.renderer.addClass(element, 'sky-form-control');
1203
- this.skyColorpickerInput.initialColor = this.initialColor;
1204
- this.skyColorpickerInput.returnFormat = this.returnFormat;
1205
- this.pickerChangedSubscription =
1206
- this.skyColorpickerInput.selectedColorChanged.subscribe(function (newColor) {
1207
- /* istanbul ignore else */
1208
- if (newColor) {
1209
- _this.modelValue = _this.formatter(newColor);
1210
- _this.writeModelValue(_this.modelValue);
1211
- }
1212
- _this._onChange(newColor);
1213
- });
1214
- this.skyColorpickerInput.updatePickerValues(this.initialColor);
1215
- /* Sanity check */
1216
- /* istanbul ignore else */
1217
- if (!this._disabled) {
1218
- this.skyColorpickerInput.backgroundColorForDisplay = this.initialColor;
1219
- }
1220
- /// Set aria-label as default, if not set
1221
- if (!element.getAttribute('aria-label')) {
1222
- this.renderer.setAttribute(element, 'aria-label', this.getString('skyux_colorpicker_input_default_label'));
1223
- }
1224
- var typeAttr = element.getAttribute('type');
1225
- if (typeAttr && typeAttr === 'hidden') {
1226
- this.skyColorpickerInput.isVisible = false;
1227
- }
1228
- else {
1229
- this.skyColorpickerInput.isVisible = true;
1230
- }
1231
- element.setAttribute('readonly', 'true');
1232
- this.renderer.addClass(element, 'sky-colorpicker-input');
1233
- };
1234
- SkyColorpickerInputDirective.prototype.ngOnDestroy = function () {
1235
- this.pickerChangedSubscription.unsubscribe();
1236
- };
1237
- SkyColorpickerInputDirective.prototype.setColorPickerDefaults = function () {
1238
- this.skyColorpickerInput.setDialog(this, this.elementRef, this.initialColor, this.outputFormat, this.presetColors, this.alphaChannel, this.allowTransparency);
1239
- };
1240
- SkyColorpickerInputDirective.prototype.ngOnChanges = function () {
1241
- this._validatorChange();
1242
- this.skyColorpickerInput.returnFormat = this.returnFormat;
1243
- this.setColorPickerDefaults();
1244
- };
1245
- SkyColorpickerInputDirective.prototype.registerOnChange = function (fn) {
1246
- this._onChange = fn;
1247
- };
1248
- SkyColorpickerInputDirective.prototype.registerOnTouched = function (fn) {
1249
- this._onTouched = fn;
1250
- };
1251
- SkyColorpickerInputDirective.prototype.registerOnValidatorChange = function (fn) {
1252
- this._validatorChange = fn;
1253
- };
1254
- SkyColorpickerInputDirective.prototype.writeValue = function (value) {
1255
- if (this.skyColorpickerInput &&
1256
- value &&
1257
- value !== this.skyColorpickerInput.lastAppliedColor) {
1258
- this.modelValue = this.formatter(value);
1259
- this.writeModelValue(this.modelValue);
1260
- if (!this._initialColor) {
1261
- this._initialColor = value;
1262
- this.skyColorpickerInput.initialColor = value;
1263
- }
1264
- this.skyColorpickerInput.lastAppliedColor = value;
1265
- var control = this.injector.get(forms.NgControl)
1266
- .control;
1267
- if (control) {
1268
- control.setValue(this.modelValue, { emitEvent: false });
1269
- }
1270
- }
1271
- };
1272
- SkyColorpickerInputDirective.prototype.validate = function (control) {
1273
- var value = control.value;
1274
- if (!value) {
1275
- return;
1276
- }
1277
- // Validation
1278
- };
1279
- /**
1280
- * Implemented as part of ControlValueAccessor.
1281
- */
1282
- SkyColorpickerInputDirective.prototype.setDisabledState = function (isDisabled) {
1283
- this._disabled = isDisabled;
1284
- this.skyColorpickerInput.disabled = isDisabled;
1285
- if (this._disabled) {
1286
- this.skyColorpickerInput.backgroundColorForDisplay = '#fff';
1287
- }
1288
- else {
1289
- this.skyColorpickerInput.backgroundColorForDisplay = this.modelValue.hex;
1290
- }
1291
- };
1292
- SkyColorpickerInputDirective.prototype.writeModelValue = function (model) {
1293
- var setElementValue = model.rgbaText;
1294
- var element = this.elementRef.nativeElement;
1295
- var output;
1296
- // tslint:disable-next-line:switch-default
1297
- switch (this.outputFormat) {
1298
- case 'rgba':
1299
- output = model.rgbaText;
1300
- break;
1301
- case 'hsla':
1302
- output = model.hslaText;
1303
- break;
1304
- case 'cmyk':
1305
- output = model.cmykText;
1306
- break;
1307
- case 'hex':
1308
- output = model.hex;
1309
- break;
1310
- }
1311
- this.skyColorpickerInput.updatePickerValues(output);
1312
- this.skyColorpickerInput.backgroundColorForDisplay = output;
1313
- this.renderer.setStyle(element, 'background-color', setElementValue);
1314
- this.renderer.setProperty(element, 'value', output);
1315
- };
1316
- SkyColorpickerInputDirective.prototype.formatter = function (color) {
1317
- if (color && typeof color !== 'string') {
1318
- return color;
1319
- }
1320
- var formatColor;
1321
- var hsva = this.service.stringToHsva(color, this.alphaChannel === 'hex8');
1322
- formatColor = this.service.skyColorpickerOut(hsva);
1323
- return formatColor;
1324
- };
1325
- SkyColorpickerInputDirective.prototype.getString = function (key) {
1326
- // TODO: Need to implement the async `getString` method in a breaking change.
1327
- return this.resourcesService.getStringForLocale({ locale: 'en-US' }, key);
1328
- };
1329
- return SkyColorpickerInputDirective;
1330
- }());
1331
- SkyColorpickerInputDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyColorpickerInputDirective, deps: [{ token: i0__namespace.ElementRef }, { token: i0__namespace.Renderer2 }, { token: SkyColorpickerService }, { token: i2__namespace.SkyLibResourcesService }, { token: i0__namespace.Injector }], target: i0__namespace.ɵɵFactoryTarget.Directive });
1332
- SkyColorpickerInputDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyColorpickerInputDirective, selector: "[skyColorpickerInput]", inputs: { skyColorpickerInput: "skyColorpickerInput", initialColor: "initialColor", returnFormat: "returnFormat", outputFormat: "outputFormat", presetColors: "presetColors", alphaChannel: "alphaChannel", allowTransparency: "allowTransparency" }, host: { listeners: { "input": "changeInput($event)", "change": "onChange($event)", "blur": "onBlur()" } }, providers: [SKY_COLORPICKER_VALUE_ACCESSOR, SKY_COLORPICKER_VALIDATOR], usesOnChanges: true, ngImport: i0__namespace });
1333
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyColorpickerInputDirective, decorators: [{
1334
- type: i0.Directive,
1335
- args: [{
1336
- selector: '[skyColorpickerInput]',
1337
- providers: [SKY_COLORPICKER_VALUE_ACCESSOR, SKY_COLORPICKER_VALIDATOR],
1338
- }]
1339
- }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }, { type: i0__namespace.Renderer2 }, { type: SkyColorpickerService }, { type: i2__namespace.SkyLibResourcesService }, { type: i0__namespace.Injector }]; }, propDecorators: { skyColorpickerInput: [{
1340
- type: i0.Input
1341
- }], initialColor: [{
1342
- type: i0.Input
1343
- }], returnFormat: [{
1344
- type: i0.Input
1345
- }], outputFormat: [{
1346
- type: i0.Input
1347
- }], presetColors: [{
1348
- type: i0.Input
1349
- }], alphaChannel: [{
1350
- type: i0.Input
1351
- }], allowTransparency: [{
1352
- type: i0.Input
1353
- }], changeInput: [{
1354
- type: i0.HostListener,
1355
- args: ['input', ['$event']]
1356
- }], onChange: [{
1357
- type: i0.HostListener,
1358
- args: ['change', ['$event']]
1359
- }], onBlur: [{
1360
- type: i0.HostListener,
1361
- args: ['blur']
1362
- }] } });
1363
-
1364
1363
  var SkyColorpickerModule = /** @class */ (function () {
1365
1364
  function SkyColorpickerModule() {
1366
1365
  }