Migrate core/renderers/geras/path_object.js to goog.module syntax (#5306)

* Migrate core/renderers/geras/path_object.js to goog.module

* Migrate core/renderers/geras/path_object.js to named requires

* clang-format core/renderers/geras/path_object.js
This commit is contained in:
Aaron Dodson
2021-08-09 12:30:07 -07:00
committed by GitHub
parent 0ffdc6106d
commit b5444b4e89
2 changed files with 40 additions and 40 deletions

View File

@@ -11,32 +11,35 @@
'use strict';
goog.provide('Blockly.geras.PathObject');
goog.module('Blockly.geras.PathObject');
goog.module.declareLegacyNamespace();
goog.require('Blockly.blockRendering.PathObject');
goog.require('Blockly.geras.ConstantProvider');
goog.require('Blockly.Theme');
goog.require('Blockly.utils.colour');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.object');
goog.require('Blockly.utils.Svg');
const BasePathObject = goog.require('Blockly.blockRendering.PathObject');
/* eslint-disable-next-line no-unused-vars */
const ConstantProvider = goog.requireType('Blockly.geras.ConstantProvider');
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 dom = goog.require('Blockly.utils.dom');
const object = goog.require('Blockly.utils.object');
/**
* An object that handles creating and setting each of the SVG elements
* used by the renderer.
* @param {!SVGElement} root The root SVG element.
* @param {!Blockly.Theme.BlockStyle} style The style object to use for
* @param {!Theme.BlockStyle} style The style object to use for
* colouring.
* @param {!Blockly.geras.ConstantProvider} constants The renderer's constants.
* @param {!ConstantProvider} constants The renderer's constants.
* @constructor
* @extends {Blockly.blockRendering.PathObject}
* @extends {BasePathObject}
* @package
*/
Blockly.geras.PathObject = function(root, style, constants) {
const PathObject = function(root, style, constants) {
/**
* The renderer's constant provider.
* @type {!Blockly.geras.ConstantProvider}
* @type {!ConstantProvider}
*/
this.constants = constants;
@@ -50,9 +53,8 @@ Blockly.geras.PathObject = function(root, style, constants) {
* @type {SVGElement}
* @package
*/
this.svgPathDark = Blockly.utils.dom.createSvgElement(
Blockly.utils.Svg.PATH,
{'class': 'blocklyPathDark', 'transform': 'translate(1,1)'},
this.svgPathDark = dom.createSvgElement(
Svg.PATH, {'class': 'blocklyPathDark', 'transform': 'translate(1,1)'},
this.svgRoot);
/**
@@ -60,18 +62,16 @@ Blockly.geras.PathObject = function(root, style, constants) {
* @type {!SVGElement}
* @package
*/
this.svgPath = Blockly.utils.dom.createSvgElement(
Blockly.utils.Svg.PATH,
{'class': 'blocklyPath'}, this.svgRoot);
this.svgPath =
dom.createSvgElement(Svg.PATH, {'class': 'blocklyPath'}, this.svgRoot);
/**
* The light path of the block.
* @type {SVGElement}
* @package
*/
this.svgPathLight = Blockly.utils.dom.createSvgElement(
Blockly.utils.Svg.PATH,
{'class': 'blocklyPathLight'}, this.svgRoot);
this.svgPathLight = dom.createSvgElement(
Svg.PATH, {'class': 'blocklyPathLight'}, this.svgRoot);
/**
* The colour of the dark path on the block in '#RRGGBB' format.
@@ -82,18 +82,17 @@ Blockly.geras.PathObject = function(root, style, constants) {
/**
* The style object to use when colouring block paths.
* @type {!Blockly.Theme.BlockStyle}
* @type {!Theme.BlockStyle}
* @package
*/
this.style = style;
};
Blockly.utils.object.inherits(Blockly.geras.PathObject,
Blockly.blockRendering.PathObject);
object.inherits(PathObject, BasePathObject);
/**
* @override
*/
Blockly.geras.PathObject.prototype.setPath = function(mainPath) {
PathObject.prototype.setPath = function(mainPath) {
this.svgPath.setAttribute('d', mainPath);
this.svgPathDark.setAttribute('d', mainPath);
};
@@ -103,14 +102,14 @@ Blockly.geras.PathObject.prototype.setPath = function(mainPath) {
* @param {string} highlightPath The highlight path.
* @package
*/
Blockly.geras.PathObject.prototype.setHighlightPath = function(highlightPath) {
PathObject.prototype.setHighlightPath = function(highlightPath) {
this.svgPathLight.setAttribute('d', highlightPath);
};
/**
* @override
*/
Blockly.geras.PathObject.prototype.flipRTL = function() {
PathObject.prototype.flipRTL = function() {
// Mirror the block's path.
this.svgPath.setAttribute('transform', 'scale(-1 1)');
this.svgPathLight.setAttribute('transform', 'scale(-1 1)');
@@ -120,13 +119,13 @@ Blockly.geras.PathObject.prototype.flipRTL = function() {
/**
* @override
*/
Blockly.geras.PathObject.prototype.applyColour = function(block) {
PathObject.prototype.applyColour = function(block) {
this.svgPathLight.style.display = '';
this.svgPathDark.style.display = '';
this.svgPathLight.setAttribute('stroke', this.style.colourTertiary);
this.svgPathDark.setAttribute('fill', this.colourDark);
Blockly.geras.PathObject.superClass_.applyColour.call(this, block);
PathObject.superClass_.applyColour.call(this, block);
this.svgPath.setAttribute('stroke', 'none');
};
@@ -134,20 +133,19 @@ Blockly.geras.PathObject.prototype.applyColour = function(block) {
/**
* @override
*/
Blockly.geras.PathObject.prototype.setStyle = function(blockStyle) {
PathObject.prototype.setStyle = function(blockStyle) {
this.style = blockStyle;
this.colourDark =
Blockly.utils.colour.blend('#000', this.style.colourPrimary, 0.2) ||
this.colourDark;
colour.blend('#000', this.style.colourPrimary, 0.2) || this.colourDark;
};
/**
* @override
*/
Blockly.geras.PathObject.prototype.updateHighlighted = function(highlighted) {
PathObject.prototype.updateHighlighted = function(highlighted) {
if (highlighted) {
this.svgPath.setAttribute('filter',
'url(#' + this.constants.embossFilterId + ')');
this.svgPath.setAttribute(
'filter', 'url(#' + this.constants.embossFilterId + ')');
this.svgPathLight.style.display = 'none';
} else {
this.svgPath.setAttribute('filter', 'none');
@@ -158,7 +156,7 @@ Blockly.geras.PathObject.prototype.updateHighlighted = function(highlighted) {
/**
* @override
*/
Blockly.geras.PathObject.prototype.updateShadow_ = function(shadow) {
PathObject.prototype.updateShadow_ = function(shadow) {
if (shadow) {
this.svgPathLight.style.display = 'none';
this.svgPathDark.setAttribute('fill', this.style.colourSecondary);
@@ -170,9 +168,11 @@ Blockly.geras.PathObject.prototype.updateShadow_ = function(shadow) {
/**
* @override
*/
Blockly.geras.PathObject.prototype.updateDisabled_ = function(disabled) {
Blockly.geras.PathObject.superClass_.updateDisabled_.call(this, disabled);
PathObject.prototype.updateDisabled_ = function(disabled) {
PathObject.superClass_.updateDisabled_.call(this, disabled);
if (disabled) {
this.svgPath.setAttribute('stroke', 'none');
}
};
exports = PathObject;

View File

@@ -137,7 +137,7 @@ goog.addDependency('../../core/renderers/geras/highlight_constants.js', ['Blockl
goog.addDependency('../../core/renderers/geras/highlighter.js', ['Blockly.geras.Highlighter'], ['Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/geras/info.js', ['Blockly.geras.RenderInfo'], ['Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.geras.InlineInput', 'Blockly.geras.StatementInput', 'Blockly.inputTypes', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/geras/measurables/inputs.js', ['Blockly.geras.InlineInput', 'Blockly.geras.StatementInput'], ['Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.StatementInput', 'Blockly.utils.object']);
goog.addDependency('../../core/renderers/geras/path_object.js', ['Blockly.geras.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.PathObject', 'Blockly.geras.ConstantProvider', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']);
goog.addDependency('../../core/renderers/geras/path_object.js', ['Blockly.geras.PathObject'], ['Blockly.blockRendering.PathObject', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/geras/renderer.js', ['Blockly.geras.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.geras.ConstantProvider', 'Blockly.geras.Drawer', 'Blockly.geras.HighlightConstantProvider', 'Blockly.geras.PathObject', 'Blockly.geras.RenderInfo', 'Blockly.utils.object']);
goog.addDependency('../../core/renderers/measurables/base.js', ['Blockly.blockRendering.Measurable'], ['Blockly.blockRendering.Types']);
goog.addDependency('../../core/renderers/measurables/connections.js', ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object']);