scratch-blocks 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +140 -0
- package/commitlint.config.js +2 -2
- package/dist/main.mjs +1 -2
- package/dist/types/msg/scratch_msgs.d.ts.map +1 -1
- package/dist/types/src/block_reporting.d.ts.map +1 -1
- package/dist/types/src/blocks/colour.d.ts +0 -19
- package/dist/types/src/blocks/colour.d.ts.map +1 -1
- package/dist/types/src/blocks/control.d.ts +0 -19
- package/dist/types/src/blocks/control.d.ts.map +1 -1
- package/dist/types/src/blocks/data.d.ts +0 -19
- package/dist/types/src/blocks/data.d.ts.map +1 -1
- package/dist/types/src/blocks/event.d.ts +0 -19
- package/dist/types/src/blocks/event.d.ts.map +1 -1
- package/dist/types/src/blocks/looks.d.ts +0 -19
- package/dist/types/src/blocks/looks.d.ts.map +1 -1
- package/dist/types/src/blocks/math.d.ts +0 -19
- package/dist/types/src/blocks/math.d.ts.map +1 -1
- package/dist/types/src/blocks/matrix.d.ts +0 -19
- package/dist/types/src/blocks/matrix.d.ts.map +1 -1
- package/dist/types/src/blocks/motion.d.ts +0 -19
- package/dist/types/src/blocks/motion.d.ts.map +1 -1
- package/dist/types/src/blocks/note.d.ts +0 -19
- package/dist/types/src/blocks/note.d.ts.map +1 -1
- package/dist/types/src/blocks/operators.d.ts +0 -19
- package/dist/types/src/blocks/operators.d.ts.map +1 -1
- package/dist/types/src/blocks/procedures.d.ts +6 -9
- package/dist/types/src/blocks/procedures.d.ts.map +1 -1
- package/dist/types/src/blocks/sensing.d.ts +0 -19
- package/dist/types/src/blocks/sensing.d.ts.map +1 -1
- package/dist/types/src/blocks/sound.d.ts +0 -19
- package/dist/types/src/blocks/sound.d.ts.map +1 -1
- package/dist/types/src/blocks/text.d.ts +0 -19
- package/dist/types/src/blocks/text.d.ts.map +1 -1
- package/dist/types/src/blocks/vertical_extensions.d.ts +0 -19
- package/dist/types/src/blocks/vertical_extensions.d.ts.map +1 -1
- package/dist/types/src/checkable_continuous_flyout.d.ts +2 -7
- package/dist/types/src/checkable_continuous_flyout.d.ts.map +1 -1
- package/dist/types/src/checkbox_bubble.d.ts +13 -12
- package/dist/types/src/checkbox_bubble.d.ts.map +1 -1
- package/dist/types/src/colours.d.ts.map +1 -1
- package/dist/types/src/constants.d.ts +0 -7
- package/dist/types/src/constants.d.ts.map +1 -1
- package/dist/types/src/context_menu_items.d.ts +0 -5
- package/dist/types/src/context_menu_items.d.ts.map +1 -1
- package/dist/types/src/data_category.d.ts +2 -4
- package/dist/types/src/data_category.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_base.d.ts +2 -3
- package/dist/types/src/events/events_block_comment_base.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_change.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_change.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_collapse.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_collapse.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_create.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_create.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_delete.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_delete.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_move.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_move.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_resize.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_resize.d.ts.map +1 -1
- package/dist/types/src/events/events_block_drag_end.d.ts +1 -2
- package/dist/types/src/events/events_block_drag_end.d.ts.map +1 -1
- package/dist/types/src/events/events_block_drag_outside.d.ts +1 -2
- package/dist/types/src/events/events_block_drag_outside.d.ts.map +1 -1
- package/dist/types/src/events/events_scratch_variable_create.d.ts +0 -5
- package/dist/types/src/events/events_scratch_variable_create.d.ts.map +1 -1
- package/dist/types/src/fields/field_colour_slider.d.ts +7 -31
- package/dist/types/src/fields/field_colour_slider.d.ts.map +1 -1
- package/dist/types/src/fields/field_matrix.d.ts +0 -19
- package/dist/types/src/fields/field_matrix.d.ts.map +1 -1
- package/dist/types/src/fields/field_note.d.ts +8 -23
- package/dist/types/src/fields/field_note.d.ts.map +1 -1
- package/dist/types/src/fields/field_textinput_removable.d.ts +2 -4
- package/dist/types/src/fields/field_textinput_removable.d.ts.map +1 -1
- package/dist/types/src/fields/field_variable_getter.d.ts +0 -19
- package/dist/types/src/fields/field_variable_getter.d.ts.map +1 -1
- package/dist/types/src/fields/field_vertical_separator.d.ts +0 -19
- package/dist/types/src/fields/field_vertical_separator.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_angle.d.ts +0 -19
- package/dist/types/src/fields/scratch_field_angle.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_dropdown.d.ts +0 -5
- package/dist/types/src/fields/scratch_field_dropdown.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_number.d.ts +0 -19
- package/dist/types/src/fields/scratch_field_number.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_variable.d.ts +5 -8
- package/dist/types/src/fields/scratch_field_variable.d.ts.map +1 -1
- package/dist/types/src/flyout_checkbox_icon.d.ts +2 -3
- package/dist/types/src/flyout_checkbox_icon.d.ts.map +1 -1
- package/dist/types/src/glows.d.ts +1 -3
- package/dist/types/src/glows.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +50 -51
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/procedures.d.ts +6 -8
- package/dist/types/src/procedures.d.ts.map +1 -1
- package/dist/types/src/recyclable_block_flyout_inflater.d.ts +3 -5
- package/dist/types/src/recyclable_block_flyout_inflater.d.ts.map +1 -1
- package/dist/types/src/renderer/bowler_hat.d.ts +2 -3
- package/dist/types/src/renderer/bowler_hat.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/cat_face.d.ts +6 -5
- package/dist/types/src/renderer/cat/cat_face.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/constants.d.ts +2 -2
- package/dist/types/src/renderer/cat/constants.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/drawer.d.ts +4 -5
- package/dist/types/src/renderer/cat/drawer.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/path_object.d.ts +2 -3
- package/dist/types/src/renderer/cat/path_object.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/render_info.d.ts +3 -4
- package/dist/types/src/renderer/cat/render_info.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/renderer.d.ts +7 -8
- package/dist/types/src/renderer/cat/renderer.d.ts.map +1 -1
- package/dist/types/src/renderer/constants.d.ts +41 -0
- package/dist/types/src/renderer/constants.d.ts.map +1 -0
- package/dist/types/src/renderer/drawer.d.ts +7 -6
- package/dist/types/src/renderer/drawer.d.ts.map +1 -1
- package/dist/types/src/renderer/path_object.d.ts +1 -3
- package/dist/types/src/renderer/path_object.d.ts.map +1 -1
- package/dist/types/src/renderer/render_info.d.ts +3 -4
- package/dist/types/src/renderer/render_info.d.ts.map +1 -1
- package/dist/types/src/renderer/renderer.d.ts +9 -16
- package/dist/types/src/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/scratch_block_paster.d.ts +0 -5
- package/dist/types/src/scratch_block_paster.d.ts.map +1 -1
- package/dist/types/src/scratch_blocks_utils.d.ts +0 -20
- package/dist/types/src/scratch_blocks_utils.d.ts.map +1 -1
- package/dist/types/src/scratch_comment_bubble.d.ts +3 -6
- package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
- package/dist/types/src/scratch_comment_icon.d.ts +3 -4
- package/dist/types/src/scratch_comment_icon.d.ts.map +1 -1
- package/dist/types/src/scratch_connection_checker.d.ts +0 -5
- package/dist/types/src/scratch_connection_checker.d.ts.map +1 -1
- package/dist/types/src/scratch_continuous_category.d.ts +5 -5
- package/dist/types/src/scratch_continuous_category.d.ts.map +1 -1
- package/dist/types/src/scratch_continuous_toolbox.d.ts +3 -6
- package/dist/types/src/scratch_continuous_toolbox.d.ts.map +1 -1
- package/dist/types/src/scratch_dragger.d.ts +2 -11
- package/dist/types/src/scratch_dragger.d.ts.map +1 -1
- package/dist/types/src/scratch_insertion_marker_previewer.d.ts +0 -5
- package/dist/types/src/scratch_insertion_marker_previewer.d.ts.map +1 -1
- package/dist/types/src/scratch_variable_map.d.ts +0 -5
- package/dist/types/src/scratch_variable_map.d.ts.map +1 -1
- package/dist/types/src/scratch_variable_model.d.ts +2 -3
- package/dist/types/src/scratch_variable_model.d.ts.map +1 -1
- package/dist/types/src/scratch_zoom_controls.d.ts +4 -6
- package/dist/types/src/scratch_zoom_controls.d.ts.map +1 -1
- package/dist/types/src/shadows.d.ts +2 -2
- package/dist/types/src/shadows.d.ts.map +1 -1
- package/dist/types/src/status_indicator_label.d.ts +4 -6
- package/dist/types/src/status_indicator_label.d.ts.map +1 -1
- package/dist/types/src/status_indicator_label_flyout_inflater.d.ts +1 -6
- package/dist/types/src/status_indicator_label_flyout_inflater.d.ts.map +1 -1
- package/dist/types/src/variables.d.ts +4 -8
- package/dist/types/src/variables.d.ts.map +1 -1
- package/dist/types/src/xml.d.ts +2 -3
- package/dist/types/src/xml.d.ts.map +1 -1
- package/dist/types/tests/jsunit/block_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/connection_db_test.d.ts +3 -3
- package/dist/types/tests/jsunit/connection_db_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/connection_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/event_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/extensions_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_number_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_variable_getter_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_variable_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/gesture_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/input_test.d.ts +1 -0
- package/dist/types/tests/jsunit/input_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/json_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/names_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/procedure_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/svg_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/test_utilities.d.ts.map +1 -1
- package/dist/types/tests/jsunit/utils_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/variable_map_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/variable_model_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/widget_div_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/workspace_comment_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/workspace_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/xml_test.d.ts.map +1 -1
- package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts.map +1 -1
- package/eslint.config.mjs +69 -0
- package/i18n/create_scratch_msgs.js +44 -45
- package/i18n/js_to_json.js +40 -32
- package/i18n/json_to_js.js +37 -37
- package/i18n/sync_tx_translations.js +64 -65
- package/i18n/test_scratch_msgs.js +66 -63
- package/msg/js/en.js +289 -287
- package/msg/json/en.json +284 -284
- package/msg/messages.js +289 -287
- package/msg/scratch_msgs.js +22959 -22970
- package/package.json +13 -10
- package/prettier.config.mjs +3 -0
- package/release.config.js +7 -7
- package/renovate.json5 +7 -9
- package/src/block_reporting.ts +16 -19
- package/src/blocks/colour.ts +12 -15
- package/src/blocks/control.ts +171 -174
- package/src/blocks/data.ts +233 -272
- package/src/blocks/event.ts +121 -123
- package/src/blocks/looks.ts +165 -167
- package/src/blocks/math.ts +44 -46
- package/src/blocks/matrix.ts +11 -13
- package/src/blocks/motion.ts +151 -153
- package/src/blocks/note.ts +11 -13
- package/src/blocks/operators.ts +158 -160
- package/src/blocks/procedures.ts +421 -511
- package/src/blocks/sensing.ts +163 -165
- package/src/blocks/sound.ts +58 -60
- package/src/blocks/text.ts +10 -12
- package/src/blocks/vertical_extensions.ts +86 -102
- package/src/checkable_continuous_flyout.ts +25 -42
- package/src/checkbox_bubble.ts +83 -100
- package/src/colours.ts +35 -37
- package/src/constants.ts +22 -29
- package/src/context_menu_items.ts +59 -84
- package/src/css.ts +3 -4
- package/src/data_category.ts +137 -251
- package/src/events/events_block_comment_base.ts +23 -30
- package/src/events/events_block_comment_change.ts +21 -42
- package/src/events/events_block_comment_collapse.ts +27 -36
- package/src/events/events_block_comment_create.ts +32 -46
- package/src/events/events_block_comment_delete.ts +12 -19
- package/src/events/events_block_comment_move.ts +27 -52
- package/src/events/events_block_comment_resize.ts +28 -55
- package/src/events/events_block_drag_end.ts +16 -26
- package/src/events/events_block_drag_outside.ts +12 -22
- package/src/events/events_scratch_variable_create.ts +37 -42
- package/src/fields/field_colour_slider.ts +186 -216
- package/src/fields/field_matrix.ts +202 -270
- package/src/fields/field_note.ts +277 -375
- package/src/fields/field_textinput_removable.ts +25 -40
- package/src/fields/field_variable_getter.ts +26 -31
- package/src/fields/field_vertical_separator.ts +19 -24
- package/src/fields/scratch_field_angle.ts +151 -187
- package/src/fields/scratch_field_dropdown.ts +15 -19
- package/src/fields/scratch_field_number.ts +125 -181
- package/src/fields/scratch_field_variable.ts +57 -75
- package/src/flyout_checkbox_icon.ts +18 -28
- package/src/glows.ts +52 -59
- package/src/index.ts +119 -133
- package/src/procedures.ts +150 -209
- package/src/recyclable_block_flyout_inflater.ts +14 -25
- package/src/renderer/bowler_hat.ts +6 -8
- package/src/renderer/cat/cat_face.ts +98 -99
- package/src/renderer/cat/constants.ts +67 -87
- package/src/renderer/cat/drawer.ts +21 -27
- package/src/renderer/cat/path_object.ts +3 -5
- package/src/renderer/cat/render_info.ts +5 -8
- package/src/renderer/cat/renderer.ts +12 -16
- package/src/renderer/constants.ts +34 -49
- package/src/renderer/drawer.ts +35 -51
- package/src/renderer/path_object.ts +4 -10
- package/src/renderer/render_info.ts +39 -56
- package/src/renderer/renderer.ts +17 -30
- package/src/scratch_block_paster.ts +12 -20
- package/src/scratch_blocks_utils.ts +4 -7
- package/src/scratch_comment_bubble.ts +76 -105
- package/src/scratch_comment_icon.ts +75 -124
- package/src/scratch_connection_checker.ts +7 -17
- package/src/scratch_continuous_category.ts +24 -28
- package/src/scratch_continuous_toolbox.ts +20 -27
- package/src/scratch_dragger.ts +42 -81
- package/src/scratch_insertion_marker_previewer.ts +6 -11
- package/src/scratch_variable_map.ts +5 -12
- package/src/scratch_variable_model.ts +6 -13
- package/src/scratch_zoom_controls.ts +101 -156
- package/src/shadows.ts +32 -37
- package/src/status_indicator_label.ts +54 -67
- package/src/status_indicator_label_flyout_inflater.ts +11 -21
- package/src/variables.ts +92 -141
- package/src/xml.ts +21 -35
- package/tsconfig.json +3 -7
- package/types/continuous-toolbox.d.ts +1 -1
- package/dist/main.mjs.LICENSE.txt +0 -163
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2026 Scratch Foundation
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import { ConstantProvider } from "./constants";
|
|
10
|
-
import { CatScratchRenderer } from "./renderer";
|
|
5
|
+
import { RenderInfo as ClassicRenderInfo } from '../render_info'
|
|
6
|
+
import { ConstantProvider } from './constants'
|
|
7
|
+
import { CatScratchRenderer } from './renderer'
|
|
11
8
|
|
|
12
9
|
export class RenderInfo extends ClassicRenderInfo {
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
declare constants_: ConstantProvider
|
|
11
|
+
declare renderer_: CatScratchRenderer
|
|
15
12
|
}
|
|
@@ -1,34 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2026 Scratch Foundation
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import { Drawer } from "./drawer";
|
|
13
|
-
import { RenderInfo } from "./render_info";
|
|
14
|
-
import { PathObject } from "./path_object";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
6
|
+
import { ScratchRenderer } from '../renderer'
|
|
7
|
+
import { ConstantProvider } from './constants'
|
|
8
|
+
import { Drawer } from './drawer'
|
|
9
|
+
import { PathObject } from './path_object'
|
|
10
|
+
import { RenderInfo } from './render_info'
|
|
15
11
|
|
|
16
12
|
export class CatScratchRenderer extends ScratchRenderer {
|
|
17
13
|
override makeConstants_() {
|
|
18
|
-
return new ConstantProvider()
|
|
14
|
+
return new ConstantProvider()
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
override makeDrawer_(block: Blockly.BlockSvg, info: RenderInfo) {
|
|
22
|
-
return new Drawer(block, info)
|
|
17
|
+
override makeDrawer_(block: Blockly.BlockSvg, info: Blockly.blockRendering.RenderInfo) {
|
|
18
|
+
return new Drawer(block, info as RenderInfo)
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
override makeRenderInfo_(block: Blockly.BlockSvg): RenderInfo {
|
|
26
|
-
return new RenderInfo(this, block)
|
|
22
|
+
return new RenderInfo(this, block)
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
override makePathObject(root: SVGElement, style: Blockly.Theme.BlockStyle): PathObject {
|
|
30
|
-
return new PathObject(root, style, this.getConstants())
|
|
26
|
+
return new PathObject(root, style, this.getConstants())
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
Blockly.blockRendering.register(
|
|
30
|
+
Blockly.blockRendering.register('scratch_catblocks', CatScratchRenderer)
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2024 Google LLC
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
import * as Blockly from "blockly/core";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
8
6
|
|
|
9
7
|
export class ConstantProvider extends Blockly.zelos.ConstantProvider {
|
|
10
|
-
REPLACEMENT_GLOW_COLOUR =
|
|
11
|
-
SELECTED_GLOW_COLOUR =
|
|
8
|
+
REPLACEMENT_GLOW_COLOUR = '#ffffff'
|
|
9
|
+
SELECTED_GLOW_COLOUR = '#ffffff'
|
|
12
10
|
|
|
13
|
-
BOWLER_HAT_HEIGHT = 20
|
|
11
|
+
BOWLER_HAT_HEIGHT = 20
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
14
|
* Sets the visual theme used to render the workspace.
|
|
@@ -19,39 +17,26 @@ export class ConstantProvider extends Blockly.zelos.ConstantProvider {
|
|
|
19
17
|
* styles contain any raw color values, corresponding CSS variables will be
|
|
20
18
|
* created/overridden so that those colors can be dynamically referenced in
|
|
21
19
|
* stylesheets.
|
|
22
|
-
*
|
|
23
20
|
* @param theme The new theme to apply.
|
|
24
21
|
*/
|
|
25
22
|
override setTheme(theme: Blockly.Theme) {
|
|
26
|
-
const root = document.
|
|
23
|
+
const root = document.documentElement
|
|
27
24
|
for (const [key, colour] of Object.entries(theme.blockStyles)) {
|
|
28
|
-
if (typeof colour !==
|
|
29
|
-
const varKey = `--colour-${key}
|
|
30
|
-
root.style.setProperty(varKey, colour)
|
|
25
|
+
if (typeof colour !== 'object') {
|
|
26
|
+
const varKey = `--colour-${key}`
|
|
27
|
+
root.style.setProperty(varKey, colour)
|
|
31
28
|
} else {
|
|
32
29
|
const style = {
|
|
33
|
-
colourPrimary:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
: colour.colourTertiary,
|
|
41
|
-
colourTertiary:
|
|
42
|
-
"colourQuaternary" in colour
|
|
43
|
-
? `${colour.colourQuaternary}`
|
|
44
|
-
: colour.colourTertiary,
|
|
45
|
-
colourQuaternary:
|
|
46
|
-
"colourQuaternary" in colour
|
|
47
|
-
? `${colour.colourQuaternary}`
|
|
48
|
-
: colour.colourTertiary,
|
|
49
|
-
hat: "",
|
|
50
|
-
};
|
|
51
|
-
theme.setBlockStyle(`${key}_selected`, style);
|
|
30
|
+
colourPrimary: 'colourQuaternary' in colour ? `${colour.colourQuaternary}` : colour.colourTertiary,
|
|
31
|
+
colourSecondary: 'colourQuaternary' in colour ? `${colour.colourQuaternary}` : colour.colourTertiary,
|
|
32
|
+
colourTertiary: 'colourQuaternary' in colour ? `${colour.colourQuaternary}` : colour.colourTertiary,
|
|
33
|
+
colourQuaternary: 'colourQuaternary' in colour ? `${colour.colourQuaternary}` : colour.colourTertiary,
|
|
34
|
+
hat: '',
|
|
35
|
+
}
|
|
36
|
+
theme.setBlockStyle(`${key}_selected`, style)
|
|
52
37
|
}
|
|
53
38
|
}
|
|
54
|
-
super.setTheme(theme)
|
|
39
|
+
super.setTheme(theme)
|
|
55
40
|
}
|
|
56
41
|
|
|
57
42
|
/**
|
|
@@ -63,31 +48,33 @@ export class ConstantProvider extends Blockly.zelos.ConstantProvider {
|
|
|
63
48
|
* that input slots inside a Boolean reporter (like `<a = b>`) are still
|
|
64
49
|
* drawn with the rounded shape that matches what they accept, not the
|
|
65
50
|
* hexagonal shape of their parent block's output.
|
|
51
|
+
* @param connection The connection whose shape to determine.
|
|
52
|
+
* @returns The shape object for the given connection.
|
|
66
53
|
*/
|
|
67
|
-
override shapeFor(connection: Blockly.RenderedConnection) {
|
|
68
|
-
let checks = connection.getCheck()
|
|
54
|
+
override shapeFor(connection: Blockly.RenderedConnection): ReturnType<Blockly.zelos.ConstantProvider['shapeFor']> {
|
|
55
|
+
let checks = connection.getCheck()
|
|
69
56
|
if (!checks && connection.targetConnection) {
|
|
70
|
-
checks = connection.targetConnection.getCheck()
|
|
57
|
+
checks = connection.targetConnection.getCheck()
|
|
71
58
|
}
|
|
72
59
|
|
|
73
60
|
if (connection.type === Blockly.ConnectionType.OUTPUT_VALUE) {
|
|
74
|
-
const outputShape = connection.getSourceBlock().getOutputShape()
|
|
61
|
+
const outputShape = connection.getSourceBlock().getOutputShape()
|
|
75
62
|
if (outputShape !== null) {
|
|
76
63
|
switch (outputShape) {
|
|
77
64
|
case this.SHAPES.HEXAGONAL:
|
|
78
|
-
return this.HEXAGONAL
|
|
65
|
+
return this.HEXAGONAL!
|
|
79
66
|
case this.SHAPES.ROUND:
|
|
80
|
-
return this.ROUNDED
|
|
67
|
+
return this.ROUNDED!
|
|
81
68
|
case this.SHAPES.SQUARE:
|
|
82
|
-
return this.SQUARED
|
|
69
|
+
return this.SQUARED!
|
|
83
70
|
}
|
|
84
71
|
}
|
|
85
72
|
}
|
|
86
73
|
|
|
87
74
|
// For INPUT_VALUE (and OUTPUT_VALUE fallthrough), use connection checks.
|
|
88
|
-
if (checks?.includes(
|
|
89
|
-
if (checks?.includes(
|
|
90
|
-
if (checks?.includes(
|
|
75
|
+
if (checks?.includes('Boolean')) return this.HEXAGONAL!
|
|
76
|
+
if (checks?.includes('Number')) return this.ROUNDED!
|
|
77
|
+
if (checks?.includes('String')) return this.ROUNDED!
|
|
91
78
|
// For INPUT_VALUE or OUTPUT_VALUE with unrecognized checks, default to
|
|
92
79
|
// ROUNDED. Don't call super.shapeFor() here: the base implementation
|
|
93
80
|
// uses getSourceBlock().getOutputShape(), which would incorrectly return
|
|
@@ -96,14 +83,14 @@ export class ConstantProvider extends Blockly.zelos.ConstantProvider {
|
|
|
96
83
|
connection.type === Blockly.ConnectionType.INPUT_VALUE ||
|
|
97
84
|
connection.type === Blockly.ConnectionType.OUTPUT_VALUE
|
|
98
85
|
) {
|
|
99
|
-
return this.ROUNDED
|
|
86
|
+
return this.ROUNDED!
|
|
100
87
|
}
|
|
101
|
-
return super.shapeFor(connection)
|
|
88
|
+
return super.shapeFor(connection)
|
|
102
89
|
}
|
|
103
90
|
|
|
104
91
|
override createDom(svg: SVGElement, tagName: string, selector: string) {
|
|
105
|
-
super.createDom(svg, tagName, selector)
|
|
106
|
-
this.selectedGlowFilterId =
|
|
92
|
+
super.createDom(svg, tagName, selector)
|
|
93
|
+
this.selectedGlowFilterId = ''
|
|
107
94
|
}
|
|
108
95
|
|
|
109
96
|
/**
|
|
@@ -112,9 +99,7 @@ export class ConstantProvider extends Blockly.zelos.ConstantProvider {
|
|
|
112
99
|
* @returns The SVG path string for the bowler hat.
|
|
113
100
|
*/
|
|
114
101
|
makeBowlerHatPath(width: number): string {
|
|
115
|
-
const bowlerHatPath = `a20,20 0 0,1 20,-20 l ${
|
|
116
|
-
|
|
117
|
-
} 0 a20,20 0 0,1 20,20`;
|
|
118
|
-
return bowlerHatPath;
|
|
102
|
+
const bowlerHatPath = `a20,20 0 0,1 20,-20 l ${width - 40} 0 a20,20 0 0,1 20,20`
|
|
103
|
+
return bowlerHatPath
|
|
119
104
|
}
|
|
120
105
|
}
|
package/src/renderer/drawer.ts
CHANGED
|
@@ -1,46 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2024 Google LLC
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import type { RenderInfo } from
|
|
9
|
-
import { ConstantProvider } from "./constants";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
6
|
+
import { ConstantProvider } from './constants'
|
|
7
|
+
import type { RenderInfo } from './render_info'
|
|
10
8
|
|
|
11
9
|
export class Drawer extends Blockly.zelos.Drawer {
|
|
12
|
-
constants_: ConstantProvider
|
|
13
|
-
info_: RenderInfo
|
|
10
|
+
declare constants_: ConstantProvider
|
|
11
|
+
declare info_: RenderInfo
|
|
14
12
|
|
|
15
13
|
override drawStatementInput_(row: Blockly.blockRendering.Row) {
|
|
16
14
|
if (this.info_.isBowlerHatBlock()) {
|
|
17
15
|
// Bowler hat blocks have straight sides with no C-shape/indentation for
|
|
18
16
|
// statement blocks.
|
|
19
|
-
this.drawRightSideRow_(row)
|
|
20
|
-
this.positionStatementInputConnection_(row)
|
|
17
|
+
this.drawRightSideRow_(row)
|
|
18
|
+
this.positionStatementInputConnection_(row)
|
|
21
19
|
} else {
|
|
22
|
-
super.drawStatementInput_(row)
|
|
20
|
+
super.drawStatementInput_(row)
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
override drawRightSideRow_(row: Blockly.blockRendering.Row) {
|
|
27
|
-
if (
|
|
28
|
-
this.info_.isBowlerHatBlock() &&
|
|
29
|
-
Blockly.blockRendering.Types.isSpacer(row)
|
|
30
|
-
) {
|
|
25
|
+
if (this.info_.isBowlerHatBlock() && Blockly.blockRendering.Types.isSpacer(row)) {
|
|
31
26
|
// Multi-row bowler hat blocks are not supported, this may need
|
|
32
27
|
// adjustment to do so.
|
|
33
|
-
this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis(
|
|
34
|
-
"V",
|
|
35
|
-
row.yPos + row.height
|
|
36
|
-
);
|
|
28
|
+
this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('V', row.yPos + row.height)
|
|
37
29
|
} else {
|
|
38
|
-
super.drawRightSideRow_(row)
|
|
30
|
+
super.drawRightSideRow_(row)
|
|
39
31
|
}
|
|
40
32
|
}
|
|
41
33
|
|
|
42
34
|
override drawTop_() {
|
|
43
|
-
super.drawTop_()
|
|
35
|
+
super.drawTop_()
|
|
44
36
|
// This is a horrible hack, but the superclass' implementation of drawTop_()
|
|
45
37
|
// provides no way to cleanly override a hat's path without copying and
|
|
46
38
|
// pasting the entire implementation here. We know that there will only be
|
|
@@ -48,16 +40,16 @@ export class Drawer extends Blockly.zelos.Drawer {
|
|
|
48
40
|
// replace it with the desired bowler hat path here.
|
|
49
41
|
// If https://github.com/RaspberryPiFoundation/blockly/issues/7292 is
|
|
50
42
|
// resolved, this should be revisited.
|
|
51
|
-
const replacementTop = this.makeReplacementTop_()
|
|
43
|
+
const replacementTop = this.makeReplacementTop_()
|
|
52
44
|
if (replacementTop) {
|
|
53
|
-
const capHatPath = this.constants_.START_HAT.path
|
|
54
|
-
this.outlinePath_ = this.outlinePath_.replace(capHatPath, replacementTop)
|
|
45
|
+
const capHatPath = this.constants_.START_HAT.path
|
|
46
|
+
this.outlinePath_ = this.outlinePath_.replace(capHatPath, replacementTop)
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
49
|
|
|
58
50
|
makeReplacementTop_() {
|
|
59
51
|
if (this.info_.isBowlerHatBlock()) {
|
|
60
|
-
return this.constants_.makeBowlerHatPath(this.info_.width)
|
|
52
|
+
return this.constants_.makeBowlerHatPath(this.info_.width)
|
|
61
53
|
}
|
|
62
54
|
}
|
|
63
55
|
|
|
@@ -67,38 +59,30 @@ export class Drawer extends Blockly.zelos.Drawer {
|
|
|
67
59
|
* For rounded (non-hexagonal) input slots we expand the outline by 1px in
|
|
68
60
|
* every direction so the white highlight stroke sits just outside the input
|
|
69
61
|
* slot's background and remains visible rather than merging with it.
|
|
62
|
+
* @param measurable The connection measurable to highlight.
|
|
63
|
+
* @returns The highlight path element, if one was created.
|
|
70
64
|
*/
|
|
71
|
-
override drawConnectionHighlightPath(
|
|
72
|
-
measurable
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const xPos = input.connectionWidth - EXPAND_X;
|
|
83
|
-
const yPos = -input.height / 2 - EXPAND_Y;
|
|
84
|
-
const width = input.width - input.connectionWidth * 2 + 2 * EXPAND_X;
|
|
85
|
-
const height = input.height + 2 * EXPAND_Y;
|
|
86
|
-
const shape = input.shape as Blockly.blockRendering.DynamicShape;
|
|
65
|
+
override drawConnectionHighlightPath(measurable: Blockly.blockRendering.Connection) {
|
|
66
|
+
const conn = measurable.connectionModel
|
|
67
|
+
if (conn.type === Blockly.ConnectionType.INPUT_VALUE && measurable.isDynamicShape) {
|
|
68
|
+
const input = measurable as Blockly.blockRendering.InlineInput
|
|
69
|
+
const EXPAND_X = 0.5
|
|
70
|
+
const EXPAND_Y = 2
|
|
71
|
+
const xPos = input.connectionWidth - EXPAND_X
|
|
72
|
+
const yPos = -input.height / 2 - EXPAND_Y
|
|
73
|
+
const width = input.width - input.connectionWidth * 2 + 2 * EXPAND_X
|
|
74
|
+
const height = input.height + 2 * EXPAND_Y
|
|
75
|
+
const shape = input.shape as Blockly.blockRendering.DynamicShape
|
|
87
76
|
const path =
|
|
88
77
|
Blockly.utils.svgPaths.moveTo(xPos, yPos) +
|
|
89
|
-
Blockly.utils.svgPaths.lineOnAxis(
|
|
78
|
+
Blockly.utils.svgPaths.lineOnAxis('h', width) +
|
|
90
79
|
shape.pathRightDown(height) +
|
|
91
|
-
Blockly.utils.svgPaths.lineOnAxis(
|
|
80
|
+
Blockly.utils.svgPaths.lineOnAxis('h', -width) +
|
|
92
81
|
shape.pathUp(height) +
|
|
93
|
-
|
|
94
|
-
const block = conn.getSourceBlock()
|
|
95
|
-
return block.pathObject.addConnectionHighlight?.(
|
|
96
|
-
conn,
|
|
97
|
-
path,
|
|
98
|
-
conn.getOffsetInBlock(),
|
|
99
|
-
block.RTL
|
|
100
|
-
);
|
|
82
|
+
'z'
|
|
83
|
+
const block = conn.getSourceBlock()
|
|
84
|
+
return block.pathObject.addConnectionHighlight?.(conn, path, conn.getOffsetInBlock(), block.RTL)
|
|
101
85
|
}
|
|
102
|
-
return super.drawConnectionHighlightPath(measurable)
|
|
86
|
+
return super.drawConnectionHighlightPath(measurable)
|
|
103
87
|
}
|
|
104
88
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2024 Google LLC
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
import * as Blockly from "blockly/core";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* An object that handles creating and setting each of the SVG elements
|
|
@@ -14,22 +12,18 @@ export class PathObject extends Blockly.zelos.PathObject {
|
|
|
14
12
|
/**
|
|
15
13
|
* Apply the stored colours to the block's path, taking into account whether
|
|
16
14
|
* the paths belong to a shadow block.
|
|
17
|
-
*
|
|
18
15
|
* @param block The source block.
|
|
19
16
|
*/
|
|
20
17
|
override applyColour(block: Blockly.BlockSvg) {
|
|
21
|
-
super.applyColour(block)
|
|
18
|
+
super.applyColour(block)
|
|
22
19
|
|
|
23
20
|
// These blocks are special in that, while they are technically shadow
|
|
24
21
|
// blocks when contained in a procedure definition/prototype, their parent
|
|
25
22
|
// (the sample procedure caller block embedded in the definition block) is
|
|
26
23
|
// also a shadow, so they need to use normal block colors in order to
|
|
27
24
|
// provide contrast with it.
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
block.type === "argument_reporter_boolean"
|
|
31
|
-
) {
|
|
32
|
-
this.svgPath.setAttribute("fill", this.style.colourPrimary);
|
|
25
|
+
if (block.type === 'argument_reporter_string_number' || block.type === 'argument_reporter_boolean') {
|
|
26
|
+
this.svgPath.setAttribute('fill', this.style.colourPrimary)
|
|
33
27
|
}
|
|
34
28
|
}
|
|
35
29
|
}
|
|
@@ -1,118 +1,101 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2024 Google LLC
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import { BowlerHat } from "./bowler_hat";
|
|
10
|
-
import { ConstantProvider } from "./constants";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
6
|
+
import { BowlerHat } from './bowler_hat'
|
|
7
|
+
import { ConstantProvider } from './constants'
|
|
11
8
|
|
|
12
9
|
export class RenderInfo extends Blockly.zelos.RenderInfo {
|
|
13
|
-
constants_: ConstantProvider
|
|
10
|
+
declare constants_: ConstantProvider
|
|
14
11
|
|
|
15
12
|
override populateTopRow_() {
|
|
16
13
|
if (this.isBowlerHatBlock()) {
|
|
17
|
-
const bowlerHat = this.makeBowlerHat()
|
|
18
|
-
this.topRow.elements.push(
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
this.topRow.
|
|
22
|
-
this.topRow.
|
|
23
|
-
new Blockly.blockRendering.SquareCorner(this.constants_)
|
|
24
|
-
);
|
|
25
|
-
this.topRow.minHeight = 0;
|
|
26
|
-
this.topRow.capline = bowlerHat.ascenderHeight;
|
|
14
|
+
const bowlerHat = this.makeBowlerHat()
|
|
15
|
+
this.topRow.elements.push(new Blockly.blockRendering.SquareCorner(this.constants_))
|
|
16
|
+
this.topRow.elements.push(bowlerHat)
|
|
17
|
+
this.topRow.elements.push(new Blockly.blockRendering.SquareCorner(this.constants_))
|
|
18
|
+
this.topRow.minHeight = 0
|
|
19
|
+
this.topRow.capline = bowlerHat.ascenderHeight
|
|
27
20
|
} else {
|
|
28
|
-
super.populateTopRow_()
|
|
21
|
+
super.populateTopRow_()
|
|
29
22
|
}
|
|
30
23
|
}
|
|
31
24
|
|
|
32
25
|
override populateBottomRow_() {
|
|
33
|
-
super.populateBottomRow_()
|
|
26
|
+
super.populateBottomRow_()
|
|
34
27
|
if (this.isBowlerHatBlock()) {
|
|
35
|
-
this.bottomRow.minHeight = this.constants_.MEDIUM_PADDING
|
|
28
|
+
this.bottomRow.minHeight = this.constants_.MEDIUM_PADDING
|
|
36
29
|
}
|
|
37
30
|
}
|
|
38
31
|
|
|
39
32
|
override computeBounds_() {
|
|
40
|
-
super.computeBounds_()
|
|
33
|
+
super.computeBounds_()
|
|
41
34
|
if (this.isBowlerHatBlock()) {
|
|
42
35
|
// Resize the render info to the same width as the widest part of a
|
|
43
36
|
// bowler hat block.
|
|
44
|
-
|
|
37
|
+
// Bowler hat blocks always have exactly one statement row and one input
|
|
38
|
+
// element, so these find() calls are guaranteed to succeed.
|
|
39
|
+
const statementRow = this.rows.find(r => r.hasStatement)!
|
|
45
40
|
this.width =
|
|
46
41
|
statementRow.widthWithConnectedBlocks -
|
|
47
|
-
statementRow.elements.find((e)
|
|
48
|
-
|
|
49
|
-
).width +
|
|
50
|
-
this.constants_.MEDIUM_PADDING;
|
|
42
|
+
statementRow.elements.find(e => Blockly.blockRendering.Types.isInput(e))!.width +
|
|
43
|
+
this.constants_.MEDIUM_PADDING
|
|
51
44
|
|
|
52
45
|
// The bowler hat's width is the same as the block's width, so it can't
|
|
53
46
|
// be derived from the constants like a normal hat and has to be set here.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.topRow.measure();
|
|
47
|
+
// populateTopRow_ always adds a hat element for bowler hat blocks.
|
|
48
|
+
const hat = this.topRow.elements.find(e => Blockly.blockRendering.Types.isHat(e))!
|
|
49
|
+
hat.width = this.width
|
|
50
|
+
this.topRow.measure()
|
|
59
51
|
}
|
|
60
52
|
}
|
|
61
53
|
|
|
62
54
|
override getInRowSpacing_(
|
|
63
55
|
prev: Blockly.blockRendering.Measurable,
|
|
64
|
-
next: Blockly.blockRendering.Measurable
|
|
56
|
+
next: Blockly.blockRendering.Measurable,
|
|
65
57
|
): number {
|
|
66
58
|
if (
|
|
67
59
|
this.isBowlerHatBlock() &&
|
|
68
|
-
((prev && Blockly.blockRendering.Types.isHat(prev)) ||
|
|
69
|
-
(next && Blockly.blockRendering.Types.isHat(next)))
|
|
60
|
+
((prev && Blockly.blockRendering.Types.isHat(prev)) || (next && Blockly.blockRendering.Types.isHat(next)))
|
|
70
61
|
) {
|
|
71
62
|
// Bowler hat rows have no spacing/gaps, just the hat.
|
|
72
|
-
return 0
|
|
63
|
+
return 0
|
|
73
64
|
}
|
|
74
65
|
|
|
75
|
-
return super.getInRowSpacing_(prev, next)
|
|
66
|
+
return super.getInRowSpacing_(prev, next)
|
|
76
67
|
}
|
|
77
68
|
|
|
78
|
-
override getSpacerRowHeight_(
|
|
79
|
-
prev: Blockly.blockRendering.Row,
|
|
80
|
-
next: Blockly.blockRendering.Row
|
|
81
|
-
): number {
|
|
69
|
+
override getSpacerRowHeight_(prev: Blockly.blockRendering.Row, next: Blockly.blockRendering.Row): number {
|
|
82
70
|
if (this.isBowlerHatBlock() && prev === this.topRow) {
|
|
83
|
-
return 0
|
|
71
|
+
return 0
|
|
84
72
|
}
|
|
85
73
|
|
|
86
|
-
return super.getSpacerRowHeight_(prev, next)
|
|
74
|
+
return super.getSpacerRowHeight_(prev, next)
|
|
87
75
|
}
|
|
88
76
|
|
|
89
|
-
override getElemCenterline_(
|
|
90
|
-
row: Blockly.blockRendering.Row,
|
|
91
|
-
elem: Blockly.blockRendering.Measurable
|
|
92
|
-
): number {
|
|
77
|
+
override getElemCenterline_(row: Blockly.blockRendering.Row, elem: Blockly.blockRendering.Measurable): number {
|
|
93
78
|
if (this.isBowlerHatBlock() && Blockly.blockRendering.Types.isField(elem)) {
|
|
94
|
-
return row.yPos + row.height / 2
|
|
79
|
+
return row.yPos + row.height / 2
|
|
95
80
|
} else if (
|
|
96
|
-
|
|
81
|
+
'isScratchExtension' in this.block_ &&
|
|
97
82
|
this.block_.isScratchExtension &&
|
|
98
83
|
Blockly.blockRendering.Types.isField(elem) &&
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
(elem as Blockly.blockRendering.Field).field ===
|
|
102
|
-
this.block_.inputList[0].fieldRow[0] &&
|
|
84
|
+
elem.field instanceof Blockly.FieldImage &&
|
|
85
|
+
elem.field === this.block_.inputList[0].fieldRow[0] &&
|
|
103
86
|
this.block_.previousConnection
|
|
104
87
|
) {
|
|
105
88
|
// Vertically center the icon on extension blocks.
|
|
106
|
-
return super.getElemCenterline_(row, elem) + this.constants_.GRID_UNIT
|
|
89
|
+
return super.getElemCenterline_(row, elem) + this.constants_.GRID_UNIT
|
|
107
90
|
}
|
|
108
|
-
return super.getElemCenterline_(row, elem)
|
|
91
|
+
return super.getElemCenterline_(row, elem)
|
|
109
92
|
}
|
|
110
93
|
|
|
111
94
|
isBowlerHatBlock() {
|
|
112
|
-
return this.block_.hat ===
|
|
95
|
+
return this.block_.hat === 'bowler'
|
|
113
96
|
}
|
|
114
97
|
|
|
115
98
|
makeBowlerHat() {
|
|
116
|
-
return new BowlerHat(this.constants_)
|
|
99
|
+
return new BowlerHat(this.constants_)
|
|
117
100
|
}
|
|
118
101
|
}
|
package/src/renderer/renderer.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2024 Google LLC
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import { Drawer } from
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { PathObject } from "./path_object";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
6
|
+
import { ConstantProvider } from './constants'
|
|
7
|
+
import { Drawer } from './drawer'
|
|
8
|
+
import { PathObject } from './path_object'
|
|
9
|
+
import { RenderInfo } from './render_info'
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* Custom renderer for Scratch-style blocks.
|
|
@@ -17,69 +15,58 @@ export class ScratchRenderer extends Blockly.zelos.Renderer {
|
|
|
17
15
|
/**
|
|
18
16
|
* Get the CSS class name associated with this renderer.
|
|
19
17
|
* Note that all Scratch renderers share the same CSS class name.
|
|
20
|
-
*
|
|
21
|
-
* @returns The class name.
|
|
18
|
+
* @returns The CSS class name shared by all Scratch-style renderers.
|
|
22
19
|
*/
|
|
23
20
|
override getClassName(): string {
|
|
24
|
-
return
|
|
21
|
+
return 'scratch-renderer'
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
/**
|
|
28
25
|
* Create a new instance of the renderer's drawer.
|
|
29
|
-
*
|
|
30
26
|
* @param block The block to render.
|
|
31
|
-
* @param
|
|
27
|
+
* @param info An object containing all the information needed to render this
|
|
32
28
|
* block.
|
|
33
29
|
* @returns The drawer.
|
|
34
30
|
*/
|
|
35
|
-
override makeDrawer_(block: Blockly.BlockSvg, info: RenderInfo): Drawer {
|
|
36
|
-
return new Drawer(block, info)
|
|
31
|
+
override makeDrawer_(block: Blockly.BlockSvg, info: Blockly.blockRendering.RenderInfo): Drawer {
|
|
32
|
+
return new Drawer(block, info as RenderInfo)
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
/**
|
|
40
36
|
* Create a new instance of the renderer's render info object.
|
|
41
|
-
*
|
|
42
37
|
* @param block The block to measure.
|
|
43
38
|
* @returns The render info object.
|
|
44
39
|
*/
|
|
45
40
|
override makeRenderInfo_(block: Blockly.BlockSvg): RenderInfo {
|
|
46
|
-
return new RenderInfo(this, block)
|
|
41
|
+
return new RenderInfo(this, block)
|
|
47
42
|
}
|
|
48
43
|
|
|
49
44
|
/**
|
|
50
45
|
* Create a new instance of the renderer's constant provider.
|
|
51
|
-
*
|
|
52
46
|
* @returns The constant provider.
|
|
53
47
|
*/
|
|
54
48
|
override makeConstants_(): ConstantProvider {
|
|
55
|
-
return new ConstantProvider()
|
|
49
|
+
return new ConstantProvider()
|
|
56
50
|
}
|
|
57
51
|
|
|
58
52
|
/**
|
|
59
53
|
* Create a new instance of a renderer path object.
|
|
60
|
-
*
|
|
61
54
|
* @param root The root SVG element.
|
|
62
55
|
* @param style The style object to use for colouring.
|
|
63
|
-
* @returns
|
|
56
|
+
* @returns A new path object configured for the given SVG root and block style.
|
|
64
57
|
*/
|
|
65
|
-
override makePathObject(
|
|
66
|
-
root
|
|
67
|
-
style: Blockly.Theme.BlockStyle
|
|
68
|
-
): PathObject {
|
|
69
|
-
return new PathObject(root, style, this.getConstants());
|
|
58
|
+
override makePathObject(root: SVGElement, style: Blockly.Theme.BlockStyle): PathObject {
|
|
59
|
+
return new PathObject(root, style, this.getConstants())
|
|
70
60
|
}
|
|
71
61
|
|
|
72
62
|
/**
|
|
73
63
|
* Determine whether or not to highlight a connection.
|
|
74
|
-
*
|
|
75
64
|
* @param connection The connection to determine whether or not to highlight.
|
|
76
65
|
* @returns True if we should highlight the connection.
|
|
77
66
|
*/
|
|
78
67
|
override shouldHighlightConnection(connection: Blockly.RenderedConnection): boolean {
|
|
79
|
-
return
|
|
80
|
-
connection.type === Blockly.ConnectionType.INPUT_VALUE
|
|
81
|
-
);
|
|
68
|
+
return connection.type === Blockly.ConnectionType.INPUT_VALUE
|
|
82
69
|
}
|
|
83
70
|
}
|
|
84
71
|
|
|
85
|
-
Blockly.blockRendering.register(
|
|
72
|
+
Blockly.blockRendering.register('scratch_classic', ScratchRenderer)
|