Class: ConstantProvider

Constructor

ConstantProvider

new ConstantProvider()

An object that provides constants for rendering blocks.

Enumeration

SHAPES

number

Enum for connection shapes.

Value

PUZZLE

NOTCH

Properties

ADD_START_HATS

boolean

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.

BETWEEN_STATEMENT_PADDING_Y

number

Vertical padding between consecutive statement inputs.

blockStyles

package

Object with Blockly.Theme.BlockStyle properties

The block styles map.

BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT

number

The bottom row's minimum height if it follows a statement input.

BOTTOM_ROW_MIN_HEIGHT

number

The bottom row's minimum height.

CORNER_RADIUS

number

Rounded corner radius.

CURSOR_BLOCK_PADDING

package

number

Padding around a block.

CURSOR_COLOUR

package

string

Cursor colour.

CURSOR_STACK_PADDING

package

number

Padding around a stack.

CURSOR_STROKE_WIDTH

package

number

Stroke of the cursor.

CURSOR_WS_WIDTH

package

number

Width of the horizontal cursor.

debugFilterId

package

string

The ID of the debug filter, or the empty string if no pattern is set.

disabledPatternId

package

string

The ID of the disabled pattern, or the empty string if no pattern is set.

DUMMY_INPUT_MIN_HEIGHT

number

The minimum height of a dummy input row.

DUMMY_INPUT_SHADOW_MIN_HEIGHT

number

The minimum height of a dummy input row in a shadow block.

embossFilterId

package

string

The ID of the emboss filter, or the empty string if no filter is set.

EMPTY_INLINE_INPUT_HEIGHT

number

The height of an empty inline input.

EMPTY_STATEMENT_INPUT_HEIGHT

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.

FIELD_BORDER_RECT_COLOUR

package

string

The backing colour of a field's border rect.

FIELD_BORDER_RECT_HEIGHT

number

A field's border rect default height.

FIELD_BORDER_RECT_RADIUS

number

A field's border rect corner radius.

FIELD_BORDER_RECT_X_PADDING

number

A field's border rect X padding.

FIELD_BORDER_RECT_Y_PADDING

number

A field's border rect Y padding.

FIELD_CHECKBOX_X_OFFSET

number

A checkbox field's X offset.

FIELD_COLOUR_DEFAULT_HEIGHT

number

A colour field's default height.

FIELD_COLOUR_DEFAULT_WIDTH

number

A colour field's default width.

FIELD_COLOUR_FULL_BLOCK

boolean

Whether or not the colour field should display its colour value on the entire block.

FIELD_DROPDOWN_BORDER_RECT_HEIGHT

number

A dropdown field's border rect height.

FIELD_DROPDOWN_COLOURED_DIV

boolean

Whether or not a dropdown field's div should be coloured to match the block colours.

FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW

boolean

Whether or not a dropdown field should add a border rect when in a shadow block.

FIELD_DROPDOWN_SVG_ARROW

boolean

Whether or not a dropdown field uses a text or SVG arrow.

FIELD_DROPDOWN_SVG_ARROW_DATAURI

string

A dropdown field's SVG arrow datauri.

FIELD_DROPDOWN_SVG_ARROW_PADDING

number

A dropdown field's SVG arrow padding.

FIELD_DROPDOWN_SVG_ARROW_SIZE

number

A dropdown field's SVG arrow size.

FIELD_TEXT_BASELINE

number

Text baseline. This constant is dynamically set in setFontConstants_ to be the baseline of the text based on the font used.

FIELD_TEXT_BASELINE_CENTER

boolean

A field's text element's dominant baseline.

FIELD_TEXT_FONTFAMILY

string

Text font family.

FIELD_TEXT_FONTSIZE

number

Point size of text.

FIELD_TEXT_FONTWEIGHT

string

Text font weight.

FIELD_TEXT_HEIGHT

number

Height of text. This constant is dynamically set in setFontConstants_ to be the height of the text based on the font used.

FIELD_TEXTINPUT_BOX_SHADOW

boolean

Whether or not to show a box shadow around the widget div. This is only a feature of full block fields.

FULL_BLOCK_FIELDS

package

boolean

Whether text input and colour fields fill up the entire source block.

INSERTION_MARKER_COLOUR

package

string

The main colour of insertion markers, in hex. The block is rendered a transparent grey by changing the fill opacity in CSS.

INSERTION_MARKER_OPACITY

package

number

The insertion marker opacity.

INSIDE_CORNERS

non-null Object

An object containing sizing and path information about inside corners

JAGGED_TEETH

non-null Object

An object containing sizing and path information about collapsed block indicators.

JAGGED_TEETH_HEIGHT

number

Height of SVG path for jagged teeth at the end of collapsed blocks.

JAGGED_TEETH_WIDTH

number

Width of SVG path for jagged teeth at the end of collapsed blocks.

LARGE_PADDING

number

The size of large padding.

MARKER_COLOUR

package

string

Immovable marker colour.

MEDIUM_LARGE_PADDING

number

The size of medium-large padding.

MEDIUM_PADDING

number

The size of medium padding.

MIN_BLOCK_WIDTH

number

The minimum width of the block.

NO_PADDING

number

The size of an empty spacer.

NOTCH

non-null Object

An object containing sizing and path information about notches.

NOTCH_HEIGHT

number

The height of the notch used for previous and next connections.

NOTCH_OFFSET_LEFT

number

Offset from the left side of a block or the inside of a statement input to the left side of the notch.

NOTCH_WIDTH

number

The width of the notch used for previous and next connections.

OUTSIDE_CORNERS

non-null Object

An object containing sizing and path information about outside corners.

PUZZLE_TAB

non-null Object

An object containing sizing and path information about puzzle tabs.

