Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Colorpicker library used in page builder

givanzfe646543f32a
diff --git a/public/js/libs/coloris/coloris.css b/public/js/libs/coloris/coloris.css
new file mode 100644
index 0000000..41ddad2
--- /dev/null
+++ b/public/js/libs/coloris/coloris.css
@@ -0,0 +1,577 @@
+.clr-picker {
+ display: none;
+ flex-wrap: wrap;
+ position: absolute;
+ width: 200px;
+ z-index: 1000;
+ border-radius: 10px;
+ background-color: #fff;
+ justify-content: flex-end;
+ direction: ltr;
+ box-shadow: 0 0 5px rgba(0,0,0,.05), 0 5px 20px rgba(0,0,0,.1);
+ -moz-user-select: none;
+ -webkit-user-select: none;
+ user-select: none;
+}
+
+.clr-picker.clr-open,
+.clr-picker[data-inline="true"] {
+ display: flex;
+}
+
+.clr-picker[data-inline="true"] {
+ position: relative;
+}
+
+.clr-gradient {
+ position: relative;
+ width: 100%;
+ height: 100px;
+ margin-bottom: 15px;
+ border-radius: 3px 3px 0 0;
+ background-image: linear-gradient(rgba(0,0,0,0), #000), linear-gradient(90deg, #fff, currentColor);
+ cursor: pointer;
+}
+
+.clr-marker {
+ position: absolute;
+ width: 12px;
+ height: 12px;
+ margin: -6px 0 0 -6px;
+ border: 1px solid #fff;
+ border-radius: 50%;
+ background-color: currentColor;
+ cursor: pointer;
+}
+
+.clr-picker input[type="range"]::-webkit-slider-runnable-track {
+ width: 100%;
+ height: 16px;
+}
+
+.clr-picker input[type="range"]::-webkit-slider-thumb {
+ width: 16px;
+ height: 16px;
+ -webkit-appearance: none;
+}
+
+.clr-picker input[type="range"]::-moz-range-track {
+ width: 100%;
+ height: 16px;
+ border: 0;
+}
+
+.clr-picker input[type="range"]::-moz-range-thumb {
+ width: 16px;
+ height: 16px;
+ border: 0;
+}
+
+.clr-hue {
+ background-image: linear-gradient(to right, #f00 0%, #ff0 16.66%, #0f0 33.33%, #0ff 50%, #00f 66.66%, #f0f 83.33%, #f00 100%);
+}
+
+.clr-hue,
+.clr-alpha {
+ position: relative;
+ width: calc(100% - 40px);
+ height: 8px;
+ margin: 5px 20px;
+ border-radius: 4px;
+}
+
+.clr-alpha span {
+ display: block;
+ height: 100%;
+ width: 100%;
+ border-radius: inherit;
+ background-image: linear-gradient(90deg, rgba(0,0,0,0), currentColor);
+}
+
+.clr-hue input[type="range"],
+.clr-alpha input[type="range"] {
+ position: absolute;
+ width: calc(100% + 32px);
+ height: 16px;
+ left: -16px;
+ top: -4px;
+ margin: 0;
+ background-color: transparent;
+ opacity: 0;
+ cursor: pointer;
+ appearance: none;
+ -webkit-appearance: none;
+}
+
+.clr-hue div,
+.clr-alpha div {
+ position: absolute;
+ width: 16px;
+ height: 16px;
+ left: 0;
+ top: 50%;
+ margin-left: -8px;
+ transform: translateY(-50%);
+ border: 2px solid #fff;
+ border-radius: 50%;
+ background-color: currentColor;
+ box-shadow: 0 0 1px #888;
+ pointer-events: none;
+}
+
+.clr-alpha div:before {
+ content: '';
+ position: absolute;
+ height: 100%;
+ width: 100%;
+ left: 0;
+ top: 0;
+ border-radius: 50%;
+ background-color: currentColor;
+}
+
+.clr-format {
+ display: none;
+ order: 1;
+ width: calc(100% - 40px);
+ margin: 0 20px 20px;
+}
+
+.clr-segmented {
+ display: flex;
+ position: relative;
+ width: 100%;
+ margin: 0;
+ padding: 0;
+ border: 1px solid #ddd;
+ border-radius: 15px;
+ box-sizing: border-box;
+ color: #999;
+ font-size: 12px;
+}
+
+.clr-segmented input,
+.clr-segmented legend {
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ padding: 0;
+ border: 0;
+ left: 0;
+ top: 0;
+ opacity: 0;
+ pointer-events: none;
+}
+
+.clr-segmented label {
+ flex-grow: 1;
+ margin: 0;
+ padding: 4px 0;
+ font-size: inherit;
+ font-weight: normal;
+ line-height: initial;
+ text-align: center;
+ cursor: pointer;
+}
+
+.clr-segmented label:first-of-type {
+ border-radius: 10px 0 0 10px;
+}
+
+.clr-segmented label:last-of-type {
+ border-radius: 0 10px 10px 0;
+}
+
+.clr-segmented input:checked + label {
+ color: #fff;
+ background-color: #666;
+}
+
+.clr-swatches {
+ order: 2;
+ width: calc(100% - 32px);
+ margin: 0 16px;
+}
+
+.clr-swatches div {
+ display: flex;
+ flex-wrap: wrap;
+ padding-bottom: 12px;
+ justify-content: center;
+}
+
+.clr-swatches button {
+ position: relative;
+ width: 20px;
+ height: 20px;
+ margin: 0 4px 6px 4px;
+ padding: 0;
+ border: 0;
+ border-radius: 50%;
+ color: inherit;
+ text-indent: -1000px;
+ white-space: nowrap;
+ overflow: hidden;
+ cursor: pointer;
+}
+
+.clr-swatches button:after {
+ content: '';
+ display: block;
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ left: 0;
+ top: 0;
+ border-radius: inherit;
+ background-color: currentColor;
+ box-shadow: inset 0 0 0 1px rgba(0,0,0,.1);
+}
+
+input.clr-color {
+ order: 1;
+ width: calc(100% - 80px);
+ height: 32px;
+ margin: 15px 20px 20px auto;
+ padding: 0 10px;
+ border: 1px solid #ddd;
+ border-radius: 16px;
+ color: #444;
+ background-color: #fff;
+ font-family: sans-serif;
+ font-size: 14px;
+ text-align: center;
+ box-shadow: none;
+}
+
+input.clr-color:focus {
+ outline: none;
+ border: 1px solid #1e90ff;
+}
+
+.clr-close,
+.clr-clear {
+ display: none;
+ order: 2;
+ height: 24px;
+ margin: 0 20px 20px;
+ padding: 0 20px;
+ border: 0;
+ border-radius: 12px;
+ color: #fff;
+ background-color: #666;
+ font-family: inherit;
+ font-size: 12px;
+ font-weight: 400;
+ cursor: pointer;
+}
+
+.clr-close {
+ display: block;
+ margin: 0 20px 20px auto;
+}
+
+.clr-preview {
+ position: relative;
+ width: 32px;
+ height: 32px;
+ margin: 15px 0 20px 20px;
+ border-radius: 50%;
+ overflow: hidden;
+}
+
+.clr-preview:before,
+.clr-preview:after {
+ content: '';
+ position: absolute;
+ height: 100%;
+ width: 100%;
+ left: 0;
+ top: 0;
+ border: 1px solid #fff;
+ border-radius: 50%;
+}
+
+.clr-preview:after {
+ border: 0;
+ background-color: currentColor;
+ box-shadow: inset 0 0 0 1px rgba(0,0,0,.1);
+}
+
+.clr-preview button {
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ z-index: 1;
+ margin: 0;
+ padding: 0;
+ border: 0;
+ border-radius: 50%;
+ outline-offset: -2px;
+ background-color: transparent;
+ text-indent: -9999px;
+ cursor: pointer;
+ overflow: hidden;
+}
+
+.clr-marker,
+.clr-hue div,
+.clr-alpha div,
+.clr-color {
+ box-sizing: border-box;
+}
+
+.clr-field {
+ display: inline-block;
+ position: relative;
+ color: transparent;
+}
+
+.clr-field input {
+ margin: 0;
+ direction: ltr;
+}
+
+.clr-field.clr-rtl input {
+ text-align: right;
+}
+
+.clr-field button {
+ position: absolute;
+ width: 30px;
+ height: 100%;
+ right: 0;
+ top: 50%;
+ transform: translateY(-50%);
+ margin: 0;
+ padding: 0;
+ border: 0;
+ color: inherit;
+ text-indent: -1000px;
+ white-space: nowrap;
+ overflow: hidden;
+ pointer-events: none;
+}
+
+.clr-field.clr-rtl button {
+ right: auto;
+ left: 0;
+}
+
+.clr-field button:after {
+ content: '';
+ display: block;
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ left: 0;
+ top: 0;
+ border-radius: inherit;
+ background-color: currentColor;
+ box-shadow: inset 0 0 1px rgba(0,0,0,.5);
+}
+
+.clr-alpha,
+.clr-alpha div,
+.clr-swatches button,
+.clr-preview:before,
+.clr-field button {
+ background-image: repeating-linear-gradient(45deg, #aaa 25%, transparent 25%, transparent 75%, #aaa 75%, #aaa), repeating-linear-gradient(45deg, #aaa 25%, #fff 25%, #fff 75%, #aaa 75%, #aaa);
+ background-position: 0 0, 4px 4px;
+ background-size: 8px 8px;
+}
+
+.clr-marker:focus {
+ outline: none;
+}
+
+.clr-keyboard-nav .clr-marker:focus,
+.clr-keyboard-nav .clr-hue input:focus + div,
+.clr-keyboard-nav .clr-alpha input:focus + div,
+.clr-keyboard-nav .clr-segmented input:focus + label {
+ outline: none;
+ box-shadow: 0 0 0 2px #1e90ff, 0 0 2px 2px #fff;
+}
+
+.clr-picker[data-alpha="false"] .clr-alpha {
+ display: none;
+}
+
+.clr-picker[data-minimal="true"] {
+ padding-top: 16px;
+}
+
+.clr-picker[data-minimal="true"] .clr-gradient,
+.clr-picker[data-minimal="true"] .clr-hue,
+.clr-picker[data-minimal="true"] .clr-alpha,
+.clr-picker[data-minimal="true"] .clr-color,
+.clr-picker[data-minimal="true"] .clr-preview {
+ display: none;
+}
+
+/** Dark theme **/
+
+.clr-dark {
+ background-color: #444;
+}
+
+.clr-dark .clr-segmented {
+ border-color: #777;
+}
+
+.clr-dark .clr-swatches button:after {
+ box-shadow: inset 0 0 0 1px rgba(255,255,255,.3);
+}
+
+.clr-dark input.clr-color {
+ color: #fff;
+ border-color: #777;
+ background-color: #555;
+}
+
+.clr-dark input.clr-color:focus {
+ border-color: #1e90ff;
+}
+
+.clr-dark .clr-preview:after {
+ box-shadow: inset 0 0 0 1px rgba(255,255,255,.5);
+}
+
+.clr-dark .clr-alpha,
+.clr-dark .clr-alpha div,
+.clr-dark .clr-swatches button,
+.clr-dark .clr-preview:before {
+ background-image: repeating-linear-gradient(45deg, #666 25%, transparent 25%, transparent 75%, #888 75%, #888), repeating-linear-gradient(45deg, #888 25%, #444 25%, #444 75%, #888 75%, #888);
+}
+
+/** Polaroid theme **/
+
+.clr-picker.clr-polaroid {
+ border-radius: 6px;
+ box-shadow: 0 0 5px rgba(0,0,0,.1), 0 5px 30px rgba(0,0,0,.2);
+}
+
+.clr-picker.clr-polaroid:before {
+ content: '';
+ display: block;
+ position: absolute;
+ width: 16px;
+ height: 10px;
+ left: 20px;
+ top: -10px;
+ border: solid transparent;
+ border-width: 0 8px 10px 8px;
+ border-bottom-color: currentColor;
+ box-sizing: border-box;
+ color: #fff;
+ filter: drop-shadow(0 -4px 3px rgba(0,0,0,.1));
+ pointer-events: none;
+}
+
+.clr-picker.clr-polaroid.clr-dark:before {
+ color: #444;
+}
+
+.clr-picker.clr-polaroid.clr-left:before {
+ left: auto;
+ right: 20px;
+}
+
+.clr-picker.clr-polaroid.clr-top:before {
+ top: auto;
+ bottom: -10px;
+ transform: rotateZ(180deg);
+}
+
+.clr-polaroid .clr-gradient {
+ width: calc(100% - 20px);
+ height: 120px;
+ margin: 10px;
+ border-radius: 3px;
+}
+
+.clr-polaroid .clr-hue,
+.clr-polaroid .clr-alpha {
+ width: calc(100% - 30px);
+ height: 10px;
+ margin: 6px 15px;
+ border-radius: 5px;
+}
+
+.clr-polaroid .clr-hue div,
+.clr-polaroid .clr-alpha div {
+ box-shadow: 0 0 5px rgba(0,0,0,.2);
+}
+
+.clr-polaroid .clr-format {
+ width: calc(100% - 20px);
+ margin: 0 10px 15px;
+}
+
+.clr-polaroid .clr-swatches {
+ width: calc(100% - 12px);
+ margin: 0 6px;
+}
+.clr-polaroid .clr-swatches div {
+ padding-bottom: 10px;
+}
+
+.clr-polaroid .clr-swatches button {
+ width: 22px;
+ height: 22px;
+}
+
+.clr-polaroid input.clr-color {
+ width: calc(100% - 60px);
+ margin: 10px 10px 15px auto;
+}
+
+.clr-polaroid .clr-clear {
+ margin: 0 10px 15px 10px;
+}
+
+.clr-polaroid .clr-close {
+ margin: 0 10px 15px auto;
+}
+
+.clr-polaroid .clr-preview {
+ margin: 10px 0 15px 10px;
+}
+
+/** Large theme **/
+
+.clr-picker.clr-large {
+ width: 275px;
+}
+
+.clr-large .clr-gradient {
+ height: 150px;
+}
+
+.clr-large .clr-swatches button {
+ width: 22px;
+ height: 22px;
+}
+
+/** Pill (horizontal) theme **/
+
+.clr-picker.clr-pill {
+ width: 380px;
+ padding-left: 180px;
+ box-sizing: border-box;
+}
+
+.clr-pill .clr-gradient {
+ position: absolute;
+ width: 180px;
+ height: 100%;
+ left: 0;
+ top: 0;
+ margin-bottom: 0;
+ border-radius: 3px 0 0 3px;
+}
+
+.clr-pill .clr-hue {
+ margin-top: 20px;
+}
\ No newline at end of file
diff --git a/public/js/libs/coloris/coloris.js b/public/js/libs/coloris/coloris.js
new file mode 100644
index 0000000..a313d38
--- /dev/null
+++ b/public/js/libs/coloris/coloris.js
@@ -0,0 +1,1269 @@
+/*!
+ * Copyright (c) 2021 Momo Bassit.
+ * Licensed under the MIT License (MIT)
+ * https://github.com/mdbassit/Coloris
+ */
+
+((window, document, Math, undefined) => {
+ const ctx = document.createElement('canvas').getContext('2d');
+ const currentColor = { r: 0, g: 0, b: 0, h: 0, s: 0, v: 0, a: 1 };
+ let container, picker, colorArea, colorMarker, colorPreview, colorValue, clearButton, closeButton,
+ hueSlider, hueMarker, alphaSlider, alphaMarker, currentEl, currentFormat, oldColor, keyboardNav,
+ colorAreaDims = {};
+
+ // Default settings
+ const settings = {
+ el: '[data-coloris]',
+ parent: 'body',
+ theme: 'default',
+ themeMode: 'light',
+ rtl: false,
+ wrap: true,
+ margin: 2,
+ format: 'hex',
+ formatToggle : false,
+ swatches: [],
+ swatchesOnly: false,
+ alpha: true,
+ forceAlpha: false,
+ focusInput: true,
+ selectInput: false,
+ inline: false,
+ defaultColor: '#000000',
+ clearButton: false,
+ clearLabel: 'Clear',
+ closeButton: false,
+ closeLabel: 'Close',
+ onChange: () => undefined,
+ a11y: {
+ open: 'Open color picker',
+ close: 'Close color picker',
+ clear: 'Clear the selected color',
+ marker: 'Saturation: {s}. Brightness: {v}.',
+ hueSlider: 'Hue slider',
+ alphaSlider: 'Opacity slider',
+ input: 'Color value field',
+ format: 'Color format',
+ swatch: 'Color swatch',
+ instruction: 'Saturation and brightness selector. Use up, down, left and right arrow keys to select.'
+ }
+ };
+
+ // Virtual instances cache
+ const instances = {};
+ let currentInstanceId = '';
+ let defaultInstance = {};
+ let hasInstance = false;
+
+ /**
+ * Configure the color picker.
+ * @param {object} options Configuration options.
+ */
+ function configure(options) {
+ if (typeof options !== 'object') {
+ return;
+ }
+
+ for (const key in options) {
+ switch (key) {
+ case 'el':
+ bindFields(options.el);
+ if (options.wrap !== false) {
+ wrapFields(options.el);
+ }
+ break;
+ case 'parent':
+ container = options.parent instanceof HTMLElement ? options.parent : document.querySelector(options.parent);
+ if (container) {
+ container.appendChild(picker);
+ settings.parent = options.parent;
+
+ // document.body is special
+ if (container === document.body) {
+ container = undefined;
+ }
+ }
+ break;
+ case 'themeMode':
+ settings.themeMode = options.themeMode;
+ if (options.themeMode === 'auto' && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
+ settings.themeMode = 'dark';
+ }
+ // The lack of a break statement is intentional
+ case 'theme':
+ if (options.theme) {
+ settings.theme = options.theme;
+ }
+
+ // Set the theme and color scheme
+ picker.className = `clr-picker clr-${settings.theme} clr-${settings.themeMode}`;
+
+ // Update the color picker's position if inline mode is in use
+ if (settings.inline) {
+ updatePickerPosition();
+ }
+ break;
+ case 'rtl':
+ settings.rtl = !!options.rtl;
+ Array.from(document.getElementsByClassName('clr-field')).forEach(field => field.classList.toggle('clr-rtl', settings.rtl));
+ break;
+ case 'margin':
+ options.margin *= 1;
+ settings.margin = !isNaN(options.margin) ? options.margin : settings.margin;
+ break;
+ case 'wrap':
+ if (options.el && options.wrap) {
+ wrapFields(options.el);
+ }
+ break;
+ case 'formatToggle':
+ settings.formatToggle = !!options.formatToggle;
+ getEl('clr-format').style.display = settings.formatToggle ? 'block' : 'none';
+ if (settings.formatToggle) {
+ settings.format = 'auto';
+ }
+ break;
+ case 'swatches':
+ if (Array.isArray(options.swatches)) {
+ const swatchesContainer = getEl('clr-swatches');
+ const swatches = document.createElement('div');
+
+ // Clear current swatches
+ swatchesContainer.textContent = '';
+
+ // Build new swatches
+ options.swatches.forEach((swatch, i) => {
+ const button = document.createElement('button');
+
+ button.setAttribute('type', `button`);
+ button.setAttribute('id', `clr-swatch-${i}`);
+ button.setAttribute('aria-labelledby', `clr-swatch-label clr-swatch-${i}`);
+ button.style.color = swatch;
+ button.textContent = swatch;
+
+ swatches.appendChild(button);
+ });
+
+ // Append new swatches if any
+ if (options.swatches.length) {
+ swatchesContainer.appendChild(swatches);
+ }
+
+ settings.swatches = options.swatches.slice();
+ }
+ break;
+ case 'swatchesOnly':
+ settings.swatchesOnly = !!options.swatchesOnly;
+ picker.setAttribute('data-minimal', settings.swatchesOnly);
+ break;
+ case 'alpha':
+ settings.alpha = !!options.alpha;
+ picker.setAttribute('data-alpha', settings.alpha);
+ break;
+ case 'inline':
+ settings.inline = !!options.inline;
+ picker.setAttribute('data-inline', settings.inline);
+
+ if (settings.inline) {
+ const defaultColor = options.defaultColor || settings.defaultColor;
+
+ currentFormat = getColorFormatFromStr(defaultColor);
+ updatePickerPosition();
+ setColorFromStr(defaultColor);
+ }
+ break;
+ case 'clearButton':
+ // Backward compatibility
+ if (typeof options.clearButton === 'object') {
+ if (options.clearButton.label) {
+ settings.clearLabel = options.clearButton.label;
+ clearButton.innerHTML = settings.clearLabel;
+ }
+
+ options.clearButton = options.clearButton.show;
+ }
+
+ settings.clearButton = !!options.clearButton;
+ clearButton.style.display = settings.clearButton ? 'block' : 'none';
+ break;
+ case 'clearLabel':
+ settings.clearLabel = options.clearLabel;
+ clearButton.innerHTML = settings.clearLabel;
+ break;
+ case 'closeButton':
+ settings.closeButton = !!options.closeButton;
+
+ if (settings.closeButton) {
+ picker.insertBefore(closeButton, colorPreview);
+ } else {
+ colorPreview.appendChild(closeButton);
+ }
+
+ break;
+ case 'closeLabel':
+ settings.closeLabel = options.closeLabel;
+ closeButton.innerHTML = settings.closeLabel;
+ break;
+ case 'a11y':
+ const labels = options.a11y;
+ let update = false;
+
+ if (typeof labels === 'object') {
+ for (const label in labels) {
+ if (labels[label] && settings.a11y[label]) {
+ settings.a11y[label] = labels[label];
+ update = true;
+ }
+ }
+ }
+
+ if (update) {
+ const openLabel = getEl('clr-open-label');
+ const swatchLabel = getEl('clr-swatch-label');
+
+ openLabel.innerHTML = settings.a11y.open;
+ swatchLabel.innerHTML = settings.a11y.swatch;
+ closeButton.setAttribute('aria-label', settings.a11y.close);
+ clearButton.setAttribute('aria-label', settings.a11y.clear);
+ hueSlider.setAttribute('aria-label', settings.a11y.hueSlider);
+ alphaSlider.setAttribute('aria-label', settings.a11y.alphaSlider);
+ colorValue.setAttribute('aria-label', settings.a11y.input);
+ colorArea.setAttribute('aria-label', settings.a11y.instruction);
+ }
+ break;
+ default:
+ settings[key] = options[key];
+ }
+ }
+ }
+
+ /**
+ * Add or update a virtual instance.
+ * @param {String} selector The CSS selector of the elements to which the instance is attached.
+ * @param {Object} options Per-instance options to apply.
+ */
+ function setVirtualInstance(selector, options) {
+ if (typeof selector === 'string' && typeof options === 'object') {
+ instances[selector] = options;
+ hasInstance = true;
+ }
+ }
+
+ /**
+ * Remove a virtual instance.
+ * @param {String} selector The CSS selector of the elements to which the instance is attached.
+ */
+ function removeVirtualInstance(selector) {
+ delete instances[selector];
+
+ if (Object.keys(instances).length === 0) {
+ hasInstance = false;
+
+ if (selector === currentInstanceId) {
+ resetVirtualInstance();
+ }
+ }
+ }
+
+ /**
+ * Attach a virtual instance to an element if it matches a selector.
+ * @param {Object} element Target element that will receive a virtual instance if applicable.
+ */
+ function attachVirtualInstance(element) {
+ if (hasInstance) {
+ // These options can only be set globally, not per instance
+ const unsupportedOptions = ['el', 'wrap', 'rtl', 'inline', 'defaultColor', 'a11y'];
+
+ for (let selector in instances) {
+ const options = instances[selector];
+
+ // If the element matches an instance's CSS selector
+ if (element.matches(selector)) {
+ currentInstanceId = selector;
+ defaultInstance = {};
+
+ // Delete unsupported options
+ unsupportedOptions.forEach(option => delete options[option]);
+
+ // Back up the default options so we can restore them later
+ for (let option in options) {
+ defaultInstance[option] = Array.isArray(settings[option]) ? settings[option].slice() : settings[option];
+ }
+
+ // Set the instance's options
+ configure(options);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Revert any per-instance options that were previously applied.
+ */
+ function resetVirtualInstance() {
+ if (Object.keys(defaultInstance).length > 0) {
+ configure(defaultInstance);
+ currentInstanceId = '';
+ defaultInstance = {};
+ }
+ }
+
+ /**
+ * Bind the color picker to input fields that match the selector.
+ * @param {(string|HTMLElement|HTMLElement[])} selector A CSS selector string, a DOM element or a list of DOM elements.
+ */
+ function bindFields(selector) {
+ if (selector instanceof HTMLElement) {
+ selector = [selector];
+ }
+
+ if (Array.isArray(selector)) {
+ selector.forEach(field => {
+ addListener(field, 'click', openPicker);
+ addListener(field, 'input', updateColorPreview);
+ });
+ } else {
+ addListener(document, 'click', selector, openPicker);
+ addListener(document, 'input', selector, updateColorPreview);
+ }
+ }
+
+ /**
+ * Open the color picker.
+ * @param {object} event The event that opens the color picker.
+ */
+ function openPicker(event) {
+ // Skip if inline mode is in use
+ if (settings.inline) {
+ return;
+ }
+
+ // Apply any per-instance options first
+ attachVirtualInstance(event.target);
+
+ currentEl = event.target;
+ oldColor = currentEl.value;
+ currentFormat = getColorFormatFromStr(oldColor);
+ picker.classList.add('clr-open');
+
+ updatePickerPosition();
+ setColorFromStr(oldColor);
+
+ if (settings.focusInput || settings.selectInput) {
+ colorValue.focus({ preventScroll: true });
+ colorValue.setSelectionRange(currentEl.selectionStart, currentEl.selectionEnd);
+ }
+
+ if (settings.selectInput) {
+ colorValue.select();
+ }
+
+ // Always focus the first element when using keyboard navigation
+ if (keyboardNav || settings.swatchesOnly) {
+ getFocusableElements().shift().focus();
+ }
+
+ // Trigger an "open" event
+ currentEl.dispatchEvent(new Event('open', { bubbles: true }));
+ }
+
+ /**
+ * Update the color picker's position and the color gradient's offset
+ */
+ function updatePickerPosition() {
+ const parent = container;
+ const scrollY = window.scrollY;
+ const pickerWidth = picker.offsetWidth;
+ const pickerHeight = picker.offsetHeight;
+ const reposition = { left: false, top: false };
+ let parentStyle, parentMarginTop, parentBorderTop;
+ let offset = { x: 0, y: 0 };
+
+ if (parent) {
+ parentStyle = window.getComputedStyle(parent);
+ parentMarginTop = parseFloat(parentStyle.marginTop);
+ parentBorderTop = parseFloat(parentStyle.borderTopWidth);
+
+ offset = parent.getBoundingClientRect();
+ offset.y += parentBorderTop + scrollY;
+ }
+
+ if (!settings.inline) {
+ const coords = currentEl.getBoundingClientRect();
+ let left = coords.x;
+ let top = scrollY + coords.y + coords.height + settings.margin;
+
+ // If the color picker is inside a custom container
+ // set the position relative to it
+ if (parent) {
+ left -= offset.x;
+ top -= offset.y;
+
+ if (left + pickerWidth > parent.clientWidth) {
+ left += coords.width - pickerWidth;
+ reposition.left = true;
+ }
+
+ if (top + pickerHeight > parent.clientHeight - parentMarginTop) {
+ if (pickerHeight + settings.margin <= coords.top - (offset.y - scrollY)) {
+ top -= coords.height + pickerHeight + settings.margin * 2;
+ reposition.top = true;
+ }
+ }
+
+ top += parent.scrollTop;
+
+ // Otherwise set the position relative to the whole document
+ } else {
+ if (left + pickerWidth > document.documentElement.clientWidth) {
+ left += coords.width - pickerWidth;
+ reposition.left = true;
+ }
+
+ if (top + pickerHeight - scrollY > document.documentElement.clientHeight) {
+ if (pickerHeight + settings.margin <= coords.top) {
+ top = scrollY + coords.y - pickerHeight - settings.margin;
+ reposition.top = true;
+ }
+ }
+ }
+
+ picker.classList.toggle('clr-left', reposition.left);
+ picker.classList.toggle('clr-top', reposition.top);
+ picker.style.left = `${left}px`;
+ picker.style.top = `${top}px`;
+ offset.x += picker.offsetLeft;
+ offset.y += picker.offsetTop;
+ }
+
+ colorAreaDims = {
+ width: colorArea.offsetWidth,
+ height: colorArea.offsetHeight,
+ x: colorArea.offsetLeft + offset.x,
+ y: colorArea.offsetTop + offset.y
+ };
+ }
+
+ /**
+ * Wrap the linked input fields in a div that adds a color preview.
+ * @param {(string|HTMLElement|HTMLElement[])} selector A CSS selector string, a DOM element or a list of DOM elements.
+ */
+ function wrapFields(selector) {
+ if (selector instanceof HTMLElement) {
+ wrapColorField(selector);
+ } else if (Array.isArray(selector)) {
+ selector.forEach(wrapColorField);
+ } else {
+ document.querySelectorAll(selector).forEach(wrapColorField);
+ }
+ }
+
+ /**
+ * Wrap an input field in a div that adds a color preview.
+ * @param {object} field The input field.
+ */
+ function wrapColorField(field) {
+ const parentNode = field.parentNode;
+
+ if (!parentNode.classList.contains('clr-field')) {
+ const wrapper = document.createElement('div');
+ let classes = 'clr-field';
+
+ if (settings.rtl || field.classList.contains('clr-rtl')) {
+ classes += ' clr-rtl';
+ }
+
+ wrapper.innerHTML = '<button type="button" aria-labelledby="clr-open-label"></button>';
+ parentNode.insertBefore(wrapper, field);
+ wrapper.className = classes;
+ wrapper.style.color = field.value;
+ wrapper.appendChild(field);
+ }
+ }
+
+ /**
+ * Update the color preview of an input field
+ * @param {object} event The "input" event that triggers the color change.
+ */
+ function updateColorPreview(event) {
+ const parent = event.target.parentNode;
+
+ // Only update the preview if the field has been previously wrapped
+ if (parent.classList.contains('clr-field')) {
+ parent.style.color = event.target.value;
+ }
+ }
+
+ /**
+ * Close the color picker.
+ * @param {boolean} [revert] If true, revert the color to the original value.
+ */
+ function closePicker(revert) {
+ if (currentEl && !settings.inline) {
+ const prevEl = currentEl;
+
+ // Revert the color to the original value if needed
+ if (revert) {
+ // This will prevent the "change" event on the colorValue input to execute its handler
+ currentEl = undefined;
+
+ if (oldColor !== prevEl.value) {
+ prevEl.value = oldColor;
+
+ // Trigger an "input" event to force update the thumbnail next to the input field
+ prevEl.dispatchEvent(new Event('input', { bubbles: true }));
+ }
+ }
+
+ // Trigger a "change" event if needed
+ setTimeout(() => { // Add this to the end of the event loop
+ if (oldColor !== prevEl.value) {
+ prevEl.dispatchEvent(new Event('change', { bubbles: true }));
+ }
+ });
+
+ // Hide the picker dialog
+ picker.classList.remove('clr-open');
+
+ // Reset any previously set per-instance options
+ if (hasInstance) {
+ resetVirtualInstance();
+ }
+
+ // Trigger a "close" event
+ prevEl.dispatchEvent(new Event('close', { bubbles: true }));
+
+ if (settings.focusInput) {
+ prevEl.focus({ preventScroll: true });
+ }
+
+ // This essentially marks the picker as closed
+ currentEl = undefined;
+ }
+ }
+
+ /**
+ * Set the active color from a string.
+ * @param {string} str String representing a color.
+ */
+ function setColorFromStr(str) {
+ const rgba = strToRGBA(str);
+ const hsva = RGBAtoHSVA(rgba);
+
+ updateMarkerA11yLabel(hsva.s, hsva.v);
+ updateColor(rgba, hsva);
+
+ // Update the UI
+ hueSlider.value = hsva.h;
+ picker.style.color = `hsl(${hsva.h}, 100%, 50%)`;
+ hueMarker.style.left = `${hsva.h / 360 * 100}%`;
+
+ colorMarker.style.left = `${colorAreaDims.width * hsva.s / 100}px`;
+ colorMarker.style.top = `${colorAreaDims.height - (colorAreaDims.height * hsva.v / 100)}px`;
+
+ alphaSlider.value = hsva.a * 100;
+ alphaMarker.style.left = `${hsva.a * 100}%`;
+ }
+
+ /**
+ * Guess the color format from a string.
+ * @param {string} str String representing a color.
+ * @return {string} The color format.
+ */
+ function getColorFormatFromStr(str) {
+ const format = str.substring(0, 3).toLowerCase();
+
+ if (format === 'rgb' || format === 'hsl' ) {
+ return format;
+ }
+
+ return 'hex';
+ }
+
+ /**
+ * Copy the active color to the linked input field.
+ * @param {number} [color] Color value to override the active color.
+ */
+ function pickColor(color) {
+ color = color !== undefined ? color : colorValue.value;
+
+ if (currentEl) {
+ currentEl.value = color;
+ currentEl.dispatchEvent(new Event('input', { bubbles: true }));
+ }
+
+ if (settings.onChange) {
+ settings.onChange.call(window, color, currentEl);
+ }
+
+ document.dispatchEvent(new CustomEvent('coloris:pick', { detail: { color, currentEl } }));
+ }
+
+ /**
+ * Set the active color based on a specific point in the color gradient.
+ * @param {number} x Left position.
+ * @param {number} y Top position.
+ */
+ function setColorAtPosition(x, y) {
+ const hsva = {
+ h: hueSlider.value * 1,
+ s: x / colorAreaDims.width * 100,
+ v: 100 - (y / colorAreaDims.height * 100),
+ a: alphaSlider.value / 100
+ };
+ const rgba = HSVAtoRGBA(hsva);
+
+ updateMarkerA11yLabel(hsva.s, hsva.v);
+ updateColor(rgba, hsva);
+ pickColor();
+ }
+
+ /**
+ * Update the color marker's accessibility label.
+ * @param {number} saturation
+ * @param {number} value
+ */
+ function updateMarkerA11yLabel(saturation, value) {
+ let label = settings.a11y.marker;
+
+ saturation = saturation.toFixed(1) * 1;
+ value = value.toFixed(1) * 1;
+ label = label.replace('{s}', saturation);
+ label = label.replace('{v}', value);
+ colorMarker.setAttribute('aria-label', label);
+ }
+
+ //
+ /**
+ * Get the pageX and pageY positions of the pointer.
+ * @param {object} event The MouseEvent or TouchEvent object.
+ * @return {object} The pageX and pageY positions.
+ */
+ function getPointerPosition(event) {
+ return {
+ pageX: event.changedTouches ? event.changedTouches[0].pageX : event.pageX,
+ pageY: event.changedTouches ? event.changedTouches[0].pageY : event.pageY
+ };
+ }
+
+ /**
+ * Move the color marker when dragged.
+ * @param {object} event The MouseEvent object.
+ */
+ function moveMarker(event) {
+ const pointer = getPointerPosition(event);
+ let x = pointer.pageX - colorAreaDims.x;
+ let y = pointer.pageY - colorAreaDims.y;
+
+ if (container) {
+ y += container.scrollTop;
+ }
+
+ setMarkerPosition(x, y);
+
+ // Prevent scrolling while dragging the marker
+ event.preventDefault();
+ event.stopPropagation();
+ }
+
+ /**
+ * Move the color marker when the arrow keys are pressed.
+ * @param {number} offsetX The horizontal amount to move.
+ * @param {number} offsetY The vertical amount to move.
+ */
+ function moveMarkerOnKeydown(offsetX, offsetY) {
+ let x = colorMarker.style.left.replace('px', '') * 1 + offsetX;
+ let y = colorMarker.style.top.replace('px', '') * 1 + offsetY;
+
+ setMarkerPosition(x, y);
+ }
+
+ /**
+ * Set the color marker's position.
+ * @param {number} x Left position.
+ * @param {number} y Top position.
+ */
+ function setMarkerPosition(x, y) {
+ // Make sure the marker doesn't go out of bounds
+ x = (x < 0) ? 0 : (x > colorAreaDims.width) ? colorAreaDims.width : x;
+ y = (y < 0) ? 0 : (y > colorAreaDims.height) ? colorAreaDims.height : y;
+
+ // Set the position
+ colorMarker.style.left = `${x}px`;
+ colorMarker.style.top = `${y}px`;
+
+ // Update the color
+ setColorAtPosition(x, y);
+
+ // Make sure the marker is focused
+ colorMarker.focus();
+ }
+
+ /**
+ * Update the color picker's input field and preview thumb.
+ * @param {Object} rgba Red, green, blue and alpha values.
+ * @param {Object} [hsva] Hue, saturation, value and alpha values.
+ */
+ function updateColor(rgba = {}, hsva = {}) {
+ let format = settings.format;
+
+ for (const key in rgba) {
+ currentColor[key] = rgba[key];
+ }
+
+ for (const key in hsva) {
+ currentColor[key] = hsva[key];
+ }
+
+ const hex = RGBAToHex(currentColor);
+ const opaqueHex = hex.substring(0, 7);
+
+ colorMarker.style.color = opaqueHex;
+ alphaMarker.parentNode.style.color = opaqueHex;
+ alphaMarker.style.color = hex;
+ colorPreview.style.color = hex;
+
+ // Force repaint the color and alpha gradients as a workaround for a Google Chrome bug
+ colorArea.style.display = 'none';
+ colorArea.offsetHeight;
+ colorArea.style.display = '';
+ alphaMarker.nextElementSibling.style.display = 'none';
+ alphaMarker.nextElementSibling.offsetHeight;
+ alphaMarker.nextElementSibling.style.display = '';
+
+ if (format === 'mixed') {
+ format = currentColor.a === 1 ? 'hex' : 'rgb';
+ } else if (format === 'auto') {
+ format = currentFormat;
+ }
+
+ switch (format) {
+ case 'hex':
+ colorValue.value = hex;
+ break;
+ case 'rgb':
+ colorValue.value = RGBAToStr(currentColor);
+ break;
+ case 'hsl':
+ colorValue.value = HSLAToStr(HSVAtoHSLA(currentColor));
+ break;
+ }
+
+ // Select the current format in the format switcher
+ document.querySelector(`.clr-format [value="${format}"]`).checked = true;
+ }
+
+ /**
+ * Set the hue when its slider is moved.
+ */
+ function setHue() {
+ const hue = hueSlider.value * 1;
+ const x = colorMarker.style.left.replace('px', '') * 1;
+ const y = colorMarker.style.top.replace('px', '') * 1;
+
+ picker.style.color = `hsl(${hue}, 100%, 50%)`;
+ hueMarker.style.left = `${hue / 360 * 100}%`;
+
+ setColorAtPosition(x, y);
+ }
+
+ /**
+ * Set the alpha when its slider is moved.
+ */
+ function setAlpha() {
+ const alpha = alphaSlider.value / 100;
+
+ alphaMarker.style.left = `${alpha * 100}%`;
+ updateColor({ a: alpha });
+ pickColor();
+ }
+
+ /**
+ * Convert HSVA to RGBA.
+ * @param {object} hsva Hue, saturation, value and alpha values.
+ * @return {object} Red, green, blue and alpha values.
+ */
+ function HSVAtoRGBA(hsva) {
+ const saturation = hsva.s / 100;
+ const value = hsva.v / 100;
+ let chroma = saturation * value;
+ let hueBy60 = hsva.h / 60;
+ let x = chroma * (1 - Math.abs(hueBy60 % 2 - 1));
+ let m = value - chroma;
+
+ chroma = (chroma + m);
+ x = (x + m);
+
+ const index = Math.floor(hueBy60) % 6;
+ const red = [chroma, x, m, m, x, chroma][index];
+ const green = [x, chroma, chroma, x, m, m][index];
+ const blue = [m, m, x, chroma, chroma, x][index];
+
+ return {
+ r: Math.round(red * 255),
+ g: Math.round(green * 255),
+ b: Math.round(blue * 255),
+ a: hsva.a
+ };
+ }
+
+ /**
+ * Convert HSVA to HSLA.
+ * @param {object} hsva Hue, saturation, value and alpha values.
+ * @return {object} Hue, saturation, lightness and alpha values.
+ */
+ function HSVAtoHSLA(hsva) {
+ const value = hsva.v / 100;
+ const lightness = value * (1 - (hsva.s / 100) / 2);
+ let saturation;
+
+ if (lightness > 0 && lightness < 1) {
+ saturation = Math.round((value - lightness) / Math.min(lightness, 1 - lightness) * 100);
+ }
+
+ return {
+ h: hsva.h,
+ s: saturation || 0,
+ l: Math.round(lightness * 100),
+ a: hsva.a
+ };
+ }
+
+ /**
+ * Convert RGBA to HSVA.
+ * @param {object} rgba Red, green, blue and alpha values.
+ * @return {object} Hue, saturation, value and alpha values.
+ */
+ function RGBAtoHSVA(rgba) {
+ const red = rgba.r / 255;
+ const green = rgba.g / 255;
+ const blue = rgba.b / 255;
+ const xmax = Math.max(red, green, blue);
+ const xmin = Math.min(red, green, blue);
+ const chroma = xmax - xmin;
+ const value = xmax;
+ let hue = 0;
+ let saturation = 0;
+
+ if (chroma) {
+ if (xmax === red ) { hue = ((green - blue) / chroma); }
+ if (xmax === green ) { hue = 2 + (blue - red) / chroma; }
+ if (xmax === blue ) { hue = 4 + (red - green) / chroma; }
+ if (xmax) { saturation = chroma / xmax; }
+ }
+
+ hue = Math.floor(hue * 60);
+
+ return {
+ h: hue < 0 ? hue + 360 : hue,
+ s: Math.round(saturation * 100),
+ v: Math.round(value * 100),
+ a: rgba.a
+ };
+ }
+
+ /**
+ * Parse a string to RGBA.
+ * @param {string} str String representing a color.
+ * @return {object} Red, green, blue and alpha values.
+ */
+ function strToRGBA(str) {
+ const regex = /^((rgba)|rgb)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i;
+ let match, rgba;
+
+ // Default to black for invalid color strings
+ ctx.fillStyle = '#000';
+
+ // Use canvas to convert the string to a valid color string
+ ctx.fillStyle = str;
+ match = regex.exec(ctx.fillStyle);
+
+ if (match) {
+ rgba = {
+ r: match[3] * 1,
+ g: match[4] * 1,
+ b: match[5] * 1,
+ a: match[6] * 1
+ };
+
+ } else {
+ match = ctx.fillStyle.replace('#', '').match(/.{2}/g).map(h => parseInt(h, 16));
+ rgba = {
+ r: match[0],
+ g: match[1],
+ b: match[2],
+ a: 1
+ };
+ }
+
+ return rgba;
+ }
+
+ /**
+ * Convert RGBA to Hex.
+ * @param {object} rgba Red, green, blue and alpha values.
+ * @return {string} Hex color string.
+ */
+ function RGBAToHex(rgba) {
+ let R = rgba.r.toString(16);
+ let G = rgba.g.toString(16);
+ let B = rgba.b.toString(16);
+ let A = '';
+
+ if (rgba.r < 16) {
+ R = '0' + R;
+ }
+
+ if (rgba.g < 16) {
+ G = '0' + G;
+ }
+
+ if (rgba.b < 16) {
+ B = '0' + B;
+ }
+
+ if (settings.alpha && (rgba.a < 1 || settings.forceAlpha)) {
+ const alpha = rgba.a * 255 | 0;
+ A = alpha.toString(16);
+
+ if (alpha < 16) {
+ A = '0' + A;
+ }
+ }
+
+ return '#' + R + G + B + A;
+ }
+
+ /**
+ * Convert RGBA values to a CSS rgb/rgba string.
+ * @param {object} rgba Red, green, blue and alpha values.
+ * @return {string} CSS color string.
+ */
+ function RGBAToStr(rgba) {
+ if (!settings.alpha || (rgba.a === 1 && !settings.forceAlpha)) {
+ return `rgb(${rgba.r}, ${rgba.g}, ${rgba.b})`;
+ } else {
+ return `rgba(${rgba.r}, ${rgba.g}, ${rgba.b}, ${rgba.a})`;
+ }
+ }
+
+ /**
+ * Convert HSLA values to a CSS hsl/hsla string.
+ * @param {object} hsla Hue, saturation, lightness and alpha values.
+ * @return {string} CSS color string.
+ */
+ function HSLAToStr(hsla) {
+ if (!settings.alpha || (hsla.a === 1 && !settings.forceAlpha)) {
+ return `hsl(${hsla.h}, ${hsla.s}%, ${hsla.l}%)`;
+ } else {
+ return `hsla(${hsla.h}, ${hsla.s}%, ${hsla.l}%, ${hsla.a})`;
+ }
+ }
+
+ /**
+ * Init the color picker.
+ */
+ function init() {
+ // Render the UI
+ container = undefined;
+ picker = document.createElement('div');
+ picker.setAttribute('id', 'clr-picker');
+ picker.className = 'clr-picker';
+ picker.innerHTML =
+ `<input id="clr-color-value" name="clr-color-value" class="clr-color" type="text" value="" spellcheck="false" aria-label="${settings.a11y.input}">`+
+ `<div id="clr-color-area" class="clr-gradient" role="application" aria-label="${settings.a11y.instruction}">`+
+ '<div id="clr-color-marker" class="clr-marker" tabindex="0"></div>'+
+ '</div>'+
+ '<div class="clr-hue">'+
+ `<input id="clr-hue-slider" name="clr-hue-slider" type="range" min="0" max="360" step="1" aria-label="${settings.a11y.hueSlider}">`+
+ '<div id="clr-hue-marker"></div>'+
+ '</div>'+
+ '<div class="clr-alpha">'+
+ `<input id="clr-alpha-slider" name="clr-alpha-slider" type="range" min="0" max="100" step="1" aria-label="${settings.a11y.alphaSlider}">`+
+ '<div id="clr-alpha-marker"></div>'+
+ '<span></span>'+
+ '</div>'+
+ '<div id="clr-format" class="clr-format">'+
+ '<fieldset class="clr-segmented">'+
+ `<legend>${settings.a11y.format}</legend>`+
+ '<input id="clr-f1" type="radio" name="clr-format" value="hex">'+
+ '<label for="clr-f1">Hex</label>'+
+ '<input id="clr-f2" type="radio" name="clr-format" value="rgb">'+
+ '<label for="clr-f2">RGB</label>'+
+ '<input id="clr-f3" type="radio" name="clr-format" value="hsl">'+
+ '<label for="clr-f3">HSL</label>'+
+ '<span></span>'+
+ '</fieldset>'+
+ '</div>'+
+ '<div id="clr-swatches" class="clr-swatches"></div>'+
+ `<button type="button" id="clr-clear" class="clr-clear" aria-label="${settings.a11y.clear}">${settings.clearLabel}</button>`+
+ '<div id="clr-color-preview" class="clr-preview">'+
+ `<button type="button" id="clr-close" class="clr-close" aria-label="${settings.a11y.close}">${settings.closeLabel}</button>`+
+ '</div>'+
+ `<span id="clr-open-label" hidden>${settings.a11y.open}</span>`+
+ `<span id="clr-swatch-label" hidden>${settings.a11y.swatch}</span>`;
+
+ // Append the color picker to the DOM
+ document.body.appendChild(picker);
+
+ // Reference the UI elements
+ colorArea = getEl('clr-color-area');
+ colorMarker = getEl('clr-color-marker');
+ clearButton = getEl('clr-clear');
+ closeButton = getEl('clr-close');
+ colorPreview = getEl('clr-color-preview');
+ colorValue = getEl('clr-color-value');
+ hueSlider = getEl('clr-hue-slider');
+ hueMarker = getEl('clr-hue-marker');
+ alphaSlider = getEl('clr-alpha-slider');
+ alphaMarker = getEl('clr-alpha-marker');
+
+ // Bind the picker to the default selector
+ bindFields(settings.el);
+ wrapFields(settings.el);
+
+ addListener(picker, 'mousedown', event => {
+ picker.classList.remove('clr-keyboard-nav');
+ event.stopPropagation();
+ });
+
+ addListener(colorArea, 'mousedown', event => {
+ addListener(document, 'mousemove', moveMarker);
+ });
+
+ addListener(colorArea, 'contextmenu', event => {
+ event.preventDefault();
+ });
+
+ addListener(colorArea, 'touchstart', event => {
+ document.addEventListener('touchmove', moveMarker, { passive: false });
+ });
+
+ addListener(colorMarker, 'mousedown', event => {
+ addListener(document, 'mousemove', moveMarker);
+ });
+
+ addListener(colorMarker, 'touchstart', event => {
+ document.addEventListener('touchmove', moveMarker, { passive: false });
+ });
+
+ addListener(colorValue, 'change', event => {
+ const value = colorValue.value;
+
+ if (currentEl || settings.inline) {
+ const color = value === '' ? value : setColorFromStr(value);
+ pickColor(color);
+ }
+ });
+
+ addListener(clearButton, 'click', event => {
+ pickColor('');
+ closePicker();
+ });
+
+ addListener(closeButton, 'click', event => {
+ pickColor();
+ closePicker();
+ });
+
+ addListener(getEl('clr-format'), 'click', '.clr-format input', event => {
+ currentFormat = event.target.value;
+ updateColor();
+ pickColor();
+ });
+
+ addListener(picker, 'click', '.clr-swatches button', event => {
+ setColorFromStr(event.target.textContent);
+ pickColor();
+
+ if (settings.swatchesOnly) {
+ closePicker();
+ }
+ });
+
+ addListener(document, 'mouseup', event => {
+ document.removeEventListener('mousemove', moveMarker);
+ });
+
+ addListener(document, 'touchend', event => {
+ document.removeEventListener('touchmove', moveMarker);
+ });
+
+ addListener(document, 'mousedown', event => {
+ keyboardNav = false;
+ picker.classList.remove('clr-keyboard-nav');
+ closePicker();
+ });
+
+ addListener(document, 'keydown', event => {
+ const key = event.key;
+ const target = event.target;
+ const shiftKey = event.shiftKey;
+ const navKeys = ['Tab', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];
+
+ if (key === 'Escape') {
+ closePicker(true);
+ return;
+
+ // Close the color picker and keep the selected color on press on Enter
+ } else if (key === 'Enter' && target.tagName !== 'BUTTON') {
+ closePicker();
+ return;
+
+ // Display focus rings when using the keyboard
+ } else if (navKeys.includes(key)) {
+ keyboardNav = true;
+ picker.classList.add('clr-keyboard-nav');
+ }
+
+ // Trap the focus within the color picker while it's open
+ if (key === 'Tab' && target.matches('.clr-picker *')) {
+ const focusables = getFocusableElements();
+ const firstFocusable = focusables.shift();
+ const lastFocusable = focusables.pop();
+
+ if (shiftKey && target === firstFocusable) {
+ lastFocusable.focus();
+ event.preventDefault();
+ } else if (!shiftKey && target === lastFocusable) {
+ firstFocusable.focus();
+ event.preventDefault();
+ }
+ }
+ });
+
+ addListener(document, 'click', '.clr-field button', event => {
+ // Reset any previously set per-instance options
+ if (hasInstance) {
+ resetVirtualInstance();
+ }
+
+ // Open the color picker
+ event.target.nextElementSibling.dispatchEvent(new Event('click', { bubbles: true }));
+ });
+
+ addListener(colorMarker, 'keydown', event => {
+ const movements = {
+ ArrowUp: [0, -1],
+ ArrowDown: [0, 1],
+ ArrowLeft: [-1, 0],
+ ArrowRight: [1, 0]
+ };
+
+ if (Object.keys(movements).includes(event.key)) {
+ moveMarkerOnKeydown(...movements[event.key]);
+ event.preventDefault();
+ }
+ });
+
+ addListener(colorArea, 'click', moveMarker);
+ addListener(hueSlider, 'input', setHue);
+ addListener(alphaSlider, 'input', setAlpha);
+ }
+
+ /**
+ * Return a list of focusable elements within the color picker.
+ * @return {array} The list of focusable DOM elemnts.
+ */
+ function getFocusableElements() {
+ const controls = Array.from(picker.querySelectorAll('input, button'));
+ const focusables = controls.filter(node => !!node.offsetWidth);
+
+ return focusables;
+ }
+
+ /**
+ * Shortcut for getElementById to optimize the minified JS.
+ * @param {string} id The element id.
+ * @return {object} The DOM element with the provided id.
+ */
+ function getEl(id) {
+ return document.getElementById(id);
+ }
+
+ /**
+ * Shortcut for addEventListener to optimize the minified JS.
+ * @param {object} context The context to which the listener is attached.
+ * @param {string} type Event type.
+ * @param {(string|function)} selector Event target if delegation is used, event handler if not.
+ * @param {function} [fn] Event handler if delegation is used.
+ */
+ function addListener(context, type, selector, fn) {
+ const matches = Element.prototype.matches || Element.prototype.msMatchesSelector;
+
+ // Delegate event to the target of the selector
+ if (typeof selector === 'string') {
+ context.addEventListener(type, event => {
+ if (matches.call(event.target, selector)) {
+ fn.call(event.target, event);
+ }
+ });
+
+ // If the selector is not a string then it's a function
+ // in which case we need a regular event listener
+ } else {
+ fn = selector;
+ context.addEventListener(type, fn);
+ }
+ }
+
+ /**
+ * Call a function only when the DOM is ready.
+ * @param {function} fn The function to call.
+ * @param {array} [args] Arguments to pass to the function.
+ */
+ function DOMReady(fn, args) {
+ args = args !== undefined ? args : [];
+
+ if (document.readyState !== 'loading') {
+ fn(...args);
+ } else {
+ document.addEventListener('DOMContentLoaded', () => {
+ fn(...args);
+ });
+ }
+ }
+
+ // Polyfill for Nodelist.forEach
+ if (NodeList !== undefined && NodeList.prototype && !NodeList.prototype.forEach) {
+ NodeList.prototype.forEach = Array.prototype.forEach;
+ }
+
+ // Expose the color picker to the global scope
+ window.Coloris = (() => {
+ const methods = {
+ set: configure,
+ wrap: wrapFields,
+ close: closePicker,
+ setInstance: setVirtualInstance,
+ removeInstance: removeVirtualInstance,
+ updatePosition: updatePickerPosition,
+ ready: DOMReady
+ };
+
+ function Coloris(options) {
+ DOMReady(() => {
+ if (options) {
+ if (typeof options === 'string') {
+ bindFields(options);
+ } else {
+ configure(options);
+ }
+ }
+ });
+ }
+
+ for (const key in methods) {
+ Coloris[key] = (...args) => {
+ DOMReady(methods[key], args);
+ };
+ }
+
+ return Coloris;
+ })();
+
+ // Init the color picker when the DOM is ready
+ DOMReady(init);
+
+})(window, document, Math);
diff --git a/public/js/libs/coloris/coloris.min.css b/public/js/libs/coloris/coloris.min.css
new file mode 100644
index 0000000..161bb69
--- /dev/null
+++ b/public/js/libs/coloris/coloris.min.css
@@ -0,0 +1,22 @@
+.clr-picker{display:none;flex-wrap:wrap;position:absolute;width:200px;z-index:1000;border-radius:10px;background-color:#fff;justify-content:flex-end;direction:ltr;box-shadow:0 0 5px rgba(0,0,0,.05),0 5px 20px rgba(0,0,0,.1);-moz-user-select:none;-webkit-user-select:none;user-select:none}.clr-picker.clr-open,.clr-picker[data-inline=true]{display:flex}.clr-picker[data-inline=true]{position:relative}.clr-gradient{position:relative;width:100%;height:100px;margin-bottom:15px;border-radius:3px 3px 0 0;background-image:linear-gradient(rgba(0,0,0,0),#000),linear-gradient(90deg,#fff,currentColor);cursor:pointer}.clr-marker{position:absolute;width:12px;height:12px;margin:-6px 0 0 -6px;border:1px solid #fff;border-radius:50%;background-color:currentColor;cursor:pointer}.clr-picker input[type=range]::-webkit-slider-runnable-track{width:100%;height:16px}.clr-picker input[type=range]::-webkit-slider-thumb{width:16px;height:16px;-webkit-appearance:none}.clr-picker input[type=range]::-moz-range-track{width:100%;height:16px;border:0}.clr-picker input[type=range]::-moz-range-thumb{width:16px;height:16px;border:0}.clr-hue{background-image:linear-gradient(to right,red 0,#ff0 16.66%,#0f0 33.33%,#0ff 50%,#00f 66.66%,#f0f 83.33%,red 100%)}.clr-alpha,.clr-hue{position:relative;width:calc(100% - 40px);height:8px;margin:5px 20px;border-radius:4px}.clr-alpha span{display:block;height:100%;width:100%;border-radius:inherit;background-image:linear-gradient(90deg,rgba(0,0,0,0),currentColor)}.clr-alpha input[type=range],.clr-hue input[type=range]{position:absolute;width:calc(100% + 32px);height:16px;left:-16px;top:-4px;margin:0;background-color:transparent;opacity:0;cursor:pointer;appearance:none;-webkit-appearance:none}.clr-alpha div,.clr-hue div{position:absolute;width:16px;height:16px;left:0;top:50%;margin-left:-8px;transform:translateY(-50%);border:2px solid #fff;border-radius:50%;background-color:currentColor;box-shadow:0 0 1px #888;pointer-events:none}.clr-alpha div:before{content:'';position:absolute;height:100%;width:100%;left:0;top:0;border-radius:50%;background-color:currentColor}.clr-format{display:none;order:1;width:calc(100% - 40px);margin:0 20px 20px}.clr-segmented{display:flex;position:relative;width:100%;margin:0;padding:0;border:1px solid #ddd;border-radius:15px;box-sizing:border-box;color:#999;font-size:12px}.clr-segmented input,.clr-segmented legend{position:absolute;width:100%;height:100%;margin:0;padding:0;border:0;left:0;top:0;opacity:0;pointer-events:none}.clr-segmented label{flex-grow:1;margin:0;padding:4px 0;font-size:inherit;font-weight:400;line-height:initial;text-align:center;cursor:pointer}.clr-segmented label:first-of-type{border-radius:10px 0 0 10px}.clr-segmented label:last-of-type{border-radius:0 10px 10px 0}.clr-segmented input:checked+label{color:#fff;background-color:#666}.clr-swatches{order:2;width:calc(100% - 32px);margin:0 16px}.clr-swatches div{display:flex;flex-wrap:wrap;padding-bottom:12px;justify-content:center}.clr-swatches button{position:relative;width:20px;height:20px;margin:0 4px 6px 4px;padding:0;border:0;border-radius:50%;color:inherit;text-indent:-1000px;white-space:nowrap;overflow:hidden;cursor:pointer}.clr-swatches button:after{content:'';display:block;position:absolute;width:100%;height:100%;left:0;top:0;border-radius:inherit;background-color:currentColor;box-shadow:inset 0 0 0 1px rgba(0,0,0,.1)}input.clr-color{order:1;width:calc(100% - 80px);height:32px;margin:15px 20px 20px auto;padding:0 10px;border:1px solid #ddd;border-radius:16px;color:#444;background-color:#fff;font-family:sans-serif;font-size:14px;text-align:center;box-shadow:none}input.clr-color:focus{outline:0;border:1px solid #1e90ff}.clr-clear,.clr-close{display:none;order:2;height:24px;margin:0 20px 20px;padding:0 20px;border:0;border-radius:12px;color:#fff;background-color:#666;font-family:inherit;font-size:12px;font-weight:400;cursor:pointer}.clr-close{display:block;margin:0 20px 20px auto}.clr-preview{position:relative;width:32px;height:32px;margin:15px 0 20px 20px;border-radius:50%;overflow:hidden}.clr-preview:after,.clr-preview:before{content:'';position:absolute;height:100%;width:100%;left:0;top:0;border:1px solid #fff;border-radius:50%}.clr-preview:after{border:0;background-color:currentColor;box-shadow:inset 0 0 0 1px rgba(0,0,0,.1)}.clr-preview button{position:absolute;width:100%;height:100%;z-index:1;margin:0;padding:0;border:0;border-radius:50%;outline-offset:-2px;background-color:transparent;text-indent:-9999px;cursor:pointer;overflow:hidden}.clr-alpha div,.clr-color,.clr-hue div,.clr-marker{box-sizing:border-box}.clr-field{display:inline-block;position:relative;color:transparent}.clr-field input{margin:0;direction:ltr}.clr-field.clr-rtl input{text-align:right}.clr-field button{position:absolute;width:30px;height:100%;right:0;top:50%;transform:translateY(-50%);margin:0;padding:0;border:0;color:inherit;text-indent:-1000px;white-space:nowrap;overflow:hidden;pointer-events:none}.clr-field.clr-rtl button{right:auto;left:0}.clr-field button:after{content:'';display:block;position:absolute;width:100%;height:100%;left:0;top:0;border-radius:inherit;background-color:currentColor;box-shadow:inset 0 0 1px rgba(0,0,0,.5)}.clr-alpha,.clr-alpha div,.clr-field button,.clr-preview:before,.clr-swatches button{background-image:repeating-linear-gradient(45deg,#aaa 25%,transparent 25%,transparent 75%,#aaa 75%,#aaa),repeating-linear-gradient(45deg,#aaa 25%,#fff 25%,#fff 75%,#aaa 75%,#aaa);background-position:0 0,4px 4px;background-size:8px 8px}.clr-marker:focus{outline:0}.clr-keyboard-nav .clr-alpha input:focus+div,.clr-keyboard-nav .clr-hue input:focus+div,.clr-keyboard-nav .clr-marker:focus,.clr-keyboard-nav .clr-segmented input:focus+label{outline:0;box-shadow:0 0 0 2px #1e90ff,0 0 2px 2px #fff}.clr-picker[data-alpha=false] .clr-alpha{display:none}.clr-picker[data-minimal=true]{padding-top:16px}.clr-picker[data-minimal=true] .clr-alpha,.clr-picker[data-minimal=true] .clr-color,.clr-picker[data-minimal=true] .clr-gradient,.clr-picker[data-minimal=true] .clr-hue,.clr-picker[data-minimal=true] .clr-preview{display:none}.clr-dark{background-color:#444}.clr-dark .clr-segmented{border-color:#777}.clr-dark .clr-swatches button:after{box-shadow:inset 0 0 0 1px rgba(255,255,255,.3)}.clr-dark input.clr-color{color:#fff;border-color:#777;background-color:#555}.clr-dark input.clr-color:focus{border-color:#1e90ff}.clr-dark .clr-preview:after{box-shadow:inset 0 0 0 1px rgba(255,255,255,.5)}.clr-dark .clr-alpha,.clr-dark .clr-alpha div,.clr-dark .clr-preview:before,.clr-dark .clr-swatches button{background-image:repeating-linear-gradient(45deg,#666 25%,transparent 25%,transparent 75%,#888 75%,#888),repeating-linear-gradient(45deg,#888 25%,#444 25%,#444 75%,#888 75%,#888)}.clr-picker.clr-polaroid{border-radius:6px;box-shadow:0 0 5px rgba(0,0,0,.1),0 5px 30px rgba(0,0,0,.2)}.clr-picker.clr-polaroid:before{content:'';display:block;position:absolute;width:16px;height:10px;left:20px;top:-10px;border:solid transparent;border-width:0 8px 10px 8px;border-bottom-color:currentColor;box-sizing:border-box;color:#fff;filter:drop-shadow(0 -4px 3px rgba(0,0,0,.1));pointer-events:none}.clr-picker.clr-polaroid.clr-dark:before{color:#444}.clr-picker.clr-polaroid.clr-left:before{left:auto;right:20px}.clr-picker.clr-polaroid.clr-top:before{top:auto;bottom:-10px;transform:rotateZ(180deg)}.clr-polaroid .clr-gradient{width:calc(100% - 20px);height:120px;margin:10px;border-radius:3px}.clr-polaroid .clr-alpha,.clr-polaroid .clr-hue{width:calc(100% - 30px);height:10px;margin:6px 15px;border-radius:5px}.clr-polaroid .clr-alpha div,.clr-polaroid .clr-hue div{box-shadow:0 0 5px rgba(0,0,0,.2)}.clr-polaroid .clr-format{width:calc(100% - 20px);margin:0 10px 15px}.clr-polaroid .clr-swatches{width:calc(100% - 12px);margin:0 6px}.clr-polaroid .clr-swatches div{padding-bottom:10px}.clr-polaroid .clr-swatches button{width:22px;height:22px}.clr-polaroid input.clr-color{width:calc(100% - 60px);margin:10px 10px 15px auto}.clr-polaroid .clr-clear{margin:0 10px 15px 10px}.clr-polaroid .clr-close{margin:0 10px 15px auto}.clr-polaroid .clr-preview{margin:10px 0 15px 10px}.clr-picker.clr-large{width:275px}.clr-large .clr-gradient{height:150px}.clr-large .clr-swatches button{width:22px;height:22px}.clr-picker.clr-pill{width:380px;padding-left:180px;box-sizing:border-box}.clr-pill .clr-gradient{position:absolute;width:180px;height:100%;left:0;top:0;margin-bottom:0;border-radius:3px 0 0 3px}.clr-pill .clr-hue{margin-top:20px}
+.clr-field {
+ display: block;
+}
+.clr-field button {
+ width: 22px;
+ height: 22px;
+ left: 5px;
+ right: auto;
+ border-radius: 5px;
+}
+
+.clr-field input {
+ padding-right: 30px;
+ max-width:150px;
+ margin-left: auto;
+}
+.clr-field button {
+ right: 5px;
+ left: auto;
+ border-radius: 5px;
+}
diff --git a/public/js/libs/coloris/coloris.min.js b/public/js/libs/coloris/coloris.min.js
new file mode 100644
index 0000000..b0a968e
--- /dev/null
+++ b/public/js/libs/coloris/coloris.min.js
@@ -0,0 +1,6 @@
+/*!
+ * Copyright (c) 2021 Momo Bassit.
+ * Licensed under the MIT License (MIT)
+ * https://github.com/mdbassit/Coloris
+ */
+((e,t,l,a)=>{const r=t.createElement("canvas").getContext("2d"),n={r:0,g:0,b:0,h:0,s:0,v:0,a:1};let o,c,s,i,u,p,d,h,f,b,y,m,g,v,w,k,L={};const E={el:"[data-coloris]",parent:"body",theme:"default",themeMode:"light",rtl:!1,wrap:!0,margin:2,format:"hex",formatToggle:!1,swatches:[],swatchesOnly:!1,alpha:!0,forceAlpha:!1,focusInput:!0,selectInput:!1,inline:!1,defaultColor:"#000000",clearButton:!1,clearLabel:"Clear",closeButton:!1,closeLabel:"Close",onChange:()=>a,a11y:{open:"Open color picker",close:"Close color picker",clear:"Clear the selected color",marker:"Saturation: {s}. Brightness: {v}.",hueSlider:"Hue slider",alphaSlider:"Opacity slider",input:"Color value field",format:"Color format",swatch:"Color swatch",instruction:"Saturation and brightness selector. Use up, down, left and right arrow keys to select."}},x={};let A="",$={},C=!1;function S(l){if("object"==typeof l)for(const r in l)switch(r){case"el":H(l.el),!1!==l.wrap&&D(l.el);break;case"parent":o=l.parent instanceof HTMLElement?l.parent:t.querySelector(l.parent),o&&(o.appendChild(c),E.parent=l.parent,o===t.body&&(o=a));break;case"themeMode":E.themeMode=l.themeMode,"auto"===l.themeMode&&e.matchMedia&&e.matchMedia("(prefers-color-scheme: dark)").matches&&(E.themeMode="dark");case"theme":l.theme&&(E.theme=l.theme),c.className=`clr-picker clr-${E.theme} clr-${E.themeMode}`,E.inline&&O();break;case"rtl":E.rtl=!!l.rtl,Array.from(t.getElementsByClassName("clr-field")).forEach((e=>e.classList.toggle("clr-rtl",E.rtl)));break;case"margin":l.margin*=1,E.margin=isNaN(l.margin)?E.margin:l.margin;break;case"wrap":l.el&&l.wrap&&D(l.el);break;case"formatToggle":E.formatToggle=!!l.formatToggle,Q("clr-format").style.display=E.formatToggle?"block":"none",E.formatToggle&&(E.format="auto");break;case"swatches":if(Array.isArray(l.swatches)){const e=Q("clr-swatches"),a=t.createElement("div");e.textContent="",l.swatches.forEach(((e,l)=>{const r=t.createElement("button");r.setAttribute("type","button"),r.setAttribute("id",`clr-swatch-${l}`),r.setAttribute("aria-labelledby",`clr-swatch-label clr-swatch-${l}`),r.style.color=e,r.textContent=e,a.appendChild(r)})),l.swatches.length&&e.appendChild(a),E.swatches=l.swatches.slice()}break;case"swatchesOnly":E.swatchesOnly=!!l.swatchesOnly,c.setAttribute("data-minimal",E.swatchesOnly);break;case"alpha":E.alpha=!!l.alpha,c.setAttribute("data-alpha",E.alpha);break;case"inline":if(E.inline=!!l.inline,c.setAttribute("data-inline",E.inline),E.inline){const e=l.defaultColor||E.defaultColor;v=Y(e),O(),W(e)}break;case"clearButton":"object"==typeof l.clearButton&&(l.clearButton.label&&(E.clearLabel=l.clearButton.label,d.innerHTML=E.clearLabel),l.clearButton=l.clearButton.show),E.clearButton=!!l.clearButton,d.style.display=E.clearButton?"block":"none";break;case"clearLabel":E.clearLabel=l.clearLabel,d.innerHTML=E.clearLabel;break;case"closeButton":E.closeButton=!!l.closeButton,E.closeButton?c.insertBefore(h,u):u.appendChild(h);break;case"closeLabel":E.closeLabel=l.closeLabel,h.innerHTML=E.closeLabel;break;case"a11y":const n=l.a11y;let i=!1;if("object"==typeof n)for(const e in n)n[e]&&E.a11y[e]&&(E.a11y[e]=n[e],i=!0);if(i){const e=Q("clr-open-label"),t=Q("clr-swatch-label");e.innerHTML=E.a11y.open,t.innerHTML=E.a11y.swatch,h.setAttribute("aria-label",E.a11y.close),d.setAttribute("aria-label",E.a11y.clear),f.setAttribute("aria-label",E.a11y.hueSlider),y.setAttribute("aria-label",E.a11y.alphaSlider),p.setAttribute("aria-label",E.a11y.input),s.setAttribute("aria-label",E.a11y.instruction)}break;default:E[r]=l[r]}}function T(e,t){"string"==typeof e&&"object"==typeof t&&(x[e]=t,C=!0)}function B(e){delete x[e],0===Object.keys(x).length&&(C=!1,e===A&&M())}function M(){Object.keys($).length>0&&(S($),A="",$={})}function H(e){e instanceof HTMLElement&&(e=[e]),Array.isArray(e)?e.forEach((e=>{V(e,"click",N),V(e,"input",j)})):(V(t,"click",e,N),V(t,"input",e,j))}function N(e){E.inline||(!function(e){if(C){const t=["el","wrap","rtl","inline","defaultColor","a11y"];for(let l in x){const a=x[l];if(e.matches(l)){A=l,$={},t.forEach((e=>delete a[e]));for(let e in a)$[e]=Array.isArray(E[e])?E[e].slice():E[e];S(a);break}}}}(e.target),g=e.target,w=g.value,v=Y(w),c.classList.add("clr-open"),O(),W(w),(E.focusInput||E.selectInput)&&(p.focus({preventScroll:!0}),p.setSelectionRange(g.selectionStart,g.selectionEnd)),E.selectInput&&p.select(),(k||E.swatchesOnly)&&J().shift().focus(),g.dispatchEvent(new Event("open",{bubbles:!0})))}function O(){const l=o,a=e.scrollY,r=c.offsetWidth,n=c.offsetHeight,i={left:!1,top:!1};let u,p,d,h={x:0,y:0};if(l&&(u=e.getComputedStyle(l),p=parseFloat(u.marginTop),d=parseFloat(u.borderTopWidth),h=l.getBoundingClientRect(),h.y+=d+a),!E.inline){const e=g.getBoundingClientRect();let o=e.x,s=a+e.y+e.height+E.margin;l?(o-=h.x,s-=h.y,o+r>l.clientWidth&&(o+=e.width-r,i.left=!0),s+n>l.clientHeight-p&&n+E.margin<=e.top-(h.y-a)&&(s-=e.height+n+2*E.margin,i.top=!0),s+=l.scrollTop):(o+r>t.documentElement.clientWidth&&(o+=e.width-r,i.left=!0),s+n-a>t.documentElement.clientHeight&&n+E.margin<=e.top&&(s=a+e.y-n-E.margin,i.top=!0)),c.classList.toggle("clr-left",i.left),c.classList.toggle("clr-top",i.top),c.style.left=`${o}px`,c.style.top=`${s}px`,h.x+=c.offsetLeft,h.y+=c.offsetTop}L={width:s.offsetWidth,height:s.offsetHeight,x:s.offsetLeft+h.x,y:s.offsetTop+h.y}}function D(e){e instanceof HTMLElement?I(e):Array.isArray(e)?e.forEach(I):t.querySelectorAll(e).forEach(I)}function I(e){const l=e.parentNode;if(!l.classList.contains("clr-field")){const a=t.createElement("div");let r="clr-field";(E.rtl||e.classList.contains("clr-rtl"))&&(r+=" clr-rtl"),a.innerHTML='<button type="button" aria-labelledby="clr-open-label"></button>',l.insertBefore(a,e),a.className=r,a.style.color=e.value,a.appendChild(e)}}function j(e){const t=e.target.parentNode;t.classList.contains("clr-field")&&(t.style.color=e.target.value)}function R(e){if(g&&!E.inline){const t=g;e&&(g=a,w!==t.value&&(t.value=w,t.dispatchEvent(new Event("input",{bubbles:!0})))),setTimeout((()=>{w!==t.value&&t.dispatchEvent(new Event("change",{bubbles:!0}))})),c.classList.remove("clr-open"),C&&M(),t.dispatchEvent(new Event("close",{bubbles:!0})),E.focusInput&&t.focus({preventScroll:!0}),g=a}}function W(e){const t=function(e){const t=/^((rgba)|rgb)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i;let l,a;r.fillStyle="#000",r.fillStyle=e,l=t.exec(r.fillStyle),l?a={r:1*l[3],g:1*l[4],b:1*l[5],a:1*l[6]}:(l=r.fillStyle.replace("#","").match(/.{2}/g).map((e=>parseInt(e,16))),a={r:l[0],g:l[1],b:l[2],a:1});return a}(e),a=function(e){const t=e.r/255,a=e.g/255,r=e.b/255,n=l.max(t,a,r),o=l.min(t,a,r),c=n-o,s=n;let i=0,u=0;c&&(n===t&&(i=(a-r)/c),n===a&&(i=2+(r-t)/c),n===r&&(i=4+(t-a)/c),n&&(u=c/n));return i=l.floor(60*i),{h:i<0?i+360:i,s:l.round(100*u),v:l.round(100*s),a:e.a}}(t);U(a.s,a.v),G(t,a),f.value=a.h,c.style.color=`hsl(${a.h}, 100%, 50%)`,b.style.left=a.h/360*100+"%",i.style.left=L.width*a.s/100+"px",i.style.top=L.height-L.height*a.v/100+"px",y.value=100*a.a,m.style.left=100*a.a+"%"}function Y(e){const t=e.substring(0,3).toLowerCase();return"rgb"===t||"hsl"===t?t:"hex"}function q(l){l=l!==a?l:p.value,g&&(g.value=l,g.dispatchEvent(new Event("input",{bubbles:!0}))),E.onChange&&E.onChange.call(e,l,g),t.dispatchEvent(new CustomEvent("coloris:pick",{detail:{color:l,currentEl:g}}))}function F(e,t){const a={h:1*f.value,s:e/L.width*100,v:100-t/L.height*100,a:y.value/100},r=function(e){const t=e.s/100,a=e.v/100;let r=t*a,n=e.h/60,o=r*(1-l.abs(n%2-1)),c=a-r;r+=c,o+=c;const s=l.floor(n)%6,i=[r,o,c,c,o,r][s],u=[o,r,r,o,c,c][s],p=[c,c,o,r,r,o][s];return{r:l.round(255*i),g:l.round(255*u),b:l.round(255*p),a:e.a}}(a);U(a.s,a.v),G(r,a),q()}function U(e,t){let l=E.a11y.marker;e=1*e.toFixed(1),t=1*t.toFixed(1),l=l.replace("{s}",e),l=l.replace("{v}",t),i.setAttribute("aria-label",l)}function X(e){const t=function(e){return{pageX:e.changedTouches?e.changedTouches[0].pageX:e.pageX,pageY:e.changedTouches?e.changedTouches[0].pageY:e.pageY}}(e);let l=t.pageX-L.x,a=t.pageY-L.y;o&&(a+=o.scrollTop),P(l,a),e.preventDefault(),e.stopPropagation()}function P(e,t){e=e<0?0:e>L.width?L.width:e,t=t<0?0:t>L.height?L.height:t,i.style.left=`${e}px`,i.style.top=`${t}px`,F(e,t),i.focus()}function G(e={},a={}){let r=E.format;for(const t in e)n[t]=e[t];for(const e in a)n[e]=a[e];const o=function(e){let t=e.r.toString(16),l=e.g.toString(16),a=e.b.toString(16),r="";e.r<16&&(t="0"+t);e.g<16&&(l="0"+l);e.b<16&&(a="0"+a);if(E.alpha&&(e.a<1||E.forceAlpha)){const t=255*e.a|0;r=t.toString(16),t<16&&(r="0"+r)}return"#"+t+l+a+r}(n),c=o.substring(0,7);switch(i.style.color=c,m.parentNode.style.color=c,m.style.color=o,u.style.color=o,s.style.display="none",s.offsetHeight,s.style.display="",m.nextElementSibling.style.display="none",m.nextElementSibling.offsetHeight,m.nextElementSibling.style.display="","mixed"===r?r=1===n.a?"hex":"rgb":"auto"===r&&(r=v),r){case"hex":p.value=o;break;case"rgb":p.value=function(e){return!E.alpha||1===e.a&&!E.forceAlpha?`rgb(${e.r}, ${e.g}, ${e.b})`:`rgba(${e.r}, ${e.g}, ${e.b}, ${e.a})`}(n);break;case"hsl":p.value=(d=function(e){const t=e.v/100,a=t*(1-e.s/100/2);let r;return a>0&&a<1&&(r=l.round((t-a)/l.min(a,1-a)*100)),{h:e.h,s:r||0,l:l.round(100*a),a:e.a}}(n),!E.alpha||1===d.a&&!E.forceAlpha?`hsl(${d.h}, ${d.s}%, ${d.l}%)`:`hsla(${d.h}, ${d.s}%, ${d.l}%, ${d.a})`)}var d;t.querySelector(`.clr-format [value="${r}"]`).checked=!0}function K(){const e=1*f.value,t=1*i.style.left.replace("px",""),l=1*i.style.top.replace("px","");c.style.color=`hsl(${e}, 100%, 50%)`,b.style.left=e/360*100+"%",F(t,l)}function z(){const e=y.value/100;m.style.left=100*e+"%",G({a:e}),q()}function J(){return Array.from(c.querySelectorAll("input, button")).filter((e=>!!e.offsetWidth))}function Q(e){return t.getElementById(e)}function V(e,t,l,a){const r=Element.prototype.matches||Element.prototype.msMatchesSelector;"string"==typeof l?e.addEventListener(t,(e=>{r.call(e.target,l)&&a.call(e.target,e)})):(a=l,e.addEventListener(t,a))}function Z(e,l){l=l!==a?l:[],"loading"!==t.readyState?e(...l):t.addEventListener("DOMContentLoaded",(()=>{e(...l)}))}NodeList!==a&&NodeList.prototype&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),e.Coloris=(()=>{const e={set:S,wrap:D,close:R,setInstance:T,removeInstance:B,updatePosition:O,ready:Z};function t(e){Z((()=>{e&&("string"==typeof e?H(e):S(e))}))}for(const l in e)t[l]=(...t)=>{Z(e[l],t)};return t})(),Z((function(){o=a,c=t.createElement("div"),c.setAttribute("id","clr-picker"),c.className="clr-picker",c.innerHTML=`<input id="clr-color-value" name="clr-color-value" class="clr-color" type="text" value="" spellcheck="false" aria-label="${E.a11y.input}"><div id="clr-color-area" class="clr-gradient" role="application" aria-label="${E.a11y.instruction}"><div id="clr-color-marker" class="clr-marker" tabindex="0"></div></div><div class="clr-hue"><input id="clr-hue-slider" name="clr-hue-slider" type="range" min="0" max="360" step="1" aria-label="${E.a11y.hueSlider}"><div id="clr-hue-marker"></div></div><div class="clr-alpha"><input id="clr-alpha-slider" name="clr-alpha-slider" type="range" min="0" max="100" step="1" aria-label="${E.a11y.alphaSlider}"><div id="clr-alpha-marker"></div><span></span></div><div id="clr-format" class="clr-format"><fieldset class="clr-segmented"><legend>${E.a11y.format}</legend><input id="clr-f1" type="radio" name="clr-format" value="hex"><label for="clr-f1">Hex</label><input id="clr-f2" type="radio" name="clr-format" value="rgb"><label for="clr-f2">RGB</label><input id="clr-f3" type="radio" name="clr-format" value="hsl"><label for="clr-f3">HSL</label><span></span></fieldset></div><div id="clr-swatches" class="clr-swatches"></div><button type="button" id="clr-clear" class="clr-clear" aria-label="${E.a11y.clear}">${E.clearLabel}</button><div id="clr-color-preview" class="clr-preview"><button type="button" id="clr-close" class="clr-close" aria-label="${E.a11y.close}">${E.closeLabel}</button></div><span id="clr-open-label" hidden>${E.a11y.open}</span><span id="clr-swatch-label" hidden>${E.a11y.swatch}</span>`,t.body.appendChild(c),s=Q("clr-color-area"),i=Q("clr-color-marker"),d=Q("clr-clear"),h=Q("clr-close"),u=Q("clr-color-preview"),p=Q("clr-color-value"),f=Q("clr-hue-slider"),b=Q("clr-hue-marker"),y=Q("clr-alpha-slider"),m=Q("clr-alpha-marker"),H(E.el),D(E.el),V(c,"mousedown",(e=>{c.classList.remove("clr-keyboard-nav"),e.stopPropagation()})),V(s,"mousedown",(e=>{V(t,"mousemove",X)})),V(s,"contextmenu",(e=>{e.preventDefault()})),V(s,"touchstart",(e=>{t.addEventListener("touchmove",X,{passive:!1})})),V(i,"mousedown",(e=>{V(t,"mousemove",X)})),V(i,"touchstart",(e=>{t.addEventListener("touchmove",X,{passive:!1})})),V(p,"change",(e=>{const t=p.value;if(g||E.inline){q(""===t?t:W(t))}})),V(d,"click",(e=>{q(""),R()})),V(h,"click",(e=>{q(),R()})),V(Q("clr-format"),"click",".clr-format input",(e=>{v=e.target.value,G(),q()})),V(c,"click",".clr-swatches button",(e=>{W(e.target.textContent),q(),E.swatchesOnly&&R()})),V(t,"mouseup",(e=>{t.removeEventListener("mousemove",X)})),V(t,"touchend",(e=>{t.removeEventListener("touchmove",X)})),V(t,"mousedown",(e=>{k=!1,c.classList.remove("clr-keyboard-nav"),R()})),V(t,"keydown",(e=>{const t=e.key,l=e.target,a=e.shiftKey;if("Escape"!==t)if("Enter"!==t||"BUTTON"===l.tagName){if(["Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(t)&&(k=!0,c.classList.add("clr-keyboard-nav")),"Tab"===t&&l.matches(".clr-picker *")){const t=J(),r=t.shift(),n=t.pop();a&&l===r?(n.focus(),e.preventDefault()):a||l!==n||(r.focus(),e.preventDefault())}}else R();else R(!0)})),V(t,"click",".clr-field button",(e=>{C&&M(),e.target.nextElementSibling.dispatchEvent(new Event("click",{bubbles:!0}))})),V(i,"keydown",(e=>{const t={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]};Object.keys(t).includes(e.key)&&(!function(e,t){P(1*i.style.left.replace("px","")+e,1*i.style.top.replace("px","")+t)}(...t[e.key]),e.preventDefault())})),V(s,"click",X),V(f,"input",K),V(y,"input",z)}))})(window,document,Math);
diff --git a/public/js/libs/coloris/examples.html b/public/js/libs/coloris/examples.html
new file mode 100644
index 0000000..c0a264b
--- /dev/null
+++ b/public/js/libs/coloris/examples.html
@@ -0,0 +1,146 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>Coloris examples</title>
+ <link rel="stylesheet" type="text/css" href="coloris.min.css">
+ <style type="text/css">
+ @import url(https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap);
+
+ body {
+ height: 120vh;
+ margin: 30px;
+ color: #444;
+ background-color: #fff;
+ font-family: 'Lato', sans-serif;
+ }
+
+ h1 {
+ margin-bottom: 1.5em;
+ }
+
+ input {
+ width: 150px;
+ height: 32px;
+ padding: 0 10px;
+ border: 1px solid #ccc;
+ border-radius: 5px;
+ font-family: inherit;
+ font-size: inherit;
+ font-weight: inherit;
+ box-sizing: border-box;
+ }
+
+ .examples {
+ display: flex;
+ flex-wrap: wrap;
+ }
+
+ .example {
+ flex-shrink: 0;
+ width: 300px;
+ margin-bottom: 30px;
+ }
+
+ .square .clr-field button,
+ .circle .clr-field button {
+ width: 22px;
+ height: 22px;
+ left: 5px;
+ right: auto;
+ border-radius: 5px;
+ }
+
+ .square .clr-field input,
+ .circle .clr-field input {
+ padding-left: 36px;
+ }
+
+ .circle .clr-field button {
+ border-radius: 50%;
+ }
+
+ .full .clr-field button {
+ width: 100%;
+ height: 100%;
+ border-radius: 5px;
+ }
+
+ </style>
+ </head>
+ <body>
+ <a href="https://github.com/mdbassit/Coloris">View <b>Coloris</b> on GitHub</a>
+ <h1>Coloris examples</h1>
+ <div class="examples">
+ <div class="example">
+ <p>Default color thumbnail</p>
+ <input type="text" value="green" data-coloris>
+ </div>
+ <div class="example square">
+ <p>Rounded square thumbnail</p>
+ <input type="text" class="coloris instance1" value="rgb(255, 0, 0)">
+ </div>
+ <div class="example circle">
+ <p>Circular thumbnail</p>
+ <input type="text" class="coloris instance2" value="#cc458faa">
+ </div>
+ <div class="example full">
+ <p>Full size thumbnail</p>
+ <input type="text" class="coloris instance3" value="#ffcc00">
+ </div>
+ <div class="example square" style="position: relative; top: 300px; padding-bottom: 30px;">
+ <p>The dialog will appear on top of this field for lack of space under it.</p>
+ <input type="text" class="coloris" value="#00a5cc">
+ </div>
+ </div>
+ <script type="text/javascript" src="coloris.min.js"></script>
+ <script type="text/javascript">
+
+ /** Default configuration **/
+
+ Coloris({
+ el: '.coloris',
+ swatches: [
+ '#264653',
+ '#2a9d8f',
+ '#e9c46a',
+ '#f4a261',
+ '#e76f51',
+ '#d62828',
+ '#023e8a',
+ '#0077b6',
+ '#0096c7',
+ '#00b4d8',
+ '#48cae4'
+ ]
+ });
+
+ /** Instances **/
+
+ Coloris.setInstance('.instance1', {
+ theme: 'pill',
+ themeMode: 'dark',
+ formatToggle: true,
+ closeButton: true,
+ clearButton: true,
+ swatches: [
+ '#067bc2',
+ '#84bcda',
+ '#80e377',
+ '#ecc30b',
+ '#f37748',
+ '#d56062'
+ ]
+ });
+
+ Coloris.setInstance('.instance2', { theme: 'polaroid' });
+
+ Coloris.setInstance('.instance3', {
+ theme: 'polaroid',
+ swatchesOnly: true
+ });
+
+ </script>
+ </body>
+</html>
diff --git a/public/js/vvvebjs/plugin-coloris.js b/public/js/vvvebjs/plugin-coloris.js
new file mode 100644
index 0000000..5316577
--- /dev/null
+++ b/public/js/vvvebjs/plugin-coloris.js
@@ -0,0 +1,50 @@
+let colorisOptions = {
+ el: '.coloris',
+ theme: 'polaroid',
+// themeMode: 'dark',
+ formatToggle: true,
+// closeButton: true,
+// clearButton: true,
+/*
+ swatches: [
+ '#264653',
+ '#2a9d8f',
+ '#e9c46a',
+ '#f4a261',
+ '#e76f51',
+ '#d62828',
+ '#023e8a',
+ '#0077b6',
+ '#0096c7',
+ '#00b4d8',
+ '#48cae4'
+ ]
+*/
+};
+
+ColorInput = { ...Input, ...{
+
+ events: [
+ ["change", "onChange", "input"],
+ ],
+
+ setValue: function(value) {
+ if (this.element && value) {
+ let input = this.element.querySelector('input');
+ this.element.style.color = value;
+
+ if (input) {
+ input.value = value;//this.rgb2hex(value);
+ }
+ }
+ },
+
+ init: function(data) {
+ this.element = this.render("colorinput", data);
+ //Coloris({ ...colorisOptions, ...{el: this.element.firstElementChild}});
+ return this.element;
+ },
+ }
+};
+
+Coloris(colorisOptions);