Skip to content

Commit

Permalink
fix: faster transparentize by using string index instead of replace
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 3, 2021
1 parent 69c7354 commit 1801ec8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,12 +946,13 @@ function drawCustomDecoration (decoration, data, decorationColor, editorElement)
* opacity.
*
* @param {string} color the CSS RGB color to transparentize
* @param {number} [opacity=1] the opacity amount
* @param {number} opacity the opacity amount
* @return {string} the transparentized CSS color
* @access private
*/
function transparentize (color, opacity = 1) {
return color.replace('rgb(', 'rgba(').replace(')', `, ${opacity})`)
function transparentize (color, opacity) {
// assumes that color is in form of `rgb(content)` with no spaces around the given value
return `rgba(${color.slice(4, -1)}, ${opacity})`
}

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

0 comments on commit 1801ec8

Please sign in to comment.