Skip to content

Commit

Permalink
fixes cross platform color mode regression
Browse files Browse the repository at this point in the history
  • Loading branch information
argyleink committed Nov 12, 2020
1 parent cca2583 commit 325a322
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
19 changes: 4 additions & 15 deletions app/components/vis-bug/vis-bug.element.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ import {
constructibleStylesheetSupport
} from '../../utilities/'

const modemap = {
'hex': 'toHexString',
'hsla': 'toHslString',
'rgba': 'toRgbString',
}

export default class VisBug extends HTMLElement {
constructor() {
super()
Expand Down Expand Up @@ -63,7 +57,10 @@ export default class VisBug extends HTMLElement {

setup() {
this.$shadow.innerHTML = this.render()
this._colormode = modemap['hsla']

this.hasAttribute('color-mode')
? this.getAttribute('color-mode')
: this.setAttribute('color-mode', 'hex')

$('li[data-tool]', this.$shadow).on('click', e =>
this.toolSelected(e.currentTarget) && e.stopPropagation())
Expand Down Expand Up @@ -246,14 +243,6 @@ export default class VisBug extends HTMLElement {
get activeTool() {
return this.active_tool.dataset.tool
}

set colorMode(mode) {
this._colormode = modemap[mode]
}

get colorMode() {
return this._colormode
}
}

customElements.define('vis-bug', VisBug)
8 changes: 7 additions & 1 deletion app/features/metatip.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const state = {
tips: new Map(),
}

const modemap = {
'hex': 'toHexString',
'hsl': 'toHslString',
'rgb': 'toRgbString',
}

const services = {}

export function MetaTip(visbug) {
Expand Down Expand Up @@ -131,7 +137,7 @@ export function removeAll() {

const render = (el, tip = document.createElement('visbug-metatip')) => {
const { width, height } = el.getBoundingClientRect()
const colormode = $('vis-bug')[0].colorMode
const colormode = modemap[$('vis-bug').attr('color-mode')]

const styles = getStyles(el)
.map(style => Object.assign(style, {
Expand Down
6 changes: 3 additions & 3 deletions extension/contextmenu/colormode.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const storagekey = 'visbug-color-mode'
const defaultcolormode = 'hsla'
const defaultcolormode = 'hex'

const color_options = [
'hsla',
'hsl',
'hex',
'rgba',
'rgb',
// 'hsv',
// 'lch',
// 'lab',
Expand Down
2 changes: 1 addition & 1 deletion extension/toolbar/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ document.body.prepend(visbug)

platform.runtime.onMessage.addListener(request => {
if (request.action === 'COLOR_MODE')
visbug.colorMode = request.params.mode
visbug.setAttribute('color-mode', request.params.mode)
})

0 comments on commit 325a322

Please sign in to comment.