|
|
|
@ -1,7 +1,11 @@
|
|
|
|
|
class YJColorPicker {
|
|
|
|
|
constructor(options = {}) {
|
|
|
|
|
let _this = this
|
|
|
|
|
let pickAlphaInput
|
|
|
|
|
let RInput
|
|
|
|
|
let GInput
|
|
|
|
|
let BInput
|
|
|
|
|
let AInput
|
|
|
|
|
|
|
|
|
|
let config = {
|
|
|
|
|
el: options.el,
|
|
|
|
|
size: "mini",
|
|
|
|
@ -12,18 +16,22 @@ class YJColorPicker {
|
|
|
|
|
hasClear: true,
|
|
|
|
|
openPickerAni: 'opacity',
|
|
|
|
|
defaultColor: options.defaultColor,
|
|
|
|
|
pickerInputChange: pickerInputChange,
|
|
|
|
|
startMainCallback: (t) => {
|
|
|
|
|
customizeStyle()
|
|
|
|
|
_this.colorPicker && (_this.colorPicker.picker.style.opacity = 0)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
customizeStyle()
|
|
|
|
|
}, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.el = options.el
|
|
|
|
|
if (options.sure) {
|
|
|
|
|
config.sure = (color) => {
|
|
|
|
|
this.colorPicker.config.defaultColor = this.colorPicker.pickerInput.value
|
|
|
|
|
// this.colorPicker.config.defaultColor = this.colorPicker.pickerInput.value
|
|
|
|
|
let c = Cesium.Color.fromCssColorString(color)
|
|
|
|
|
if (pickAlphaInput) {
|
|
|
|
|
c = c.withAlpha(pickAlphaInput.value / 100)
|
|
|
|
|
this.pickAlphaInputValue = pickAlphaInput.value
|
|
|
|
|
if (AInput) {
|
|
|
|
|
c = c.withAlpha(AInput.value)
|
|
|
|
|
this.pickAlphaInputValue = AInput.value
|
|
|
|
|
}
|
|
|
|
|
color = c.toCssHexString()
|
|
|
|
|
if (typeof options.sure == 'function') {
|
|
|
|
@ -34,8 +42,8 @@ class YJColorPicker {
|
|
|
|
|
}
|
|
|
|
|
if (options.clear) {
|
|
|
|
|
config.clear = () => {
|
|
|
|
|
if (pickAlphaInput) {
|
|
|
|
|
pickAlphaInput.value = this.pickAlphaInputValue = 100
|
|
|
|
|
if (AInput) {
|
|
|
|
|
AInput.value = this.pickAlphaInputValue = 1
|
|
|
|
|
}
|
|
|
|
|
this.colorPicker.config.defaultColor = ''
|
|
|
|
|
customizeStyle()
|
|
|
|
@ -53,7 +61,7 @@ class YJColorPicker {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let CesiumColor
|
|
|
|
|
if(config.defaultColor) {
|
|
|
|
|
if (config.defaultColor) {
|
|
|
|
|
CesiumColor = Cesium.Color.fromCssColorString(config.defaultColor)
|
|
|
|
|
}
|
|
|
|
|
// if (options.predefineColor) {
|
|
|
|
@ -66,42 +74,172 @@ class YJColorPicker {
|
|
|
|
|
customizeStyle()
|
|
|
|
|
|
|
|
|
|
function customizeStyle() {
|
|
|
|
|
if (!_this.colorPicker) {
|
|
|
|
|
if (!_this.colorPicker || !_this.colorPicker.picker) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
let isSubtract = false
|
|
|
|
|
let box = _this.colorPicker.box
|
|
|
|
|
let picker = _this.colorPicker.picker
|
|
|
|
|
let x = box.getBoundingClientRect().x
|
|
|
|
|
let y = box.getBoundingClientRect().y
|
|
|
|
|
let height = 0
|
|
|
|
|
|
|
|
|
|
// if (picker.style.display === 'none') {
|
|
|
|
|
// picker.style.display = 'block'
|
|
|
|
|
// height = picker.offsetHeight
|
|
|
|
|
// console.log('picker.style.display.opacity', picker.style.display.opacity)
|
|
|
|
|
// picker.style.display = 'none'
|
|
|
|
|
// }
|
|
|
|
|
// console.log('===========================================')
|
|
|
|
|
// console.log((y + box.offsetHeight + 4), height, window.innerHeight)
|
|
|
|
|
// if ((y + box.offsetHeight + 4) + height > window.innerHeight) {
|
|
|
|
|
// console.log(y, height)
|
|
|
|
|
// picker.style.top = y - height + 'px'
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// picker.style.top = (y + box.offsetHeight + 4) + 'px'
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
picker.style.left = x + 'px'
|
|
|
|
|
picker.style.minWidth = '325px'
|
|
|
|
|
let pickerContent = picker.getElementsByClassName('ew-color-picker-content')[0]
|
|
|
|
|
// let pickerContent = picker.getElementsByClassName('ew-color-picker-content')[0]
|
|
|
|
|
let pickAlphaSliderBar = picker.getElementsByClassName('ew-alpha-slider-bar')[0]
|
|
|
|
|
if (pickAlphaSliderBar) {
|
|
|
|
|
pickAlphaSliderBar.parentNode.style.width = '16px'
|
|
|
|
|
pickAlphaSliderBar.parentNode.removeChild(pickAlphaSliderBar)
|
|
|
|
|
}
|
|
|
|
|
// let customDivider = document.createElement('span')
|
|
|
|
|
// customDivider.className = 'custom-divider'
|
|
|
|
|
// customDivider.style.margin = '10px 0'
|
|
|
|
|
// pickerContent.parentNode.insertBefore(customDivider, pickerContent.nextSibling)
|
|
|
|
|
|
|
|
|
|
let pickPen = document.createElement('div')
|
|
|
|
|
pickPen.className = 'icon-pen-box'
|
|
|
|
|
pickPen.innerHTML = '<svg class="icon-pen"><use xlink:href="#yj-icon-pen"></use></svg>'
|
|
|
|
|
|
|
|
|
|
/** 为完成、暂时隐藏 *///////
|
|
|
|
|
pickPen.style.display = 'none'
|
|
|
|
|
pickPen.style.cursor = 'unset'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let pickerInput = _this.colorPicker.pickerInput
|
|
|
|
|
pickerInput.parentNode.insertBefore(pickPen, pickerInput)
|
|
|
|
|
pickerInput.style.width = '188px'
|
|
|
|
|
pickerInput.style.display = 'none'
|
|
|
|
|
|
|
|
|
|
let colorInputBox = document.createElement('div')
|
|
|
|
|
let row1Elm = document.createElement('div')
|
|
|
|
|
row1Elm.className = 'row'
|
|
|
|
|
row1Elm.style.margin = '6px 0 0 0'
|
|
|
|
|
row1Elm.innerHTML = `
|
|
|
|
|
<div class="col">R</div>
|
|
|
|
|
<div class="col">G</div>
|
|
|
|
|
<div class="col">B</div>
|
|
|
|
|
<div class="col" style="flex: 0 0 92px;"></div>
|
|
|
|
|
`
|
|
|
|
|
let row2Elm = document.createElement('div')
|
|
|
|
|
row2Elm.className = 'row'
|
|
|
|
|
row2Elm.innerHTML = `
|
|
|
|
|
<div class="col">
|
|
|
|
|
<input type="number" step="1" min="0" max="255">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col">
|
|
|
|
|
<input type="number" step="1" min="0" max="255">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col">
|
|
|
|
|
<input type="number" step="1" min="0" max="255">
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
colorInputBox.appendChild(row1Elm)
|
|
|
|
|
colorInputBox.appendChild(row2Elm)
|
|
|
|
|
let Inputs = row2Elm.getElementsByTagName('input')
|
|
|
|
|
Inputs[0].style.width = '72px'
|
|
|
|
|
Inputs[1].style.width = '72px'
|
|
|
|
|
Inputs[2].style.width = '72px'
|
|
|
|
|
RInput = Inputs[0]
|
|
|
|
|
GInput = Inputs[1]
|
|
|
|
|
BInput = Inputs[2]
|
|
|
|
|
|
|
|
|
|
let dropbtns = picker.getElementsByClassName('ew-color-dropbtns')[0]
|
|
|
|
|
picker.insertBefore(colorInputBox, dropbtns)
|
|
|
|
|
|
|
|
|
|
RInput.addEventListener('blur', (e) => {
|
|
|
|
|
let value = e.target.value
|
|
|
|
|
if (e.target.value || (e.target.dataset.null !== 'undefined' && e.target.dataset.null !== '' && !Boolean(e.target.dataset.null))) {
|
|
|
|
|
value = Number(value)
|
|
|
|
|
if ((e.target.max) && value > Number(e.target.max)) {
|
|
|
|
|
value = Number(e.target.max)
|
|
|
|
|
}
|
|
|
|
|
if ((e.target.min) && value < Number(e.target.min)) {
|
|
|
|
|
value = Number(e.target.min)
|
|
|
|
|
}
|
|
|
|
|
if ((e.target.dataset.min) && value < Number(e.target.dataset.min)) {
|
|
|
|
|
value = Number(e.target.dataset.min)
|
|
|
|
|
}
|
|
|
|
|
RInput.value = parseInt(value)
|
|
|
|
|
_this.colorPicker.hsba = colorRgbaToHsba(`rgb(${RInput.value}, ${GInput.value}, ${BInput.value})`)
|
|
|
|
|
_this.colorPicker.changeColor(_this.colorPicker, _this.colorPicker.pickerPanel.offsetWidth,_this.colorPicker.pickerPanel.offsetHeight)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
GInput.addEventListener('blur', (e) => {
|
|
|
|
|
let value = e.target.value
|
|
|
|
|
if (e.target.value || (e.target.dataset.null !== 'undefined' && e.target.dataset.null !== '' && !Boolean(e.target.dataset.null))) {
|
|
|
|
|
value = Number(value)
|
|
|
|
|
if ((e.target.max) && value > Number(e.target.max)) {
|
|
|
|
|
value = Number(e.target.max)
|
|
|
|
|
}
|
|
|
|
|
if ((e.target.min) && value < Number(e.target.min)) {
|
|
|
|
|
value = Number(e.target.min)
|
|
|
|
|
}
|
|
|
|
|
if ((e.target.dataset.min) && value < Number(e.target.dataset.min)) {
|
|
|
|
|
value = Number(e.target.dataset.min)
|
|
|
|
|
}
|
|
|
|
|
GInput.value = parseInt(value)
|
|
|
|
|
_this.colorPicker.hsba = colorRgbaToHsba(`rgb(${RInput.value}, ${GInput.value}, ${BInput.value})`)
|
|
|
|
|
_this.colorPicker.changeColor(_this.colorPicker, _this.colorPicker.pickerPanel.offsetWidth,_this.colorPicker.pickerPanel.offsetHeight)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
BInput.addEventListener('blur', (e) => {
|
|
|
|
|
let value = e.target.value
|
|
|
|
|
if (e.target.value || (e.target.dataset.null !== 'undefined' && e.target.dataset.null !== '' && !Boolean(e.target.dataset.null))) {
|
|
|
|
|
value = Number(value)
|
|
|
|
|
if ((e.target.max) && value > Number(e.target.max)) {
|
|
|
|
|
value = Number(e.target.max)
|
|
|
|
|
}
|
|
|
|
|
if ((e.target.min) && value < Number(e.target.min)) {
|
|
|
|
|
value = Number(e.target.min)
|
|
|
|
|
}
|
|
|
|
|
if ((e.target.dataset.min) && value < Number(e.target.dataset.min)) {
|
|
|
|
|
value = Number(e.target.dataset.min)
|
|
|
|
|
}
|
|
|
|
|
BInput.value = parseInt(value)
|
|
|
|
|
_this.colorPicker.hsba = colorRgbaToHsba(`rgb(${RInput.value}, ${GInput.value}, ${BInput.value})`)
|
|
|
|
|
_this.colorPicker.changeColor(_this.colorPicker, _this.colorPicker.pickerPanel.offsetWidth,_this.colorPicker.pickerPanel.offsetHeight)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (options.alpha) {
|
|
|
|
|
Inputs[0].style.width = '52px'
|
|
|
|
|
Inputs[1].style.width = '52px'
|
|
|
|
|
Inputs[2].style.width = '52px'
|
|
|
|
|
let pickAlpha = document.createElement('div')
|
|
|
|
|
pickAlpha.className = 'input-number input-number-unit-1 color-alpha'
|
|
|
|
|
pickAlpha.className = 'input-number input-number-unit color-alpha'
|
|
|
|
|
pickAlpha.innerHTML = `
|
|
|
|
|
<input class="input" type="number" title="" step="0.01" min="0" max="100">
|
|
|
|
|
<span class="unit">%</span>
|
|
|
|
|
<input class="input" type="number" title="" step="0.01" min="0" max="1">
|
|
|
|
|
<span class="arrow"></span>`
|
|
|
|
|
pickerInput.parentNode.insertBefore(pickAlpha, pickerInput.nextSibling)
|
|
|
|
|
pickerInput.style.width = '106px'
|
|
|
|
|
pickAlpha.style.width = '80px'
|
|
|
|
|
pickAlphaInput = pickAlpha.getElementsByClassName('input')[0]
|
|
|
|
|
pickAlphaInput.addEventListener('blur', (e) => {
|
|
|
|
|
pickAlpha.style.width = '66px'
|
|
|
|
|
pickAlpha.style.margin = '0 6px 0 0'
|
|
|
|
|
AInput = pickAlpha.getElementsByClassName('input')[0]
|
|
|
|
|
row1Elm.innerHTML = `
|
|
|
|
|
<div class="col">R</div>
|
|
|
|
|
<div class="col">G</div>
|
|
|
|
|
<div class="col">B</div>
|
|
|
|
|
<div class="col">A</div>
|
|
|
|
|
<div class="col" style="flex: 0 0 106px;"></div>
|
|
|
|
|
`
|
|
|
|
|
row2Elm.appendChild(pickAlpha)
|
|
|
|
|
AInput.addEventListener('blur', (e) => {
|
|
|
|
|
let value = e.target.value
|
|
|
|
|
if (e.target.value || (e.target.dataset.null !== 'undefined' && e.target.dataset.null !== '' && !Boolean(e.target.dataset.null))) {
|
|
|
|
|
value = Number(value)
|
|
|
|
@ -114,23 +252,26 @@ class YJColorPicker {
|
|
|
|
|
if ((e.target.dataset.min) && value < Number(e.target.dataset.min)) {
|
|
|
|
|
value = Number(e.target.dataset.min)
|
|
|
|
|
}
|
|
|
|
|
pickAlphaInput.value = Number(value.toFixed(2))
|
|
|
|
|
AInput.value = parseInt(value * 100) / 100
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (_this.pickAlphaInputValue || _this.pickAlphaInputValue === 0 || _this.pickAlphaInputValue === '0') {
|
|
|
|
|
pickAlphaInput.value = Number(Number(_this.pickAlphaInputValue).toFixed(2))
|
|
|
|
|
AInput.value = parseInt(_this.pickAlphaInputValue * 100) / 100
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
pickAlphaInput.value = CesiumColor ? Number((CesiumColor.alpha * 100).toFixed(2)) : 100
|
|
|
|
|
AInput.value = CesiumColor ? parseInt(Number(CesiumColor.alpha.toFixed(2)) * 100) / 100 : 1
|
|
|
|
|
}
|
|
|
|
|
_this.pickAlphaInputValue = pickAlphaInput.value
|
|
|
|
|
box.style.background = Cesium.Color.fromCssColorString(_this.colorPicker.config.defaultColor || '#ffffff').withAlpha(pickAlphaInput.value / 100).toCssColorString()
|
|
|
|
|
_this.pickAlphaInputValue = AInput.value
|
|
|
|
|
box.style.background = Cesium.Color.fromCssColorString(_this.colorPicker.config.defaultColor || '#ffffff').withAlpha(AInput.value).toCssColorString()
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
CesiumColor = CesiumColor ? CesiumColor.withAlpha(1) : ''
|
|
|
|
|
box.style.background = Cesium.Color.fromCssColorString(_this.colorPicker.config.defaultColor || '#ffffff').toCssColorString()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let btngroup = picker.getElementsByClassName('ew-color-dropbtngroup')[0]
|
|
|
|
|
row2Elm.appendChild(btngroup)
|
|
|
|
|
|
|
|
|
|
let defineColorContainer = picker.getElementsByClassName('ew-pre-define-color-container')[0]
|
|
|
|
|
if (defineColorContainer) {
|
|
|
|
|
let colorList = localStorage.getItem('custom-color')
|
|
|
|
@ -157,8 +298,10 @@ class YJColorPicker {
|
|
|
|
|
addColorBtn.className = 'yj-pre-collect-color add'
|
|
|
|
|
|
|
|
|
|
let subtractColorBtn = document.createElement('div')
|
|
|
|
|
subtractColorBtn.innerHTML = '<svg class="icon-minus"><use xlink:href="#yj-icon-minus"></use></svg>'
|
|
|
|
|
subtractColorBtn.innerHTML = '<svg class="icon-minus" style="display: unset;"><use xlink:href="#yj-icon-minus"></use></svg><svg class="icon-confirm" style="display: none;"><use xlink:href="#yj-icom-confirm"></use></svg>'
|
|
|
|
|
subtractColorBtn.className = 'yj-pre-collect-color subtract'
|
|
|
|
|
let minusIcon = subtractColorBtn.getElementsByClassName('icon-minus')[0]
|
|
|
|
|
let confirmIcon = subtractColorBtn.getElementsByClassName('icon-confirm')[0]
|
|
|
|
|
collectColorContainer.appendChild(addColorBtn)
|
|
|
|
|
collectColorContainer.appendChild(subtractColorBtn)
|
|
|
|
|
|
|
|
|
@ -217,8 +360,8 @@ class YJColorPicker {
|
|
|
|
|
|
|
|
|
|
let color = colorRgbaToHex(colorHsbaToRgba(_this.colorPicker.hsba))
|
|
|
|
|
let c = Cesium.Color.fromCssColorString(color || '#ffffff')
|
|
|
|
|
if (pickAlphaInput) {
|
|
|
|
|
c = c.withAlpha(pickAlphaInput.value / 100)
|
|
|
|
|
if (AInput) {
|
|
|
|
|
c = c.withAlpha(AInput.value)
|
|
|
|
|
}
|
|
|
|
|
let colorString = c.toCssHexString()
|
|
|
|
|
colorItemElm.style.backgroundColor = colorString
|
|
|
|
@ -252,23 +395,43 @@ class YJColorPicker {
|
|
|
|
|
subtractColorBtn.addEventListener('click', () => {
|
|
|
|
|
isSubtract = !isSubtract
|
|
|
|
|
if (isSubtract) {
|
|
|
|
|
minusIcon.style.display = 'none'
|
|
|
|
|
confirmIcon.style.display = 'unset'
|
|
|
|
|
for (let i = 0; i < subtractElmList.length; i++) {
|
|
|
|
|
subtractElmList[i].style.display = 'block'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
minusIcon.style.display = 'unset'
|
|
|
|
|
confirmIcon.style.display = 'none'
|
|
|
|
|
for (let i = 0; i < subtractElmList.length; i++) {
|
|
|
|
|
subtractElmList[i].style.display = 'none'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
height = picker.offsetHeight
|
|
|
|
|
if (picker.style.display === 'none') {
|
|
|
|
|
picker.style.display = 'block'
|
|
|
|
|
height = picker.offsetHeight
|
|
|
|
|
picker.style.display = 'none'
|
|
|
|
|
}
|
|
|
|
|
if ((y + box.offsetHeight + 4) + height > window.innerHeight) {
|
|
|
|
|
picker.style.top = y - height + 'px'
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
picker.style.top = (y + box.offsetHeight + 4) + 'px'
|
|
|
|
|
}
|
|
|
|
|
_this.colorPicker.pancelTop = parseFloat(picker.style.top) - 2
|
|
|
|
|
|
|
|
|
|
pickerInputChange(Cesium.Color.fromCssColorString(_this.colorPicker.config.defaultColor || '#ffffff').toCssHexString())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clickDefineColor(color) {
|
|
|
|
|
if (pickAlphaInput) {
|
|
|
|
|
if (AInput) {
|
|
|
|
|
let c = Cesium.Color.fromCssColorString(color)
|
|
|
|
|
pickAlphaInput.value = Number((c.alpha * 100).toFixed(2))
|
|
|
|
|
AInput.value = parseInt(Number(c.alpha.toFixed(2)) * 100) / 100
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -321,6 +484,84 @@ class YJColorPicker {
|
|
|
|
|
"#" + n
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function colorHexToRgba(hex, alpha) {
|
|
|
|
|
let a = alpha || 1,
|
|
|
|
|
hColor = hex.toLowerCase(),
|
|
|
|
|
hLen = hex.length,
|
|
|
|
|
rgbaColor = [];
|
|
|
|
|
hColor = Cesium.Color.fromCssColorString(hColor).toCssHexString().substring(0, 7)
|
|
|
|
|
const colorRegExp = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
|
|
|
|
|
if (hex && colorRegExp.test(hColor)) {
|
|
|
|
|
//the hex length may be 4 or 7,contained the symbol of #
|
|
|
|
|
if (hLen === 4) {
|
|
|
|
|
let hSixColor = '#';
|
|
|
|
|
|
|
|
|
|
for (let i = 1; i < hLen; i++) {
|
|
|
|
|
let sColor = hColor.slice(i, i + 1);
|
|
|
|
|
hSixColor += sColor.concat(sColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hColor = hSixColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (let j = 1, len = hColor.length; j < len; j += 2) {
|
|
|
|
|
rgbaColor.push(parseInt('0X' + hColor.slice(j, j + 2), 16));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// return "rgba(" + rgbaColor.join(",") + ',' + a + ")";
|
|
|
|
|
return rgbaColor;
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function colorRgbaToHsba(e) {
|
|
|
|
|
var t = e.slice(e.indexOf("(") + 1, e.lastIndexOf(")")).split(",")
|
|
|
|
|
, r = t.length < 4 ? 1 : Number(t[3])
|
|
|
|
|
, n = Number(t[0]) / 255
|
|
|
|
|
, o = Number(t[1]) / 255
|
|
|
|
|
, i = Number(t[2]) / 255
|
|
|
|
|
, a = void 0
|
|
|
|
|
, s = void 0
|
|
|
|
|
, l = void 0
|
|
|
|
|
, c = Math.min(n, o, i)
|
|
|
|
|
, d = l = Math.max(n, o, i)
|
|
|
|
|
, u = d - c;
|
|
|
|
|
if (d === c)
|
|
|
|
|
a = 0;
|
|
|
|
|
else {
|
|
|
|
|
switch (d) {
|
|
|
|
|
case n:
|
|
|
|
|
a = (o - i) / u + (o < i ? 6 : 0);
|
|
|
|
|
break;
|
|
|
|
|
case o:
|
|
|
|
|
a = 2 + (i - n) / u;
|
|
|
|
|
break;
|
|
|
|
|
case i:
|
|
|
|
|
a = 4 + (n - o) / u
|
|
|
|
|
}
|
|
|
|
|
a = Math.round(60 * a)
|
|
|
|
|
}
|
|
|
|
|
s = 0 === d ? 0 : 1 - c / d;
|
|
|
|
|
return s = Math.round(100 * s),
|
|
|
|
|
l = Math.round(100 * l),
|
|
|
|
|
{
|
|
|
|
|
h: a,
|
|
|
|
|
s: s,
|
|
|
|
|
b: l,
|
|
|
|
|
a: r
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function pickerInputChange(v) {
|
|
|
|
|
if (_this.colorPicker && _this.colorPicker.pickerInput) {
|
|
|
|
|
let rgbaColor = colorHexToRgba(v || _this.colorPicker.pickerInput.value)
|
|
|
|
|
RInput.value = rgbaColor[0]
|
|
|
|
|
GInput.value = rgbaColor[1]
|
|
|
|
|
BInput.value = rgbaColor[2]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|