/** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * An object that provides constants for rendering blocks. * * @class */ import * as goog from '../../../closure/goog/goog.js'; goog.declareModuleId('Blockly.blockRendering.ConstantProvider'); import {ConnectionType} from '../../connection_type.js'; import type {RenderedConnection} from '../../rendered_connection.js'; import type {BlockStyle, Theme} from '../../theme.js'; import * as colour from '../../utils/colour.js'; import * as dom from '../../utils/dom.js'; import * as parsing from '../../utils/parsing.js'; import {Svg} from '../../utils/svg.js'; import * as svgPaths from '../../utils/svg_paths.js'; /** An object containing sizing and path information about outside corners. */ export interface OutsideCorners { topLeft: string; topRight: string; bottomRight: string; bottomLeft: string; rightHeight: number; } /** An object containing sizing and path information about inside corners. */ export interface InsideCorners { width: number; height: number; pathTop: string; pathBottom: string; } /** An object containing sizing and path information about a start hat. */ export interface StartHat { height: number; width: number; path: string; } /** An object containing sizing and path information about a notch. */ export interface Notch { type: number; width: number; height: number; pathLeft: string; pathRight: string; } /** An object containing sizing and path information about a puzzle tab. */ export interface PuzzleTab { type: number; width: number; height: number; pathDown: string|((p1: number) => string); pathUp: string|((p1: number) => string); } /** * An object containing sizing and path information about collapsed block * indicators. */ export interface JaggedTeeth { height: number; width: number; path: string; } export type BaseShape = { type: number; width: number; height: number; }; /** An object containing sizing and type information about a dynamic shape. */ export type DynamicShape = { type: number; width: (p1: number) => number; height: (p1: number) => number; isDynamic: true; connectionOffsetY: (p1: number) => number; connectionOffsetX: (p1: number) => number; pathDown: (p1: number) => string; pathUp: (p1: number) => string; pathRightDown: (p1: number) => string; pathRightUp: (p1: number) => string; }; /** An object containing sizing and type information about a shape. */ export type Shape = BaseShape|DynamicShape; /** * An object that provides constants for rendering blocks. * * @alias Blockly.blockRendering.ConstantProvider */ export class ConstantProvider { /** The size of an empty spacer. */ NO_PADDING = 0; /** The size of small padding. */ SMALL_PADDING = 3; /** The size of medium padding. */ MEDIUM_PADDING = 5; /** The size of medium-large padding. */ MEDIUM_LARGE_PADDING = 8; /** The size of large padding. */ LARGE_PADDING = 10; TALL_INPUT_FIELD_OFFSET_Y: number; /** The height of the puzzle tab used for input and output connections. */ TAB_HEIGHT = 15; /** * The offset from the top of the block at which a puzzle tab is positioned. */ TAB_OFFSET_FROM_TOP = 5; /** * Vertical overlap of the puzzle tab, used to make it look more like a * puzzle piece. */ TAB_VERTICAL_OVERLAP = 2.5; /** The width of the puzzle tab used for input and output connections. */ TAB_WIDTH = 8; /** The width of the notch used for previous and next connections. */ NOTCH_WIDTH = 15; /** The height of the notch used for previous and next connections. */ NOTCH_HEIGHT = 4; /** The minimum width of the block. */ MIN_BLOCK_WIDTH = 12; EMPTY_BLOCK_SPACER_HEIGHT = 16; DUMMY_INPUT_MIN_HEIGHT: number; DUMMY_INPUT_SHADOW_MIN_HEIGHT: number; /** Rounded corner radius. */ CORNER_RADIUS = 8; /** * Offset from the left side of a block or the inside of a statement input * to the left side of the notch. */ NOTCH_OFFSET_LEFT = 15; STATEMENT_INPUT_NOTCH_OFFSET: number; STATEMENT_BOTTOM_SPACER = 0; STATEMENT_INPUT_PADDING_LEFT = 20; /** Vertical padding between consecutive statement inputs. */ BETWEEN_STATEMENT_PADDING_Y = 4; TOP_ROW_MIN_HEIGHT: number; TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT: number; BOTTOM_ROW_MIN_HEIGHT: 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. */ ADD_START_HATS = false; /** Height of the top hat. */ START_HAT_HEIGHT = 15; /** Width of the top hat. */ START_HAT_WIDTH = 100; SPACER_DEFAULT_HEIGHT = 15; MIN_BLOCK_HEIGHT = 24; EMPTY_INLINE_INPUT_PADDING = 14.5; EMPTY_INLINE_INPUT_HEIGHT: number; EXTERNAL_VALUE_INPUT_PADDING = 2; EMPTY_STATEMENT_INPUT_HEIGHT: number; START_POINT: AnyDuringMigration; /** Height of SVG path for jagged teeth at the end of collapsed blocks. */ JAGGED_TEETH_HEIGHT = 12; /** Width of SVG path for jagged teeth at the end of collapsed blocks. */ JAGGED_TEETH_WIDTH = 6; /** Point size of text. */ FIELD_TEXT_FONTSIZE = 11; /** Text font weight. */ FIELD_TEXT_FONTWEIGHT = 'normal'; /** Text font family. */ FIELD_TEXT_FONTFAMILY = 'sans-serif'; /** * Height of text. This constant is dynamically set in * `setFontConstants_` to be the height of the text based on the font * used. */ FIELD_TEXT_HEIGHT = -1; // Dynamically set. /** * Text baseline. This constant is dynamically set in `setFontConstants_` * to be the baseline of the text based on the font used. */ FIELD_TEXT_BASELINE = -1; // Dynamically set. /** A field's border rect corner radius. */ FIELD_BORDER_RECT_RADIUS = 4; /** A field's border rect default height. */ FIELD_BORDER_RECT_HEIGHT = 16; /** A field's border rect X padding. */ FIELD_BORDER_RECT_X_PADDING = 5; /** A field's border rect Y padding. */ FIELD_BORDER_RECT_Y_PADDING = 3; /** * The backing colour of a field's border rect. * * @internal */ FIELD_BORDER_RECT_COLOUR = '#fff'; FIELD_TEXT_BASELINE_CENTER: boolean; FIELD_DROPDOWN_BORDER_RECT_HEIGHT: number; /** * Whether or not a dropdown field should add a border rect when in a shadow * block. */ FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW = false; /** * Whether or not a dropdown field's div should be coloured to match the * block colours. */ FIELD_DROPDOWN_COLOURED_DIV = false; /** Whether or not a dropdown field uses a text or SVG arrow. */ FIELD_DROPDOWN_SVG_ARROW = false; FIELD_DROPDOWN_SVG_ARROW_PADDING: number; /** A dropdown field's SVG arrow size. */ FIELD_DROPDOWN_SVG_ARROW_SIZE = 12; 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. */ FIELD_TEXTINPUT_BOX_SHADOW = false; /** * Whether or not the colour field should display its colour value on the * entire block. */ FIELD_COLOUR_FULL_BLOCK = false; /** A colour field's default width. */ FIELD_COLOUR_DEFAULT_WIDTH = 26; FIELD_COLOUR_DEFAULT_HEIGHT: number; FIELD_CHECKBOX_X_OFFSET: number; /** @internal */ randomIdentifier: string; /** * The defs tag that contains all filters and patterns for this Blockly * instance. */ private defs_: SVGElement|null = null; /** * The ID of the emboss filter, or the empty string if no filter is set. * * @internal */ embossFilterId = ''; /** The element to use for highlighting, or null if not set. */ // AnyDuringMigration because: Type 'null' is not assignable to type // 'SVGElement'. private embossFilter_: SVGElement = null as AnyDuringMigration; /** * The ID of the disabled pattern, or the empty string if no pattern is set. * * @internal */ disabledPatternId = ''; /** * The element to use for disabled blocks, or null if not set. */ // AnyDuringMigration because: Type 'null' is not assignable to type // 'SVGElement'. private disabledPattern_: SVGElement = null as AnyDuringMigration; /** * The ID of the debug filter, or the empty string if no pattern is set. */ debugFilterId = ''; /** * The element to use for a debug highlight, or null if not set. */ // AnyDuringMigration because: Type 'null' is not assignable to type // 'SVGElement'. private debugFilter_: SVGElement = null as AnyDuringMigration; /** The