@thednp/color-picker 0.0.2-alpha1 → 0.0.2-alpha4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -1
- package/dist/js/color-esm.js +94 -105
- package/dist/js/color-esm.min.js +2 -2
- package/dist/js/color-palette-esm.js +105 -119
- package/dist/js/color-palette-esm.min.js +2 -2
- package/dist/js/color-palette.js +105 -119
- package/dist/js/color-palette.min.js +2 -2
- package/dist/js/color-picker-element-esm.js +279 -375
- package/dist/js/color-picker-element-esm.min.js +2 -2
- package/dist/js/color-picker-element.js +279 -375
- package/dist/js/color-picker-element.min.js +2 -2
- package/dist/js/color-picker-esm.js +235 -323
- package/dist/js/color-picker-esm.min.js +2 -2
- package/dist/js/color-picker.js +235 -323
- package/dist/js/color-picker.min.js +2 -2
- package/dist/js/color.js +94 -105
- package/dist/js/color.min.js +2 -2
- package/package.json +7 -4
- package/src/js/color-palette.js +10 -13
- package/src/js/color-picker-element.js +46 -54
- package/src/js/color-picker.js +131 -206
- package/src/js/color.js +93 -106
- package/types/cp.d.ts +31 -29
- package/types/source/types.d.ts +1 -1
package/dist/js/color.min.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
// Color v0.0.
|
2
|
-
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).Color=r()}(this,(function(){"use strict";const{head:t}=document;function r(t,r){const e=getComputedStyle(t);return r in e?e[r]:""}const e=(t,r)=>Object.assign(t,r),n=(t,r)=>{e(t.style,r)},o=["transparent","currentColor","inherit","revert","initial"];function s(t){const r=Math.floor(t);return t-r<.5?r:Math.round(t)}const
|
1
|
+
// Color v0.0.2alpha4 | thednp © 2022 | MIT-License
|
2
|
+
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).Color=r()}(this,(function(){"use strict";const{head:t}=document;function r(t,r){const e=getComputedStyle(t);return r in e?e[r]:""}const e=(t,r)=>Object.assign(t,r),n=(t,r)=>{e(t.style,r)},o=["transparent","currentColor","inherit","revert","initial"];function s(t){const r=Math.floor(t);return t-r<.5?r:Math.round(t)}const i=["rgb","hex","hsl","hsv","hwb"],a="[-\\+]?\\d*\\.?\\d+(?:deg|rad|grad|turn)?",h="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)",u=`(?:${h})|(?:${a})`,c="(?:[,|\\s]+)",l=`(?:[\\s|\\(\\s|\\s\\(\\s]+)?(${u})${c}(${h})${c}(${h})(?:[,|\\/\\s]*)?(${h})?(?:[\\s|\\)\\s]+)?`,g={CSS_UNIT:new RegExp(u),hwb:new RegExp("hwb"+l),rgb:new RegExp("rgb(?:a)?"+l),hsl:new RegExp("hsl(?:a)?"+l),hsv:new RegExp("hsv(?:a)?"+l),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/};function b(t){return(""+t).includes(".")&&1===parseFloat(t)}function f(t){return(""+t).includes("%")}function m(e){return!o.includes(e)&&!["#",...i].some(t=>e.includes(t))&&(!!["black","white"].includes(e)||["rgb(255, 255, 255)","rgb(0, 0, 0)"].every(o=>{n(t,{color:e});const s=r(t,"color");return n(t,{color:""}),s!==o}))}function d(t){return Boolean(g.CSS_UNIT.exec(String(t)))}function x(t,r){let e=t;if("number"==typeof t&&0===Math.min(t,0)&&1===Math.max(t,1))return t;b(t)&&(e="100%");const n=f(e);return e=360===r?parseFloat(e):Math.min(r,Math.max(0,parseFloat(e))),n&&(e=e*r/100),Math.abs(e-r)<1e-6?1:(e=360===r?(e<0?e%r+r:e%r)/r:e%r/r,e)}function S(t){let r=parseFloat(""+t);return(Number.isNaN(r)||r<0||r>1)&&(r=1),r}function p(t){return Math.min(1,Math.max(0,t))}function A(e){n(t,{color:e});const o=r(t,"color");return n(t,{color:""}),o}function $(t){return s(255*t).toString(16)}function w(t){return H(t)/255}function H(t){return parseInt(t,16)}function v(t){return 1===t.length?"0"+t:String(t)}function R(t,r,e){const n=Math.max(t,r,e),o=Math.min(t,r,e);let s=0,i=0;const a=(n+o)/2;if(n===o)i=0,s=0;else{const h=n-o;i=a>.5?h/(2-n-o):h/(n+o),n===t&&(s=(r-e)/h+(r<e?6:0)),n===r&&(s=(e-t)/h+2),n===e&&(s=(t-r)/h+4),s/=6}return{h:s,s:i,l:a}}function F(t,r,e){let n=e;return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*n*(r-t):n<.5?r:n<2/3?t+(r-t)*(2/3-n)*6:t}function T(t,r,e){let n=0,o=0,s=0;if(0===r)o=e,s=e,n=e;else{const i=e<.5?e*(1+r):e+r-e*r,a=2*e-i;n=F(a,i,t+1/3),o=F(a,i,t),s=F(a,i,t-1/3)}return{r:n,g:o,b:s}}function y(t,r,e){let n=0,o=0;const s=Math.min(t,r,e),i=Math.max(t,r,e),a=1-i;if(i===s)return{h:0,w:s,b:a};t===s?(n=r-e,o=3):(n=r===s?e-t:t-r,o=r===s?5:1);const h=(o-n/(i-s))/6;return{h:1===h?0:h,w:s,b:a}}function M(t,r,e){if(r+e>=1){const t=r/(r+e);return{r:t,g:t,b:t}}let{r:n,g:o,b:s}=T(t,1,.5);return[n,o,s]=[n,o,s].map(t=>t*(1-r-e)+r),{r:n,g:o,b:s}}function C(t,r,e){const n=Math.max(t,r,e),o=Math.min(t,r,e);let s=0;const i=n-o;return n===o?s=0:(t===n&&(s=(r-e)/i+(r<e?6:0)),r===n&&(s=(e-t)/i+2),e===n&&(s=(t-r)/i+4),s/=6),{h:s,s:0===n?0:i/n,v:n}}function E(t,r,e){const n=6*t,o=r,s=e,i=Math.floor(n),a=n-i,h=s*(1-o),u=s*(1-a*o),c=s*(1-(1-a)*o),l=i%6;return{r:[s,u,h,h,c,s][l],g:[c,s,s,u,h,h][l],b:[h,h,c,s,s,u][l]}}function N(t,r,e,n){const o=[v(s(t).toString(16)),v(s(r).toString(16)),v(s(e).toString(16))];return n&&o[0].charAt(0)===o[0].charAt(1)&&o[1].charAt(0)===o[1].charAt(1)&&o[2].charAt(0)===o[2].charAt(1)?o[0].charAt(0)+o[1].charAt(0)+o[2].charAt(0):o.join("")}function I(t,r,e,n,o){const i=[v(s(t).toString(16)),v(s(r).toString(16)),v(s(e).toString(16)),v($(n))];return o&&i[0].charAt(0)===i[0].charAt(1)&&i[1].charAt(0)===i[1].charAt(1)&&i[2].charAt(0)===i[2].charAt(1)&&i[3].charAt(0)===i[3].charAt(1)?i[0].charAt(0)+i[1].charAt(0)+i[2].charAt(0)+i[3].charAt(0):i.join("")}function j(t){let r=t.trim().toLowerCase();if(0===r.length)return{r:0,g:0,b:0,a:1};if(m(r))r=A(r);else if(o.includes(r)){return{r:0,g:0,b:0,a:"transparent"===r?0:1,format:"rgb",ok:!0}}let[,e,n,s,i]=g.rgb.exec(r)||[];return e&&n&&s?{r:e,g:n,b:s,a:void 0!==i?i:1,format:"rgb"}:([,e,n,s,i]=g.hsl.exec(r)||[],e&&n&&s?{h:e,s:n,l:s,a:void 0!==i?i:1,format:"hsl"}:([,e,n,s,i]=g.hsv.exec(r)||[],e&&n&&s?{h:e,s:n,v:s,a:void 0!==i?i:1,format:"hsv"}:([,e,n,s,i]=g.hwb.exec(r)||[],e&&n&&s?{h:e,w:n,b:s,a:void 0!==i?i:1,format:"hwb"}:([,e,n,s,i]=g.hex8.exec(r)||[],e&&n&&s&&i?{r:H(e),g:H(n),b:H(s),a:w(i),format:"hex"}:([,e,n,s]=g.hex6.exec(r)||[],e&&n&&s?{r:H(e),g:H(n),b:H(s),format:"hex"}:([,e,n,s,i]=g.hex4.exec(r)||[],e&&n&&s&&i?{r:H(e+e),g:H(n+n),b:H(s+s),a:w(i+i),format:"hex"}:([,e,n,s]=g.hex3.exec(r)||[],!!(e&&n&&s)&&{r:H(e+e),g:H(n+n),b:H(s+s),format:"hex"})))))))}function k(t){let r={r:0,g:0,b:0},e=t,n=1,o=null,s=null,a=null,h=null,u=null,c=null,l=null,g=null,b=!1;const m="object"==typeof e&&e.format;let p=m&&i.includes(m)?m:"rgb";return"string"==typeof t&&(e=j(t),e&&(b=!0)),"object"==typeof e&&(d(e.r)&&d(e.g)&&d(e.b)&&(({r:l,g:g,b:u}=e),[l,g,u]=[l,g,u].map(t=>x(t,f(t)?100:255)),r={r:l,g:g,b:u},b=!0,p=e.format||"rgb"),d(e.h)&&d(e.s)&&d(e.v)&&(({h:c,s:o,v:s}=e),c=x(c,360),o=x(o,100),s=x(s,100),r=E(c,o,s),b=!0,p="hsv"),d(e.h)&&d(e.s)&&d(e.l)&&(({h:c,s:o,l:a}=e),c=x(c,360),o=x(o,100),a=x(a,100),r=T(c,o,a),b=!0,p="hsl"),d(e.h)&&d(e.w)&&d(e.b)&&(({h:c,w:h,b:u}=e),c=x(c,360),h=x(h,100),u=x(u,100),r=M(c,h,u),b=!0,p="hwb"),d(e.a)&&(n=e.a,n=f(""+n)||parseFloat(n)>1?x(n,100):n)),void 0===e&&(b=!0),{ok:b,format:p,r:r.r,g:r.g,b:r.b,a:S(n)}}class _{constructor(t,r){let e=t;const n=r&&i.includes(r)?r:"";e instanceof _&&(e=k(e));const{r:o,g:s,b:a,a:h,ok:u,format:c}=k(e);this.originalInput=t,this.r=o,this.g=s,this.b=a,this.a=h,this.ok=u,this.format=n||c}get isValid(){return this.ok}get isDark(){return this.brightness<120}get luminance(){const{r:t,g:r,b:e}=this;let n=0,o=0,s=0;return n=t<=.03928?t/12.92:((t+.055)/1.055)**2.4,o=r<=.03928?r/12.92:((r+.055)/1.055)**2.4,s=e<=.03928?e/12.92:((e+.055)/1.055)**2.4,.2126*n+.7152*o+.0722*s}get brightness(){const{r:t,g:r,b:e}=this.toRgb();return(299*t+587*r+114*e)/1e3}toRgb(){let{r:t,g:r,b:e,a:n}=this;return[t,r,e]=[t,r,e].map(t=>s(255*t*100)/100),n=s(100*n)/100,{r:t,g:r,b:e,a:n}}toRgbString(){const{r:t,g:r,b:e,a:n}=this.toRgb(),[o,i,a]=[t,r,e].map(s);return 1===n?`rgb(${o}, ${i}, ${a})`:`rgba(${o}, ${i}, ${a}, ${n})`}toRgbCSS4String(){const{r:t,g:r,b:e,a:n}=this.toRgb(),[o,i,a]=[t,r,e].map(s);return`rgb(${o} ${i} ${a}${1===n?"":` / ${s(100*n)}%`})`}toHex(t){const{r:r,g:e,b:n,a:o}=this.toRgb();return 1===o?N(r,e,n,t):I(r,e,n,o,t)}toHexString(t){return"#"+this.toHex(t)}toHex8(t){const{r:r,g:e,b:n,a:o}=this.toRgb();return I(r,e,n,o,t)}toHex8String(t){return"#"+this.toHex8(t)}toHsv(){const{r:t,g:r,b:e,a:n}=this,{h:o,s:s,v:i}=C(t,r,e);return{h:o,s:s,v:i,a:n}}toHsl(){const{r:t,g:r,b:e,a:n}=this,{h:o,s:s,l:i}=R(t,r,e);return{h:o,s:s,l:i,a:n}}toHslString(){let{h:t,s:r,l:e,a:n}=this.toHsl();return t=s(360*t),r=s(100*r),e=s(100*e),n=s(100*n)/100,1===n?`hsl(${t}, ${r}%, ${e}%)`:`hsla(${t}, ${r}%, ${e}%, ${n})`}toHslCSS4String(){let{h:t,s:r,l:e,a:n}=this.toHsl();t=s(360*t),r=s(100*r),e=s(100*e),n=s(100*n);return`hsl(${t}deg ${r}% ${e}%${n<100?` / ${s(n)}%`:""})`}toHwb(){const{r:t,g:r,b:e,a:n}=this,{h:o,w:s,b:i}=y(t,r,e);return{h:o,w:s,b:i,a:n}}toHwbString(){let{h:t,w:r,b:e,a:n}=this.toHwb();t=s(360*t),r=s(100*r),e=s(100*e),n=s(100*n);return`hwb(${t}deg ${r}% ${e}%${n<100?` / ${s(n)}%`:""})`}setAlpha(t){return"number"!=typeof t||(this.a=S(t)),this}saturate(t){if("number"!=typeof t)return this;const{h:r,s:n,l:o}=this.toHsl(),{r:s,g:i,b:a}=T(r,p(n+t/100),o);return e(this,{r:s,g:i,b:a}),this}desaturate(t){return"number"==typeof t?this.saturate(-t):this}greyscale(){return this.saturate(-100)}lighten(t){if("number"!=typeof t)return this;const{h:r,s:n,l:o}=this.toHsl(),{r:s,g:i,b:a}=T(r,n,p(o+t/100));return e(this,{r:s,g:i,b:a}),this}darken(t){return"number"==typeof t?this.lighten(-t):this}spin(t){if("number"!=typeof t)return this;const{h:r,s:n,l:o}=this.toHsl(),{r:s,g:i,b:a}=T(p((360*r+t)%360/360),n,o);return e(this,{r:s,g:i,b:a}),this}clone(){return new _(this)}toString(t){const{format:r}=this;return"hex"===r?this.toHexString(t):"hsl"===r?this.toHslString():"hwb"===r?this.toHwbString():this.toRgbString()}}return e(_,{ANGLES:"deg|rad|grad|turn",CSS_ANGLE:a,CSS_INTEGER:"[-\\+]?\\d+%?",CSS_NUMBER:"[-\\+]?\\d*\\.\\d+%?",CSS_UNIT:h,CSS_UNIT2:u,PERMISSIVE_MATCH:l,matchers:g,isOnePointZero:b,isPercentage:f,isValidCSSUnit:d,isColorName:m,pad2:v,clamp01:p,bound01:x,boundAlpha:S,getRGBFromName:A,convertHexToDecimal:w,convertDecimalToHex:$,rgbToHsl:R,rgbToHex:N,rgbToHsv:C,rgbToHwb:y,rgbaToHex:I,hslToRgb:T,hsvToRgb:E,hueToRgb:F,hwbToRgb:M,parseIntFromHex:H,stringInputToObject:j,inputToRGB:k,roundPart:s,getElementStyle:r,setElementStyle:n,ObjectAssign:e}),_}));
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@thednp/color-picker",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.2alpha4",
|
4
4
|
"description": "Modern Color Picker Web Component",
|
5
5
|
"main": "dist/js/color-picker.min.js",
|
6
6
|
"module": "dist/js/color-picker.esm.js",
|
@@ -18,9 +18,11 @@
|
|
18
18
|
"registry": "https://registry.npmjs.org/"
|
19
19
|
},
|
20
20
|
"scripts": {
|
21
|
-
"instrument": "npx nyc instrument --
|
21
|
+
"instrument": "npx nyc instrument --compact=false src/js cypress/instrumented",
|
22
22
|
"test": "npm run instrument && npx cypress run",
|
23
|
-
"
|
23
|
+
"cypress": "npm run instrument && npx cypress open",
|
24
|
+
"coverage:report": "npx nyc report --exclude=src/js/util --reporter=lcov --reporter=json --reporter=text --reporter=json-summary",
|
25
|
+
"coverage:badge": "npx --check-coverage update-badge",
|
24
26
|
"fix:js": "eslint src/ --config .eslintrc --fix",
|
25
27
|
"lint:js": "eslint src/ --config .eslintrc",
|
26
28
|
"fix:css": "stylelint --config .stylelintrc.json -s --fix scss \"src/scss/*.scss\"",
|
@@ -85,7 +87,8 @@
|
|
85
87
|
"@rollup/plugin-json": "^4.1.0",
|
86
88
|
"@rollup/plugin-node-resolve": "^7.1.3",
|
87
89
|
"babel-plugin-istanbul": "^6.1.1",
|
88
|
-
"
|
90
|
+
"check-code-coverage": "^1.10.0",
|
91
|
+
"cypress": "^9.5.4",
|
89
92
|
"esbuild": "^0.14.30",
|
90
93
|
"eslint": "^7.22.0",
|
91
94
|
"eslint-config-airbnb-base": "^14.2.1",
|
package/src/js/color-palette.js
CHANGED
@@ -29,26 +29,23 @@ export default class ColorPalette {
|
|
29
29
|
} else if (args.length === 2) {
|
30
30
|
[hueSteps, lightSteps] = args;
|
31
31
|
if ([hueSteps, lightSteps].some((n) => n < 1)) {
|
32
|
-
throw TypeError('ColorPalette:
|
32
|
+
throw TypeError('ColorPalette: both arguments must be higher than 0.');
|
33
33
|
}
|
34
|
-
} else {
|
35
|
-
throw TypeError('ColorPalette requires minimum 2 arguments');
|
36
34
|
}
|
37
35
|
|
38
|
-
/** @type {
|
36
|
+
/** @type {*} */
|
39
37
|
const colors = [];
|
40
|
-
|
41
38
|
const hueStep = 360 / hueSteps;
|
42
39
|
const half = roundPart((lightSteps - (lightSteps % 2 ? 1 : 0)) / 2);
|
43
|
-
const
|
40
|
+
const steps1To13 = [0.25, 0.2, 0.15, 0.11, 0.09, 0.075];
|
41
|
+
const lightSets = [[1, 2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13]];
|
42
|
+
const closestSet = lightSets.find((set) => set.includes(lightSteps));
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
lightStep =
|
48
|
-
|
49
|
-
|
50
|
-
lightStep = [12, 13].includes(lightSteps) ? 0.075 : lightStep;
|
51
|
-
lightStep = lightSteps > 13 ? estimatedStep : lightStep;
|
44
|
+
// find a lightStep that won't go beyond black and white
|
45
|
+
// something within the [10-90] range of lightness
|
46
|
+
const lightStep = closestSet
|
47
|
+
? steps1To13[lightSets.indexOf(closestSet)]
|
48
|
+
: (100 / (lightSteps + (lightSteps % 2 ? 0 : 1)) / 100);
|
52
49
|
|
53
50
|
// light tints
|
54
51
|
for (let i = 1; i < half + 1; i += 1) {
|
@@ -5,7 +5,7 @@ import setAttribute from 'shorter-js/src/attr/setAttribute';
|
|
5
5
|
import getAttribute from 'shorter-js/src/attr/getAttribute';
|
6
6
|
|
7
7
|
import Color from './color';
|
8
|
-
import ColorPicker
|
8
|
+
import ColorPicker from './color-picker';
|
9
9
|
import ColorPalette from './color-palette';
|
10
10
|
import Version from './util/version';
|
11
11
|
|
@@ -15,90 +15,82 @@ let CPID = 0;
|
|
15
15
|
* `ColorPickerElement` Web Component.
|
16
16
|
* @example
|
17
17
|
* <label for="UNIQUE_ID">Label</label>
|
18
|
-
* <color-picker
|
19
|
-
* <input id="UNIQUE_ID"
|
18
|
+
* <color-picker>
|
19
|
+
* <input id="UNIQUE_ID" value="red" format="hex" class="color-preview btn-appearance">
|
20
20
|
* </color-picker>
|
21
|
+
* // or
|
22
|
+
* <label for="UNIQUE_ID">Label</label>
|
23
|
+
* <color-picker data-id="UNIQUE_ID" data-value="red" data-format="hex"></color-picker>
|
21
24
|
*/
|
22
25
|
class ColorPickerElement extends HTMLElement {
|
23
26
|
constructor() {
|
24
27
|
super();
|
25
|
-
/** @type {boolean} */
|
26
|
-
this.isDisconnected = true;
|
27
28
|
this.attachShadow({ mode: 'open' });
|
28
29
|
}
|
29
30
|
|
30
31
|
/**
|
31
32
|
* Returns the current color value.
|
32
|
-
* @returns {string
|
33
|
+
* @returns {string | undefined}
|
33
34
|
*/
|
34
|
-
get value() { return this.input
|
35
|
+
get value() { return this.input && this.input.value; }
|
35
36
|
|
36
37
|
connectedCallback() {
|
37
|
-
if (this.
|
38
|
-
if (this.isDisconnected) {
|
39
|
-
this.isDisconnected = false;
|
40
|
-
}
|
41
|
-
return;
|
42
|
-
}
|
38
|
+
if (this.input) return;
|
43
39
|
|
44
|
-
|
40
|
+
let [input] = getElementsByTagName('input', this);
|
41
|
+
const value = (input && getAttribute(input, 'value')) || getAttribute(this, 'data-value') || '#fff';
|
42
|
+
const format = (input && getAttribute(input, 'format')) || getAttribute(this, 'data-format') || 'rgb';
|
43
|
+
let id = (input && getAttribute(input, 'id')) || getAttribute(this, 'data-id');
|
45
44
|
|
46
|
-
if (!
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
if (!id) {
|
46
|
+
id = `color-picker-${format}-${CPID}`;
|
47
|
+
CPID += 1;
|
48
|
+
}
|
49
|
+
|
50
|
+
if (!input) {
|
51
|
+
input = createElement({
|
51
52
|
tagName: 'input',
|
52
53
|
type: 'text',
|
53
54
|
className: 'color-preview btn-appearance',
|
54
55
|
});
|
55
|
-
let id = getAttribute(this, 'data-id');
|
56
|
-
if (!id) {
|
57
|
-
id = `color-picker-${format}-${CPID}`;
|
58
|
-
CPID += 1;
|
59
|
-
}
|
60
|
-
|
61
|
-
const labelElement = createElement({ tagName: 'label', innerText: label || 'Color Picker' });
|
62
|
-
this.before(labelElement);
|
63
|
-
setAttribute(labelElement, 'for', id);
|
64
|
-
setAttribute(newInput, 'id', id);
|
65
|
-
setAttribute(newInput, 'name', id);
|
66
|
-
setAttribute(newInput, 'autocomplete', 'off');
|
67
|
-
setAttribute(newInput, 'spellcheck', 'false');
|
68
|
-
setAttribute(newInput, 'value', value);
|
69
|
-
this.append(newInput);
|
70
|
-
}
|
71
56
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
this.input
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
57
|
+
setAttribute(input, 'id', id);
|
58
|
+
setAttribute(input, 'name', id);
|
59
|
+
setAttribute(input, 'autocomplete', 'off');
|
60
|
+
setAttribute(input, 'spellcheck', 'false');
|
61
|
+
setAttribute(input, 'value', value);
|
62
|
+
this.append(input);
|
63
|
+
}
|
64
|
+
/** @type {HTMLInputElement} */
|
65
|
+
// @ts-ignore - `HTMLInputElement` is `HTMLElement`
|
66
|
+
this.input = input;
|
82
67
|
|
83
|
-
|
84
|
-
|
85
|
-
}
|
68
|
+
// @ts-ignore - `HTMLInputElement` is `HTMLElement`
|
69
|
+
this.colorPicker = new ColorPicker(input);
|
86
70
|
|
87
|
-
|
88
|
-
|
71
|
+
// @ts-ignore - `shadowRoot` is defined in the constructor
|
72
|
+
this.shadowRoot.append(createElement('slot'));
|
89
73
|
}
|
90
74
|
|
75
|
+
/** @this {ColorPickerElement} */
|
91
76
|
disconnectedCallback() {
|
92
|
-
|
93
|
-
|
77
|
+
const { input, colorPicker, shadowRoot } = this;
|
78
|
+
if (colorPicker) colorPicker.dispose();
|
79
|
+
if (input) input.remove();
|
80
|
+
if (shadowRoot) shadowRoot.innerHTML = '';
|
81
|
+
|
82
|
+
ObjectAssign(this, {
|
83
|
+
colorPicker: undefined,
|
84
|
+
input: undefined,
|
85
|
+
});
|
94
86
|
}
|
95
87
|
}
|
96
88
|
|
97
89
|
ObjectAssign(ColorPickerElement, {
|
98
90
|
Color,
|
99
91
|
ColorPicker,
|
100
|
-
ColorPalette,
|
101
|
-
getInstance:
|
92
|
+
ColorPalette, // @ts-ignore
|
93
|
+
getInstance: ColorPicker.getInstance,
|
102
94
|
Version,
|
103
95
|
});
|
104
96
|
|