mirror of
https://github.com/google/blockly.git
synced 2025-12-16 06:10:12 +01:00
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:
@@ -354,16 +354,15 @@ Blockly.isNumber = function(str) {
|
|||||||
return /^\s*-?\d+(\.\d+)?\s*$/.test(str);
|
return /^\s*-?\d+(\.\d+)?\s*$/.test(str);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// Add a getter for Blockly.hueToHex, for legacy reasons.
|
||||||
* Convert a hue (HSV model) into an RGB hex triplet.
|
Object.defineProperty(Blockly, 'hueToHex', {
|
||||||
* @param {number} hue Hue on a colour wheel (0-360).
|
get: function() {
|
||||||
* @return {string} RGB code, e.g. '#5ba65b'.
|
Blockly.utils.deprecation.warn(
|
||||||
*/
|
'Blockly.hueToHex()', 'September 2021', 'September 2022',
|
||||||
Blockly.hueToHex = function(hue) {
|
'Blockly.utils.colour.hueToHex()');
|
||||||
return Blockly.utils.colour.hsvToHex(
|
return Blockly.utils.colour.hueToHex;
|
||||||
hue, Blockly.internalConstants.HSV_SATURATION,
|
}
|
||||||
Blockly.internalConstants.HSV_VALUE * 255);
|
});
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the parent container. This is the container element that the WidgetDiv,
|
* Set the parent container. This is the container element that the WidgetDiv,
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ ToolboxCategory.prototype.parseColour_ = function(colourValue) {
|
|||||||
} else {
|
} else {
|
||||||
const hue = Number(colour);
|
const hue = Number(colour);
|
||||||
if (!isNaN(hue)) {
|
if (!isNaN(hue)) {
|
||||||
return Blockly.hueToHex(hue);
|
return colourUtils.hueToHex(hue);
|
||||||
} else {
|
} else {
|
||||||
const hex = colourUtils.parse(colour);
|
const hex = colourUtils.parse(colour);
|
||||||
if (hex) {
|
if (hex) {
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
goog.module('Blockly.utils.colour');
|
goog.module('Blockly.utils.colour');
|
||||||
goog.module.declareLegacyNamespace();
|
goog.module.declareLegacyNamespace();
|
||||||
|
|
||||||
|
const internalConstants = goog.require('Blockly.internalConstants');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a colour from a string.
|
* Parses a colour from a string.
|
||||||
@@ -212,3 +214,14 @@ const names = {
|
|||||||
'yellow': '#ffff00'
|
'yellow': '#ffff00'
|
||||||
};
|
};
|
||||||
exports.names = names;
|
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;
|
||||||
|
|||||||
@@ -590,7 +590,8 @@ WorkspaceFactoryController.prototype.loadCategoryByName = function(name) {
|
|||||||
}
|
}
|
||||||
if (!standardCategory.colour && standardCategory.hue !== undefined) {
|
if (!standardCategory.colour && standardCategory.hue !== undefined) {
|
||||||
// Calculate the hex colour based on the hue.
|
// 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
|
// Transfers current flyout blocks to a category if it's the first category
|
||||||
// created.
|
// created.
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ WorkspaceFactoryInit.initColourPicker_ = function(controller) {
|
|||||||
// Convert hue numbers to RRGGBB strings.
|
// Convert hue numbers to RRGGBB strings.
|
||||||
for (var i = 0; i < colours.length; i++) {
|
for (var i = 0; i < colours.length; i++) {
|
||||||
if (colours[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.
|
// Convert to 2D array.
|
||||||
|
|||||||
@@ -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/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.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/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/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/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'});
|
goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
|
||||||
|
|||||||
Reference in New Issue
Block a user