@ngx-mce/color-picker 21.1.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.
- package/README.md +93 -0
- package/fesm2022/ngx-mce-color-picker.mjs +1251 -0
- package/fesm2022/ngx-mce-color-picker.mjs.map +1 -0
- package/package.json +58 -0
- package/types/ngx-mce-color-picker.d.ts +386 -0
|
@@ -0,0 +1,1251 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { output, input, signal, Input, Directive, Component, ViewEncapsulation, Injectable, InjectionToken, viewChild, ChangeDetectionStrategy, EventEmitter, DOCUMENT, HostBinding, Output, Optional, Inject, forwardRef, effect, untracked, HostListener } from '@angular/core';
|
|
3
|
+
import * as i3 from '@angular/forms';
|
|
4
|
+
import { FormGroup, FormControl, Validators, ReactiveFormsModule, NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';
|
|
5
|
+
import * as i1 from '@angular/material/form-field';
|
|
6
|
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
7
|
+
import * as i2 from '@angular/material/input';
|
|
8
|
+
import { MatInputModule, MAT_INPUT_VALUE_ACCESSOR } from '@angular/material/input';
|
|
9
|
+
import { Subject, merge, Subscription, of } from 'rxjs';
|
|
10
|
+
import { takeUntil, debounceTime, distinctUntilChanged, take, filter } from 'rxjs/operators';
|
|
11
|
+
import { NgClass } from '@angular/common';
|
|
12
|
+
import * as i1$1 from '@angular/material/button';
|
|
13
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
14
|
+
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
|
15
|
+
import { ESCAPE, UP_ARROW, DOWN_ARROW } from '@angular/cdk/keycodes';
|
|
16
|
+
import * as i2$1 from '@angular/cdk/overlay';
|
|
17
|
+
import { Overlay, OverlayConfig } from '@angular/cdk/overlay';
|
|
18
|
+
import { ComponentPortal } from '@angular/cdk/portal';
|
|
19
|
+
import * as i1$2 from '@angular/material/dialog';
|
|
20
|
+
import * as i4 from '@angular/cdk/bidi';
|
|
21
|
+
import * as i2$2 from '@angular/material/icon';
|
|
22
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
23
|
+
|
|
24
|
+
const trimLeft = /^\s+/;
|
|
25
|
+
const trimRight = /\s+$/;
|
|
26
|
+
const tinyCounter = 0;
|
|
27
|
+
const mathRound = Math.round;
|
|
28
|
+
const mathMin = Math.min;
|
|
29
|
+
const mathMax = Math.max;
|
|
30
|
+
const mathRandom = Math.random;
|
|
31
|
+
const NUMERIC_REGEX = /[^0-9]/g;
|
|
32
|
+
const MAX_RGB = 255;
|
|
33
|
+
const MIN_RGB = 0;
|
|
34
|
+
/** List basic colors */
|
|
35
|
+
const BASIC_COLORS = [
|
|
36
|
+
'#ffffff',
|
|
37
|
+
'#ffff00',
|
|
38
|
+
'#ff00ff',
|
|
39
|
+
'#ff0000',
|
|
40
|
+
'#c0c0c0',
|
|
41
|
+
'#808080',
|
|
42
|
+
'#808000',
|
|
43
|
+
'#800080',
|
|
44
|
+
'#800000',
|
|
45
|
+
'#00ffff',
|
|
46
|
+
'#00ff00',
|
|
47
|
+
'#008080',
|
|
48
|
+
'#008000',
|
|
49
|
+
'#0000ff',
|
|
50
|
+
'#000080',
|
|
51
|
+
'#000000',
|
|
52
|
+
];
|
|
53
|
+
/**
|
|
54
|
+
* Get color at position
|
|
55
|
+
* @param ctx
|
|
56
|
+
* @param x
|
|
57
|
+
* @param y
|
|
58
|
+
*/
|
|
59
|
+
function getColorAtPosition(ctx, x, y) {
|
|
60
|
+
const imageData = ctx.getImageData(x, y, 1, 1).data;
|
|
61
|
+
return { r: imageData[0], g: imageData[1], b: imageData[2] };
|
|
62
|
+
}
|
|
63
|
+
// `rgbaToHex`
|
|
64
|
+
// Converts an RGBA color plus alpha transparency to hex
|
|
65
|
+
// Assumes r, g, b are contained in the set [0, 255] and
|
|
66
|
+
// a in [0, 1]. Returns a 4 or 8 character rgba hex
|
|
67
|
+
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
68
|
+
var hex = [
|
|
69
|
+
pad2(mathRound(r).toString(16)),
|
|
70
|
+
pad2(mathRound(g).toString(16)),
|
|
71
|
+
pad2(mathRound(b).toString(16)),
|
|
72
|
+
pad2(convertDecimalToHex(a)),
|
|
73
|
+
];
|
|
74
|
+
// Return a 4 character hex if possible
|
|
75
|
+
if (allow4Char &&
|
|
76
|
+
hex[0].charAt(0) == hex[0].charAt(1) &&
|
|
77
|
+
hex[1].charAt(0) == hex[1].charAt(1) &&
|
|
78
|
+
hex[2].charAt(0) == hex[2].charAt(1) &&
|
|
79
|
+
hex[3].charAt(0) == hex[3].charAt(1)) {
|
|
80
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
|
|
81
|
+
}
|
|
82
|
+
return hex.join('');
|
|
83
|
+
}
|
|
84
|
+
// Force a hex value to have 2 characters
|
|
85
|
+
function pad2(c) {
|
|
86
|
+
return c.length == 1 ? '0' + c : '' + c;
|
|
87
|
+
}
|
|
88
|
+
// Converts a decimal to a hex value
|
|
89
|
+
function convertDecimalToHex(d) {
|
|
90
|
+
return Math.round(parseFloat(d) * 255).toString(16);
|
|
91
|
+
}
|
|
92
|
+
// Converts a hex value to a decimal
|
|
93
|
+
function convertHexToDecimal(h) {
|
|
94
|
+
return parseIntFromHex(h) / 255;
|
|
95
|
+
}
|
|
96
|
+
// Parse a base-16 hex value into a base-10 integer
|
|
97
|
+
function parseIntFromHex(val) {
|
|
98
|
+
return parseInt(val, 16);
|
|
99
|
+
}
|
|
100
|
+
// `rgbToHex`
|
|
101
|
+
// Converts an RGB color to hex
|
|
102
|
+
// Assumes r, g, and b are contained in the set [0, 255]
|
|
103
|
+
// Returns a 3 or 6 character hex
|
|
104
|
+
function rgbToHex(r, g, b, allow3Char) {
|
|
105
|
+
var hex = [
|
|
106
|
+
pad2(mathRound(r).toString(16)),
|
|
107
|
+
pad2(mathRound(g).toString(16)),
|
|
108
|
+
pad2(mathRound(b).toString(16)),
|
|
109
|
+
];
|
|
110
|
+
// Return a 3 character hex if possible
|
|
111
|
+
if (allow3Char &&
|
|
112
|
+
hex[0].charAt(0) == hex[0].charAt(1) &&
|
|
113
|
+
hex[1].charAt(0) == hex[1].charAt(1) &&
|
|
114
|
+
hex[2].charAt(0) == hex[2].charAt(1)) {
|
|
115
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
116
|
+
}
|
|
117
|
+
return hex.join('');
|
|
118
|
+
}
|
|
119
|
+
// Actual matching.
|
|
120
|
+
// Parentheses and commas are optional, but not required.
|
|
121
|
+
// Whitespace can take the place of commas or opening parent
|
|
122
|
+
const CSS_INTEGER = '[-\\+]?\\d+%?';
|
|
123
|
+
const CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';
|
|
124
|
+
const CSS_UNIT = '(?:' + CSS_NUMBER + ')|(?:' + CSS_INTEGER + ')';
|
|
125
|
+
const PERMISSIVE_MATCH3 = '[\\s|\\(]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')\\s*\\)?';
|
|
126
|
+
const PERMISSIVE_MATCH4 = '[\\s|\\(]+(' +
|
|
127
|
+
CSS_UNIT +
|
|
128
|
+
')[,|\\s]+(' +
|
|
129
|
+
CSS_UNIT +
|
|
130
|
+
')[,|\\s]+(' +
|
|
131
|
+
CSS_UNIT +
|
|
132
|
+
')[,|\\s]+(' +
|
|
133
|
+
CSS_UNIT +
|
|
134
|
+
')\\s*\\)?';
|
|
135
|
+
const matchers = {
|
|
136
|
+
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
137
|
+
rgb: new RegExp('rgb' + PERMISSIVE_MATCH3),
|
|
138
|
+
rgba: new RegExp('rgba' + PERMISSIVE_MATCH4),
|
|
139
|
+
hsl: new RegExp('hsl' + PERMISSIVE_MATCH3),
|
|
140
|
+
hsla: new RegExp('hsla' + PERMISSIVE_MATCH4),
|
|
141
|
+
hsv: new RegExp('hsv' + PERMISSIVE_MATCH3),
|
|
142
|
+
hsva: new RegExp('hsva' + PERMISSIVE_MATCH4),
|
|
143
|
+
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
144
|
+
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
145
|
+
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
146
|
+
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
147
|
+
};
|
|
148
|
+
// `stringInputToObject`
|
|
149
|
+
// Permissive string parsing. Take in a number of formats, and output an object
|
|
150
|
+
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
|
|
151
|
+
function stringInputToObject(color) {
|
|
152
|
+
color = color.replace(trimLeft, '').replace(trimRight, '').toLowerCase();
|
|
153
|
+
// Try to match string input using regular expressions.
|
|
154
|
+
// Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
|
|
155
|
+
// Just return an object and let the conversion functions handle that.
|
|
156
|
+
// This way the result will be the same whether the tinycolor is initialized with string or object.
|
|
157
|
+
let match;
|
|
158
|
+
let obj;
|
|
159
|
+
if ((match = matchers.rgb.exec(color))) {
|
|
160
|
+
return { r: match[1], g: match[2], b: match[3], a: 1 };
|
|
161
|
+
}
|
|
162
|
+
if ((match = matchers.rgba.exec(color))) {
|
|
163
|
+
return { r: match[1], g: match[2], b: match[3], a: match[4] };
|
|
164
|
+
}
|
|
165
|
+
if ((match = matchers.hex8.exec(color))) {
|
|
166
|
+
return {
|
|
167
|
+
r: parseIntFromHex(match[1]),
|
|
168
|
+
g: parseIntFromHex(match[2]),
|
|
169
|
+
b: parseIntFromHex(match[3]),
|
|
170
|
+
a: convertHexToDecimal(match[4]),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if ((match = matchers.hex6.exec(color))) {
|
|
174
|
+
return {
|
|
175
|
+
r: parseIntFromHex(match[1]),
|
|
176
|
+
g: parseIntFromHex(match[2]),
|
|
177
|
+
b: parseIntFromHex(match[3]),
|
|
178
|
+
a: 1,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if ((match = matchers.hex4.exec(color))) {
|
|
182
|
+
return {
|
|
183
|
+
r: parseIntFromHex(match[1] + '' + match[1]),
|
|
184
|
+
g: parseIntFromHex(match[2] + '' + match[2]),
|
|
185
|
+
b: parseIntFromHex(match[3] + '' + match[3]),
|
|
186
|
+
a: convertHexToDecimal(match[4] + '' + match[4]),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if ((match = matchers.hex3.exec(color))) {
|
|
190
|
+
return {
|
|
191
|
+
r: parseIntFromHex(match[1] + '' + match[1]),
|
|
192
|
+
g: parseIntFromHex(match[2] + '' + match[2]),
|
|
193
|
+
b: parseIntFromHex(match[3] + '' + match[3]),
|
|
194
|
+
a: 1,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
function createMissingDateImplError(provider) {
|
|
200
|
+
return Error(`NgxMatColorPicker: No provider found for ${provider}. You must define MAT_COLOR_FORMATS in your module`);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
class Color {
|
|
204
|
+
constructor(_r, _g, _b, _a) {
|
|
205
|
+
this.r = _r > MAX_RGB ? MAX_RGB : _r;
|
|
206
|
+
this.g = _g > MAX_RGB ? MAX_RGB : _g;
|
|
207
|
+
this.b = _b > MAX_RGB ? MAX_RGB : _b;
|
|
208
|
+
if (_a != null) {
|
|
209
|
+
this.a = _a > 1 ? 1 : _a;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
this.a = 1;
|
|
213
|
+
}
|
|
214
|
+
this.roundA = Math.round(this.a);
|
|
215
|
+
this.hex = rgbToHex(this.r, this.g, this.b);
|
|
216
|
+
this.rgba = this.toRgba();
|
|
217
|
+
}
|
|
218
|
+
toHex(allow3Char) {
|
|
219
|
+
return rgbToHex(this.r, this.g, this.b, allow3Char);
|
|
220
|
+
}
|
|
221
|
+
toRgba() {
|
|
222
|
+
return `rgba(${this.r},${this.g},${this.b},${this.a})`;
|
|
223
|
+
}
|
|
224
|
+
toHexString(allow3Char) {
|
|
225
|
+
return '#' + this.toHex(allow3Char);
|
|
226
|
+
}
|
|
227
|
+
toRgbString() {
|
|
228
|
+
return this.a === 1
|
|
229
|
+
? 'rgb(' + Math.round(this.r) + ', ' + Math.round(this.g) + ', ' + Math.round(this.b) + ')'
|
|
230
|
+
: 'rgba(' +
|
|
231
|
+
Math.round(this.r) +
|
|
232
|
+
', ' +
|
|
233
|
+
Math.round(this.g) +
|
|
234
|
+
', ' +
|
|
235
|
+
Math.round(this.b) +
|
|
236
|
+
', ' +
|
|
237
|
+
this.roundA +
|
|
238
|
+
')';
|
|
239
|
+
}
|
|
240
|
+
toHex8(allow4Char) {
|
|
241
|
+
return rgbaToHex(this.r, this.g, this.b, this.a, allow4Char);
|
|
242
|
+
}
|
|
243
|
+
toHex8String(allow4Char) {
|
|
244
|
+
return '#' + this.toHex8(allow4Char);
|
|
245
|
+
}
|
|
246
|
+
toString(format) {
|
|
247
|
+
let formatSet = !!format;
|
|
248
|
+
let formattedString;
|
|
249
|
+
let hasAlpha = this.a < 1 && this.a >= 0;
|
|
250
|
+
let needsAlphaFormat = !formatSet &&
|
|
251
|
+
hasAlpha &&
|
|
252
|
+
(format === 'hex' ||
|
|
253
|
+
format === 'hex6' ||
|
|
254
|
+
format === 'hex3' ||
|
|
255
|
+
format === 'hex4' ||
|
|
256
|
+
format === 'hex8');
|
|
257
|
+
if (needsAlphaFormat) {
|
|
258
|
+
return this.toRgbString();
|
|
259
|
+
}
|
|
260
|
+
if (format === 'rgb') {
|
|
261
|
+
formattedString = this.toRgbString();
|
|
262
|
+
}
|
|
263
|
+
if (format === 'hex' || format === 'hex6') {
|
|
264
|
+
formattedString = this.toHexString();
|
|
265
|
+
}
|
|
266
|
+
if (format === 'hex3') {
|
|
267
|
+
formattedString = this.toHexString(true);
|
|
268
|
+
}
|
|
269
|
+
if (format === 'hex4') {
|
|
270
|
+
formattedString = this.toHex8String(true);
|
|
271
|
+
}
|
|
272
|
+
if (format === 'hex8') {
|
|
273
|
+
formattedString = this.toHex8String();
|
|
274
|
+
}
|
|
275
|
+
return formattedString || this.toHexString();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
class NgxMatBaseColorCanvas {
|
|
280
|
+
set setColor(color) {
|
|
281
|
+
this.color.set(color);
|
|
282
|
+
}
|
|
283
|
+
constructor(zone, elementId) {
|
|
284
|
+
this.zone = zone;
|
|
285
|
+
this.colorChanged = output();
|
|
286
|
+
this.theme = input(...(ngDevMode ? [undefined, { debugName: "theme" }] : []));
|
|
287
|
+
this.color = signal(null, ...(ngDevMode ? [{ debugName: "color" }] : []));
|
|
288
|
+
this.x = 0;
|
|
289
|
+
this.y = 0;
|
|
290
|
+
this.drag = false;
|
|
291
|
+
this._destroyed = new Subject();
|
|
292
|
+
this.elementId = elementId;
|
|
293
|
+
}
|
|
294
|
+
ngOnDestroy() {
|
|
295
|
+
this._destroyed.next();
|
|
296
|
+
this._destroyed.complete();
|
|
297
|
+
}
|
|
298
|
+
ngAfterViewInit() {
|
|
299
|
+
this.canvas = document.getElementById(this.elementId);
|
|
300
|
+
this.ctx = this.canvas.getContext('2d');
|
|
301
|
+
this.width = this.canvas.width;
|
|
302
|
+
this.height = this.canvas.height;
|
|
303
|
+
this.draw();
|
|
304
|
+
}
|
|
305
|
+
draw() {
|
|
306
|
+
this.ctx.clearRect(0, 0, this.width, this.height);
|
|
307
|
+
this.ctx.rect(0, 0, this.width, this.height);
|
|
308
|
+
this.fillGradient();
|
|
309
|
+
if (this.y != 0) {
|
|
310
|
+
this.redrawIndicator(this.x, this.y);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
onMousedown(e) {
|
|
314
|
+
this.drag = true;
|
|
315
|
+
this.changeColor(e);
|
|
316
|
+
this.zone.runOutsideAngular(() => {
|
|
317
|
+
this.canvas.addEventListener('mousemove', this.onMousemove.bind(this));
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
onMousemove(e) {
|
|
321
|
+
if (this.drag) {
|
|
322
|
+
this.zone.run(() => {
|
|
323
|
+
this.changeColor(e);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
onMouseup(e) {
|
|
328
|
+
this.drag = false;
|
|
329
|
+
this.canvas.removeEventListener('mousemove', this.onMousemove);
|
|
330
|
+
}
|
|
331
|
+
emitChange(color) {
|
|
332
|
+
this.colorChanged.emit(color);
|
|
333
|
+
}
|
|
334
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatBaseColorCanvas, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive }); }
|
|
335
|
+
/** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.3", type: NgxMatBaseColorCanvas, isStandalone: true, inputs: { theme: { classPropertyName: "theme", publicName: "theme", isSignal: true, isRequired: false, transformFunction: null }, setColor: { classPropertyName: "setColor", publicName: "color", isSignal: false, isRequired: false, transformFunction: null } }, outputs: { colorChanged: "colorChanged" }, ngImport: i0 }); }
|
|
336
|
+
}
|
|
337
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatBaseColorCanvas, decorators: [{
|
|
338
|
+
type: Directive
|
|
339
|
+
}], ctorParameters: () => [{ type: i0.NgZone }, { type: undefined }], propDecorators: { colorChanged: [{ type: i0.Output, args: ["colorChanged"] }], theme: [{ type: i0.Input, args: [{ isSignal: true, alias: "theme", required: false }] }], setColor: [{
|
|
340
|
+
type: Input,
|
|
341
|
+
args: [{
|
|
342
|
+
alias: 'color',
|
|
343
|
+
}]
|
|
344
|
+
}] } });
|
|
345
|
+
|
|
346
|
+
class NgxMatColorSliderComponent extends NgxMatBaseColorCanvas {
|
|
347
|
+
constructor(zone) {
|
|
348
|
+
super(zone, 'color-strip');
|
|
349
|
+
this.zone = zone;
|
|
350
|
+
}
|
|
351
|
+
ngAfterViewInit() {
|
|
352
|
+
super.ngAfterViewInit();
|
|
353
|
+
}
|
|
354
|
+
fillGradient() {
|
|
355
|
+
const grd = this.ctx.createLinearGradient(0, 0, 0, this.height);
|
|
356
|
+
grd.addColorStop(0, 'rgba(255, 0, 0, 1)');
|
|
357
|
+
grd.addColorStop(0.17, 'rgba(255, 255, 0, 1)');
|
|
358
|
+
grd.addColorStop(0.34, 'rgba(0, 255, 0, 1)');
|
|
359
|
+
grd.addColorStop(0.51, 'rgba(0, 255, 255, 1)');
|
|
360
|
+
grd.addColorStop(0.68, 'rgba(0, 0, 255, 1)');
|
|
361
|
+
grd.addColorStop(0.85, 'rgba(255, 0, 255, 1)');
|
|
362
|
+
grd.addColorStop(1, 'rgba(255, 0, 0, 1)');
|
|
363
|
+
this.ctx.fillStyle = grd;
|
|
364
|
+
this.ctx.fill();
|
|
365
|
+
}
|
|
366
|
+
redrawIndicator(x, y) {
|
|
367
|
+
this.ctx.beginPath();
|
|
368
|
+
this.ctx.strokeStyle = 'white';
|
|
369
|
+
this.ctx.lineWidth = 2;
|
|
370
|
+
this.ctx.arc(7.5, y, 7.5, 0, 2 * Math.PI, false);
|
|
371
|
+
this.ctx.stroke();
|
|
372
|
+
this.ctx.closePath();
|
|
373
|
+
}
|
|
374
|
+
changeColor(e) {
|
|
375
|
+
this.x = e.offsetX;
|
|
376
|
+
this.y = e.offsetY;
|
|
377
|
+
this.draw();
|
|
378
|
+
const { r, g, b } = getColorAtPosition(this.ctx, e.offsetX, e.offsetY);
|
|
379
|
+
this.emitChange(new Color(r, g, b));
|
|
380
|
+
}
|
|
381
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorSliderComponent, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
382
|
+
/** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.1.3", type: NgxMatColorSliderComponent, isStandalone: true, selector: "ngx-mat-color-slider", usesInheritance: true, ngImport: i0, template: "<canvas\r\n id=\"color-strip\"\r\n class=\"zone-strip\"\r\n (mousedown)=\"onMousedown($event)\"\r\n (mouseup)=\"onMouseup($event)\"\r\n width=\"15\"\r\n height=\"234\"\r\n></canvas>\r\n", styles: [""] }); }
|
|
383
|
+
}
|
|
384
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorSliderComponent, decorators: [{
|
|
385
|
+
type: Component,
|
|
386
|
+
args: [{ selector: 'ngx-mat-color-slider', template: "<canvas\r\n id=\"color-strip\"\r\n class=\"zone-strip\"\r\n (mousedown)=\"onMousedown($event)\"\r\n (mouseup)=\"onMouseup($event)\"\r\n width=\"15\"\r\n height=\"234\"\r\n></canvas>\r\n" }]
|
|
387
|
+
}], ctorParameters: () => [{ type: i0.NgZone }] });
|
|
388
|
+
|
|
389
|
+
const RADIUS_NOB = 5;
|
|
390
|
+
class NgxMatColorCanvasComponent extends NgxMatBaseColorCanvas {
|
|
391
|
+
get rCtrl() {
|
|
392
|
+
return this.formGroup.get('r');
|
|
393
|
+
}
|
|
394
|
+
get gCtrl() {
|
|
395
|
+
return this.formGroup.get('g');
|
|
396
|
+
}
|
|
397
|
+
get bCtrl() {
|
|
398
|
+
return this.formGroup.get('b');
|
|
399
|
+
}
|
|
400
|
+
get aCtrl() {
|
|
401
|
+
return this.formGroup.get('a');
|
|
402
|
+
}
|
|
403
|
+
get hexCtrl() {
|
|
404
|
+
return this.formGroup.get('hex');
|
|
405
|
+
}
|
|
406
|
+
constructor(zone) {
|
|
407
|
+
super(zone, 'color-block');
|
|
408
|
+
this.zone = zone;
|
|
409
|
+
this._resetBaseColor = true;
|
|
410
|
+
this.formGroup = new FormGroup({
|
|
411
|
+
r: new FormControl(null, [Validators.required]),
|
|
412
|
+
g: new FormControl(null, [Validators.required]),
|
|
413
|
+
b: new FormControl(null, [Validators.required]),
|
|
414
|
+
a: new FormControl(null, [Validators.required]),
|
|
415
|
+
hex: new FormControl(null, [Validators.required, Validators.pattern(matchers.hex6)]),
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
ngOnInit() {
|
|
419
|
+
const rgbaCtrl$ = merge(this.rCtrl.valueChanges, this.gCtrl.valueChanges, this.bCtrl.valueChanges, this.aCtrl.valueChanges);
|
|
420
|
+
rgbaCtrl$.pipe(takeUntil(this._destroyed), debounceTime(400)).subscribe((_) => {
|
|
421
|
+
const color = new Color(Number(this.rCtrl.value), Number(this.gCtrl.value), Number(this.bCtrl.value), Number(this.aCtrl.value));
|
|
422
|
+
this.emitChange(color);
|
|
423
|
+
});
|
|
424
|
+
const hexCtrl$ = this.hexCtrl.valueChanges;
|
|
425
|
+
hexCtrl$
|
|
426
|
+
.pipe(takeUntil(this._destroyed), debounceTime(400), distinctUntilChanged())
|
|
427
|
+
.subscribe((hex) => {
|
|
428
|
+
const obj = stringInputToObject(hex);
|
|
429
|
+
if (obj != null) {
|
|
430
|
+
const color = new Color(obj.r, obj.g, obj.b, obj.a);
|
|
431
|
+
this.emitChange(color);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
ngOnChanges(changes) {
|
|
436
|
+
if (changes.color && changes.color.currentValue) {
|
|
437
|
+
this.updateForm(changes.color.currentValue);
|
|
438
|
+
if (this._resetBaseColor) {
|
|
439
|
+
this._baseColor = changes.color.currentValue;
|
|
440
|
+
}
|
|
441
|
+
this._resetBaseColor = true;
|
|
442
|
+
if (!changes.color.firstChange) {
|
|
443
|
+
this.draw();
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
updateForm(val) {
|
|
448
|
+
const config = { emitEvent: false };
|
|
449
|
+
this.rCtrl.setValue(val.r, config);
|
|
450
|
+
this.gCtrl.setValue(val.g, config);
|
|
451
|
+
this.bCtrl.setValue(val.b, config);
|
|
452
|
+
this.aCtrl.setValue(val.a, config);
|
|
453
|
+
this.hexCtrl.setValue(val.hex, config);
|
|
454
|
+
}
|
|
455
|
+
redrawIndicator(x, y) {
|
|
456
|
+
this.ctx.beginPath();
|
|
457
|
+
this.ctx.strokeStyle = 'white';
|
|
458
|
+
this.ctx.arc(x, y, RADIUS_NOB, 0, 2 * Math.PI, false);
|
|
459
|
+
this.ctx.stroke();
|
|
460
|
+
this.ctx.closePath();
|
|
461
|
+
}
|
|
462
|
+
fillGradient() {
|
|
463
|
+
this.ctx.fillStyle = this._baseColor ? this._baseColor.rgba : 'rgba(255,255,255,1)';
|
|
464
|
+
this.ctx.fillRect(0, 0, this.width, this.height);
|
|
465
|
+
const grdWhite = this.ctx.createLinearGradient(0, 0, this.width, 0);
|
|
466
|
+
grdWhite.addColorStop(0, 'rgba(255,255,255,1)');
|
|
467
|
+
grdWhite.addColorStop(1, 'rgba(255,255,255,0)');
|
|
468
|
+
this.ctx.fillStyle = grdWhite;
|
|
469
|
+
this.ctx.fillRect(0, 0, this.width, this.height);
|
|
470
|
+
const grdBlack = this.ctx.createLinearGradient(0, 0, 0, this.height);
|
|
471
|
+
grdBlack.addColorStop(0, 'rgba(0,0,0,0)');
|
|
472
|
+
grdBlack.addColorStop(1, 'rgba(0,0,0,1)');
|
|
473
|
+
this.ctx.fillStyle = grdBlack;
|
|
474
|
+
this.ctx.fillRect(0, 0, this.width, this.height);
|
|
475
|
+
}
|
|
476
|
+
onSliderColorChanged(c) {
|
|
477
|
+
this._baseColor = c;
|
|
478
|
+
this.color.set(c);
|
|
479
|
+
this.fillGradient();
|
|
480
|
+
this.emitChange(c);
|
|
481
|
+
}
|
|
482
|
+
changeColor(e) {
|
|
483
|
+
this.x = e.offsetX;
|
|
484
|
+
this.y = e.offsetY;
|
|
485
|
+
this._resetBaseColor = false;
|
|
486
|
+
this.draw();
|
|
487
|
+
const { r, g, b } = getColorAtPosition(this.ctx, e.offsetX, e.offsetY);
|
|
488
|
+
this.emitChange(new Color(r, g, b));
|
|
489
|
+
}
|
|
490
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorCanvasComponent, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
491
|
+
/** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.1.3", type: NgxMatColorCanvasComponent, isStandalone: true, selector: "ngx-mat-color-canvas", host: { classAttribute: "ngx-mat-color-canvas" }, usesInheritance: true, usesOnChanges: true, ngImport: i0, template: "<form [formGroup]=\"formGroup\">\r\n <div class=\"color-canvas-row\">\r\n <div class=\"zone-canvas\">\r\n <canvas\r\n id=\"color-block\"\r\n class=\"zone-block\"\r\n (mousedown)=\"onMousedown($event)\"\r\n (mouseup)=\"onMouseup($event)\"\r\n width=\"200\"\r\n height=\"235\"\r\n ></canvas>\r\n <ngx-mat-color-slider (colorChanged)=\"onSliderColorChanged($event)\" />\r\n </div>\r\n\r\n <div class=\"zone-inputs\">\r\n <mat-form-field [color]=\"theme\">\r\n <mat-label>R</mat-label>\r\n <input\r\n matInput\r\n formControlName=\"r\"\r\n ngxMatNumericColorInput\r\n autocomplete=\"off\"\r\n />\r\n </mat-form-field>\r\n\r\n <mat-form-field [color]=\"theme\">\r\n <mat-label>G</mat-label>\r\n <input\r\n matInput\r\n formControlName=\"g\"\r\n ngxMatNumericColorInput\r\n autocomplete=\"off\"\r\n />\r\n </mat-form-field>\r\n\r\n <mat-form-field [color]=\"theme\">\r\n <mat-label>B</mat-label>\r\n <input\r\n matInput\r\n formControlName=\"b\"\r\n ngxMatNumericColorInput\r\n autocomplete=\"off\"\r\n />\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n\r\n <div class=\"color-canvas-row\">\r\n <button\r\n mat-mini-fab\r\n [style.background-color]=\"color()?.rgba || 'transparent'\"\r\n class=\"preview\"\r\n ></button>\r\n <mat-form-field [color]=\"theme\">\r\n <mat-label>HEX6</mat-label>\r\n <mat-label matPrefix class=\"symbol\"># </mat-label>\r\n <input matInput formControlName=\"hex\" autocomplete=\"off\" />\r\n </mat-form-field>\r\n <mat-form-field class=\"input-opacity\" [color]=\"theme\">\r\n <mat-label>A</mat-label>\r\n <input\r\n matInput\r\n formControlName=\"a\"\r\n type=\"number\"\r\n min=\"0\"\r\n max=\"1\"\r\n step=\"0.1\"\r\n autocomplete=\"off\"\r\n />\r\n </mat-form-field>\r\n </div>\r\n</form>\r\n", styles: [".ngx-mat-color-canvas .color-canvas-row{display:flex}.ngx-mat-color-canvas .color-canvas-row:first-of-type{height:235px;margin-bottom:12px}.ngx-mat-color-canvas .color-canvas-row:first-of-type .card{height:180px}.ngx-mat-color-canvas .color-canvas-row canvas:hover{cursor:crosshair}.ngx-mat-color-canvas .color-canvas-row .zone{display:flex}.ngx-mat-color-canvas .color-canvas-row .zone-canvas{height:235px}.ngx-mat-color-canvas .color-canvas-row .zone-canvas .zone-block{border:1px solid rgba(0,0,0,.12)}.ngx-mat-color-canvas .color-canvas-row .zone-strip{flex-basis:auto;margin-left:10px}.ngx-mat-color-canvas .color-canvas-row .zone-inputs{display:flex;width:60px;height:235px;flex-direction:column;margin-left:16px;margin-top:12px}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2){display:flex}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .preview{min-width:40px;min-height:40px;height:40px;width:40px;margin-top:12px}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .mat-mdc-form-field{margin-left:16px}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .mat-mdc-form-field:first-of-type{width:170px}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .mat-mdc-form-field:first-of-type .symbol{font-weight:700;color:#0000008a}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .mat-mdc-form-field:last-of-type{width:60px}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .mat-mdc-form-field:last-of-type .mat-mdc-text-field-wrapper{padding:0 8px}.ngx-mat-color-canvas .mat-mdc-form-field-label{font-weight:700}.ngx-mat-color-canvas .mat-mdc-form-field .mdc-text-field--filled:not(.mdc-text-field--disabled){background-color:transparent}\n"], dependencies: [{ kind: "ngmodule", type: MatFormFieldModule }, { kind: "component", type: i1.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i1.MatLabel, selector: "mat-label" }, { kind: "directive", type: i1.MatPrefix, selector: "[matPrefix], [matIconPrefix], [matTextPrefix]", inputs: ["matTextPrefix"] }, { kind: "ngmodule", type: MatInputModule }, { kind: "directive", type: i2.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "component", type: NgxMatColorSliderComponent, selector: "ngx-mat-color-slider" }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i3.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.MinValidator, selector: "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", inputs: ["min"] }, { kind: "directive", type: i3.MaxValidator, selector: "input[type=number][max][formControlName],input[type=number][max][formControl],input[type=number][max][ngModel]", inputs: ["max"] }, { kind: "directive", type: i3.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i3.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }], encapsulation: i0.ViewEncapsulation.None }); }
|
|
492
|
+
}
|
|
493
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorCanvasComponent, decorators: [{
|
|
494
|
+
type: Component,
|
|
495
|
+
args: [{ selector: 'ngx-mat-color-canvas', encapsulation: ViewEncapsulation.None, host: {
|
|
496
|
+
class: 'ngx-mat-color-canvas',
|
|
497
|
+
}, imports: [MatFormFieldModule, MatInputModule, NgxMatColorSliderComponent, ReactiveFormsModule], template: "<form [formGroup]=\"formGroup\">\r\n <div class=\"color-canvas-row\">\r\n <div class=\"zone-canvas\">\r\n <canvas\r\n id=\"color-block\"\r\n class=\"zone-block\"\r\n (mousedown)=\"onMousedown($event)\"\r\n (mouseup)=\"onMouseup($event)\"\r\n width=\"200\"\r\n height=\"235\"\r\n ></canvas>\r\n <ngx-mat-color-slider (colorChanged)=\"onSliderColorChanged($event)\" />\r\n </div>\r\n\r\n <div class=\"zone-inputs\">\r\n <mat-form-field [color]=\"theme\">\r\n <mat-label>R</mat-label>\r\n <input\r\n matInput\r\n formControlName=\"r\"\r\n ngxMatNumericColorInput\r\n autocomplete=\"off\"\r\n />\r\n </mat-form-field>\r\n\r\n <mat-form-field [color]=\"theme\">\r\n <mat-label>G</mat-label>\r\n <input\r\n matInput\r\n formControlName=\"g\"\r\n ngxMatNumericColorInput\r\n autocomplete=\"off\"\r\n />\r\n </mat-form-field>\r\n\r\n <mat-form-field [color]=\"theme\">\r\n <mat-label>B</mat-label>\r\n <input\r\n matInput\r\n formControlName=\"b\"\r\n ngxMatNumericColorInput\r\n autocomplete=\"off\"\r\n />\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n\r\n <div class=\"color-canvas-row\">\r\n <button\r\n mat-mini-fab\r\n [style.background-color]=\"color()?.rgba || 'transparent'\"\r\n class=\"preview\"\r\n ></button>\r\n <mat-form-field [color]=\"theme\">\r\n <mat-label>HEX6</mat-label>\r\n <mat-label matPrefix class=\"symbol\"># </mat-label>\r\n <input matInput formControlName=\"hex\" autocomplete=\"off\" />\r\n </mat-form-field>\r\n <mat-form-field class=\"input-opacity\" [color]=\"theme\">\r\n <mat-label>A</mat-label>\r\n <input\r\n matInput\r\n formControlName=\"a\"\r\n type=\"number\"\r\n min=\"0\"\r\n max=\"1\"\r\n step=\"0.1\"\r\n autocomplete=\"off\"\r\n />\r\n </mat-form-field>\r\n </div>\r\n</form>\r\n", styles: [".ngx-mat-color-canvas .color-canvas-row{display:flex}.ngx-mat-color-canvas .color-canvas-row:first-of-type{height:235px;margin-bottom:12px}.ngx-mat-color-canvas .color-canvas-row:first-of-type .card{height:180px}.ngx-mat-color-canvas .color-canvas-row canvas:hover{cursor:crosshair}.ngx-mat-color-canvas .color-canvas-row .zone{display:flex}.ngx-mat-color-canvas .color-canvas-row .zone-canvas{height:235px}.ngx-mat-color-canvas .color-canvas-row .zone-canvas .zone-block{border:1px solid rgba(0,0,0,.12)}.ngx-mat-color-canvas .color-canvas-row .zone-strip{flex-basis:auto;margin-left:10px}.ngx-mat-color-canvas .color-canvas-row .zone-inputs{display:flex;width:60px;height:235px;flex-direction:column;margin-left:16px;margin-top:12px}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2){display:flex}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .preview{min-width:40px;min-height:40px;height:40px;width:40px;margin-top:12px}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .mat-mdc-form-field{margin-left:16px}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .mat-mdc-form-field:first-of-type{width:170px}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .mat-mdc-form-field:first-of-type .symbol{font-weight:700;color:#0000008a}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .mat-mdc-form-field:last-of-type{width:60px}.ngx-mat-color-canvas .color-canvas-row:nth-of-type(2) .mat-mdc-form-field:last-of-type .mat-mdc-text-field-wrapper{padding:0 8px}.ngx-mat-color-canvas .mat-mdc-form-field-label{font-weight:700}.ngx-mat-color-canvas .mat-mdc-form-field .mdc-text-field--filled:not(.mdc-text-field--disabled){background-color:transparent}\n"] }]
|
|
498
|
+
}], ctorParameters: () => [{ type: i0.NgZone }] });
|
|
499
|
+
|
|
500
|
+
class NgxMatColorCollectionComponent {
|
|
501
|
+
constructor() {
|
|
502
|
+
this.colorChanged = output();
|
|
503
|
+
this.selectedColor = signal('', ...(ngDevMode ? [{ debugName: "selectedColor" }] : []));
|
|
504
|
+
this.colors1 = BASIC_COLORS.slice(0, 8);
|
|
505
|
+
this.colors2 = BASIC_COLORS.slice(8, 16);
|
|
506
|
+
}
|
|
507
|
+
set color(c) {
|
|
508
|
+
if (c) {
|
|
509
|
+
this.selectedColor.set(c.toHexString());
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
select(hex) {
|
|
513
|
+
this.selectedColor.set(hex);
|
|
514
|
+
const { r, g, b, a } = stringInputToObject(hex);
|
|
515
|
+
this.colorChanged.emit(new Color(r, g, b, a));
|
|
516
|
+
}
|
|
517
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorCollectionComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
518
|
+
/** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: NgxMatColorCollectionComponent, isStandalone: true, selector: "ngx-mat-color-collection", inputs: { color: "color" }, outputs: { colorChanged: "colorChanged" }, host: { classAttribute: "ngx-mat-color-collection" }, ngImport: i0, template: "<div class=\"color-collection-row\">\r\n @for (c of colors1; track c) {\r\n <button\r\n mat-mini-fab\r\n [style.background-color]=\"c\"\r\n class=\"btn-color\"\r\n (click)=\"select(c)\"\r\n [ngClass]=\"{ active: selectedColor() === c }\"\r\n [disableRipple]=\"true\"></button>\r\n }\r\n</div>\r\n<div class=\"color-collection-row\">\r\n @for (c of colors2; track c) {\r\n <button\r\n mat-mini-fab\r\n [style.background-color]=\"c\"\r\n class=\"btn-color\"\r\n (click)=\"select(c)\"\r\n [ngClass]=\"{ active: selectedColor() === c }\"\r\n [disableRipple]=\"true\"></button>\r\n }\r\n</div>\r\n", styles: [".ngx-mat-color-collection .btn-color{height:20px;width:20px;margin-right:11px;box-shadow:none;opacity:.3;will-change:opacity;transition:opacity .3s linear}.ngx-mat-color-collection .btn-color.active{box-shadow:0 3px 5px -1px #0003,0 6px 10px #00000024,0 1px 18px #0000001f;opacity:1}.ngx-mat-color-collection .btn-color .mat-mdc-button-touch-target{display:none!important}\n"], dependencies: [{ kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i1$1.MatMiniFabButton, selector: "button[mat-mini-fab], a[mat-mini-fab], button[matMiniFab], a[matMiniFab]", exportAs: ["matButton", "matAnchor"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], encapsulation: i0.ViewEncapsulation.None }); }
|
|
519
|
+
}
|
|
520
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorCollectionComponent, decorators: [{
|
|
521
|
+
type: Component,
|
|
522
|
+
args: [{ selector: 'ngx-mat-color-collection', encapsulation: ViewEncapsulation.None, host: {
|
|
523
|
+
class: 'ngx-mat-color-collection',
|
|
524
|
+
}, imports: [MatButtonModule, NgClass], template: "<div class=\"color-collection-row\">\r\n @for (c of colors1; track c) {\r\n <button\r\n mat-mini-fab\r\n [style.background-color]=\"c\"\r\n class=\"btn-color\"\r\n (click)=\"select(c)\"\r\n [ngClass]=\"{ active: selectedColor() === c }\"\r\n [disableRipple]=\"true\"></button>\r\n }\r\n</div>\r\n<div class=\"color-collection-row\">\r\n @for (c of colors2; track c) {\r\n <button\r\n mat-mini-fab\r\n [style.background-color]=\"c\"\r\n class=\"btn-color\"\r\n (click)=\"select(c)\"\r\n [ngClass]=\"{ active: selectedColor() === c }\"\r\n [disableRipple]=\"true\"></button>\r\n }\r\n</div>\r\n", styles: [".ngx-mat-color-collection .btn-color{height:20px;width:20px;margin-right:11px;box-shadow:none;opacity:.3;will-change:opacity;transition:opacity .3s linear}.ngx-mat-color-collection .btn-color.active{box-shadow:0 3px 5px -1px #0003,0 6px 10px #00000024,0 1px 18px #0000001f;opacity:1}.ngx-mat-color-collection .btn-color .mat-mdc-button-touch-target{display:none!important}\n"] }]
|
|
525
|
+
}], propDecorators: { colorChanged: [{ type: i0.Output, args: ["colorChanged"] }], color: [{
|
|
526
|
+
type: Input
|
|
527
|
+
}] } });
|
|
528
|
+
|
|
529
|
+
class NgxMatColorPaletteComponent {
|
|
530
|
+
constructor() {
|
|
531
|
+
this.colorChanged = output();
|
|
532
|
+
this.color = input(...(ngDevMode ? [undefined, { debugName: "color" }] : []));
|
|
533
|
+
this.theme = input(...(ngDevMode ? [undefined, { debugName: "theme" }] : []));
|
|
534
|
+
}
|
|
535
|
+
handleColorChanged(color) {
|
|
536
|
+
this.colorChanged.emit(color);
|
|
537
|
+
}
|
|
538
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorPaletteComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
539
|
+
/** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.1.3", type: NgxMatColorPaletteComponent, isStandalone: true, selector: "ngx-mat-color-palette", inputs: { color: { classPropertyName: "color", publicName: "color", isSignal: true, isRequired: false, transformFunction: null }, theme: { classPropertyName: "theme", publicName: "theme", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { colorChanged: "colorChanged" }, host: { classAttribute: "ngx-mat-color-palette" }, ngImport: i0, template: "<ngx-mat-color-canvas\r\n (colorChanged)=\"handleColorChanged($event)\"\r\n [color]=\"color()\"\r\n [theme]=\"theme()\"\r\n/>\r\n\r\n<ngx-mat-color-collection\r\n (colorChanged)=\"handleColorChanged($event)\"\r\n [color]=\"color()\"\r\n/>\r\n", styles: [".ngx-mat-color-palette .actions{margin-top:10px;display:flex}.ngx-mat-color-palette .actions .left{display:flex;flex-direction:column;margin-right:15px}.ngx-mat-color-palette .actions .left .preview{flex:2 1 auto;margin-bottom:10px}.ngx-mat-color-palette .actions .right{display:flex;width:60px;flex-direction:column}\n"], dependencies: [{ kind: "component", type: NgxMatColorCollectionComponent, selector: "ngx-mat-color-collection", inputs: ["color"], outputs: ["colorChanged"] }, { kind: "component", type: NgxMatColorCanvasComponent, selector: "ngx-mat-color-canvas" }], encapsulation: i0.ViewEncapsulation.None }); }
|
|
540
|
+
}
|
|
541
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorPaletteComponent, decorators: [{
|
|
542
|
+
type: Component,
|
|
543
|
+
args: [{ selector: 'ngx-mat-color-palette', encapsulation: ViewEncapsulation.None, host: {
|
|
544
|
+
class: 'ngx-mat-color-palette',
|
|
545
|
+
}, imports: [NgxMatColorCollectionComponent, NgxMatColorCanvasComponent], template: "<ngx-mat-color-canvas\r\n (colorChanged)=\"handleColorChanged($event)\"\r\n [color]=\"color()\"\r\n [theme]=\"theme()\"\r\n/>\r\n\r\n<ngx-mat-color-collection\r\n (colorChanged)=\"handleColorChanged($event)\"\r\n [color]=\"color()\"\r\n/>\r\n", styles: [".ngx-mat-color-palette .actions{margin-top:10px;display:flex}.ngx-mat-color-palette .actions .left{display:flex;flex-direction:column;margin-right:15px}.ngx-mat-color-palette .actions .left .preview{flex:2 1 auto;margin-bottom:10px}.ngx-mat-color-palette .actions .right{display:flex;width:60px;flex-direction:column}\n"] }]
|
|
546
|
+
}], propDecorators: { colorChanged: [{ type: i0.Output, args: ["colorChanged"] }], color: [{ type: i0.Input, args: [{ isSignal: true, alias: "color", required: false }] }], theme: [{ type: i0.Input, args: [{ isSignal: true, alias: "theme", required: false }] }] } });
|
|
547
|
+
|
|
548
|
+
class ColorAdapter {
|
|
549
|
+
sameColor(a, b) {
|
|
550
|
+
if (a == null && b == null)
|
|
551
|
+
return true;
|
|
552
|
+
if (a != null && b != null)
|
|
553
|
+
return a.rgba === b.rgba;
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
format(c, format) {
|
|
557
|
+
return c.toString(format);
|
|
558
|
+
}
|
|
559
|
+
parse(value) {
|
|
560
|
+
const obj = stringInputToObject(value);
|
|
561
|
+
if (obj) {
|
|
562
|
+
return new Color(obj.r, obj.g, obj.b, obj.a);
|
|
563
|
+
}
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ColorAdapter, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
567
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ColorAdapter }); }
|
|
568
|
+
}
|
|
569
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ColorAdapter, decorators: [{
|
|
570
|
+
type: Injectable
|
|
571
|
+
}] });
|
|
572
|
+
|
|
573
|
+
const NGX_MAT_COLOR_FORMATS = {
|
|
574
|
+
display: {
|
|
575
|
+
colorInput: 'hex',
|
|
576
|
+
},
|
|
577
|
+
};
|
|
578
|
+
const MAT_COLOR_FORMATS = new InjectionToken('mat-color-formats');
|
|
579
|
+
|
|
580
|
+
/** Injection token that determines the scroll handling while the calendar is open. */
|
|
581
|
+
const NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY = new InjectionToken('ngx-mat-colorpicker-scroll-strategy');
|
|
582
|
+
function NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY_FACTORY(overlay) {
|
|
583
|
+
return () => overlay.scrollStrategies.reposition();
|
|
584
|
+
}
|
|
585
|
+
const NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY_FACTORY_PROVIDER = {
|
|
586
|
+
provide: NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY,
|
|
587
|
+
deps: [Overlay],
|
|
588
|
+
useFactory: NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY_FACTORY,
|
|
589
|
+
};
|
|
590
|
+
class NgxMatColorPickerContentComponent {
|
|
591
|
+
constructor() {
|
|
592
|
+
/** Reference to the internal calendar component. */
|
|
593
|
+
this._palette = viewChild(NgxMatColorPaletteComponent, ...(ngDevMode ? [{ debugName: "_palette" }] : []));
|
|
594
|
+
}
|
|
595
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorPickerContentComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
596
|
+
/** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.1.3", type: NgxMatColorPickerContentComponent, isStandalone: true, selector: "ngx-mat-color-picker-content", inputs: { color: "color" }, host: { properties: { "@transformPanel": "\"enter\"", "class.ngx-mat-colorpicker-content-touch": "picker.touchUi" }, classAttribute: "ngx-mat-colorpicker-content" }, viewQueries: [{ propertyName: "_palette", first: true, predicate: NgxMatColorPaletteComponent, descendants: true, isSignal: true }], exportAs: ["ngxMatColorPickerContent"], ngImport: i0, template: "<ngx-mat-color-palette\r\n (colorChanged)=\"picker.select($event)\"\r\n [color]=\"picker._selected\"\r\n [theme]=\"color\"></ngx-mat-color-palette>\r\n", styles: [".ngx-mat-colorpicker-content{display:block;border-radius:4px;box-shadow:0 2px 4px -1px #0003,0 4px 5px #00000024,0 1px 10px #0000001f;background-color:#fff;color:#000000de;padding:16px}.ngx-mat-colorpicker-content .ngx-mat-color-palette{width:296px;height:354px}.ngx-mat-colorpicker-content-touch{display:block;max-height:80vh;overflow:auto}.ngx-mat-colorpicker-content-touch .ngx-mat-color-palette{min-width:250px;min-height:312px;max-width:750px;max-height:788px}@media all and (orientation:landscape){.mat-colorpicker-content-touch .ngx-mat-color-palette{width:64vh;height:80vh}}@media all and (orientation:portrait){.mat-colorpicker-content-touch .ngx-mat-color-palette{width:80vw;height:100vw}}\n"], dependencies: [{ kind: "component", type: NgxMatColorPaletteComponent, selector: "ngx-mat-color-palette", inputs: ["color", "theme"], outputs: ["colorChanged"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
597
|
+
}
|
|
598
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorPickerContentComponent, decorators: [{
|
|
599
|
+
type: Component,
|
|
600
|
+
args: [{ selector: 'ngx-mat-color-picker-content', host: {
|
|
601
|
+
class: 'ngx-mat-colorpicker-content',
|
|
602
|
+
'[@transformPanel]': '"enter"',
|
|
603
|
+
'[class.ngx-mat-colorpicker-content-touch]': 'picker.touchUi',
|
|
604
|
+
}, exportAs: 'ngxMatColorPickerContent', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, inputs: ['color'], imports: [NgxMatColorPaletteComponent], template: "<ngx-mat-color-palette\r\n (colorChanged)=\"picker.select($event)\"\r\n [color]=\"picker._selected\"\r\n [theme]=\"color\"></ngx-mat-color-palette>\r\n", styles: [".ngx-mat-colorpicker-content{display:block;border-radius:4px;box-shadow:0 2px 4px -1px #0003,0 4px 5px #00000024,0 1px 10px #0000001f;background-color:#fff;color:#000000de;padding:16px}.ngx-mat-colorpicker-content .ngx-mat-color-palette{width:296px;height:354px}.ngx-mat-colorpicker-content-touch{display:block;max-height:80vh;overflow:auto}.ngx-mat-colorpicker-content-touch .ngx-mat-color-palette{min-width:250px;min-height:312px;max-width:750px;max-height:788px}@media all and (orientation:landscape){.mat-colorpicker-content-touch .ngx-mat-color-palette{width:64vh;height:80vh}}@media all and (orientation:portrait){.mat-colorpicker-content-touch .ngx-mat-color-palette{width:80vw;height:100vw}}\n"] }]
|
|
605
|
+
}], ctorParameters: () => [], propDecorators: { _palette: [{ type: i0.ViewChild, args: [i0.forwardRef(() => NgxMatColorPaletteComponent), { isSignal: true }] }] } });
|
|
606
|
+
class NgxMatColorPickerComponent {
|
|
607
|
+
get disabled() {
|
|
608
|
+
return this._disabled === undefined && this._pickerInput
|
|
609
|
+
? this._pickerInput.disabled
|
|
610
|
+
: !!this._disabled;
|
|
611
|
+
}
|
|
612
|
+
set disabled(value) {
|
|
613
|
+
const newValue = coerceBooleanProperty(value);
|
|
614
|
+
if (newValue !== this._disabled) {
|
|
615
|
+
this._disabled = newValue;
|
|
616
|
+
this._disabledChange.next(newValue);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
get touchUi() {
|
|
620
|
+
return this._touchUi;
|
|
621
|
+
}
|
|
622
|
+
set touchUi(value) {
|
|
623
|
+
this._touchUi = coerceBooleanProperty(value);
|
|
624
|
+
}
|
|
625
|
+
/** Whether the calendar is open. */
|
|
626
|
+
get opened() {
|
|
627
|
+
return this._opened;
|
|
628
|
+
}
|
|
629
|
+
set opened(value) {
|
|
630
|
+
value ? this.open() : this.close();
|
|
631
|
+
}
|
|
632
|
+
/** Default Color palette to use on the datepicker's calendar. */
|
|
633
|
+
get defaultColor() {
|
|
634
|
+
return this._defaultColor;
|
|
635
|
+
}
|
|
636
|
+
set defaultColor(value) {
|
|
637
|
+
this._defaultColor = value;
|
|
638
|
+
}
|
|
639
|
+
/** Color palette to use on the datepicker's calendar. */
|
|
640
|
+
get color() {
|
|
641
|
+
return this._color || (this._pickerInput ? this._pickerInput.getThemePalette() : undefined);
|
|
642
|
+
}
|
|
643
|
+
set color(value) {
|
|
644
|
+
this._color = value;
|
|
645
|
+
}
|
|
646
|
+
get isPrimary() {
|
|
647
|
+
return this.color === 'primary';
|
|
648
|
+
}
|
|
649
|
+
get isAccent() {
|
|
650
|
+
return this.color === 'accent';
|
|
651
|
+
}
|
|
652
|
+
get isWarn() {
|
|
653
|
+
return this.color === 'warn';
|
|
654
|
+
}
|
|
655
|
+
/** The currently selected date. */
|
|
656
|
+
get _selected() {
|
|
657
|
+
return this._validSelected;
|
|
658
|
+
}
|
|
659
|
+
set _selected(value) {
|
|
660
|
+
this._validSelected = value;
|
|
661
|
+
}
|
|
662
|
+
constructor(_dialog, _overlay, _zone, _adapter, _dir, scrollStrategy, _document, _viewContainerRef) {
|
|
663
|
+
this._dialog = _dialog;
|
|
664
|
+
this._overlay = _overlay;
|
|
665
|
+
this._zone = _zone;
|
|
666
|
+
this._adapter = _adapter;
|
|
667
|
+
this._dir = _dir;
|
|
668
|
+
this._document = _document;
|
|
669
|
+
this._viewContainerRef = _viewContainerRef;
|
|
670
|
+
this.id = `ngx-mat-color-picker-${Math.floor(Math.random() * 1000000)}`;
|
|
671
|
+
/** Emits when the datepicker has been opened. */
|
|
672
|
+
this.openedStream = new EventEmitter();
|
|
673
|
+
/** Emits when the datepicker has been closed. */
|
|
674
|
+
this.closedStream = new EventEmitter();
|
|
675
|
+
this._touchUi = false;
|
|
676
|
+
this._opened = false;
|
|
677
|
+
this._defaultColor = 'primary';
|
|
678
|
+
this._validSelected = null;
|
|
679
|
+
/** Emits when the datepicker is disabled. */
|
|
680
|
+
this._disabledChange = new EventEmitter();
|
|
681
|
+
/** The element that was focused before the datepicker was opened. */
|
|
682
|
+
this._focusedElementBeforeOpen = null;
|
|
683
|
+
/** Subscription to value changes in the associated input element. */
|
|
684
|
+
this._inputSubscription = Subscription.EMPTY;
|
|
685
|
+
/** Emits new selected date when selected date changes. */
|
|
686
|
+
this._selectedChanged = new Subject();
|
|
687
|
+
this._scrollStrategy = scrollStrategy;
|
|
688
|
+
}
|
|
689
|
+
ngOnDestroy() {
|
|
690
|
+
this.close();
|
|
691
|
+
this._inputSubscription.unsubscribe();
|
|
692
|
+
this._disabledChange.complete();
|
|
693
|
+
if (this._popupRef) {
|
|
694
|
+
this._popupRef.dispose();
|
|
695
|
+
this._popupComponentRef = null;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
/** Selects the given date */
|
|
699
|
+
select(nextVal) {
|
|
700
|
+
let oldValue = this._selected;
|
|
701
|
+
this._selected = nextVal;
|
|
702
|
+
if (!this._adapter.sameColor(oldValue, this._selected)) {
|
|
703
|
+
this._selectedChanged.next(nextVal);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Register an input with this datepicker.
|
|
708
|
+
* @param input The datepicker input to register with this datepicker.
|
|
709
|
+
*/
|
|
710
|
+
registerInput(input) {
|
|
711
|
+
if (this._pickerInput) {
|
|
712
|
+
throw Error('A ColorPicker can only be associated with a single input.');
|
|
713
|
+
}
|
|
714
|
+
this._pickerInput = input;
|
|
715
|
+
this._inputSubscription = this._pickerInput._valueChange.subscribe((value) => (this._selected = value));
|
|
716
|
+
}
|
|
717
|
+
open() {
|
|
718
|
+
if (this._opened || this.disabled) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
if (!this._pickerInput) {
|
|
722
|
+
throw Error('Attempted to open an ColorPicker with no associated input.');
|
|
723
|
+
}
|
|
724
|
+
if (this._document) {
|
|
725
|
+
this._focusedElementBeforeOpen = this._document.activeElement;
|
|
726
|
+
}
|
|
727
|
+
this.touchUi ? this._openAsDialog() : this._openAsPopup();
|
|
728
|
+
this._opened = true;
|
|
729
|
+
this.openedStream.emit();
|
|
730
|
+
}
|
|
731
|
+
/** Open the calendar as a dialog. */
|
|
732
|
+
_openAsDialog() {
|
|
733
|
+
if (this._dialogRef) {
|
|
734
|
+
this._dialogRef.close();
|
|
735
|
+
}
|
|
736
|
+
this._dialogRef = this._dialog.open(NgxMatColorPickerContentComponent, {
|
|
737
|
+
direction: this._dir ? this._dir.value : 'ltr',
|
|
738
|
+
viewContainerRef: this._viewContainerRef,
|
|
739
|
+
panelClass: 'ngx-mat-colorpicker-dialog',
|
|
740
|
+
});
|
|
741
|
+
this._dialogRef.afterClosed().subscribe(() => this.close());
|
|
742
|
+
this._dialogRef.componentInstance.picker = this;
|
|
743
|
+
this._setColor();
|
|
744
|
+
}
|
|
745
|
+
/** Open the calendar as a popup. */
|
|
746
|
+
_openAsPopup() {
|
|
747
|
+
if (!this._portal) {
|
|
748
|
+
this._portal = new ComponentPortal(NgxMatColorPickerContentComponent, this._viewContainerRef);
|
|
749
|
+
}
|
|
750
|
+
if (!this._popupRef) {
|
|
751
|
+
this._createPopup();
|
|
752
|
+
}
|
|
753
|
+
if (!this._popupRef.hasAttached()) {
|
|
754
|
+
this._popupComponentRef = this._popupRef.attach(this._portal);
|
|
755
|
+
this._popupComponentRef.instance.picker = this;
|
|
756
|
+
this._setColor();
|
|
757
|
+
// Update the position once the calendar has rendered.
|
|
758
|
+
this._zone.onStable
|
|
759
|
+
.asObservable()
|
|
760
|
+
.pipe(take(1))
|
|
761
|
+
.subscribe(() => {
|
|
762
|
+
this._popupRef.updatePosition();
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
/** Create the popup. */
|
|
767
|
+
_createPopup() {
|
|
768
|
+
const overlayConfig = new OverlayConfig({
|
|
769
|
+
positionStrategy: this._createPopupPositionStrategy(),
|
|
770
|
+
hasBackdrop: true,
|
|
771
|
+
backdropClass: 'mat-overlay-transparent-backdrop',
|
|
772
|
+
direction: this._dir,
|
|
773
|
+
scrollStrategy: this._scrollStrategy(),
|
|
774
|
+
panelClass: 'mat-colorpicker-popup',
|
|
775
|
+
});
|
|
776
|
+
this._popupRef = this._overlay.create(overlayConfig);
|
|
777
|
+
this._popupRef.overlayElement.setAttribute('role', 'dialog');
|
|
778
|
+
merge(this._popupRef.backdropClick(), this._popupRef.detachments(), this._popupRef.keydownEvents().pipe(filter((event) => {
|
|
779
|
+
// Closing on alt + up is only valid when there's an input associated with the datepicker.
|
|
780
|
+
return (event.keyCode === ESCAPE ||
|
|
781
|
+
(this._pickerInput && event.altKey && event.keyCode === UP_ARROW));
|
|
782
|
+
}))).subscribe((event) => {
|
|
783
|
+
if (event) {
|
|
784
|
+
event.preventDefault();
|
|
785
|
+
}
|
|
786
|
+
this.close();
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
close() {
|
|
790
|
+
if (!this._opened) {
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
if (this._popupRef && this._popupRef.hasAttached()) {
|
|
794
|
+
this._popupRef.detach();
|
|
795
|
+
}
|
|
796
|
+
if (this._dialogRef) {
|
|
797
|
+
this._dialogRef.close();
|
|
798
|
+
this._dialogRef = null;
|
|
799
|
+
}
|
|
800
|
+
if (this._portal && this._portal.isAttached) {
|
|
801
|
+
this._portal.detach();
|
|
802
|
+
}
|
|
803
|
+
const completeClose = () => {
|
|
804
|
+
// The `_opened` could've been reset already if
|
|
805
|
+
// we got two events in quick succession.
|
|
806
|
+
if (this._opened) {
|
|
807
|
+
this._opened = false;
|
|
808
|
+
this.closedStream.emit();
|
|
809
|
+
this._focusedElementBeforeOpen = null;
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
if (this._focusedElementBeforeOpen &&
|
|
813
|
+
typeof this._focusedElementBeforeOpen.focus === 'function') {
|
|
814
|
+
// Because IE moves focus asynchronously, we can't count on it being restored before we've
|
|
815
|
+
// marked the datepicker as closed. If the event fires out of sequence and the element that
|
|
816
|
+
// we're refocusing opens the datepicker on focus, the user could be stuck with not being
|
|
817
|
+
// able to close the calendar at all. We work around it by making the logic, that marks
|
|
818
|
+
// the datepicker as closed, async as well.
|
|
819
|
+
this._focusedElementBeforeOpen.focus();
|
|
820
|
+
setTimeout(completeClose);
|
|
821
|
+
}
|
|
822
|
+
else {
|
|
823
|
+
completeClose();
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/** Passes the current theme color along to the calendar overlay. */
|
|
827
|
+
_setColor() {
|
|
828
|
+
const color = this.color;
|
|
829
|
+
if (this._popupComponentRef) {
|
|
830
|
+
this._popupComponentRef.instance.color = color;
|
|
831
|
+
}
|
|
832
|
+
if (this._dialogRef) {
|
|
833
|
+
this._dialogRef.componentInstance.color = color;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
/** Create the popup PositionStrategy. */
|
|
837
|
+
_createPopupPositionStrategy() {
|
|
838
|
+
return this._overlay
|
|
839
|
+
.position()
|
|
840
|
+
.flexibleConnectedTo(this._pickerInput.getConnectedOverlayOrigin())
|
|
841
|
+
.withTransformOriginOn('.ngx-mat-colorpicker-content')
|
|
842
|
+
.withFlexibleDimensions(false)
|
|
843
|
+
.withViewportMargin(8)
|
|
844
|
+
.withLockedPosition()
|
|
845
|
+
.withPositions([
|
|
846
|
+
{
|
|
847
|
+
originX: 'start',
|
|
848
|
+
originY: 'bottom',
|
|
849
|
+
overlayX: 'start',
|
|
850
|
+
overlayY: 'top',
|
|
851
|
+
},
|
|
852
|
+
{
|
|
853
|
+
originX: 'start',
|
|
854
|
+
originY: 'top',
|
|
855
|
+
overlayX: 'start',
|
|
856
|
+
overlayY: 'bottom',
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
originX: 'end',
|
|
860
|
+
originY: 'bottom',
|
|
861
|
+
overlayX: 'end',
|
|
862
|
+
overlayY: 'top',
|
|
863
|
+
},
|
|
864
|
+
{
|
|
865
|
+
originX: 'end',
|
|
866
|
+
originY: 'top',
|
|
867
|
+
overlayX: 'end',
|
|
868
|
+
overlayY: 'bottom',
|
|
869
|
+
},
|
|
870
|
+
]);
|
|
871
|
+
}
|
|
872
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorPickerComponent, deps: [{ token: i1$2.MatDialog }, { token: i2$1.Overlay }, { token: i0.NgZone }, { token: ColorAdapter }, { token: i4.Directionality, optional: true }, { token: NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY }, { token: DOCUMENT, optional: true }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
873
|
+
/** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.1.3", type: NgxMatColorPickerComponent, isStandalone: true, selector: "ngx-mat-color-picker", inputs: { id: "id", disabled: "disabled", touchUi: "touchUi", opened: "opened", defaultColor: "defaultColor", color: "color" }, outputs: { openedStream: "opened", closedStream: "closed" }, host: { properties: { "class.mat-primary": "this.isPrimary", "class.mat-accent": "this.isAccent", "class.mat-warn": "this.isWarn" } }, providers: [ColorAdapter, NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY_FACTORY_PROVIDER], exportAs: ["ngxMatColorPicker"], ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
874
|
+
}
|
|
875
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorPickerComponent, decorators: [{
|
|
876
|
+
type: Component,
|
|
877
|
+
args: [{
|
|
878
|
+
selector: 'ngx-mat-color-picker',
|
|
879
|
+
template: '',
|
|
880
|
+
exportAs: 'ngxMatColorPicker',
|
|
881
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
882
|
+
encapsulation: ViewEncapsulation.None,
|
|
883
|
+
providers: [ColorAdapter, NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY_FACTORY_PROVIDER],
|
|
884
|
+
}]
|
|
885
|
+
}], ctorParameters: () => [{ type: i1$2.MatDialog }, { type: i2$1.Overlay }, { type: i0.NgZone }, { type: ColorAdapter }, { type: i4.Directionality, decorators: [{
|
|
886
|
+
type: Optional
|
|
887
|
+
}] }, { type: undefined, decorators: [{
|
|
888
|
+
type: Inject,
|
|
889
|
+
args: [NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY]
|
|
890
|
+
}] }, { type: undefined, decorators: [{
|
|
891
|
+
type: Optional
|
|
892
|
+
}, {
|
|
893
|
+
type: Inject,
|
|
894
|
+
args: [DOCUMENT]
|
|
895
|
+
}] }, { type: i0.ViewContainerRef }], propDecorators: { id: [{
|
|
896
|
+
type: Input
|
|
897
|
+
}], openedStream: [{
|
|
898
|
+
type: Output,
|
|
899
|
+
args: ['opened']
|
|
900
|
+
}], closedStream: [{
|
|
901
|
+
type: Output,
|
|
902
|
+
args: ['closed']
|
|
903
|
+
}], disabled: [{
|
|
904
|
+
type: Input
|
|
905
|
+
}], touchUi: [{
|
|
906
|
+
type: Input
|
|
907
|
+
}], opened: [{
|
|
908
|
+
type: Input
|
|
909
|
+
}], defaultColor: [{
|
|
910
|
+
type: Input
|
|
911
|
+
}], color: [{
|
|
912
|
+
type: Input
|
|
913
|
+
}], isPrimary: [{
|
|
914
|
+
type: HostBinding,
|
|
915
|
+
args: ['class.mat-primary']
|
|
916
|
+
}], isAccent: [{
|
|
917
|
+
type: HostBinding,
|
|
918
|
+
args: ['class.mat-accent']
|
|
919
|
+
}], isWarn: [{
|
|
920
|
+
type: HostBinding,
|
|
921
|
+
args: ['class.mat-warn']
|
|
922
|
+
}] } });
|
|
923
|
+
|
|
924
|
+
class NgxMatColorPickerInputEvent {
|
|
925
|
+
constructor(
|
|
926
|
+
/** Reference to the colorpicker input component that emitted the event. */
|
|
927
|
+
target,
|
|
928
|
+
/** Reference to the native input element associated with the colorpicker input. */
|
|
929
|
+
targetElement) {
|
|
930
|
+
this.target = target;
|
|
931
|
+
this.targetElement = targetElement;
|
|
932
|
+
this.value = this.target.value;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
const MAT_COLORPICKER_VALUE_ACCESSOR = {
|
|
936
|
+
provide: NG_VALUE_ACCESSOR,
|
|
937
|
+
useExisting: forwardRef(() => NgxMatColorPickerInput),
|
|
938
|
+
multi: true,
|
|
939
|
+
};
|
|
940
|
+
const MAT_COLORPICKER_VALIDATORS = {
|
|
941
|
+
provide: NG_VALIDATORS,
|
|
942
|
+
useExisting: forwardRef(() => NgxMatColorPickerInput),
|
|
943
|
+
multi: true,
|
|
944
|
+
};
|
|
945
|
+
class NgxMatColorPickerInput {
|
|
946
|
+
set ngxMatColorPicker(value) {
|
|
947
|
+
if (!value) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
this._picker = value;
|
|
951
|
+
this._picker.registerInput(this);
|
|
952
|
+
this._pickerSubscription.unsubscribe();
|
|
953
|
+
this._pickerSubscription = this._picker._selectedChanged.subscribe((selected) => {
|
|
954
|
+
this.value = selected;
|
|
955
|
+
this._cvaOnChange(selected);
|
|
956
|
+
this._onTouched();
|
|
957
|
+
this.colorInput.emit(new NgxMatColorPickerInputEvent(this, this._elementRef.nativeElement));
|
|
958
|
+
this.colorChange.emit(new NgxMatColorPickerInputEvent(this, this._elementRef.nativeElement));
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
/** Whether the colorpicker-input is disabled. */
|
|
962
|
+
get disabled() {
|
|
963
|
+
return !!this._disabled;
|
|
964
|
+
}
|
|
965
|
+
set disabled(value) {
|
|
966
|
+
const newValue = coerceBooleanProperty(value);
|
|
967
|
+
const element = this._elementRef.nativeElement;
|
|
968
|
+
if (this._disabled !== newValue) {
|
|
969
|
+
this._disabled = newValue;
|
|
970
|
+
this._disabledChange.emit(newValue);
|
|
971
|
+
}
|
|
972
|
+
// We need to null check the `blur` method, because it's undefined during SSR.
|
|
973
|
+
if (newValue && element.blur) {
|
|
974
|
+
// Normally, native input elements automatically blur if they turn disabled. This behavior
|
|
975
|
+
// is problematic, because it would mean that it triggers another change detection cycle,
|
|
976
|
+
// which then causes a changed after checked error if the input element was focused before.
|
|
977
|
+
element.blur();
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
/** The value of the input. */
|
|
981
|
+
get value() {
|
|
982
|
+
return this._value;
|
|
983
|
+
}
|
|
984
|
+
set value(value) {
|
|
985
|
+
const oldValue = this.value;
|
|
986
|
+
this._value = value;
|
|
987
|
+
this._formatValue(value);
|
|
988
|
+
if (!this._adapter.sameColor(oldValue, value)) {
|
|
989
|
+
this._valueChange.emit(value);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
constructor(_elementRef, _formField, _colorFormats, _adapter) {
|
|
993
|
+
this._elementRef = _elementRef;
|
|
994
|
+
this._formField = _formField;
|
|
995
|
+
this._colorFormats = _colorFormats;
|
|
996
|
+
this._adapter = _adapter;
|
|
997
|
+
/** Emits when a `change` event is fired on this `<input>`. */
|
|
998
|
+
this.colorChange = output();
|
|
999
|
+
/** Emits when an `input` event is fired on this `<input>`. */
|
|
1000
|
+
this.colorInput = output();
|
|
1001
|
+
/** Emits when the disabled state has changed */
|
|
1002
|
+
this._disabledChange = new EventEmitter();
|
|
1003
|
+
/** Emits when the value changes (either due to user input or programmatic change). */
|
|
1004
|
+
this._valueChange = new EventEmitter();
|
|
1005
|
+
this._onTouched = () => { };
|
|
1006
|
+
this._cvaOnChange = () => { };
|
|
1007
|
+
this._validatorOnChange = () => { };
|
|
1008
|
+
this._pickerSubscription = Subscription.EMPTY;
|
|
1009
|
+
/** The combined form control validator for this input. */
|
|
1010
|
+
this._validator = Validators.compose([]);
|
|
1011
|
+
/** Whether the last value set on the input was valid. */
|
|
1012
|
+
this._lastValueValid = false;
|
|
1013
|
+
if (!this._colorFormats) {
|
|
1014
|
+
throw createMissingDateImplError('MAT_COLOR_FORMATS');
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
/** Returns the palette used by the input's form field, if any. */
|
|
1018
|
+
getThemePalette() {
|
|
1019
|
+
return this._formField ? this._formField.color : undefined;
|
|
1020
|
+
}
|
|
1021
|
+
registerOnValidatorChange(fn) {
|
|
1022
|
+
this._validatorOnChange = fn;
|
|
1023
|
+
}
|
|
1024
|
+
validate(c) {
|
|
1025
|
+
return this._validator ? this._validator(c) : null;
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* @deprecated
|
|
1029
|
+
* @breaking-change 8.0.0 Use `getConnectedOverlayOrigin` instead
|
|
1030
|
+
*/
|
|
1031
|
+
getPopupConnectionElementRef() {
|
|
1032
|
+
return this.getConnectedOverlayOrigin();
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* Gets the element that the colorpicker popup should be connected to.
|
|
1036
|
+
* @return The element to connect the popup to.
|
|
1037
|
+
*/
|
|
1038
|
+
getConnectedOverlayOrigin() {
|
|
1039
|
+
return this._formField ? this._formField.getConnectedOverlayOrigin() : this._elementRef;
|
|
1040
|
+
}
|
|
1041
|
+
ngOnInit() { }
|
|
1042
|
+
ngOnDestroy() {
|
|
1043
|
+
this._pickerSubscription.unsubscribe();
|
|
1044
|
+
this._valueChange.complete();
|
|
1045
|
+
this._disabledChange.complete();
|
|
1046
|
+
}
|
|
1047
|
+
// Implemented as part of ControlValueAccessor.
|
|
1048
|
+
writeValue(value) {
|
|
1049
|
+
this.value = value;
|
|
1050
|
+
}
|
|
1051
|
+
// Implemented as part of ControlValueAccessor.
|
|
1052
|
+
registerOnChange(fn) {
|
|
1053
|
+
this._cvaOnChange = fn;
|
|
1054
|
+
}
|
|
1055
|
+
// Implemented as part of ControlValueAccessor.
|
|
1056
|
+
registerOnTouched(fn) {
|
|
1057
|
+
this._onTouched = fn;
|
|
1058
|
+
}
|
|
1059
|
+
// Implemented as part of ControlValueAccessor.
|
|
1060
|
+
setDisabledState(isDisabled) {
|
|
1061
|
+
this.disabled = isDisabled;
|
|
1062
|
+
}
|
|
1063
|
+
_onChange() {
|
|
1064
|
+
this.colorChange.emit(new NgxMatColorPickerInputEvent(this, this._elementRef.nativeElement));
|
|
1065
|
+
}
|
|
1066
|
+
_onKeydown(event) {
|
|
1067
|
+
const isAltDownArrow = event.altKey && event.keyCode === DOWN_ARROW;
|
|
1068
|
+
if (this._picker && isAltDownArrow && !this._elementRef.nativeElement.readOnly) {
|
|
1069
|
+
this._picker.open();
|
|
1070
|
+
event.preventDefault();
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
/** Handles blur events on the input. */
|
|
1074
|
+
_onBlur() {
|
|
1075
|
+
// Reformat the input only if we have a valid value.
|
|
1076
|
+
if (this.value) {
|
|
1077
|
+
this._formatValue(this.value);
|
|
1078
|
+
}
|
|
1079
|
+
this._onTouched();
|
|
1080
|
+
}
|
|
1081
|
+
/** Formats a value and sets it on the input element. */
|
|
1082
|
+
_formatValue(value) {
|
|
1083
|
+
this._elementRef.nativeElement.value = value
|
|
1084
|
+
? this._adapter.format(value, this._colorFormats.display.colorInput)
|
|
1085
|
+
: '';
|
|
1086
|
+
}
|
|
1087
|
+
_onInput(value) {
|
|
1088
|
+
const lastValueWasValid = this._lastValueValid;
|
|
1089
|
+
const nextValue = this._adapter.parse(value);
|
|
1090
|
+
if (!this._adapter.sameColor(nextValue, this._value)) {
|
|
1091
|
+
this._value = nextValue;
|
|
1092
|
+
this._cvaOnChange(nextValue);
|
|
1093
|
+
this._valueChange.emit(nextValue);
|
|
1094
|
+
this.colorInput.emit(new NgxMatColorPickerInputEvent(this, this._elementRef.nativeElement));
|
|
1095
|
+
}
|
|
1096
|
+
else if (lastValueWasValid !== this._lastValueValid) {
|
|
1097
|
+
this._validatorOnChange();
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorPickerInput, deps: [{ token: i0.ElementRef }, { token: i1.MatFormField, optional: true }, { token: MAT_COLOR_FORMATS, optional: true }, { token: ColorAdapter }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1101
|
+
/** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.3", type: NgxMatColorPickerInput, isStandalone: true, selector: "input[ngxMatColorPicker]", inputs: { ngxMatColorPicker: "ngxMatColorPicker", disabled: "disabled", value: "value" }, outputs: { colorChange: "colorChange", colorInput: "colorInput" }, host: { listeners: { "input": "_onInput($event.target.value)", "change": "_onChange()", "blur": "_onBlur()", "keydown": "_onKeydown($event)" }, properties: { "attr.aria-haspopup": "_picker ? \"dialog\" : null", "attr.aria-owns": "(_picker?.opened && _picker.id) || null", "disabled": "disabled" } }, providers: [
|
|
1102
|
+
{ provide: MAT_INPUT_VALUE_ACCESSOR, useExisting: NgxMatColorPickerInput },
|
|
1103
|
+
ColorAdapter,
|
|
1104
|
+
MAT_COLORPICKER_VALIDATORS,
|
|
1105
|
+
MAT_COLORPICKER_VALUE_ACCESSOR,
|
|
1106
|
+
], exportAs: ["ngxMatColorPickerInput"], ngImport: i0 }); }
|
|
1107
|
+
}
|
|
1108
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorPickerInput, decorators: [{
|
|
1109
|
+
type: Directive,
|
|
1110
|
+
args: [{
|
|
1111
|
+
selector: 'input[ngxMatColorPicker]',
|
|
1112
|
+
providers: [
|
|
1113
|
+
{ provide: MAT_INPUT_VALUE_ACCESSOR, useExisting: NgxMatColorPickerInput },
|
|
1114
|
+
ColorAdapter,
|
|
1115
|
+
MAT_COLORPICKER_VALIDATORS,
|
|
1116
|
+
MAT_COLORPICKER_VALUE_ACCESSOR,
|
|
1117
|
+
],
|
|
1118
|
+
host: {
|
|
1119
|
+
'[attr.aria-haspopup]': '_picker ? "dialog" : null',
|
|
1120
|
+
'[attr.aria-owns]': '(_picker?.opened && _picker.id) || null',
|
|
1121
|
+
'[disabled]': 'disabled',
|
|
1122
|
+
'(input)': '_onInput($event.target.value)',
|
|
1123
|
+
'(change)': '_onChange()',
|
|
1124
|
+
'(blur)': '_onBlur()',
|
|
1125
|
+
'(keydown)': '_onKeydown($event)',
|
|
1126
|
+
},
|
|
1127
|
+
exportAs: 'ngxMatColorPickerInput',
|
|
1128
|
+
}]
|
|
1129
|
+
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.MatFormField, decorators: [{
|
|
1130
|
+
type: Optional
|
|
1131
|
+
}] }, { type: undefined, decorators: [{
|
|
1132
|
+
type: Optional
|
|
1133
|
+
}, {
|
|
1134
|
+
type: Inject,
|
|
1135
|
+
args: [MAT_COLOR_FORMATS]
|
|
1136
|
+
}] }, { type: ColorAdapter }], propDecorators: { ngxMatColorPicker: [{
|
|
1137
|
+
type: Input
|
|
1138
|
+
}], disabled: [{
|
|
1139
|
+
type: Input
|
|
1140
|
+
}], value: [{
|
|
1141
|
+
type: Input
|
|
1142
|
+
}], colorChange: [{ type: i0.Output, args: ["colorChange"] }], colorInput: [{ type: i0.Output, args: ["colorInput"] }] } });
|
|
1143
|
+
|
|
1144
|
+
class NgxMatColorpickerToggleIcon {
|
|
1145
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorpickerToggleIcon, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1146
|
+
/** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.3", type: NgxMatColorpickerToggleIcon, isStandalone: true, selector: "[ngxMatColorpickerToggleIcon]", ngImport: i0 }); }
|
|
1147
|
+
}
|
|
1148
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorpickerToggleIcon, decorators: [{
|
|
1149
|
+
type: Directive,
|
|
1150
|
+
args: [{
|
|
1151
|
+
selector: '[ngxMatColorpickerToggleIcon]',
|
|
1152
|
+
}]
|
|
1153
|
+
}] });
|
|
1154
|
+
class NgxMatColorToggleComponent {
|
|
1155
|
+
get disabled() {
|
|
1156
|
+
if (this._disabled == null && this.picker()) {
|
|
1157
|
+
return this.picker().disabled;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
set disabled(value) {
|
|
1161
|
+
this._disabled = value;
|
|
1162
|
+
}
|
|
1163
|
+
constructor(_cd) {
|
|
1164
|
+
this._cd = _cd;
|
|
1165
|
+
this._stateChanges = Subscription.EMPTY;
|
|
1166
|
+
this.picker = input(undefined, { ...(ngDevMode ? { debugName: "picker" } : {}), alias: 'for' });
|
|
1167
|
+
this.tabIndex = input(...(ngDevMode ? [undefined, { debugName: "tabIndex" }] : []));
|
|
1168
|
+
/** Whether ripples on the toggle should be disabled. */
|
|
1169
|
+
this.disableRipple = input(...(ngDevMode ? [undefined, { debugName: "disableRipple" }] : []));
|
|
1170
|
+
this._button = viewChild('button', ...(ngDevMode ? [{ debugName: "_button" }] : []));
|
|
1171
|
+
effect(() => {
|
|
1172
|
+
this.picker();
|
|
1173
|
+
untracked(() => this._watchStateChanges());
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
ngOnDestroy() {
|
|
1177
|
+
this._stateChanges.unsubscribe();
|
|
1178
|
+
}
|
|
1179
|
+
ngAfterContentInit() {
|
|
1180
|
+
this._watchStateChanges();
|
|
1181
|
+
}
|
|
1182
|
+
open(event) {
|
|
1183
|
+
if (this.picker() && !this.disabled) {
|
|
1184
|
+
this.picker().open();
|
|
1185
|
+
event.stopPropagation();
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
_watchStateChanges() {
|
|
1189
|
+
const disabled$ = this.picker()?._disabledChange ?? new EventEmitter();
|
|
1190
|
+
const inputDisabled$ = this.picker()?._pickerInput?._disabledChange ?? new EventEmitter();
|
|
1191
|
+
const pickerToggled$ = this.picker()
|
|
1192
|
+
? merge(this.picker().openedStream, this.picker().closedStream)
|
|
1193
|
+
: of();
|
|
1194
|
+
this._stateChanges.unsubscribe();
|
|
1195
|
+
this._stateChanges = merge(disabled$, inputDisabled$, pickerToggled$).subscribe(() => this._cd.markForCheck());
|
|
1196
|
+
}
|
|
1197
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorToggleComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
1198
|
+
/** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.1.3", type: NgxMatColorToggleComponent, isStandalone: true, selector: "ngx-mat-color-toggle", inputs: { picker: { classPropertyName: "picker", publicName: "for", isSignal: true, isRequired: false, transformFunction: null }, tabIndex: { classPropertyName: "tabIndex", publicName: "tabIndex", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: false, isRequired: false, transformFunction: null }, disableRipple: { classPropertyName: "disableRipple", publicName: "disableRipple", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "focus": "_button()?.focus()" }, properties: { "attr.tabindex": "-1", "class.ngx-mat-color-toggle-active": "picker && picker()?.opened", "class.mat-accent": "picker && picker()?.color === \"accent\"", "class.mat-warn": "picker && picker()?.color === \"warn\"" }, classAttribute: "ngx-mat-color-toggle" }, viewQueries: [{ propertyName: "_button", first: true, predicate: ["button"], descendants: true, isSignal: true }], exportAs: ["ngxMatColorPickerToggle"], ngImport: i0, template: "<button\r\n #button\r\n mat-icon-button\r\n type=\"button\"\r\n [attr.aria-haspopup]=\"picker() ? 'dialog' : null\"\r\n [attr.tabindex]=\"disabled ? -1 : tabIndex()\"\r\n [disabled]=\"disabled\"\r\n (click)=\"open($event)\"\r\n [disableRipple]=\"disableRipple()\"\r\n>\r\n <ng-content select=\"[ngxMatColorpickerToggleIcon]\">\r\n <mat-icon [style.color]=\"picker()?._selected?.rgba\">palette</mat-icon>\r\n </ng-content>\r\n</button>\r\n", styles: [".mat-form-field-appearance .mat-form-field-prefix .ngx-mat-color-toggle-default-icon,.mat-form-field-appearance .mat-form-field-suffix .ngx-mat-color-toggle-default-icon{width:1em}.mat-form-field:not(.mat-form-field-appearance) .mat-form-field-prefix .ngx-mat-color-toggle-default-icon,.mat-form-field:not(.mat-form-field-appearance) .mat-form-field-suffix .ngx-mat-color-toggle-default-icon{display:block;width:1.5em;height:1.5em}.mat-form-field:not(.mat-form-field-appearance) .mat-form-field-prefix .mat-icon-button .ngx-mat-color-toggle-default-icon,.mat-form-field:not(.mat-form-field-appearance) .mat-form-field-suffix .mat-icon-button .ngx-mat-color-toggle-default-icon{margin:auto}\n"], dependencies: [{ kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i1$1.MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i2$2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], encapsulation: i0.ViewEncapsulation.None }); }
|
|
1199
|
+
}
|
|
1200
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NgxMatColorToggleComponent, decorators: [{
|
|
1201
|
+
type: Component,
|
|
1202
|
+
args: [{ selector: 'ngx-mat-color-toggle', host: {
|
|
1203
|
+
class: 'ngx-mat-color-toggle',
|
|
1204
|
+
// Always set the tabindex to -1 so that it doesn't overlap with any custom tabindex the
|
|
1205
|
+
// consumer may have provided, while still being able to receive focus.
|
|
1206
|
+
'[attr.tabindex]': '-1',
|
|
1207
|
+
'[class.ngx-mat-color-toggle-active]': 'picker && picker()?.opened',
|
|
1208
|
+
'[class.mat-accent]': 'picker && picker()?.color === "accent"',
|
|
1209
|
+
'[class.mat-warn]': 'picker && picker()?.color === "warn"',
|
|
1210
|
+
'(focus)': '_button()?.focus()',
|
|
1211
|
+
}, exportAs: 'ngxMatColorPickerToggle', encapsulation: ViewEncapsulation.None, imports: [MatButtonModule, MatIconModule], template: "<button\r\n #button\r\n mat-icon-button\r\n type=\"button\"\r\n [attr.aria-haspopup]=\"picker() ? 'dialog' : null\"\r\n [attr.tabindex]=\"disabled ? -1 : tabIndex()\"\r\n [disabled]=\"disabled\"\r\n (click)=\"open($event)\"\r\n [disableRipple]=\"disableRipple()\"\r\n>\r\n <ng-content select=\"[ngxMatColorpickerToggleIcon]\">\r\n <mat-icon [style.color]=\"picker()?._selected?.rgba\">palette</mat-icon>\r\n </ng-content>\r\n</button>\r\n", styles: [".mat-form-field-appearance .mat-form-field-prefix .ngx-mat-color-toggle-default-icon,.mat-form-field-appearance .mat-form-field-suffix .ngx-mat-color-toggle-default-icon{width:1em}.mat-form-field:not(.mat-form-field-appearance) .mat-form-field-prefix .ngx-mat-color-toggle-default-icon,.mat-form-field:not(.mat-form-field-appearance) .mat-form-field-suffix .ngx-mat-color-toggle-default-icon{display:block;width:1.5em;height:1.5em}.mat-form-field:not(.mat-form-field-appearance) .mat-form-field-prefix .mat-icon-button .ngx-mat-color-toggle-default-icon,.mat-form-field:not(.mat-form-field-appearance) .mat-form-field-suffix .mat-icon-button .ngx-mat-color-toggle-default-icon{margin:auto}\n"] }]
|
|
1212
|
+
}], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { picker: [{ type: i0.Input, args: [{ isSignal: true, alias: "for", required: false }] }], tabIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabIndex", required: false }] }], disabled: [{
|
|
1213
|
+
type: Input
|
|
1214
|
+
}], disableRipple: [{ type: i0.Input, args: [{ isSignal: true, alias: "disableRipple", required: false }] }], _button: [{ type: i0.ViewChild, args: ['button', { isSignal: true }] }] } });
|
|
1215
|
+
|
|
1216
|
+
class NumericColorInputDirective {
|
|
1217
|
+
onInput($event) {
|
|
1218
|
+
this._formatInput($event.target);
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* Format input
|
|
1222
|
+
* @param input
|
|
1223
|
+
*/
|
|
1224
|
+
_formatInput(input) {
|
|
1225
|
+
let val = Number(input.value.replace(NUMERIC_REGEX, ''));
|
|
1226
|
+
val = isNaN(val) ? 0 : val;
|
|
1227
|
+
input.value = val;
|
|
1228
|
+
}
|
|
1229
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NumericColorInputDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1230
|
+
/** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.3", type: NumericColorInputDirective, isStandalone: true, selector: "[ngxMatNumericColorInput]", host: { listeners: { "input": "onInput($event)" } }, ngImport: i0 }); }
|
|
1231
|
+
}
|
|
1232
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: NumericColorInputDirective, decorators: [{
|
|
1233
|
+
type: Directive,
|
|
1234
|
+
args: [{
|
|
1235
|
+
selector: '[ngxMatNumericColorInput]',
|
|
1236
|
+
}]
|
|
1237
|
+
}], propDecorators: { onInput: [{
|
|
1238
|
+
type: HostListener,
|
|
1239
|
+
args: ['input', ['$event']]
|
|
1240
|
+
}] } });
|
|
1241
|
+
|
|
1242
|
+
/*
|
|
1243
|
+
* Public API Surface of color-picker
|
|
1244
|
+
*/
|
|
1245
|
+
|
|
1246
|
+
/**
|
|
1247
|
+
* Generated bundle index. Do not edit.
|
|
1248
|
+
*/
|
|
1249
|
+
|
|
1250
|
+
export { BASIC_COLORS, Color, ColorAdapter, MAT_COLORPICKER_VALIDATORS, MAT_COLORPICKER_VALUE_ACCESSOR, MAT_COLOR_FORMATS, MAX_RGB, MIN_RGB, NGX_MAT_COLOR_FORMATS, NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY, NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY_FACTORY, NGX_MAT_COLOR_PICKER_SCROLL_STRATEGY_FACTORY_PROVIDER, NUMERIC_REGEX, NgxMatColorCanvasComponent, NgxMatColorCollectionComponent, NgxMatColorPaletteComponent, NgxMatColorPickerComponent, NgxMatColorPickerContentComponent, NgxMatColorPickerInput, NgxMatColorPickerInputEvent, NgxMatColorSliderComponent, NgxMatColorToggleComponent, NgxMatColorpickerToggleIcon, NumericColorInputDirective, convertDecimalToHex, createMissingDateImplError, getColorAtPosition, matchers, pad2, rgbToHex, rgbaToHex, stringInputToObject };
|
|
1251
|
+
//# sourceMappingURL=ngx-mce-color-picker.mjs.map
|