diff --git a/core/blockly.js b/core/blockly.js index dd12f0f1bcb..b916abd6ebf 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -444,6 +444,36 @@ Object.defineProperties(exports, { common.setSelected(newSelection); }, }, + /** + * The richness of block colours, regardless of the hue. + * Must be in the range of 0 (inclusive) to 1 (exclusive). + * @name Blockly.HSV_SATURATION + * @type {number} + * @suppress {checkTypes} + */ + HSV_SATURATION: { + get: function() { + return utils.colour.getHsvSaturation(); + }, + set: function(newValue) { + utils.colour.setHsvSaturation(newValue); + }, + }, + /** + * The intensity of block colours, regardless of the hue. + * Must be in the range of 0 (inclusive) to 1 (exclusive). + * @name Blockly.HSV_VALUE + * @type {number} + * @suppress {checkTypes} + */ + HSV_VALUE: { + get: function() { + return utils.colour.getHsvValue(); + }, + set: function(newValue) { + utils.colour.setHsvValue(newValue); + }, + }, }); /** @@ -639,8 +669,6 @@ exports.COLLAPSE_CHARS = internalConstants.COLLAPSE_CHARS; exports.LONGPRESS = internalConstants.LONGPRESS; exports.SOUND_LIMIT = internalConstants.SOUND_LIMIT; exports.DRAG_STACK = internalConstants.DRAG_STACK; -exports.HSV_SATURATION = internalConstants.HSV_SATURATION; -exports.HSV_VALUE = internalConstants.HSV_VALUE; exports.SPRITE = internalConstants.SPRITE; exports.DRAG_NONE = internalConstants.DRAG_NONE; exports.DRAG_STICKY = internalConstants.DRAG_STICKY; diff --git a/core/internal_constants.js b/core/internal_constants.js index f043fa8b45d..d5952eb05c2 100644 --- a/core/internal_constants.js +++ b/core/internal_constants.js @@ -121,22 +121,6 @@ exports.SOUND_LIMIT = SOUND_LIMIT; const DRAG_STACK = true; exports.DRAG_STACK = DRAG_STACK; -/** - * The richness of block colours, regardless of the hue. - * Must be in the range of 0 (inclusive) to 1 (exclusive). - * @alias Blockly.internalConstants.HSV_SATURATION - */ -const HSV_SATURATION = 0.45; -exports.HSV_SATURATION = HSV_SATURATION; - -/** - * The intensity of block colours, regardless of the hue. - * Must be in the range of 0 (inclusive) to 1 (exclusive). - * @alias Blockly.internalConstants.HSV_VALUE - */ -const HSV_VALUE = 0.65; -exports.HSV_VALUE = HSV_VALUE; - /** * Sprited icons and images. * @alias Blockly.internalConstants.SPRITE diff --git a/core/utils/colour.js b/core/utils/colour.js index 6624732337a..18cbf3b61f9 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -6,21 +6,76 @@ /** * @fileoverview Utility methods for colour manipulation. - * These methods are not specific to Blockly, and could be factored out into - * a JavaScript framework such as Closure. */ 'use strict'; /** * Utility methods for colour manipulation. - * These methods are not specific to Blockly, and could be factored out into - * a JavaScript framework such as Closure. * @namespace Blockly.utils.colour */ goog.module('Blockly.utils.colour'); -const internalConstants = goog.require('Blockly.internalConstants'); +/** + * The richness of block colours, regardless of the hue. + * Must be in the range of 0 (inclusive) to 1 (exclusive). + * @alias Blockly.utils.colour.hsvSaturation + * @package + */ +let hsvSaturation = 0.45; + +/** + * Get the richness of block colours, regardless of the hue. + * @alias Blockly.utils.colour.getHsvSaturation + * @return {number} The current richness. + * @package + */ +const getHsvSaturation = function() { + return hsvSaturation; +}; +exports.getHsvSaturation = getHsvSaturation; + +/** + * Set the richness of block colours, regardless of the hue. + * @param {number} newSaturation The new richness, in the range of 0 + * (inclusive) to 1 (exclusive) + * @alias Blockly.utils.colour.setHsvSaturation + * @package + */ +const setHsvSaturation = function(newSaturation) { + hsvSaturation = newSaturation; +}; +exports.setHsvSaturation = setHsvSaturation; +/** + * The intensity of block colours, regardless of the hue. + * Must be in the range of 0 (inclusive) to 1 (exclusive). + * @alias Blockly.utils.colour.hsvValue + * @package + */ +let hsvValue = 0.65; + +/** + * Get the intensity of block colours, regardless of the hue. + * @alias Blockly.utils.colour.getHsvValue + * @return {number} The current intensity. + * @package + */ +const getHsvValue = function() { + return hsvValue; +}; +exports.getHsvValue = getHsvValue; + +/** + * Set the intensity of block colours, regardless of the hue. + * @param {number} newValue The new intensity, in the range of 0 + * (inclusive) to 1 (exclusive) + * @alias Blockly.utils.colour.setHsvValue + * @package + */ +const setHsvValue = function(newValue) { + hsvValue = newValue; +}; +exports.setHsvValue = setHsvValue; /** * Parses a colour from a string. @@ -228,7 +283,6 @@ exports.names = names; * @alias Blockly.utils.colour.hueToHex */ const hueToHex = function(hue) { - return hsvToHex( - hue, internalConstants.HSV_SATURATION, internalConstants.HSV_VALUE * 255); + return hsvToHex(hue, hsvSaturation, hsvValue * 255); }; exports.hueToHex = hueToHex; diff --git a/core/utils/parsing.js b/core/utils/parsing.js index 9df2bc77713..b8eb9bedfb9 100644 --- a/core/utils/parsing.js +++ b/core/utils/parsing.js @@ -15,7 +15,6 @@ goog.module('Blockly.utils.parsing'); const colourUtils = goog.require('Blockly.utils.colour'); -const internalConstants = goog.require('Blockly.internalConstants'); const stringUtils = goog.require('Blockly.utils.string'); const {Msg} = goog.require('Blockly.Msg'); @@ -243,8 +242,7 @@ const parseBlockColour = function(colour) { return { hue: hue, hex: colourUtils.hsvToHex( - hue, internalConstants.HSV_SATURATION, - internalConstants.HSV_VALUE * 255), + hue, colourUtils.getHsvSaturation(), colourUtils.getHsvValue() * 255), }; } else { const hex = colourUtils.parse(dereferenced);