feat: sync mixly root files and common folder

This commit is contained in:
yczpf2019
2026-01-24 16:12:04 +08:00
parent 93e17c00ae
commit c8c5fcf726
2920 changed files with 186461 additions and 0 deletions

View File

@@ -0,0 +1,526 @@
// Copyright 2006 The Closure Library Authors. All Rights Reserved.
//
// 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.
/**
* @fileoverview Bootstrap for the Google JS Library (Closure).
*
* In uncompiled mode base.js will attempt to load Closure's deps file, unless
* the global <code>CLOSURE_NO_DEPS</code> is set to true. This allows projects
* to include their own deps file(s) from different locations.
*
* Avoid including base.js more than once. This is strictly discouraged and not
* supported. goog.require(...) won't work properly in that case.
*
* @provideGoog
*/
/**
* Base namespace for the Closure library. Checks to see goog is already
* defined in the current scope before assigning to prevent clobbering if
* base.js is loaded more than once.
*
* @const
*/
var goog = goog || {};
/**
* Reference to the global object.
* https://www.ecma-international.org/ecma-262/9.0/index.html#sec-global-object
*
* More info on this implementation here:
* https://docs.google.com/document/d/1NAeW4Wk7I7FV0Y2tcUFvQdGMc89k2vdgSXInw8_nvCI/edit
*
* @const
* @suppress {undefinedVars} self won't be referenced unless `this` is falsy.
* @type {!Global}
*/
goog.global =
// Check `this` first for backwards compatibility.
// Valid unless running as an ES module or in a function wrapper called
// without setting `this` properly.
// Note that base.js can't usefully be imported as an ES module, but it may
// be compiled into bundles that are loadable as ES modules.
this ||
// https://developer.mozilla.org/en-US/docs/Web/API/Window/self
// For in-page browser environments and workers.
self;
/**
* Builds an object structure for the provided namespace path, ensuring that
* names that already exist are not overwritten. For example:
* "a.b.c" -> a = {};a.b={};a.b.c={};
* Used by goog.provide and goog.exportSymbol.
* @param {string} name name of the object that this file defines.
* @private
*/
goog.exportPath_ = function(name) {
var parts = name.split('.');
var cur = goog.global;
// Internet Explorer exhibits strange behavior when throwing errors from
// methods externed in this manner. See the testExportSymbolExceptions in
// base_test.html for an example.
if (!(parts[0] in cur) && typeof cur.execScript != 'undefined') {
cur.execScript('var ' + parts[0]);
}
for (var part; parts.length && (part = parts.shift());) {
if (cur[part] && cur[part] !== Object.prototype[part]) {
cur = cur[part];
} else {
cur = cur[part] = {};
}
}
};
/**
* Defines a namespace in Closure.
*
* A namespace may only be defined once in a codebase. It may be defined using
* goog.provide() or goog.module().
*
* The presence of one or more goog.provide() calls in a file indicates
* that the file defines the given objects/namespaces.
* Provided symbols must not be null or undefined.
*
* In addition, goog.provide() creates the object stubs for a namespace
* (for example, goog.provide("goog.foo.bar") will create the object
* goog.foo.bar if it does not already exist).
*
* Build tools also scan for provide/require/module statements
* to discern dependencies, build dependency files (see deps.js), etc.
*
* @see goog.require
* @see goog.module
* @param {string} name Namespace provided by this file in the form
* "goog.package.part".
*/
goog.provide = function(name) {
// Ensure that the same namespace isn't provided twice.
// A goog.module/goog.provide maps a goog.require to a specific file
/*
if (goog.isProvided_(name)) {
throw Error('Namespace "' + name + '" already declared.');
}
delete goog.implicitNamespaces_[name];
*/
var namespace = name;
while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) {
if (goog.getObjectByName(namespace)) {
break;
}
goog.implicitNamespaces_[namespace] = true;
}
goog.exportPath_(name);
};
/**
* @private {?{
* moduleName: (string|undefined),
* declareLegacyNamespace:boolean,
* type: ?goog.ModuleType
* }}
*/
goog.moduleLoaderState_ = null;
/**
* Check if the given name has been goog.provided. This will return false for
* names that are available only as implicit namespaces.
* @param {string} name name of the object to look for.
* @return {boolean} Whether the name has been provided.
* @private
*/
goog.isProvided_ = function(name) {
return (!goog.implicitNamespaces_[name] &&
goog.isDefAndNotNull(goog.getObjectByName(name)));
};
/**
* Namespaces implicitly defined by goog.provide. For example,
* goog.provide('goog.events.Event') implicitly declares that 'goog' and
* 'goog.events' must be namespaces.
*
* @type {!Object<string, (boolean|undefined)>}
* @private
*/
goog.implicitNamespaces_ = {};
// NOTE: We add goog.module as an implicit namespace as goog.module is defined
// here and because the existing module package has not been moved yet out of
// the goog.module namespace. This satisfies both the debug loader and
// ahead-of-time dependency management.
/**
* Returns an object based on its fully qualified external name. The object
* is not found if null or undefined. If you are using a compilation pass that
* renames property names beware that using this function will not find renamed
* properties.
*
* @param {string} name The fully qualified name.
* @param {Object=} opt_obj The object within which to look; default is
* |goog.global|.
* @return {?} The value (object or primitive) or, if not found, null.
*/
goog.getObjectByName = function(name, opt_obj) {
var parts = name.split('.');
var cur = opt_obj || goog.global;
for (var i = 0; i < parts.length; i++) {
cur = cur[parts[i]];
if (!goog.isDefAndNotNull(cur)) {
return null;
}
}
return cur;
};
/**
* Adds a dependency from a file to the files it requires.
* @param {string} relPath The path to the js file.
* @param {!Array<string>} provides An array of strings with
* the names of the objects this file provides.
* @param {!Array<string>} requires An array of strings with
* the names of the objects this file requires.
*/
goog.addDependency = function(relPath, provides, requires) {
goog.debugLoader_.addDependency(relPath, provides, requires);
};
// NOTE(nnaze): The debug DOM loader was included in base.js as an original way
// to do "debug-mode" development. The dependency system can sometimes be
// confusing, as can the debug DOM loader's asynchronous nature.
//
// With the DOM loader, a call to goog.require() is not blocking -- the script
// will not load until some point after the current script. If a namespace is
// needed at runtime, it needs to be defined in a previous script, or loaded via
// require() with its registered dependencies.
//
// User-defined namespaces may need their own deps file. For a reference on
// creating a deps file, see:
// Externally: https://developers.google.com/closure/library/docs/depswriter
//
// Because of legacy clients, the DOM loader can't be easily removed from
// base.js. Work was done to make it disableable or replaceable for
// different environments (DOM-less JavaScript interpreters like Rhino or V8,
// for example). See bootstrap/ for more information.
/**
* Implements a system for the dynamic resolution of dependencies that works in
* parallel with the BUILD system.
*
* Note that all calls to goog.require will be stripped by the compiler.
*
* @see goog.provide
* @param {string} namespace Namespace (as was given in goog.provide,
* goog.module, or goog.declareModuleId) in the form
* "goog.package.part".
* @return {?} If called within a goog.module or ES6 module file, the associated
* namespace or module otherwise null.
*/
goog.require = function(namespace) {
// If the object already exists we do not need to do anything.
if (!goog.isProvided_(namespace)) {
goog.debugLoader_.load_(namespace);
}
return null;
};
/**
* Requires a symbol for its type information. This is an indication to the
* compiler that the symbol may appear in type annotations, yet it is not
* referenced at runtime.
*
* When called within a goog.module or ES6 module file, the return value may be
* assigned to or destructured into a variable, but it may not be otherwise used
* in code outside of a type annotation.
*
* Note that all calls to goog.requireType will be stripped by the compiler.
*
* @param {string} namespace Namespace (as was given in goog.provide,
* goog.module, or goog.declareModuleId) in the form
* "goog.package.part".
* @return {?}
*/
goog.requireType = function(namespace) {
// Return an empty object so that single-level destructuring of the return
// value doesn't crash at runtime when using the debug loader. Multi-level
// destructuring isn't supported.
return {};
};
/**
* Path for included scripts.
* @type {string}
*/
goog.basePath = '';
/**
* Normalize a file path by removing redundant ".." and extraneous "." file
* path components.
* @param {string} path
* @return {string}
* @private
*/
goog.normalizePath_ = function(path) {
var components = path.split('/');
var i = 0;
while (i < components.length) {
if (components[i] == '.') {
components.splice(i, 1);
} else if (
i && components[i] == '..' && components[i - 1] &&
components[i - 1] != '..') {
components.splice(--i, 2);
} else {
i++;
}
}
return components.join('/');
};
//==============================================================================
// Language Enhancements
//==============================================================================
/**
* Returns true if the specified value is defined and not null.
* @param {?} val Variable to test.
* @return {boolean} Whether variable is defined and not null.
*/
goog.isDefAndNotNull = function(val) {
// Note that undefined == null.
return val != null;
};
//==============================================================================
// goog.defineClass implementation
//==============================================================================
// There's a bug in the compiler where without collapse properties the
// Closure namespace defines do not guard code correctly. To help reduce code
// size also check for !COMPILED even though it redundant until this is fixed.
/**
* Tries to detect the base path of base.js script that bootstraps Closure.
* @private
*/
goog.findBasePath_ = function() {
/** @type {!Document} */
var doc = goog.global.document;
// If we have a currentScript available, use it exclusively.
var currentScript = doc.currentScript;
if (currentScript) {
var scripts = [currentScript];
} else {
var scripts = doc.getElementsByTagName('SCRIPT');
}
// Search backwards since the current script is in almost all cases the one
// that has base.js.
for (var i = scripts.length - 1; i >= 0; --i) {
var script = /** @type {!HTMLScriptElement} */ (scripts[i]);
var src = script.src;
var qmark = src.lastIndexOf('?');
var l = qmark == -1 ? src.length : qmark;
if (src.substr(l - 7, 7) == 'base.js') {
goog.basePath = src.substr(0, l - 7);
return;
}
}
};
goog.findBasePath_();
/**
* A debug loader is responsible for downloading and executing javascript
* files in an unbundled, uncompiled environment.
*
* @struct @constructor @final @private
*/
goog.DebugLoader_ = function() {
/** @private @const {!Object<string, !goog.Dependency>} */
this.dependencies_ = {};
/** @private @const {!Object<string, string>} */
this.idToPath_ = {};
/** @private @const {!Object<string, boolean>} */
this.written_ = {};
/** @private {!Array<!goog.Dependency>} */
this.depsToLoad_ = [];
};
/**
* Travserses the dependency graph and queues the given dependency, and all of
* its transitive dependencies, for loading and then starts loading if not
* paused.
*
* @param {string} namespace
* @private
*/
goog.DebugLoader_.prototype.load_ = function(namespace) {
if (!this.getPathFromDeps_(namespace)) {
throw Error('goog.require could not find: ' + namespace);
} else {
var loader = this;
var deps = [];
/** @param {string} namespace */
var visit = function(namespace) {
var path = loader.getPathFromDeps_(namespace);
if (!path) {
throw Error('Bad dependency path or symbol: ' + namespace);
}
if (loader.written_[path]) {
return;
}
loader.written_[path] = true;
var dep = loader.dependencies_[path];
for (var i = 0; i < dep.requires.length; i++) {
if (!goog.isProvided_(dep.requires[i])) {
visit(dep.requires[i]);
}
}
deps.push(dep);
};
visit(namespace);
var wasLoading = !!this.depsToLoad_.length;
this.depsToLoad_ = this.depsToLoad_.concat(deps);
if (!wasLoading) {
this.loadDeps_();
}
}
};
/**
* Loads any queued dependencies until they are all loaded or paused.
*
* @private
*/
goog.DebugLoader_.prototype.loadDeps_ = async function() {
var loader = this;
var depsPath = [];
var namespacePath = '';
if (!this.depsToLoad_.length) {
return;
}
for (var dep of this.depsToLoad_) {
depsPath.push(dep.path);
}
namespacePath = depsPath.pop();
LazyLoad.js(depsPath, function() {
LazyLoad.js(namespacePath);
});
};
/**
* @param {string} absPathOrId
* @return {?string}
* @private
*/
goog.DebugLoader_.prototype.getPathFromDeps_ = function(absPathOrId) {
return this.idToPath_[absPathOrId];
};
/**
* Basic super class for all dependencies Closure Library can load.
*
* This default implementation is designed to load untranspiled, non-module
* scripts in a web broswer.
*
* For transpiled non-goog.module files {@see goog.TranspiledDependency}.
* For goog.modules see {@see goog.GoogModuleDependency}.
* For untranspiled ES6 modules {@see goog.Es6ModuleDependency}.
*
* @param {string} path Absolute path of this script.
* @param {!Array<string>} requires goog symbols or relative paths to Closure
* this depends on.
* @struct @constructor
*/
goog.Dependency = function(path, requires) {
/** @const */
this.path = path;
/** @const */
this.requires = requires;
};
/**
* Map of script ready / state change callbacks. Old IE cannot handle putting
* these properties on goog.global.
*
* @private @const {!Object<string, function(?):undefined>}
*/
goog.Dependency.callbackMap_ = {};
/**
* Starts loading this dependency. This dependency can pause loading if it
* needs to and resume it later via the controller interface.
*
* When this is loaded it should call controller.loaded(). Note that this will
* end up calling the loaded method of this dependency; there is no need to
* call it explicitly.
*/
goog.Dependency.prototype.load = function() {
/** @type {!HTMLDocument} */
var doc = goog.global.document;
doc.write('<script src="' + this.path + '" type="text/javascript"><' +
'/script>');
};
/**
* @param {string} relPath
* @param {!Array<string>|undefined} provides
* @param {!Array<string>} requires
* @see goog.addDependency
*/
goog.DebugLoader_.prototype.addDependency = function(
relPath, provides, requires) {
relPath = relPath.replace(/\\/g, '/');
var path = goog.normalizePath_(goog.basePath + relPath);
var dep = new goog.Dependency(path, requires);
this.dependencies_[path] = dep;
for (var i = 0; i < provides.length; i++) {
this.idToPath_[provides[i]] = path;
}
this.idToPath_[relPath] = path;
};
/** @private @const */
goog.debugLoader_ = new goog.DebugLoader_();

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
/*! For license information please see index.js.LICENSE.txt */
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("blockly/core"));else if("function"==typeof define&&define.amd)define(["blockly/core"],e);else{var s="object"==typeof exports?e(require("blockly/core")):e(t.Blockly);for(var i in s)("object"==typeof exports?exports:t)[i]=s[i]}}(this,(t=>(()=>{"use strict";var e={370:e=>{e.exports=t}},s={};function i(t){var o=s[t];if(void 0!==o)return o.exports;var r=s[t]={exports:{}};return e[t](r,r.exports,i),r.exports}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};i.r(o),i.d(o,{ContentHighlight:()=>h});var r=i(370);const n=[r.Events.VIEWPORT_CHANGE,r.Events.BLOCK_MOVE,r.Events.BLOCK_DELETE,r.Events.COMMENT_MOVE,r.Events.COMMENT_CREATE,r.Events.COMMENT_DELETE];class h{constructor(t){this.workspace=t,this.width=0,this.height=0,this.top=0,this.left=0,this.lastScale=1,this.padding=10,this.theme="#ffffff",this.workspace=t}init(t){this.padding=t||10,this.svgGroup=r.utils.dom.createSvgElement(r.utils.Svg.G,{class:"contentAreaHighlight"},null);const e=String(Math.random()).substring(2),s=r.utils.dom.createSvgElement(new r.utils.Svg("mask"),{id:"contentAreaHighlightMask"+e},this.svgGroup);r.utils.dom.createSvgElement(r.utils.Svg.RECT,{x:0,y:0,width:"100%",height:"100%",fill:"white"},s),this.rect=r.utils.dom.createSvgElement(r.utils.Svg.RECT,{x:0,y:0,rx:r.bubbles.Bubble.BORDER_WIDTH,ry:r.bubbles.Bubble.BORDER_WIDTH,fill:"black"},s),this.background=r.utils.dom.createSvgElement(r.utils.Svg.RECT,{x:0,y:0,width:"100%",height:"100%",mask:`url(#contentAreaHighlightMask${e})`},this.svgGroup);const i=this.workspace.getTheme();this.theme=i.getComponentStyle("workspaceBackgroundColour")||"#ffffff",this.applyColor();const o=this.workspace.getMetricsManager();this.cachedContentMetrics=o.getContentMetrics(!0),this.resize(this.cachedContentMetrics);const n=o.getAbsoluteMetrics();this.position(this.cachedContentMetrics,n),this.svgGroup.style.transition="opacity 0.25s";const h=this.workspace.getParentSvg();h.firstChild?h.insertBefore(this.svgGroup,h.firstChild):h.appendChild(this.svgGroup),this.onChangeWrapper=this.onChange.bind(this),this.workspace.addChangeListener(this.onChangeWrapper)}dispose(){this.svgGroup&&r.utils.dom.removeNode(this.svgGroup),this.onChangeWrapper&&this.workspace.removeChangeListener(this.onChangeWrapper)}onChange(t){if(t.type===r.Events.THEME_CHANGE)this.applyColor();else if(-1!==n.indexOf(t.type)){const e=this.workspace.getMetricsManager();t.type!==r.Events.VIEWPORT_CHANGE&&(this.cachedContentMetrics=e.getContentMetrics(!0),this.resize(this.cachedContentMetrics));const s=e.getAbsoluteMetrics();this.cachedContentMetrics&&this.position(this.cachedContentMetrics,s)}else if(t.type===r.Events.BLOCK_DRAG)this.handleBlockDrag(t);else if(t.type===r.Events.BLOCK_CHANGE){const t=this.workspace.getMetricsManager();this.cachedContentMetrics=t.getContentMetrics(!0),this.resize(this.cachedContentMetrics)}}handleBlockDrag(t){var e;null===(e=this.svgGroup)||void 0===e||e.setAttribute("opacity","1")}applyColor(){var t;const e=r.utils.colour.blend("#000",this.theme,.1),s=r.utils.colour.blend("#fff",this.theme,.1),i="#ffffff"===this.theme||"#fff"===this.theme?e:s;null===(t=this.background)||void 0===t||t.setAttribute("fill",this.theme);const o=this.workspace.getTheme();i!==(o.getComponentStyle("workspaceBackgroundColour")||"#ffffff")&&(o.setComponentStyle("workspaceBackgroundColour",i),this.workspace.setTheme(o))}resize(t){var e,s;const i=t.width?t.width+2*this.padding:0,o=t.height?t.height+2*this.padding:0;i!==this.width&&(this.width=i,null===(e=this.rect)||void 0===e||e.setAttribute("width",`${i}`)),o!==this.height&&(this.height=o,null===(s=this.rect)||void 0===s||s.setAttribute("height",`${o}`))}position(t,e){var s;const i=-this.workspace.scrollY,o=-this.workspace.scrollX,r=this.workspace.scale,n=e.top+t.top*r-i-this.padding*r,h=e.left+t.left*r-o-this.padding*r;n===this.top&&h===this.left&&this.lastScale===r||(this.top=n,this.left=h,this.lastScale=r,null===(s=this.rect)||void 0===s||s.setAttribute("transform",`translate(${h}, ${n}) scale(${r})`))}}return o})()));

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
!function(e,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o(require("blockly/core"));else if("function"==typeof define&&define.amd)define(["blockly/core"],o);else{var t="object"==typeof exports?o(require("blockly/core")):o(e.Blockly);for(var r in t)("object"==typeof exports?exports:e)[r]=t[r]}}(this,(e=>(()=>{"use strict";var o={573:o=>{o.exports=e}},t={};function r(e){var n=t[e];if(void 0!==n)return n.exports;var i=t[e]={exports:{}};return o[e](i,i.exports,r),i.exports}r.n=e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return r.d(o,{a:o}),o},r.d=(e,o)=>{for(var t in o)r.o(o,t)&&!r.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},r.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{r.r(n),r.d(n,{DisableTopBlocks:()=>o});var e=r(573);class o{init(){const o=e.ContextMenuRegistry.registry.getItem("blockDisable");this.oldPreconditionFn=o.preconditionFn,o.preconditionFn=function(e){const o=e.block;return!o.isInFlyout&&o.workspace.options.disable&&o.isEditable()?o.getInheritedDisabled()||t(o)?"disabled":"enabled":"hidden"}}dispose(){e.ContextMenuRegistry.registry.getItem("blockDisable").preconditionFn=this.oldPreconditionFn}}function t(e){const o=e.getParent();return!(!o||!t(o))||!(o||!e.outputConnection&&!e.previousConnection)}})(),n})()));

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
/*! For license information please see index.js.LICENSE.txt */
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("blockly/core"));else if("function"==typeof define&&define.amd)define(["blockly/core"],t);else{var n="object"==typeof exports?t(require("blockly/core")):t(e.Blockly);for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,(e=>(()=>{"use strict";var t={573:t=>{t.exports=e}},n={};function o(e){var i=n[e];if(void 0!==i)return i.exports;var s=n[e]={exports:{}};return t[e](s,s.exports,o),s.exports}o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{o.r(i),o.d(i,{FieldDependentDropdown:()=>s});var e=o(573);function t(e,n){return e.length===n.length&&e.every(((e,o)=>{const i=n[o];return Array.isArray(e)&&Array.isArray(i)?t(e,i):e===i}))}class n extends e.Events.BlockBase{constructor(e,t,o,i,s,r){super(e),this.type=n.EVENT_TYPE,e&&t&&o&&i&&s&&r&&(this.name=t,this.oldValue=o,this.newValue=i,this.oldOptions=s,this.newOptions=r)}toJson(){const e=super.toJson();if(!(this.name&&this.oldValue&&this.newValue&&this.oldOptions&&this.newOptions))throw new Error("The changed element is undefined. Either pass all needed parameters to the constructor, or call fromJson.");return e.name=this.name,e.oldValue=this.oldValue,e.newValue=this.newValue,e.oldOptions=this.oldOptions,e.newOptions=this.newOptions,e}static fromJson(e,t,n){const o=super.fromJson(e,t,n);return o.name=e.name,o.oldValue=e.oldValue,o.newValue=e.newValue,o.oldOptions=e.oldOptions,o.newOptions=e.newOptions,o}isNull(){const e=this.oldValue===this.newValue,n=this.oldOptions===this.newOptions||Array.isArray(this.oldOptions)&&Array.isArray(this.newOptions)&&t(this.oldOptions,this.newOptions);return e&&n}run(e){if(!(this.blockId&&this.name&&this.oldValue&&this.newValue&&this.oldOptions&&this.newOptions))return void console.warn("Can't run uninitialized event.");const t=this.getEventWorkspace_().getBlockById(this.blockId);if(!t)return void console.warn("Can't change non-existent block: "+this.blockId);const n=t.getField(this.name);if(!n)return void console.warn("Can't change non-existent dropdown field: "+this.name);const o=e?this.newValue:this.oldValue,i=e?this.newOptions:this.oldOptions;n.dependencyData.derivedOptions=i,n.getOptions(!1),n.setValue(o)}}n.EVENT_TYPE="dropdown_options_change",e.registry.register(e.registry.Type.EVENT,n.EVENT_TYPE,n);class s extends e.FieldDropdown{constructor(e,t,n,o,i){const s={};super((()=>{if(s.derivedOptions)return s.derivedOptions;if(s.parentField){const e=s.parentField.getValue();if(e){const n=t[e];if(n)return n}}return n||[["",""]]}),o,i),this.parentName=e,this.optionMapping=t,this.defaultOptions=n,this.dependencyData=s}static fromJson(e){return new s(e.parentName,e.optionMapping,e.defaultOptions,void 0,e)}setSourceBlock(e){var t;super.setSourceBlock(e);const n=e.getField(this.parentName);if(!n)throw new Error("Could not find a parent field with the name "+this.parentName+" for the dependent dropdown.");this.dependencyData.parentField=n;const o=n.getValidator();n.setValidator((e=>{if(o){const t=o(e);if(null===t)return null;void 0!==t&&(e=t)}return this.updateOptionsBasedOnNewValue(e),e})),this.updateOptionsBasedOnNewValue(null!==(t=n.getValue())&&void 0!==t?t:void 0)}updateOptionsBasedOnNewValue(t){if(null==t)return;const o=this.getSourceBlock();if(!o)throw new Error("Could not validate a field that is not attached to a block: "+this.name);const i=this.getValue(),s=this.getOptions(!1);let r=this.optionMapping[t];if(!r){if(!this.defaultOptions)return void console.warn("Could not find child options for the parent value: "+t);r=this.defaultOptions}const l=null!=r.find((e=>e[1]==i))?i:r[0][1];this.dependencyData.derivedOptions=r,this.getOptions(!1),e.Events.disable(),this.setValue(l),e.Events.enable(),e.Events.getRecordUndo()&&(e.Events.getGroup()||(e.Events.setGroup(!0),setTimeout((()=>e.Events.setGroup(!1)))),e.Events.fire(new n(o,this.name,null!=i?i:void 0,null!=l?l:void 0,s,r)))}}Object.defineProperty(e,"FieldDependentDropdown",{value:s,writable:!0,enumerable:!0,configurable:!0}),e.fieldRegistry.register("field_dependent_dropdown",s)})(),i})()));

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,158 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Download screenshot.
*/
'use strict';
goog.require('Blockly');
goog.provide('Blockly.Screenshot');
/**
* Convert an SVG datauri into a PNG datauri.
* @param {string} data SVG datauri.
* @param {number} width Image width.
* @param {number} height Image height.
* @param {!Function} callback Callback.
*/
Blockly.Screenshot.svgToPng_ = function (data, width, height, callback) {
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
const img = new Image();
const maxSize = Math.max(width, height);
const pixelDensity = Math.max(Math.min(10, 15000 / maxSize), window.devicePixelRatio || 1);
canvas.width = width * pixelDensity;
canvas.height = height * pixelDensity;
img.onload = function () {
context.drawImage(
img,
0,
0,
width,
height,
0,
0,
canvas.width,
canvas.height
);
try {
const dataUri = canvas.toDataURL('image/png');
callback(dataUri);
} catch (err) {
console.warn('Error converting the workspace svg to a png');
callback('');
}
};
img.src = data;
}
Blockly.Screenshot.getBase64Image_ = function(image) {
return new Promise(resolve => {
const img = new Image();
img.crossOrigin = '';
const href = image.getAttribute('xlink:href');
if (!href) {
resolve();
return;
}
img.src = href;
img.onload = function () {
const canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
const ctx = canvas.getContext('2d');
ctx?.drawImage(img, 0, 0, img.width, img.height);
const ext = img.src.substring(img.src.lastIndexOf('.') + 1).toLowerCase();
const dataURL = canvas.toDataURL('image/' + ext);
image.setAttribute('xlink:href', dataURL);
resolve();
}
});
}
/**
* Create an SVG of the blocks on the workspace.
* @param {!Blockly.WorkspaceSvg} workspace The workspace.
* @param {!Function} callback Callback.
* @param {string=} customCss Custom CSS to append to the SVG.
*/
Blockly.Screenshot.workspaceToSvg_ = function (workspace, callback, customCss) {
// Go through all text areas and set their value.
const textAreas = document.getElementsByTagName('textarea');
for (let i = 0; i < textAreas.length; i++) {
textAreas[i].innerHTML = textAreas[i].value;
}
const bBox = workspace.getBlocksBoundingBox();
const x = bBox.x || bBox.left;
const y = bBox.y || bBox.top;
const width = bBox.width || bBox.right - x;
const height = bBox.height || bBox.bottom - y;
const blockCanvas = workspace.getCanvas();
const clone = blockCanvas.cloneNode(true);
clone.removeAttribute('transform');
const $images = $(clone).find('image');
let resolveList = [];
for (let i = 0; i < $images.length; i++) {
resolveList.push(this.getBase64Image_($images[i]));
}
Promise.all(resolveList)
.then(() => {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
svg.appendChild(clone);
svg.setAttribute('viewBox', x + ' ' + y + ' ' + width + ' ' + height);
svg.setAttribute(
'class',
'blocklySvg ' +
(workspace.options.renderer || 'geras') +
'-renderer ' +
(workspace.getTheme ? workspace.getTheme().name + '-theme' : '')
);
svg.setAttribute('width', width);
svg.setAttribute('height', height);
svg.setAttribute('style', 'background-color: transparent');
const css = [].slice
.call(document.head.querySelectorAll('style'))
.filter(
(el) =>
/\.blocklySvg/.test(el.innerText) || el.id.indexOf('blockly-') === 0
)
.map((el) => el.innerText)
.join('\n');
const style = document.createElement('style');
style.innerHTML = css + '\n' + customCss;
svg.insertBefore(style, svg.firstChild);
let svgAsXML = new XMLSerializer().serializeToString(svg);
svgAsXML = svgAsXML.replace(/&nbsp/g, '&#160');
const data = 'data:image/svg+xml,' + encodeURIComponent(svgAsXML);
Blockly.Screenshot.svgToPng_(data, width, height, callback);
});
}
/* eslint-disable no-unused-vars */
/**
* Download a screenshot of the blocks on a Blockly workspace.
* @param {!Blockly.WorkspaceSvg} workspace The Blockly workspace.
*/
Blockly.Screenshot.downloadScreenshot = function (workspace) {
Blockly.Screenshot.workspaceToSvg_(workspace, function (datauri) {
const a = document.createElement('a');
a.download = 'screenshot.png';
a.target = '_self';
a.href = datauri;
document.body.appendChild(a);
a.click();
a.parentNode.removeChild(a);
});
}
/* eslint-enable */

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
/*! For license information please see index.js.LICENSE.txt */
!function(t,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o(require("blockly/core"));else if("function"==typeof define&&define.amd)define(["blockly/core"],o);else{var e="object"==typeof exports?o(require("blockly/core")):o(t.Blockly);for(var i in e)("object"==typeof exports?exports:t)[i]=e[i]}}(this,(t=>(()=>{"use strict";var o={573:o=>{o.exports=t}},e={};function i(t){var r=e[t];if(void 0!==r)return r.exports;var s=e[t]={exports:{}};return o[t](s,s.exports,i),s.exports}i.n=t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return i.d(o,{a:o}),o},i.d=(t,o)=>{for(var e in o)i.o(o,e)&&!i.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:o[e]})},i.o=(t,o)=>Object.prototype.hasOwnProperty.call(t,o),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{i.r(r),i.d(r,{ZoomToFitControl:()=>s});var t=i(573);function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function e(t,e){for(var i=0;i<e.length;i++){var r=e[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,s=function(t,e){if("object"!==o(t)||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var r=i.call(t,"string");if("object"!==o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key),"symbol"===o(s)?s:String(s)),r)}var s}var s=function(){function o(t){!function(t,o){if(!(t instanceof o))throw new TypeError("Cannot call a class as a function")}(this,o),this.workspace_=t,this.id="zoomToFit",this.svgGroup_=null,this.left_=0,this.top_=0,this.WIDTH_=32,this.HEIGHT_=32,this.MARGIN_VERTICAL_=20,this.MARGIN_HORIZONTAL_=20,this.initialized_=!1}var i,r;return i=o,(r=[{key:"init",value:function(){this.workspace_.getComponentManager().addComponent({component:this,weight:2,capabilities:[t.ComponentManager.Capability.POSITIONABLE]}),this.createDom_(),this.initialized_=!0,this.workspace_.resize()}},{key:"dispose",value:function(){this.svgGroup_&&t.utils.dom.removeNode(this.svgGroup_),this.onZoomToFitWrapper_&&t.unbindEvent_(this.onZoomToFitWrapper_)}},{key:"createDom_",value:function(){this.svgGroup_=t.utils.dom.createSvgElement(t.utils.Svg.IMAGE,{height:this.HEIGHT_+"px",width:this.WIDTH_+"px",class:"zoomToFit"}),this.svgGroup_.setAttributeNS(t.utils.dom.XLINK_NS,"xlink:href",n),t.utils.dom.insertAfter(this.svgGroup_,this.workspace_.getBubbleCanvas()),this.onZoomToFitWrapper_=t.browserEvents.conditionalBind(this.svgGroup_,"mousedown",null,this.onClick_.bind(this))}},{key:"onClick_",value:function(){this.workspace_.zoomToFit();var o=new(t.Events.get(t.Events.CLICK))(null,this.workspace_.id,"zoom_reset_control");t.Events.fire(o)}},{key:"getBoundingRectangle",value:function(){return new t.utils.Rect(this.top_,this.top_+this.HEIGHT_,this.left_,this.left_+this.WIDTH_)}},{key:"position",value:function(o,e){if(this.initialized_){var i=this.workspace_.scrollbar&&this.workspace_.scrollbar.canScrollHorizontally(),r=this.workspace_.scrollbar&&this.workspace_.scrollbar.canScrollVertically();o.toolboxMetrics.position===t.TOOLBOX_AT_LEFT||this.workspace_.horizontalLayout&&!this.workspace_.RTL?(this.left_=o.absoluteMetrics.left+o.viewMetrics.width-this.WIDTH_-this.MARGIN_HORIZONTAL_,i&&!this.workspace_.RTL&&(this.left_-=t.Scrollbar.scrollbarThickness)):(this.left_=this.MARGIN_HORIZONTAL_,i&&this.workspace_.RTL&&(this.left_+=t.Scrollbar.scrollbarThickness));var s=o.toolboxMetrics.position!==t.TOOLBOX_AT_BOTTOM;s?(this.top_=o.absoluteMetrics.top+o.viewMetrics.height-this.HEIGHT_-this.MARGIN_VERTICAL_,r&&(this.top_-=t.Scrollbar.scrollbarThickness)):this.top_=o.absoluteMetrics.top+this.MARGIN_VERTICAL_;for(var n,l=this.getBoundingRectangle(),a=0;n=e[a];a++)l.intersects(n)&&(this.top_=s?n.top-this.HEIGHT_-this.MARGIN_VERTICAL_:n.bottom+this.MARGIN_VERTICAL_,l=this.getBoundingRectangle(),a=-1);this.svgGroup_.setAttribute("transform","translate("+this.left_+","+this.top_+")")}}}])&&e(i.prototype,r),Object.defineProperty(i,"prototype",{writable:!1}),o}(),n="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iIzU0NkU3QSI+PHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTUgNi40Mkw4LjA5IDkuNSA5LjUgOC4wOSA2LjQxIDVIOVYzSDN2Nmgyem0xMC0zLjQxdjJoMi41N0wxNC41IDguMDlsMS40MSAxLjQxTDE5IDYuNDFWOWgyVjMuMDF6bTQgMTQuNTdsLTMuMDktMy4wOC0xLjQxIDEuNDFMMTcuNTkgMTlIMTV2Mmg2di02aC0yek04LjA5IDE0LjVMNSAxNy41OVYxNUgzdjZoNnYtMkg2LjQybDMuMDgtMy4wOXoiLz48L3N2Zz4=";t.Css.register(["\n .zoomToFit {\n opacity: .4;\n }\n .zoomToFit:hover {\n opacity: .6;\n }\n .zoomToFit:active {\n opacity: .8;\n }\n"])})(),r})()));