Skip to content

Commit

Permalink
fix: make transparentize a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Dec 31, 2020
1 parent 22f541f commit 9eb52f1
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default class CanvasDrawer extends Mixin {
*/
getDefaultColor () {
const color = this.retrieveStyleFromDom(['.editor'], 'color', true)
return this.transparentize(color, this.getTextOpacity())
return transparentize(color, this.getTextOpacity())
}

/**
Expand All @@ -208,7 +208,7 @@ export default class CanvasDrawer extends Mixin {
const scopes = token.scopeDescriptor || token.scopes
const color = this.retrieveStyleFromDom(scopes, 'color')

return this.transparentize(color, this.getTextOpacity())
return transparentize(color, this.getTextOpacity())
}

/**
Expand All @@ -233,19 +233,6 @@ export default class CanvasDrawer extends Mixin {
}
}

/**
* Converts a `rgb(...)` color into a `rgba(...)` color with the specified
* opacity.
*
* @param {string} color the CSS RGB color to transparentize
* @param {number} [opacity=1] the opacity amount
* @return {string} the transparentized CSS color
* @access private
*/
transparentize (color, opacity = 1) {
return color.replace('rgb(', 'rgba(').replace(')', `, ${opacity})`)
}

// ######## ######## ### ## ##
// ## ## ## ## ## ## ## ## ##
// ## ## ## ## ## ## ## ## ##
Expand Down Expand Up @@ -740,6 +727,27 @@ export default class CanvasDrawer extends Mixin {
}
}

// ###### ####### ## ####### ######## ######
// ## ## ## ## ## ## ## ## ## ## ##
// ## ## ## ## ## ## ## ## ##
// ## ## ## ## ## ## ######## ######
// ## ## ## ## ## ## ## ## ##
// ## ## ## ## ## ## ## ## ## ## ##
// ###### ####### ######## ####### ## ## ######

/**
* Converts a `rgb(...)` color into a `rgba(...)` color with the specified
* opacity.
*
* @param {string} color the CSS RGB color to transparentize
* @param {number} [opacity=1] the opacity amount
* @return {string} the transparentized CSS color
* @access private
*/
function transparentize (color, opacity = 1) {
return color.replace('rgb(', 'rgba(').replace(')', `, ${opacity})`)
}

// ######## ### ## ## ###### ######## ######
// ## ## ## ## ### ## ## ## ## ## ##
// ## ## ## ## #### ## ## ## ##
Expand Down

0 comments on commit 9eb52f1

Please sign in to comment.