fix(editor): always use random hex colors
chance.color() can output all valid CSS values for colors, including rgba() syntax and predefined color names. Due to the usage of hex2rgb and other methods, this can break the editor. This commit ensures that all randomly generated colors are specified in hex format. Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
@@ -8,6 +8,7 @@ const config = require('./config')
|
|||||||
exports.generateAvatar = function (name) {
|
exports.generateAvatar = function (name) {
|
||||||
// use darker colors for better contrast
|
// use darker colors for better contrast
|
||||||
const color = new Chance(name).color({
|
const color = new Chance(name).color({
|
||||||
|
format: 'hex',
|
||||||
max_red: 150,
|
max_red: 150,
|
||||||
max_green: 150,
|
max_green: 150,
|
||||||
max_blue: 150
|
max_blue: 150
|
||||||
|
|||||||
@@ -710,7 +710,7 @@ function connection (socket) {
|
|||||||
|
|
||||||
// initialize user data
|
// initialize user data
|
||||||
// random color
|
// random color
|
||||||
let color = chance.color()
|
let color = chance.color({ format: 'hex' })
|
||||||
// make sure color not duplicated or reach max random count
|
// make sure color not duplicated or reach max random count
|
||||||
if (notes[noteId]) {
|
if (notes[noteId]) {
|
||||||
let randomcount = 0
|
let randomcount = 0
|
||||||
@@ -723,7 +723,7 @@ function connection (socket) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (found) {
|
if (found) {
|
||||||
color = chance.color()
|
color = chance.color({ format: 'hex' })
|
||||||
randomcount++
|
randomcount++
|
||||||
}
|
}
|
||||||
} while (found && randomcount < maxrandomcount)
|
} while (found && randomcount < maxrandomcount)
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# Release Notes
|
# Release Notes
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### Bugfixes
|
||||||
|
- Random colors for user's cursors and selections are now always in hex format to avoid conversion errors
|
||||||
|
|
||||||
## <i class="fa fa-tag"></i> 1.10.6 <i class="fa fa-calendar-o"></i> 2026-02-04
|
## <i class="fa fa-tag"></i> 1.10.6 <i class="fa fa-calendar-o"></i> 2026-02-04
|
||||||
|
|
||||||
### Security fixes
|
### Security fixes
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ const supportExtraTags = [
|
|||||||
text: '[random color tag]',
|
text: '[random color tag]',
|
||||||
search: '[]',
|
search: '[]',
|
||||||
command: function () {
|
command: function () {
|
||||||
const color = chance().color()
|
const color = chance().color({ format: 'hex' })
|
||||||
return '[color=' + color + ']'
|
return '[color=' + color + ']'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user