Migrate Blockly.hueToHex to Blockly.utils.colour.hueToHex (#5462)

* Move hueToHex to core/utils/colour.js

* Mark Blockly.hueToHex as deprecated and pass calls through to Blockly.utils.colour.hueToHex

* Migrate core to use Blockly.utils.colour.hueToHex

* Migrate demos to use Blockly.utils.colour.hueToHex
This commit is contained in:
Aaron Dodson
2021-09-14 14:13:24 -07:00
committed by GitHub
parent d202ae0201
commit 2ba51d4d75
6 changed files with 27 additions and 14 deletions

View File

@@ -354,16 +354,15 @@ Blockly.isNumber = function(str) {
return /^\s*-?\d+(\.\d+)?\s*$/.test(str);
};
/**
* Convert a hue (HSV model) into an RGB hex triplet.
* @param {number} hue Hue on a colour wheel (0-360).
* @return {string} RGB code, e.g. '#5ba65b'.
*/
Blockly.hueToHex = function(hue) {
return Blockly.utils.colour.hsvToHex(
hue, Blockly.internalConstants.HSV_SATURATION,
Blockly.internalConstants.HSV_VALUE * 255);
};
// Add a getter for Blockly.hueToHex, for legacy reasons.
Object.defineProperty(Blockly, 'hueToHex', {
get: function() {
Blockly.utils.deprecation.warn(
'Blockly.hueToHex()', 'September 2021', 'September 2022',
'Blockly.utils.colour.hueToHex()');
return Blockly.utils.colour.hueToHex;
}
});
/**
* Set the parent container. This is the container element that the WidgetDiv,

View File

@@ -428,7 +428,7 @@ ToolboxCategory.prototype.parseColour_ = function(colourValue) {
} else {
const hue = Number(colour);
if (!isNaN(hue)) {
return Blockly.hueToHex(hue);
return colourUtils.hueToHex(hue);
} else {
const hex = colourUtils.parse(colour);
if (hex) {

View File

@@ -19,6 +19,8 @@
goog.module('Blockly.utils.colour');
goog.module.declareLegacyNamespace();
const internalConstants = goog.require('Blockly.internalConstants');
/**
* Parses a colour from a string.
@@ -212,3 +214,14 @@ const names = {
'yellow': '#ffff00'
};
exports.names = names;
/**
* Convert a hue (HSV model) into an RGB hex triplet.
* @param {number} hue Hue on a colour wheel (0-360).
* @return {string} RGB code, e.g. '#5ba65b'.
*/
const hueToHex = function(hue) {
return hsvToHex(
hue, internalConstants.HSV_SATURATION, internalConstants.HSV_VALUE * 255);
};
exports.hueToHex = hueToHex;

View File

@@ -590,7 +590,8 @@ WorkspaceFactoryController.prototype.loadCategoryByName = function(name) {
}
if (!standardCategory.colour && standardCategory.hue !== undefined) {
// Calculate the hex colour based on the hue.
standardCategory.colour = Blockly.hueToHex(standardCategory.hue);
standardCategory.colour = Blockly.utils.colour.hueToHex(
standardCategory.hue);
}
// Transfers current flyout blocks to a category if it's the first category
// created.

View File

@@ -52,7 +52,7 @@ WorkspaceFactoryInit.initColourPicker_ = function(controller) {
// Convert hue numbers to RRGGBB strings.
for (var i = 0; i < colours.length; i++) {
if (colours[i] !== '') {
colours[i] = Blockly.hueToHex(colours[i]).substring(1);
colours[i] = Blockly.utils.colour.hueToHex(colours[i]).substring(1);
}
}
// Convert to 2D array.

View File

@@ -213,7 +213,7 @@ goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Bl
goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.global', 'Blockly.utils.idGenerator', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], ['Blockly.internalConstants'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});