mirror of
https://github.com/google/blockly.git
synced 2026-01-04 23:50:12 +01:00
Compatibility for Closure Compiler. (#1240)
This commit is contained in:
25
build.py
25
build.py
@@ -377,31 +377,6 @@ class Gen_compressed(threading.Thread):
|
|||||||
|
|
||||||
code = HEADER + "\n" + json_data["compiledCode"]
|
code = HEADER + "\n" + json_data["compiledCode"]
|
||||||
code = code.replace(remove, "")
|
code = code.replace(remove, "")
|
||||||
|
|
||||||
# Trim down Google's Apache licences.
|
|
||||||
# The Closure Compiler used to preserve these until August 2015.
|
|
||||||
# Delete this in a few months if the licences don't return.
|
|
||||||
LICENSE = re.compile("""/\\*
|
|
||||||
|
|
||||||
[\w ]+
|
|
||||||
|
|
||||||
(Copyright \\d+ Google Inc.)
|
|
||||||
https://developers.google.com/blockly/
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 \(the "License"\);
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
\\*/""")
|
|
||||||
code = re.sub(LICENSE, r"\n// \1 Apache License 2.0", code)
|
|
||||||
|
|
||||||
stats = json_data["statistics"]
|
stats = json_data["statistics"]
|
||||||
original_b = stats["originalSize"]
|
original_b = stats["originalSize"]
|
||||||
compressed_b = stats["compressedSize"]
|
compressed_b = stats["compressedSize"]
|
||||||
|
|||||||
@@ -901,10 +901,8 @@ Blockly.BlockSvg.disposeUiStep_ = function(clone, rtl, start, workspaceScale) {
|
|||||||
var scale = (1 - percent) * workspaceScale;
|
var scale = (1 - percent) * workspaceScale;
|
||||||
clone.setAttribute('transform', 'translate(' + x + ',' + y + ')' +
|
clone.setAttribute('transform', 'translate(' + x + ',' + y + ')' +
|
||||||
' scale(' + scale + ')');
|
' scale(' + scale + ')');
|
||||||
var closure = function() {
|
setTimeout(Blockly.BlockSvg.disposeUiStep_, 10, clone, rtl, start,
|
||||||
Blockly.BlockSvg.disposeUiStep_(clone, rtl, start, workspaceScale);
|
workspaceScale);
|
||||||
};
|
|
||||||
setTimeout(closure, 10);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -949,10 +947,8 @@ Blockly.BlockSvg.connectionUiStep_ = function(ripple, start, workspaceScale) {
|
|||||||
} else {
|
} else {
|
||||||
ripple.setAttribute('r', percent * 25 * workspaceScale);
|
ripple.setAttribute('r', percent * 25 * workspaceScale);
|
||||||
ripple.style.opacity = 1 - percent;
|
ripple.style.opacity = 1 - percent;
|
||||||
var closure = function() {
|
Blockly.BlockSvg.disconnectUiStop_.pid_ = setTimeout(
|
||||||
Blockly.BlockSvg.connectionUiStep_(ripple, start, workspaceScale);
|
Blockly.BlockSvg.connectionUiStep_, 10, ripple, start, workspaceScale);
|
||||||
};
|
|
||||||
Blockly.BlockSvg.disconnectUiStop_.pid_ = setTimeout(closure, 10);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -996,11 +992,10 @@ Blockly.BlockSvg.disconnectUiStep_ = function(group, magnitude, start) {
|
|||||||
var skew = Math.round(Math.sin(percent * Math.PI * WIGGLES) *
|
var skew = Math.round(Math.sin(percent * Math.PI * WIGGLES) *
|
||||||
(1 - percent) * magnitude);
|
(1 - percent) * magnitude);
|
||||||
group.skew_ = 'skewX(' + skew + ')';
|
group.skew_ = 'skewX(' + skew + ')';
|
||||||
var closure = function() {
|
|
||||||
Blockly.BlockSvg.disconnectUiStep_(group, magnitude, start);
|
|
||||||
};
|
|
||||||
Blockly.BlockSvg.disconnectUiStop_.group = group;
|
Blockly.BlockSvg.disconnectUiStop_.group = group;
|
||||||
Blockly.BlockSvg.disconnectUiStop_.pid = setTimeout(closure, 10);
|
Blockly.BlockSvg.disconnectUiStop_.pid =
|
||||||
|
setTimeout(Blockly.BlockSvg.disconnectUiStep_, 10, group, magnitude,
|
||||||
|
start);
|
||||||
}
|
}
|
||||||
group.setAttribute('transform', group.translate_ + group.skew_);
|
group.setAttribute('transform', group.translate_ + group.skew_);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ Blockly.Extensions.MUTATOR_PROPERTIES_ =
|
|||||||
* handlers and mutators. These are applied using Block.applyExtension(), or
|
* handlers and mutators. These are applied using Block.applyExtension(), or
|
||||||
* the JSON "extensions" array attribute.
|
* the JSON "extensions" array attribute.
|
||||||
* @param {string} name The name of this extension.
|
* @param {string} name The name of this extension.
|
||||||
* @param {function} initFn The function to initialize an extended block.
|
* @param {Function} initFn The function to initialize an extended block.
|
||||||
* @throws {Error} if the extension name is empty, the extension is already
|
* @throws {Error} if the extension name is empty, the extension is already
|
||||||
* registered, or extensionFn is not a function.
|
* registered, or extensionFn is not a function.
|
||||||
*/
|
*/
|
||||||
@@ -92,7 +92,7 @@ Blockly.Extensions.registerMixin = function(name, mixinObj) {
|
|||||||
* decompose are defined on the mixin.
|
* decompose are defined on the mixin.
|
||||||
* @param {string} name The name of this mutator extension.
|
* @param {string} name The name of this mutator extension.
|
||||||
* @param {!Object} mixinObj The values to mix in.
|
* @param {!Object} mixinObj The values to mix in.
|
||||||
* @param {function()=} opt_helperFn An optional function to apply after mixing
|
* @param {(function())=} opt_helperFn An optional function to apply after mixing
|
||||||
* in the object.
|
* in the object.
|
||||||
* @param {Array.<string>=} opt_blockList A list of blocks to appear in the
|
* @param {Array.<string>=} opt_blockList A list of blocks to appear in the
|
||||||
* flyout of the mutator dialog.
|
* flyout of the mutator dialog.
|
||||||
@@ -103,8 +103,10 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn,
|
|||||||
var errorPrefix = 'Error when registering mutator "' + name + '": ';
|
var errorPrefix = 'Error when registering mutator "' + name + '": ';
|
||||||
|
|
||||||
// Sanity check the mixin object before registering it.
|
// Sanity check the mixin object before registering it.
|
||||||
Blockly.Extensions.checkHasFunction_(errorPrefix, mixinObj, 'domToMutation');
|
Blockly.Extensions.checkHasFunction_(errorPrefix, mixinObj.domToMutation,
|
||||||
Blockly.Extensions.checkHasFunction_(errorPrefix, mixinObj, 'mutationToDom');
|
'domToMutation');
|
||||||
|
Blockly.Extensions.checkHasFunction_(errorPrefix, mixinObj.mutationToDom,
|
||||||
|
'mutationToDom');
|
||||||
|
|
||||||
var hasMutatorDialog = Blockly.Extensions.checkMutatorDialog_(mixinObj,
|
var hasMutatorDialog = Blockly.Extensions.checkMutatorDialog_(mixinObj,
|
||||||
errorPrefix);
|
errorPrefix);
|
||||||
@@ -162,20 +164,19 @@ Blockly.Extensions.apply = function(name, block, isMutator) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that the given object has a property with the given name, and that the
|
* Check that the given value is a function.
|
||||||
* property is a function.
|
|
||||||
* @param {string} errorPrefix The string to prepend to any error message.
|
* @param {string} errorPrefix The string to prepend to any error message.
|
||||||
* @param {!Object} object The object to check.
|
* @param {*} func Function to check.
|
||||||
* @param {string} propertyName Which property to check.
|
* @param {string} propertyName Which property to check.
|
||||||
* @throws {Error} if the property does not exist or is not a function.
|
* @throws {Error} if the property does not exist or is not a function.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
Blockly.Extensions.checkHasFunction_ = function(errorPrefix, object,
|
Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func,
|
||||||
propertyName) {
|
propertyName) {
|
||||||
if (!object.hasOwnProperty(propertyName)) {
|
if (!func) {
|
||||||
throw new Error(errorPrefix +
|
throw new Error(errorPrefix +
|
||||||
'missing required property "' + propertyName + '"');
|
'missing required property "' + propertyName + '"');
|
||||||
} else if (typeof object[propertyName] !== "function") {
|
} else if (typeof func != 'function') {
|
||||||
throw new Error(errorPrefix +
|
throw new Error(errorPrefix +
|
||||||
'" required property "' + propertyName + '" must be a function');
|
'" required property "' + propertyName + '" must be a function');
|
||||||
}
|
}
|
||||||
@@ -442,5 +443,3 @@ Blockly.Extensions.extensionParentTooltip_ = function() {
|
|||||||
};
|
};
|
||||||
Blockly.Extensions.register('parent_tooltip_when_inline',
|
Blockly.Extensions.register('parent_tooltip_when_inline',
|
||||||
Blockly.Extensions.extensionParentTooltip_);
|
Blockly.Extensions.extensionParentTooltip_);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ goog.require('goog.userAgent');
|
|||||||
* @param {number} width Width of the image.
|
* @param {number} width Width of the image.
|
||||||
* @param {number} height Height of the image.
|
* @param {number} height Height of the image.
|
||||||
* @param {string=} opt_alt Optional alt text for when block is collapsed.
|
* @param {string=} opt_alt Optional alt text for when block is collapsed.
|
||||||
* @param {function=} opt_onClick Optional function to be called when image is clicked
|
* @param {Function=} opt_onClick Optional function to be called when image is clicked
|
||||||
* @extends {Blockly.Field}
|
* @extends {Blockly.Field}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -166,8 +166,9 @@ Blockly.Trashcan.prototype.createDom = function() {
|
|||||||
*/
|
*/
|
||||||
this.svgGroup_ = Blockly.utils.createSvgElement('g',
|
this.svgGroup_ = Blockly.utils.createSvgElement('g',
|
||||||
{'class': 'blocklyTrash'}, null);
|
{'class': 'blocklyTrash'}, null);
|
||||||
|
var clip;
|
||||||
var rnd = String(Math.random()).substring(2);
|
var rnd = String(Math.random()).substring(2);
|
||||||
var clip = Blockly.utils.createSvgElement('clipPath',
|
clip = Blockly.utils.createSvgElement('clipPath',
|
||||||
{'id': 'blocklyTrashBodyClipPath' + rnd},
|
{'id': 'blocklyTrashBodyClipPath' + rnd},
|
||||||
this.svgGroup_);
|
this.svgGroup_);
|
||||||
Blockly.utils.createSvgElement('rect',
|
Blockly.utils.createSvgElement('rect',
|
||||||
@@ -182,7 +183,7 @@ Blockly.Trashcan.prototype.createDom = function() {
|
|||||||
body.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
body.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
||||||
this.workspace_.options.pathToMedia + Blockly.SPRITE.url);
|
this.workspace_.options.pathToMedia + Blockly.SPRITE.url);
|
||||||
|
|
||||||
var clip = Blockly.utils.createSvgElement('clipPath',
|
clip = Blockly.utils.createSvgElement('clipPath',
|
||||||
{'id': 'blocklyTrashLidClipPath' + rnd},
|
{'id': 'blocklyTrashLidClipPath' + rnd},
|
||||||
this.svgGroup_);
|
this.svgGroup_);
|
||||||
Blockly.utils.createSvgElement('rect',
|
Blockly.utils.createSvgElement('rect',
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ Blockly.utils.getInjectionDivXY_ = function(element) {
|
|||||||
var scale = 1;
|
var scale = 1;
|
||||||
while (element) {
|
while (element) {
|
||||||
var xy = Blockly.utils.getRelativeXY(element);
|
var xy = Blockly.utils.getRelativeXY(element);
|
||||||
var scale = Blockly.utils.getScale_(element);
|
scale = Blockly.utils.getScale_(element);
|
||||||
x = (x * scale) + xy.x;
|
x = (x * scale) + xy.x;
|
||||||
y = (y * scale) + xy.y;
|
y = (y * scale) + xy.y;
|
||||||
var classes = element.getAttribute('class') || '';
|
var classes = element.getAttribute('class') || '';
|
||||||
|
|||||||
@@ -1777,7 +1777,6 @@ Blockly.WorkspaceSvg.prototype.cancelCurrentGesture = function() {
|
|||||||
/**
|
/**
|
||||||
* Get the audio manager for this workspace.
|
* Get the audio manager for this workspace.
|
||||||
* @return {Blockly.WorkspaceAudio} The audio manager for this workspace.
|
* @return {Blockly.WorkspaceAudio} The audio manager for this workspace.
|
||||||
* @package
|
|
||||||
*/
|
*/
|
||||||
Blockly.WorkspaceSvg.prototype.getAudioManager = function() {
|
Blockly.WorkspaceSvg.prototype.getAudioManager = function() {
|
||||||
return this.audioManager_;
|
return this.audioManager_;
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ Blockly.Xml.appendDomToWorkspace = function(xml, workspace) {
|
|||||||
var savetab = Blockly.BlockSvg.TAB_WIDTH;
|
var savetab = Blockly.BlockSvg.TAB_WIDTH;
|
||||||
try {
|
try {
|
||||||
Blockly.BlockSvg.TAB_WIDTH = 0;
|
Blockly.BlockSvg.TAB_WIDTH = 0;
|
||||||
var bbox = workspace.getBlocksBoundingBox();
|
bbox = workspace.getBlocksBoundingBox();
|
||||||
} finally {
|
} finally {
|
||||||
Blockly.BlockSvg.TAB_WIDTH = savetab;
|
Blockly.BlockSvg.TAB_WIDTH = savetab;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,9 +115,10 @@ Blockly.ZoomControls.prototype.createDom = function() {
|
|||||||
*/
|
*/
|
||||||
this.svgGroup_ = Blockly.utils.createSvgElement('g',
|
this.svgGroup_ = Blockly.utils.createSvgElement('g',
|
||||||
{'class': 'blocklyZoom'}, null);
|
{'class': 'blocklyZoom'}, null);
|
||||||
|
var clip;
|
||||||
var rnd = String(Math.random()).substring(2);
|
var rnd = String(Math.random()).substring(2);
|
||||||
|
|
||||||
var clip = Blockly.utils.createSvgElement('clipPath',
|
clip = Blockly.utils.createSvgElement('clipPath',
|
||||||
{'id': 'blocklyZoomoutClipPath' + rnd},
|
{'id': 'blocklyZoomoutClipPath' + rnd},
|
||||||
this.svgGroup_);
|
this.svgGroup_);
|
||||||
Blockly.utils.createSvgElement('rect',
|
Blockly.utils.createSvgElement('rect',
|
||||||
@@ -132,7 +133,7 @@ Blockly.ZoomControls.prototype.createDom = function() {
|
|||||||
zoomoutSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
zoomoutSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
||||||
workspace.options.pathToMedia + Blockly.SPRITE.url);
|
workspace.options.pathToMedia + Blockly.SPRITE.url);
|
||||||
|
|
||||||
var clip = Blockly.utils.createSvgElement('clipPath',
|
clip = Blockly.utils.createSvgElement('clipPath',
|
||||||
{'id': 'blocklyZoominClipPath' + rnd},
|
{'id': 'blocklyZoominClipPath' + rnd},
|
||||||
this.svgGroup_);
|
this.svgGroup_);
|
||||||
Blockly.utils.createSvgElement('rect',
|
Blockly.utils.createSvgElement('rect',
|
||||||
@@ -148,7 +149,7 @@ Blockly.ZoomControls.prototype.createDom = function() {
|
|||||||
zoominSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
zoominSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
||||||
workspace.options.pathToMedia + Blockly.SPRITE.url);
|
workspace.options.pathToMedia + Blockly.SPRITE.url);
|
||||||
|
|
||||||
var clip = Blockly.utils.createSvgElement('clipPath',
|
clip = Blockly.utils.createSvgElement('clipPath',
|
||||||
{'id': 'blocklyZoomresetClipPath' + rnd},
|
{'id': 'blocklyZoomresetClipPath' + rnd},
|
||||||
this.svgGroup_);
|
this.svgGroup_);
|
||||||
Blockly.utils.createSvgElement('rect',
|
Blockly.utils.createSvgElement('rect',
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ def string_is_ascii(s):
|
|||||||
return True
|
return True
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def load_constants(filename):
|
def load_constants(filename):
|
||||||
"""Read in constants file, which must be output in every language."""
|
"""Read in constants file, which must be output in every language."""
|
||||||
constant_defs = read_json_file(filename);
|
constant_defs = read_json_file(filename);
|
||||||
@@ -42,7 +42,7 @@ def load_constants(filename):
|
|||||||
for key in constant_defs:
|
for key in constant_defs:
|
||||||
value = constant_defs[key]
|
value = constant_defs[key]
|
||||||
value = value.replace('"', '\\"')
|
value = value.replace('"', '\\"')
|
||||||
constants_text += '\nBlockly.Msg.{0} = \"{1}\";'.format(key, value)
|
constants_text += '\nBlockly.Msg["{0}"] = "{1}";'.format(key, value)
|
||||||
return constants_text
|
return constants_text
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -139,7 +139,7 @@ goog.require('Blockly.Msg');
|
|||||||
value = source_defs[key]
|
value = source_defs[key]
|
||||||
comment = ' // untranslated'
|
comment = ' // untranslated'
|
||||||
value = value.replace('"', '\\"')
|
value = value.replace('"', '\\"')
|
||||||
outfile.write(u'Blockly.Msg.{0} = "{1}";{2}\n'.format(
|
outfile.write(u'Blockly.Msg["{0}"] = "{1}";{2}\n'.format(
|
||||||
key, value, comment))
|
key, value, comment))
|
||||||
|
|
||||||
# Announce any keys defined only for target language.
|
# Announce any keys defined only for target language.
|
||||||
|
|||||||
Reference in New Issue
Block a user