From 8f0a5ae6a8eeb8d12d98f49a371e0cd1f24f4764 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 5 Aug 2022 15:25:41 +0000 Subject: [PATCH] chore: properly package .ts and .d.ts files (#6257) * fix: package .ts sources * chore: add generating type defs * chore: copy generated type defs into dist dir * chore: fix adding generated def files * chore: remove unnecessary imports * chore: make handcrafted files reference generated * chore: replace AnyDuringMigration with any * chore: use replace instead of regex-replace * chore: use value in config instead of magic strings * chore: remove blockly.d.ts * chore: update jsdocs * chore: remove old references to typings --- gulpfile.js | 5 - package.json | 1 - scripts/gulpfiles/build_tasks.js | 6 +- scripts/gulpfiles/config.js | 2 +- scripts/gulpfiles/package_tasks.js | 16 +- scripts/gulpfiles/release_tasks.js | 4 - tsconfig.json | 10 +- typings/blockly.d.ts | 26118 --------------------------- typings/blocks.d.ts | 2 - typings/core.d.ts | 4 +- typings/dart.d.ts | 3 - typings/index.d.ts | 10 +- typings/javascript.d.ts | 3 - typings/lua.d.ts | 3 - typings/php.d.ts | 3 - typings/python.d.ts | 3 - 16 files changed, 20 insertions(+), 26173 deletions(-) delete mode 100644 typings/blockly.d.ts diff --git a/gulpfile.js b/gulpfile.js index 1b6f01269..f8bbbca6b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -32,8 +32,6 @@ module.exports = { buildAdvancedCompilationTest: buildTasks.advancedCompilationTest, buildJavaScript: buildTasks.javaScript, buildJavaScriptAndDeps: buildTasks.javaScriptAndDeps, - // TODO(5621): Re-enable once typings generation is fixed. - // checkin: gulp.parallel(buildTasks.checkinBuilt, typings.checkinTypings), checkin: gulp.parallel(buildTasks.checkinBuilt), checkinBuilt: buildTasks.checkinBuilt, clangFormat: buildTasks.format, @@ -44,9 +42,6 @@ module.exports = { gitSyncMaster: gitTasks.syncMaster, gitCreateRC: gitTasks.createRC, gitUpdateGithubPages: gitTasks.updateGithubPages, - // TODO(5621): Re-enable once typings generation is fixed. - // typings: gulp.series(typings.typings, typings.msgTypings), - // checkinTypings: typings.checkinTypings, package: packageTasks.package, prepare: buildTasks.prepare, checkLicenses: licenseTasks.checkLicenses, diff --git a/package.json b/package.json index 0ef0e0368..727a9ba3e 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "clean:release": "gulp cleanReleaseDir", "checkin": "gulp checkin", "checkin:built": "gulp checkinBuilt", - "checkin:typings": "gulp checkinTypings", "deployDemos": "gulp deployDemos", "deployDemos:beta": "gulp deployDemosBeta", "format": "gulp clangFormat", diff --git a/scripts/gulpfiles/build_tasks.js b/scripts/gulpfiles/build_tasks.js index 4ed0d6232..36899f35a 100644 --- a/scripts/gulpfiles/build_tasks.js +++ b/scripts/gulpfiles/build_tasks.js @@ -25,7 +25,7 @@ var closureDeps = require('google-closure-deps'); var argv = require('yargs').argv; var rimraf = require('rimraf'); -var {BUILD_DIR, DEPS_FILE, TEST_DEPS_FILE, TSC_OUTPUT_DIR} = require('./config'); +var {BUILD_DIR, DEPS_FILE, TEST_DEPS_FILE, TSC_OUTPUT_DIR, TYPINGS_BUILD_DIR} = require('./config'); var {getPackageJson} = require('./helper_tasks'); //////////////////////////////////////////////////////////// @@ -317,7 +317,9 @@ const buildJavaScriptAndDeps = gulp.series(buildJavaScript, buildDeps); * buildCompiled. */ function buildJavaScript(done) { - execSync(`tsc -outDir "${TSC_OUTPUT_DIR}"`, {stdio: 'inherit'}); + execSync( + `tsc -outDir "${TSC_OUTPUT_DIR}" -declarationDir "${TYPINGS_BUILD_DIR}"`, + {stdio: 'inherit'}); done(); } diff --git a/scripts/gulpfiles/config.js b/scripts/gulpfiles/config.js index 02df80291..200d6ac45 100644 --- a/scripts/gulpfiles/config.js +++ b/scripts/gulpfiles/config.js @@ -32,7 +32,7 @@ exports.DEPS_FILE = path.join(exports.BUILD_DIR, 'deps.js'); exports.TEST_DEPS_FILE = path.join(exports.BUILD_DIR, 'deps.mocha.js'); // Directory to write typings output to. -exports.TYPINGS_BUILD_DIR = path.join(exports.BUILD_DIR, 'typings'); +exports.TYPINGS_BUILD_DIR = path.join(exports.BUILD_DIR, 'declarations'); // Directory where typescript compiler output can be found. // Matches the value in tsconfig.json: outDir diff --git a/scripts/gulpfiles/package_tasks.js b/scripts/gulpfiles/package_tasks.js index 5297ddf07..84e218298 100644 --- a/scripts/gulpfiles/package_tasks.js +++ b/scripts/gulpfiles/package_tasks.js @@ -14,6 +14,7 @@ gulp.replace = require('gulp-replace'); gulp.rename = require('gulp-rename'); gulp.insert = require('gulp-insert'); gulp.umd = require('gulp-umd'); +gulp.replace = require('gulp-replace'); var path = require('path'); var fs = require('fs'); @@ -82,7 +83,7 @@ function checkBuildDir(done) { * This task copies source files into the release directory. */ function packageSources() { - return gulp.src(['core/**/**.js', 'blocks/**.js', 'generators/**/**.js'], + return gulp.src(['core/**/**', 'blocks/**', 'generators/**/**'], {base: '.'}) .pipe(gulp.dest(RELEASE_DIR)); }; @@ -377,13 +378,10 @@ function packageReadme() { }; /** - * This task copies the typings/blockly.d.ts TypeScript definition - * file into the release directory. The bundled declaration file is - * referenced in package.json in the types property. - * As of Q4 2021 this simply copies the existing ts definition files, since - * generation through typescript-closure-tools does not work with goog.module. - * TODO(5621): Regenerate definition files and copy them into the release dir as - * needed. + * This task copies the generated .d.ts files in build/declarations and the + * hand-written .d.ts files in typings/ into the release directory. The main + * entrypoint file (index.d.ts) is referenced in package.json in the types + * property. */ function packageDTS() { const handwrittenSrcs = [ @@ -391,6 +389,8 @@ function packageDTS() { 'typings/msg/msg.d.ts', ]; return gulp.src(handwrittenSrcs, {base: 'typings'}) + .pipe(gulp.src(`${BUILD_DIR}/${TYPINGS_BUILD_DIR}/**/*.d.ts`)) + .pipe(gulp.replace('AnyDuringMigration', 'any')) .pipe(gulp.dest(RELEASE_DIR)); }; diff --git a/scripts/gulpfiles/release_tasks.js b/scripts/gulpfiles/release_tasks.js index d44928ca3..b633391f4 100644 --- a/scripts/gulpfiles/release_tasks.js +++ b/scripts/gulpfiles/release_tasks.js @@ -153,10 +153,6 @@ const rebuildAll = gulp.series( buildTasks.cleanBuildDir, buildTasks.build, buildTasks.checkinBuilt, - // TODO(5621): Re-enable once typings generation is fixed. - // typings.typings, - // typings.msgTypings, - // typings.checkinTypings, ); // Package and publish to npm. diff --git a/tsconfig.json b/tsconfig.json index f8780939c..3b1971dc5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,18 +3,16 @@ "core/**/*", // N.B.: also pulls in closure/goog/goog.js if needed. "closure/**/*", // Just for ouptut directory structure. ], + "exclude": [ + "core/blockly.js" + ], "compilerOptions": { // Tells TypeScript to read JS files, as // normally they are ignored as source files "allowJs": true, - // Enable the next few options for type declarations. // Generate d.ts files - //"declaration": true, - // Types should go into this directory. - // Removing this would place the .d.ts files - // next to the .js files - //"declarationDir": "build/ts/declarations", + "declaration": true, "module": "ES2015", "moduleResolution": "node", diff --git a/typings/blockly.d.ts b/typings/blockly.d.ts deleted file mode 100644 index dce24590f..000000000 --- a/typings/blockly.d.ts +++ /dev/null @@ -1,26118 +0,0 @@ -declare module "core/utils/colour" { - /** - * Get the richness of block colours, regardless of the hue. - * @alias Blockly.utils.colour.getHsvSaturation - * @return {number} The current richness. - * @package - */ - export function getHsvSaturation(): number; - /** - * Set the richness of block colours, regardless of the hue. - * @param {number} newSaturation The new richness, in the range of 0 - * (inclusive) to 1 (exclusive) - * @alias Blockly.utils.colour.setHsvSaturation - * @package - */ - export function setHsvSaturation(newSaturation: number): void; - /** - * Get the intensity of block colours, regardless of the hue. - * @alias Blockly.utils.colour.getHsvValue - * @return {number} The current intensity. - * @package - */ - export function getHsvValue(): number; - /** - * Set the intensity of block colours, regardless of the hue. - * @param {number} newValue The new intensity, in the range of 0 - * (inclusive) to 1 (exclusive) - * @alias Blockly.utils.colour.setHsvValue - * @package - */ - export function setHsvValue(newValue: number): void; - /** - * Parses a colour from a string. - * .parse('red') -> '#ff0000' - * .parse('#f00') -> '#ff0000' - * .parse('#ff0000') -> '#ff0000' - * .parse('0xff0000') -> '#ff0000' - * .parse('rgb(255, 0, 0)') -> '#ff0000' - * @param {string|number} str Colour in some CSS format. - * @return {?string} A string containing a hex representation of the colour, - * or null if can't be parsed. - * @alias Blockly.utils.colour.parse - */ - export function parse(str: string | number): string | null; - /** - * Converts a colour from RGB to hex representation. - * @param {number} r Amount of red, int between 0 and 255. - * @param {number} g Amount of green, int between 0 and 255. - * @param {number} b Amount of blue, int between 0 and 255. - * @return {string} Hex representation of the colour. - * @alias Blockly.utils.colour.rgbToHex - */ - export function rgbToHex(r: number, g: number, b: number): string; - /** - * Converts a colour to RGB. - * @param {string} colour String representing colour in any - * colour format ('#ff0000', 'red', '0xff000', etc). - * @return {!Array} RGB representation of the colour. - * @alias Blockly.utils.colour.hexToRgb - */ - export function hexToRgb(colour: string): Array; - /** - * Converts an HSV triplet to hex representation. - * @param {number} h Hue value in [0, 360]. - * @param {number} s Saturation value in [0, 1]. - * @param {number} v Brightness in [0, 255]. - * @return {string} Hex representation of the colour. - * @alias Blockly.utils.colour.hsvToHex - */ - export function hsvToHex(h: number, s: number, v: number): string; - /** - * Blend two colours together, using the specified factor to indicate the - * weight given to the first colour. - * @param {string} colour1 First colour. - * @param {string} colour2 Second colour. - * @param {number} factor The weight to be given to colour1 over colour2. - * Values should be in the range [0, 1]. - * @return {?string} Combined colour represented in hex. - * @alias Blockly.utils.colour.blend - */ - export function blend(colour1: string, colour2: string, factor: number): string | null; - /** - * A map that contains the 16 basic colour keywords as defined by W3C: - * https://www.w3.org/TR/2018/REC-css-color-3-20180619/#html4 - * The keys of this map are the lowercase "readable" names of the colours, - * while the values are the "hex" values. - * - * @type {!Object} - * @alias Blockly.utils.colour.names - */ - export const names: { - [x: string]: string; - }; - /** - * Convert a hue (HSV model) into an RGB hex triplet. - * @param {number} hue Hue on a colour wheel (0-360). - * @return {string} RGB code, e.g. '#5ba65b'. - * @alias Blockly.utils.colour.hueToHex - */ - export function hueToHex(hue: number): string; -} -declare module "core/utils/string" { - /** - * Given an array of strings, return the length of the shortest one. - * @param {!Array} array Array of strings. - * @return {number} Length of shortest string. - * @alias Blockly.utils.string.shortestStringLength - */ - export function shortestStringLength(array: Array): number; - /** - * Given an array of strings, return the length of the common prefix. - * Words may not be split. Any space after a word is included in the length. - * @param {!Array} array Array of strings. - * @param {number=} opt_shortest Length of shortest string. - * @return {number} Length of common prefix. - * @alias Blockly.utils.string.commonWordPrefix - */ - export function commonWordPrefix(array: Array, opt_shortest?: number | undefined): number; - /** - * Given an array of strings, return the length of the common suffix. - * Words may not be split. Any space after a word is included in the length. - * @param {!Array} array Array of strings. - * @param {number=} opt_shortest Length of shortest string. - * @return {number} Length of common suffix. - * @alias Blockly.utils.string.commonWordSuffix - */ - export function commonWordSuffix(array: Array, opt_shortest?: number | undefined): number; - /** - * Wrap text to the specified width. - * @param {string} text Text to wrap. - * @param {number} limit Width to wrap each line. - * @return {string} Wrapped text. - * @alias Blockly.utils.string.wrap - */ - export function wrap(text: string, limit: number): string; - /** - * Is the given string a number (includes negative and decimals). - * @param {string} str Input string. - * @return {boolean} True if number, false otherwise. - * @alias Blockly.utils.string.isNumber - */ - export function isNumber(str: string): boolean; -} -declare module "core/msg" { - /** - * A dictionary of localised messages. - * @type {!Object} - */ - export const Msg: any; -} -declare module "core/utils/parsing" { - /** - * Parse a string with any number of interpolation tokens (%1, %2, ...). - * It will also replace string table references (e.g., %{bky_my_msg} and - * %{BKY_MY_MSG} will both be replaced with the value in - * Msg['MY_MSG']). Percentage sign characters '%' may be self-escaped - * (e.g., '%%'). - * @param {string} message Text which might contain string table references and - * interpolation tokens. - * @return {!Array} Array of strings and numbers. - * @alias Blockly.utils.parsing.tokenizeInterpolation - */ - export function tokenizeInterpolation(message: string): Array; - /** - * Replaces string table references in a message, if the message is a string. - * For example, "%{bky_my_msg}" and "%{BKY_MY_MSG}" will both be replaced with - * the value in Msg['MY_MSG']. - * @param {string|?} message Message, which may be a string that contains - * string table references. - * @return {string} String with message references replaced. - * @alias Blockly.utils.parsing.replaceMessageReferences - */ - export function replaceMessageReferences(message: string | unknown): string; - /** - * Validates that any %{MSG_KEY} references in the message refer to keys of - * the Msg string table. - * @param {string} message Text which might contain string table references. - * @return {boolean} True if all message references have matching values. - * Otherwise, false. - * @alias Blockly.utils.parsing.checkMessageReferences - */ - export function checkMessageReferences(message: string): boolean; - /** - * Parse a block colour from a number or string, as provided in a block - * definition. - * @param {number|string} colour HSV hue value (0 to 360), #RRGGBB string, - * or a message reference string pointing to one of those two values. - * @return {{hue: ?number, hex: string}} An object containing the colour as - * a #RRGGBB string, and the hue if the input was an HSV hue value. - * @throws {Error} If the colour cannot be parsed. - * @alias Blockly.utils.parsing.parseBlockColour - */ - export function parseBlockColour(colour: number | string): { - hue: number | null; - hex: string; - }; -} -declare module "core/utils/aria" { - /** - * * - */ - export type Role = string; - export namespace Role { - const GRID: string; - const GRIDCELL: string; - const GROUP: string; - const LISTBOX: string; - const MENU: string; - const MENUITEM: string; - const MENUITEMCHECKBOX: string; - const OPTION: string; - const PRESENTATION: string; - const ROW: string; - const TREE: string; - const TREEITEM: string; - } - /** - * * - */ - export type State = string; - export namespace State { - const ACTIVEDESCENDANT: string; - const COLCOUNT: string; - const DISABLED: string; - const EXPANDED: string; - const INVALID: string; - const LABEL: string; - const LABELLEDBY: string; - const LEVEL: string; - const ORIENTATION: string; - const POSINSET: string; - const ROWCOUNT: string; - const SELECTED: string; - const SETSIZE: string; - const VALUEMAX: string; - const VALUEMIN: string; - } - /** - * Sets the role of an element. - * - * Similar to Closure's goog.a11y.aria - * - * @param {!Element} element DOM node to set role of. - * @param {!Role} roleName Role name. - * @alias Blockly.utils.aria.setRole - */ - export function setRole(element: Element, roleName: Role): void; - /** - * Sets the state or property of an element. - * Copied from Closure's goog.a11y.aria - * @param {!Element} element DOM node where we set state. - * @param {!State} stateName State attribute being set. - * Automatically adds prefix 'aria-' to the state name if the attribute is - * not an extra attribute. - * @param {string|boolean|number|!Array} value Value - * for the state attribute. - * @alias Blockly.utils.aria.setState - */ - export function setState(element: Element, stateName: State, value: string | boolean | number | Array): void; -} -declare module "core/utils/global" { - /** - * Reference to the global object. - * - * More info on this implementation here: - * https://docs.google.com/document/d/1NAeW4Wk7I7FV0Y2tcUFvQdGMc89k2vdgSXInw8_nvCI - */ - export var globalThis: any; -} -declare module "core/utils/useragent" { - /** - * The raw useragent string. - * @type {string} - */ - let rawUserAgent: string; - /** @type {boolean} */ - let isIe: boolean; - /** @type {boolean} */ - let isEdge: boolean; - /** @type {boolean} */ - let isJavaFx: boolean; - /** @type {boolean} */ - let isChrome: boolean; - /** @type {boolean} */ - let isWebKit: boolean; - /** @type {boolean} */ - let isGecko: boolean; - /** @type {boolean} */ - let isAndroid: boolean; - /** @type {boolean} */ - let isIPad: boolean; - /** @type {boolean} */ - let isIPod: boolean; - /** @type {boolean} */ - let isIPhone: boolean; - /** @type {boolean} */ - let isMac: boolean; - /** @type {boolean} */ - let isTablet: boolean; - /** @type {boolean} */ - let isMobile: boolean; - export { rawUserAgent as raw, isIe as IE, isEdge as EDGE, isJavaFx as JavaFx, isChrome as CHROME, isWebKit as WEBKIT, isGecko as GECKO, isAndroid as ANDROID, isIPad as IPAD, isIPod as IPOD, isIPhone as IPHONE, isMac as MAC, isTablet as TABLET, isMobile as MOBILE }; -} -declare module "core/utils/svg" { - /** - * A name with the type of the SVG element stored in the generic. - * @template T - * @alias Blockly.utils.Svg - */ - export class Svg { - /** - * @param {string} tagName The SVG element tag name. - * @package - */ - constructor(tagName: string); - /** - * @type {string} - * @private - */ - private tagName_; - /** - * Returns the SVG element tag name. - * @return {string} The name. - */ - toString(): string; - } - export namespace Svg { - const ANIMATE: Svg; - const CIRCLE: Svg; - const CLIPPATH: Svg; - const DEFS: Svg; - const FECOMPOSITE: Svg; - const FECOMPONENTTRANSFER: Svg; - const FEFLOOD: Svg; - const FEFUNCA: Svg; - const FEGAUSSIANBLUR: Svg; - const FEPOINTLIGHT: Svg; - const FESPECULARLIGHTING: Svg; - const FILTER: Svg; - const FOREIGNOBJECT: Svg; - const G: Svg; - const IMAGE: Svg; - const LINE: Svg; - const PATH: Svg; - const PATTERN: Svg; - const POLYGON: Svg; - const RECT: Svg; - const SVG: Svg; - const TEXT: Svg; - const TSPAN: Svg; - } -} -declare module "core/utils/dom" { - /** - * Required name space for SVG elements. - * @const - * @alias Blockly.utils.dom.SVG_NS - */ - export const SVG_NS: "http://www.w3.org/2000/svg"; - /** - * Required name space for HTML elements. - * @const - * @alias Blockly.utils.dom.HTML_NS - */ - export const HTML_NS: "http://www.w3.org/1999/xhtml"; - /** - * Required name space for XLINK elements. - * @const - * @alias Blockly.utils.dom.XLINK_NS - */ - export const XLINK_NS: "http://www.w3.org/1999/xlink"; - /** - * * - */ - export type NodeType = number; - export namespace NodeType { - const ELEMENT_NODE: number; - const TEXT_NODE: number; - const COMMENT_NODE: number; - const DOCUMENT_POSITION_CONTAINED_BY: number; - } - /** - * Helper method for creating SVG elements. - * @param {string|Svg} name Element's tag name. - * @param {!Object} attrs Dictionary of attribute names and values. - * @param {Element=} opt_parent Optional parent on which to append the element. - * @return {T} Newly created SVG element. The return type is {!SVGElement} if - * name is a string or a more specific type if it a member of Svg. - * @template T - * @alias Blockly.utils.dom.createSvgElement - */ - export function createSvgElement(name: string | Svg, attrs: Object, opt_parent?: Element | undefined): T; - /** - * Add a CSS class to a element. - * Similar to Closure's goog.dom.classes.add, except it handles SVG elements. - * @param {!Element} element DOM element to add class to. - * @param {string} className Name of class to add. - * @return {boolean} True if class was added, false if already present. - * @alias Blockly.utils.dom.addClass - */ - export function addClass(element: Element, className: string): boolean; - /** - * Removes multiple calsses from an element. - * @param {!Element} element DOM element to remove classes from. - * @param {string} classNames A string of one or multiple class names for an - * element. - * @alias Blockly.utils.dom.removeClasses - */ - export function removeClasses(element: Element, classNames: string): void; - /** - * Remove a CSS class from a element. - * Similar to Closure's goog.dom.classes.remove, except it handles SVG elements. - * @param {!Element} element DOM element to remove class from. - * @param {string} className Name of class to remove. - * @return {boolean} True if class was removed, false if never present. - * @alias Blockly.utils.dom.removeClass - */ - export function removeClass(element: Element, className: string): boolean; - /** - * Checks if an element has the specified CSS class. - * Similar to Closure's goog.dom.classes.has, except it handles SVG elements. - * @param {!Element} element DOM element to check. - * @param {string} className Name of class to check. - * @return {boolean} True if class exists, false otherwise. - * @alias Blockly.utils.dom.hasClass - */ - export function hasClass(element: Element, className: string): boolean; - /** - * Removes a node from its parent. No-op if not attached to a parent. - * @param {?Node} node The node to remove. - * @return {?Node} The node removed if removed; else, null. - * @alias Blockly.utils.dom.removeNode - */ - export function removeNode(node: Node | null): Node | null; - /** - * Insert a node after a reference node. - * Contrast with node.insertBefore function. - * @param {!Element} newNode New element to insert. - * @param {!Element} refNode Existing element to precede new node. - * @alias Blockly.utils.dom.insertAfter - */ - export function insertAfter(newNode: Element, refNode: Element): void; - /** - * Whether a node contains another node. - * @param {!Node} parent The node that should contain the other node. - * @param {!Node} descendant The node to test presence of. - * @return {boolean} Whether the parent node contains the descendant node. - * @alias Blockly.utils.dom.containsNode - */ - export function containsNode(parent: Node, descendant: Node): boolean; - /** - * Sets the CSS transform property on an element. This function sets the - * non-vendor-prefixed and vendor-prefixed versions for backwards compatibility - * with older browsers. See https://caniuse.com/#feat=transforms2d - * @param {!Element} element Element to which the CSS transform will be applied. - * @param {string} transform The value of the CSS `transform` property. - * @alias Blockly.utils.dom.setCssTransform - */ - export function setCssTransform(element: Element, transform: string): void; - /** - * Start caching text widths. Every call to this function MUST also call - * stopTextWidthCache. Caches must not survive between execution threads. - * @alias Blockly.utils.dom.startTextWidthCache - */ - export function startTextWidthCache(): void; - /** - * Stop caching field widths. Unless caching was already on when the - * corresponding call to startTextWidthCache was made. - * @alias Blockly.utils.dom.stopTextWidthCache - */ - export function stopTextWidthCache(): void; - /** - * Gets the width of a text element, caching it in the process. - * @param {!Element} textElement An SVG 'text' element. - * @return {number} Width of element. - * @alias Blockly.utils.dom.getTextWidth - */ - export function getTextWidth(textElement: Element): number; - /** - * Gets the width of a text element using a faster method than `getTextWidth`. - * This method requires that we know the text element's font family and size in - * advance. Similar to `getTextWidth`, we cache the width we compute. - * @param {!Element} textElement An SVG 'text' element. - * @param {number} fontSize The font size to use. - * @param {string} fontWeight The font weight to use. - * @param {string} fontFamily The font family to use. - * @return {number} Width of element. - * @alias Blockly.utils.dom.getFastTextWidth - */ - export function getFastTextWidth(textElement: Element, fontSize: number, fontWeight: string, fontFamily: string): number; - /** - * Gets the width of a text element using a faster method than `getTextWidth`. - * This method requires that we know the text element's font family and size in - * advance. Similar to `getTextWidth`, we cache the width we compute. - * This method is similar to ``getFastTextWidth`` but expects the font size - * parameter to be a string. - * @param {!Element} textElement An SVG 'text' element. - * @param {string} fontSize The font size to use. - * @param {string} fontWeight The font weight to use. - * @param {string} fontFamily The font family to use. - * @return {number} Width of element. - * @alias Blockly.utils.dom.getFastTextWidthWithSizeString - */ - export function getFastTextWidthWithSizeString(textElement: Element, fontSize: string, fontWeight: string, fontFamily: string): number; - /** - * Measure a font's metrics. The height and baseline values. - * @param {string} text Text to measure the font dimensions of. - * @param {string} fontSize The font size to use. - * @param {string} fontWeight The font weight to use. - * @param {string} fontFamily The font family to use. - * @return {{height: number, baseline: number}} Font measurements. - * @alias Blockly.utils.dom.measureFontMetrics - */ - export function measureFontMetrics(text: string, fontSize: string, fontWeight: string, fontFamily: string): { - height: number; - baseline: number; - }; - import { Svg } from "core/utils/svg"; -} -declare module "core/blocks" { - /** - * A block definition. For now this very lose, but it can potentially - * be refined e.g. by replacing this typedef with a class definition. - */ - export type BlockDefinition = any; - /** - * A block definition. For now this very lose, but it can potentially - * be refined e.g. by replacing this typedef with a class definition. - * @typedef {!Object} - */ - // export let BlockDefinition: any; - /** - * A mapping of block type names to block prototype objects. - * @type {!Object} - * @alias Blockly.blocks.Blocks - */ - export const Blocks: { - [x: string]: BlockDefinition; - }; -} -declare module "core/utils/idgenerator" { - namespace internal { - /** - * Generate a random unique ID. This should be globally unique. - * 87 characters ^ 20 length > 128 bits (better than a UUID). - * @return {string} A globally unique ID string. - */ - function genUid(): string; - } - /** - * Generate the next unique element IDs. - * IDs are compatible with the HTML4 id attribute restrictions: - * Use only ASCII letters, digits, '_', '-' and '.' - * - * For UUIDs use genUid (below) instead; this ID generator should - * primarily be used for IDs that end up in the DOM. - * - * @return {string} The next unique identifier. - * @alias Blockly.utils.idGenerator.getNextUniqueId - */ - export function getNextUniqueId(): string; - /** - * Generate a random unique ID. - * @see internal.genUid - * @return {string} A globally unique ID string. - * @alias Blockly.utils.idGenerator.genUid - */ - export function genUid(): string; - export { internal as TEST_ONLY }; -} -declare module "core/utils/array" { - /** - * Removes the first occurrence of a particular value from an array. - * @param {!Array} arr Array from which to remove value. - * @param {*} value Value to remove. - * @return {boolean} True if an element was removed. - * @alias Blockly.array.removeElem - * @package - */ - export function removeElem(arr: any[], value: any): boolean; -} -declare module "core/utils/math" { - /** - * Converts degrees to radians. - * Copied from Closure's goog.math.toRadians. - * @param {number} angleDegrees Angle in degrees. - * @return {number} Angle in radians. - * @alias Blockly.utils.math.toRadians - */ - export function toRadians(angleDegrees: number): number; - /** - * Converts radians to degrees. - * Copied from Closure's goog.math.toDegrees. - * @param {number} angleRadians Angle in radians. - * @return {number} Angle in degrees. - * @alias Blockly.utils.math.toDegrees - */ - export function toDegrees(angleRadians: number): number; - /** - * Clamp the provided number between the lower bound and the upper bound. - * @param {number} lowerBound The desired lower bound. - * @param {number} number The number to clamp. - * @param {number} upperBound The desired upper bound. - * @return {number} The clamped number. - * @alias Blockly.utils.math.clamp - */ - export function clamp(lowerBound: number, number: number, upperBound: number): number; -} -declare module "core/serialization/priorities" { - /** - * The priority for deserializing variables. - * @type {number} - * @const - * @alias Blockly.serialization.priorities.VARIABLES - */ - export const VARIABLES: number; - /** - * The priority for deserializing blocks. - * @type {number} - * @const - * @alias Blockly.serialization.priorities.BLOCKS - */ - export const BLOCKS: number; -} -declare module "core/interfaces/i_serializer" { - /** - * Serializes and deserializes a plugin or system. - * @interface - * @alias Blockly.serialization.ISerializer.ISerializer - */ - export class ISerializer { - /** - * A priority value used to determine the order of deserializing state. - * More positive priorities are deserialized before less positive - * priorities. Eg if you have priorities (0, -10, 10, 100) the order of - * deserialiation will be (100, 10, 0, -10). - * If two serializers have the same priority, they are deserialized in an - * arbitrary order relative to each other. - * @type {number} - */ - priority: number; - /** - * Saves the state of the plugin or system. - * @param {!Workspace} workspace The workspace the system to serialize is - * associated with. - * @return {?} A JS object containing the system's state, or null if - * there is no state to record. - */ - save(workspace: Workspace): unknown; - /** - * Loads the state of the plugin or system. - * @param {?} state The state of the system to deserialize. This will always - * be non-null. - * @param {!Workspace} workspace The workspace the system to deserialize is - * associated with. - */ - load(state: unknown, workspace: Workspace): void; - /** - * Clears the state of the plugin or system. - * @param {!Workspace} workspace The workspace the system to clear the state - * of is associated with. - */ - clear(workspace: Workspace): void; - } - import { Workspace } from "core/workspace"; -} -declare module "core/serialization/registry" { - /** - * Registers the given serializer so that it can be used for serialization and - * deserialization. - * @param {string} name The name of the serializer to register. - * @param {ISerializer} serializer The serializer to register. - * @alias Blockly.serialization.registry.register - */ - export function register(name: string, serializer: ISerializer): void; - /** - * Unregisters the serializer associated with the given name. - * @param {string} name The name of the serializer to unregister. - * @alias Blockly.serialization.registry.unregister - */ - export function unregister(name: string): void; - import { ISerializer } from "core/interfaces/i_serializer"; -} -declare module "core/serialization/exceptions" { - /** - * @alias Blockly.serialization.exceptions.DeserializationError - */ - export class DeserializationError extends Error { - } - /** - * Represents an error where the serialized state is expected to provide a - * block type, but it is not provided. - * @alias Blockly.serialization.exceptions.MissingBlockType - */ - export class MissingBlockType extends DeserializationError { - /** - * @param {!State} state The state object which is missing the block type. - * @package - */ - constructor(state: any); - /** - * The state object containing the bad name. - * @type {!State} - */ - state: any; - } - /** - * Represents an error where deserialization encountered a block that did - * not have a connection that was defined in the serialized state. - * @alias Blockly.serialization.exceptions.MissingConnection - */ - export class MissingConnection extends DeserializationError { - /** - * @param {string} connection The name of the connection that is missing. E.g. - * 'IF0', or 'next'. - * @param {!Block} block The block missing the connection. - * @param {!State} state The state object containing the bad connection. - * @package - */ - constructor(connection: string, block: Block, state: any); - /** - * The block missing the connection. - * @type {!Block} - */ - block: Block; - /** - * The state object containing the bad name. - * @type {!State} - */ - state: any; - } - /** - * Represents an error where deserialization tried to connect two connections - * that were not compatible. - * @alias Blockly.serialization.exceptions.BadConnectionCheck - */ - export class BadConnectionCheck extends DeserializationError { - /** - * @param {string} reason The reason the connections were not compatible. - * @param {string} childConnection The name of the incompatible child - * connection. E.g. 'output' or 'previous'. - * @param {!Block} childBlock The child block that could not connect - * to its parent. - * @param {!State} childState The state object representing the child block. - * @package - */ - constructor(reason: string, childConnection: string, childBlock: Block, childState: any); - /** - * The block that could not connect to its parent. - * @type {!Block} - */ - childBlock: Block; - /** - * The state object representing the block that could not connect to its - * parent. - * @type {!State} - */ - childState: any; - } - /** - * Represents an error where deserialization encountered a real block as it - * was deserializing children of a shadow. - * This is an error because it is an invariant of Blockly that shadow blocks - * do not have real children. - * @alias Blockly.serialization.exceptions.RealChildOfShadow - */ - export class RealChildOfShadow extends DeserializationError { - /** - * @param {!State} state The state object representing the real block. - * @package - */ - constructor(state: any); - /** - * The state object representing the real block. - * @type {!State} - */ - state: any; - } - import { Block } from "core/block"; -} -declare module "core/utils/rect" { - /** - * Class for representing rectangular regions. - * @alias Blockly.utils.Rect - */ - export const Rect: { - new (top: number, bottom: number, left: number, right: number): { - /** @type {number} */ - top: number; - /** @type {number} */ - bottom: number; - /** @type {number} */ - left: number; - /** @type {number} */ - right: number; - /** - * Tests whether this rectangle contains a x/y coordinate. - * - * @param {number} x The x coordinate to test for containment. - * @param {number} y The y coordinate to test for containment. - * @return {boolean} Whether this rectangle contains given coordinate. - */ - contains(x: number, y: number): boolean; - /** - * Tests whether this rectangle intersects the provided rectangle. - * Assumes that the coordinate system increases going down and left. - * @param {!Rect} other The other rectangle to check for - * intersection with. - * @return {boolean} Whether this rectangle intersects the provided rectangle. - */ - intersects(other: any): boolean; - }; - }; -} -declare module "core/utils/size" { - /** - * Class for representing sizes consisting of a width and height. - * @alias Blockly.utils.Size - */ - export const Size: { - new (width: number, height: number): { - /** - * Width - * @type {number} - */ - width: number; - /** - * Height - * @type {number} - */ - height: number; - }; - /** - * Compares sizes for equality. - * @param {?Size} a A Size. - * @param {?Size} b A Size. - * @return {boolean} True iff the sizes have equal widths and equal - * heights, or if both are null. - */ - equals(a: { - /** - * Width - * @type {number} - */ - width: number; - /** - * Height - * @type {number} - */ - height: number; - } | null, b: { - /** - * Width - * @type {number} - */ - width: number; - /** - * Height - * @type {number} - */ - height: number; - } | null): boolean; - }; -} -declare module "core/dialog" { - /** - * Wrapper to window.alert() that app developers may override via setAlert to - * provide alternatives to the modal browser window. - * @param {string} message The message to display to the user. - * @param {function()=} opt_callback The callback when the alert is dismissed. - * @alias Blockly.dialog.alert - */ - export function alert(message: string, opt_callback?: (() => any) | undefined): void; - /** - * Sets the function to be run when Blockly.dialog.alert() is called. - * @param {!function(string, function()=)} alertFunction The function to be run. - * @see Blockly.dialog.alert - * @alias Blockly.dialog.setAlert - */ - export function setAlert(alertFunction: (arg0: string, arg1: (() => any) | undefined) => any): void; - /** - * Wrapper to window.confirm() that app developers may override via setConfirm - * to provide alternatives to the modal browser window. - * @param {string} message The message to display to the user. - * @param {!function(boolean)} callback The callback for handling user response. - * @alias Blockly.dialog.confirm - */ - export function confirm(message: string, callback: (arg0: boolean) => any): void; - /** - * Sets the function to be run when Blockly.dialog.confirm() is called. - * @param {!function(string, !function(boolean))} confirmFunction The function - * to be run. - * @see Blockly.dialog.confirm - * @alias Blockly.dialog.setConfirm - */ - export function setConfirm(confirmFunction: (arg0: string, arg1: (arg0: boolean) => any) => any): void; - /** - * Wrapper to window.prompt() that app developers may override via setPrompt to - * provide alternatives to the modal browser window. Built-in browser prompts - * are often used for better text input experience on mobile device. We strongly - * recommend testing mobile when overriding this. - * @param {string} message The message to display to the user. - * @param {string} defaultValue The value to initialize the prompt with. - * @param {!function(?string)} callback The callback for handling user response. - * @alias Blockly.dialog.prompt - */ - export function prompt(message: string, defaultValue: string, callback: (arg0: string | null) => any): void; - /** - * Sets the function to be run when Blockly.dialog.prompt() is called. - * @param {!function(string, string, !function(?string))} promptFunction The - * function to be run. - * @see Blockly.dialog.prompt - * @alias Blockly.dialog.setPrompt - */ - export function setPrompt(promptFunction: (arg0: string, arg1: string, arg2: (arg0: string | null) => any) => any): void; -} -declare module "core/utils/xml" { - /** - * Namespace for Blockly's XML. - * @alias Blockly.utils.xml.NAME_SPACE - */ - export const NAME_SPACE: "https://developers.google.com/blockly/xml"; - /** - * Get the document object to use for XML serialization. - * @return {!Document} The document object. - * @alias Blockly.utils.xml.getDocument - */ - export function getDocument(): Document; - /** - * Get the document object to use for XML serialization. - * @param {!Document} document The document object to use. - * @alias Blockly.utils.xml.setDocument - */ - export function setDocument(document: Document): void; - /** - * Create DOM element for XML. - * @param {string} tagName Name of DOM element. - * @return {!Element} New DOM element. - * @alias Blockly.utils.xml.createElement - */ - export function createElement(tagName: string): Element; - /** - * Create text element for XML. - * @param {string} text Text content. - * @return {!Text} New DOM text node. - * @alias Blockly.utils.xml.createTextNode - */ - export function createTextNode(text: string): Text; - /** - * Converts an XML string into a DOM tree. - * @param {string} text XML string. - * @return {Document} The DOM document. - * @throws if XML doesn't parse. - * @alias Blockly.utils.xml.textToDomDocument - */ - export function textToDomDocument(text: string): Document; - /** - * Converts a DOM structure into plain text. - * Currently the text format is fairly ugly: all one line with no whitespace. - * @param {!Node} dom A tree of XML nodes. - * @return {string} Text representation. - * @alias Blockly.utils.xml.domToText - */ - export function domToText(dom: Node): string; -} -declare module "core/events/events_var_base" { - /** - * Abstract class for a variable event. - * @extends {AbstractEvent} - * @alias Blockly.Events.VarBase - */ - export class VarBase extends AbstractEvent { - /** - * @param {!VariableModel=} opt_variable The variable this event - * corresponds to. Undefined for a blank event. - */ - constructor(opt_variable?: VariableModel | undefined); - /** - * The variable id for the variable this event pertains to. - * @type {string} - */ - varId: string; - } - import { Abstract as AbstractEvent } from "core/events/events_abstract"; - import { VariableModel } from "core/variable_model"; -} -declare module "core/events/events_var_create" { - /** - * Class for a variable creation event. - * @extends {VarBase} - * @alias Blockly.Events.VarCreate - */ - export class VarCreate extends VarBase { - varType: string | undefined; - varName: string | undefined; - } - import { VarBase } from "core/events/events_var_base"; -} -declare module "core/variable_model" { - /** - * Class for a variable model. - * Holds information for the variable including name, ID, and type. - * @see {Blockly.FieldVariable} - * @alias Blockly.VariableModel - */ - export class VariableModel { - /** - * A custom compare function for the VariableModel objects. - * @param {VariableModel} var1 First variable to compare. - * @param {VariableModel} var2 Second variable to compare. - * @return {number} -1 if name of var1 is less than name of var2, 0 if equal, - * and 1 if greater. - * @package - */ - static compareByName(var1: VariableModel, var2: VariableModel): number; - /** - * @param {!Workspace} workspace The variable's workspace. - * @param {string} name The name of the variable. This is the user-visible - * name (e.g. 'my var' or '私の変数'), not the generated name. - * @param {string=} opt_type The type of the variable like 'int' or 'string'. - * Does not need to be unique. Field_variable can filter variables based - * on their type. This will default to '' which is a specific type. - * @param {string=} opt_id The unique ID of the variable. This will default to - * a UUID. - */ - constructor(workspace: Workspace, name: string, opt_type?: string | undefined, opt_id?: string | undefined); - /** - * The workspace the variable is in. - * @type {!Workspace} - */ - workspace: Workspace; - /** - * The name of the variable, typically defined by the user. It may be - * changed by the user. - * @type {string} - */ - name: string; - /** - * The type of the variable, such as 'int' or 'sound_effect'. This may be - * used to build a list of variables of a specific type. By default this is - * the empty string '', which is a specific type. - * @see {Blockly.FieldVariable} - * @type {string} - */ - type: string; - /** - * A unique ID for the variable. This should be defined at creation and - * not change, even if the name changes. In most cases this should be a - * UUID. - * @type {string} - * @private - */ - private id_; - /** - * @return {string} The ID for the variable. - */ - getId(): string; - } - import { Workspace } from "core/workspace"; -} -declare module "core/variables" { - /** - * String for use in the "custom" attribute of a category in toolbox XML. - * This string indicates that the category should be dynamically populated with - * variable blocks. - * See also Blockly.Procedures.CATEGORY_NAME and - * Blockly.VariablesDynamic.CATEGORY_NAME. - * @const {string} - * @alias Blockly.Variables.CATEGORY_NAME - */ - export const CATEGORY_NAME: "VARIABLE"; - /** - * Find all user-created variables that are in use in the workspace. - * For use by generators. - * To get a list of all variables on a workspace, including unused variables, - * call Workspace.getAllVariables. - * @param {!Workspace} ws The workspace to search for variables. - * @return {!Array} Array of variable models. - * @alias Blockly.Variables.allUsedVarModels - */ - export function allUsedVarModels(ws: Workspace): Array; - /** - * Find all developer variables used by blocks in the workspace. - * Developer variables are never shown to the user, but are declared as global - * variables in the generated code. - * To declare developer variables, define the getDeveloperVariables function on - * your block and return a list of variable names. - * For use by generators. - * @param {!Workspace} workspace The workspace to search. - * @return {!Array} A list of non-duplicated variable names. - * @alias Blockly.Variables.allDeveloperVariables - */ - export function allDeveloperVariables(workspace: Workspace): Array; - /** - * Construct the elements (blocks and button) required by the flyout for the - * variable category. - * @param {!WorkspaceSvg} workspace The workspace containing variables. - * @return {!Array} Array of XML elements. - * @alias Blockly.Variables.flyoutCategory - */ - export function flyoutCategory(workspace: WorkspaceSvg): Array; - /** - * Construct the blocks required by the flyout for the variable category. - * @param {!Workspace} workspace The workspace containing variables. - * @return {!Array} Array of XML block elements. - * @alias Blockly.Variables.flyoutCategoryBlocks - */ - export function flyoutCategoryBlocks(workspace: Workspace): Array; - /** - * @alias Blockly.Variables.VAR_LETTER_OPTIONS - */ - export const VAR_LETTER_OPTIONS: "ijkmnopqrstuvwxyzabcdefgh"; - /** - * Return a new variable name that is not yet being used. This will try to - * generate single letter variable names in the range 'i' to 'z' to start with. - * If no unique name is located it will try 'i' to 'z', 'a' to 'h', - * then 'i2' to 'z2' etc. Skip 'l'. - * @param {!Workspace} workspace The workspace to be unique in. - * @return {string} New variable name. - * @alias Blockly.Variables.generateUniqueName - */ - export function generateUniqueName(workspace: Workspace): string; - /** - * Returns a unique name that is not present in the usedNames array. This - * will try to generate single letter names in the range a -> z (skip l). It - * will start with the character passed to startChar. - * @param {string} startChar The character to start the search at. - * @param {!Array} usedNames A list of all of the used names. - * @return {string} A unique name that is not present in the usedNames array. - * @alias Blockly.Variables.generateUniqueNameFromOptions - */ - export function generateUniqueNameFromOptions(startChar: string, usedNames: Array): string; - /** - * Handles "Create Variable" button in the default variables toolbox category. - * It will prompt the user for a variable name, including re-prompts if a name - * is already in use among the workspace's variables. - * - * Custom button handlers can delegate to this function, allowing variables - * types and after-creation processing. More complex customization (e.g., - * prompting for variable type) is beyond the scope of this function. - * - * @param {!Workspace} workspace The workspace on which to create the - * variable. - * @param {function(?string=)=} opt_callback A callback. It will be passed an - * acceptable new variable name, or null if change is to be aborted (cancel - * button), or undefined if an existing variable was chosen. - * @param {string=} opt_type The type of the variable like 'int', 'string', or - * ''. This will default to '', which is a specific type. - * @alias Blockly.Variables.createVariableButtonHandler - */ - export function createVariableButtonHandler(workspace: Workspace, opt_callback?: ((arg0: (string | null) | undefined) => any) | undefined, opt_type?: string | undefined): void; - /** - * Opens a prompt that allows the user to enter a new name for a variable. - * Triggers a rename if the new name is valid. Or re-prompts if there is a - * collision. - * @param {!Workspace} workspace The workspace on which to rename the - * variable. - * @param {!VariableModel} variable Variable to rename. - * @param {function(?string=)=} opt_callback A callback. It will - * be passed an acceptable new variable name, or null if change is to be - * aborted (cancel button), or undefined if an existing variable was chosen. - * @alias Blockly.Variables.renameVariable - */ - export function renameVariable(workspace: Workspace, variable: VariableModel, opt_callback?: ((arg0: (string | null) | undefined) => any) | undefined): void; - /** - * Prompt the user for a new variable name. - * @param {string} promptText The string of the prompt. - * @param {string} defaultText The default value to show in the prompt's field. - * @param {function(?string)} callback A callback. It will return the new - * variable name, or null if the user picked something illegal. - * @alias Blockly.Variables.promptName - */ - export function promptName(promptText: string, defaultText: string, callback: (arg0: string | null) => any): void; - /** - * Check whether there exists a variable with the given name of any type. - * @param {string} name The name to search for. - * @param {!Workspace} workspace The workspace to search for the - * variable. - * @return {?VariableModel} The variable with the given name, - * or null if none was found. - * @alias Blockly.Variables.nameUsedWithAnyType - */ - export function nameUsedWithAnyType(name: string, workspace: Workspace): VariableModel | null; - /** - * Generate DOM objects representing a variable field. - * @param {!VariableModel} variableModel The variable model to - * represent. - * @return {?Element} The generated DOM. - * @alias Blockly.Variables.generateVariableFieldDom - */ - export function generateVariableFieldDom(variableModel: VariableModel): Element | null; - /** - * Helper function to look up or create a variable on the given workspace. - * If no variable exists, creates and returns it. - * @param {!Workspace} workspace The workspace to search for the - * variable. It may be a flyout workspace or main workspace. - * @param {?string} id The ID to use to look up or create the variable, or null. - * @param {string=} opt_name The string to use to look up or create the - * variable. - * @param {string=} opt_type The type to use to look up or create the variable. - * @return {!VariableModel} The variable corresponding to the given ID - * or name + type combination. - * @alias Blockly.Variables.getOrCreateVariablePackage - */ - export function getOrCreateVariablePackage(workspace: Workspace, id: string | null, opt_name?: string | undefined, opt_type?: string | undefined): VariableModel; - /** - * Look up a variable on the given workspace. - * Always looks in the main workspace before looking in the flyout workspace. - * Always prefers lookup by ID to lookup by name + type. - * @param {!Workspace} workspace The workspace to search for the - * variable. It may be a flyout workspace or main workspace. - * @param {?string} id The ID to use to look up the variable, or null. - * @param {string=} opt_name The string to use to look up the variable. - * Only used if lookup by ID fails. - * @param {string=} opt_type The type to use to look up the variable. - * Only used if lookup by ID fails. - * @return {?VariableModel} The variable corresponding to the given ID - * or name + type combination, or null if not found. - * @alias Blockly.Variables.getVariable - */ - export function getVariable(workspace: Workspace, id: string | null, opt_name?: string | undefined, opt_type?: string | undefined): VariableModel | null; - /** - * Helper function to get the list of variables that have been added to the - * workspace after adding a new block, using the given list of variables that - * were in the workspace before the new block was added. - * @param {!Workspace} workspace The workspace to inspect. - * @param {!Array} originalVariables The array of - * variables that existed in the workspace before adding the new block. - * @return {!Array} The new array of variables that - * were freshly added to the workspace after creating the new block, - * or [] if no new variables were added to the workspace. - * @alias Blockly.Variables.getAddedVariables - * @package - */ - export function getAddedVariables(workspace: Workspace, originalVariables: Array): Array; - import { Workspace } from "core/workspace"; - import { VariableModel } from "core/variable_model"; - import { WorkspaceSvg } from "core/workspace_svg"; -} -declare module "core/events/events_ui_base" { - /** - * Base class for a UI event. - * UI events are events that don't need to be sent over the wire for multi-user - * editing to work (e.g. scrolling the workspace, zooming, opening toolbox - * categories). - * UI events do not undo or redo. - * @extends {AbstractEvent} - * @alias Blockly.Events.UiBase - */ - export class UiBase extends AbstractEvent { - /** - * @param {string=} opt_workspaceId The workspace identifier for this event. - * Undefined for a blank event. - */ - constructor(opt_workspaceId?: string | undefined); - } - import { Abstract as AbstractEvent } from "core/events/events_abstract"; -} -declare module "core/events/events_bubble_open" { - /** - * Class for a bubble open event. - * @extends {UiBase} - * @alias Blockly.Events.BubbleOpen - */ - export class BubbleOpen extends UiBase { - /** - * @param {BlockSvg} opt_block The associated block. Undefined for a - * blank event. - * @param {boolean=} opt_isOpen Whether the bubble is opening (false if - * closing). Undefined for a blank event. - * @param {string=} opt_bubbleType The type of bubble. One of 'mutator', - * 'comment' - * or 'warning'. Undefined for a blank event. - */ - constructor(opt_block: BlockSvg, opt_isOpen?: boolean | undefined, opt_bubbleType?: string | undefined); - blockId: string | null; - /** - * Whether the bubble is opening (false if closing). - * @type {boolean|undefined} - */ - isOpen: boolean | undefined; - /** - * The type of bubble. One of 'mutator', 'comment', or 'warning'. - * @type {string|undefined} - */ - bubbleType: string | undefined; - } - import { UiBase } from "core/events/events_ui_base"; - import { BlockSvg } from "core/block_svg"; -} -declare module "core/block_animations" { - /** - * Play some UI effects (sound, animation) when disposing of a block. - * @param {!BlockSvg} block The block being disposed of. - * @alias Blockly.blockAnimations.disposeUiEffect - * @package - */ - export function disposeUiEffect(block: BlockSvg): void; - /** - * Play some UI effects (sound, ripple) after a connection has been established. - * @param {!BlockSvg} block The block being connected. - * @alias Blockly.blockAnimations.connectionUiEffect - * @package - */ - export function connectionUiEffect(block: BlockSvg): void; - /** - * Play some UI effects (sound, animation) when disconnecting a block. - * @param {!BlockSvg} block The block being disconnected. - * @alias Blockly.blockAnimations.disconnectUiEffect - * @package - */ - export function disconnectUiEffect(block: BlockSvg): void; - /** - * Stop the disconnect UI animation immediately. - * @alias Blockly.blockAnimations.disconnectUiStop - * @package - */ - export function disconnectUiStop(): void; - import { BlockSvg } from "core/block_svg"; -} -declare module "core/connection_type" { - /** - * * - */ - export type ConnectionType = number; - export namespace ConnectionType { - const INPUT_VALUE: number; - const OUTPUT_VALUE: number; - const NEXT_STATEMENT: number; - const PREVIOUS_STATEMENT: number; - } -} -declare module "core/internal_constants" { - /** - * Number of characters to truncate a collapsed block to. - * @alias Blockly.internalConstants.COLLAPSE_CHARS - */ - export const COLLAPSE_CHARS: 30; - /** - * When dragging a block out of a stack, split the stack in two (true), or drag - * out the block healing the stack (false). - * @alias Blockly.internalConstants.DRAG_STACK - */ - export const DRAG_STACK: true; - /** - * Lookup table for determining the opposite type of a connection. - * @const - * @alias Blockly.internalConstants.OPPOSITE_TYPE - */ - export const OPPOSITE_TYPE: any[]; - /** - * String for use in the dropdown created in field_variable. - * This string indicates that this option in the dropdown is 'Rename - * variable...' and if selected, should trigger the prompt to rename a variable. - * @const {string} - * @alias Blockly.internalConstants.RENAME_VARIABLE_ID - */ - export const RENAME_VARIABLE_ID: "RENAME_VARIABLE_ID"; - /** - * String for use in the dropdown created in field_variable. - * This string indicates that this option in the dropdown is 'Delete the "%1" - * variable' and if selected, should trigger the prompt to delete a variable. - * @const {string} - * @alias Blockly.internalConstants.DELETE_VARIABLE_ID - */ - export const DELETE_VARIABLE_ID: "DELETE_VARIABLE_ID"; -} -declare module "core/utils/deprecation" { - /** - * Warn developers that a function or property is deprecated. - * @param {string} name The name of the function or property. - * @param {string} deprecationDate The date of deprecation. - * Prefer 'month yyyy' or 'quarter yyyy' format. - * @param {string} deletionDate The date of deletion, in the same format as the - * deprecation date. - * @param {string=} opt_use The name of a function or property to use instead, - * if any. - * @alias Blockly.utils.deprecation.warn - * @package - */ - export function warn(name: string, deprecationDate: string, deletionDate: string, opt_use?: string | undefined): void; -} -declare module "core/utils/coordinate" { - /** - * Class for representing coordinates and positions. - * @alias Blockly.utils.Coordinate - */ - export const Coordinate: { - new (x: number, y: number): { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - }; - /** - * Compares coordinates for equality. - * @param {?Coordinate} a A Coordinate. - * @param {?Coordinate} b A Coordinate. - * @return {boolean} True iff the coordinates are equal, or if both are null. - */ - equals(a: { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - } | null, b: { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - } | null): boolean; - /** - * Returns the distance between two coordinates. - * @param {!Coordinate} a A Coordinate. - * @param {!Coordinate} b A Coordinate. - * @return {number} The distance between `a` and `b`. - */ - distance(a: { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - }, b: { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - }): number; - /** - * Returns the magnitude of a coordinate. - * @param {!Coordinate} a A Coordinate. - * @return {number} The distance between the origin and `a`. - */ - magnitude(a: { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - }): number; - /** - * Returns the difference between two coordinates as a new - * Coordinate. - * @param {!Coordinate|!SVGPoint} a An x/y coordinate. - * @param {!Coordinate|!SVGPoint} b An x/y coordinate. - * @return {!Coordinate} A Coordinate representing the difference - * between `a` and `b`. - */ - difference(a: { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - } | SVGPoint, b: { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - } | SVGPoint): { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - }; - /** - * Returns the sum of two coordinates as a new Coordinate. - * @param {!Coordinate|!SVGPoint} a An x/y coordinate. - * @param {!Coordinate|!SVGPoint} b An x/y coordinate. - * @return {!Coordinate} A Coordinate representing the sum of - * the two coordinates. - */ - sum(a: { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - } | SVGPoint, b: { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - } | SVGPoint): { - /** - * X-value - * @type {number} - */ - x: number; - /** - * Y-value - * @type {number} - */ - y: number; - /** - * Creates a new copy of this coordinate. - * @return {!Coordinate} A copy of this coordinate. - */ - clone(): any; - /** - * Scales this coordinate by the given scale factor. - * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Coordinate} This coordinate after scaling. - */ - scale(s: number): any; - /** - * Translates this coordinate by the given offsets. - * respectively. - * @param {number} tx The value to translate x by. - * @param {number} ty The value to translate y by. - * @return {!Coordinate} This coordinate after translating. - */ - translate(tx: number, ty: number): any; - }; - }; -} -declare module "core/utils/style" { - /** - * Gets the height and width of an element. - * Similar to Closure's goog.style.getSize - * @param {!Element} element Element to get size of. - * @return {!Size} Object with width/height properties. - * @alias Blockly.utils.style.getSize - */ - export function getSize(element: Element): { - width: number; - height: number; - }; - /** - * Retrieves a computed style value of a node. It returns empty string if the - * value cannot be computed (which will be the case in Internet Explorer) or - * "none" if the property requested is an SVG one and it has not been - * explicitly set (firefox and webkit). - * - * Copied from Closure's goog.style.getComputedStyle - * - * @param {!Element} element Element to get style of. - * @param {string} property Property to get (camel-case). - * @return {string} Style value. - * @alias Blockly.utils.style.getComputedStyle - */ - export function getComputedStyle(element: Element, property: string): string; - /** - * Gets the cascaded style value of a node, or null if the value cannot be - * computed (only Internet Explorer can do this). - * - * Copied from Closure's goog.style.getCascadedStyle - * - * @param {!Element} element Element to get style of. - * @param {string} style Property to get (camel-case). - * @return {string} Style value. - * @alias Blockly.utils.style.getCascadedStyle - */ - export function getCascadedStyle(element: Element, style: string): string; - /** - * Returns a Coordinate object relative to the top-left of the HTML document. - * Similar to Closure's goog.style.getPageOffset - * @param {!Element} el Element to get the page offset for. - * @return {!Coordinate} The page offset. - * @alias Blockly.utils.style.getPageOffset - */ - export function getPageOffset(el: Element): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Calculates the viewport coordinates relative to the document. - * Similar to Closure's goog.style.getViewportPageOffset - * @return {!Coordinate} The page offset of the viewport. - * @alias Blockly.utils.style.getViewportPageOffset - */ - export function getViewportPageOffset(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Shows or hides an element from the page. Hiding the element is done by - * setting the display property to "none", removing the element from the - * rendering hierarchy so it takes up no space. To show the element, the default - * inherited display property is restored (defined either in stylesheets or by - * the browser's default style rules). - * Copied from Closure's goog.style.getViewportPageOffset - * - * @param {!Element} el Element to show or hide. - * @param {*} isShown True to render the element in its default style, - * false to disable rendering the element. - * @alias Blockly.utils.style.setElementShown - */ - export function setElementShown(el: Element, isShown: any): void; - /** - * Returns true if the element is using right to left (RTL) direction. - * Copied from Closure's goog.style.isRightToLeft - * - * @param {!Element} el The element to test. - * @return {boolean} True for right to left, false for left to right. - * @alias Blockly.utils.style.isRightToLeft - */ - export function isRightToLeft(el: Element): boolean; - /** - * Gets the computed border widths (on all sides) in pixels - * Copied from Closure's goog.style.getBorderBox - * @param {!Element} element The element to get the border widths for. - * @return {!Object} The computed border widths. - * @alias Blockly.utils.style.getBorderBox - */ - export function getBorderBox(element: Element): Object; - /** - * Changes the scroll position of `container` with the minimum amount so - * that the content and the borders of the given `element` become visible. - * If the element is bigger than the container, its top left corner will be - * aligned as close to the container's top left corner as possible. - * Copied from Closure's goog.style.scrollIntoContainerView - * - * @param {!Element} element The element to make visible. - * @param {!Element} container The container to scroll. If not set, then the - * document scroll element will be used. - * @param {boolean=} opt_center Whether to center the element in the container. - * Defaults to false. - * @alias Blockly.utils.style.scrollIntoContainerView - */ - export function scrollIntoContainerView(element: Element, container: Element, opt_center?: boolean | undefined): void; - /** - * Calculate the scroll position of `container` with the minimum amount so - * that the content and the borders of the given `element` become visible. - * If the element is bigger than the container, its top left corner will be - * aligned as close to the container's top left corner as possible. - * Copied from Closure's goog.style.getContainerOffsetToScrollInto - * - * @param {!Element} element The element to make visible. - * @param {!Element} container The container to scroll. If not set, then the - * document scroll element will be used. - * @param {boolean=} opt_center Whether to center the element in the container. - * Defaults to false. - * @return {!Coordinate} The new scroll position of the container, - * in form of goog.math.Coordinate(scrollLeft, scrollTop). - * @alias Blockly.utils.style.getContainerOffsetToScrollInto - */ - export function getContainerOffsetToScrollInto(element: Element, container: Element, opt_center?: boolean | undefined): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; -} -declare module "core/utils/svg_math" { - export namespace TEST_ONLY { - export { XY_REGEX }; - export { XY_STYLE_REGEX }; - } - /** - * Return the coordinates of the top-left corner of this element relative to - * its parent. Only for SVG elements and children (e.g. rect, g, path). - * @param {!Element} element SVG element to find the coordinates of. - * @return {!Coordinate} Object with .x and .y properties. - * @alias Blockly.utils.svgMath.getRelativeXY - */ - export function getRelativeXY(element: Element): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Return the coordinates of the top-left corner of this element relative to - * the div Blockly was injected into. - * @param {!Element} element SVG element to find the coordinates of. If this is - * not a child of the div Blockly was injected into, the behaviour is - * undefined. - * @return {!Coordinate} Object with .x and .y properties. - * @alias Blockly.utils.svgMath.getInjectionDivXY - */ - export function getInjectionDivXY(element: Element): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Check if 3D transforms are supported by adding an element - * and attempting to set the property. - * @return {boolean} True if 3D transforms are supported. - * @alias Blockly.utils.svgMath.is3dSupported - */ - export function is3dSupported(): boolean; - /** - * Get the position of the current viewport in window coordinates. This takes - * scroll into account. - * @return {!Rect} An object containing window width, height, and - * scroll position in window coordinates. - * @alias Blockly.utils.svgMath.getViewportBBox - * @package - */ - export function getViewportBBox(): { - top: number; - bottom: number; - left: number; - right: number; - contains(x: number, y: number): boolean; - intersects(other: any): boolean; - }; - /** - * Gets the document scroll distance as a coordinate object. - * Copied from Closure's goog.dom.getDocumentScroll. - * @return {!Coordinate} Object with values 'x' and 'y'. - * @alias Blockly.utils.svgMath.getDocumentScroll - */ - export function getDocumentScroll(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Converts screen coordinates to workspace coordinates. - * @param {!WorkspaceSvg} ws The workspace to find the coordinates on. - * @param {!Coordinate} screenCoordinates The screen coordinates to - * be converted to workspace coordinates - * @return {!Coordinate} The workspace coordinates. - * @alias Blockly.utils.svgMath.screenToWsCoordinates - */ - export function screenToWsCoordinates(ws: WorkspaceSvg, screenCoordinates: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Returns the dimensions of the specified SVG image. - * @param {!SVGElement} svg SVG image. - * @return {!Size} Contains width and height properties. - * @deprecated Use workspace.getCachedParentSvgSize. (2021 March 5) - * @alias Blockly.utils.svgMath.svgSize - */ - export function svgSize(svg: SVGElement): { - width: number; - height: number; - }; - /** - * Static regex to pull the x,y values out of an SVG translate() directive. - * Note that Firefox and IE (9,10) return 'translate(12)' instead of - * 'translate(12, 0)'. - * Note that IE (9,10) returns 'translate(16 8)' instead of 'translate(16, 8)'. - * Note that IE has been reported to return scientific notation (0.123456e-42). - * @type {!RegExp} - */ - const XY_REGEX: RegExp; - /** - * Static regex to pull the x,y values out of a translate() or translate3d() - * style property. - * Accounts for same exceptions as XY_REGEX. - * @type {!RegExp} - */ - const XY_STYLE_REGEX: RegExp; - import { WorkspaceSvg } from "core/workspace_svg"; - export {}; -} -declare module "core/block_drag_surface" { - /** - * Class for a drag surface for the currently dragged block. This is a separate - * SVG that contains only the currently moving block, or nothing. - * @alias Blockly.BlockDragSurfaceSvg - */ - export const BlockDragSurfaceSvg: { - new (container: Element): { - /** - * The SVG drag surface. Set once by BlockDragSurfaceSvg.createDom. - * @type {?SVGElement} - * @private - */ - SVG_: SVGElement | null; - /** - * This is where blocks live while they are being dragged if the drag - * surface is enabled. - * @type {?SVGElement} - * @private - */ - dragGroup_: SVGElement | null; - /** - * Containing HTML element; parent of the workspace and the drag surface. - * @type {!Element} - * @private - */ - container_: Element; - /** - * Cached value for the scale of the drag surface. - * Used to set/get the correct translation during and after a drag. - * @type {number} - * @private - */ - scale_: number; - /** - * Cached value for the translation of the drag surface. - * This translation is in pixel units, because the scale is applied to the - * drag group rather than the top-level SVG. - * @type {?Coordinate} - * @private - */ - surfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - } | null; - /** - * Cached value for the translation of the child drag surface in pixel - * units. Since the child drag surface tracks the translation of the - * workspace this is ultimately the translation of the workspace. - * @type {!Coordinate} - * @private - */ - childSurfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Create the drag surface and inject it into the container. - */ - createDom(): void; - /** - * Set the SVG blocks on the drag surface's group and show the surface. - * Only one block group should be on the drag surface at a time. - * @param {!SVGElement} blocks Block or group of blocks to place on the drag - * surface. - */ - setBlocksAndShow(blocks: SVGElement): void; - /** - * Translate and scale the entire drag surface group to the given position, to - * keep in sync with the workspace. - * @param {number} x X translation in pixel coordinates. - * @param {number} y Y translation in pixel coordinates. - * @param {number} scale Scale of the group. - */ - translateAndScaleGroup(x: number, y: number, scale: number): void; - /** - * Translate the drag surface's SVG based on its internal state. - * @private - */ - translateSurfaceInternal_(): void; - /** - * Translates the entire surface by a relative offset. - * @param {number} deltaX Horizontal offset in pixel units. - * @param {number} deltaY Vertical offset in pixel units. - */ - translateBy(deltaX: number, deltaY: number): void; - /** - * Translate the entire drag surface during a drag. - * We translate the drag surface instead of the blocks inside the surface - * so that the browser avoids repainting the SVG. - * Because of this, the drag coordinates must be adjusted by scale. - * @param {number} x X translation for the entire surface. - * @param {number} y Y translation for the entire surface. - */ - translateSurface(x: number, y: number): void; - /** - * Reports the surface translation in scaled workspace coordinates. - * Use this when finishing a drag to return blocks to the correct position. - * @return {!Coordinate} Current translation of the surface. - */ - getSurfaceTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Provide a reference to the drag group (primarily for - * BlockSvg.getRelativeToSurfaceXY). - * @return {?SVGElement} Drag surface group element. - */ - getGroup(): SVGElement | null; - /** - * Returns the SVG drag surface. - * @returns {?SVGElement} The SVG drag surface. - */ - getSvgRoot(): SVGElement | null; - /** - * Get the current blocks on the drag surface, if any (primarily - * for BlockSvg.getRelativeToSurfaceXY). - * @return {?Element} Drag surface block DOM element, or null if no blocks - * exist. - */ - getCurrentBlock(): Element | null; - /** - * Gets the translation of the child block surface - * This surface is in charge of keeping track of how much the workspace has - * moved. - * @return {!Coordinate} The amount the workspace has been moved. - */ - getWsTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Clear the group and hide the surface; move the blocks off onto the provided - * element. - * If the block is being deleted it doesn't need to go back to the original - * surface, since it would be removed immediately during dispose. - * @param {Element=} opt_newSurface Surface the dragging blocks should be - * moved to, or null if the blocks should be removed from this surface - * without being moved to a different surface. - */ - clearAndHide(opt_newSurface?: Element | undefined): void; - }; - }; -} -declare module "core/events/events_comment_change" { - /** - * Class for a comment change event. - * @extends {CommentBase} - * @alias Blockly.Events.CommentChange - */ - export class CommentChange extends CommentBase { - /** - * @param {!WorkspaceComment=} opt_comment The comment that is being - * changed. Undefined for a blank event. - * @param {string=} opt_oldContents Previous contents of the comment. - * @param {string=} opt_newContents New contents of the comment. - */ - constructor(opt_comment?: WorkspaceComment | undefined, opt_oldContents?: string | undefined, opt_newContents?: string | undefined); - oldContents_: string | undefined; - newContents_: string | undefined; - } - import { CommentBase } from "core/events/events_comment_base"; - import { WorkspaceComment } from "core/workspace_comment"; -} -declare module "core/events/events_comment_delete" { - /** - * Class for a comment deletion event. - * @extends {CommentBase} - * @alias Blockly.Events.CommentDelete - */ - export class CommentDelete extends CommentBase { - xml: Element | undefined; - } - import { CommentBase } from "core/events/events_comment_base"; -} -declare module "core/workspace_comment" { - /** - * Class for a workspace comment. - * @alias Blockly.WorkspaceComment - */ - export class WorkspaceComment { - /** - * Fire a create event for the given workspace comment, if comments are - * enabled. - * @param {!WorkspaceComment} comment The comment that was just created. - * @package - */ - static fireCreateEvent(comment: WorkspaceComment): void; - /** - * Decode an XML comment tag and create a comment on the workspace. - * @param {!Element} xmlComment XML comment element. - * @param {!Workspace} workspace The workspace. - * @return {!WorkspaceComment} The created workspace comment. - * @package - */ - static fromXml(xmlComment: Element, workspace: Workspace): WorkspaceComment; - /** - * Decode an XML comment tag and return the results in an object. - * @param {!Element} xml XML comment element. - * @return {{w: number, h: number, x: number, y: number, content: string}} An - * object containing the id, size, position, and comment string. - * @package - */ - static parseAttributes(xml: Element): { - w: number; - h: number; - x: number; - y: number; - content: string; - }; - /** - * @param {!Workspace} workspace The block's workspace. - * @param {string} content The content of this workspace comment. - * @param {number} height Height of the comment. - * @param {number} width Width of the comment. - * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise - * create a new ID. - */ - constructor(workspace: Workspace, content: string, height: number, width: number, opt_id?: string | undefined); - /** @type {string} */ - id: string; - /** - * The comment's position in workspace units. (0, 0) is at the workspace's - * origin; scale does not change this value. - * @type {!Coordinate} - * @protected - */ - protected xy_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * The comment's height in workspace units. Scale does not change this - * value. - * @type {number} - * @protected - */ - protected height_: number; - /** - * The comment's width in workspace units. Scale does not change this - * value. - * @type {number} - * @protected - */ - protected width_: number; - /** - * @type {!Workspace} - */ - workspace: Workspace; - /** - * @protected - * @type {boolean} - */ - protected RTL: boolean; - /** - * @type {boolean} - * @private - */ - private deletable_; - /** - * @type {boolean} - * @private - */ - private movable_; - /** - * @type {boolean} - * @private - */ - private editable_; - /** - * @protected - * @type {string} - */ - protected content_: string; - /** - * Whether this comment has been disposed. - * @protected - * @type {boolean} - */ - protected disposed_: boolean; - /** - * @package - * @type {boolean} - */ - isComment: boolean; - /** - * Dispose of this comment. - * @package - */ - dispose(): void; - /** - * Get comment height. - * @return {number} Comment height. - * @package - */ - getHeight(): number; - /** - * Set comment height. - * @param {number} height Comment height. - * @package - */ - setHeight(height: number): void; - /** - * Get comment width. - * @return {number} Comment width. - * @package - */ - getWidth(): number; - /** - * Set comment width. - * @param {number} width comment width. - * @package - */ - setWidth(width: number): void; - /** - * Get stored location. - * @return {!Coordinate} The comment's stored location. - * This is not valid if the comment is currently being dragged. - * @package - */ - getXY(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Move a comment by a relative offset. - * @param {number} dx Horizontal offset, in workspace units. - * @param {number} dy Vertical offset, in workspace units. - * @package - */ - moveBy(dx: number, dy: number): void; - /** - * Get whether this comment is deletable or not. - * @return {boolean} True if deletable. - * @package - */ - isDeletable(): boolean; - /** - * Set whether this comment is deletable or not. - * @param {boolean} deletable True if deletable. - * @package - */ - setDeletable(deletable: boolean): void; - /** - * Get whether this comment is movable or not. - * @return {boolean} True if movable. - * @package - */ - isMovable(): boolean; - /** - * Set whether this comment is movable or not. - * @param {boolean} movable True if movable. - * @package - */ - setMovable(movable: boolean): void; - /** - * Get whether this comment is editable or not. - * @return {boolean} True if editable. - */ - isEditable(): boolean; - /** - * Set whether this comment is editable or not. - * @param {boolean} editable True if editable. - */ - setEditable(editable: boolean): void; - /** - * Returns this comment's text. - * @return {string} Comment text. - * @package - */ - getContent(): string; - /** - * Set this comment's content. - * @param {string} content Comment content. - * @package - */ - setContent(content: string): void; - /** - * Encode a comment subtree as XML with XY coordinates. - * @param {boolean=} opt_noId True if the encoder should skip the comment ID. - * @return {!Element} Tree of XML elements. - * @package - */ - toXmlWithXY(opt_noId?: boolean | undefined): Element; - /** - * Encode a comment subtree as XML, but don't serialize the XY coordinates. - * This method avoids some expensive metrics-related calls that are made in - * toXmlWithXY(). - * @param {boolean=} opt_noId True if the encoder should skip the comment ID. - * @return {!Element} Tree of XML elements. - * @package - */ - toXml(opt_noId?: boolean | undefined): Element; - } - import { Workspace } from "core/workspace"; -} -declare module "core/events/events_comment_create" { - /** - * Class for a comment creation event. - * @extends {CommentBase} - * @alias Blockly.Events.CommentCreate - */ - export class CommentCreate extends CommentBase { - xml: Element | undefined; - } - import { CommentBase } from "core/events/events_comment_base"; -} -declare module "core/events/events_comment_base" { - /** - * Abstract class for a comment event. - * @extends {AbstractEvent} - * @alias Blockly.Events.CommentBase - */ - export class CommentBase extends AbstractEvent { - /** - * Helper function for Comment[Create|Delete] - * @param {!CommentCreate|!CommentDelete} event - * The event to run. - * @param {boolean} create if True then Create, if False then Delete - */ - static CommentCreateDeleteHelper(event: CommentCreate | CommentDelete, create: boolean): void; - /** - * @param {!WorkspaceComment=} opt_comment The comment this event - * corresponds to. Undefined for a blank event. - */ - constructor(opt_comment?: WorkspaceComment | undefined); - /** - * The ID of the comment this event pertains to. - * @type {string} - */ - commentId: string; - } - import { Abstract as AbstractEvent } from "core/events/events_abstract"; - import { CommentCreate } from "core/events/events_comment_create"; - import { CommentDelete } from "core/events/events_comment_delete"; - import { WorkspaceComment } from "core/workspace_comment"; -} -declare module "core/events/events_comment_move" { - /** - * Class for a comment move event. Created before the move. - * @extends {CommentBase} - * @alias Blockly.Events.CommentMove - */ - export class CommentMove extends CommentBase { - /** - * The comment that is being moved. Will be cleared after recording the new - * location. - * @type {WorkspaceComment} - */ - comment_: WorkspaceComment; - /** - * The location before the move, in workspace coordinates. - * @type {!Coordinate} - */ - oldCoordinate_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * The location after the move, in workspace coordinates. - * @type {Coordinate} - */ - newCoordinate_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Record the comment's new location. Called after the move. Can only be - * called once. - */ - recordNew(): void; - /** - * Override the location before the move. Use this if you don't create the - * event until the end of the move, but you know the original location. - * @param {!Coordinate} xy The location before the move, - * in workspace coordinates. - */ - setOldCoordinate(xy: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - } - import { CommentBase } from "core/events/events_comment_base"; - import { WorkspaceComment } from "core/workspace_comment"; -} -declare module "core/interfaces/i_component" { - /** - * The interface for a workspace component that can be registered with the - * ComponentManager. - * @interface - * @alias Blockly.IComponent - */ - export function IComponent(): void; - export namespace IComponent { - const id: string; - } -} -declare module "core/interfaces/i_autohideable" { - /** - * Interface for a component that can be automatically hidden. - * @extends {IComponent} - * @interface - * @alias Blockly.IAutoHideable - */ - export class IAutoHideable {} -} -declare module "core/interfaces/i_deletable" { - /** - * The interface for an object that can be deleted. - * @interface - * @alias Blockly.IDeletable - */ - export class IDeletable {} -} -declare module "core/interfaces/i_draggable" { - /** - * The interface for an object that can be dragged. - * @extends {IDeletable} - * @interface - * @alias Blockly.IDraggable - */ - export class IDraggable {} -} -declare module "core/interfaces/i_drag_target" { - /** - * Interface for a component with custom behaviour when a block or bubble is - * dragged over or dropped on top of it. - * @extends {IComponent} - * @interface - * @alias Blockly.IDragTarget - */ - export class IDragTarget {} -} -declare module "core/interfaces/i_delete_area" { - /** - * Interface for a component that can delete a block or bubble that is dropped - * on top of it. - * @extends {IDragTarget} - * @interface - * @alias Blockly.IDeleteArea - */ - export class IDeleteArea {} -} -declare module "core/interfaces/i_registrable" { - /** - * The interface for a Blockly component that can be registered. - * @interface - * @alias Blockly.IRegistrable - */ - export class IRegistrable {} -} -declare module "core/interfaces/i_flyout" { - export class IFlyout { - /** - * Whether the flyout is laid out horizontally or not. - * @type {boolean} - */ - horizontalLayout: boolean; - /** - * Is RTL vs LTR. - * @type {boolean} - */ - RTL: boolean; - /** - * The target workspace - * @type {?WorkspaceSvg} - */ - targetWorkspace: WorkspaceSvg | null; - /** - * Margin around the edges of the blocks in the flyout. - * @type {number} - * @const - */ - MARGIN: number; - /** - * Does the flyout automatically close when a block is created? - * @type {boolean} - */ - autoClose: boolean; - /** - * Corner radius of the flyout background. - * @type {number} - * @const - */ - CORNER_RADIUS: number; - } - import { WorkspaceSvg } from "core/workspace_svg"; -} -declare module "core/utils/metrics" { - /** - * @record - * @alias Blockly.utils.Metrics - */ - export class Metrics { - /** - * Height of the visible portion of the workspace. - * @type {number} - */ - viewHeight: number; - /** - * Width of the visible portion of the workspace. - * @type {number} - */ - viewWidth: number; - /** - * Height of the content. - * @type {number} - */ - contentHeight: number; - /** - * Width of the content. - * @type {number} - */ - contentWidth: number; - /** - * Height of the scroll area. - * @type {number} - */ - scrollHeight: number; - /** - * Width of the scroll area. - * @type {number} - */ - scrollWidth: number; - /** - * Top-edge of the visible portion of the workspace, relative to the workspace - * origin. - * @type {number} - */ - viewTop: number; - /** - * Left-edge of the visible portion of the workspace, relative to the workspace - * origin. - * @type {number} - */ - viewLeft: number; - /** - * Top-edge of the content, relative to the workspace origin. - * @type {number} - */ - contentTop: number; - /** - * Left-edge of the content relative to the workspace origin. - * @type {number} - */ - contentLeft: number; - /** - * Top-edge of the scroll area, relative to the workspace origin. - * @type {number} - */ - scrollTop: number; - /** - * Left-edge of the scroll area relative to the workspace origin. - * @type {number} - */ - scrollLeft: number; - /** - * Top-edge of the visible portion of the workspace, relative to the blocklyDiv. - * @type {number} - */ - absoluteTop: number; - /** - * Left-edge of the visible portion of the workspace, relative to the - * blocklyDiv. - * @type {number} - */ - absoluteLeft: number; - /** - * Height of the Blockly div (the view + the toolbox, simple of otherwise). - * @type {number} - */ - svgHeight: number; - /** - * Width of the Blockly div (the view + the toolbox, simple or otherwise). - * @type {number} - */ - svgWidth: number; - /** - * Width of the toolbox, if it exists. Otherwise zero. - * @type {number} - */ - toolboxWidth: number; - /** - * Height of the toolbox, if it exists. Otherwise zero. - * @type {number} - */ - toolboxHeight: number; - /** - * Top, bottom, left or right. Use TOOLBOX_AT constants to compare. - * @type {number} - */ - toolboxPosition: number; - /** - * Width of the flyout if it is always open. Otherwise zero. - * @type {number} - */ - flyoutWidth: number; - /** - * Height of the flyout if it is always open. Otherwise zero. - * @type {number} - */ - flyoutHeight: number; - } -} -declare module "core/interfaces/i_metrics_manager" { - /** - * Interface for a metrics manager. - * @interface - * @alias Blockly.IMetricsManager - */ - export class IMetricsManager {} -} -declare module "core/interfaces/i_toolbox_item" { - /** - * Interface for an item in the toolbox. - * @interface - * @alias Blockly.IToolboxItem - */ - export class IToolboxItem {} -} -declare module "core/interfaces/i_toolbox" { - /** - * Interface for a toolbox. - * @extends {IRegistrable} - * @interface - * @alias Blockly.IToolbox - */ - export class IToolbox {} -} -declare module "core/metrics_manager" { - /** - * The manager for all workspace metrics calculations. - * @implements {IMetricsManager} - * @alias Blockly.MetricsManager - */ - export class MetricsManager implements IMetricsManager { - /** - * @param {!WorkspaceSvg} workspace The workspace to calculate metrics - * for. - */ - constructor(workspace: WorkspaceSvg); - /** - * The workspace to calculate metrics for. - * @type {!WorkspaceSvg} - * @protected - */ - protected workspace_: WorkspaceSvg; - /** - * Gets the dimensions of the given workspace component, in pixel coordinates. - * @param {?IToolbox|?IFlyout} elem The element to get the - * dimensions of, or null. It should be a toolbox or flyout, and should - * implement getWidth() and getHeight(). - * @return {!Size} An object containing width and height - * attributes, which will both be zero if elem did not exist. - * @protected - */ - protected getDimensionsPx_(elem: ((() => void) | (IFlyout | null)) | null): { - width: number; - height: number; - }; - /** - * Gets the width and the height of the flyout on the workspace in pixel - * coordinates. Returns 0 for the width and height if the workspace has a - * category toolbox instead of a simple toolbox. - * @param {boolean=} opt_own Whether to only return the workspace's own - * flyout. - * @return {!MetricsManager.ToolboxMetrics} The width and height of the - * flyout. - * @public - */ - public getFlyoutMetrics(opt_own?: boolean | undefined): MetricsManager.ToolboxMetrics; - /** - * Gets the width, height and position of the toolbox on the workspace in - * pixel coordinates. Returns 0 for the width and height if the workspace has - * a simple toolbox instead of a category toolbox. To get the width and height - * of a - * simple toolbox @see {@link getFlyoutMetrics}. - * @return {!MetricsManager.ToolboxMetrics} The object with the width, - * height and position of the toolbox. - * @public - */ - public getToolboxMetrics(): MetricsManager.ToolboxMetrics; - /** - * Gets the width and height of the workspace's parent SVG element in pixel - * coordinates. This area includes the toolbox and the visible workspace area. - * @return {!Size} The width and height of the workspace's parent - * SVG element. - * @public - */ - public getSvgMetrics(): { - width: number; - height: number; - }; - /** - * Gets the absolute left and absolute top in pixel coordinates. - * This is where the visible workspace starts in relation to the SVG - * container. - * @return {!MetricsManager.AbsoluteMetrics} The absolute metrics for - * the workspace. - * @public - */ - public getAbsoluteMetrics(): MetricsManager.AbsoluteMetrics; - /** - * Gets the metrics for the visible workspace in either pixel or workspace - * coordinates. The visible workspace does not include the toolbox or flyout. - * @param {boolean=} opt_getWorkspaceCoordinates True to get the view metrics - * in workspace coordinates, false to get them in pixel coordinates. - * @return {!MetricsManager.ContainerRegion} The width, height, top and - * left of the viewport in either workspace coordinates or pixel - * coordinates. - * @public - */ - public getViewMetrics(opt_getWorkspaceCoordinates?: boolean | undefined): MetricsManager.ContainerRegion; - /** - * Gets content metrics in either pixel or workspace coordinates. - * The content area is a rectangle around all the top bounded elements on the - * workspace (workspace comments and blocks). - * @param {boolean=} opt_getWorkspaceCoordinates True to get the content - * metrics in workspace coordinates, false to get them in pixel - * coordinates. - * @return {!MetricsManager.ContainerRegion} The - * metrics for the content container. - * @public - */ - public getContentMetrics(opt_getWorkspaceCoordinates?: boolean | undefined): MetricsManager.ContainerRegion; - /** - * Returns whether the scroll area has fixed edges. - * @return {boolean} Whether the scroll area has fixed edges. - * @package - */ - hasFixedEdges(): boolean; - /** - * Computes the fixed edges of the scroll area. - * @param {!MetricsManager.ContainerRegion=} opt_viewMetrics The view - * metrics if they have been previously computed. Passing in null may - * cause the view metrics to be computed again, if it is needed. - * @return {!MetricsManager.FixedEdges} The fixed edges of the scroll - * area. - * @protected - */ - protected getComputedFixedEdges_(opt_viewMetrics?: MetricsManager.ContainerRegion | undefined): MetricsManager.FixedEdges; - /** - * Returns the content area with added padding. - * @param {!MetricsManager.ContainerRegion} viewMetrics The view - * metrics. - * @param {!MetricsManager.ContainerRegion} contentMetrics The content - * metrics. - * @return {{top: number, bottom: number, left: number, right: number}} The - * padded content area. - * @protected - */ - protected getPaddedContent_(viewMetrics: MetricsManager.ContainerRegion, contentMetrics: MetricsManager.ContainerRegion): { - top: number; - bottom: number; - left: number; - right: number; - }; - /** - * Returns the metrics for the scroll area of the workspace. - * @param {boolean=} opt_getWorkspaceCoordinates True to get the scroll - * metrics in workspace coordinates, false to get them in pixel - * coordinates. - * @param {!MetricsManager.ContainerRegion=} opt_viewMetrics The view - * metrics if they have been previously computed. Passing in null may - * cause the view metrics to be computed again, if it is needed. - * @param {!MetricsManager.ContainerRegion=} opt_contentMetrics The - * content metrics if they have been previously computed. Passing in null - * may cause the content metrics to be computed again, if it is needed. - * @return {!MetricsManager.ContainerRegion} The metrics for the scroll - * container. - */ - getScrollMetrics(opt_getWorkspaceCoordinates?: boolean | undefined, opt_viewMetrics?: MetricsManager.ContainerRegion | undefined, opt_contentMetrics?: MetricsManager.ContainerRegion | undefined): MetricsManager.ContainerRegion; - /** - * Returns common metrics used by UI elements. - * @return {!MetricsManager.UiMetrics} The UI metrics. - */ - getUiMetrics(): MetricsManager.UiMetrics; - /** - * Returns an object with all the metrics required to size scrollbars for a - * top level workspace. The following properties are computed: - * Coordinate system: pixel coordinates, -left, -up, +right, +down - * .viewHeight: Height of the visible portion of the workspace. - * .viewWidth: Width of the visible portion of the workspace. - * .contentHeight: Height of the content. - * .contentWidth: Width of the content. - * .scrollHeight: Height of the scroll area. - * .scrollWidth: Width of the scroll area. - * .svgHeight: Height of the Blockly div (the view + the toolbox, - * simple or otherwise), - * .svgWidth: Width of the Blockly div (the view + the toolbox, - * simple or otherwise), - * .viewTop: Top-edge of the visible portion of the workspace, relative to - * the workspace origin. - * .viewLeft: Left-edge of the visible portion of the workspace, relative to - * the workspace origin. - * .contentTop: Top-edge of the content, relative to the workspace origin. - * .contentLeft: Left-edge of the content relative to the workspace origin. - * .scrollTop: Top-edge of the scroll area, relative to the workspace origin. - * .scrollLeft: Left-edge of the scroll area relative to the workspace origin. - * .absoluteTop: Top-edge of the visible portion of the workspace, relative - * to the blocklyDiv. - * .absoluteLeft: Left-edge of the visible portion of the workspace, relative - * to the blocklyDiv. - * .toolboxWidth: Width of the toolbox, if it exists. Otherwise zero. - * .toolboxHeight: Height of the toolbox, if it exists. Otherwise zero. - * .flyoutWidth: Width of the flyout if it is always open. Otherwise zero. - * .flyoutHeight: Height of the flyout if it is always open. Otherwise zero. - * .toolboxPosition: Top, bottom, left or right. Use TOOLBOX_AT constants to - * compare. - * @return {!Metrics} Contains size and position metrics of a top - * level workspace. - * @public - */ - public getMetrics(): Metrics; - } - export namespace MetricsManager { - /** - * Describes the width, height and location of the toolbox on the main - * workspace. - */ - type ToolboxMetrics = { - width: number; - height: number; - position: toolboxUtils.Position; - }; - /** - * Describes where the viewport starts in relation to the workspace SVG. - */ - type AbsoluteMetrics = { - left: number; - top: number; - }; - /** - * All the measurements needed to describe the size and location of a - * container. - */ - type ContainerRegion = { - height: number; - width: number; - top: number; - left: number; - }; - /** - * Describes fixed edges of the workspace. - */ - type FixedEdges = { - top: (number | undefined); - bottom: (number | undefined); - left: (number | undefined); - right: (number | undefined); - }; - /** - * Common metrics used for UI elements. - */ - type UiMetrics = { - viewMetrics: MetricsManager.ContainerRegion; - absoluteMetrics: MetricsManager.AbsoluteMetrics; - toolboxMetrics: MetricsManager.ToolboxMetrics; - }; - } - import { IMetricsManager } from "core/interfaces/i_metrics_manager"; - import { WorkspaceSvg } from "core/workspace_svg"; - import { IFlyout } from "core/interfaces/i_flyout"; - import { Metrics } from "core/utils/metrics"; - import * as toolboxUtils from "core/utils/toolbox"; -} -declare module "core/interfaces/i_positionable" { - /** - * Interface for a component that is positioned on top of the workspace. - * @extends {IComponent} - * @interface - * @alias Blockly.IPositionable - */ - export class IPositionable {} -} -declare module "core/component_manager" { - /** - * Manager for all items registered with the workspace. - * @alias Blockly.ComponentManager - */ - export class ComponentManager { - /** - * A map of the components registered with the workspace, mapped to id. - * @type {!Object} - * @private - */ - private componentData_; - /** - * A map of capabilities to component IDs. - * @type {!Object>} - * @private - */ - private capabilityToComponentIds_; - /** - * Adds a component. - * @param {!ComponentManager.ComponentDatum} componentInfo The data for - * the component to register. - * @param {boolean=} opt_allowOverrides True to prevent an error when - * overriding an already registered item. - */ - addComponent(componentInfo: ComponentManager.ComponentDatum, opt_allowOverrides?: boolean | undefined): void; - /** - * Removes a component. - * @param {string} id The ID of the component to remove. - */ - removeComponent(id: string): void; - /** - * Adds a capability to a existing registered component. - * @param {string} id The ID of the component to add the capability to. - * @param {string|!ComponentManager.Capability} capability The - * capability to add. - * @template T - */ - addCapability(id: string, capability: string | { - /** - * @type {string} - * @private - */ - name_: string; - /** - * Returns the name of the capability. - * @return {string} The name. - * @override - */ - toString(): string; - }): void; - /** - * Removes a capability from an existing registered component. - * @param {string} id The ID of the component to remove the capability from. - * @param {string|!ComponentManager.Capability} capability The - * capability to remove. - * @template T - */ - removeCapability(id: string, capability: string | { - /** - * @type {string} - * @private - */ - name_: string; - /** - * Returns the name of the capability. - * @return {string} The name. - * @override - */ - toString(): string; - }): void; - /** - * Returns whether the component with this id has the specified capability. - * @param {string} id The ID of the component to check. - * @param {string|!ComponentManager.Capability} capability The - * capability to check for. - * @return {boolean} Whether the component has the capability. - * @template T - */ - hasCapability(id: string, capability: string | { - /** - * @type {string} - * @private - */ - name_: string; - /** - * Returns the name of the capability. - * @return {string} The name. - * @override - */ - toString(): string; - }): boolean; - /** - * Gets the component with the given ID. - * @param {string} id The ID of the component to get. - * @return {!IComponent|undefined} The component with the given name - * or undefined if not found. - */ - getComponent(id: string): { - (): void; - id: string; - } | undefined; - /** - * Gets all the components with the specified capability. - * @param {string|!ComponentManager.Capability - * } capability The capability of the component. - * @param {boolean} sorted Whether to return list ordered by weights. - * @return {!Array} The components that match the specified capability. - * @template T - */ - getComponents(capability: string | { - /** - * @type {string} - * @private - */ - name_: string; - /** - * Returns the name of the capability. - * @return {string} The name. - * @override - */ - toString(): string; - }, sorted: boolean): T_4[]; - } - export namespace ComponentManager { - export { Capability }; - /** - * An object storing component information. - */ - export type ComponentDatum = { - component: { - (): void; - id: string; - }; - capabilities: (Array); - weight: number; - }; - } - class Capability { - /** - * @param {string} name The name of the component capability. - */ - constructor(name: string); - /** - * @type {string} - * @private - */ - private name_; - /** - * Returns the name of the capability. - * @return {string} The name. - * @override - */ - toString(): string; - } - export {}; -} -declare module "core/interfaces/i_contextmenu" { - /** - * @interface - * @alias Blockly.IContextMenu - */ - export class IContextMenu {} -} -declare module "core/interfaces/i_bubble" { - /** - * A bubble interface. - * @interface - * @extends {IDraggable} - * @extends {IContextMenu} - * @alias Blockly.IBubble - */ - export class IBubble {} -} -declare module "core/css" { - /** - * Add some CSS to the blob that will be injected later. Allows optional - * components such as fields and the toolbox to store separate CSS. - * @param {string|!Array} cssContent Multiline CSS string or an array of - * single lines of CSS. - * @alias Blockly.Css.register - */ - export function register(cssContent: string | Array): void; - /** - * Inject the CSS into the DOM. This is preferable over using a regular CSS - * file since: - * a) It loads synchronously and doesn't force a redraw later. - * b) It speeds up loading by not blocking on a separate HTTP transfer. - * c) The CSS content may be made dynamic depending on init options. - * @param {boolean} hasCss If false, don't inject CSS - * (providing CSS becomes the document's responsibility). - * @param {string} pathToMedia Path from page to the Blockly media directory. - * @alias Blockly.Css.inject - */ - export function inject(hasCss: boolean, pathToMedia: string): void; - /** - * The CSS content for Blockly. - * @alias Blockly.Css.content - */ - export let content: string; -} -declare module "core/interfaces/i_bounded_element" { - /** - * A bounded element interface. - * @interface - * @alias Blockly.IBoundedElement - */ - export class IBoundedElement {} -} -declare module "core/interfaces/i_movable" { - /** - * The interface for an object that is movable. - * @interface - * @alias Blockly.IMovable - */ - export class IMovable {} -} -declare module "core/interfaces/i_selectable" { - export class ISelectable { - /** - * @type {string} - */ - id: string; - } -} -declare module "core/interfaces/i_copyable" { - /** - * @extends {ISelectable} - * @interface - * @alias Blockly.ICopyable - */ - export class ICopyable {} - export namespace ICopyable { - /** - * Copy Metadata. - */ - type CopyData = { - saveInfo: (Object | Element); - source: WorkspaceSvg; - typeCounts: Object | null; - }; - } - import { WorkspaceSvg } from "core/workspace_svg"; -} -declare module "core/events/events_selected" { - /** - * Class for a selected event. - * @extends {UiBase} - * @alias Blockly.Events.Selected - */ - export class Selected extends UiBase { - /** - * @param {?string=} opt_oldElementId The ID of the previously selected - * element. Null if no element last selected. Undefined for a blank event. - * @param {?string=} opt_newElementId The ID of the selected element. Null if - * no element currently selected (deselect). Undefined for a blank event. - * @param {string=} opt_workspaceId The workspace identifier for this event. - * Null if no element previously selected. Undefined for a blank event. - */ - constructor(opt_oldElementId?: (string | null) | undefined, opt_newElementId?: (string | null) | undefined, opt_workspaceId?: string | undefined); - /** - * The id of the last selected element. - * @type {?string|undefined} - */ - oldElementId: (string | undefined) | null; - /** - * The id of the selected element. - * @type {?string|undefined} - */ - newElementId: (string | undefined) | null; - } - import { UiBase } from "core/events/events_ui_base"; -} -declare module "core/workspace_comment_svg" { - /** - * Class for a workspace comment's SVG representation. - * @extends {WorkspaceComment} - * @implements {IBoundedElement} - * @implements {IBubble} - * @implements {ICopyable} - * @alias Blockly.WorkspaceCommentSvg - */ - export class WorkspaceCommentSvg extends WorkspaceComment implements IBoundedElement, IBubble, ICopyable { - /** - * Decode an XML comment tag and create a rendered comment on the workspace. - * @param {!Element} xmlComment XML comment element. - * @param {!WorkspaceSvg} workspace The workspace. - * @param {number=} opt_wsWidth The width of the workspace, which is used to - * position comments correctly in RTL. - * @return {!WorkspaceCommentSvg} The created workspace comment. - * @package - */ - static fromXmlRendered(xmlComment: Element, workspace: WorkspaceSvg, opt_wsWidth?: number | undefined): WorkspaceCommentSvg; - /** - * @param {!WorkspaceSvg} workspace The block's workspace. - * @param {string} content The content of this workspace comment. - * @param {number} height Height of the comment. - * @param {number} width Width of the comment. - * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise - * create a new ID. - */ - constructor(workspace: WorkspaceSvg, content: string, height: number, width: number, opt_id?: string | undefined); - /** - * Mouse up event data. - * @type {?browserEvents.Data} - * @private - */ - private onMouseUpWrapper_; - /** - * Mouse move event data. - * @type {?browserEvents.Data} - * @private - */ - private onMouseMoveWrapper_; - /** - * Whether event handlers have been initialized. - * @type {boolean} - * @private - */ - private eventsInit_; - /** - * @type {?Element} - * @private - */ - private textarea_; - /** - * @type {?SVGRectElement} - * @private - */ - private svgRectTarget_; - /** - * @type {?SVGRectElement} - * @private - */ - private svgHandleTarget_; - /** - * @type {?SVGForeignObjectElement} - * @private - */ - private foreignObject_; - /** - * @type {?SVGGElement} - * @private - */ - private resizeGroup_; - /** - * @type {?SVGGElement} - * @private - */ - private deleteGroup_; - /** - * @type {?SVGCircleElement} - * @private - */ - private deleteIconBorder_; - /** - * @type {boolean} - * @private - */ - private focused_; - /** - * @type {boolean} - * @private - */ - private autoLayout_; - /** - * @type {!SVGElement} - * @private - */ - private svgGroup_; - svgRect_: SVGRectElement; - /** - * Whether the comment is rendered onscreen and is a part of the DOM. - * @type {boolean} - * @private - */ - private rendered_; - /** - * Whether to move the comment to the drag surface when it is dragged. - * True if it should move, false if it should be translated directly. - * @type {boolean} - * @private - */ - private useDragSurface_; - /** - * Create and initialize the SVG representation of a workspace comment. - * May be called more than once. - * - * @param {boolean=} opt_noSelect Text inside text area will be selected if - * false - * - * @package - */ - initSvg(opt_noSelect?: boolean | undefined): void; - /** - * Handle a mouse-down on an SVG comment. - * @param {!Event} e Mouse down event or touch start event. - * @private - */ - private pathMouseDown_; - /** - * Show the context menu for this workspace comment. - * @param {!Event} e Mouse event. - * @package - */ - showContextMenu(e: Event): void; - /** - * Select this comment. Highlight it visually. - * @package - */ - select(): void; - /** - * Unselect this comment. Remove its highlighting. - * @package - */ - unselect(): void; - /** - * Select this comment. Highlight it visually. - * @package - */ - addSelect(): void; - /** - * Unselect this comment. Remove its highlighting. - * @package - */ - removeSelect(): void; - /** - * Focus this comment. Highlight it visually. - * @package - */ - addFocus(): void; - /** - * Unfocus this comment. Remove its highlighting. - * @package - */ - removeFocus(): void; - /** - * Return the coordinates of the top-left corner of this comment relative to - * the drawing surface's origin (0,0), in workspace units. - * If the comment is on the workspace, (0, 0) is the origin of the workspace - * coordinate system. - * This does not change with workspace scale. - * @return {!Coordinate} Object with .x and .y properties in - * workspace coordinates. - * @package - */ - getRelativeToSurfaceXY(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Transforms a comment by setting the translation on the transform attribute - * of the block's SVG. - * @param {number} x The x coordinate of the translation in workspace units. - * @param {number} y The y coordinate of the translation in workspace units. - * @package - */ - translate(x: number, y: number): void; - /** - * Move this comment to its workspace's drag surface, accounting for - * positioning. Generally should be called at the same time as - * setDragging(true). Does nothing if useDragSurface_ is false. - * @package - */ - moveToDragSurface(): void; - /** - * Move this comment during a drag, taking into account whether we are using a - * drag surface to translate blocks. - * @param {BlockDragSurfaceSvg} dragSurface The surface that carries - * rendered items during a drag, or null if no drag surface is in use. - * @param {!Coordinate} newLoc The location to translate to, in - * workspace coordinates. - * @package - */ - moveDuringDrag(dragSurface: { - SVG_: SVGElement | null; - dragGroup_: SVGElement | null; - container_: Element; - scale_: number; - surfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - } | null; - childSurfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - createDom(): void; /** - * @type {?SVGRectElement} - * @private - */ - setBlocksAndShow(blocks: SVGElement): void; /** - * @type {boolean} - * @private - */ - translateAndScaleGroup(x: number, y: number, scale: number): void; - translateSurfaceInternal_(): void; - translateBy(deltaX: number, deltaY: number): void; - translateSurface(x: number, y: number): void; - getSurfaceTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - getGroup(): SVGElement | null; - getSvgRoot(): SVGElement | null; - getCurrentBlock(): Element | null; - getWsTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - clearAndHide(opt_newSurface?: Element | undefined): void; - }, newLoc: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Move the bubble group to the specified location in workspace coordinates. - * @param {number} x The x position to move to. - * @param {number} y The y position to move to. - * @package - */ - moveTo(x: number, y: number): void; - /** - * Clear the comment of transform="..." attributes. - * Used when the comment is switching from 3d to 2d transform or vice versa. - * @private - */ - private clearTransformAttributes_; - /** - * Returns the coordinates of a bounding box describing the dimensions of this - * comment. - * Coordinate system: workspace coordinates. - * @return {!Rect} Object with coordinates of the bounding box. - * @package - */ - getBoundingRectangle(): { - top: number; - bottom: number; - left: number; - right: number; - contains(x: number, y: number): boolean; - intersects(other: any): boolean; - }; - /** - * Add or remove the UI indicating if this comment is movable or not. - * @package - */ - updateMovable(): void; - /** - * Recursively adds or removes the dragging class to this node and its - * children. - * @param {boolean} adding True if adding, false if removing. - * @package - */ - setDragging(adding: boolean): void; - /** - * Return the root node of the SVG or null if none exists. - * @return {!SVGElement} The root SVG node (probably a group). - * @package - */ - getSvgRoot(): SVGElement; - /** - * Update the cursor over this comment by adding or removing a class. - * @param {boolean} enable True if the delete cursor should be shown, false - * otherwise. - * @package - */ - setDeleteStyle(enable: boolean): void; - /** - * Set whether auto-layout of this bubble is enabled. The first time a bubble - * is shown it positions itself to not cover any blocks. Once a user has - * dragged it to reposition, it renders where the user put it. - * @param {boolean} _enable True if auto-layout should be enabled, false - * otherwise. - * @package - */ - setAutoLayout(_enable: boolean): void; - /** - * Encode a comment for copying. - * @return {!ICopyable.CopyData} Copy metadata. - * @package - */ - toCopyData(): ICopyable.CopyData; - /** - * Returns a bounding box describing the dimensions of this comment. - * @return {!{height: number, width: number}} Object with height and width - * properties in workspace units. - * @package - */ - getHeightWidth(): { - height: number; - width: number; - }; - /** - * Renders the workspace comment. - * @package - */ - render(): void; - /** - * Create the text area for the comment. - * @return {!Element} The top-level node of the editor. - * @private - */ - private createEditor_; - /** - * Add the resize icon to the DOM - * @private - */ - private addResizeDom_; - /** - * Add the delete icon to the DOM - * @private - */ - private addDeleteDom_; - /** - * Handle a mouse-down on comment's resize corner. - * @param {!Event} e Mouse down event. - * @private - */ - private resizeMouseDown_; - /** - * Handle a mouse-down on comment's delete icon. - * @param {!Event} e Mouse down event. - * @private - */ - private deleteMouseDown_; - /** - * Handle a mouse-out on comment's delete icon. - * @param {!Event} _e Mouse out event. - * @private - */ - private deleteMouseOut_; - /** - * Handle a mouse-up on comment's delete icon. - * @param {!Event} e Mouse up event. - * @private - */ - private deleteMouseUp_; - /** - * Stop binding to the global mouseup and mousemove events. - * @private - */ - private unbindDragEvents_; - /** - * Handle a mouse-up event while dragging a comment's border or resize handle. - * @param {!Event} _e Mouse up event. - * @private - */ - private resizeMouseUp_; - /** - * Resize this comment to follow the mouse. - * @param {!Event} e Mouse move event. - * @private - */ - private resizeMouseMove_; - /** - * Callback function triggered when the comment has resized. - * Resize the text area accordingly. - * @private - */ - private resizeComment_; - /** - * Set size - * @param {number} width width of the container - * @param {number} height height of the container - * @private - */ - private setSize_; - /** - * Dispose of any rendered comment components. - * @private - */ - private disposeInternal_; - /** - * Set the focus on the text area. - * @package - */ - setFocus(): void; - /** - * Remove focus from the text area. - * @package - */ - blurFocus(): void; - } - export namespace WorkspaceCommentSvg { - const DEFAULT_SIZE: number; - const TOP_OFFSET: number; - } - import { IBoundedElement } from "core/interfaces/i_bounded_element"; - import { IBubble } from "core/interfaces/i_bubble"; - import { ICopyable } from "core/interfaces/i_copyable"; - import { WorkspaceComment } from "core/workspace_comment"; - import { WorkspaceSvg } from "core/workspace_svg"; -} -declare module "core/scrollbar" { - /** - * A note on units: most of the numbers that are in CSS pixels are scaled if the - * scrollbar is in a mutator. - */ - /** - * Class for a pure SVG scrollbar. - * This technique offers a scrollbar that is guaranteed to work, but may not - * look or behave like the system's scrollbars. - * @alias Blockly.Scrollbar - */ - export class Scrollbar { - /** - * @param {!Metrics} first An object containing computed - * measurements of a workspace. - * @param {!Metrics} second Another object containing computed - * measurements of a workspace. - * @return {boolean} Whether the two sets of metrics are equivalent. - * @private - */ - private static metricsAreEquivalent_; - /** - * @param {!WorkspaceSvg} workspace Workspace to bind the scrollbar to. - * @param {boolean} horizontal True if horizontal, false if vertical. - * @param {boolean=} opt_pair True if scrollbar is part of a horiz/vert pair. - * @param {string=} opt_class A class to be applied to this scrollbar. - * @param {number=} opt_margin The margin to apply to this scrollbar. - */ - constructor(workspace: WorkspaceSvg, horizontal: boolean, opt_pair?: boolean | undefined, opt_class?: string | undefined, opt_margin?: number | undefined); - /** - * The workspace this scrollbar is bound to. - * @type {!WorkspaceSvg} - * @private - */ - private workspace_; - /** - * Whether this scrollbar is part of a pair. - * @type {boolean} - * @private - */ - private pair_; - /** - * Whether this is a horizontal scrollbar. - * @type {boolean} - * @private - */ - private horizontal_; - /** - * Margin around the scrollbar (between the scrollbar and the edge of the - * viewport in pixels). - * @type {number} - * @const - * @private - */ - private margin_; - /** - * Previously recorded metrics from the workspace. - * @type {?Metrics} - * @private - */ - private oldHostMetrics_; - /** - * The ratio of handle position offset to workspace content displacement. - * @type {?number} - * @package - */ - ratio: number | null; - /** - * The location of the origin of the workspace that the scrollbar is in, - * measured in CSS pixels relative to the injection div origin. This is - * usually (0, 0). When the scrollbar is in a flyout it may have a - * different origin. - * @type {Coordinate} - * @private - */ - private origin_; - /** - * The position of the mouse along this scrollbar's major axis at the start - * of the most recent drag. Units are CSS pixels, with (0, 0) at the top - * left of the browser window. For a horizontal scrollbar this is the x - * coordinate of the mouse down event; for a vertical scrollbar it's the y - * coordinate of the mouse down event. - * @type {number} - * @private - */ - private startDragMouse_; - /** - * The length of the scrollbars (including the handle and the background), - * in CSS pixels. This is equivalent to scrollbar background length and the - * area within which the scrollbar handle can move. - * @type {number} - * @private - */ - private scrollbarLength_; - /** - * The length of the scrollbar handle in CSS pixels. - * @type {number} - * @private - */ - private handleLength_; - /** - * The offset of the start of the handle from the scrollbar position, in CSS - * pixels. - * @type {number} - * @private - */ - private handlePosition_; - /** - * @type {number} - * @private - */ - private startDragHandle; - /** - * Whether the scrollbar handle is visible. - * @type {boolean} - * @private - */ - private isVisible_; - /** - * Whether the workspace containing this scrollbar is visible. - * @type {boolean} - * @private - */ - private containerVisible_; - /** - * @type {?SVGRectElement} - * @private - */ - private svgBackground_; - /** - * @type {?SVGRectElement} - * @private - */ - private svgHandle_; - /** - * @type {?SVGSVGElement} - * @private - */ - private outerSvg_; - /** - * @type {?SVGGElement} - * @private - */ - private svgGroup_; - /** - * The upper left corner of the scrollbar's SVG group in CSS pixels relative - * to the scrollbar's origin. This is usually relative to the injection div - * origin. - * @type {Coordinate} - * @package - */ - position: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - lengthAttribute_: string; - positionAttribute_: string; - onMouseDownBarWrapper_: any[][]; - onMouseDownHandleWrapper_: any[][]; - /** - * Dispose of this scrollbar. - * Unlink from all DOM elements to prevent memory leaks. - * @suppress {checkTypes} - */ - dispose(): void; - /** - * Constrain the handle's length within the minimum (0) and maximum - * (scrollbar background) values allowed for the scrollbar. - * @param {number} value Value that is potentially out of bounds, in CSS - * pixels. - * @return {number} Constrained value, in CSS pixels. - * @private - */ - private constrainHandleLength_; - /** - * Set the length of the scrollbar's handle and change the SVG attribute - * accordingly. - * @param {number} newLength The new scrollbar handle length in CSS pixels. - * @private - */ - private setHandleLength_; - /** - * Constrain the handle's position within the minimum (0) and maximum values - * allowed for the scrollbar. - * @param {number} value Value that is potentially out of bounds, in CSS - * pixels. - * @return {number} Constrained value, in CSS pixels. - * @private - */ - private constrainHandlePosition_; - /** - * Set the offset of the scrollbar's handle from the scrollbar's position, and - * change the SVG attribute accordingly. - * @param {number} newPosition The new scrollbar handle offset in CSS pixels. - */ - setHandlePosition(newPosition: number): void; - /** - * Set the size of the scrollbar's background and change the SVG attribute - * accordingly. - * @param {number} newSize The new scrollbar background length in CSS pixels. - * @private - */ - private setScrollbarLength_; - /** - * Set the position of the scrollbar's SVG group in CSS pixels relative to the - * scrollbar's origin. This sets the scrollbar's location within the - * workspace. - * @param {number} x The new x coordinate. - * @param {number} y The new y coordinate. - * @package - */ - setPosition(x: number, y: number): void; - /** - * Recalculate the scrollbar's location and its length. - * @param {Metrics=} opt_metrics A data structure of from the - * describing all the required dimensions. If not provided, it will be - * fetched from the host object. - */ - resize(opt_metrics?: Metrics | undefined): void; - /** - * Returns whether the a resizeView is necessary by comparing the passed - * hostMetrics with cached old host metrics. - * @param {!Metrics} hostMetrics A data structure describing all - * the required dimensions, possibly fetched from the host object. - * @return {boolean} Whether a resizeView is necessary. - * @private - */ - private requiresViewResize_; - /** - * Recalculate a horizontal scrollbar's location and length. - * @param {!Metrics} hostMetrics A data structure describing all - * the required dimensions, possibly fetched from the host object. - * @private - */ - private resizeHorizontal_; - /** - * Recalculate a horizontal scrollbar's location on the screen and path - * length. This should be called when the layout or size of the window has - * changed. - * @param {!Metrics} hostMetrics A data structure describing all - * the required dimensions, possibly fetched from the host object. - */ - resizeViewHorizontal(hostMetrics: Metrics): void; - /** - * Recalculate a horizontal scrollbar's location within its path and length. - * This should be called when the contents of the workspace have changed. - * @param {!Metrics} hostMetrics A data structure describing all - * the required dimensions, possibly fetched from the host object. - */ - resizeContentHorizontal(hostMetrics: Metrics): void; - /** - * Recalculate a vertical scrollbar's location and length. - * @param {!Metrics} hostMetrics A data structure describing all - * the required dimensions, possibly fetched from the host object. - * @private - */ - private resizeVertical_; - /** - * Recalculate a vertical scrollbar's location on the screen and path length. - * This should be called when the layout or size of the window has changed. - * @param {!Metrics} hostMetrics A data structure describing all - * the required dimensions, possibly fetched from the host object. - */ - resizeViewVertical(hostMetrics: Metrics): void; - /** - * Recalculate a vertical scrollbar's location within its path and length. - * This should be called when the contents of the workspace have changed. - * @param {!Metrics} hostMetrics A data structure describing all - * the required dimensions, possibly fetched from the host object. - */ - resizeContentVertical(hostMetrics: Metrics): void; - /** - * Create all the DOM elements required for a scrollbar. - * The resulting widget is not sized. - * @param {string=} opt_class A class to be applied to this scrollbar. - * @private - */ - private createDom_; - /** - * Is the scrollbar visible. Non-paired scrollbars disappear when they aren't - * needed. - * @return {boolean} True if visible. - */ - isVisible(): boolean; - /** - * Set whether the scrollbar's container is visible and update - * display accordingly if visibility has changed. - * @param {boolean} visible Whether the container is visible - */ - setContainerVisible(visible: boolean): void; - /** - * Set whether the scrollbar is visible. - * Only applies to non-paired scrollbars. - * @param {boolean} visible True if visible. - */ - setVisible(visible: boolean): void; - /** - * Update visibility of scrollbar based on whether it thinks it should - * be visible and whether its containing workspace is visible. - * We cannot rely on the containing workspace being hidden to hide us - * because it is not necessarily our parent in the DOM. - */ - updateDisplay_(): void; - /** - * Scroll by one pageful. - * Called when scrollbar background is clicked. - * @param {!Event} e Mouse down event. - * @private - */ - private onMouseDownBar_; - /** - * Start a dragging operation. - * Called when scrollbar handle is clicked. - * @param {!Event} e Mouse down event. - * @private - */ - private onMouseDownHandle_; - /** - * Drag the scrollbar's handle. - * @param {!Event} e Mouse up event. - * @private - */ - private onMouseMoveHandle_; - /** - * Release the scrollbar handle and reset state accordingly. - * @private - */ - private onMouseUpHandle_; - /** - * Hide chaff and stop binding to mouseup and mousemove events. Call this to - * wrap up loose ends associated with the scrollbar. - * @private - */ - private cleanUp_; - /** - * Helper to calculate the ratio of handle position to scrollbar view size. - * @return {number} Ratio. - * @package - */ - getRatio_(): number; - /** - * Updates workspace metrics based on new scroll ratio. Called when scrollbar - * is moved. - * @private - */ - private updateMetrics_; - /** - * Set the scrollbar handle's position. - * @param {number} value The content displacement, relative to the view in - * pixels. - * @param {boolean=} updateMetrics Whether to update metrics on this set call. - * Defaults to true. - */ - set(value: number, updateMetrics?: boolean | undefined): void; - /** - * Record the origin of the workspace that the scrollbar is in, in pixels - * relative to the injection div origin. This is for times when the scrollbar - * is used in an object whose origin isn't the same as the main workspace - * (e.g. in a flyout.) - * @param {number} x The x coordinate of the scrollbar's origin, in CSS - * pixels. - * @param {number} y The y coordinate of the scrollbar's origin, in CSS - * pixels. - */ - setOrigin(x: number, y: number): void; - } - export namespace Scrollbar { - const scrollbarThickness: number; - const DEFAULT_SCROLLBAR_MARGIN: number; - } - import { Metrics } from "core/utils/metrics"; - import { WorkspaceSvg } from "core/workspace_svg"; -} -declare module "core/bubble" { - /** - * Class for UI bubble. - * @implements {IBubble} - * @alias Blockly.Bubble - */ - export const Bubble: { - new (workspace: WorkspaceSvg, content: Element, shape: Element, anchorXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }, bubbleWidth: number | null, bubbleHeight: number | null): { - workspace_: WorkspaceSvg; - content_: Element; - shape_: Element; - /** - * Flag to stop incremental rendering during construction. - * @type {boolean} - * @private - */ - rendered_: boolean; - /** - * The SVG group containing all parts of the bubble. - * @type {SVGGElement} - * @private - */ - bubbleGroup_: SVGGElement; - /** - * The SVG path for the arrow from the bubble to the icon on the block. - * @type {SVGPathElement} - * @private - */ - bubbleArrow_: SVGPathElement; - /** - * The SVG rect for the main body of the bubble. - * @type {SVGRectElement} - * @private - */ - bubbleBack_: SVGRectElement; - /** - * The SVG group for the resize hash marks on some bubbles. - * @type {SVGGElement} - * @private - */ - resizeGroup_: SVGGElement; - /** - * Absolute coordinate of anchor point, in workspace coordinates. - * @type {Coordinate} - * @private - */ - anchorXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Relative X coordinate of bubble with respect to the anchor's centre, - * in workspace units. - * In RTL mode the initial value is negated. - * @type {number} - * @private - */ - relativeLeft_: number; - /** - * Relative Y coordinate of bubble with respect to the anchor's centre, in - * workspace units. - * @type {number} - * @private - */ - relativeTop_: number; - /** - * Width of bubble, in workspace units. - * @type {number} - * @private - */ - width_: number; - /** - * Height of bubble, in workspace units. - * @type {number} - * @private - */ - height_: number; - /** - * Automatically position and reposition the bubble. - * @type {boolean} - * @private - */ - autoLayout_: boolean; - /** - * Method to call on resize of bubble. - * @type {?function()} - * @private - */ - resizeCallback_: (() => any) | null; - /** - * Method to call on move of bubble. - * @type {?function()} - * @private - */ - moveCallback_: (() => any) | null; - /** - * Mouse down on bubbleBack_ event data. - * @type {?browserEvents.Data} - * @private - */ - onMouseDownBubbleWrapper_: any[][] | null; - /** - * Mouse down on resizeGroup_ event data. - * @type {?browserEvents.Data} - * @private - */ - onMouseDownResizeWrapper_: any[][] | null; - /** - * Describes whether this bubble has been disposed of (nodes and event - * listeners removed from the page) or not. - * @type {boolean} - * @package - */ - disposed: boolean; - arrow_radians_: number; - /** - * Create the bubble's DOM. - * @param {!Element} content SVG content for the bubble. - * @param {boolean} hasResize Add diagonal resize gripper if true. - * @return {!SVGElement} The bubble's SVG group. - * @private - */ - createDom_(content: Element, hasResize: boolean): SVGElement; - /** - * Return the root node of the bubble's SVG group. - * @return {!SVGElement} The root SVG node of the bubble's group. - */ - getSvgRoot(): SVGElement; - /** - * Expose the block's ID on the bubble's top-level SVG group. - * @param {string} id ID of block. - */ - setSvgId(id: string): void; - /** - * Handle a mouse-down on bubble's border. - * @param {!Event} e Mouse down event. - * @private - */ - bubbleMouseDown_(e: Event): void; - /** - * Show the context menu for this bubble. - * @param {!Event} _e Mouse event. - * @package - */ - showContextMenu(_e: Event): void; - /** - * Get whether this bubble is deletable or not. - * @return {boolean} True if deletable. - * @package - */ - isDeletable(): boolean; - /** - * Update the style of this bubble when it is dragged over a delete area. - * @param {boolean} _enable True if the bubble is about to be deleted, false - * otherwise. - */ - setDeleteStyle(_enable: boolean): void; - /** - * Handle a mouse-down on bubble's resize corner. - * @param {!Event} e Mouse down event. - * @private - */ - resizeMouseDown_(e: Event): void; - /** - * Resize this bubble to follow the mouse. - * @param {!Event} e Mouse move event. - * @private - */ - resizeMouseMove_(e: Event): void; - /** - * Register a function as a callback event for when the bubble is resized. - * @param {!Function} callback The function to call on resize. - */ - registerResizeEvent(callback: Function): void; - /** - * Register a function as a callback event for when the bubble is moved. - * @param {!Function} callback The function to call on move. - */ - registerMoveEvent(callback: Function): void; - /** - * Move this bubble to the top of the stack. - * @return {boolean} Whether or not the bubble has been moved. - * @package - */ - promote(): boolean; - /** - * Notification that the anchor has moved. - * Update the arrow and bubble accordingly. - * @param {!Coordinate} xy Absolute location. - */ - setAnchorLocation(xy: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Position the bubble so that it does not fall off-screen. - * @private - */ - layoutBubble_(): void; - /** - * Calculate the what percentage of the bubble overlaps with the visible - * workspace (what percentage of the bubble is visible). - * @param {!{x: number, y: number}} relativeMin The position of the top-left - * corner of the bubble relative to the anchor point. - * @param {!MetricsManager.ContainerRegion} viewMetrics The view metrics - * of the workspace the bubble will appear in. - * @return {number} The percentage of the bubble that is visible. - * @private - */ - getOverlap_(relativeMin: { - x: number; - y: number; - }, viewMetrics: MetricsManager.ContainerRegion): number; - /** - * Calculate what the optimal horizontal position of the top-left corner of - * the bubble is (relative to the anchor point) so that the most area of the - * bubble is shown. - * @param {!MetricsManager.ContainerRegion} viewMetrics The view metrics - * of the workspace the bubble will appear in. - * @return {number} The optimal horizontal position of the top-left corner - * of the bubble. - * @private - */ - getOptimalRelativeLeft_(viewMetrics: MetricsManager.ContainerRegion): number; - /** - * Calculate what the optimal vertical position of the top-left corner of - * the bubble is (relative to the anchor point) so that the most area of the - * bubble is shown. - * @param {!MetricsManager.ContainerRegion} viewMetrics The view metrics - * of the workspace the bubble will appear in. - * @return {number} The optimal vertical position of the top-left corner - * of the bubble. - * @private - */ - getOptimalRelativeTop_(viewMetrics: MetricsManager.ContainerRegion): number; - /** - * Move the bubble to a location relative to the anchor's centre. - * @private - */ - positionBubble_(): void; - /** - * Move the bubble group to the specified location in workspace coordinates. - * @param {number} x The x position to move to. - * @param {number} y The y position to move to. - * @package - */ - moveTo(x: number, y: number): void; - /** - * Triggers a move callback if one exists at the end of a drag. - * @param {boolean} adding True if adding, false if removing. - * @package - */ - setDragging(adding: boolean): void; - /** - * Get the dimensions of this bubble. - * @return {!Size} The height and width of the bubble. - */ - getBubbleSize(): { - width: number; - height: number; - }; - /** - * Size this bubble. - * @param {number} width Width of the bubble. - * @param {number} height Height of the bubble. - */ - setBubbleSize(width: number, height: number): void; - /** - * Draw the arrow between the bubble and the origin. - * @private - */ - renderArrow_(): void; - /** - * Change the colour of a bubble. - * @param {string} hexColour Hex code of colour. - */ - setColour(hexColour: string): void; - /** - * Dispose of this bubble. - */ - dispose(): void; - /** - * Move this bubble during a drag, taking into account whether or not there is - * a drag surface. - * @param {BlockDragSurfaceSvg} dragSurface The surface that carries - * rendered items during a drag, or null if no drag surface is in use. - * @param {!Coordinate} newLoc The location to translate to, in - * workspace coordinates. - * @package - */ - moveDuringDrag(dragSurface: { - SVG_: SVGElement | null; - dragGroup_: SVGElement | null; - container_: Element; - scale_: number; - surfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - } | null; - childSurfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - createDom(): void; - setBlocksAndShow(blocks: SVGElement): void; - translateAndScaleGroup(x: number, y: number, scale: number): void; - translateSurfaceInternal_(): void; - translateBy(deltaX: number, deltaY: number): void; - translateSurface(x: number, y: number): void; - getSurfaceTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - getGroup(): SVGElement | null; - getSvgRoot(): SVGElement | null; - getCurrentBlock(): Element | null; - getWsTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - clearAndHide(opt_newSurface?: Element | undefined): void; - }, newLoc: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Return the coordinates of the top-left corner of this bubble's body - * relative to the drawing surface's origin (0,0), in workspace units. - * @return {!Coordinate} Object with .x and .y properties. - */ - getRelativeToSurfaceXY(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Set whether auto-layout of this bubble is enabled. The first time a bubble - * is shown it positions itself to not cover any blocks. Once a user has - * dragged it to reposition, it renders where the user put it. - * @param {boolean} enable True if auto-layout should be enabled, false - * otherwise. - * @package - */ - setAutoLayout(enable: boolean): void; - }; - /** - * Stop binding to the global mouseup and mousemove events. - * @private - */ - unbindDragEvents_(): void; - /** - * Handle a mouse-up event while dragging a bubble's border or resize handle. - * @param {!Event} _e Mouse up event. - * @private - */ - bubbleMouseUp_(_e: Event): void; - /** - * Create the text for a non editable bubble. - * @param {string} text The text to display. - * @return {!SVGTextElement} The top-level node of the text. - * @package - */ - textToDom(text: string): SVGTextElement; - /** - * Creates a bubble that can not be edited. - * @param {!SVGTextElement} paragraphElement The text element for the non - * editable bubble. - * @param {!BlockSvg} block The block that the bubble is attached to. - * @param {!Coordinate} iconXY The coordinate of the icon. - * @return {!Bubble} The non editable bubble. - * @package - */ - createNonEditableBubble(paragraphElement: SVGTextElement, block: BlockSvg, iconXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): { - workspace_: WorkspaceSvg; - content_: Element; - shape_: Element; - /** - * Flag to stop incremental rendering during construction. - * @type {boolean} - * @private - */ - rendered_: boolean; - /** - * The SVG group containing all parts of the bubble. - * @type {SVGGElement} - * @private - */ - bubbleGroup_: SVGGElement; - /** - * The SVG path for the arrow from the bubble to the icon on the block. - * @type {SVGPathElement} - * @private - */ - bubbleArrow_: SVGPathElement; - /** - * The SVG rect for the main body of the bubble. - * @type {SVGRectElement} - * @private - */ - bubbleBack_: SVGRectElement; - /** - * The SVG group for the resize hash marks on some bubbles. - * @type {SVGGElement} - * @private - */ - resizeGroup_: SVGGElement; - /** - * Absolute coordinate of anchor point, in workspace coordinates. - * @type {Coordinate} - * @private - */ - anchorXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Relative X coordinate of bubble with respect to the anchor's centre, - * in workspace units. - * In RTL mode the initial value is negated. - * @type {number} - * @private - */ - relativeLeft_: number; - /** - * Relative Y coordinate of bubble with respect to the anchor's centre, in - * workspace units. - * @type {number} - * @private - */ - relativeTop_: number; - /** - * Width of bubble, in workspace units. - * @type {number} - * @private - */ - width_: number; - /** - * Height of bubble, in workspace units. - * @type {number} - * @private - */ - height_: number; - /** - * Automatically position and reposition the bubble. - * @type {boolean} - * @private - */ - autoLayout_: boolean; - /** - * Method to call on resize of bubble. - * @type {?function()} - * @private - */ - resizeCallback_: (() => any) | null; - /** - * Method to call on move of bubble. - * @type {?function()} - * @private - */ - moveCallback_: (() => any) | null; - /** - * Mouse down on bubbleBack_ event data. - * @type {?browserEvents.Data} - * @private - */ - onMouseDownBubbleWrapper_: any[][] | null; - /** - * Mouse down on resizeGroup_ event data. - * @type {?browserEvents.Data} - * @private - */ - onMouseDownResizeWrapper_: any[][] | null; - /** - * Describes whether this bubble has been disposed of (nodes and event - * listeners removed from the page) or not. - * @type {boolean} - * @package - */ - disposed: boolean; - arrow_radians_: number; - /** - * Create the bubble's DOM. - * @param {!Element} content SVG content for the bubble. - * @param {boolean} hasResize Add diagonal resize gripper if true. - * @return {!SVGElement} The bubble's SVG group. - * @private - */ - createDom_(content: Element, hasResize: boolean): SVGElement; - /** - * Return the root node of the bubble's SVG group. - * @return {!SVGElement} The root SVG node of the bubble's group. - */ - getSvgRoot(): SVGElement; - /** - * Expose the block's ID on the bubble's top-level SVG group. - * @param {string} id ID of block. - */ - setSvgId(id: string): void; - /** - * Handle a mouse-down on bubble's border. - * @param {!Event} e Mouse down event. - * @private - */ - bubbleMouseDown_(e: Event): void; - /** - * Show the context menu for this bubble. - * @param {!Event} _e Mouse event. - * @package - */ - showContextMenu(_e: Event): void; - /** - * Get whether this bubble is deletable or not. - * @return {boolean} True if deletable. - * @package - */ - isDeletable(): boolean; - /** - * Update the style of this bubble when it is dragged over a delete area. - * @param {boolean} _enable True if the bubble is about to be deleted, false - * otherwise. - */ - setDeleteStyle(_enable: boolean): void; - /** - * Handle a mouse-down on bubble's resize corner. - * @param {!Event} e Mouse down event. - * @private - */ - resizeMouseDown_(e: Event): void; - /** - * Resize this bubble to follow the mouse. - * @param {!Event} e Mouse move event. - * @private - */ - resizeMouseMove_(e: Event): void; - /** - * Register a function as a callback event for when the bubble is resized. - * @param {!Function} callback The function to call on resize. - */ - registerResizeEvent(callback: Function): void; - /** - * Register a function as a callback event for when the bubble is moved. - * @param {!Function} callback The function to call on move. - */ - registerMoveEvent(callback: Function): void; - /** - * Move this bubble to the top of the stack. - * @return {boolean} Whether or not the bubble has been moved. - * @package - */ - promote(): boolean; - /** - * Notification that the anchor has moved. - * Update the arrow and bubble accordingly. - * @param {!Coordinate} xy Absolute location. - */ - setAnchorLocation(xy: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Position the bubble so that it does not fall off-screen. - * @private - */ - layoutBubble_(): void; - /** - * Calculate the what percentage of the bubble overlaps with the visible - * workspace (what percentage of the bubble is visible). - * @param {!{x: number, y: number}} relativeMin The position of the top-left - * corner of the bubble relative to the anchor point. - * @param {!MetricsManager.ContainerRegion} viewMetrics The view metrics - * of the workspace the bubble will appear in. - * @return {number} The percentage of the bubble that is visible. - * @private - */ - getOverlap_(relativeMin: { - x: number; - y: number; - }, viewMetrics: MetricsManager.ContainerRegion): number; - /** - * Calculate what the optimal horizontal position of the top-left corner of - * the bubble is (relative to the anchor point) so that the most area of the - * bubble is shown. - * @param {!MetricsManager.ContainerRegion} viewMetrics The view metrics - * of the workspace the bubble will appear in. - * @return {number} The optimal horizontal position of the top-left corner - * of the bubble. - * @private - */ - getOptimalRelativeLeft_(viewMetrics: MetricsManager.ContainerRegion): number; - /** - * Calculate what the optimal vertical position of the top-left corner of - * the bubble is (relative to the anchor point) so that the most area of the - * bubble is shown. - * @param {!MetricsManager.ContainerRegion} viewMetrics The view metrics - * of the workspace the bubble will appear in. - * @return {number} The optimal vertical position of the top-left corner - * of the bubble. - * @private - */ - getOptimalRelativeTop_(viewMetrics: MetricsManager.ContainerRegion): number; - /** - * Move the bubble to a location relative to the anchor's centre. - * @private - */ - positionBubble_(): void; - /** - * Move the bubble group to the specified location in workspace coordinates. - * @param {number} x The x position to move to. - * @param {number} y The y position to move to. - * @package - */ - moveTo(x: number, y: number): void; - /** - * Triggers a move callback if one exists at the end of a drag. - * @param {boolean} adding True if adding, false if removing. - * @package - */ - setDragging(adding: boolean): void; - /** - * Get the dimensions of this bubble. - * @return {!Size} The height and width of the bubble. - */ - getBubbleSize(): { - width: number; - height: number; - }; - /** - * Size this bubble. - * @param {number} width Width of the bubble. - * @param {number} height Height of the bubble. - */ - setBubbleSize(width: number, height: number): void; - /** - * Draw the arrow between the bubble and the origin. - * @private - */ - renderArrow_(): void; - /** - * Change the colour of a bubble. - * @param {string} hexColour Hex code of colour. - */ - setColour(hexColour: string): void; - /** - * Dispose of this bubble. - */ - dispose(): void; - /** - * Move this bubble during a drag, taking into account whether or not there is - * a drag surface. - * @param {BlockDragSurfaceSvg} dragSurface The surface that carries - * rendered items during a drag, or null if no drag surface is in use. - * @param {!Coordinate} newLoc The location to translate to, in - * workspace coordinates. - * @package - */ - moveDuringDrag(dragSurface: { - SVG_: SVGElement | null; - dragGroup_: SVGElement | null; - container_: Element; - scale_: number; - surfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - } | null; - childSurfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - createDom(): void; - setBlocksAndShow(blocks: SVGElement): void; - translateAndScaleGroup(x: number, y: number, scale: number): void; - translateSurfaceInternal_(): void; - translateBy(deltaX: number, deltaY: number): void; - translateSurface(x: number, y: number): void; - getSurfaceTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - getGroup(): SVGElement | null; - getSvgRoot(): SVGElement | null; - getCurrentBlock(): Element | null; - getWsTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - clearAndHide(opt_newSurface?: Element | undefined): void; - }, newLoc: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Return the coordinates of the top-left corner of this bubble's body - * relative to the drawing surface's origin (0,0), in workspace units. - * @return {!Coordinate} Object with .x and .y properties. - */ - getRelativeToSurfaceXY(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Set whether auto-layout of this bubble is enabled. The first time a bubble - * is shown it positions itself to not cover any blocks. Once a user has - * dragged it to reposition, it renders where the user put it. - * @param {boolean} enable True if auto-layout should be enabled, false - * otherwise. - * @package - */ - setAutoLayout(enable: boolean): void; - }; - /** - * Width of the border around the bubble. - */ - BORDER_WIDTH: number; - /** - * Determines the thickness of the base of the arrow in relation to the size - * of the bubble. Higher numbers result in thinner arrows. - */ - ARROW_THICKNESS: number; - /** - * The number of degrees that the arrow bends counter-clockwise. - */ - ARROW_ANGLE: number; - /** - * The sharpness of the arrow's bend. Higher numbers result in smoother arrows. - */ - ARROW_BEND: number; - /** - * Distance between arrow point and anchor point. - */ - ANCHOR_RADIUS: number; - /** - * Mouse up event data. - * @type {?browserEvents.Data} - * @private - */ - onMouseUpWrapper_: any[][] | null; - /** - * Mouse move event data. - * @type {?browserEvents.Data} - * @private - */ - onMouseMoveWrapper_: any[][] | null; - }; - import { WorkspaceSvg } from "core/workspace_svg"; - import { MetricsManager } from "core/metrics_manager"; - import { BlockSvg } from "core/block_svg"; -} -declare module "core/constants" { - /** - * The language-neutral ID given to the collapsed input. - * @const {string} - * @alias Blockly.constants.COLLAPSED_INPUT_NAME - */ - export const COLLAPSED_INPUT_NAME: "_TEMP_COLLAPSED_INPUT"; - /** - * The language-neutral ID given to the collapsed field. - * @const {string} - * @alias Blockly.constants.COLLAPSED_FIELD_NAME - */ - export const COLLAPSED_FIELD_NAME: "_TEMP_COLLAPSED_FIELD"; -} -declare module "core/bubble_dragger" { - /** - * Class for a bubble dragger. It moves things on the bubble canvas around the - * workspace when they are being dragged by a mouse or touch. These can be - * block comments, mutators, warnings, or workspace comments. - * @alias Blockly.BubbleDragger - */ - export const BubbleDragger: { - new (bubble: () => void, workspace: WorkspaceSvg): { - /** - * The item on the bubble canvas that is being dragged. - * @type {!IBubble} - * @private - */ - draggingBubble_: () => void; - /** - * The workspace on which the bubble is being dragged. - * @type {!WorkspaceSvg} - * @private - */ - workspace_: WorkspaceSvg; - /** - * Which drag target the mouse pointer is over, if any. - * @type {?IDragTarget} - * @private - */ - dragTarget_: (() => void) | null; - /** - * Whether the bubble would be deleted if dropped immediately. - * @type {boolean} - * @private - */ - wouldDeleteBubble_: boolean; - /** - * The location of the top left corner of the dragging bubble's body at the - * beginning of the drag, in workspace coordinates. - * @type {!Coordinate} - * @private - */ - startXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * The drag surface to move bubbles to during a drag, or null if none should - * be used. Block dragging and bubble dragging use the same surface. - * @type {BlockDragSurfaceSvg} - * @private - */ - dragSurface_: { - SVG_: SVGElement | null; - dragGroup_: SVGElement | null; - container_: Element; - scale_: number; - surfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - } | null; - childSurfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - createDom(): void; - setBlocksAndShow(blocks: SVGElement): void; - translateAndScaleGroup(x: number, y: number, scale: number): void; - translateSurfaceInternal_(): void; - translateBy(deltaX: number, deltaY: number): void; - translateSurface(x: number, y: number): void; - getSurfaceTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - getGroup(): SVGElement | null; - getSvgRoot(): SVGElement | null; - getCurrentBlock(): Element | null; - getWsTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - clearAndHide(opt_newSurface?: Element | undefined): void; - }; - /** - * Sever all links from this object. - * @package - * @suppress {checkTypes} - */ - dispose(): void; - /** - * Start dragging a bubble. This includes moving it to the drag surface. - * @package - */ - startBubbleDrag(): void; - /** - * Execute a step of bubble dragging, based on the given event. Update the - * display accordingly. - * @param {!Event} e The most recent move event. - * @param {!Coordinate} currentDragDeltaXY How far the pointer has - * moved from the position at the start of the drag, in pixel units. - * @package - */ - dragBubble(e: Event, currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Whether ending the drag would delete the bubble. - * @param {?IDragTarget} dragTarget The drag target that the bubblee is - * currently over. - * @return {boolean} Whether dropping the bubble immediately would delete the - * block. - * @private - */ - shouldDelete_(dragTarget: (() => void) | null): boolean; - /** - * Update the cursor (and possibly the trash can lid) to reflect whether the - * dragging bubble would be deleted if released immediately. - * @private - */ - updateCursorDuringBubbleDrag_(): void; - /** - * Finish a bubble drag and put the bubble back on the workspace. - * @param {!Event} e The mouseup/touchend event. - * @param {!Coordinate} currentDragDeltaXY How far the pointer has - * moved from the position at the start of the drag, in pixel units. - * @package - */ - endBubbleDrag(e: Event, currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Fire a move event at the end of a bubble drag. - * @private - */ - fireMoveEvent_(): void; - /** - * Convert a coordinate object from pixels to workspace units, including a - * correction for mutator workspaces. - * This function does not consider differing origins. It simply scales the - * input's x and y values. - * @param {!Coordinate} pixelCoord A coordinate with x and y - * values in CSS pixel units. - * @return {!Coordinate} The input coordinate divided by the - * workspace scale. - * @private - */ - pixelsToWorkspaceUnits_(pixelCoord: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Move the bubble onto the drag surface at the beginning of a drag. Move the - * drag surface to preserve the apparent location of the bubble. - * @private - */ - moveToDragSurface_(): void; - }; - }; - import { WorkspaceSvg } from "core/workspace_svg"; -} -declare module "core/config" { - /** - * Object holding all the values on Blockly that we expect developers to be - * able to change. - * @type {Config} - */ - export const config: Config; - /** - * All the values that we expect developers to be able to change - * before injecting Blockly. - */ - type Config = { - dragRadius: number; - flyoutDragRadius: number; - snapRadius: number; - currentConnectionPreference: number; - bumpDelay: number; - connectingSnapRadius: number; - }; - /** - * All the values that we expect developers to be able to change - * before injecting Blockly. - * @typedef {{ - * dragRadius: number, - * flyoutDragRadius: number, - * snapRadius: number, - * currentConnectionPreference: number, - * bumpDelay: number, - * connectingSnapRadius: number - * }} - */ - let Config: any; - export {}; -} -declare module "core/interfaces/i_block_dragger" { - /** - * A block dragger interface. - * @interface - * @alias Blockly.IBlockDragger - */ - export function IBlockDragger(): void; -} -declare module "core/workspace_dragger" { - /** - * Class for a workspace dragger. It moves the workspace around when it is - * being dragged by a mouse or touch. - * Note that the workspace itself manages whether or not it has a drag surface - * and how to do translations based on that. This simply passes the right - * commands based on events. - * @alias Blockly.WorkspaceDragger - */ - export class WorkspaceDragger { - /** - * @param {!WorkspaceSvg} workspace The workspace to drag. - */ - constructor(workspace: WorkspaceSvg); - /** - * @type {!WorkspaceSvg} - * @private - */ - private workspace_; - /** - * Whether horizontal scroll is enabled. - * @type {boolean} - * @private - */ - private horizontalScrollEnabled_; - /** - * Whether vertical scroll is enabled. - * @type {boolean} - * @private - */ - private verticalScrollEnabled_; - /** - * The scroll position of the workspace at the beginning of the drag. - * Coordinate system: pixel coordinates. - * @type {!Coordinate} - * @protected - */ - protected startScrollXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Sever all links from this object. - * @package - * @suppress {checkTypes} - */ - dispose(): void; - /** - * Start dragging the workspace. - * @package - */ - startDrag(): void; - /** - * Finish dragging the workspace and put everything back where it belongs. - * @param {!Coordinate} currentDragDeltaXY How far the pointer has - * moved from the position at the start of the drag, in pixel coordinates. - * @package - */ - endDrag(currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Move the workspace based on the most recent mouse movements. - * @param {!Coordinate} currentDragDeltaXY How far the pointer has - * moved from the position at the start of the drag, in pixel coordinates. - * @package - */ - drag(currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - } - import { WorkspaceSvg } from "core/workspace_svg"; -} -declare module "core/events/events_viewport" { - /** - * Class for a viewport change event. - * @extends {UiBase} - * @alias Blockly.Events.ViewportChange - */ - export class ViewportChange extends UiBase { - /** - * @param {number=} opt_top Top-edge of the visible portion of the workspace, - * relative to the workspace origin. Undefined for a blank event. - * @param {number=} opt_left Left-edge of the visible portion of the - * workspace relative to the workspace origin. Undefined for a blank - * event. - * @param {number=} opt_scale The scale of the workspace. Undefined for a - * blank event. - * @param {string=} opt_workspaceId The workspace identifier for this event. - * Undefined for a blank event. - * @param {number=} opt_oldScale The old scale of the workspace. Undefined for - * a blank event. - */ - constructor(opt_top?: number | undefined, opt_left?: number | undefined, opt_scale?: number | undefined, opt_workspaceId?: string | undefined, opt_oldScale?: number | undefined); - /** - * Top-edge of the visible portion of the workspace, relative to the - * workspace origin. - * @type {number|undefined} - */ - viewTop: number | undefined; - /** - * Left-edge of the visible portion of the workspace, relative to the - * workspace origin. - * @type {number|undefined} - */ - viewLeft: number | undefined; - /** - * The scale of the workspace. - * @type {number|undefined} - */ - scale: number | undefined; - /** - * The old scale of the workspace. - * @type {number|undefined} - */ - oldScale: number | undefined; - } - import { UiBase } from "core/events/events_ui_base"; -} -declare module "core/bump_objects" { - /** - * Bumps the given object that has passed out of bounds. - * @param {!WorkspaceSvg} workspace The workspace containing the object. - * @param {!MetricsManager.ContainerRegion} scrollMetrics Scroll metrics - * in workspace coordinates. - * @param {!IBoundedElement} object The object to bump. - * @return {boolean} True if block was bumped. - * @alias Blockly.bumpObjects.bumpIntoBounds - */ - function bumpObjectIntoBounds(workspace: WorkspaceSvg, scrollMetrics: MetricsManager.ContainerRegion, object: () => void): boolean; - /** - * Creates a handler for bumping objects when they cross fixed bounds. - * @param {!WorkspaceSvg} workspace The workspace to handle. - * @return {function(Abstract)} The event handler. - * @alias Blockly.bumpObjects.bumpIntoBoundsHandler - */ - export function bumpIntoBoundsHandler(workspace: WorkspaceSvg): (arg0: Abstract) => any; - /** - * Bumps the top objects in the given workspace into bounds. - * @param {!WorkspaceSvg} workspace The workspace. - * @alias Blockly.bumpObjects.bumpTopObjectsIntoBounds - */ - export function bumpTopObjectsIntoBounds(workspace: WorkspaceSvg): void; - import { WorkspaceSvg } from "core/workspace_svg"; - import { MetricsManager } from "core/metrics_manager"; - import { Abstract } from "core/events/events_abstract"; - export { bumpObjectIntoBounds as bumpIntoBounds }; -} -declare module "core/events/events_block_base" { - /** - * Abstract class for a block event. - * @extends {AbstractEvent} - * @alias Blockly.Events.BlockBase - */ - export class BlockBase extends AbstractEvent { - /** - * @param {!Block=} opt_block The block this event corresponds to. - * Undefined for a blank event. - */ - constructor(opt_block?: Block | undefined); - /** - * The block ID for the block this event pertains to - * @type {string} - */ - blockId: string; - } - import { Abstract as AbstractEvent } from "core/events/events_abstract"; - import { Block } from "core/block"; -} -declare module "core/events/events_block_move" { - /** - * Class for a block move event. Created before the move. - * @extends {BlockBase} - * @alias Blockly.Events.BlockMove - */ - export class BlockMove extends BlockBase { - oldParentId: any; - oldInputName: any; - oldCoordinate: any; - newParentId: any; - newInputName: any; - newCoordinate: any; - /** - * Record the block's new location. Called after the move. - */ - recordNew(): void; - /** - * Returns the parentId and input if the block is connected, - * or the XY location if disconnected. - * @return {!Object} Collection of location info. - * @private - */ - private currentLocation_; - } - import { BlockBase } from "core/events/events_block_base"; -} -declare module "core/utils/svg_paths" { - /** - * Create a string representing the given x, y pair. It does not matter whether - * the coordinate is relative or absolute. The result has leading - * and trailing spaces, and separates the x and y coordinates with a comma but - * no space. - * @param {number} x The x coordinate. - * @param {number} y The y coordinate. - * @return {string} A string of the format ' x,y ' - * @alias Blockly.utils.svgPaths.point - */ - export function point(x: number, y: number): string; - /** - * Draw a cubic or quadratic curve. See - * developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#Cubic_B%C3%A9zier_Curve - * 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} 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. - * @alias Blockly.utils.svgPaths.curve - */ - export function curve(command: string, points: Array): string; - /** - * Move the cursor to the given position without drawing a line. - * The coordinates are absolute. - * These coordinates are unitless and hence in the user coordinate system. - * See developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Line_commands - * @param {number} x The absolute x coordinate. - * @param {number} y The absolute y coordinate. - * @return {string} A string of the format ' M x,y ' - * @alias Blockly.utils.svgPaths.moveTo - */ - export function moveTo(x: number, y: number): string; - /** - * Move the cursor to the given position without drawing a line. - * Coordinates are relative. - * These coordinates are unitless and hence in the user coordinate system. - * See developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Line_commands - * @param {number} dx The relative x coordinate. - * @param {number} dy The relative y coordinate. - * @return {string} A string of the format ' m dx,dy ' - * @alias Blockly.utils.svgPaths.moveBy - */ - export function moveBy(dx: number, dy: number): string; - /** - * Draw a line from the current point to the end point, which is the current - * point shifted by dx along the x-axis and dy along the y-axis. - * These coordinates are unitless and hence in the user coordinate system. - * See developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Line_commands - * @param {number} dx The relative x coordinate. - * @param {number} dy The relative y coordinate. - * @return {string} A string of the format ' l dx,dy ' - * @alias Blockly.utils.svgPaths.lineTo - */ - export function lineTo(dx: number, dy: number): string; - /** - * Draw multiple lines connecting all of the given points in order. This is - * equivalent to a series of 'l' commands. - * These coordinates are unitless and hence in the user coordinate system. - * See developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Line_commands - * @param {!Array} points An array containing all of the points to - * draw lines to, in order. The points are represented as strings of the - * format ' dx,dy '. - * @return {string} A string of the format ' l (dx,dy)+ ' - * @alias Blockly.utils.svgPaths.line - */ - export function line(points: Array): string; - /** - * Draw a horizontal or vertical line. - * The first argument specifies the direction and whether the given position is - * relative or absolute. - * These coordinates are unitless and hence in the user coordinate system. - * See developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#LineTo_path_commands - * @param {string} command The command to prepend to the coordinate. This - * should be one of: V, v, H, h. - * @param {number} val The coordinate to pass to the command. It may be - * absolute or relative. - * @return {string} A string of the format ' command val ' - * @alias Blockly.utils.svgPaths.lineOnAxis - */ - export function lineOnAxis(command: string, val: number): string; - /** - * Draw an elliptical arc curve. - * These coordinates are unitless and hence in the user coordinate system. - * See developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#Elliptical_Arc_Curve - * @param {string} command The command string. Either 'a' or 'A'. - * @param {string} flags The flag string. See the MDN documentation for a - * description and examples. - * @param {number} radius The radius of the arc to draw. - * @param {string} point The point to move the cursor to after drawing the arc, - * specified either in absolute or relative coordinates depending on the - * command. - * @return {string} A string of the format 'command radius radius flags point' - * @alias Blockly.utils.svgPaths.arc - */ - export function arc(command: string, flags: string, radius: number, point: string): string; -} -declare module "core/interfaces/i_connection_checker" { - /** - * Class for connection type checking logic. - * @interface - * @alias Blockly.IConnectionChecker - */ - export class IConnectionChecker {} -} -declare module "core/connection_db" { - /** - * Database of connections. - * Connections are stored in order of their vertical component. This way - * connections in an area may be looked up quickly using a binary search. - * @alias Blockly.ConnectionDB - */ - export class ConnectionDB { - /** - * Initialize a set of connection DBs for a workspace. - * @param {!IConnectionChecker} checker The workspace's - * connection checker, used to decide if connections are valid during a - * drag. - * @return {!Array} Array of databases. - */ - static init(checker: () => void): Array; - /** - * @param {!IConnectionChecker} checker The workspace's - * connection type checker, used to decide if connections are valid during - * a drag. - */ - constructor(checker: () => void); - /** - * Array of connections sorted by y position in workspace units. - * @type {!Array} - * @private - */ - private connections_; - /** - * The workspace's connection type checker, used to decide if connections - * are valid during a drag. - * @type {!IConnectionChecker} - * @private - */ - private connectionChecker_; - /** - * Add a connection to the database. Should not already exist in the database. - * @param {!RenderedConnection} connection The connection to be added. - * @param {number} yPos The y position used to decide where to insert the - * connection. - * @package - */ - addConnection(connection: RenderedConnection, yPos: number): void; - /** - * Finds the index of the given connection. - * - * Starts by doing a binary search to find the approximate location, then - * linearly searches nearby for the exact connection. - * @param {!RenderedConnection} conn The connection to find. - * @param {number} yPos The y position used to find the index of the - * connection. - * @return {number} The index of the connection, or -1 if the connection was - * not found. - * @private - */ - private findIndexOfConnection_; - /** - * Finds the correct index for the given y position. - * @param {number} yPos The y position used to decide where to - * insert the connection. - * @return {number} The candidate index. - * @private - */ - private calculateIndexForYPos_; - /** - * Remove a connection from the database. Must already exist in DB. - * @param {!RenderedConnection} connection The connection to be removed. - * @param {number} yPos The y position used to find the index of the - * connection. - * @throws {Error} If the connection cannot be found in the database. - */ - removeConnection(connection: RenderedConnection, yPos: number): void; - /** - * Find all nearby connections to the given connection. - * Type checking does not apply, since this function is used for bumping. - * @param {!RenderedConnection} connection The connection whose - * neighbours should be returned. - * @param {number} maxRadius The maximum radius to another connection. - * @return {!Array} List of connections. - */ - getNeighbours(connection: RenderedConnection, maxRadius: number): Array; - /** - * Is the candidate connection close to the reference connection. - * Extremely fast; only looks at Y distance. - * @param {number} index Index in database of candidate connection. - * @param {number} baseY Reference connection's Y value. - * @param {number} maxRadius The maximum radius to another connection. - * @return {boolean} True if connection is in range. - * @private - */ - private isInYRange_; - /** - * Find the closest compatible connection to this connection. - * @param {!RenderedConnection} conn The connection searching for a compatible - * mate. - * @param {number} maxRadius The maximum radius to another connection. - * @param {!Coordinate} dxy Offset between this connection's - * location in the database and the current location (as a result of - * dragging). - * @return {!{connection: RenderedConnection, radius: number}} - * Contains two properties: 'connection' which is either another - * connection or null, and 'radius' which is the distance. - */ - searchForClosest(conn: RenderedConnection, maxRadius: number, dxy: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): { - connection: RenderedConnection; - radius: number; - }; - } - import { RenderedConnection } from "core/rendered_connection"; -} -declare module "core/rendered_connection" { - /** - * Class for a connection between blocks that may be rendered on screen. - * @extends {Connection} - * @alias Blockly.RenderedConnection - */ - export class RenderedConnection extends Connection { - /** - * @param {!BlockSvg} source The block establishing this connection. - * @param {number} type The type of the connection. - */ - constructor(source: BlockSvg, type: number); - /** - * Connection database for connections of this type on the current - * workspace. - * @const {!ConnectionDB} - * @private - */ - private db_; - /** - * Connection database for connections compatible with this type on the - * current workspace. - * @const {!ConnectionDB} - * @private - */ - private dbOpposite_; - /** - * Workspace units, (0, 0) is top left of block. - * @type {!Coordinate} - * @private - */ - private offsetInBlock_; - /** - * Describes the state of this connection's tracked-ness. - * @type {RenderedConnection.TrackedState} - * @private - */ - private trackedState_; - /** - * Returns the distance between this connection and another connection in - * workspace units. - * @param {!Connection} otherConnection The other connection to measure - * the distance to. - * @return {number} The distance between connections, in workspace units. - */ - distanceFrom(otherConnection: Connection): number; - /** - * Move the block(s) belonging to the connection to a point where they don't - * visually interfere with the specified connection. - * @param {!RenderedConnection} staticConnection The connection to move away - * from. - * @package - */ - bumpAwayFrom(staticConnection: RenderedConnection): void; - /** - * Change the connection's coordinates. - * @param {number} x New absolute x coordinate, in workspace coordinates. - * @param {number} y New absolute y coordinate, in workspace coordinates. - */ - moveTo(x: number, y: number): void; - /** - * Change the connection's coordinates. - * @param {number} dx Change to x coordinate, in workspace units. - * @param {number} dy Change to y coordinate, in workspace units. - */ - moveBy(dx: number, dy: number): void; - /** - * Move this connection to the location given by its offset within the block - * and the location of the block's top left corner. - * @param {!Coordinate} blockTL The location of the top left - * corner of the block, in workspace coordinates. - */ - moveToOffset(blockTL: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Set the offset of this connection relative to the top left of its block. - * @param {number} x The new relative x, in workspace units. - * @param {number} y The new relative y, in workspace units. - */ - setOffsetInBlock(x: number, y: number): void; - /** - * Get the offset of this connection relative to the top left of its block. - * @return {!Coordinate} The offset of the connection. - * @package - */ - getOffsetInBlock(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Move the blocks on either side of this connection right next to each other. - * @package - */ - tighten(): void; - /** - * Find the closest compatible connection to this connection. - * All parameters are in workspace units. - * @param {number} maxLimit The maximum radius to another connection. - * @param {!Coordinate} dxy Offset between this connection's location - * in the database and the current location (as a result of dragging). - * @return {!{connection: ?Connection, radius: number}} Contains two - * properties: 'connection' which is either another connection or null, - * and 'radius' which is the distance. - */ - closest(maxLimit: number, dxy: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): { - connection: Connection | null; - radius: number; - }; - /** - * Add highlighting around this connection. - */ - highlight(): void; - /** - * Remove the highlighting around this connection. - */ - unhighlight(): void; - /** - * Set whether this connections is tracked in the database or not. - * @param {boolean} doTracking If true, start tracking. If false, stop - * tracking. - * @package - */ - setTracking(doTracking: boolean): void; - /** - * Stop tracking this connection, as well as all down-stream connections on - * any block attached to this connection. This happens when a block is - * collapsed. - * - * Also closes down-stream icons/bubbles. - * @package - */ - stopTrackingAll(): void; - /** - * Start tracking this connection, as well as all down-stream connections on - * any block attached to this connection. This happens when a block is - * expanded. - * @return {!Array} List of blocks to render. - */ - startTrackingAll(): Array; - } - export namespace RenderedConnection { - namespace TrackedState { - const WILL_TRACK: number; - const UNTRACKED: number; - const TRACKED: number; - } - /** - * Enum for different kinds of tracked states. - * - * WILL_TRACK means that this connection will add itself to - * the db on the next moveTo call it receives. - * - * UNTRACKED means that this connection will not add - * itself to the database until setTracking(true) is explicitly called. - * - * TRACKED means that this connection is currently being tracked. - */ - type TrackedState = number; - } - import { Connection } from "core/connection"; - import { Block } from "core/block"; - import { BlockSvg } from "core/block_svg"; -} -declare module "core/insertion_marker_manager" { - /** - * Class that controls updates to connections during drags. It is primarily - * responsible for finding the closest eligible connection and highlighting or - * unhighlighting it as needed during a drag. - * @alias Blockly.InsertionMarkerManager - */ - export class InsertionMarkerManager { - /** - * @param {!BlockSvg} block The top block in the stack being dragged. - */ - constructor(block: BlockSvg); - /** - * The top block in the stack being dragged. - * Does not change during a drag. - * @type {!BlockSvg} - * @private - */ - private topBlock_; - /** - * The workspace on which these connections are being dragged. - * Does not change during a drag. - * @type {!WorkspaceSvg} - * @private - */ - private workspace_; - /** - * The last connection on the stack, if it's not the last connection on the - * first block. - * Set in initAvailableConnections, if at all. - * @type {RenderedConnection} - * @private - */ - private lastOnStack_; - /** - * The insertion marker corresponding to the last block in the stack, if - * that's not the same as the first block in the stack. - * Set in initAvailableConnections, if at all - * @type {BlockSvg} - * @private - */ - private lastMarker_; - /** - * The insertion marker that shows up between blocks to show where a block - * would go if dropped immediately. - * @type {BlockSvg} - * @private - */ - private firstMarker_; - /** - * The connection that this block would connect to if released immediately. - * Updated on every mouse move. - * This is not on any of the blocks that are being dragged. - * @type {RenderedConnection} - * @private - */ - private closestConnection_; - /** - * The connection that would connect to this.closestConnection_ if this - * block were released immediately. Updated on every mouse move. This is on - * the top block that is being dragged or the last block in the dragging - * stack. - * @type {RenderedConnection} - * @private - */ - private localConnection_; - /** - * Whether the block would be deleted if it were dropped immediately. - * Updated on every mouse move. - * @type {boolean} - * @private - */ - private wouldDeleteBlock_; - /** - * Connection on the insertion marker block that corresponds to - * this.localConnection_ on the currently dragged block. - * @type {RenderedConnection} - * @private - */ - private markerConnection_; - /** - * The block that currently has an input being highlighted, or null. - * @type {BlockSvg} - * @private - */ - private highlightedBlock_; - /** - * The block being faded to indicate replacement, or null. - * @type {BlockSvg} - * @private - */ - private fadedBlock_; - /** - * The connections on the dragging blocks that are available to connect to - * other blocks. This includes all open connections on the top block, as - * well as the last connection on the block stack. Does not change during a - * drag. - * @type {!Array} - * @private - */ - private availableConnections_; - /** - * Sever all links from this object. - * @package - */ - dispose(): void; - /** - * Update the available connections for the top block. These connections can - * change if a block is unplugged and the stack is healed. - * @package - */ - updateAvailableConnections(): void; - /** - * Return whether the block would be deleted if dropped immediately, based on - * information from the most recent move event. - * @return {boolean} True if the block would be deleted if dropped - * immediately. - * @package - */ - wouldDeleteBlock(): boolean; - /** - * Return whether the block would be connected if dropped immediately, based - * on information from the most recent move event. - * @return {boolean} True if the block would be connected if dropped - * immediately. - * @package - */ - wouldConnectBlock(): boolean; - /** - * Connect to the closest connection and render the results. - * This should be called at the end of a drag. - * @package - */ - applyConnections(): void; - /** - * Update connections based on the most recent move location. - * @param {!Coordinate} dxy Position relative to drag start, - * in workspace units. - * @param {?IDragTarget} dragTarget The drag target that the block is - * currently over. - * @package - */ - update(dxy: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }, dragTarget: (() => void) | null): void; - /** - * Create an insertion marker that represents the given block. - * @param {!BlockSvg} sourceBlock The block that the insertion marker - * will represent. - * @return {!BlockSvg} The insertion marker that represents the given - * block. - * @private - */ - private createMarkerBlock_; - /** - * Populate the list of available connections on this block stack. This - * should only be called once, at the beginning of a drag. If the stack has - * more than one block, this function will populate lastOnStack_ and create - * the corresponding insertion marker. - * @return {!Array} A list of available - * connections. - * @private - */ - private initAvailableConnections_; - /** - * Whether the previews (insertion marker and replacement marker) should be - * updated based on the closest candidate and the current drag distance. - * @param {!Object} candidate An object containing a local connection, a - * closest connection, and a radius. Returned by getCandidate_. - * @param {!Coordinate} dxy Position relative to drag start, - * in workspace units. - * @return {boolean} Whether the preview should be updated. - * @private - */ - private shouldUpdatePreviews_; - /** - * Find the nearest valid connection, which may be the same as the current - * closest connection. - * @param {!Coordinate} dxy Position relative to drag start, - * in workspace units. - * @return {!Object} An object containing a local connection, a closest - * connection, and a radius. - * @private - */ - private getCandidate_; - /** - * Decide the radius at which to start searching for the closest connection. - * @return {number} The radius at which to start the search for the closest - * connection. - * @private - */ - private getStartRadius_; - /** - * Whether ending the drag would delete the block. - * @param {!Object} candidate An object containing a local connection, a - * closest - * connection, and a radius. - * @param {?IDragTarget} dragTarget The drag target that the block is - * currently over. - * @return {boolean} Whether dropping the block immediately would delete the - * block. - * @private - */ - private shouldDelete_; - /** - * Show an insertion marker or replacement highlighting during a drag, if - * needed. - * At the beginning of this function, this.localConnection_ and - * this.closestConnection_ should both be null. - * @param {!Object} candidate An object containing a local connection, a - * closest connection, and a radius. - * @private - */ - private maybeShowPreview_; - /** - * A preview should be shown. This function figures out if it should be a - * block highlight or an insertion marker, and shows the appropriate one. - * @private - */ - private showPreview_; - /** - * Show an insertion marker or replacement highlighting during a drag, if - * needed. - * At the end of this function, this.localConnection_ and - * this.closestConnection_ should both be null. - * @param {!Object} candidate An object containing a local connection, a - * closest connection, and a radius. - * @private - */ - private maybeHidePreview_; - /** - * A preview should be hidden. This function figures out if it is a block - * highlight or an insertion marker, and hides the appropriate one. - * @private - */ - private hidePreview_; - /** - * Shows an insertion marker connected to the appropriate blocks (based on - * manager state). - * @private - */ - private showInsertionMarker_; - /** - * Disconnects and hides the current insertion marker. Should return the - * blocks to their original state. - * @private - */ - private hideInsertionMarker_; - /** - * Shows an outline around the input the closest connection belongs to. - * @private - */ - private showInsertionInputOutline_; - /** - * Hides any visible input outlines. - * @private - */ - private hideInsertionInputOutline_; - /** - * Shows a replacement fade affect on the closest connection's target block - * (the block that is currently connected to it). - * @private - */ - private showReplacementFade_; - /** - * Hides/Removes any visible fade affects. - * @private - */ - private hideReplacementFade_; - /** - * Get a list of the insertion markers that currently exist. Drags have 0, 1, - * or 2 insertion markers. - * @return {!Array} A possibly empty list of insertion - * marker blocks. - * @package - */ - getInsertionMarkers(): Array; - } - export namespace InsertionMarkerManager { - namespace PREVIEW_TYPE { - const INSERTION_MARKER: number; - const INPUT_OUTLINE: number; - const REPLACEMENT_FADE: number; - } - /** - * An enum describing different kinds of previews the InsertionMarkerManager - * could display. - */ - type PREVIEW_TYPE = number; - } - import { BlockSvg } from "core/block_svg"; -} -declare module "core/events/events_block_drag" { - /** - * Class for a block drag event. - * @extends {UiBase} - * @alias Blockly.Events.BlockDrag - */ - export class BlockDrag extends UiBase { - /** - * @param {!Block=} opt_block The top block in the stack that is being - * dragged. Undefined for a blank event. - * @param {boolean=} opt_isStart Whether this is the start of a block drag. - * Undefined for a blank event. - * @param {!Array=} opt_blocks The blocks affected by this - * drag. Undefined for a blank event. - */ - constructor(opt_block?: Block | undefined, opt_isStart?: boolean | undefined, opt_blocks?: Array | undefined); - blockId: string | null; - /** - * Whether this is the start of a block drag. - * @type {boolean|undefined} - */ - isStart: boolean | undefined; - /** - * The blocks affected by this drag event. - * @type {!Array|undefined} - */ - blocks: Array | undefined; - } - import { UiBase } from "core/events/events_ui_base"; - import { Block } from "core/block"; -} -declare module "core/block_dragger" { - /** - * Class for a block dragger. It moves blocks around the workspace when they - * are being dragged by a mouse or touch. - * @implements {IBlockDragger} - * @alias Blockly.BlockDragger - */ - export const BlockDragger: { - new (block: BlockSvg, workspace: WorkspaceSvg): { - /** - * The top block in the stack that is being dragged. - * @type {!BlockSvg} - * @protected - */ - draggingBlock_: BlockSvg; - /** - * The workspace on which the block is being dragged. - * @type {!WorkspaceSvg} - * @protected - */ - workspace_: WorkspaceSvg; - /** - * Object that keeps track of connections on dragged blocks. - * @type {!InsertionMarkerManager} - * @protected - */ - draggedConnectionManager_: InsertionMarkerManager; - /** - * Which drag area the mouse pointer is over, if any. - * @type {?IDragTarget} - * @private - */ - dragTarget_: (() => void) | null; - /** - * Whether the block would be deleted if dropped immediately. - * @type {boolean} - * @protected - */ - wouldDeleteBlock_: boolean; - /** - * The location of the top left corner of the dragging block at the - * beginning of the drag in workspace coordinates. - * @type {!Coordinate} - * @protected - */ - startXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * A list of all of the icons (comment, warning, and mutator) that are - * on this block and its descendants. Moving an icon moves the bubble that - * extends from it if that bubble is open. - * @type {Array} - * @protected - */ - dragIconData_: Array; - /** - * Sever all links from this object. - * @package - */ - dispose(): void; - /** - * Start dragging a block. This includes moving it to the drag surface. - * @param {!Coordinate} currentDragDeltaXY How far the pointer has - * moved from the position at mouse down, in pixel units. - * @param {boolean} healStack Whether or not to heal the stack after - * disconnecting. - * @public - */ - startDrag(currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }, healStack: boolean): void; - /** - * Whether or not we should disconnect the block when a drag is started. - * @param {boolean} healStack Whether or not to heal the stack after - * disconnecting. - * @return {boolean} True to disconnect the block, false otherwise. - * @protected - */ - shouldDisconnect_(healStack: boolean): boolean; - /** - * Disconnects the block and moves it to a new location. - * @param {boolean} healStack Whether or not to heal the stack after - * disconnecting. - * @param {!Coordinate} currentDragDeltaXY How far the pointer has - * moved from the position at mouse down, in pixel units. - * @protected - */ - disconnectBlock_(healStack: boolean, currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Fire a UI event at the start of a block drag. - * @protected - */ - fireDragStartEvent_(): void; - /** - * Execute a step of block dragging, based on the given event. Update the - * display accordingly. - * @param {!Event} e The most recent move event. - * @param {!Coordinate} currentDragDeltaXY How far the pointer has - * moved from the position at the start of the drag, in pixel units. - * @public - */ - drag(e: Event, currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Finish a block drag and put the block back on the workspace. - * @param {!Event} e The mouseup/touchend event. - * @param {!Coordinate} currentDragDeltaXY How far the pointer has - * moved from the position at the start of the drag, in pixel units. - * @public - */ - endDrag(e: Event, currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Calculates the drag delta and new location values after a block is dragged. - * @param {!Coordinate} currentDragDeltaXY How far the pointer has - * moved from the start of the drag, in pixel units. - * @return {{delta: !Coordinate, newLocation: - * !Coordinate}} New location after drag. delta is in - * workspace units. newLocation is the new coordinate where the block - * should end up. - * @protected - */ - getNewLocationAfterDrag_(currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): { - delta: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - newLocation: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - }; - /** - * May delete the dragging block, if allowed. If `this.wouldDeleteBlock_` is - * not true, the block will not be deleted. This should be called at the end - * of a block drag. - * @return {boolean} True if the block was deleted. - * @protected - */ - maybeDeleteBlock_(): boolean; - /** - * Updates the necessary information to place a block at a certain location. - * @param {!Coordinate} delta The change in location from where - * the block started the drag to where it ended the drag. - * @protected - */ - updateBlockAfterMove_(delta: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Fire a UI event at the end of a block drag. - * @protected - */ - fireDragEndEvent_(): void; - /** - * Adds or removes the style of the cursor for the toolbox. - * This is what changes the cursor to display an x when a deletable block is - * held over the toolbox. - * @param {boolean} isEnd True if we are at the end of a drag, false - * otherwise. - * @protected - */ - updateToolboxStyle_(isEnd: boolean): void; - /** - * Fire a move event at the end of a block drag. - * @protected - */ - fireMoveEvent_(): void; - /** - * Update the cursor (and possibly the trash can lid) to reflect whether the - * dragging block would be deleted if released immediately. - * @protected - */ - updateCursorDuringBlockDrag_(): void; - /** - * Convert a coordinate object from pixels to workspace units, including a - * correction for mutator workspaces. - * This function does not consider differing origins. It simply scales the - * input's x and y values. - * @param {!Coordinate} pixelCoord A coordinate with x and y - * values in CSS pixel units. - * @return {!Coordinate} The input coordinate divided by the - * workspace scale. - * @protected - */ - pixelsToWorkspaceUnits_(pixelCoord: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - /** - * Move all of the icons connected to this drag. - * @param {!Coordinate} dxy How far to move the icons from their - * original positions, in workspace units. - * @protected - */ - dragIcons_(dxy: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - /** - * Get a list of the insertion markers that currently exist. Drags have 0, 1, - * or 2 insertion markers. - * @return {!Array} A possibly empty list of insertion - * marker blocks. - * @public - */ - getInsertionMarkers(): Array; - }; - }; - import { BlockSvg } from "core/block_svg"; - import { WorkspaceSvg } from "core/workspace_svg"; - import { InsertionMarkerManager } from "core/insertion_marker_manager"; -} -declare module "core/events/events_click" { - /** - * Class for a click event. - * @extends {UiBase} - * @alias Blockly.Events.Click - */ - export class Click extends UiBase { - /** - * @param {?Block=} opt_block The affected block. Null for click events - * that do not have an associated block (i.e. workspace click). Undefined - * for a blank event. - * @param {?string=} opt_workspaceId The workspace identifier for this event. - * Not used if block is passed. Undefined for a blank event. - * @param {string=} opt_targetType The type of element targeted by this click - * event. Undefined for a blank event. - */ - constructor(opt_block?: (Block | null) | undefined, opt_workspaceId?: (string | null) | undefined, opt_targetType?: string | undefined); - blockId: string | null; - /** - * The type of element targeted by this click event. - * @type {string|undefined} - */ - targetType: string | undefined; - } - import { UiBase } from "core/events/events_ui_base"; - import { Block } from "core/block"; -} -declare module "core/gesture" { - /** - * Note: In this file "start" refers to touchstart, mousedown, and pointerstart - * events. "End" refers to touchend, mouseup, and pointerend events. - */ - /** - * Class for one gesture. - * @alias Blockly.Gesture - */ - export class Gesture { - /** - * Is a drag or other gesture currently in progress on any workspace? - * @return {boolean} True if gesture is occurring. - */ - static inProgress(): boolean; - /** - * @param {!Event} e The event that kicked off this gesture. - * @param {!WorkspaceSvg} creatorWorkspace The workspace that created - * this gesture and has a reference to it. - */ - constructor(e: Event, creatorWorkspace: WorkspaceSvg); - /** - * The position of the mouse when the gesture started. Units are CSS - * pixels, with (0, 0) at the top left of the browser window (mouseEvent - * clientX/Y). - * @type {Coordinate} - * @private - */ - private mouseDownXY_; - /** - * How far the mouse has moved during this drag, in pixel units. - * (0, 0) is at this.mouseDownXY_. - * @type {!Coordinate} - * @private - */ - private currentDragDeltaXY_; - /** - * The bubble that the gesture started on, or null if it did not start on a - * bubble. - * @type {IBubble} - * @private - */ - private startBubble_; - /** - * The field that the gesture started on, or null if it did not start on a - * field. - * @type {Field} - * @private - */ - private startField_; - /** - * The block that the gesture started on, or null if it did not start on a - * block. - * @type {BlockSvg} - * @private - */ - private startBlock_; - /** - * The block that this gesture targets. If the gesture started on a - * shadow block, this is the first non-shadow parent of the block. If the - * gesture started in the flyout, this is the root block of the block group - * that was clicked or dragged. - * @type {BlockSvg} - * @private - */ - private targetBlock_; - /** - * The workspace that the gesture started on. There may be multiple - * workspaces on a page; this is more accurate than using - * Blockly.common.getMainWorkspace(). - * @type {WorkspaceSvg} - * @protected - */ - protected startWorkspace_: WorkspaceSvg; - /** - * The workspace that created this gesture. This workspace keeps a - * reference to the gesture, which will need to be cleared at deletion. This - * may be different from the start workspace. For instance, a flyout is a - * workspace, but its parent workspace manages gestures for it. - * @type {!WorkspaceSvg} - * @private - */ - private creatorWorkspace_; - /** - * Whether the pointer has at any point moved out of the drag radius. - * A gesture that exceeds the drag radius is a drag even if it ends exactly - * at its start point. - * @type {boolean} - * @private - */ - private hasExceededDragRadius_; - /** - * Whether the workspace is currently being dragged. - * @type {boolean} - * @private - */ - private isDraggingWorkspace_; - /** - * Whether the block is currently being dragged. - * @type {boolean} - * @private - */ - private isDraggingBlock_; - /** - * Whether the bubble is currently being dragged. - * @type {boolean} - * @private - */ - private isDraggingBubble_; - /** - * The event that most recently updated this gesture. - * @type {!Event} - * @private - */ - private mostRecentEvent_; - /** - * A handle to use to unbind a mouse move listener at the end of a drag. - * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?browserEvents.Data} - * @protected - */ - protected onMoveWrapper_: any[][] | null; - /** - * A handle to use to unbind a mouse up listener at the end of a drag. - * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?browserEvents.Data} - * @protected - */ - protected onUpWrapper_: any[][] | null; - /** - * The object tracking a bubble drag, or null if none is in progress. - * @type {BubbleDragger} - * @private - */ - private bubbleDragger_; - /** - * The object tracking a block drag, or null if none is in progress. - * @type {?IBlockDragger} - * @private - */ - private blockDragger_; - /** - * The object tracking a workspace or flyout workspace drag, or null if none - * is in progress. - * @type {WorkspaceDragger} - * @private - */ - private workspaceDragger_; - /** - * The flyout a gesture started in, if any. - * @type {IFlyout} - * @private - */ - private flyout_; - /** - * Boolean for sanity-checking that some code is only called once. - * @type {boolean} - * @private - */ - private calledUpdateIsDragging_; - /** - * Boolean for sanity-checking that some code is only called once. - * @type {boolean} - * @private - */ - private hasStarted_; - /** - * Boolean used internally to break a cycle in disposal. - * @type {boolean} - * @protected - */ - protected isEnding_: boolean; - /** - * Boolean used to indicate whether or not to heal the stack after - * disconnecting a block. - * @type {boolean} - * @private - */ - private healStack_; - /** - * Sever all links from this object. - * @package - */ - dispose(): void; - /** - * Update internal state based on an event. - * @param {!Event} e The most recent mouse or touch event. - * @private - */ - private updateFromEvent_; - /** - * DO MATH to set currentDragDeltaXY_ based on the most recent mouse position. - * @param {!Coordinate} currentXY The most recent mouse/pointer - * position, in pixel units, with (0, 0) at the window's top left corner. - * @return {boolean} True if the drag just exceeded the drag radius for the - * first time. - * @private - */ - private updateDragDelta_; - /** - * Update this gesture to record whether a block is being dragged from the - * flyout. - * This function should be called on a mouse/touch move event the first time - * the drag radius is exceeded. It should be called no more than once per - * gesture. If a block should be dragged from the flyout this function creates - * the new block on the main workspace and updates targetBlock_ and - * startWorkspace_. - * @return {boolean} True if a block is being dragged from the flyout. - * @private - */ - private updateIsDraggingFromFlyout_; - /** - * Update this gesture to record whether a bubble is being dragged. - * This function should be called on a mouse/touch move event the first time - * the drag radius is exceeded. It should be called no more than once per - * gesture. If a bubble should be dragged this function creates the necessary - * BubbleDragger and starts the drag. - * @return {boolean} True if a bubble is being dragged. - * @private - */ - private updateIsDraggingBubble_; - /** - * Update this gesture to record whether a block is being dragged. - * This function should be called on a mouse/touch move event the first time - * the drag radius is exceeded. It should be called no more than once per - * gesture. If a block should be dragged, either from the flyout or in the - * workspace, this function creates the necessary BlockDragger and starts the - * drag. - * @return {boolean} True if a block is being dragged. - * @private - */ - private updateIsDraggingBlock_; - /** - * Update this gesture to record whether a workspace is being dragged. - * This function should be called on a mouse/touch move event the first time - * the drag radius is exceeded. It should be called no more than once per - * gesture. If a workspace is being dragged this function creates the - * necessary WorkspaceDragger and starts the drag. - * @private - */ - private updateIsDraggingWorkspace_; - /** - * Update this gesture to record whether anything is being dragged. - * This function should be called on a mouse/touch move event the first time - * the drag radius is exceeded. It should be called no more than once per - * gesture. - * @private - */ - private updateIsDragging_; - /** - * Create a block dragger and start dragging the selected block. - * @private - */ - private startDraggingBlock_; - /** - * Create a bubble dragger and start dragging the selected bubble. - * @private - */ - private startDraggingBubble_; - /** - * Start a gesture: update the workspace to indicate that a gesture is in - * progress and bind mousemove and mouseup handlers. - * @param {!Event} e A mouse down or touch start event. - * @package - */ - doStart(e: Event): void; - /** - * Bind gesture events. - * @param {!Event} e A mouse down or touch start event. - * @package - */ - bindMouseEvents(e: Event): void; - /** - * Handle a mouse move or touch move event. - * @param {!Event} e A mouse move or touch move event. - * @package - */ - handleMove(e: Event): void; - /** - * Handle a mouse up or touch end event. - * @param {!Event} e A mouse up or touch end event. - * @package - */ - handleUp(e: Event): void; - /** - * Cancel an in-progress gesture. If a workspace or block drag is in - * progress, end the drag at the most recent location. - * @package - */ - cancel(): void; - /** - * Handle a real or faked right-click event by showing a context menu. - * @param {!Event} e A mouse move or touch move event. - * @package - */ - handleRightClick(e: Event): void; - /** - * Handle a mousedown/touchstart event on a workspace. - * @param {!Event} e A mouse down or touch start event. - * @param {!WorkspaceSvg} ws The workspace the event hit. - * @package - */ - handleWsStart(e: Event, ws: WorkspaceSvg): void; - /** - * Fires a workspace click event. - * @param {!WorkspaceSvg} ws The workspace that a user clicks on. - * @private - */ - private fireWorkspaceClick_; - /** - * Handle a mousedown/touchstart event on a flyout. - * @param {!Event} e A mouse down or touch start event. - * @param {!IFlyout} flyout The flyout the event hit. - * @package - */ - handleFlyoutStart(e: Event, flyout: IFlyout): void; - /** - * Handle a mousedown/touchstart event on a block. - * @param {!Event} e A mouse down or touch start event. - * @param {!BlockSvg} block The block the event hit. - * @package - */ - handleBlockStart(e: Event, block: BlockSvg): void; - /** - * Handle a mousedown/touchstart event on a bubble. - * @param {!Event} e A mouse down or touch start event. - * @param {!IBubble} bubble The bubble the event hit. - * @package - */ - handleBubbleStart(e: Event, bubble: () => void): void; - /** - * Execute a bubble click. - * @private - */ - private doBubbleClick_; - /** - * Execute a field click. - * @private - */ - private doFieldClick_; - /** - * Execute a block click. - * @private - */ - private doBlockClick_; - /** - * Execute a workspace click. When in accessibility mode shift clicking will - * move the cursor. - * @param {!Event} _e A mouse up or touch end event. - * @private - */ - private doWorkspaceClick_; - /** - * Move the dragged/clicked block to the front of the workspace so that it is - * not occluded by other blocks. - * @private - */ - private bringBlockToFront_; - /** - * Record the field that a gesture started on. - * @param {Field} field The field the gesture started on. - * @package - */ - setStartField(field: Field): void; - /** - * Record the bubble that a gesture started on - * @param {IBubble} bubble The bubble the gesture started on. - * @package - */ - setStartBubble(bubble: () => void): void; - /** - * Record the block that a gesture started on, and set the target block - * appropriately. - * @param {BlockSvg} block The block the gesture started on. - * @package - */ - setStartBlock(block: BlockSvg): void; - /** - * Record the block that a gesture targets, meaning the block that will be - * dragged if this turns into a drag. If this block is a shadow, that will be - * its first non-shadow parent. - * @param {BlockSvg} block The block the gesture targets. - * @private - */ - private setTargetBlock_; - /** - * Record the workspace that a gesture started on. - * @param {WorkspaceSvg} ws The workspace the gesture started on. - * @private - */ - private setStartWorkspace_; - /** - * Record the flyout that a gesture started on. - * @param {IFlyout} flyout The flyout the gesture started on. - * @private - */ - private setStartFlyout_; - /** - * Whether this gesture is a click on a bubble. This should only be called - * when ending a gesture (mouse up, touch end). - * @return {boolean} Whether this gesture was a click on a bubble. - * @private - */ - private isBubbleClick_; - /** - * Whether this gesture is a click on a block. This should only be called - * when ending a gesture (mouse up, touch end). - * @return {boolean} Whether this gesture was a click on a block. - * @private - */ - private isBlockClick_; - /** - * Whether this gesture is a click on a field. This should only be called - * when ending a gesture (mouse up, touch end). - * @return {boolean} Whether this gesture was a click on a field. - * @private - */ - private isFieldClick_; - /** - * Whether this gesture is a click on a workspace. This should only be called - * when ending a gesture (mouse up, touch end). - * @return {boolean} Whether this gesture was a click on a workspace. - * @private - */ - private isWorkspaceClick_; - /** - * Whether this gesture is a drag of either a workspace or block. - * This function is called externally to block actions that cannot be taken - * mid-drag (e.g. using the keyboard to delete the selected blocks). - * @return {boolean} True if this gesture is a drag of a workspace or block. - * @package - */ - isDragging(): boolean; - /** - * Whether this gesture has already been started. In theory every mouse down - * has a corresponding mouse up, but in reality it is possible to lose a - * mouse up, leaving an in-process gesture hanging. - * @return {boolean} Whether this gesture was a click on a workspace. - * @package - */ - hasStarted(): boolean; - /** - * Get a list of the insertion markers that currently exist. Block drags have - * 0, 1, or 2 insertion markers. - * @return {!Array} A possibly empty list of insertion - * marker blocks. - * @package - */ - getInsertionMarkers(): Array; - /** - * Gets the current dragger if an item is being dragged. Null if nothing is - * being dragged. - * @return {!WorkspaceDragger|!BubbleDragger|!IBlockDragger|null} - * The dragger that is currently in use or null if no drag is in progress. - */ - getCurrentDragger(): WorkspaceDragger | { - draggingBubble_: () => void; - workspace_: WorkspaceSvg; - dragTarget_: (() => void) | null; - wouldDeleteBubble_: boolean; - startXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - dragSurface_: { - SVG_: SVGElement | null; - dragGroup_: SVGElement | null; - container_: Element; - scale_: number; - surfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - } | null; - childSurfaceXY_: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - createDom(): void; - setBlocksAndShow(blocks: SVGElement): void; - translateAndScaleGroup(x: number, y: number, scale: number): void; - translateSurfaceInternal_(): void; - translateBy(deltaX: number, deltaY: number): void; - translateSurface(x: number, y: number): void; - getSurfaceTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - getGroup(): SVGElement | null; - getSvgRoot(): SVGElement | null; - getCurrentBlock(): Element | null; - getWsTranslation(): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - clearAndHide(opt_newSurface?: Element | undefined): void; - }; - dispose(): void; - startBubbleDrag(): void; - dragBubble(e: Event, currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - shouldDelete_(dragTarget: (() => void) | null): boolean; - updateCursorDuringBubbleDrag_(): void; - endBubbleDrag(e: Event, currentDragDeltaXY: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): void; - fireMoveEvent_(): void; - pixelsToWorkspaceUnits_(pixelCoord: { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }): { - x: number; - y: number; - clone(): any; - scale(s: number): any; - translate(tx: number, ty: number): any; - }; - moveToDragSurface_(): void; - } | (() => void) | null; - } - import { WorkspaceSvg } from "core/workspace_svg"; - import { IFlyout } from "core/interfaces/i_flyout"; - import { BlockSvg } from "core/block_svg"; - import { Field } from "core/field"; - import { WorkspaceDragger } from "core/workspace_dragger"; -} -declare module "core/touch" { - /** - * Whether touch is enabled in the browser. - * Copied from Closure's goog.events.BrowserFeature.TOUCH_ENABLED - * @const - */ - export const TOUCH_ENABLED: boolean; - /** - * The TOUCH_MAP lookup dictionary specifies additional touch events to fire, - * in conjunction with mouse events. - * @type {Object} - * @alias Blockly.Touch.TOUCH_MAP - */ - export let TOUCH_MAP: Object; - /** - * Context menus on touch devices are activated using a long-press. - * Unfortunately the contextmenu touch event is currently (2015) only supported - * by Chrome. This function is fired on any touchstart event, queues a task, - * which after about a second opens the context menu. The tasks is killed - * if the touch event terminates early. - * @param {!Event} e Touch start event. - * @param {Gesture} gesture The gesture that triggered this longStart. - * @alias Blockly.Touch.longStart - * @package - */ - export function longStart(e: Event, gesture: Gesture): void; - /** - * Nope, that's not a long-press. Either touchend or touchcancel was fired, - * or a drag hath begun. Kill the queued long-press task. - * @alias Blockly.Touch.longStop - * @package - */ - export function longStop(): void; - /** - * Clear the touch identifier that tracks which touch stream to pay attention - * to. This ends the current drag/gesture and allows other pointers to be - * captured. - * @alias Blockly.Touch.clearTouchIdentifier - */ - export function clearTouchIdentifier(): void; - /** - * Decide whether Blockly should handle or ignore this event. - * Mouse and touch events require special checks because we only want to deal - * with one touch stream at a time. All other events should always be handled. - * @param {!Event} e The event to check. - * @return {boolean} True if this event should be passed through to the - * registered handler; false if it should be blocked. - * @alias Blockly.Touch.shouldHandleEvent - */ - export function shouldHandleEvent(e: Event): boolean; - /** - * Get the touch identifier from the given event. If it was a mouse event, the - * identifier is the string 'mouse'. - * @param {!Event} e Mouse event or touch event. - * @return {string} The touch identifier from the first changed touch, if - * defined. Otherwise 'mouse'. - * @alias Blockly.Touch.getTouchIdentifierFromEvent - */ - export function getTouchIdentifierFromEvent(e: Event): string; - /** - * Check whether the touch identifier on the event matches the current saved - * identifier. If there is no identifier, that means it's a mouse event and - * we'll use the identifier "mouse". This means we won't deal well with - * multiple mice being used at the same time. That seems okay. - * If the current identifier was unset, save the identifier from the - * event. This starts a drag/gesture, during which touch events with other - * identifiers will be silently ignored. - * @param {!Event} e Mouse event or touch event. - * @return {boolean} Whether the identifier on the event matches the current - * saved identifier. - * @alias Blockly.Touch.checkTouchIdentifier - */ - export function checkTouchIdentifier(e: Event): boolean; - /** - * Set an event's clientX and clientY from its first changed touch. Use this to - * make a touch event work in a mouse event handler. - * @param {!Event} e A touch event. - * @alias Blockly.Touch.setClientFromTouch - */ - export function setClientFromTouch(e: Event): void; - /** - * Check whether a given event is a mouse or touch event. - * @param {!Event} e An event. - * @return {boolean} True if it is a mouse or touch event; false otherwise. - * @alias Blockly.Touch.isMouseOrTouchEvent - */ - export function isMouseOrTouchEvent(e: Event): boolean; - /** - * Check whether a given event is a touch event or a pointer event. - * @param {!Event} e An event. - * @return {boolean} True if it is a touch event; false otherwise. - * @alias Blockly.Touch.isTouchEvent - */ - export function isTouchEvent(e: Event): boolean; - /** - * Split an event into an array of events, one per changed touch or mouse - * point. - * @param {!Event} e A mouse event or a touch event with one or more changed - * touches. - * @return {!Array} An array of mouse or touch events. Each touch - * event will have exactly one changed touch. - * @alias Blockly.Touch.splitEventByTouches - */ - export function splitEventByTouches(e: Event): Array; - import { Gesture } from "core/gesture"; -} -declare module "core/browser_events" { - /** - * Blockly opaque event data used to unbind events when using - * `bind` and `conditionalBind`. - */ - export type Data = Array; - /** - * Blockly opaque event data used to unbind events when using - * `bind` and `conditionalBind`. - * @typedef {!Array} - * @alias Blockly.browserEvents.Data - */ - export let Data: any; - /** - * Bind an event handler that can be ignored if it is not part of the active - * touch stream. - * Use this for events that either start or continue a multi-part gesture (e.g. - * mousedown or mousemove, which may be part of a drag or click). - * @param {!EventTarget} node Node upon which to listen. - * @param {string} name Event name to listen to (e.g. 'mousedown'). - * @param {?Object} thisObject The value of 'this' in the function. - * @param {!Function} func Function to call when event is triggered. - * @param {boolean=} opt_noCaptureIdentifier True if triggering on this event - * should not block execution of other event handlers on this touch or - * other simultaneous touches. False by default. - * @param {boolean=} opt_noPreventDefault True if triggering on this event - * should prevent the default handler. False by default. If - * opt_noPreventDefault is provided, opt_noCaptureIdentifier must also be - * provided. - * @return {!Data} Opaque data that can be passed to - * unbindEvent_. - * @alias Blockly.browserEvents.conditionalBind - */ - export function conditionalBind(node: EventTarget, name: string, thisObject: Object | null, func: Function, opt_noCaptureIdentifier?: boolean | undefined, opt_noPreventDefault?: boolean | undefined): any[][]; - /** - * Bind an event handler that should be called regardless of whether it is part - * of the active touch stream. - * Use this for events that are not part of a multi-part gesture (e.g. - * mouseover for tooltips). - * @param {!EventTarget} node Node upon which to listen. - * @param {string} name Event name to listen to (e.g. 'mousedown'). - * @param {?Object} thisObject The value of 'this' in the function. - * @param {!Function} func Function to call when event is triggered. - * @return {!Data} Opaque data that can be passed to - * unbindEvent_. - * @alias Blockly.browserEvents.bind - */ - export function bind(node: EventTarget, name: string, thisObject: Object | null, func: Function): any[][]; - /** - * Unbind one or more events event from a function call. - * @param {!Data} bindData Opaque data from bindEvent_. - * This list is emptied during the course of calling this function. - * @return {!Function} The function call. - * @alias Blockly.browserEvents.unbind - */ - export function unbind(bindData: any[][]): Function; - /** - * Returns true if this event is targeting a text input widget? - * @param {!Event} e An event. - * @return {boolean} True if text input. - * @alias Blockly.browserEvents.isTargetInput - */ - export function isTargetInput(e: Event): boolean; - /** - * Returns true this event is a right-click. - * @param {!Event} e Mouse event. - * @return {boolean} True if right-click. - * @alias Blockly.browserEvents.isRightButton - */ - export function isRightButton(e: Event): boolean; - /** - * Returns the converted coordinates of the given mouse event. - * The origin (0,0) is the top-left corner of the Blockly SVG. - * @param {!Event} e Mouse event. - * @param {!Element} svg SVG element. - * @param {?SVGMatrix} matrix Inverted screen CTM to use. - * @return {!SVGPoint} Object with .x and .y properties. - * @alias Blockly.browserEvents.mouseToSvg - */ - export function mouseToSvg(e: Event, svg: Element, matrix: SVGMatrix | null): SVGPoint; - /** - * Returns the scroll delta of a mouse event in pixel units. - * @param {!Event} e Mouse event. - * @return {{x: number, y: number}} Scroll delta object with .x and .y - * properties. - * @alias Blockly.browserEvents.getScrollDeltaPixels - */ - export function getScrollDeltaPixels(e: Event): { - x: number; - y: number; - }; -} -declare module "core/tooltip" { - /** - * A type which can define a tooltip. - * Either a string, an object containing a tooltip property, or a function which - * returns either a string, or another arbitrarily nested function which - * eventually unwinds to a string. - */ - export type TipInfo = string | { - tooltip: any; - } | (() => (string | Function)); - /** - * A type which can define a tooltip. - * Either a string, an object containing a tooltip property, or a function which - * returns either a string, or another arbitrarily nested function which - * eventually unwinds to a string. - * @typedef {string|{tooltip}|function(): (string|!Function)} - * @alias Blockly.Tooltip.TipInfo - */ - export let TipInfo: any; - /** - * A function that renders custom tooltip UI. - * 1st parameter: the div element to render content into. - * 2nd parameter: the element being moused over (i.e., the element for which the - * tooltip should be shown). - */ - export type CustomTooltip = (arg0: Element, arg1: Element) => any; - /** - * A function that renders custom tooltip UI. - * 1st parameter: the div element to render content into. - * 2nd parameter: the element being moused over (i.e., the element for which the - * tooltip should be shown). - * @typedef {function(!Element, !Element)} - * @alias Blockly.Tooltip.CustomTooltip - */ - export let CustomTooltip: any; - /** - * Sets a custom function that will be called if present instead of the default - * tooltip UI. - * @param {!CustomTooltip} customFn A custom tooltip used to render an alternate - * tooltip UI. - * @alias Blockly.Tooltip.setCustomTooltip - */ - export function setCustomTooltip(customFn: CustomTooltip): void; - /** - * Gets the custom tooltip function. - * @returns {!CustomTooltip|undefined} The custom tooltip function, if defined. - */ - export function getCustomTooltip(): CustomTooltip | undefined; - /** - * Returns whether or not a tooltip is showing - * @returns {boolean} True if a tooltip is showing - * @alias Blockly.Tooltip.isVisible - */ - export function isVisible(): boolean; - /** - * Maximum width (in characters) of a tooltip. - * @alias Blockly.Tooltip.LIMIT - */ - export const LIMIT: 50; - /** - * Horizontal offset between mouse cursor and tooltip. - * @alias Blockly.Tooltip.OFFSET_X - */ - export const OFFSET_X: 0; - /** - * Vertical offset between mouse cursor and tooltip. - * @alias Blockly.Tooltip.OFFSET_Y - */ - export const OFFSET_Y: 10; - /** - * Radius mouse can move before killing tooltip. - * @alias Blockly.Tooltip.RADIUS_OK - */ - export const RADIUS_OK: 10; - /** - * Delay before tooltip appears. - * @alias Blockly.Tooltip.HOVER_MS - */ - export const HOVER_MS: 750; - /** - * Horizontal padding between tooltip and screen edge. - * @alias Blockly.Tooltip.MARGINS - */ - export const MARGINS: 5; - /** - * Returns the HTML tooltip container. - * @returns {?HTMLDivElement} The HTML tooltip container. - * @alias Blockly.Tooltip.getDiv - */ - export function getDiv(): HTMLDivElement | null; - /** - * Returns the tooltip text for the given element. - * @param {?Object} object The object to get the tooltip text of. - * @return {string} The tooltip text of the element. - * @alias Blockly.Tooltip.getTooltipOfObject - */ - export function getTooltipOfObject(object: Object | null): string; - /** - * Create the tooltip div and inject it onto the page. - * @alias Blockly.Tooltip.createDom - */ - export function createDom(): void; - /** - * Binds the required mouse events onto an SVG element. - * @param {!Element} element SVG element onto which tooltip is to be bound. - * @alias Blockly.Tooltip.bindMouseEvents - */ - export function bindMouseEvents(element: Element): void; - /** - * Unbinds tooltip mouse events from the SVG element. - * @param {!Element} element SVG element onto which tooltip is bound. - * @alias Blockly.Tooltip.unbindMouseEvents - */ - export function unbindMouseEvents(element: Element): void; - /** - * Dispose of the tooltip. - * @alias Blockly.Tooltip.dispose - * @package - */ - export function dispose(): void; - /** - * Hide the tooltip. - * @alias Blockly.Tooltip.hide - */ - export function hide(): void; - /** - * Hide any in-progress tooltips and block showing new tooltips until the next - * call to unblock(). - * @alias Blockly.Tooltip.block - * @package - */ - export function block(): void; - /** - * Unblock tooltips: allow them to be scheduled and shown according to their own - * logic. - * @alias Blockly.Tooltip.unblock - * @package - */ - export function unblock(): void; -} -declare module "core/utils/object" { - /** - * Inherit the prototype methods from one constructor into another. - * @param {!Function} childCtor Child class. - * @param {!Function} parentCtor Parent class. - * @suppress {strictMissingProperties} superClass_ is not defined on Function. - * @alias Blockly.utils.object.inherits - */ - export function inherits(childCtor: Function, parentCtor: Function): void; - /** - * Copies all the members of a source object to a target object. - * @param {!Object} target Target. - * @param {!Object} source Source. - * @alias Blockly.utils.object.mixin - */ - export function mixin(target: Object, source: Object): void; - /** - * Complete a deep merge of all members of a source object with a target object. - * @param {!Object} target Target. - * @param {!Object} source Source. - * @return {!Object} The resulting object. - * @alias Blockly.utils.object.deepMerge - */ - export function deepMerge(target: Object, source: Object): Object; - /** - * Returns an array of a given object's own enumerable property values. - * @param {!Object} obj Object containing values. - * @return {!Array} Array of values. - * @alias Blockly.utils.object.values - */ - export function values(obj: Object): any[]; -} -declare module "core/theme" { - /** - * Class for a theme. - * @alias Blockly.Theme - */ - export class Theme { - /** - * Define a new Blockly theme. - * @param {string} name The name of the theme. - * @param {!Object} themeObj An object containing theme properties. - * @return {!Theme} A new Blockly theme. - */ - static defineTheme(name: string, themeObj: Object): Theme; - /** - * @param {string} name Theme name. - * @param {!Object=} opt_blockStyles A map - * from style names (strings) to objects with style attributes for blocks. - * @param {!Object=} opt_categoryStyles A - * map from style names (strings) to objects with style attributes for - * categories. - * @param {!Theme.ComponentStyle=} opt_componentStyles A map of Blockly - * component names to style value. - */ - constructor(name: string, opt_blockStyles?: { - [x: string]: Theme.BlockStyle; - } | undefined, opt_categoryStyles?: { - [x: string]: Theme.CategoryStyle; - } | undefined, opt_componentStyles?: Theme.ComponentStyle | undefined); - /** - * The theme name. This can be used to reference a specific theme in CSS. - * @type {string} - */ - name: string; - /** - * The block styles map. - * @type {!Object} - * @package - */ - blockStyles: { - [x: string]: Theme.BlockStyle; - }; - /** - * The category styles map. - * @type {!Object} - * @package - */ - categoryStyles: { - [x: string]: Theme.CategoryStyle; - }; - /** - * The UI components styles map. - * @type {!Theme.ComponentStyle} - * @package - */ - componentStyles: Theme.ComponentStyle; - /** - * The font style. - * @type {!Theme.FontStyle} - * @package - */ - fontStyle: Theme.FontStyle; - /** - * Whether or not to add a 'hat' on top of all blocks with no previous or - * output connections. - * @type {?boolean} - * @package - */ - startHats: boolean | null; - /** - * Gets the class name that identifies this theme. - * @return {string} The CSS class name. - * @package - */ - getClassName(): string; - /** - * Overrides or adds a style to the blockStyles map. - * @param {string} blockStyleName The name of the block style. - * @param {Theme.BlockStyle} blockStyle The block style. - */ - setBlockStyle(blockStyleName: string, blockStyle: Theme.BlockStyle): void; - /** - * Overrides or adds a style to the categoryStyles map. - * @param {string} categoryStyleName The name of the category style. - * @param {Theme.CategoryStyle} categoryStyle The category style. - */ - setCategoryStyle(categoryStyleName: string, categoryStyle: Theme.CategoryStyle): void; - /** - * Gets the style for a given Blockly UI component. If the style value is a - * string, we attempt to find the value of any named references. - * @param {string} componentName The name of the component. - * @return {?string} The style value. - */ - getComponentStyle(componentName: string): string | null; - /** - * Configure a specific Blockly UI component with a style value. - * @param {string} componentName The name of the component. - * @param {*} styleValue The style value. - */ - setComponentStyle(componentName: string, styleValue: any): void; - /** - * Configure a theme's font style. - * @param {Theme.FontStyle} fontStyle The font style. - */ - setFontStyle(fontStyle: Theme.FontStyle): void; - /** - * Configure a theme's start hats. - * @param {boolean} startHats True if the theme enables start hats, false - * otherwise. - */ - setStartHats(startHats: boolean): void; - } - export namespace Theme { - /** - * A block style. - */ - type BlockStyle = { - colourPrimary: string; - colourSecondary: string; - colourTertiary: string; - hat: string; - }; - /** - * A category style. - */ - type CategoryStyle = { - colour: string; - }; - /** - * A component style. - */ - type ComponentStyle = { - workspaceBackgroundColour: string | null; - toolboxBackgroundColour: string | null; - toolboxForegroundColour: string | null; - flyoutBackgroundColour: string | null; - flyoutForegroundColour: string | null; - flyoutOpacity: number | null; - scrollbarColour: string | null; - scrollbarOpacity: number | null; - insertionMarkerColour: string | null; - insertionMarkerOpacity: number | null; - markerColour: string | null; - cursorColour: string | null; - selectedGlowColour: string | null; - selectedGlowOpacity: number | null; - replacementGlowColour: string | null; - replacementGlowOpacity: number | null; - }; - /** - * A font style. - */ - type FontStyle = { - family: string | null; - weight: string | null; - size: number | null; - }; - } -} -declare module "core/renderers/common/constants" { - /** - * An object that provides constants for rendering blocks. - * @alias Blockly.blockRendering.ConstantProvider - */ - export class ConstantProvider { - /** - * The size of an empty spacer. - * @type {number} - */ - NO_PADDING: number; - /** - * The size of small padding. - * @type {number} - */ - SMALL_PADDING: number; - /** - * The size of medium padding. - * @type {number} - */ - MEDIUM_PADDING: number; - /** - * The size of medium-large padding. - * @type {number} - */ - MEDIUM_LARGE_PADDING: number; - /** - * The size of large padding. - * @type {number} - */ - LARGE_PADDING: number; - /** - * Offset from the top of the row for placing fields on inline input rows - * and statement input rows. - * Matches existing rendering (in 2019). - * @type {number} - */ - TALL_INPUT_FIELD_OFFSET_Y: number; - /** - * The height of the puzzle tab used for input and output connections. - * @type {number} - */ - TAB_HEIGHT: number; - /** - * The offset from the top of the block at which a puzzle tab is positioned. - * @type {number} - */ - TAB_OFFSET_FROM_TOP: number; - /** - * Vertical overlap of the puzzle tab, used to make it look more like a - * puzzle piece. - * @type {number} - */ - TAB_VERTICAL_OVERLAP: number; - /** - * The width of the puzzle tab used for input and output connections. - * @type {number} - */ - TAB_WIDTH: number; - /** - * The width of the notch used for previous and next connections. - * @type {number} - */ - NOTCH_WIDTH: number; - /** - * The height of the notch used for previous and next connections. - * @type {number} - */ - NOTCH_HEIGHT: number; - /** - * The minimum width of the block. - * @type {number} - */ - MIN_BLOCK_WIDTH: number; - EMPTY_BLOCK_SPACER_HEIGHT: number; - /** - * The minimum height of a dummy input row. - * @type {number} - */ - DUMMY_INPUT_MIN_HEIGHT: number; - /** - * The minimum height of a dummy input row in a shadow block. - * @type {number} - */ - DUMMY_INPUT_SHADOW_MIN_HEIGHT: number; - /** - * Rounded corner radius. - * @type {number} - */ - CORNER_RADIUS: number; - /** - * Offset from the left side of a block or the inside of a statement input - * to the left side of the notch. - * @type {number} - */ - NOTCH_OFFSET_LEFT: number; - /** - * Additional offset added to the statement input's width to account for the - * notch. - * @type {number} - */ - STATEMENT_INPUT_NOTCH_OFFSET: number; - STATEMENT_BOTTOM_SPACER: number; - STATEMENT_INPUT_PADDING_LEFT: number; - /** - * Vertical padding between consecutive statement inputs. - * @type {number} - */ - BETWEEN_STATEMENT_PADDING_Y: number; - /** - * The top row's minimum height. - * @type {number} - */ - TOP_ROW_MIN_HEIGHT: number; - /** - * The top row's minimum height if it precedes a statement. - * @type {number} - */ - TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT: number; - /** - * The bottom row's minimum height. - * @type {number} - */ - BOTTOM_ROW_MIN_HEIGHT: number; - /** - * The bottom row's minimum height if it follows a statement input. - * @type {number} - */ - BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT: number; - /** - * Whether to add a 'hat' on top of all blocks with no previous or output - * connections. Can be overridden by 'hat' property on Theme.BlockStyle. - * @type {boolean} - */ - ADD_START_HATS: boolean; - /** - * Height of the top hat. - * @type {number} - */ - START_HAT_HEIGHT: number; - /** - * Width of the top hat. - * @type {number} - */ - START_HAT_WIDTH: number; - SPACER_DEFAULT_HEIGHT: number; - MIN_BLOCK_HEIGHT: number; - EMPTY_INLINE_INPUT_PADDING: number; - /** - * The height of an empty inline input. - * @type {number} - */ - EMPTY_INLINE_INPUT_HEIGHT: number; - EXTERNAL_VALUE_INPUT_PADDING: number; - /** - * The height of an empty statement input. Note that in the old rendering - * this varies slightly depending on whether the block has external or - * inline inputs. In the new rendering this is consistent. It seems - * unlikely that the old behaviour was intentional. - * @type {number} - */ - EMPTY_STATEMENT_INPUT_HEIGHT: number; - START_POINT: string; - /** - * Height of SVG path for jagged teeth at the end of collapsed blocks. - * @type {number} - */ - JAGGED_TEETH_HEIGHT: number; - /** - * Width of SVG path for jagged teeth at the end of collapsed blocks. - * @type {number} - */ - JAGGED_TEETH_WIDTH: number; - /** - * Point size of text. - * @type {number} - */ - FIELD_TEXT_FONTSIZE: number; - /** - * Text font weight. - * @type {string} - */ - FIELD_TEXT_FONTWEIGHT: string; - /** - * Text font family. - * @type {string} - */ - FIELD_TEXT_FONTFAMILY: string; - /** - * Height of text. This constant is dynamically set in - * ``setFontConstants_`` to be the height of the text based on the font - * used. - * @type {number} - */ - FIELD_TEXT_HEIGHT: number; - /** - * Text baseline. This constant is dynamically set in ``setFontConstants_`` - * to be the baseline of the text based on the font used. - * @type {number} - */ - FIELD_TEXT_BASELINE: number; - /** - * A field's border rect corner radius. - * @type {number} - */ - FIELD_BORDER_RECT_RADIUS: number; - /** - * A field's border rect default height. - * @type {number} - */ - FIELD_BORDER_RECT_HEIGHT: number; - /** - * A field's border rect X padding. - * @type {number} - */ - FIELD_BORDER_RECT_X_PADDING: number; - /** - * A field's border rect Y padding. - * @type {number} - */ - FIELD_BORDER_RECT_Y_PADDING: number; - /** - * The backing colour of a field's border rect. - * @type {string} - * @package - */ - FIELD_BORDER_RECT_COLOUR: string; - /** - * A field's text element's dominant baseline. - * @type {boolean} - */ - FIELD_TEXT_BASELINE_CENTER: boolean; - /** - * A dropdown field's border rect height. - * @type {number} - */ - FIELD_DROPDOWN_BORDER_RECT_HEIGHT: number; - /** - * Whether or not a dropdown field should add a border rect when in a shadow - * block. - * @type {boolean} - */ - FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW: boolean; - /** - * Whether or not a dropdown field's div should be coloured to match the - * block colours. - * @type {boolean} - */ - FIELD_DROPDOWN_COLOURED_DIV: boolean; - /** - * Whether or not a dropdown field uses a text or SVG arrow. - * @type {boolean} - */ - FIELD_DROPDOWN_SVG_ARROW: boolean; - /** - * A dropdown field's SVG arrow padding. - * @type {number} - */ - FIELD_DROPDOWN_SVG_ARROW_PADDING: number; - /** - * A dropdown field's SVG arrow size. - * @type {number} - */ - FIELD_DROPDOWN_SVG_ARROW_SIZE: number; - /** - * A dropdown field's SVG arrow datauri. - * @type {string} - */ - FIELD_DROPDOWN_SVG_ARROW_DATAURI: string; - /** - * Whether or not to show a box shadow around the widget div. This is only a - * feature of full block fields. - * @type {boolean} - */ - FIELD_TEXTINPUT_BOX_SHADOW: boolean; - /** - * Whether or not the colour field should display its colour value on the - * entire block. - * @type {boolean} - */ - FIELD_COLOUR_FULL_BLOCK: boolean; - /** - * A colour field's default width. - * @type {number} - */ - FIELD_COLOUR_DEFAULT_WIDTH: number; - /** - * A colour field's default height. - * @type {number} - */ - FIELD_COLOUR_DEFAULT_HEIGHT: number; - /** - * A checkbox field's X offset. - * @type {number} - */ - FIELD_CHECKBOX_X_OFFSET: number; - /** - * A random identifier used to ensure a unique ID is used for each - * filter/pattern for the case of multiple Blockly instances on a page. - * @type {string} - * @package - */ - randomIdentifier: string; - /** - * The defs tag that contains all filters and patterns for this Blockly - * instance. - * @type {?SVGElement} - * @private - */ - private defs_; - /** - * The ID of the emboss filter, or the empty string if no filter is set. - * @type {string} - * @package - */ - embossFilterId: string; - /** - * The element to use for highlighting, or null if not set. - * @type {SVGElement} - * @private - */ - private embossFilter_; - /** - * The ID of the disabled pattern, or the empty string if no pattern is set. - * @type {string} - * @package - */ - disabledPatternId: string; - /** - * The element to use for disabled blocks, or null if not set. - * @type {SVGElement} - * @private - */ - private disabledPattern_; - /** - * The ID of the debug filter, or the empty string if no pattern is set. - * @type {string} - * @package - */ - debugFilterId: string; - /** - * The element to use for a debug highlight, or null if not set. - * @type {SVGElement} - * @private - */ - private debugFilter_; - /** - * The