Skip to content

Instantly share code, notes, and snippets.

@atebit
Created April 24, 2024 14:05
Show Gist options
  • Select an option

  • Save atebit/08a9d518516d444b86a7feaa4e8dd718 to your computer and use it in GitHub Desktop.

Select an option

Save atebit/08a9d518516d444b86a7feaa4e8dd718 to your computer and use it in GitHub Desktop.
Javascript Color Contrast Algo
exportColor = (flags) => {
if (!(flags & leaveValue) && valueElement) {
// Implement logic for valueElement
}
let value = this.toString();
if (this.caps) value = value.toUpperCase();
if (this.hash) value = '#' + value;
valueElement.value = value;
if (!(flags & leaveStyle) && styleElement) {
styleElement.style.backgroundImage = "none";
styleElement.style.backgroundColor = '#' + this.toString();
styleElement.style.color = (0.213 * this.rgb[0] + 0.715 * this.rgb[1] + 0.072 * this.rgb[2] < 0.5) ? '#FFF' : '#000';
}
if (!(flags & leavePad) && isPickerOwner()) redrawPad();
if (!(flags & leaveSld) && isPickerOwner()) redrawSld();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment