diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 071b21e7d..4f64223d7 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -13,17 +13,17 @@ goog.module('Blockly.blockRendering.ConstantProvider'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.colour'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.svgPaths'); -goog.require('Blockly.utils.userAgent'); - -goog.requireType('Blockly.blockRendering.Debug'); -goog.requireType('Blockly.RenderedConnection'); -goog.requireType('Blockly.Theme'); +/* eslint-disable-next-line no-unused-vars */ +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +const colour = goog.require('Blockly.utils.colour'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const dom = goog.require('Blockly.utils.dom'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const utils = goog.require('Blockly.utils'); /** @@ -223,7 +223,7 @@ const ConstantProvider = function() { */ this.EMPTY_STATEMENT_INPUT_HEIGHT = this.MIN_BLOCK_HEIGHT; - this.START_POINT = Blockly.utils.svgPaths.moveBy(0, 0); + this.START_POINT = svgPaths.moveBy(0, 0); /** * Height of SVG path for jagged teeth at the end of collapsed blocks. @@ -305,7 +305,7 @@ const ConstantProvider = function() { * @type {boolean} */ this.FIELD_TEXT_BASELINE_CENTER = - !Blockly.utils.userAgent.IE && !Blockly.utils.userAgent.EDGE; + !userAgent.IE && !userAgent.EDGE; /** * A dropdown field's border rect height. @@ -586,7 +586,7 @@ ConstantProvider.prototype.init = function() { /** * Refresh constants properties that depend on the theme. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @package */ ConstantProvider.prototype.setTheme = function( @@ -594,7 +594,7 @@ ConstantProvider.prototype.setTheme = function( /** * The block styles map. - * @type {Object} + * @type {Object} * @package */ this.blockStyles = Object.create(null); @@ -609,7 +609,7 @@ ConstantProvider.prototype.setTheme = function( /** * Sets dynamic properties that depend on other values or theme properties. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setDynamicProperties_ = @@ -624,7 +624,7 @@ ConstantProvider.prototype.setDynamicProperties_ = /** * Set constants related to fonts. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setFontConstants_ = function( @@ -639,7 +639,7 @@ ConstantProvider.prototype.setFontConstants_ = function( theme.fontStyle && theme.fontStyle['size'] != undefined ? theme.fontStyle['size'] : this.FIELD_TEXT_FONTSIZE; - var fontMetrics = Blockly.utils.dom.measureFontMetrics('Hg', + var fontMetrics = dom.measureFontMetrics('Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, this.FIELD_TEXT_FONTFAMILY); @@ -650,7 +650,7 @@ ConstantProvider.prototype.setFontConstants_ = function( /** * Set constants from a theme's component styles. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setComponentConstants_ = @@ -672,7 +672,7 @@ ConstantProvider.prototype.setComponentConstants_ = * Get or create a block style based on a single colour value. Generate a name * for the style based on the colour. * @param {string} colour #RRGGBB colour string. - * @return {{style: !Blockly.Theme.BlockStyle, name: string}} An object + * @return {{style: !Theme.BlockStyle, name: string}} An object * containing the style and an autogenerated name for that style. * @package */ @@ -689,7 +689,7 @@ ConstantProvider.prototype.getBlockStyleForColour = /** * Gets the BlockStyle for the given block style name. * @param {?string} blockStyleName The name of the block style. - * @return {!Blockly.Theme.BlockStyle} The named block style, or a default style + * @return {!Theme.BlockStyle} The named block style, or a default style * if no style with the given name was found. */ ConstantProvider.prototype.getBlockStyle = function( @@ -703,7 +703,7 @@ ConstantProvider.prototype.getBlockStyle = function( /** * Create a block style object based on the given colour. * @param {string} colour #RRGGBB colour string. - * @return {!Blockly.Theme.BlockStyle} A populated block style based on the + * @return {!Theme.BlockStyle} A populated block style based on the * given colour. * @protected */ @@ -724,7 +724,7 @@ ConstantProvider.prototype.createBlockStyle_ = function( * hat:(string|undefined) * }} blockStyle A full or partial block style object. - * @return {!Blockly.Theme.BlockStyle} A full block style object, with all + * @return {!Theme.BlockStyle} A full block style object, with all * required properties populated. * @protected */ @@ -732,19 +732,19 @@ ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { /* eslint-disable indent */ // Make a new object with all of the same properties. - var valid = /** @type {!Blockly.Theme.BlockStyle} */ ({}); + var valid = /** @type {!Theme.BlockStyle} */ ({}); if (blockStyle) { - Blockly.utils.object.mixin(valid, blockStyle); + utils.object.mixin(valid, blockStyle); } // Validate required properties. - var parsedColour = Blockly.utils.parseBlockColour( + var parsedColour = utils.parseBlockColour( valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? - Blockly.utils.parseBlockColour(valid['colourSecondary']).hex : + utils.parseBlockColour(valid['colourSecondary']).hex : this.generateSecondaryColour_(valid.colourPrimary); valid.colourTertiary = valid['colourTertiary'] ? - Blockly.utils.parseBlockColour(valid['colourTertiary']).hex : + utils.parseBlockColour(valid['colourTertiary']).hex : this.generateTertiaryColour_(valid.colourPrimary); valid.hat = valid['hat'] || ''; @@ -758,9 +758,9 @@ ConstantProvider.prototype.validatedBlockStyle_ = * @protected */ ConstantProvider.prototype.generateSecondaryColour_ = - function(colour) { + function(inputColour) { /* eslint-disable indent */ - return Blockly.utils.colour.blend('#fff', colour, 0.6) || colour; + return colour.blend('#fff', inputColour, 0.6) || inputColour; }; /* eslint-enable indent */ /** @@ -769,10 +769,9 @@ ConstantProvider.prototype.generateSecondaryColour_ = * @return {string} The generated tertiary colour. * @protected */ -ConstantProvider.prototype.generateTertiaryColour_ = - function(colour) { - /* eslint-disable indent */ - return Blockly.utils.colour.blend('#fff', colour, 0.3) || colour; +ConstantProvider.prototype.generateTertiaryColour_ = function(inputColour) { + /* eslint-disable indent */ + return colour.blend('#fff', inputColour, 0.3) || inputColour; }; /* eslint-enable indent */ @@ -783,13 +782,13 @@ ConstantProvider.prototype.generateTertiaryColour_ = */ ConstantProvider.prototype.dispose = function() { if (this.embossFilter_) { - Blockly.utils.dom.removeNode(this.embossFilter_); + dom.removeNode(this.embossFilter_); } if (this.disabledPattern_) { - Blockly.utils.dom.removeNode(this.disabledPattern_); + dom.removeNode(this.disabledPattern_); } if (this.debugFilter_) { - Blockly.utils.dom.removeNode(this.debugFilter_); + dom.removeNode(this.debugFilter_); } this.cssNode_ = null; }; @@ -804,11 +803,11 @@ ConstantProvider.prototype.makeJaggedTeeth = function() { var width = this.JAGGED_TEETH_WIDTH; var mainPath = - Blockly.utils.svgPaths.line( + svgPaths.line( [ - Blockly.utils.svgPaths.point(width, height / 4), - Blockly.utils.svgPaths.point(-width * 2, height / 2), - Blockly.utils.svgPaths.point(width, height / 4) + svgPaths.point(width, height / 4), + svgPaths.point(-width * 2, height / 2), + svgPaths.point(width, height / 4) ]); return { height: height, @@ -827,11 +826,11 @@ ConstantProvider.prototype.makeStartHat = function() { var width = this.START_HAT_WIDTH; var mainPath = - Blockly.utils.svgPaths.curve('c', + svgPaths.curve('c', [ - Blockly.utils.svgPaths.point(30, -height), - Blockly.utils.svgPaths.point(70, -height), - Blockly.utils.svgPaths.point(width, 0) + svgPaths.point(30, -height), + svgPaths.point(70, -height), + svgPaths.point(width, 0) ]); return { height: height, @@ -864,18 +863,18 @@ ConstantProvider.prototype.makePuzzleTab = function() { var control2Y = halfHeight + 0.5; var control3Y = overlap; // 2.5 - var endPoint1 = Blockly.utils.svgPaths.point(-width, forward * halfHeight); - var endPoint2 = Blockly.utils.svgPaths.point(width, forward * halfHeight); + var endPoint1 = svgPaths.point(-width, forward * halfHeight); + var endPoint2 = svgPaths.point(width, forward * halfHeight); - return Blockly.utils.svgPaths.curve('c', + return svgPaths.curve('c', [ - Blockly.utils.svgPaths.point(0, forward * control1Y), - Blockly.utils.svgPaths.point(-width, back * control2Y), + svgPaths.point(0, forward * control1Y), + svgPaths.point(-width, back * control2Y), endPoint1 ]) + - Blockly.utils.svgPaths.curve('s', + svgPaths.curve('s', [ - Blockly.utils.svgPaths.point(width, back * control3Y), + svgPaths.point(width, back * control3Y), endPoint2 ]); } @@ -905,11 +904,11 @@ ConstantProvider.prototype.makeNotch = function() { var innerWidth = 3; var outerWidth = (width - innerWidth) / 2; function makeMainPath(dir) { - return Blockly.utils.svgPaths.line( + return svgPaths.line( [ - Blockly.utils.svgPaths.point(dir * outerWidth, height), - Blockly.utils.svgPaths.point(dir * innerWidth, 0), - Blockly.utils.svgPaths.point(dir * outerWidth, -height) + svgPaths.point(dir * outerWidth, height), + svgPaths.point(dir * innerWidth, 0), + svgPaths.point(dir * outerWidth, -height) ]); } var pathLeft = makeMainPath(1); @@ -932,11 +931,11 @@ ConstantProvider.prototype.makeNotch = function() { ConstantProvider.prototype.makeInsideCorners = function() { var radius = this.CORNER_RADIUS; - var innerTopLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, - Blockly.utils.svgPaths.point(-radius, radius)); + var innerTopLeftCorner = svgPaths.arc('a', '0 0,0', radius, + svgPaths.point(-radius, radius)); - var innerBottomLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, - Blockly.utils.svgPaths.point(radius, radius)); + var innerBottomLeftCorner = svgPaths.arc('a', '0 0,0', radius, + svgPaths.point(radius, radius)); return { width: radius, @@ -958,31 +957,31 @@ ConstantProvider.prototype.makeOutsideCorners = function() { * @const */ var topLeft = - Blockly.utils.svgPaths.moveBy(0, radius) + - Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(radius, -radius)); + svgPaths.moveBy(0, radius) + + svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(radius, -radius)); /** * SVG path for drawing the rounded top-right corner. * @const */ var topRight = - Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(radius, radius)); /** * SVG path for drawing the rounded bottom-left corner. * @const */ - var bottomLeft = Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(-radius, -radius)); + var bottomLeft = svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(-radius, -radius)); /** * SVG path for drawing the rounded bottom-right corner. * @const */ - var bottomRight = Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(-radius, radius)); + var bottomRight = svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(-radius, radius)); return { topLeft: topLeft, @@ -996,7 +995,7 @@ ConstantProvider.prototype.makeOutsideCorners = function() { /** * Get an object with connection shape and sizing information based on the type * of the connection. - * @param {!Blockly.RenderedConnection} connection The connection to find a + * @param {!RenderedConnection} connection The connection to find a * shape object for * @return {!Object} The shape object for the connection. * @package @@ -1004,11 +1003,11 @@ ConstantProvider.prototype.makeOutsideCorners = function() { ConstantProvider.prototype.shapeFor = function( connection) { switch (connection.type) { - case Blockly.connectionTypes.INPUT_VALUE: - case Blockly.connectionTypes.OUTPUT_VALUE: + case connectionTypes.INPUT_VALUE: + case connectionTypes.OUTPUT_VALUE: return this.PUZZLE_TAB; - case Blockly.connectionTypes.PREVIOUS_STATEMENT: - case Blockly.connectionTypes.NEXT_STATEMENT: + case connectionTypes.PREVIOUS_STATEMENT: + case connectionTypes.NEXT_STATEMENT: return this.NOTCH; default: throw Error('Unknown connection type'); @@ -1032,8 +1031,8 @@ ConstantProvider.prototype.createDom = function(svg, ... filters go here ... */ - this.defs = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.DEFS, {}, svg); + this.defs = dom.createSvgElement( + Svg.DEFS, {}, svg); /* @@ -1048,14 +1047,14 @@ ConstantProvider.prototype.createDom = function(svg, k1="0" k2="1" k3="1" k4="0" /> */ - var embossFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, + var embossFilter = dom.createSvgElement( + Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEGAUSSIANBLUR, + dom.createSvgElement( + Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); - var feSpecularLighting = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FESPECULARLIGHTING, + var feSpecularLighting = dom.createSvgElement( + Svg.FESPECULARLIGHTING, { 'in': 'blur', 'surfaceScale': 1, @@ -1065,19 +1064,19 @@ ConstantProvider.prototype.createDom = function(svg, 'result': 'specOut' }, embossFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEPOINTLIGHT, + dom.createSvgElement( + Svg.FEPOINTLIGHT, {'x': -5000, 'y': -10000, 'z': 20000}, feSpecularLighting); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'specOut', 'in2': 'SourceAlpha', 'operator': 'in', 'result': 'specOut' }, embossFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'SourceGraphic', 'in2': 'specOut', @@ -1097,19 +1096,19 @@ ConstantProvider.prototype.createDom = function(svg, */ - var disabledPattern = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATTERN, + var disabledPattern = dom.createSvgElement( + Svg.PATTERN, { 'id': 'blocklyDisabledPattern' + this.randomIdentifier, 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10 }, this.defs); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern); this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; @@ -1126,8 +1125,8 @@ ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { - var debugFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, { + var debugFilter = dom.createSvgElement( + Svg.FILTER, { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', 'width': '180%', @@ -1136,20 +1135,20 @@ ConstantProvider.prototype.createDebugFilter = }, this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood - var debugComponentTransfer = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, + var debugComponentTransfer = dom.createSvgElement( + Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEFUNCA, + dom.createSvgElement( + Svg.FEFUNCA, {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, debugComponentTransfer); // Color the highlight - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEFLOOD, + dom.createSvgElement( + Svg.FEFLOOD, {'flood-color': '#ff0000', 'flood-opacity': 0.5, 'result': 'outColor'}, debugFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, { + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'outColor', 'in2': 'outBlur', 'operator': 'in',