randomIdentifier

package

string

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.

SHAPES

number

Enum for connection shapes.

Value

PUZZLE

NOTCH

SMALL_PADDING

number

The size of small padding.

START_HAT

non-null Object

An object containing sizing and path information about start hats

START_HAT_HEIGHT

number

Height of the top hat.

START_HAT_WIDTH

number

Width of the top hat.

STATEMENT_INPUT_NOTCH_OFFSET

number

Additional offset added to the statement input's width to account for the notch.

TAB_HEIGHT

number

The height of the puzzle tab used for input and output connections.

TAB_OFFSET_FROM_TOP

number

The offset from the top of the block at which a puzzle tab is positioned.

TAB_VERTICAL_OVERLAP

number

Vertical overlap of the puzzle tab, used to make it look more like a puzzle piece.

TAB_WIDTH

number

The width of the puzzle tab used for input and output connections.

TALL_INPUT_FIELD_OFFSET_Y

number

Offset from the top of the row for placing fields on inline input rows and statement input rows. Matches existing rendering (in 2019).

TOP_ROW_MIN_HEIGHT

number

The top row's minimum height.

TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT

number

The top row's minimum height if it precedes a statement.

WS_CURSOR_HEIGHT

package

number

Height of the horizontal cursor.

Methods

createBlockStyle_

protected

createBlockStyle_(colour) returns Blockly.Theme.BlockStyle

Create a block style object based on the given colour.

Parameter

colour

string

#RRGGBB colour string.

Returns

non-null Blockly.Theme.BlockStyle A populated block style based on the given colour.

createDom

package

createDom(svg, tagName, selector)

Create any DOM elements that this renderer needs (filters, patterns, etc).

Parameter

svg

SVGElement

The root of the workspace's SVG.

Value must not be null.

tagName

string

The name to use for the CSS style tag.

selector

string

The CSS selector to use.

dispose

package

dispose()

Dispose of this constants provider. Delete all DOM elements that this provider created.

generateSecondaryColour_

protected

generateSecondaryColour_(colour) returns string

Generate a secondary colour from the passed in primary colour.

Parameter

colour

string

Primary colour.

Returns

string The generated secondary colour.

generateTertiaryColour_

protected

generateTertiaryColour_(colour) returns string

Generate a tertiary colour from the passed in primary colour.

Parameter

colour

string

Primary colour.

Returns

string The generated tertiary colour.

getBlockStyle

getBlockStyle(blockStyleName) returns Blockly.Theme.BlockStyle

Gets the BlockStyle for the given block style name.

Parameter

blockStyleName

string

The name of the block style.

Value may be null.

Returns

non-null Blockly.Theme.BlockStyle The named block style, or a default style if no style with the given name was found.

getBlockStyleForColour

package

getBlockStyleForColour(colour) returns Object

Get or create a block style based on a single colour value. Generate a name for the style based on the colour.

Parameter

colour

string

#RRGGBB colour string.

Returns

{style: non-null Blockly.Theme.BlockStyle, name: string} An object containing the style and an autogenerated name for that style.

getCSS_

protected

getCSS_(selector) returns Array of string

Get any renderer specific CSS to inject when the renderer is initialized.

Parameter

selector

string

CSS selector to use.

Returns

non-null Array of string Array of CSS strings.

init

package

init()

Initialize shape objects based on the constants set in the constructor.

injectCSS_

protected

injectCSS_(tagName, selector)

Inject renderer specific CSS into the page.

Parameter

tagName

string

The name of the style tag to use.

selector

string

The CSS selector to use.

makeInsideCorners

package

makeInsideCorners() returns Object

Returns

non-null Object An object containing sizing and path information about inside corners.

makeJaggedTeeth

package

makeJaggedTeeth() returns Object

Returns

non-null Object An object containing sizing and path information about collapsed block indicators.

makeNotch

package

makeNotch() returns Object

Returns

non-null Object An object containing sizing and path information about notches.

makeOutsideCorners

package

makeOutsideCorners() returns Object

Returns

non-null Object An object containing sizing and path information about outside corners.

makePuzzleTab

package

makePuzzleTab() returns Object

Returns

non-null Object An object containing sizing and path information about puzzle tabs.

makeStartHat

package

makeStartHat() returns Object

Returns

non-null Object An object containing sizing and path information about start hats.

setComponentConstants_

protected

setComponentConstants_(theme)

Set constants from a theme's component styles.

Parameter

theme

Blockly.Theme

The current workspace theme.

Value must not be null.

setDynamicProperties_

protected

setDynamicProperties_(theme)

Sets dynamic properties that depend on other values or theme properties.

Parameter

theme

Blockly.Theme

The current workspace theme.

Value must not be null.

setFontConstants_

protected

setFontConstants_(theme)

Set constants related to fonts.

Parameter

theme

Blockly.Theme

The current workspace theme.

Value must not be null.

setTheme

package

setTheme(theme)

Refresh constants properties that depend on the theme.

Parameter

theme

Blockly.Theme

The current workspace theme.

Value must not be null.

shapeFor

package

shapeFor(connection) returns Object

Get an object with connection shape and sizing information based on the type of the connection.

Parameter

connection

Blockly.RenderedConnection

The connection to find a shape object for

Value must not be null.

Returns

non-null Object The shape object for the connection.

validatedBlockStyle_

protected

validatedBlockStyle_(blockStyle) returns Blockly.Theme.BlockStyle

Get a full block style object based on the input style object. Populate any missing values.

Parameter

blockStyle

{colourPrimary:string, colourSecondary: (string or undefined), colourTertiary: (string or undefined), hat: (string or undefined)}

A full or partial block style object.

Returns

non-null Blockly.Theme.BlockStyle A full block style object, with all required properties populated.