diff --git a/core/block_svg.ts b/core/block_svg.ts index 1c1de49ec..10fa995ff 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -243,7 +243,7 @@ export class BlockSvg * * @returns #RRGGBB string. */ - getColourSecondary(): string | undefined { + getColourSecondary(): string { return this.style.colourSecondary; } @@ -252,7 +252,7 @@ export class BlockSvg * * @returns #RRGGBB string. */ - getColourTertiary(): string | undefined { + getColourTertiary(): string { return this.style.colourTertiary; } @@ -1172,6 +1172,15 @@ export class BlockSvg } } + /** + * Returns the BlockStyle object used to style this block. + * + * @returns This block's style object. + */ + getStyle(): BlockStyle { + return this.style; + } + /** * Move this block to the front of the visible workspace. * tags do not respect z-index so SVG renders them in the diff --git a/core/field_dropdown.ts b/core/field_dropdown.ts index b1e3b5af2..bc2d2856f 100644 --- a/core/field_dropdown.ts +++ b/core/field_dropdown.ts @@ -291,7 +291,7 @@ export class FieldDropdown extends Field { if (this.getConstants()!.FIELD_DROPDOWN_COLOURED_DIV) { const primaryColour = block.getColour(); - const borderColour = (this.sourceBlock_ as BlockSvg).style.colourTertiary; + const borderColour = (this.sourceBlock_ as BlockSvg).getColourTertiary(); dropDownDiv.setColour(primaryColour, borderColour); } @@ -467,21 +467,21 @@ export class FieldDropdown extends Field { * Updates the dropdown arrow to match the colour/style of the block. */ override applyColour() { - const style = (this.sourceBlock_ as BlockSvg).style; + const sourceBlock = this.sourceBlock_ as BlockSvg; if (this.borderRect_) { - this.borderRect_.setAttribute('stroke', style.colourTertiary); + this.borderRect_.setAttribute('stroke', sourceBlock.getColourTertiary()); if (this.menu_) { - this.borderRect_.setAttribute('fill', style.colourTertiary); + this.borderRect_.setAttribute('fill', sourceBlock.getColourTertiary()); } else { this.borderRect_.setAttribute('fill', 'transparent'); } } // Update arrow's colour. - if (this.sourceBlock_ && this.arrow) { - if (this.sourceBlock_.isShadow()) { - this.arrow.style.fill = style.colourSecondary; + if (sourceBlock && this.arrow) { + if (sourceBlock.isShadow()) { + this.arrow.style.fill = sourceBlock.getColourSecondary(); } else { - this.arrow.style.fill = style.colourPrimary; + this.arrow.style.fill = sourceBlock.getColour(); } } } diff --git a/core/field_input.ts b/core/field_input.ts index eecb4ec94..2c8a48e67 100644 --- a/core/field_input.ts +++ b/core/field_input.ts @@ -226,7 +226,7 @@ export abstract class FieldInput extends Field< if (!this.isFullBlockField() && this.borderRect_) { this.borderRect_!.style.display = 'block'; - this.borderRect_.setAttribute('stroke', block.style.colourTertiary); + this.borderRect_.setAttribute('stroke', block.getColourTertiary()); } else { this.borderRect_!.style.display = 'none'; // In general, do *not* let fields control the color of blocks. Having the @@ -429,8 +429,8 @@ export abstract class FieldInput extends Field< borderRadius = (bBox.bottom - bBox.top) / 2 + 'px'; // Pull stroke colour from the existing shadow block const strokeColour = block.getParent() - ? (block.getParent() as BlockSvg).style.colourTertiary - : (this.sourceBlock_ as BlockSvg).style.colourTertiary; + ? (block.getParent() as BlockSvg).getColourTertiary() + : (this.sourceBlock_ as BlockSvg).getColourTertiary(); htmlInput.style.border = 1 * scale + 'px solid ' + strokeColour; div!.style.borderRadius = borderRadius; div!.style.transition = 'box-shadow 0.25s ease 0s'; diff --git a/core/icons/comment_icon.ts b/core/icons/comment_icon.ts index ea120ca17..24a276d87 100644 --- a/core/icons/comment_icon.ts +++ b/core/icons/comment_icon.ts @@ -126,7 +126,7 @@ export class CommentIcon extends Icon implements IHasBubble, ISerializable { override applyColour(): void { super.applyColour(); - const colour = (this.sourceBlock as BlockSvg).style.colourPrimary; + const colour = (this.sourceBlock as BlockSvg).getColour(); this.textInputBubble?.setColour(colour); } diff --git a/core/icons/mutator_icon.ts b/core/icons/mutator_icon.ts index d02c7e187..eea533eab 100644 --- a/core/icons/mutator_icon.ts +++ b/core/icons/mutator_icon.ts @@ -136,7 +136,7 @@ export class MutatorIcon extends Icon implements IHasBubble { override applyColour(): void { super.applyColour(); - this.miniWorkspaceBubble?.setColour(this.sourceBlock.style.colourPrimary); + this.miniWorkspaceBubble?.setColour(this.sourceBlock.getColour()); this.miniWorkspaceBubble?.updateBlockStyles(); } diff --git a/core/icons/warning_icon.ts b/core/icons/warning_icon.ts index 2744195f9..b82ad1097 100644 --- a/core/icons/warning_icon.ts +++ b/core/icons/warning_icon.ts @@ -108,7 +108,7 @@ export class WarningIcon extends Icon implements IHasBubble { override applyColour(): void { super.applyColour(); - this.textBubble?.setColour(this.sourceBlock.style.colourPrimary); + this.textBubble?.setColour(this.sourceBlock.getColour()); } override updateCollapsed(): void { diff --git a/core/renderers/zelos/path_object.ts b/core/renderers/zelos/path_object.ts index 060190ee1..a46d355b6 100644 --- a/core/renderers/zelos/path_object.ts +++ b/core/renderers/zelos/path_object.ts @@ -68,7 +68,7 @@ export class PathObject extends BasePathObject { // Set shadow stroke colour. const parent = block.getParent(); if (block.isShadow() && parent) { - this.svgPath.setAttribute('stroke', parent.style.colourTertiary); + this.svgPath.setAttribute('stroke', parent.getColourTertiary()); } // Apply colour to outlines.