diff --git a/.gitattributes b/.gitattributes
old mode 100644
new mode 100755
diff --git a/.github/source/LICENSE.txt b/.github/source/LICENSE.txt
old mode 100644
new mode 100755
diff --git a/.github/source/_index.pug b/.github/source/_index.pug
old mode 100644
new mode 100755
diff --git a/.github/source/index.css.scss b/.github/source/index.css.scss
old mode 100644
new mode 100755
index 21573fc..b90e096
--- a/.github/source/index.css.scss
+++ b/.github/source/index.css.scss
@@ -1,105 +1,66 @@
-$color: #000;
-$size: 12px;
+$name: 'color-picker';
-.color-picker {
- &,
- &::before,
- &::after,
- *,
- *::before,
- *::after {
- box-sizing: border-box;
- }
+:root {
+ --color-#{$name}__controls: #000;
+ --fill-#{$name}__controls: 0 0;
+ --height-#{$name}__controls: 10em;
+ --shadow-#{$name}__dialog: 1px 3px 6px rgba(0, 0, 0, .5);
+ --size-#{$name}__controls: 12px;
+ --stroke-#{$name}__controls: #000;
+ --width-#{$name}__control--a: 1.5em;
+ --width-#{$name}__control--h: 1.5em;
+ --width-#{$name}__control--s\/v: 10em;
}
-.color-picker {
- position: absolute;
- top: 0;
- left: 0;
- z-index: 9999;
- box-shadow: 1px 3px 6px rgba(0, 0, 0, .5);
- > div {
- display: flex;
- height: 10em;
- border: 1px solid $color;
- color: $color;
- * {
- border-color: inherit;
- color: inherit;
- }
- }
- i {
- font: inherit;
- font-size: $size; /* Measure the color picker control size by measuring the text size */
- }
- &\:a,
- &\:h,
- &\:sv {
- background-size: 100% 100%;
- position: relative;
- -webkit-touch-callout: none;
- -webkit-user-select: none;
+.#{$name}__control {
+ &--a,
+ &--h,
+ &--s\/v {
-moz-user-select: none;
-ms-user-select: none;
- user-select: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-tap-highlight-color: transparent;
+ -webkit-touch-callout: none;
+ -webkit-user-select: none;
+ background-size: 100% 100%;
+ position: relative;
+ user-select: none;
div {
- position: absolute;
- top: 0;
- right: 0;
bottom: 0;
left: 0;
+ position: absolute;
+ right: 0;
+ top: 0;
}
}
- &\:a,
- &\:h {
- width: 1.5em;
+ &--a,
+ &--h {
border-left: 1px solid;
cursor: ns-resize;
overflow: hidden;
- i {
- display: block;
- height: .5em;
- position: absolute;
- top: -.25em;
- right: 0;
- left: 0;
- z-index: 2;
- &::before {
- display: block;
- content: "";
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- border:.25em solid;
- border-top-color: transparent;
- border-bottom-color: transparent;
- }
- }
}
- &\:a {
+ &--a {
+ width: var(--width-#{$name}__control--a);
div {
z-index: 2;
+ div {
background-image: linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%, #ddd 100%), linear-gradient(45deg, #ddd 25%, #fff 25%, #fff 75%, #ddd 75%, #ddd 100%);
- background-size: .5em .5em;
background-position: 0 0, .25em .25em;
+ background-size: .5em .5em;
z-index: 1;
}
}
}
- &\:h {
+ &--h {
+ width: var(--width-#{$name}__control--a);
div {
background-image: linear-gradient(to top, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
}
}
- &\:sv {
- width: 10em;
+ &--s\/v {
cursor: crosshair;
overflow: hidden;
+ width: var(--width-#{$name}__control--s\/v);
div {
+ div {
background-image: linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
@@ -108,26 +69,86 @@ $size: 12px;
}
}
}
- i {
+ }
+}
+
+.#{$name}__controls {
+ background: var(--fill-#{$name}__controls);
+ border-radius: var(--arc-#{$name}__controls);
+ border: 1px solid;
+ border-color: var(--stroke-#{$name}__controls);
+ color: var(--color-#{$name}__controls);
+ display: flex;
+ height: var(--height-#{$name}__controls);
+ overflow: hidden;
+}
+
+.#{$name}__dialog {
+ box-shadow: var(--shadow-#{$name}__dialog);
+ &,
+ &::before,
+ &::after,
+ *,
+ *::before,
+ *::after {
+ box-sizing: border-box;
+ font: inherit;
+ }
+}
+
+.#{$name}__dialog {
+ left: 0;
+ position: absolute;
+ top: 0;
+ z-index: 9999;
+}
+
+.#{$name}__cursor {
+ border-color: inherit;
+ color: inherit;
+ font: inherit;
+ font-size: var(--size-#{$name}__controls); /* Measure the color picker control size by measuring the text size */
+ &--a,
+ &--h {
+ display: block;
+ height: .5em;
+ left: 0;
+ position: absolute;
+ right: 0;
+ top: -.25em;
+ z-index: 2;
+ &::before {
+ border:.25em solid;
+ border-bottom-color: transparent;
+ border-top-color: transparent;
+ bottom: 0;
+ content: "";
display: block;
- width: .75em;
- height: .75em;
+ left: 0;
position: absolute;
- top: -.375em;
- right: -.375em;
- z-index: 2;
- &::before {
- display: block;
- content: "";
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- border: 1px solid #fff;
- border-radius: 100%;
- box-shadow: 0 0 2px #000;
- }
+ right: 0;
+ top: 0;
}
}
-}
+ &--s\/v {
+ display: block;
+ height: .75em;
+ position: absolute;
+ right: -.375em;
+ top: -.375em;
+ width: .75em;
+ z-index: 2;
+ &::before {
+ border-radius: 100%;
+ border: 1px solid #fff;
+ bottom: 0;
+ box-shadow: 0 0 2px #000;
+ content: "";
+ display: block;
+ left: 0;
+ position: absolute;
+ right: 0;
+ top: 0;
+ }
+ }
+}
\ No newline at end of file
diff --git a/.github/source/index.html.pug b/.github/source/index.html.pug
old mode 100644
new mode 100755
index f03ca5b..9370beb
--- a/.github/source/index.html.pug
+++ b/.github/source/index.html.pug
@@ -64,7 +64,7 @@ block style
| text-align: left;
| vertical-align: top;
| }
- | body > p:first-child {
+ | [role='alert'] {
| background: #ffa;
| border: 1px dashed;
| margin-top: 0;
@@ -72,7 +72,7 @@ block style
| }
block content
- p Do you like this project? Please support my #[a(href='https://github.com/mecha-cms') Mecha CMS] project too. Thank you!
+ p(role='alert') Do you like this project? Please support my #[a(href='https://github.com/mecha-cms') Mecha CMS] project too. Thank you!
header
h1= title
p Color Picker is a simple JavaScript application that aims to provide custom color picker feature to the web with the most basic appearance and usability.
diff --git a/.github/source/index.js.mjs b/.github/source/index.js.mjs
old mode 100644
new mode 100755
index c524162..04c9e0a
--- a/.github/source/index.js.mjs
+++ b/.github/source/index.js.mjs
@@ -125,7 +125,9 @@ function CP(source, state = {}) {
return [0, 0, 0, 1]; // Default to black
}
- let className = state['class'],
+ let classNameB = state['class'],
+ classNameE = classNameB + '__',
+ classNameM = classNameB + '--',
doEnter,
doExit,
doFit,
@@ -138,31 +140,43 @@ function CP(source, state = {}) {
theData = RGB2HSV(theColor),
self = setElement('div', {
- 'class': className
+ 'class': classNameE + 'dialog',
+ 'role': 'dialog'
}),
- C = setElement('div'),
+ C = setElement('div', {
+ 'class': classNameE + 'controls'
+ }),
+ classNameControl = classNameE + 'control',
+ classNameCursor = classNameE + 'cursor',
+
SV = setElement('div', {
- 'class': className + ':sv'
+ 'class': classNameControl + ' ' + classNameControl + '--s/v'
}),
H = setElement('div', {
- 'class': className + ':h'
+ 'class': classNameControl + ' ' + classNameControl + '--h'
}),
A = setElement('div', {
- 'class': className + ':a'
+ 'class': classNameControl + ' ' + classNameControl + '--a'
}),
SVColor = setElement('div'),
SVSaturation = setElement('div'),
SVValue = setElement('div'),
- SVCursor = setElement('i'),
+ SVCursor = setElement('i', {
+ 'class': classNameCursor + ' ' + classNameCursor + '--s/v'
+ }),
HColor = setElement('div'),
- HCursor = setElement('i'),
+ HCursor = setElement('i', {
+ 'class': classNameCursor + ' ' + classNameCursor + '--h'
+ }),
AColor = setElement('div'),
APattern = setElement('div'),
- ACursor = setElement('i'),
+ ACursor = setElement('i', {
+ 'class': classNameCursor + ' ' + classNameCursor + '--a'
+ }),
SVStarting = 0,
HStarting = 0,
@@ -392,7 +406,7 @@ function CP(source, state = {}) {
return $; // Already ejected
}
delete source[name];
- letClass(source, className + '-source');
+ letClass(source, classNameE + 'source');
offEvents(EVENTS_DOWN, source, doClick);
return doExit(), fire('pop', theColor);
};
@@ -408,7 +422,7 @@ function CP(source, state = {}) {
return doSetColor(), $;
};
- setClass(source, className + '-source');
+ setClass(source, classNameE + 'source');
} doApply(1);
diff --git a/.github/source/test.html.pug b/.github/source/test.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/test/disabled.html.pug b/.github/source/test/disabled.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/test/fit.html.pug b/.github/source/test/fit.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/test/hooks.html.pug b/.github/source/test/hooks.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/test/picker.html.pug b/.github/source/test/picker.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/test/pop.html.pug b/.github/source/test/pop.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/test/size.html.pug b/.github/source/test/size.html.pug
old mode 100644
new mode 100755
index 094908f..0d8f8f9
--- a/.github/source/test/size.html.pug
+++ b/.github/source/test/size.html.pug
@@ -41,11 +41,11 @@ block content
p By default, color picker size will follow the container’s text size; the container that bounds to the color picker panel.
pre: code
| /* To change the color picker size */
- | .color-picker {
+ | .color-picker__controls {
| font-size: 20px;
| }
|
- | /* To change the color picker control’s size */
- | .color-picker i {
- | font-size: 15px;
+ | /* To change the color picker cursor’s size */
+ | .color-picker__cursor {
+ | font-size: 20px;
| }
\ No newline at end of file
diff --git a/.github/source/tweak/alpha.html.pug b/.github/source/tweak/alpha.html.pug
old mode 100644
new mode 100755
index 4f9c4e2..6daa0c7
--- a/.github/source/tweak/alpha.html.pug
+++ b/.github/source/tweak/alpha.html.pug
@@ -7,7 +7,7 @@ block state
block style
style
- | .color-picker.no-alpha .color-picker\:a {
+ | .color-picker__dialog--no-alpha .color-picker__control--a {
| display: none;
| }
@@ -18,7 +18,7 @@ block script
| return;
| }
| picker.noAlpha = true;
- | picker.self.classList.add('no-alpha');
+ | picker.self.classList.add(picker.state.class + '__dialog--no-alpha');
| picker.on('change', function(r, g, b) {
| this.source.value = this.color(r, g, b, 1);
| });
diff --git a/.github/source/tweak/button.html.pug b/.github/source/tweak/button.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/tweak/close.html.pug b/.github/source/tweak/close.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/tweak/color.hex.html.pug b/.github/source/tweak/color.hex.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/tweak/color.name.html.pug b/.github/source/tweak/color.name.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/tweak/color.rgba.html.pug b/.github/source/tweak/color.rgba.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/tweak/events.html.pug b/.github/source/tweak/events.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/tweak/input.html.pug b/.github/source/tweak/input.html.pug
old mode 100644
new mode 100755
index b60b329..0d52723
--- a/.github/source/tweak/input.html.pug
+++ b/.github/source/tweak/input.html.pug
@@ -8,7 +8,7 @@ block state
block style
style
| /* HTML5 color input does not support alpha channel */
- | .color-picker\:a {
+ | .color-picker__control--a {
| display: none;
| }
diff --git a/.github/source/tweak/keyboard.html.pug b/.github/source/tweak/keyboard.html.pug
old mode 100644
new mode 100755
index 10a48d9..a831883
--- a/.github/source/tweak/keyboard.html.pug
+++ b/.github/source/tweak/keyboard.html.pug
@@ -8,9 +8,9 @@ block state
block style
style
| /* Fake focus state */
- | .color-picker.focus\:a .color-picker\:a div,
- | .color-picker.focus\:h .color-picker\:h div,
- | .color-picker.focus\:sv .color-picker\:sv div {
+ | .color-picker--focus--a .color-picker__control--a div,
+ | .color-picker--focus--h .color-picker__control--h div,
+ | .color-picker--focus--s\/v .color-picker__control--s\/v div {
| outline: 2px solid rgba(0, 0, 255, .5);
| outline-offset: -2px;
| }
@@ -71,7 +71,8 @@ block script
| // 1: h
| // 2: a
| tabIndex = 0;
- | let source = picker.source,
+ | let classNameM = picker.state.class + '--',
+ | source = picker.source,
| self = picker.self,
| controls = self.firstChild.children,
| a = controls[2],
@@ -86,9 +87,9 @@ block script
| tabIndex = 1;
| hh = h.offsetHeight;
| hy = parseFloat(hCursor.style.top) + (ch = hCursor.offsetHeight / 2);
- | self.classList.add('focus:h');
- | self.classList.remove('focus:a');
- | self.classList.remove('focus:sv');
+ | self.classList.add(classNameM + 'focus--h');
+ | self.classList.remove(classNameM + 'focus--a');
+ | self.classList.remove(classNameM + 'focus--s/v');
| },
| svFocus = () => {
| tabIndex = 0;
@@ -96,17 +97,17 @@ block script
| sx = parseFloat(svCursor.style.right) + (cw = svCursor.offsetWidth / 2);
| vh = sv.offsetHeight;
| vy = parseFloat(svCursor.style.top) + (ch = svCursor.offsetHeight / 2);
- | self.classList.add('focus:sv');
- | self.classList.remove('focus:a');
- | self.classList.remove('focus:h');
+ | self.classList.add(classNameM + 'focus--s/v');
+ | self.classList.remove(classNameM + 'focus--a');
+ | self.classList.remove(classNameM + 'focus--h');
| },
| aFocus = () => {
| tabIndex = 2;
| ah = a.offsetHeight;
| ay = parseFloat(aCursor.style.top) + (ch = aCursor.offsetHeight / 2);
- | self.classList.add('focus:a');
- | self.classList.remove('focus:h');
- | self.classList.remove('focus:sv');
+ | self.classList.add(classNameM + 'focus--a');
+ | self.classList.remove(classNameM + 'focus--h');
+ | self.classList.remove(classNameM + 'focus--s/v');
| };
| picker.on('enter', () => {
| ['touchstart', 'mousedown'].forEach(e => {
diff --git a/.github/source/tweak/live.html.pug b/.github/source/tweak/live.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/tweak/picker-color.html.pug b/.github/source/tweak/picker-color.html.pug
old mode 100644
new mode 100755
index 8cb15ac..9a97ea8
--- a/.github/source/tweak/picker-color.html.pug
+++ b/.github/source/tweak/picker-color.html.pug
@@ -7,41 +7,42 @@ block state
block style
style
- | .color-pickers {
- | display: block;
- | border: 1px solid #000;
- | border-top-width: 0;
- | overflow: hidden;
- | }
- |
- | .color-pickers span {
+ | .color-picker__color {
| display: block;
| float: left;
| width: 10%;
| height: 1.25em;
| cursor: pointer;
| }
+ |
+ | .color-picker__colors {
+ | display: block;
+ | border: 1px solid #000;
+ | border-top-width: 0;
+ | overflow: hidden;
+ | }
block script
script
- | function preDefineColorValues(picker, colors) {
+ | function preDefineColorValues(picker, pickers) {
| if (picker.hasColorPallete) {
| return;
| }
| picker.hasColorPallete = true;
- | let pane = document.createElement('span'), c;
- | for (let i = 0, j = colors.length; i < j; ++i) {
- | c = document.createElement('span');
- | c.title = '#' + colors[i];
- | c.style.backgroundColor = '#' + colors[i];
- | c.addEventListener('click', function(e) {
+ | let color, colors = document.createElement('span');
+ | for (let i = 0, j = pickers.length; i < j; ++i) {
+ | color = document.createElement('span');
+ | color.className = picker.state.class + '__color';
+ | color.style.backgroundColor = '#' + pickers[i];
+ | color.title = '#' + pickers[i];
+ | color.addEventListener('click', function(e) {
| picker.set.apply(picker, CP.HEX(this.title));
| e.stopPropagation();
| });
- | pane.appendChild(c);
+ | colors.appendChild(color);
| }
- | pane.className = 'color-pickers';
- | picker.self.appendChild(pane);
+ | colors.className = picker.state.class + '__colors';
+ | picker.self.appendChild(colors);
| }
|
| const picker = new CP(document.querySelector('input'));
diff --git a/.github/source/tweak/picker-view-code.html.pug b/.github/source/tweak/picker-view-code.html.pug
old mode 100644
new mode 100755
index a5161f3..60e44d4
--- a/.github/source/tweak/picker-view-code.html.pug
+++ b/.github/source/tweak/picker-view-code.html.pug
@@ -7,7 +7,11 @@ block state
block style
style
- | .color-picker input {
+ | .color-picker__control--a {
+ | display: none;
+ | }
+ |
+ | .color-picker__input {
| box-sizing: border-box;
| display: block;
| width: 100%;
@@ -21,13 +25,9 @@ block style
| color: #000;
| }
|
- | .color-picker input:invalid {
+ | .color-picker__input:invalid {
| color: #f00;
| }
- |
- | .color-picker\:a {
- | display: none;
- | }
block script
script
@@ -37,6 +37,7 @@ block script
| }
| picker.hasColorInput = true;
| let code = document.createElement('input');
+ | code.className = picker.state.class + '__input';
| code.pattern = '^#([a-fA-F\\d]{3}){1,2}$';
| code.type = 'text';
| picker.self.appendChild(code);
diff --git a/.github/source/tweak/picker-view.html.pug b/.github/source/tweak/picker-view.html.pug
old mode 100644
new mode 100755
index 2d90c39..01e5d0f
--- a/.github/source/tweak/picker-view.html.pug
+++ b/.github/source/tweak/picker-view.html.pug
@@ -7,21 +7,22 @@ block state
block style
style
- | .color-view {
- | display: block;
- | border: 1px solid #000;
- | border-top-width: 0;
- | overflow: hidden;
- | }
- |
- | .color-view span {
+ | .color-picker--view {
+ | cursor: pointer;
| display: block;
| float: left;
- | width: 50%;
| height: 50px;
| line-height: 50px;
| text-align: center;
- | cursor: pointer;
+ | width: 50%;
+ | }
+ |
+ | .color-picker--views {
+ | border: 1px solid;
+ | border-color: var(--stroke-color-picker__controls);
+ | border-top-width: 0;
+ | display: block;
+ | overflow: hidden;
| }
block script
@@ -34,7 +35,9 @@ block script
| let box = document.createElement('span'),
| boxReset = document.createElement('span'),
| boxSubmit = document.createElement('span');
- | box.className = 'color-view';
+ | box.className = picker.state.class + '--views';
+ | boxReset.className = picker.state.class + '--view';
+ | boxSubmit.className = picker.state.class + '--view';
| box.appendChild(boxReset);
| box.appendChild(boxSubmit);
| boxReset.textContent = 'Reset';
diff --git a/.github/source/tweak/replace.html.pug b/.github/source/tweak/replace.html.pug
old mode 100644
new mode 100755
index de63555..351e3e8
--- a/.github/source/tweak/replace.html.pug
+++ b/.github/source/tweak/replace.html.pug
@@ -7,15 +7,16 @@ block state
block style
style
- | .color-box {
- | display: inline-block;
- | width: 30px;
- | height: 30px;
+ | .color-picker {
| border: 1px solid;
+ | border-color: var(--stroke-color-picker__controls);
| cursor: pointer;
+ | display: inline-block;
+ | height: 30px;
+ | width: 30px;
| }
|
- | .color-picker {
+ | .color-picker__dialog {
| margin-top: -1px;
| }
@@ -28,12 +29,12 @@ block script
| source.hasColorBox = true;
| let box = document.createElement('span'),
| color = source.value;
- | box.className = 'color-box';
| box.value = color; // Hacky :(
| box.style.backgroundColor = color;
| source.parentNode.insertBefore(box, source);
| source.type = 'hidden';
| const picker = new CP(box);
+ | box.className = picker.state.class;
| picker.on('change', function(r, g, b, a) {
| let color = this.color(r, g, b, a);
| source.value = color;
diff --git a/.github/source/tweak/scroll.html.pug b/.github/source/tweak/scroll.html.pug
old mode 100644
new mode 100755
diff --git a/.github/source/tweak/static.html.pug b/.github/source/tweak/static.html.pug
old mode 100644
new mode 100755
index d823b74..c032799
--- a/.github/source/tweak/static.html.pug
+++ b/.github/source/tweak/static.html.pug
@@ -7,12 +7,13 @@ block state
block style
style
- | .color-picker.is-static {
+ | .color-picker__dialog--static {
+ | box-shadow: none;
| display: inline-block;
- | position: static;
| left: 0 !important;
+ | position: static;
| top: 0 !important;
- | box-shadow: none;
+ | vertical-align: middle;
| }
block script
@@ -29,7 +30,7 @@ block script
| this.source.value = this.color(r, g, b, a);
| });
| // Add a `is-static` class to the color picker panel
- | picker.self.classList.add('is-static');
+ | picker.self.classList.add(picker.state.class + '__dialog--static');
| // Put color picker panel to `container`
| picker.enter(container);
| }
diff --git a/.github/source/tweak/transition.html.pug b/.github/source/tweak/transition.html.pug
old mode 100644
new mode 100755
diff --git a/.github/workflows/npm.yml b/.github/workflows/npm.yml
old mode 100644
new mode 100755
diff --git a/.gitignore b/.gitignore
old mode 100644
new mode 100755
diff --git a/LICENSE b/LICENSE
index 6fbf1fd..c4fd36e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright © 2021 Taufik Nurrohman Do you like this project? Please support my Mecha CMS project too. Thank you! Do you like this project? Please support my Mecha CMS project too. Thank you! Color Picker is a simple JavaScript application that aims to provide custom color picker feature to the web with the most basic appearance and usability.Color Picker 2.3.2
+ Color Picker 2.4.0
License
diff --git a/test/hooks.html b/test/hooks.html
index 2fd8223..5bc3916 100644
--- a/test/hooks.html
+++ b/test/hooks.html
@@ -16,11 +16,9 @@