Merge branch 'goog_module' of https://github.com/gonfunko/blockly into dom

This commit is contained in:
Aaron Dodson
2021-07-15 08:34:07 -07:00
10 changed files with 136 additions and 113 deletions

View File

@@ -2,29 +2,6 @@
"rules": {
"curly": ["error"],
"eol-last": ["error"],
// Blockly/Google use 2-space indents.
// Blockly/Google uses +4 space indents for line continuations.
// Ignore default rules for ternary expressions.
"indent": [
"error", 2,
{
"SwitchCase": 1,
"MemberExpression": 2,
"ObjectExpression": 1,
"FunctionDeclaration": {
"body": 1,
"parameters": 2
},
"FunctionExpression": {
"body": 1,
"parameters": 2
},
"CallExpression": {
"arguments": 2
},
"ignoredNodes": ["ConditionalExpression"]
}
],
"keyword-spacing": ["error"],
"linebreak-style": ["error", "unix"],
"max-len": [
@@ -39,7 +16,7 @@
],
"no-trailing-spaces": ["error", { "skipBlankLines": true }],
"no-unused-vars": [
"error",
"warn",
{
"args": "after-used",
// Ignore vars starting with an underscore.
@@ -48,7 +25,6 @@
"argsIgnorePattern": "^_"
}
],
"no-use-before-define": ["error"],
// Blockly uses for exporting symbols. no-self-assign added in eslint 5.
"no-self-assign": ["off"],
// Blockly uses single quotes except for JSON blobs, which must use double quotes.

View File

@@ -16,7 +16,8 @@
* @name Blockly.utils.colour
* @namespace
*/
goog.provide('Blockly.utils.colour');
goog.module('Blockly.utils.colour');
goog.module.declareLegacyNamespace();
/**
@@ -30,9 +31,9 @@ goog.provide('Blockly.utils.colour');
* @return {?string} A string containing a hex representation of the colour,
* or null if can't be parsed.
*/
Blockly.utils.colour.parse = function(str) {
const parse = function(str) {
str = String(str).toLowerCase().trim();
var hex = Blockly.utils.colour.names[str];
let hex = names[str];
if (hex) {
// e.g. 'red'
return hex;
@@ -47,14 +48,14 @@ Blockly.utils.colour.parse = function(str) {
// e.g. '#0f8'
return ['#', hex[1], hex[1], hex[2], hex[2], hex[3], hex[3]].join('');
}
var rgb = str.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);
const rgb = str.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);
if (rgb) {
// e.g. 'rgb(0, 128, 255)'
var r = Number(rgb[1]);
var g = Number(rgb[2]);
var b = Number(rgb[3]);
const r = Number(rgb[1]);
const g = Number(rgb[2]);
const b = Number(rgb[3]);
if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256) {
return Blockly.utils.colour.rgbToHex(r, g, b);
return rgbToHex(r, g, b);
}
}
return null;
@@ -67,8 +68,8 @@ Blockly.utils.colour.parse = function(str) {
* @param {number} b Amount of blue, int between 0 and 255.
* @return {string} Hex representation of the colour.
*/
Blockly.utils.colour.rgbToHex = function(r, g, b) {
var rgb = (r << 16) | (g << 8) | b;
const rgbToHex = function(r, g, b) {
const rgb = (r << 16) | (g << 8) | b;
if (r < 0x10) {
return '#' + (0x1000000 | rgb).toString(16).substr(1);
}
@@ -81,16 +82,16 @@ Blockly.utils.colour.rgbToHex = function(r, g, b) {
* colour format ('#ff0000', 'red', '0xff000', etc).
* @return {!Array<number>} RGB representation of the colour.
*/
Blockly.utils.colour.hexToRgb = function(colour) {
var hex = Blockly.utils.colour.parse(colour);
const hexToRgb = function(colour) {
const hex = parse(colour);
if (!hex) {
return [0, 0, 0];
}
var rgb = parseInt(hex.substr(1), 16);
var r = rgb >> 16;
var g = (rgb >> 8) & 255;
var b = rgb & 255;
const rgb = parseInt(hex.substr(1), 16);
const r = rgb >> 16;
const g = (rgb >> 8) & 255;
const b = rgb & 255;
return [r, g, b];
};
@@ -102,20 +103,20 @@ Blockly.utils.colour.hexToRgb = function(colour) {
* @param {number} v Brightness in [0, 255].
* @return {string} Hex representation of the colour.
*/
Blockly.utils.colour.hsvToHex = function(h, s, v) {
var red = 0;
var green = 0;
var blue = 0;
const hsvToHex = function(h, s, v) {
let red = 0;
let green = 0;
let blue = 0;
if (s == 0) {
red = v;
green = v;
blue = v;
} else {
var sextant = Math.floor(h / 60);
var remainder = (h / 60) - sextant;
var val1 = v * (1 - s);
var val2 = v * (1 - (s * remainder));
var val3 = v * (1 - (s * (1 - remainder)));
const sextant = Math.floor(h / 60);
const remainder = (h / 60) - sextant;
const val1 = v * (1 - s);
const val2 = v * (1 - (s * remainder));
const val3 = v * (1 - (s * (1 - remainder)));
switch (sextant) {
case 1:
red = val2;
@@ -150,8 +151,7 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) {
break;
}
}
return Blockly.utils.colour.rgbToHex(
Math.floor(red), Math.floor(green), Math.floor(blue));
return rgbToHex(Math.floor(red), Math.floor(green), Math.floor(blue));
};
/**
@@ -163,21 +163,21 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) {
* Values should be in the range [0, 1].
* @return {?string} Combined colour represented in hex.
*/
Blockly.utils.colour.blend = function(colour1, colour2, factor) {
var hex1 = Blockly.utils.colour.parse(colour1);
const blend = function(colour1, colour2, factor) {
const hex1 = parse(colour1);
if (!hex1) {
return null;
}
var hex2 = Blockly.utils.colour.parse(colour2);
const hex2 = parse(colour2);
if (!hex2) {
return null;
}
var rgb1 = Blockly.utils.colour.hexToRgb(hex1);
var rgb2 = Blockly.utils.colour.hexToRgb(hex2);
var r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0]));
var g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1]));
var b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2]));
return Blockly.utils.colour.rgbToHex(r, g, b);
const rgb1 = hexToRgb(hex1);
const rgb2 = hexToRgb(hex2);
const r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0]));
const g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1]));
const b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2]));
return rgbToHex(r, g, b);
};
/**
@@ -188,7 +188,7 @@ Blockly.utils.colour.blend = function(colour1, colour2, factor) {
*
* @type {!Object<string, string>}
*/
Blockly.utils.colour.names = {
const names = {
'aqua': '#00ffff',
'black': '#000000',
'blue': '#0000ff',
@@ -206,3 +206,12 @@ Blockly.utils.colour.names = {
'white': '#ffffff',
'yellow': '#ffff00'
};
exports = {
parse,
rgbToHex,
hexToRgb,
hsvToHex,
blend,
names
};

View File

@@ -15,7 +15,8 @@
* @name Blockly.utils.deprecation
* @namespace
*/
goog.provide('Blockly.utils.deprecation');
goog.module('Blockly.utils.deprecation');
goog.module.declareLegacyNamespace();
/**
@@ -29,12 +30,13 @@ goog.provide('Blockly.utils.deprecation');
* if any.
* @package
*/
Blockly.utils.deprecation.warn = function(
name, deprecationDate, deletionDate, opt_use) {
var msg = name + ' was deprecated on ' + deprecationDate +
' and will be deleted on ' + deletionDate + '.';
const warn = function(name, deprecationDate, deletionDate, opt_use) {
let msg = name + ' was deprecated on ' + deprecationDate +
' and will be deleted on ' + deletionDate + '.';
if (opt_use) {
msg += '\nUse ' + opt_use + ' instead.';
}
console.warn(msg);
};
exports = {warn};

View File

@@ -16,7 +16,8 @@
* @name Blockly.utils.IdGenerator
* @namespace
*/
goog.provide('Blockly.utils.IdGenerator');
goog.module('Blockly.utils.IdGenerator');
goog.module.declareLegacyNamespace();
/**
@@ -24,7 +25,7 @@ goog.provide('Blockly.utils.IdGenerator');
* @type {number}
* @private
*/
Blockly.utils.IdGenerator.nextId_ = 0;
let nextId = 0;
/**
* Gets the next unique ID.
@@ -32,6 +33,8 @@ Blockly.utils.IdGenerator.nextId_ = 0;
* Use only ASCII letters, digits, '_', '-' and '.'
* @return {string} The next unique identifier.
*/
Blockly.utils.IdGenerator.getNextUniqueId = function() {
return 'blockly-' + (Blockly.utils.IdGenerator.nextId_++).toString(36);
const getNextUniqueId = function() {
return 'blockly-' + (nextId++).toString(36);
};
exports = {getNextUniqueId};

View File

@@ -16,7 +16,8 @@
* @name Blockly.utils.KeyCodes
* @namespace
*/
goog.provide('Blockly.utils.KeyCodes');
goog.module('Blockly.utils.KeyCodes');
goog.module.declareLegacyNamespace();
/**
@@ -29,7 +30,7 @@ goog.provide('Blockly.utils.KeyCodes');
*
* @enum {number}
*/
Blockly.utils.KeyCodes = {
const KeyCodes = {
WIN_KEY_FF_LINUX: 0,
MAC_ENTER: 3,
BACKSPACE: 8,
@@ -166,3 +167,5 @@ Blockly.utils.KeyCodes = {
// http://en.community.dell.com/support-forums/laptop/f/3518/p/19285957/19523128.aspx
PHANTOM: 255
};
exports = KeyCodes;

View File

@@ -16,7 +16,8 @@
* @name Blockly.utils.math
* @namespace
*/
goog.provide('Blockly.utils.math');
goog.module('Blockly.utils.math');
goog.module.declareLegacyNamespace();
/**
@@ -25,7 +26,7 @@ goog.provide('Blockly.utils.math');
* @param {number} angleDegrees Angle in degrees.
* @return {number} Angle in radians.
*/
Blockly.utils.math.toRadians = function(angleDegrees) {
const toRadians = function(angleDegrees) {
return angleDegrees * Math.PI / 180;
};
@@ -35,7 +36,7 @@ Blockly.utils.math.toRadians = function(angleDegrees) {
* @param {number} angleRadians Angle in radians.
* @return {number} Angle in degrees.
*/
Blockly.utils.math.toDegrees = function(angleRadians) {
const toDegrees = function(angleRadians) {
return angleRadians * 180 / Math.PI;
};
@@ -46,11 +47,17 @@ Blockly.utils.math.toDegrees = function(angleRadians) {
* @param {number} upperBound The desired upper bound.
* @return {number} The clamped number.
*/
Blockly.utils.math.clamp = function(lowerBound, number, upperBound) {
const clamp = function(lowerBound, number, upperBound) {
if (upperBound < lowerBound) {
var temp = upperBound;
const temp = upperBound;
upperBound = lowerBound;
lowerBound = temp;
}
return Math.max(lowerBound, Math.min(number, upperBound));
};
exports = {
toRadians,
toDegrees,
clamp
};

View File

@@ -14,7 +14,8 @@
* @name Blockly.utils.object
* @namespace
*/
goog.provide('Blockly.utils.object');
goog.module('Blockly.utils.object');
goog.module.declareLegacyNamespace();
/**
@@ -23,7 +24,7 @@ goog.provide('Blockly.utils.object');
* @param {!Function} parentCtor Parent class.
* @suppress {strictMissingProperties} superClass_ is not defined on Function.
*/
Blockly.utils.object.inherits = function(childCtor, parentCtor) {
const inherits = function(childCtor, parentCtor) {
// Set a .superClass_ property so that methods can call parent methods
// without hard-coding the parent class name.
// Could be replaced by ES6's super().
@@ -45,8 +46,8 @@ Blockly.utils.object.inherits = function(childCtor, parentCtor) {
* @param {!Object} target Target.
* @param {!Object} source Source.
*/
Blockly.utils.object.mixin = function(target, source) {
for (var x in source) {
const mixin = function(target, source) {
for (const x in source) {
target[x] = source[x];
}
};
@@ -57,11 +58,10 @@ Blockly.utils.object.mixin = function(target, source) {
* @param {!Object} source Source.
* @return {!Object} The resulting object.
*/
Blockly.utils.object.deepMerge = function(target, source) {
for (var x in source) {
const deepMerge = function(target, source) {
for (const x in source) {
if (source[x] != null && typeof source[x] === 'object') {
target[x] = Blockly.utils.object.deepMerge(
target[x] || Object.create(null), source[x]);
target[x] = deepMerge(target[x] || Object.create(null), source[x]);
} else {
target[x] = source[x];
}
@@ -74,7 +74,7 @@ Blockly.utils.object.deepMerge = function(target, source) {
* @param {!Object} obj Object containing values.
* @return {!Array} Array of values.
*/
Blockly.utils.object.values = function(obj) {
const values = function(obj) {
if (Object.values) {
return Object.values(obj);
}
@@ -83,3 +83,10 @@ Blockly.utils.object.values = function(obj) {
return obj[e];
});
};
exports = {
inherits,
mixin,
deepMerge,
values,
};

View File

@@ -16,7 +16,8 @@
* @name Blockly.utils.Rect
* @namespace
*/
goog.provide('Blockly.utils.Rect');
goog.module('Blockly.utils.Rect');
goog.module.declareLegacyNamespace();
/**
@@ -28,7 +29,7 @@ goog.provide('Blockly.utils.Rect');
* @struct
* @constructor
*/
Blockly.utils.Rect = function(top, bottom, left, right) {
const Rect = function(top, bottom, left, right) {
/** @type {number} */
this.top = top;
@@ -49,7 +50,7 @@ Blockly.utils.Rect = function(top, bottom, left, right) {
* @param {number} y The y coordinate to test for containment.
* @return {boolean} Whether this rectangle contains given coordinate.
*/
Blockly.utils.Rect.prototype.contains = function(x, y) {
Rect.prototype.contains = function(x, y) {
return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom;
};
@@ -60,7 +61,10 @@ Blockly.utils.Rect.prototype.contains = function(x, y) {
* intersection with.
* @return {boolean} Whether this rectangle intersects the provided rectangle.
*/
Blockly.utils.Rect.prototype.intersects = function(other) {
return !(this.left > other.right || this.right < other.left ||
Rect.prototype.intersects = function(other) {
return !(
this.left > other.right || this.right < other.left ||
this.top > other.bottom || this.bottom < other.top);
};
exports = Rect;

View File

@@ -15,7 +15,8 @@
* @name Blockly.utils.svgPaths
* @namespace
*/
goog.provide('Blockly.utils.svgPaths');
goog.module('Blockly.utils.svgPaths');
goog.module.declareLegacyNamespace();
/**
@@ -28,7 +29,7 @@ goog.provide('Blockly.utils.svgPaths');
* @return {string} A string of the format ' x,y '
* @public
*/
Blockly.utils.svgPaths.point = function(x, y) {
const point = function(x, y) {
return ' ' + x + ',' + y + ' ';
};
@@ -38,14 +39,14 @@ Blockly.utils.svgPaths.point = function(x, y) {
* These coordinates are unitless and hence in the user coordinate system.
* @param {string} command The command to use.
* Should be one of: c, C, s, S, q, Q.
* @param {!Array<string>} points An array containing all of the points to pass to the
* curve command, in order. The points are represented as strings of the
* format ' x, y '.
* @param {!Array<string>} points An array containing all of the points to pass
* to the curve command, in order. The points are represented as strings of
* the format ' x, y '.
* @return {string} A string defining one or more Bezier curves. See the MDN
* documentation for exact format.
* @public
*/
Blockly.utils.svgPaths.curve = function(command, points) {
const curve = function(command, points) {
return ' ' + command + points.join('');
};
@@ -59,7 +60,7 @@ Blockly.utils.svgPaths.curve = function(command, points) {
* @return {string} A string of the format ' M x,y '
* @public
*/
Blockly.utils.svgPaths.moveTo = function(x, y) {
const moveTo = function(x, y) {
return ' M ' + x + ',' + y + ' ';
};
@@ -73,7 +74,7 @@ Blockly.utils.svgPaths.moveTo = function(x, y) {
* @return {string} A string of the format ' m dx,dy '
* @public
*/
Blockly.utils.svgPaths.moveBy = function(dx, dy) {
const moveBy = function(dx, dy) {
return ' m ' + dx + ',' + dy + ' ';
};
@@ -87,7 +88,7 @@ Blockly.utils.svgPaths.moveBy = function(dx, dy) {
* @return {string} A string of the format ' l dx,dy '
* @public
*/
Blockly.utils.svgPaths.lineTo = function(dx, dy) {
const lineTo = function(dx, dy) {
return ' l ' + dx + ',' + dy + ' ';
};
@@ -102,7 +103,7 @@ Blockly.utils.svgPaths.lineTo = function(dx, dy) {
* @return {string} A string of the format ' l (dx,dy)+ '
* @public
*/
Blockly.utils.svgPaths.line = function(points) {
const line = function(points) {
return ' l' + points.join('');
};
@@ -119,7 +120,7 @@ Blockly.utils.svgPaths.line = function(points) {
* @return {string} A string of the format ' command val '
* @public
*/
Blockly.utils.svgPaths.lineOnAxis = function(command, val) {
const lineOnAxis = function(command, val) {
return ' ' + command + ' ' + val + ' ';
};
@@ -137,6 +138,17 @@ Blockly.utils.svgPaths.lineOnAxis = function(command, val) {
* @return {string} A string of the format 'command radius radius flags point'
* @public
*/
Blockly.utils.svgPaths.arc = function(command, flags, radius, point) {
const arc = function(command, flags, radius, point) {
return command + ' ' + radius + ' ' + radius + ' ' + flags + point;
};
exports = {
point,
curve,
moveTo,
moveBy,
lineTo,
line,
lineOnAxis,
arc,
};

View File

@@ -170,22 +170,22 @@ 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.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'});
goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']);
goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []);
goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []);
goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []);
goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], []);
goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.userAgent'], {'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.Svg', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []);
goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []);
goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []);
goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []);
goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []);
goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], []);
goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []);
goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []);
goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []);
goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']);
goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []);
goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []);
goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']);
goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']);
goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []);