scratch-blocks 1.1.206 → 2.0.0-beta.1

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.
Files changed (1295) hide show
  1. package/.husky/commit-msg +0 -3
  2. package/CHANGELOG.md +111 -833
  3. package/TODO.md +16 -0
  4. package/blockly-rc/.eslintignore +28 -0
  5. package/blockly-rc/.eslintrc.js +187 -0
  6. package/blockly-rc/.gitattributes +1 -0
  7. package/blockly-rc/.github/CODEOWNERS +1 -0
  8. package/blockly-rc/.github/CONTRIBUTING.md +46 -0
  9. package/blockly-rc/.github/ISSUE_TEMPLATE/bug_report.yaml +58 -0
  10. package/blockly-rc/.github/ISSUE_TEMPLATE/config.yml +7 -0
  11. package/blockly-rc/.github/ISSUE_TEMPLATE/documentation.yaml +38 -0
  12. package/blockly-rc/.github/ISSUE_TEMPLATE/feature_request.yaml +39 -0
  13. package/blockly-rc/.github/PULL_REQUEST_TEMPLATE.md +42 -0
  14. package/blockly-rc/.github/dependabot.yml +27 -0
  15. package/blockly-rc/.github/release.yml +32 -0
  16. package/blockly-rc/.github/workflows/appengine_deploy.yml +54 -0
  17. package/blockly-rc/.github/workflows/assign_reviewers.yml +41 -0
  18. package/blockly-rc/.github/workflows/browser_test.yml +55 -0
  19. package/blockly-rc/.github/workflows/build.yml +86 -0
  20. package/blockly-rc/.github/workflows/conventional-label.yml +17 -0
  21. package/blockly-rc/.github/workflows/develop_freeze.yml +26 -0
  22. package/blockly-rc/.github/workflows/tag_module_cleanup.yml +37 -0
  23. package/blockly-rc/.github/workflows/welcome_new_contributors.yml +36 -0
  24. package/blockly-rc/.prettierignore +30 -0
  25. package/blockly-rc/.prettierrc.js +13 -0
  26. package/blockly-rc/CHANGELOG.md +77 -0
  27. package/blockly-rc/LICENSE +202 -0
  28. package/blockly-rc/README.md +80 -0
  29. package/blockly-rc/_config.yml +1 -0
  30. package/blockly-rc/api-extractor.json +385 -0
  31. package/blockly-rc/appengine/.gcloudignore +20 -0
  32. package/blockly-rc/appengine/README.txt +42 -0
  33. package/blockly-rc/appengine/add_timestamps.py +69 -0
  34. package/blockly-rc/appengine/app.yaml +104 -0
  35. package/blockly-rc/appengine/apple-touch-icon.png +0 -0
  36. package/blockly-rc/appengine/blockly_compressed.js +11 -0
  37. package/blockly-rc/appengine/expiration.py +52 -0
  38. package/blockly-rc/appengine/favicon.ico +0 -0
  39. package/blockly-rc/appengine/index.yaml +11 -0
  40. package/blockly-rc/appengine/main.py +39 -0
  41. package/blockly-rc/appengine/redirect.html +107 -0
  42. package/blockly-rc/appengine/requirements.txt +1 -0
  43. package/blockly-rc/appengine/robots.txt +2 -0
  44. package/blockly-rc/appengine/storage.js +190 -0
  45. package/blockly-rc/appengine/storage.py +125 -0
  46. package/blockly-rc/blocks/blocks.ts +44 -0
  47. package/blockly-rc/blocks/lists.ts +1085 -0
  48. package/blockly-rc/blocks/logic.ts +712 -0
  49. package/blockly-rc/blocks/loops.ts +408 -0
  50. package/blockly-rc/blocks/math.ts +591 -0
  51. package/blockly-rc/blocks/procedures.ts +1364 -0
  52. package/blockly-rc/blocks/text.ts +1007 -0
  53. package/blockly-rc/blocks/variables.ts +183 -0
  54. package/blockly-rc/blocks/variables_dynamic.ts +194 -0
  55. package/blockly-rc/core/any_aliases.ts +8 -0
  56. package/blockly-rc/core/block.ts +2523 -0
  57. package/blockly-rc/core/block_animations.ts +225 -0
  58. package/blockly-rc/core/block_flyout_inflater.ts +262 -0
  59. package/blockly-rc/core/block_svg.ts +1768 -0
  60. package/blockly-rc/core/blockly.ts +605 -0
  61. package/blockly-rc/core/blockly_options.ts +71 -0
  62. package/blockly-rc/core/blocks.ts +18 -0
  63. package/blockly-rc/core/browser_events.ts +244 -0
  64. package/blockly-rc/core/bubbles/bubble.ts +658 -0
  65. package/blockly-rc/core/bubbles/mini_workspace_bubble.ts +280 -0
  66. package/blockly-rc/core/bubbles/text_bubble.ts +103 -0
  67. package/blockly-rc/core/bubbles/textinput_bubble.ts +344 -0
  68. package/blockly-rc/core/bubbles.ts +12 -0
  69. package/blockly-rc/core/bump_objects.ts +192 -0
  70. package/blockly-rc/core/button_flyout_inflater.ts +63 -0
  71. package/blockly-rc/core/clipboard/block_paster.ts +142 -0
  72. package/blockly-rc/core/clipboard/registry.ts +31 -0
  73. package/blockly-rc/core/clipboard/workspace_comment_paster.ts +94 -0
  74. package/blockly-rc/core/clipboard.ts +113 -0
  75. package/blockly-rc/core/comments/comment_view.ts +899 -0
  76. package/blockly-rc/core/comments/rendered_workspace_comment.ts +297 -0
  77. package/blockly-rc/core/comments/workspace_comment.ts +237 -0
  78. package/blockly-rc/core/comments.ts +9 -0
  79. package/blockly-rc/core/common.ts +305 -0
  80. package/blockly-rc/core/component_manager.ts +235 -0
  81. package/blockly-rc/core/config.ts +65 -0
  82. package/blockly-rc/core/connection.ts +793 -0
  83. package/blockly-rc/core/connection_checker.ts +348 -0
  84. package/blockly-rc/core/connection_db.ts +297 -0
  85. package/blockly-rc/core/connection_type.ts +21 -0
  86. package/blockly-rc/core/constants.ts +23 -0
  87. package/blockly-rc/core/contextmenu.ts +268 -0
  88. package/blockly-rc/core/contextmenu_items.ts +700 -0
  89. package/blockly-rc/core/contextmenu_registry.ts +194 -0
  90. package/blockly-rc/core/css.ts +481 -0
  91. package/blockly-rc/core/delete_area.ts +77 -0
  92. package/blockly-rc/core/dialog.ts +121 -0
  93. package/blockly-rc/core/drag_target.ts +97 -0
  94. package/blockly-rc/core/dragging/block_drag_strategy.ts +454 -0
  95. package/blockly-rc/core/dragging/bubble_drag_strategy.ts +52 -0
  96. package/blockly-rc/core/dragging/comment_drag_strategy.ts +91 -0
  97. package/blockly-rc/core/dragging/dragger.ts +163 -0
  98. package/blockly-rc/core/dragging.ts +12 -0
  99. package/blockly-rc/core/dropdowndiv.ts +768 -0
  100. package/blockly-rc/core/events/events.ts +163 -0
  101. package/blockly-rc/core/events/events_abstract.ts +130 -0
  102. package/blockly-rc/core/events/events_block_base.ts +88 -0
  103. package/blockly-rc/core/events/events_block_change.ts +259 -0
  104. package/blockly-rc/core/events/events_block_create.ts +185 -0
  105. package/blockly-rc/core/events/events_block_delete.ts +182 -0
  106. package/blockly-rc/core/events/events_block_drag.ts +116 -0
  107. package/blockly-rc/core/events/events_block_field_intermediate_change.ts +167 -0
  108. package/blockly-rc/core/events/events_block_move.ts +307 -0
  109. package/blockly-rc/core/events/events_bubble_open.ts +120 -0
  110. package/blockly-rc/core/events/events_click.ts +110 -0
  111. package/blockly-rc/core/events/events_comment_base.ts +126 -0
  112. package/blockly-rc/core/events/events_comment_change.ts +161 -0
  113. package/blockly-rc/core/events/events_comment_collapse.ts +103 -0
  114. package/blockly-rc/core/events/events_comment_create.ts +118 -0
  115. package/blockly-rc/core/events/events_comment_delete.ts +117 -0
  116. package/blockly-rc/core/events/events_comment_drag.ts +99 -0
  117. package/blockly-rc/core/events/events_comment_move.ts +207 -0
  118. package/blockly-rc/core/events/events_comment_resize.ts +174 -0
  119. package/blockly-rc/core/events/events_marker_move.ts +134 -0
  120. package/blockly-rc/core/events/events_selected.ts +98 -0
  121. package/blockly-rc/core/events/events_theme_change.ts +84 -0
  122. package/blockly-rc/core/events/events_toolbox_item_select.ts +96 -0
  123. package/blockly-rc/core/events/events_trashcan_open.ts +88 -0
  124. package/blockly-rc/core/events/events_ui_base.ts +47 -0
  125. package/blockly-rc/core/events/events_var_base.ts +89 -0
  126. package/blockly-rc/core/events/events_var_create.ts +129 -0
  127. package/blockly-rc/core/events/events_var_delete.ts +124 -0
  128. package/blockly-rc/core/events/events_var_rename.ts +133 -0
  129. package/blockly-rc/core/events/events_var_type_change.ts +122 -0
  130. package/blockly-rc/core/events/events_viewport.ts +149 -0
  131. package/blockly-rc/core/events/utils.ts +595 -0
  132. package/blockly-rc/core/events/workspace_events.ts +46 -0
  133. package/blockly-rc/core/extensions.ts +491 -0
  134. package/blockly-rc/core/field.ts +1471 -0
  135. package/blockly-rc/core/field_checkbox.ts +271 -0
  136. package/blockly-rc/core/field_dropdown.ts +857 -0
  137. package/blockly-rc/core/field_image.ts +297 -0
  138. package/blockly-rc/core/field_input.ts +755 -0
  139. package/blockly-rc/core/field_label.ts +150 -0
  140. package/blockly-rc/core/field_label_serializable.ts +73 -0
  141. package/blockly-rc/core/field_number.ts +381 -0
  142. package/blockly-rc/core/field_registry.ts +115 -0
  143. package/blockly-rc/core/field_textinput.ts +117 -0
  144. package/blockly-rc/core/field_variable.ts +651 -0
  145. package/blockly-rc/core/flyout_base.ts +968 -0
  146. package/blockly-rc/core/flyout_button.ts +416 -0
  147. package/blockly-rc/core/flyout_horizontal.ts +374 -0
  148. package/blockly-rc/core/flyout_metrics_manager.ts +90 -0
  149. package/blockly-rc/core/flyout_separator.ts +61 -0
  150. package/blockly-rc/core/flyout_vertical.ts +353 -0
  151. package/blockly-rc/core/generator.ts +611 -0
  152. package/blockly-rc/core/gesture.ts +1191 -0
  153. package/blockly-rc/core/grid.ts +252 -0
  154. package/blockly-rc/core/icons/comment_icon.ts +435 -0
  155. package/blockly-rc/core/icons/exceptions.ts +23 -0
  156. package/blockly-rc/core/icons/icon.ts +147 -0
  157. package/blockly-rc/core/icons/icon_types.ts +32 -0
  158. package/blockly-rc/core/icons/mutator_icon.ts +354 -0
  159. package/blockly-rc/core/icons/registry.ts +33 -0
  160. package/blockly-rc/core/icons/warning_icon.ts +219 -0
  161. package/blockly-rc/core/icons.ts +24 -0
  162. package/blockly-rc/core/inject.ts +428 -0
  163. package/blockly-rc/core/inputs/align.ts +14 -0
  164. package/blockly-rc/core/inputs/dummy_input.ts +26 -0
  165. package/blockly-rc/core/inputs/end_row_input.ts +31 -0
  166. package/blockly-rc/core/inputs/input.ts +318 -0
  167. package/blockly-rc/core/inputs/input_types.ts +27 -0
  168. package/blockly-rc/core/inputs/statement_input.ts +34 -0
  169. package/blockly-rc/core/inputs/value_input.ts +30 -0
  170. package/blockly-rc/core/inputs.ts +23 -0
  171. package/blockly-rc/core/insertion_marker_manager.ts +742 -0
  172. package/blockly-rc/core/insertion_marker_previewer.ts +254 -0
  173. package/blockly-rc/core/interfaces/i_ast_node_location.ts +12 -0
  174. package/blockly-rc/core/interfaces/i_ast_node_location_svg.ts +28 -0
  175. package/blockly-rc/core/interfaces/i_ast_node_location_with_block.ts +22 -0
  176. package/blockly-rc/core/interfaces/i_autohideable.ts +22 -0
  177. package/blockly-rc/core/interfaces/i_bounded_element.ts +30 -0
  178. package/blockly-rc/core/interfaces/i_bubble.ts +63 -0
  179. package/blockly-rc/core/interfaces/i_collapsible_toolbox_item.ts +33 -0
  180. package/blockly-rc/core/interfaces/i_comment_icon.ts +47 -0
  181. package/blockly-rc/core/interfaces/i_component.ts +19 -0
  182. package/blockly-rc/core/interfaces/i_connection_checker.ts +100 -0
  183. package/blockly-rc/core/interfaces/i_connection_previewer.ts +50 -0
  184. package/blockly-rc/core/interfaces/i_contextmenu.ts +16 -0
  185. package/blockly-rc/core/interfaces/i_copyable.ts +31 -0
  186. package/blockly-rc/core/interfaces/i_deletable.ts +34 -0
  187. package/blockly-rc/core/interfaces/i_delete_area.ts +28 -0
  188. package/blockly-rc/core/interfaces/i_drag_target.ts +69 -0
  189. package/blockly-rc/core/interfaces/i_draggable.ts +72 -0
  190. package/blockly-rc/core/interfaces/i_dragger.ts +35 -0
  191. package/blockly-rc/core/interfaces/i_flyout.ts +189 -0
  192. package/blockly-rc/core/interfaces/i_flyout_inflater.ts +41 -0
  193. package/blockly-rc/core/interfaces/i_has_bubble.ts +20 -0
  194. package/blockly-rc/core/interfaces/i_icon.ts +114 -0
  195. package/blockly-rc/core/interfaces/i_keyboard_accessible.ts +21 -0
  196. package/blockly-rc/core/interfaces/i_legacy_procedure_blocks.ts +50 -0
  197. package/blockly-rc/core/interfaces/i_metrics_manager.ts +149 -0
  198. package/blockly-rc/core/interfaces/i_movable.ts +19 -0
  199. package/blockly-rc/core/interfaces/i_observable.ts +24 -0
  200. package/blockly-rc/core/interfaces/i_parameter_model.ts +51 -0
  201. package/blockly-rc/core/interfaces/i_paster.ts +25 -0
  202. package/blockly-rc/core/interfaces/i_positionable.ts +33 -0
  203. package/blockly-rc/core/interfaces/i_procedure_block.ts +27 -0
  204. package/blockly-rc/core/interfaces/i_procedure_map.ts +18 -0
  205. package/blockly-rc/core/interfaces/i_procedure_model.ts +71 -0
  206. package/blockly-rc/core/interfaces/i_registrable.ts +12 -0
  207. package/blockly-rc/core/interfaces/i_rendered_element.ts +22 -0
  208. package/blockly-rc/core/interfaces/i_selectable.ts +34 -0
  209. package/blockly-rc/core/interfaces/i_selectable_toolbox_item.ts +63 -0
  210. package/blockly-rc/core/interfaces/i_serializable.ts +28 -0
  211. package/blockly-rc/core/interfaces/i_serializer.ts +55 -0
  212. package/blockly-rc/core/interfaces/i_styleable.ts +26 -0
  213. package/blockly-rc/core/interfaces/i_toolbox.ts +112 -0
  214. package/blockly-rc/core/interfaces/i_toolbox_item.ts +81 -0
  215. package/blockly-rc/core/interfaces/i_variable_backed_parameter_model.ts +23 -0
  216. package/blockly-rc/core/interfaces/i_variable_map.ts +65 -0
  217. package/blockly-rc/core/interfaces/i_variable_model.ts +57 -0
  218. package/blockly-rc/core/internal_constants.ts +47 -0
  219. package/blockly-rc/core/keyboard_nav/ast_node.ts +884 -0
  220. package/blockly-rc/core/keyboard_nav/basic_cursor.ts +223 -0
  221. package/blockly-rc/core/keyboard_nav/cursor.ts +138 -0
  222. package/blockly-rc/core/keyboard_nav/marker.ts +113 -0
  223. package/blockly-rc/core/keyboard_nav/tab_navigate_cursor.ts +46 -0
  224. package/blockly-rc/core/label_flyout_inflater.ts +59 -0
  225. package/blockly-rc/core/layer_manager.ts +186 -0
  226. package/blockly-rc/core/layers.ts +17 -0
  227. package/blockly-rc/core/main.ts +31 -0
  228. package/blockly-rc/core/marker_manager.ts +189 -0
  229. package/blockly-rc/core/menu.ts +463 -0
  230. package/blockly-rc/core/menuitem.ts +221 -0
  231. package/blockly-rc/core/metrics_manager.ts +486 -0
  232. package/blockly-rc/core/msg.ts +27 -0
  233. package/blockly-rc/core/names.ts +275 -0
  234. package/blockly-rc/core/observable_procedure_map.ts +66 -0
  235. package/blockly-rc/core/options.ts +377 -0
  236. package/blockly-rc/core/positionable_helpers.ts +186 -0
  237. package/blockly-rc/core/procedures.ts +510 -0
  238. package/blockly-rc/core/registry.ts +400 -0
  239. package/blockly-rc/core/render_management.ts +193 -0
  240. package/blockly-rc/core/rendered_connection.ts +571 -0
  241. package/blockly-rc/core/renderers/common/block_rendering.ts +120 -0
  242. package/blockly-rc/core/renderers/common/constants.ts +1198 -0
  243. package/blockly-rc/core/renderers/common/drawer.ts +518 -0
  244. package/blockly-rc/core/renderers/common/i_path_object.ts +137 -0
  245. package/blockly-rc/core/renderers/common/info.ts +767 -0
  246. package/blockly-rc/core/renderers/common/marker_svg.ts +765 -0
  247. package/blockly-rc/core/renderers/common/path_object.ts +324 -0
  248. package/blockly-rc/core/renderers/common/renderer.ts +281 -0
  249. package/blockly-rc/core/renderers/geras/constants.ts +46 -0
  250. package/blockly-rc/core/renderers/geras/drawer.ts +167 -0
  251. package/blockly-rc/core/renderers/geras/geras.ts +31 -0
  252. package/blockly-rc/core/renderers/geras/highlight_constants.ts +342 -0
  253. package/blockly-rc/core/renderers/geras/highlighter.ts +313 -0
  254. package/blockly-rc/core/renderers/geras/info.ts +478 -0
  255. package/blockly-rc/core/renderers/geras/measurables/inline_input.ts +37 -0
  256. package/blockly-rc/core/renderers/geras/measurables/statement_input.ts +36 -0
  257. package/blockly-rc/core/renderers/geras/path_object.ts +135 -0
  258. package/blockly-rc/core/renderers/geras/renderer.ts +124 -0
  259. package/blockly-rc/core/renderers/measurables/base.ts +41 -0
  260. package/blockly-rc/core/renderers/measurables/bottom_row.ts +104 -0
  261. package/blockly-rc/core/renderers/measurables/connection.ts +43 -0
  262. package/blockly-rc/core/renderers/measurables/external_value_input.ts +53 -0
  263. package/blockly-rc/core/renderers/measurables/field.ts +50 -0
  264. package/blockly-rc/core/renderers/measurables/hat.ts +33 -0
  265. package/blockly-rc/core/renderers/measurables/icon.ts +42 -0
  266. package/blockly-rc/core/renderers/measurables/in_row_spacer.ts +29 -0
  267. package/blockly-rc/core/renderers/measurables/inline_input.ts +63 -0
  268. package/blockly-rc/core/renderers/measurables/input_connection.ts +57 -0
  269. package/blockly-rc/core/renderers/measurables/input_row.ts +67 -0
  270. package/blockly-rc/core/renderers/measurables/jagged_edge.ts +28 -0
  271. package/blockly-rc/core/renderers/measurables/next_connection.ts +34 -0
  272. package/blockly-rc/core/renderers/measurables/output_connection.ts +43 -0
  273. package/blockly-rc/core/renderers/measurables/previous_connection.ts +34 -0
  274. package/blockly-rc/core/renderers/measurables/round_corner.ts +34 -0
  275. package/blockly-rc/core/renderers/measurables/row.ts +191 -0
  276. package/blockly-rc/core/renderers/measurables/spacer_row.ts +44 -0
  277. package/blockly-rc/core/renderers/measurables/square_corner.ts +32 -0
  278. package/blockly-rc/core/renderers/measurables/statement_input.ts +41 -0
  279. package/blockly-rc/core/renderers/measurables/top_row.ts +110 -0
  280. package/blockly-rc/core/renderers/measurables/types.ts +319 -0
  281. package/blockly-rc/core/renderers/thrasos/info.ts +328 -0
  282. package/blockly-rc/core/renderers/thrasos/renderer.ts +40 -0
  283. package/blockly-rc/core/renderers/thrasos/thrasos.ts +14 -0
  284. package/blockly-rc/core/renderers/zelos/constants.ts +877 -0
  285. package/blockly-rc/core/renderers/zelos/drawer.ts +274 -0
  286. package/blockly-rc/core/renderers/zelos/info.ts +652 -0
  287. package/blockly-rc/core/renderers/zelos/marker_svg.ts +145 -0
  288. package/blockly-rc/core/renderers/zelos/measurables/bottom_row.ts +44 -0
  289. package/blockly-rc/core/renderers/zelos/measurables/inputs.ts +41 -0
  290. package/blockly-rc/core/renderers/zelos/measurables/row_elements.ts +29 -0
  291. package/blockly-rc/core/renderers/zelos/measurables/top_row.ts +50 -0
  292. package/blockly-rc/core/renderers/zelos/path_object.ts +209 -0
  293. package/blockly-rc/core/renderers/zelos/renderer.ts +143 -0
  294. package/blockly-rc/core/renderers/zelos/zelos.ts +33 -0
  295. package/blockly-rc/core/scrollbar.ts +898 -0
  296. package/blockly-rc/core/scrollbar_pair.ts +349 -0
  297. package/blockly-rc/core/separator_flyout_inflater.ts +69 -0
  298. package/blockly-rc/core/serialization/blocks.ts +868 -0
  299. package/blockly-rc/core/serialization/exceptions.ts +112 -0
  300. package/blockly-rc/core/serialization/priorities.ts +25 -0
  301. package/blockly-rc/core/serialization/procedures.ts +158 -0
  302. package/blockly-rc/core/serialization/registry.ts +30 -0
  303. package/blockly-rc/core/serialization/variables.ts +68 -0
  304. package/blockly-rc/core/serialization/workspace_comments.ts +143 -0
  305. package/blockly-rc/core/serialization/workspaces.ts +94 -0
  306. package/blockly-rc/core/serialization.ts +32 -0
  307. package/blockly-rc/core/shortcut_items.ts +338 -0
  308. package/blockly-rc/core/shortcut_registry.ts +368 -0
  309. package/blockly-rc/core/sprites.ts +15 -0
  310. package/blockly-rc/core/theme/classic.ts +40 -0
  311. package/blockly-rc/core/theme/themes.ts +12 -0
  312. package/blockly-rc/core/theme/zelos.ts +80 -0
  313. package/blockly-rc/core/theme.ts +232 -0
  314. package/blockly-rc/core/theme_manager.ts +192 -0
  315. package/blockly-rc/core/toolbox/category.ts +739 -0
  316. package/blockly-rc/core/toolbox/collapsible_category.ts +288 -0
  317. package/blockly-rc/core/toolbox/separator.ts +105 -0
  318. package/blockly-rc/core/toolbox/toolbox.ts +1134 -0
  319. package/blockly-rc/core/toolbox/toolbox_item.ts +152 -0
  320. package/blockly-rc/core/tooltip.ts +466 -0
  321. package/blockly-rc/core/touch.ts +155 -0
  322. package/blockly-rc/core/trashcan.ts +748 -0
  323. package/blockly-rc/core/utils/aria.ts +144 -0
  324. package/blockly-rc/core/utils/array.ts +24 -0
  325. package/blockly-rc/core/utils/colour.ts +265 -0
  326. package/blockly-rc/core/utils/coordinate.ts +129 -0
  327. package/blockly-rc/core/utils/deprecation.ts +47 -0
  328. package/blockly-rc/core/utils/dom.ts +356 -0
  329. package/blockly-rc/core/utils/idgenerator.ts +70 -0
  330. package/blockly-rc/core/utils/keycodes.ts +154 -0
  331. package/blockly-rc/core/utils/math.ts +50 -0
  332. package/blockly-rc/core/utils/metrics.ts +86 -0
  333. package/blockly-rc/core/utils/object.ts +28 -0
  334. package/blockly-rc/core/utils/parsing.ts +287 -0
  335. package/blockly-rc/core/utils/rect.ts +69 -0
  336. package/blockly-rc/core/utils/size.ts +62 -0
  337. package/blockly-rc/core/utils/string.ts +289 -0
  338. package/blockly-rc/core/utils/style.ts +219 -0
  339. package/blockly-rc/core/utils/svg.ts +84 -0
  340. package/blockly-rc/core/utils/svg_math.ts +208 -0
  341. package/blockly-rc/core/utils/svg_paths.ts +133 -0
  342. package/blockly-rc/core/utils/toolbox.ts +419 -0
  343. package/blockly-rc/core/utils/useragent.ts +86 -0
  344. package/blockly-rc/core/utils/xml.ts +165 -0
  345. package/blockly-rc/core/utils.ts +59 -0
  346. package/blockly-rc/core/variable_map.ts +437 -0
  347. package/blockly-rc/core/variable_model.ts +149 -0
  348. package/blockly-rc/core/variables.ts +773 -0
  349. package/blockly-rc/core/variables_dynamic.ts +142 -0
  350. package/blockly-rc/core/widgetdiv.ts +319 -0
  351. package/blockly-rc/core/workspace.ts +957 -0
  352. package/blockly-rc/core/workspace_audio.ts +171 -0
  353. package/blockly-rc/core/workspace_dragger.ts +97 -0
  354. package/blockly-rc/core/workspace_svg.ts +2519 -0
  355. package/blockly-rc/core/xml.ts +1133 -0
  356. package/blockly-rc/core/zoom_controls.ts +492 -0
  357. package/blockly-rc/demos/blockfactory/analytics.js +195 -0
  358. package/blockly-rc/demos/blockfactory/app_controller.js +726 -0
  359. package/blockly-rc/demos/blockfactory/block_definition_extractor.js +742 -0
  360. package/blockly-rc/demos/blockfactory/block_exporter_controller.js +311 -0
  361. package/blockly-rc/demos/blockfactory/block_exporter_tools.js +212 -0
  362. package/blockly-rc/demos/blockfactory/block_exporter_view.js +101 -0
  363. package/blockly-rc/demos/blockfactory/block_library_controller.js +325 -0
  364. package/blockly-rc/demos/blockfactory/block_library_storage.js +149 -0
  365. package/blockly-rc/demos/blockfactory/block_library_view.js +178 -0
  366. package/blockly-rc/demos/blockfactory/block_option.js +151 -0
  367. package/blockly-rc/demos/blockfactory/blocks.js +916 -0
  368. package/blockly-rc/demos/blockfactory/cp.css +46 -0
  369. package/blockly-rc/demos/blockfactory/cp.js +179 -0
  370. package/blockly-rc/demos/blockfactory/factory.css +586 -0
  371. package/blockly-rc/demos/blockfactory/factory.js +337 -0
  372. package/blockly-rc/demos/blockfactory/factory_utils.js +1036 -0
  373. package/blockly-rc/demos/blockfactory/icon.png +0 -0
  374. package/blockly-rc/demos/blockfactory/index.html +767 -0
  375. package/blockly-rc/demos/blockfactory/link.png +0 -0
  376. package/blockly-rc/demos/blockfactory/standard_categories.js +384 -0
  377. package/blockly-rc/demos/blockfactory/workspacefactory/wfactory_controller.js +1332 -0
  378. package/blockly-rc/demos/blockfactory/workspacefactory/wfactory_generator.js +224 -0
  379. package/blockly-rc/demos/blockfactory/workspacefactory/wfactory_init.js +541 -0
  380. package/blockly-rc/demos/blockfactory/workspacefactory/wfactory_model.js +548 -0
  381. package/blockly-rc/demos/blockfactory/workspacefactory/wfactory_view.js +424 -0
  382. package/blockly-rc/demos/code/code.js +626 -0
  383. package/blockly-rc/demos/code/icon.png +0 -0
  384. package/blockly-rc/demos/code/icons.png +0 -0
  385. package/blockly-rc/demos/code/index.html +359 -0
  386. package/blockly-rc/demos/code/msg/ar.js +24 -0
  387. package/blockly-rc/demos/code/msg/be-tarask.js +24 -0
  388. package/blockly-rc/demos/code/msg/br.js +24 -0
  389. package/blockly-rc/demos/code/msg/ca.js +24 -0
  390. package/blockly-rc/demos/code/msg/cs.js +24 -0
  391. package/blockly-rc/demos/code/msg/da.js +24 -0
  392. package/blockly-rc/demos/code/msg/de.js +24 -0
  393. package/blockly-rc/demos/code/msg/el.js +24 -0
  394. package/blockly-rc/demos/code/msg/en.js +24 -0
  395. package/blockly-rc/demos/code/msg/es.js +24 -0
  396. package/blockly-rc/demos/code/msg/et.js +24 -0
  397. package/blockly-rc/demos/code/msg/fa.js +24 -0
  398. package/blockly-rc/demos/code/msg/fr.js +24 -0
  399. package/blockly-rc/demos/code/msg/he.js +24 -0
  400. package/blockly-rc/demos/code/msg/hr.js +24 -0
  401. package/blockly-rc/demos/code/msg/hrx.js +24 -0
  402. package/blockly-rc/demos/code/msg/hu.js +24 -0
  403. package/blockly-rc/demos/code/msg/ia.js +24 -0
  404. package/blockly-rc/demos/code/msg/is.js +24 -0
  405. package/blockly-rc/demos/code/msg/it.js +24 -0
  406. package/blockly-rc/demos/code/msg/ja.js +24 -0
  407. package/blockly-rc/demos/code/msg/kab.js +24 -0
  408. package/blockly-rc/demos/code/msg/ko.js +24 -0
  409. package/blockly-rc/demos/code/msg/mk.js +24 -0
  410. package/blockly-rc/demos/code/msg/ms.js +24 -0
  411. package/blockly-rc/demos/code/msg/nb.js +24 -0
  412. package/blockly-rc/demos/code/msg/nl.js +24 -0
  413. package/blockly-rc/demos/code/msg/oc.js +24 -0
  414. package/blockly-rc/demos/code/msg/pl.js +24 -0
  415. package/blockly-rc/demos/code/msg/pms.js +24 -0
  416. package/blockly-rc/demos/code/msg/pt-br.js +24 -0
  417. package/blockly-rc/demos/code/msg/ro.js +24 -0
  418. package/blockly-rc/demos/code/msg/ru.js +24 -0
  419. package/blockly-rc/demos/code/msg/sc.js +24 -0
  420. package/blockly-rc/demos/code/msg/sk.js +24 -0
  421. package/blockly-rc/demos/code/msg/sr.js +24 -0
  422. package/blockly-rc/demos/code/msg/sv.js +24 -0
  423. package/blockly-rc/demos/code/msg/ta.js +24 -0
  424. package/blockly-rc/demos/code/msg/th.js +24 -0
  425. package/blockly-rc/demos/code/msg/tlh.js +24 -0
  426. package/blockly-rc/demos/code/msg/tr.js +24 -0
  427. package/blockly-rc/demos/code/msg/uk.js +24 -0
  428. package/blockly-rc/demos/code/msg/vi.js +24 -0
  429. package/blockly-rc/demos/code/msg/zh-hans.js +24 -0
  430. package/blockly-rc/demos/code/msg/zh-hant.js +24 -0
  431. package/blockly-rc/demos/code/style.css +184 -0
  432. package/blockly-rc/demos/index.html +68 -0
  433. package/blockly-rc/demos/minimap/icon.png +0 -0
  434. package/blockly-rc/demos/minimap/index.html +91 -0
  435. package/blockly-rc/demos/minimap/minimap.js +302 -0
  436. package/blockly-rc/demos/mobile/README.md +53 -0
  437. package/blockly-rc/demos/mobile/android/README.md +45 -0
  438. package/blockly-rc/demos/mobile/android/app/build.gradle +64 -0
  439. package/blockly-rc/demos/mobile/android/app/proguard-rules.pro +21 -0
  440. package/blockly-rc/demos/mobile/android/app/src/androidTest/java/com/example/blocklywebview/ExampleInstrumentedTest.java +26 -0
  441. package/blockly-rc/demos/mobile/android/app/src/main/AndroidManifest.xml +21 -0
  442. package/blockly-rc/demos/mobile/android/app/src/main/java/com/google/blockly/android/webview/BlocklyWebViewFragment.java +40 -0
  443. package/blockly-rc/demos/mobile/android/app/src/main/java/com/google/blockly/android/webview/JsDialogHelper.java +150 -0
  444. package/blockly-rc/demos/mobile/android/app/src/main/java/com/google/blockly/android/webview/WebChromeClient.java +32 -0
  445. package/blockly-rc/demos/mobile/android/app/src/main/java/com/google/blockly/android/webview/demo/MainActivity.java +18 -0
  446. package/blockly-rc/demos/mobile/android/app/src/main/res/drawable/ic_launcher_background.xml +74 -0
  447. package/blockly-rc/demos/mobile/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +34 -0
  448. package/blockly-rc/demos/mobile/android/app/src/main/res/layout/activity_main.xml +17 -0
  449. package/blockly-rc/demos/mobile/android/app/src/main/res/layout/js_prompt.xml +37 -0
  450. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +5 -0
  451. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +5 -0
  452. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  453. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  454. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  455. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  456. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  457. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  458. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  459. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  460. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  461. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  462. package/blockly-rc/demos/mobile/android/app/src/main/res/values/colors.xml +6 -0
  463. package/blockly-rc/demos/mobile/android/app/src/main/res/values/js_dialog_helper.xml +7 -0
  464. package/blockly-rc/demos/mobile/android/app/src/main/res/values/strings.xml +3 -0
  465. package/blockly-rc/demos/mobile/android/app/src/main/res/values/styles.xml +11 -0
  466. package/blockly-rc/demos/mobile/android/app/src/test/java/com/example/blocklywebview/ExampleUnitTest.java +17 -0
  467. package/blockly-rc/demos/mobile/android/build.gradle +27 -0
  468. package/blockly-rc/demos/mobile/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  469. package/blockly-rc/demos/mobile/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  470. package/blockly-rc/demos/mobile/android/gradle.properties +13 -0
  471. package/blockly-rc/demos/mobile/android/gradlew +172 -0
  472. package/blockly-rc/demos/mobile/android/gradlew.bat +84 -0
  473. package/blockly-rc/demos/mobile/android/settings.gradle +1 -0
  474. package/blockly-rc/demos/mobile/html/index.html +31 -0
  475. package/blockly-rc/demos/mobile/html/ln_resources.sh +22 -0
  476. package/blockly-rc/demos/mobile/html/toolbox_standard.js +333 -0
  477. package/blockly-rc/demos/mobile/ios/Blockly WebView/AppDelegate.swift +46 -0
  478. package/blockly-rc/demos/mobile/ios/Blockly WebView/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
  479. package/blockly-rc/demos/mobile/ios/Blockly WebView/Assets.xcassets/Contents.json +6 -0
  480. package/blockly-rc/demos/mobile/ios/Blockly WebView/Base.lproj/LaunchScreen.storyboard +25 -0
  481. package/blockly-rc/demos/mobile/ios/Blockly WebView/Base.lproj/Main.storyboard +44 -0
  482. package/blockly-rc/demos/mobile/ios/Blockly WebView/Info.plist +45 -0
  483. package/blockly-rc/demos/mobile/ios/Blockly WebView/ViewController.swift +110 -0
  484. package/blockly-rc/demos/mobile/ios/Blockly WebView.xcodeproj/project.pbxproj +390 -0
  485. package/blockly-rc/demos/mobile/ios/Blockly WebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  486. package/blockly-rc/demos/mobile/ios/Blockly WebView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  487. package/blockly-rc/demos/mobile/ios/cp_resources.sh +21 -0
  488. package/blockly-rc/demos/storage/icon.png +0 -0
  489. package/blockly-rc/demos/storage/index.html +104 -0
  490. package/blockly-rc/generators/dart/dart_generator.ts +321 -0
  491. package/blockly-rc/generators/dart/lists.ts +525 -0
  492. package/blockly-rc/generators/dart/logic.ts +155 -0
  493. package/blockly-rc/generators/dart/loops.ts +217 -0
  494. package/blockly-rc/generators/dart/math.ts +559 -0
  495. package/blockly-rc/generators/dart/procedures.ts +138 -0
  496. package/blockly-rc/generators/dart/text.ts +405 -0
  497. package/blockly-rc/generators/dart/variables.ts +32 -0
  498. package/blockly-rc/generators/dart/variables_dynamic.ts +17 -0
  499. package/blockly-rc/generators/dart.ts +50 -0
  500. package/blockly-rc/generators/javascript/javascript_generator.ts +346 -0
  501. package/blockly-rc/generators/javascript/lists.ts +465 -0
  502. package/blockly-rc/generators/javascript/logic.ts +153 -0
  503. package/blockly-rc/generators/javascript/loops.ts +245 -0
  504. package/blockly-rc/generators/javascript/math.ts +450 -0
  505. package/blockly-rc/generators/javascript/procedures.ts +142 -0
  506. package/blockly-rc/generators/javascript/text.ts +418 -0
  507. package/blockly-rc/generators/javascript/variables.ts +32 -0
  508. package/blockly-rc/generators/javascript/variables_dynamic.ts +17 -0
  509. package/blockly-rc/generators/javascript.ts +46 -0
  510. package/blockly-rc/generators/lua/lists.ts +445 -0
  511. package/blockly-rc/generators/lua/logic.ts +142 -0
  512. package/blockly-rc/generators/lua/loops.ts +192 -0
  513. package/blockly-rc/generators/lua/lua_generator.ts +225 -0
  514. package/blockly-rc/generators/lua/math.ts +473 -0
  515. package/blockly-rc/generators/lua/procedures.ts +144 -0
  516. package/blockly-rc/generators/lua/text.ts +380 -0
  517. package/blockly-rc/generators/lua/variables.ts +31 -0
  518. package/blockly-rc/generators/lua/variables_dynamic.ts +17 -0
  519. package/blockly-rc/generators/lua.ts +44 -0
  520. package/blockly-rc/generators/php/lists.ts +585 -0
  521. package/blockly-rc/generators/php/logic.ts +155 -0
  522. package/blockly-rc/generators/php/loops.ts +218 -0
  523. package/blockly-rc/generators/php/math.ts +408 -0
  524. package/blockly-rc/generators/php/php_generator.ts +320 -0
  525. package/blockly-rc/generators/php/procedures.ts +159 -0
  526. package/blockly-rc/generators/php/text.ts +315 -0
  527. package/blockly-rc/generators/php/variables.ts +32 -0
  528. package/blockly-rc/generators/php/variables_dynamic.ts +17 -0
  529. package/blockly-rc/generators/php.ts +46 -0
  530. package/blockly-rc/generators/python/lists.ts +398 -0
  531. package/blockly-rc/generators/python/logic.ts +148 -0
  532. package/blockly-rc/generators/python/loops.ts +251 -0
  533. package/blockly-rc/generators/python/math.ts +434 -0
  534. package/blockly-rc/generators/python/procedures.ts +159 -0
  535. package/blockly-rc/generators/python/python_generator.ts +355 -0
  536. package/blockly-rc/generators/python/text.ts +338 -0
  537. package/blockly-rc/generators/python/variables.ts +31 -0
  538. package/blockly-rc/generators/python/variables_dynamic.ts +17 -0
  539. package/blockly-rc/generators/python.ts +51 -0
  540. package/blockly-rc/gulpfile.js +54 -0
  541. package/blockly-rc/jsconfig.json +7 -0
  542. package/blockly-rc/media/1x1.gif +0 -0
  543. package/blockly-rc/media/click.mp3 +0 -0
  544. package/blockly-rc/media/click.ogg +0 -0
  545. package/blockly-rc/media/click.wav +0 -0
  546. package/blockly-rc/media/delete-icon.svg +1 -0
  547. package/blockly-rc/media/delete.mp3 +0 -0
  548. package/blockly-rc/media/delete.ogg +0 -0
  549. package/blockly-rc/media/delete.wav +0 -0
  550. package/blockly-rc/media/disconnect.mp3 +0 -0
  551. package/blockly-rc/media/disconnect.ogg +0 -0
  552. package/blockly-rc/media/disconnect.wav +0 -0
  553. package/blockly-rc/media/dropdown-arrow.svg +1 -0
  554. package/blockly-rc/media/foldout-icon.svg +1 -0
  555. package/blockly-rc/media/handclosed.cur +0 -0
  556. package/blockly-rc/media/handdelete.cur +0 -0
  557. package/blockly-rc/media/handopen.cur +0 -0
  558. package/blockly-rc/media/pilcrow.png +0 -0
  559. package/blockly-rc/media/quote0.png +0 -0
  560. package/blockly-rc/media/quote1.png +0 -0
  561. package/blockly-rc/media/resize-handle.svg +3 -0
  562. package/blockly-rc/media/sprites.png +0 -0
  563. package/blockly-rc/media/sprites.svg +74 -0
  564. package/blockly-rc/msg/json/README.md +33 -0
  565. package/blockly-rc/msg/json/ab.json +222 -0
  566. package/blockly-rc/msg/json/ace.json +7 -0
  567. package/blockly-rc/msg/json/af.json +34 -0
  568. package/blockly-rc/msg/json/am.json +30 -0
  569. package/blockly-rc/msg/json/ar.json +355 -0
  570. package/blockly-rc/msg/json/ast.json +10 -0
  571. package/blockly-rc/msg/json/az.json +332 -0
  572. package/blockly-rc/msg/json/ba.json +211 -0
  573. package/blockly-rc/msg/json/bcc.json +290 -0
  574. package/blockly-rc/msg/json/be-tarask.json +334 -0
  575. package/blockly-rc/msg/json/be.json +324 -0
  576. package/blockly-rc/msg/json/bg.json +345 -0
  577. package/blockly-rc/msg/json/bn.json +189 -0
  578. package/blockly-rc/msg/json/br.json +334 -0
  579. package/blockly-rc/msg/json/bs.json +166 -0
  580. package/blockly-rc/msg/json/ca.json +341 -0
  581. package/blockly-rc/msg/json/cdo.json +6 -0
  582. package/blockly-rc/msg/json/ce.json +326 -0
  583. package/blockly-rc/msg/json/constants.json +12 -0
  584. package/blockly-rc/msg/json/cs.json +343 -0
  585. package/blockly-rc/msg/json/da.json +346 -0
  586. package/blockly-rc/msg/json/de.json +369 -0
  587. package/blockly-rc/msg/json/diq.json +258 -0
  588. package/blockly-rc/msg/json/dtp.json +198 -0
  589. package/blockly-rc/msg/json/dty.json +97 -0
  590. package/blockly-rc/msg/json/ee.json +160 -0
  591. package/blockly-rc/msg/json/el.json +356 -0
  592. package/blockly-rc/msg/json/en-gb.json +199 -0
  593. package/blockly-rc/msg/json/en.json +400 -0
  594. package/blockly-rc/msg/json/eo.json +337 -0
  595. package/blockly-rc/msg/json/es.json +358 -0
  596. package/blockly-rc/msg/json/et.json +326 -0
  597. package/blockly-rc/msg/json/eu.json +219 -0
  598. package/blockly-rc/msg/json/fa.json +341 -0
  599. package/blockly-rc/msg/json/fi.json +350 -0
  600. package/blockly-rc/msg/json/fo.json +46 -0
  601. package/blockly-rc/msg/json/fr.json +373 -0
  602. package/blockly-rc/msg/json/frr.json +6 -0
  603. package/blockly-rc/msg/json/gl.json +338 -0
  604. package/blockly-rc/msg/json/gn.json +54 -0
  605. package/blockly-rc/msg/json/gor.json +87 -0
  606. package/blockly-rc/msg/json/ha.json +313 -0
  607. package/blockly-rc/msg/json/hak.json +17 -0
  608. package/blockly-rc/msg/json/he.json +354 -0
  609. package/blockly-rc/msg/json/hi.json +318 -0
  610. package/blockly-rc/msg/json/hr.json +327 -0
  611. package/blockly-rc/msg/json/hrx.json +287 -0
  612. package/blockly-rc/msg/json/hsb.json +128 -0
  613. package/blockly-rc/msg/json/hu.json +349 -0
  614. package/blockly-rc/msg/json/hy.json +337 -0
  615. package/blockly-rc/msg/json/ia.json +337 -0
  616. package/blockly-rc/msg/json/id.json +335 -0
  617. package/blockly-rc/msg/json/ig.json +323 -0
  618. package/blockly-rc/msg/json/inh.json +80 -0
  619. package/blockly-rc/msg/json/is.json +331 -0
  620. package/blockly-rc/msg/json/it.json +346 -0
  621. package/blockly-rc/msg/json/ja.json +361 -0
  622. package/blockly-rc/msg/json/ka.json +14 -0
  623. package/blockly-rc/msg/json/kab.json +323 -0
  624. package/blockly-rc/msg/json/kbd-cyrl.json +84 -0
  625. package/blockly-rc/msg/json/km.json +29 -0
  626. package/blockly-rc/msg/json/kn.json +332 -0
  627. package/blockly-rc/msg/json/ko.json +372 -0
  628. package/blockly-rc/msg/json/ksh.json +43 -0
  629. package/blockly-rc/msg/json/ku-latn.json +41 -0
  630. package/blockly-rc/msg/json/ky.json +71 -0
  631. package/blockly-rc/msg/json/la.json +6 -0
  632. package/blockly-rc/msg/json/lb.json +156 -0
  633. package/blockly-rc/msg/json/lki.json +282 -0
  634. package/blockly-rc/msg/json/lo.json +92 -0
  635. package/blockly-rc/msg/json/lrc.json +123 -0
  636. package/blockly-rc/msg/json/lt.json +321 -0
  637. package/blockly-rc/msg/json/lv.json +324 -0
  638. package/blockly-rc/msg/json/mg.json +58 -0
  639. package/blockly-rc/msg/json/mk.json +178 -0
  640. package/blockly-rc/msg/json/ml.json +35 -0
  641. package/blockly-rc/msg/json/mnw.json +90 -0
  642. package/blockly-rc/msg/json/ms.json +300 -0
  643. package/blockly-rc/msg/json/my.json +57 -0
  644. package/blockly-rc/msg/json/mzn.json +6 -0
  645. package/blockly-rc/msg/json/nb.json +330 -0
  646. package/blockly-rc/msg/json/ne.json +247 -0
  647. package/blockly-rc/msg/json/nl.json +357 -0
  648. package/blockly-rc/msg/json/oc.json +194 -0
  649. package/blockly-rc/msg/json/olo.json +37 -0
  650. package/blockly-rc/msg/json/pa.json +69 -0
  651. package/blockly-rc/msg/json/pl.json +357 -0
  652. package/blockly-rc/msg/json/pms.json +324 -0
  653. package/blockly-rc/msg/json/ps.json +50 -0
  654. package/blockly-rc/msg/json/pt-br.json +369 -0
  655. package/blockly-rc/msg/json/pt.json +358 -0
  656. package/blockly-rc/msg/json/qqq.json +406 -0
  657. package/blockly-rc/msg/json/ro.json +333 -0
  658. package/blockly-rc/msg/json/ru.json +363 -0
  659. package/blockly-rc/msg/json/sc.json +283 -0
  660. package/blockly-rc/msg/json/sco.json +11 -0
  661. package/blockly-rc/msg/json/sd.json +158 -0
  662. package/blockly-rc/msg/json/shn.json +109 -0
  663. package/blockly-rc/msg/json/si.json +16 -0
  664. package/blockly-rc/msg/json/sk.json +332 -0
  665. package/blockly-rc/msg/json/skr-arab.json +117 -0
  666. package/blockly-rc/msg/json/sl.json +355 -0
  667. package/blockly-rc/msg/json/smn.json +133 -0
  668. package/blockly-rc/msg/json/sq.json +343 -0
  669. package/blockly-rc/msg/json/sr-latn.json +324 -0
  670. package/blockly-rc/msg/json/sr.json +348 -0
  671. package/blockly-rc/msg/json/sv.json +347 -0
  672. package/blockly-rc/msg/json/sw.json +12 -0
  673. package/blockly-rc/msg/json/synonyms.json +22 -0
  674. package/blockly-rc/msg/json/ta.json +306 -0
  675. package/blockly-rc/msg/json/tcy.json +316 -0
  676. package/blockly-rc/msg/json/tdd.json +109 -0
  677. package/blockly-rc/msg/json/te.json +101 -0
  678. package/blockly-rc/msg/json/th.json +333 -0
  679. package/blockly-rc/msg/json/ti.json +50 -0
  680. package/blockly-rc/msg/json/tl.json +129 -0
  681. package/blockly-rc/msg/json/tlh.json +179 -0
  682. package/blockly-rc/msg/json/tr.json +369 -0
  683. package/blockly-rc/msg/json/ug-arab.json +132 -0
  684. package/blockly-rc/msg/json/uk.json +345 -0
  685. package/blockly-rc/msg/json/ur.json +117 -0
  686. package/blockly-rc/msg/json/uz.json +36 -0
  687. package/blockly-rc/msg/json/vi.json +345 -0
  688. package/blockly-rc/msg/json/xmf.json +96 -0
  689. package/blockly-rc/msg/json/yo.json +316 -0
  690. package/blockly-rc/msg/json/zgh.json +83 -0
  691. package/blockly-rc/msg/json/zh-hans.json +372 -0
  692. package/blockly-rc/msg/json/zh-hant.json +362 -0
  693. package/blockly-rc/msg/messages.js +1616 -0
  694. package/blockly-rc/package-lock.json +12324 -0
  695. package/blockly-rc/package.json +149 -0
  696. package/blockly-rc/patches/@microsoft+api-documenter+7.22.4.patch +81 -0
  697. package/blockly-rc/scripts/goog_module/convert-file.sh +406 -0
  698. package/blockly-rc/scripts/gulpfiles/appengine_tasks.js +195 -0
  699. package/blockly-rc/scripts/gulpfiles/build_tasks.js +752 -0
  700. package/blockly-rc/scripts/gulpfiles/config.js +41 -0
  701. package/blockly-rc/scripts/gulpfiles/docs_tasks.js +147 -0
  702. package/blockly-rc/scripts/gulpfiles/git_tasks.js +181 -0
  703. package/blockly-rc/scripts/gulpfiles/helper_tasks.js +19 -0
  704. package/blockly-rc/scripts/gulpfiles/package_tasks.js +262 -0
  705. package/blockly-rc/scripts/gulpfiles/release_tasks.js +183 -0
  706. package/blockly-rc/scripts/gulpfiles/test_tasks.js +405 -0
  707. package/blockly-rc/scripts/helpers.js +74 -0
  708. package/blockly-rc/scripts/i18n/common.py +233 -0
  709. package/blockly-rc/scripts/i18n/create_messages.py +167 -0
  710. package/blockly-rc/scripts/i18n/dedup_json.py +72 -0
  711. package/blockly-rc/scripts/i18n/js_to_json.py +135 -0
  712. package/blockly-rc/scripts/i18n/tests.py +46 -0
  713. package/blockly-rc/scripts/migration/cjs2esm +162 -0
  714. package/blockly-rc/scripts/migration/js2ts +168 -0
  715. package/blockly-rc/scripts/migration/renamings.json5 +1599 -0
  716. package/blockly-rc/scripts/package/README.md +93 -0
  717. package/blockly-rc/scripts/package/core-node.js +31 -0
  718. package/blockly-rc/scripts/package/index.js +23 -0
  719. package/blockly-rc/scripts/package/templates/umd-msg.template +16 -0
  720. package/blockly-rc/scripts/package/templates/umd.template +13 -0
  721. package/blockly-rc/scripts/themes/blockStyles_example.json +11 -0
  722. package/blockly-rc/scripts/themes/create_blockStyles.py +181 -0
  723. package/blockly-rc/scripts/tsick.js +86 -0
  724. package/blockly-rc/tests/.eslintrc.json +10 -0
  725. package/blockly-rc/tests/browser/.eslintrc.json +29 -0
  726. package/blockly-rc/tests/browser/.mocharc.js +6 -0
  727. package/blockly-rc/tests/browser/test/basic_block_factory_test.mjs +44 -0
  728. package/blockly-rc/tests/browser/test/basic_block_test.mjs +39 -0
  729. package/blockly-rc/tests/browser/test/basic_playground_test.mjs +198 -0
  730. package/blockly-rc/tests/browser/test/block_undo_test.mjs +50 -0
  731. package/blockly-rc/tests/browser/test/delete_blocks_test.mjs +211 -0
  732. package/blockly-rc/tests/browser/test/extensive_test.mjs +195 -0
  733. package/blockly-rc/tests/browser/test/field_edits_test.mjs +61 -0
  734. package/blockly-rc/tests/browser/test/hooks.mjs +23 -0
  735. package/blockly-rc/tests/browser/test/mutator_test.mjs +88 -0
  736. package/blockly-rc/tests/browser/test/procedure_test.mjs +109 -0
  737. package/blockly-rc/tests/browser/test/test_setup.mjs +589 -0
  738. package/blockly-rc/tests/browser/test/toolbox_drag_test.mjs +207 -0
  739. package/blockly-rc/tests/browser/test/workspace_comment_test.mjs +224 -0
  740. package/blockly-rc/tests/compile/index.html +43 -0
  741. package/blockly-rc/tests/compile/main.js +53 -0
  742. package/blockly-rc/tests/compile/test_blocks.js +47 -0
  743. package/blockly-rc/tests/compile/webdriver.js +81 -0
  744. package/blockly-rc/tests/generators/functions.xml +561 -0
  745. package/blockly-rc/tests/generators/golden/generated.dart +1604 -0
  746. package/blockly-rc/tests/generators/golden/generated.js +1552 -0
  747. package/blockly-rc/tests/generators/golden/generated.lua +1828 -0
  748. package/blockly-rc/tests/generators/golden/generated.php +1611 -0
  749. package/blockly-rc/tests/generators/golden/generated.py +1407 -0
  750. package/blockly-rc/tests/generators/index.html +405 -0
  751. package/blockly-rc/tests/generators/lists.xml +8675 -0
  752. package/blockly-rc/tests/generators/logic.xml +1019 -0
  753. package/blockly-rc/tests/generators/loops1.xml +345 -0
  754. package/blockly-rc/tests/generators/loops2.xml +891 -0
  755. package/blockly-rc/tests/generators/loops3.xml +735 -0
  756. package/blockly-rc/tests/generators/math.xml +2077 -0
  757. package/blockly-rc/tests/generators/text.xml +4651 -0
  758. package/blockly-rc/tests/generators/unittest.js +103 -0
  759. package/blockly-rc/tests/generators/unittest_dart.js +163 -0
  760. package/blockly-rc/tests/generators/unittest_javascript.js +167 -0
  761. package/blockly-rc/tests/generators/unittest_lua.js +165 -0
  762. package/blockly-rc/tests/generators/unittest_php.js +154 -0
  763. package/blockly-rc/tests/generators/unittest_python.js +138 -0
  764. package/blockly-rc/tests/generators/variables.xml +68 -0
  765. package/blockly-rc/tests/generators/webdriver.js +123 -0
  766. package/blockly-rc/tests/media/200px.png +0 -0
  767. package/blockly-rc/tests/media/30px.png +0 -0
  768. package/blockly-rc/tests/media/50px.png +0 -0
  769. package/blockly-rc/tests/media/a.png +0 -0
  770. package/blockly-rc/tests/media/arrow.png +0 -0
  771. package/blockly-rc/tests/media/b.png +0 -0
  772. package/blockly-rc/tests/media/c.png +0 -0
  773. package/blockly-rc/tests/media/d.png +0 -0
  774. package/blockly-rc/tests/media/e.png +0 -0
  775. package/blockly-rc/tests/media/f.png +0 -0
  776. package/blockly-rc/tests/media/g.png +0 -0
  777. package/blockly-rc/tests/media/h.png +0 -0
  778. package/blockly-rc/tests/media/i.png +0 -0
  779. package/blockly-rc/tests/media/j.png +0 -0
  780. package/blockly-rc/tests/media/k.png +0 -0
  781. package/blockly-rc/tests/media/l.png +0 -0
  782. package/blockly-rc/tests/media/m.png +0 -0
  783. package/blockly-rc/tests/migration/renamings.schema.json +59 -0
  784. package/blockly-rc/tests/migration/validate-renamings.mjs +60 -0
  785. package/blockly-rc/tests/mocha/.eslintrc.json +21 -0
  786. package/blockly-rc/tests/mocha/.mocharc.js +6 -0
  787. package/blockly-rc/tests/mocha/astnode_test.js +850 -0
  788. package/blockly-rc/tests/mocha/block_json_test.js +777 -0
  789. package/blockly-rc/tests/mocha/block_test.js +2743 -0
  790. package/blockly-rc/tests/mocha/blocks/lists_test.js +196 -0
  791. package/blockly-rc/tests/mocha/blocks/logic_ternary_test.js +320 -0
  792. package/blockly-rc/tests/mocha/blocks/loops_test.js +56 -0
  793. package/blockly-rc/tests/mocha/blocks/procedures_test.js +2495 -0
  794. package/blockly-rc/tests/mocha/blocks/variables_test.js +311 -0
  795. package/blockly-rc/tests/mocha/clipboard_test.js +136 -0
  796. package/blockly-rc/tests/mocha/comment_deserialization_test.js +122 -0
  797. package/blockly-rc/tests/mocha/comment_test.js +170 -0
  798. package/blockly-rc/tests/mocha/comment_view_test.js +188 -0
  799. package/blockly-rc/tests/mocha/connection_checker_test.js +666 -0
  800. package/blockly-rc/tests/mocha/connection_db_test.js +362 -0
  801. package/blockly-rc/tests/mocha/connection_test.js +3738 -0
  802. package/blockly-rc/tests/mocha/contextmenu_items_test.js +488 -0
  803. package/blockly-rc/tests/mocha/contextmenu_test.js +71 -0
  804. package/blockly-rc/tests/mocha/cursor_test.js +134 -0
  805. package/blockly-rc/tests/mocha/dropdowndiv_test.js +116 -0
  806. package/blockly-rc/tests/mocha/event_block_change_test.js +126 -0
  807. package/blockly-rc/tests/mocha/event_block_create_test.js +109 -0
  808. package/blockly-rc/tests/mocha/event_block_delete_test.js +55 -0
  809. package/blockly-rc/tests/mocha/event_block_drag_test.js +36 -0
  810. package/blockly-rc/tests/mocha/event_block_field_intermediate_change_test.js +67 -0
  811. package/blockly-rc/tests/mocha/event_block_move_test.js +39 -0
  812. package/blockly-rc/tests/mocha/event_bubble_open_test.js +42 -0
  813. package/blockly-rc/tests/mocha/event_click_test.js +40 -0
  814. package/blockly-rc/tests/mocha/event_comment_change_test.js +39 -0
  815. package/blockly-rc/tests/mocha/event_comment_collapse_test.js +34 -0
  816. package/blockly-rc/tests/mocha/event_comment_create_test.js +38 -0
  817. package/blockly-rc/tests/mocha/event_comment_delete_test.js +38 -0
  818. package/blockly-rc/tests/mocha/event_comment_drag_test.js +35 -0
  819. package/blockly-rc/tests/mocha/event_comment_move_test.js +40 -0
  820. package/blockly-rc/tests/mocha/event_comment_resize_test.js +38 -0
  821. package/blockly-rc/tests/mocha/event_marker_move_test.js +44 -0
  822. package/blockly-rc/tests/mocha/event_selected_test.js +41 -0
  823. package/blockly-rc/tests/mocha/event_test.js +1578 -0
  824. package/blockly-rc/tests/mocha/event_theme_change_test.js +36 -0
  825. package/blockly-rc/tests/mocha/event_toolbox_item_select_test.js +64 -0
  826. package/blockly-rc/tests/mocha/event_trashcan_open_test.js +36 -0
  827. package/blockly-rc/tests/mocha/event_var_create_test.js +54 -0
  828. package/blockly-rc/tests/mocha/event_var_delete_test.js +54 -0
  829. package/blockly-rc/tests/mocha/event_var_rename_test.js +39 -0
  830. package/blockly-rc/tests/mocha/event_var_type_change_test.js +43 -0
  831. package/blockly-rc/tests/mocha/event_viewport_test.js +39 -0
  832. package/blockly-rc/tests/mocha/extensions_test.js +613 -0
  833. package/blockly-rc/tests/mocha/field_checkbox_test.js +299 -0
  834. package/blockly-rc/tests/mocha/field_colour_test.js +395 -0
  835. package/blockly-rc/tests/mocha/field_dropdown_test.js +282 -0
  836. package/blockly-rc/tests/mocha/field_image_test.js +241 -0
  837. package/blockly-rc/tests/mocha/field_label_serializable_test.js +252 -0
  838. package/blockly-rc/tests/mocha/field_label_test.js +226 -0
  839. package/blockly-rc/tests/mocha/field_number_test.js +505 -0
  840. package/blockly-rc/tests/mocha/field_registry_test.js +116 -0
  841. package/blockly-rc/tests/mocha/field_test.js +822 -0
  842. package/blockly-rc/tests/mocha/field_textinput_test.js +297 -0
  843. package/blockly-rc/tests/mocha/field_variable_test.js +611 -0
  844. package/blockly-rc/tests/mocha/flyout_test.js +638 -0
  845. package/blockly-rc/tests/mocha/generator_test.js +233 -0
  846. package/blockly-rc/tests/mocha/gesture_test.js +97 -0
  847. package/blockly-rc/tests/mocha/icon_test.js +369 -0
  848. package/blockly-rc/tests/mocha/index.html +229 -0
  849. package/blockly-rc/tests/mocha/input_test.js +296 -0
  850. package/blockly-rc/tests/mocha/insertion_marker_manager_test.js +443 -0
  851. package/blockly-rc/tests/mocha/insertion_marker_test.js +432 -0
  852. package/blockly-rc/tests/mocha/jso_deserialization_test.js +849 -0
  853. package/blockly-rc/tests/mocha/jso_serialization_test.js +1067 -0
  854. package/blockly-rc/tests/mocha/json_test.js +315 -0
  855. package/blockly-rc/tests/mocha/keydown_test.js +364 -0
  856. package/blockly-rc/tests/mocha/layering_test.js +95 -0
  857. package/blockly-rc/tests/mocha/metrics_test.js +671 -0
  858. package/blockly-rc/tests/mocha/mutator_test.js +87 -0
  859. package/blockly-rc/tests/mocha/names_test.js +97 -0
  860. package/blockly-rc/tests/mocha/old_workspace_comment_test.js +256 -0
  861. package/blockly-rc/tests/mocha/procedure_map_test.js +57 -0
  862. package/blockly-rc/tests/mocha/registry_test.js +281 -0
  863. package/blockly-rc/tests/mocha/render_management_test.js +127 -0
  864. package/blockly-rc/tests/mocha/serializer_test.js +2104 -0
  865. package/blockly-rc/tests/mocha/shortcut_registry_test.js +450 -0
  866. package/blockly-rc/tests/mocha/test_helpers/block_definitions.js +204 -0
  867. package/blockly-rc/tests/mocha/test_helpers/code_generation.js +115 -0
  868. package/blockly-rc/tests/mocha/test_helpers/common.js +106 -0
  869. package/blockly-rc/tests/mocha/test_helpers/events.js +290 -0
  870. package/blockly-rc/tests/mocha/test_helpers/fields.js +310 -0
  871. package/blockly-rc/tests/mocha/test_helpers/icon_mocks.js +81 -0
  872. package/blockly-rc/tests/mocha/test_helpers/procedures.js +302 -0
  873. package/blockly-rc/tests/mocha/test_helpers/serialization.js +124 -0
  874. package/blockly-rc/tests/mocha/test_helpers/setup_teardown.js +209 -0
  875. package/blockly-rc/tests/mocha/test_helpers/toolbox_definitions.js +271 -0
  876. package/blockly-rc/tests/mocha/test_helpers/user_input.js +62 -0
  877. package/blockly-rc/tests/mocha/test_helpers/variables.js +23 -0
  878. package/blockly-rc/tests/mocha/test_helpers/warnings.js +83 -0
  879. package/blockly-rc/tests/mocha/test_helpers/workspace.js +1691 -0
  880. package/blockly-rc/tests/mocha/theme_test.js +307 -0
  881. package/blockly-rc/tests/mocha/toolbox_test.js +761 -0
  882. package/blockly-rc/tests/mocha/tooltip_test.js +276 -0
  883. package/blockly-rc/tests/mocha/touch_test.js +109 -0
  884. package/blockly-rc/tests/mocha/trashcan_test.js +375 -0
  885. package/blockly-rc/tests/mocha/utils_test.js +536 -0
  886. package/blockly-rc/tests/mocha/variable_map_test.js +509 -0
  887. package/blockly-rc/tests/mocha/variable_model_test.js +85 -0
  888. package/blockly-rc/tests/mocha/webdriver.js +96 -0
  889. package/blockly-rc/tests/mocha/widget_div_test.js +272 -0
  890. package/blockly-rc/tests/mocha/workspace_comment_test.js +171 -0
  891. package/blockly-rc/tests/mocha/workspace_svg_test.js +414 -0
  892. package/blockly-rc/tests/mocha/workspace_test.js +27 -0
  893. package/blockly-rc/tests/mocha/xml_test.js +951 -0
  894. package/blockly-rc/tests/mocha/zoom_controls_test.js +81 -0
  895. package/blockly-rc/tests/multi_playground.html +482 -0
  896. package/blockly-rc/tests/node/.eslintrc.json +12 -0
  897. package/blockly-rc/tests/node/.mocharc.js +6 -0
  898. package/blockly-rc/tests/node/run_node_test.mjs +72 -0
  899. package/blockly-rc/tests/playground.html +1280 -0
  900. package/blockly-rc/tests/playgrounds/advanced_playground.html +158 -0
  901. package/blockly-rc/tests/playgrounds/iframe.html +40 -0
  902. package/blockly-rc/tests/playgrounds/screenshot.js +123 -0
  903. package/blockly-rc/tests/scripts/check_metadata.sh +166 -0
  904. package/blockly-rc/tests/scripts/compile_typings.sh +32 -0
  905. package/blockly-rc/tests/scripts/load.mjs +140 -0
  906. package/blockly-rc/tests/scripts/setup_linux_env.sh +7 -0
  907. package/blockly-rc/tests/scripts/update_metadata.sh +46 -0
  908. package/blockly-rc/tests/themes/test_themes.js +62 -0
  909. package/blockly-rc/tests/typescript/README.md +4 -0
  910. package/blockly-rc/tests/typescript/src/field/different_user_input.ts +81 -0
  911. package/blockly-rc/tests/typescript/src/generators/dart.ts +24 -0
  912. package/blockly-rc/tests/typescript/src/generators/javascript.ts +28 -0
  913. package/blockly-rc/tests/typescript/src/generators/lua.ts +24 -0
  914. package/blockly-rc/tests/typescript/src/generators/php.ts +24 -0
  915. package/blockly-rc/tests/typescript/src/generators/python.ts +24 -0
  916. package/blockly-rc/tests/typescript/src/generators.ts +31 -0
  917. package/blockly-rc/tests/typescript/src/msg.ts +20 -0
  918. package/blockly-rc/tests/typescript/tsconfig.json +20 -0
  919. package/blockly-rc/tests/xml/README.txt +11 -0
  920. package/blockly-rc/tests/xml/blockly.xsd +178 -0
  921. package/blockly-rc/tests/xml/invalid.xml +6 -0
  922. package/blockly-rc/tests/xml/toolbox.xml +311 -0
  923. package/blockly-rc/tests/xml/workspace.xml +114 -0
  924. package/blockly-rc/tsconfig.json +37 -0
  925. package/blockly-rc/tsdoc.json +35 -0
  926. package/blockly-rc/typings/README.md +5 -0
  927. package/blockly-rc/typings/blocks.d.ts +17 -0
  928. package/blockly-rc/typings/core.d.ts +7 -0
  929. package/blockly-rc/typings/dart.d.ts +7 -0
  930. package/blockly-rc/typings/index.d.ts +10 -0
  931. package/blockly-rc/typings/javascript.d.ts +7 -0
  932. package/blockly-rc/typings/lua.d.ts +7 -0
  933. package/blockly-rc/typings/msg/ab.d.ts +8 -0
  934. package/blockly-rc/typings/msg/ace.d.ts +8 -0
  935. package/blockly-rc/typings/msg/af.d.ts +8 -0
  936. package/blockly-rc/typings/msg/am.d.ts +8 -0
  937. package/blockly-rc/typings/msg/ar.d.ts +8 -0
  938. package/blockly-rc/typings/msg/ast.d.ts +8 -0
  939. package/blockly-rc/typings/msg/az.d.ts +8 -0
  940. package/blockly-rc/typings/msg/ba.d.ts +8 -0
  941. package/blockly-rc/typings/msg/bcc.d.ts +8 -0
  942. package/blockly-rc/typings/msg/be-tarask.d.ts +8 -0
  943. package/blockly-rc/typings/msg/be.d.ts +8 -0
  944. package/blockly-rc/typings/msg/bg.d.ts +8 -0
  945. package/blockly-rc/typings/msg/bn.d.ts +8 -0
  946. package/blockly-rc/typings/msg/br.d.ts +8 -0
  947. package/blockly-rc/typings/msg/bs.d.ts +8 -0
  948. package/blockly-rc/typings/msg/ca.d.ts +8 -0
  949. package/blockly-rc/typings/msg/cdo.d.ts +8 -0
  950. package/blockly-rc/typings/msg/ce.d.ts +8 -0
  951. package/blockly-rc/typings/msg/cs.d.ts +8 -0
  952. package/blockly-rc/typings/msg/da.d.ts +8 -0
  953. package/blockly-rc/typings/msg/de.d.ts +8 -0
  954. package/blockly-rc/typings/msg/diq.d.ts +8 -0
  955. package/blockly-rc/typings/msg/dtp.d.ts +8 -0
  956. package/blockly-rc/typings/msg/dty.d.ts +8 -0
  957. package/blockly-rc/typings/msg/ee.d.ts +8 -0
  958. package/blockly-rc/typings/msg/el.d.ts +8 -0
  959. package/blockly-rc/typings/msg/en-gb.d.ts +8 -0
  960. package/blockly-rc/typings/msg/en.d.ts +8 -0
  961. package/blockly-rc/typings/msg/eo.d.ts +8 -0
  962. package/blockly-rc/typings/msg/es.d.ts +8 -0
  963. package/blockly-rc/typings/msg/et.d.ts +8 -0
  964. package/blockly-rc/typings/msg/eu.d.ts +8 -0
  965. package/blockly-rc/typings/msg/fa.d.ts +8 -0
  966. package/blockly-rc/typings/msg/fi.d.ts +8 -0
  967. package/blockly-rc/typings/msg/fo.d.ts +8 -0
  968. package/blockly-rc/typings/msg/fr.d.ts +8 -0
  969. package/blockly-rc/typings/msg/frr.d.ts +8 -0
  970. package/blockly-rc/typings/msg/gl.d.ts +8 -0
  971. package/blockly-rc/typings/msg/gn.d.ts +8 -0
  972. package/blockly-rc/typings/msg/gor.d.ts +8 -0
  973. package/blockly-rc/typings/msg/ha.d.ts +8 -0
  974. package/blockly-rc/typings/msg/hak.d.ts +8 -0
  975. package/blockly-rc/typings/msg/he.d.ts +8 -0
  976. package/blockly-rc/typings/msg/hi.d.ts +8 -0
  977. package/blockly-rc/typings/msg/hr.d.ts +8 -0
  978. package/blockly-rc/typings/msg/hrx.d.ts +8 -0
  979. package/blockly-rc/typings/msg/hsb.d.ts +8 -0
  980. package/blockly-rc/typings/msg/hu.d.ts +8 -0
  981. package/blockly-rc/typings/msg/hy.d.ts +8 -0
  982. package/blockly-rc/typings/msg/ia.d.ts +8 -0
  983. package/blockly-rc/typings/msg/id.d.ts +8 -0
  984. package/blockly-rc/typings/msg/ig.d.ts +8 -0
  985. package/blockly-rc/typings/msg/inh.d.ts +8 -0
  986. package/blockly-rc/typings/msg/is.d.ts +8 -0
  987. package/blockly-rc/typings/msg/it.d.ts +8 -0
  988. package/blockly-rc/typings/msg/ja.d.ts +8 -0
  989. package/blockly-rc/typings/msg/ka.d.ts +8 -0
  990. package/blockly-rc/typings/msg/kab.d.ts +8 -0
  991. package/blockly-rc/typings/msg/kbd-cyrl.d.ts +8 -0
  992. package/blockly-rc/typings/msg/km.d.ts +8 -0
  993. package/blockly-rc/typings/msg/kn.d.ts +8 -0
  994. package/blockly-rc/typings/msg/ko.d.ts +8 -0
  995. package/blockly-rc/typings/msg/ksh.d.ts +8 -0
  996. package/blockly-rc/typings/msg/ku-latn.d.ts +8 -0
  997. package/blockly-rc/typings/msg/ky.d.ts +8 -0
  998. package/blockly-rc/typings/msg/la.d.ts +8 -0
  999. package/blockly-rc/typings/msg/lb.d.ts +8 -0
  1000. package/blockly-rc/typings/msg/lki.d.ts +8 -0
  1001. package/blockly-rc/typings/msg/lo.d.ts +8 -0
  1002. package/blockly-rc/typings/msg/lrc.d.ts +8 -0
  1003. package/blockly-rc/typings/msg/lt.d.ts +8 -0
  1004. package/blockly-rc/typings/msg/lv.d.ts +8 -0
  1005. package/blockly-rc/typings/msg/mg.d.ts +8 -0
  1006. package/blockly-rc/typings/msg/mk.d.ts +8 -0
  1007. package/blockly-rc/typings/msg/ml.d.ts +8 -0
  1008. package/blockly-rc/typings/msg/mnw.d.ts +8 -0
  1009. package/blockly-rc/typings/msg/ms.d.ts +8 -0
  1010. package/blockly-rc/typings/msg/msg.d.ts +440 -0
  1011. package/blockly-rc/typings/msg/my.d.ts +8 -0
  1012. package/blockly-rc/typings/msg/mzn.d.ts +8 -0
  1013. package/blockly-rc/typings/msg/nb.d.ts +8 -0
  1014. package/blockly-rc/typings/msg/ne.d.ts +8 -0
  1015. package/blockly-rc/typings/msg/nl.d.ts +8 -0
  1016. package/blockly-rc/typings/msg/oc.d.ts +8 -0
  1017. package/blockly-rc/typings/msg/olo.d.ts +8 -0
  1018. package/blockly-rc/typings/msg/pa.d.ts +8 -0
  1019. package/blockly-rc/typings/msg/pl.d.ts +8 -0
  1020. package/blockly-rc/typings/msg/pms.d.ts +8 -0
  1021. package/blockly-rc/typings/msg/ps.d.ts +8 -0
  1022. package/blockly-rc/typings/msg/pt-br.d.ts +8 -0
  1023. package/blockly-rc/typings/msg/pt.d.ts +8 -0
  1024. package/blockly-rc/typings/msg/ro.d.ts +8 -0
  1025. package/blockly-rc/typings/msg/ru.d.ts +8 -0
  1026. package/blockly-rc/typings/msg/sc.d.ts +8 -0
  1027. package/blockly-rc/typings/msg/sco.d.ts +8 -0
  1028. package/blockly-rc/typings/msg/sd.d.ts +8 -0
  1029. package/blockly-rc/typings/msg/shn.d.ts +8 -0
  1030. package/blockly-rc/typings/msg/si.d.ts +8 -0
  1031. package/blockly-rc/typings/msg/sk.d.ts +8 -0
  1032. package/blockly-rc/typings/msg/skr-arab.d.ts +8 -0
  1033. package/blockly-rc/typings/msg/sl.d.ts +8 -0
  1034. package/blockly-rc/typings/msg/smn.d.ts +8 -0
  1035. package/blockly-rc/typings/msg/sq.d.ts +8 -0
  1036. package/blockly-rc/typings/msg/sr-latn.d.ts +8 -0
  1037. package/blockly-rc/typings/msg/sr.d.ts +8 -0
  1038. package/blockly-rc/typings/msg/sv.d.ts +8 -0
  1039. package/blockly-rc/typings/msg/sw.d.ts +8 -0
  1040. package/blockly-rc/typings/msg/ta.d.ts +8 -0
  1041. package/blockly-rc/typings/msg/tcy.d.ts +8 -0
  1042. package/blockly-rc/typings/msg/tdd.d.ts +8 -0
  1043. package/blockly-rc/typings/msg/te.d.ts +8 -0
  1044. package/blockly-rc/typings/msg/th.d.ts +8 -0
  1045. package/blockly-rc/typings/msg/ti.d.ts +8 -0
  1046. package/blockly-rc/typings/msg/tl.d.ts +8 -0
  1047. package/blockly-rc/typings/msg/tlh.d.ts +8 -0
  1048. package/blockly-rc/typings/msg/tr.d.ts +8 -0
  1049. package/blockly-rc/typings/msg/ug-arab.d.ts +8 -0
  1050. package/blockly-rc/typings/msg/uk.d.ts +8 -0
  1051. package/blockly-rc/typings/msg/ur.d.ts +8 -0
  1052. package/blockly-rc/typings/msg/uz.d.ts +8 -0
  1053. package/blockly-rc/typings/msg/vi.d.ts +8 -0
  1054. package/blockly-rc/typings/msg/xmf.d.ts +8 -0
  1055. package/blockly-rc/typings/msg/yo.d.ts +8 -0
  1056. package/blockly-rc/typings/msg/zgh.d.ts +8 -0
  1057. package/blockly-rc/typings/msg/zh-hans.d.ts +8 -0
  1058. package/blockly-rc/typings/msg/zh-hant.d.ts +8 -0
  1059. package/blockly-rc/typings/php.d.ts +7 -0
  1060. package/blockly-rc/typings/python.d.ts +7 -0
  1061. package/blockly-rc/typings/templates/blockly-header.template +11 -0
  1062. package/blockly-rc/typings/templates/blockly-interfaces.template +83 -0
  1063. package/blockly-rc/typings/templates/msg.template +15 -0
  1064. package/blockly-rc/typings/tsconfig.json +23 -0
  1065. package/continuous-toolbox.d.ts +1 -0
  1066. package/dist/main.js +2 -0
  1067. package/dist/main.js.LICENSE.txt +163 -0
  1068. package/media/delete-icon.svg +10 -0
  1069. package/media/resize-handle.svg +3 -0
  1070. package/msg/scratch_msgs.js +184 -164
  1071. package/package.json +25 -40
  1072. package/release.config.js +8 -0
  1073. package/src/block_reporting.js +31 -0
  1074. package/src/blocks/colour.js +56 -0
  1075. package/src/blocks/control.js +492 -0
  1076. package/src/blocks/data.js +690 -0
  1077. package/src/blocks/event.js +305 -0
  1078. package/src/blocks/looks.js +537 -0
  1079. package/src/blocks/math.js +137 -0
  1080. package/src/blocks/matrix.js +47 -0
  1081. package/src/blocks/motion.js +513 -0
  1082. package/src/blocks/note.js +48 -0
  1083. package/src/blocks/operators.js +463 -0
  1084. package/src/blocks/procedures.js +1009 -0
  1085. package/src/blocks/sensing.js +441 -0
  1086. package/src/blocks/sound.js +205 -0
  1087. package/src/blocks/text.js +45 -0
  1088. package/src/blocks/vertical_extensions.js +309 -0
  1089. package/src/categories.js +15 -0
  1090. package/src/checkable_continuous_flyout.js +138 -0
  1091. package/src/checkbox_bubble.js +282 -0
  1092. package/src/colours.js +77 -0
  1093. package/src/constants.js +63 -0
  1094. package/src/context_menu_items.js +150 -0
  1095. package/src/css.js +1197 -0
  1096. package/src/data_category.js +556 -0
  1097. package/src/events/events_block_comment_base.js +35 -0
  1098. package/src/events/events_block_comment_change.js +43 -0
  1099. package/src/events/events_block_comment_collapse.js +43 -0
  1100. package/src/events/events_block_comment_create.js +52 -0
  1101. package/src/events/events_block_comment_delete.js +27 -0
  1102. package/src/events/events_block_comment_move.js +54 -0
  1103. package/src/events/events_block_comment_resize.js +52 -0
  1104. package/src/events/events_block_drag_end.js +33 -0
  1105. package/src/events/events_block_drag_outside.js +30 -0
  1106. package/src/events/events_scratch_variable_create.js +67 -0
  1107. package/src/fields/field_angle.js +433 -0
  1108. package/src/fields/field_colour_slider.js +388 -0
  1109. package/src/fields/field_dropdown.js +42 -0
  1110. package/src/fields/field_matrix.js +634 -0
  1111. package/src/fields/field_note.js +937 -0
  1112. package/src/fields/field_number.js +380 -0
  1113. package/src/fields/field_textinput_removable.js +107 -0
  1114. package/src/fields/field_variable.js +171 -0
  1115. package/src/fields/field_variable_getter.js +109 -0
  1116. package/src/fields/field_vertical_separator.js +139 -0
  1117. package/src/flyout_checkbox_icon.js +88 -0
  1118. package/src/glows.js +98 -0
  1119. package/src/index.ts +137 -0
  1120. package/src/procedures.js +425 -0
  1121. package/src/recyclable_block_flyout_inflater.js +194 -0
  1122. package/src/renderer/bowler_hat.js +17 -0
  1123. package/src/renderer/constants.js +45 -0
  1124. package/src/renderer/drawer.js +51 -0
  1125. package/src/renderer/path_object.js +35 -0
  1126. package/src/renderer/render_info.js +98 -0
  1127. package/src/renderer/renderer.js +74 -0
  1128. package/src/scratch_block_paster.js +46 -0
  1129. package/src/scratch_blocks_utils.js +148 -0
  1130. package/src/scratch_comment_bubble.js +169 -0
  1131. package/src/scratch_comment_icon.js +195 -0
  1132. package/src/scratch_connection_checker.js +29 -0
  1133. package/src/scratch_continuous_category.js +80 -0
  1134. package/src/scratch_continuous_toolbox.js +78 -0
  1135. package/src/scratch_dragger.js +142 -0
  1136. package/src/scratch_variable_map.js +25 -0
  1137. package/src/scratch_variable_model.js +24 -0
  1138. package/src/shadows.js +61 -0
  1139. package/src/status_indicator_label.js +186 -0
  1140. package/src/status_indicator_label_flyout_inflater.js +42 -0
  1141. package/src/variables.js +355 -0
  1142. package/temp-use-blockly-v12-rc.sh +26 -0
  1143. package/tsconfig.json +13 -0
  1144. package/blockly_compressed_horizontal.js +0 -2255
  1145. package/blockly_compressed_vertical.js +0 -2283
  1146. package/blockly_uncompressed_horizontal.js +0 -1210
  1147. package/blockly_uncompressed_vertical.js +0 -1210
  1148. package/blocks_common/colour.js +0 -61
  1149. package/blocks_common/math.js +0 -159
  1150. package/blocks_common/matrix.js +0 -54
  1151. package/blocks_common/note.js +0 -58
  1152. package/blocks_common/text.js +0 -57
  1153. package/blocks_compressed.js +0 -36
  1154. package/blocks_compressed_horizontal.js +0 -67
  1155. package/blocks_compressed_vertical.js +0 -208
  1156. package/blocks_horizontal/control.js +0 -212
  1157. package/blocks_horizontal/default_toolbox.js +0 -139
  1158. package/blocks_horizontal/event.js +0 -190
  1159. package/blocks_horizontal/wedo.js +0 -325
  1160. package/blocks_vertical/control.js +0 -532
  1161. package/blocks_vertical/data.js +0 -666
  1162. package/blocks_vertical/default_toolbox.js +0 -564
  1163. package/blocks_vertical/event.js +0 -329
  1164. package/blocks_vertical/extensions.js +0 -294
  1165. package/blocks_vertical/looks.js +0 -591
  1166. package/blocks_vertical/motion.js +0 -587
  1167. package/blocks_vertical/operators.js +0 -470
  1168. package/blocks_vertical/procedures.js +0 -973
  1169. package/blocks_vertical/sensing.js +0 -539
  1170. package/blocks_vertical/sound.js +0 -246
  1171. package/blocks_vertical/vertical_extensions.js +0 -266
  1172. package/build/gen_blocks.js +0 -1
  1173. package/build/test_expect.js +0 -1
  1174. package/build/test_input.js +0 -1
  1175. package/build.py +0 -636
  1176. package/cleanup.sh +0 -101
  1177. package/core/block.js +0 -1837
  1178. package/core/block_animations.js +0 -107
  1179. package/core/block_drag_surface.js +0 -299
  1180. package/core/block_dragger.js +0 -421
  1181. package/core/block_events.js +0 -531
  1182. package/core/block_render_svg_horizontal.js +0 -890
  1183. package/core/block_render_svg_vertical.js +0 -1732
  1184. package/core/block_svg.js +0 -1316
  1185. package/core/blockly.js +0 -622
  1186. package/core/blocks.js +0 -37
  1187. package/core/bubble.js +0 -664
  1188. package/core/bubble_dragger.js +0 -285
  1189. package/core/colours.js +0 -160
  1190. package/core/comment.js +0 -293
  1191. package/core/comment_events.js +0 -539
  1192. package/core/connection.js +0 -766
  1193. package/core/connection_db.js +0 -300
  1194. package/core/constants.js +0 -387
  1195. package/core/contextmenu.js +0 -519
  1196. package/core/css.js +0 -1351
  1197. package/core/data_category.js +0 -490
  1198. package/core/dragged_connection_manager.js +0 -260
  1199. package/core/dropdowndiv.js +0 -408
  1200. package/core/events.js +0 -429
  1201. package/core/events_abstract.js +0 -113
  1202. package/core/extensions.js +0 -450
  1203. package/core/field.js +0 -807
  1204. package/core/field_angle.js +0 -398
  1205. package/core/field_checkbox.js +0 -133
  1206. package/core/field_colour.js +0 -253
  1207. package/core/field_colour_slider.js +0 -387
  1208. package/core/field_date.js +0 -353
  1209. package/core/field_dropdown.js +0 -483
  1210. package/core/field_iconmenu.js +0 -309
  1211. package/core/field_image.js +0 -193
  1212. package/core/field_label.js +0 -136
  1213. package/core/field_label_serializable.js +0 -125
  1214. package/core/field_matrix.js +0 -566
  1215. package/core/field_note.js +0 -850
  1216. package/core/field_number.js +0 -366
  1217. package/core/field_numberdropdown.js +0 -77
  1218. package/core/field_textdropdown.js +0 -164
  1219. package/core/field_textinput.js +0 -675
  1220. package/core/field_textinput_removable.js +0 -105
  1221. package/core/field_variable.js +0 -385
  1222. package/core/field_variable_getter.js +0 -185
  1223. package/core/field_vertical_separator.js +0 -161
  1224. package/core/flyout_base.js +0 -923
  1225. package/core/flyout_button.js +0 -322
  1226. package/core/flyout_dragger.js +0 -83
  1227. package/core/flyout_extension_category_header.js +0 -159
  1228. package/core/flyout_horizontal.js +0 -475
  1229. package/core/flyout_vertical.js +0 -770
  1230. package/core/generator.js +0 -426
  1231. package/core/gesture.js +0 -1011
  1232. package/core/grid.js +0 -227
  1233. package/core/icon.js +0 -205
  1234. package/core/inject.js +0 -491
  1235. package/core/input.js +0 -285
  1236. package/core/insertion_marker_manager.js +0 -678
  1237. package/core/msg.js +0 -62
  1238. package/core/mutator.js +0 -426
  1239. package/core/names.js +0 -198
  1240. package/core/options.js +0 -244
  1241. package/core/procedures.js +0 -577
  1242. package/core/rendered_connection.js +0 -417
  1243. package/core/scratch_block_comment.js +0 -653
  1244. package/core/scratch_blocks_utils.js +0 -244
  1245. package/core/scratch_bubble.js +0 -696
  1246. package/core/scratch_events.js +0 -131
  1247. package/core/scratch_msgs.js +0 -85
  1248. package/core/scrollbar.js +0 -875
  1249. package/core/toolbox.js +0 -801
  1250. package/core/tooltip.js +0 -337
  1251. package/core/touch.js +0 -226
  1252. package/core/trashcan.js +0 -343
  1253. package/core/ui_events.js +0 -91
  1254. package/core/ui_menu_utils.js +0 -68
  1255. package/core/utils.js +0 -948
  1256. package/core/variable_events.js +0 -259
  1257. package/core/variable_map.js +0 -415
  1258. package/core/variable_model.js +0 -116
  1259. package/core/variables.js +0 -674
  1260. package/core/warning.js +0 -199
  1261. package/core/widgetdiv.js +0 -344
  1262. package/core/workspace.js +0 -673
  1263. package/core/workspace_audio.js +0 -170
  1264. package/core/workspace_comment.js +0 -432
  1265. package/core/workspace_comment_render_svg.js +0 -723
  1266. package/core/workspace_comment_svg.js +0 -611
  1267. package/core/workspace_drag_surface_svg.js +0 -195
  1268. package/core/workspace_dragger.js +0 -132
  1269. package/core/workspace_svg.js +0 -2267
  1270. package/core/xml.js +0 -919
  1271. package/core/zoom_controls.js +0 -301
  1272. package/dist/horizontal.js +0 -222
  1273. package/dist/vertical.js +0 -222
  1274. package/dist/web/horizontal.js +0 -232
  1275. package/dist/web/vertical.js +0 -232
  1276. package/local_build.sh +0 -70
  1277. package/pack/scratch-blocks-1.1.206.tgz +0 -0
  1278. package/pull_from_blockly.sh +0 -151
  1279. package/shim/blockly_compressed_horizontal-blocks_compressed.js +0 -1
  1280. package/shim/blockly_compressed_horizontal.Blockly.js +0 -1
  1281. package/shim/blockly_compressed_horizontal.goog.js +0 -1
  1282. package/shim/blockly_compressed_horizontal.js +0 -1
  1283. package/shim/blockly_compressed_vertical-blocks_compressed.js +0 -1
  1284. package/shim/blockly_compressed_vertical.Blockly.js +0 -1
  1285. package/shim/blockly_compressed_vertical.goog.js +0 -1
  1286. package/shim/blockly_compressed_vertical.js +0 -1
  1287. package/shim/blocks_compressed_horizontal-blockly_compressed_horizontal-messages.js +0 -1
  1288. package/shim/blocks_compressed_horizontal.js +0 -1
  1289. package/shim/blocks_compressed_vertical-blockly_compressed_vertical-messages.js +0 -1
  1290. package/shim/blocks_compressed_vertical.js +0 -1
  1291. package/shim/gh-pages.js +0 -1
  1292. package/shim/horizontal.js +0 -1
  1293. package/shim/index.js +0 -17
  1294. package/shim/vertical.js +0 -1
  1295. /package/media/{comment-arrow-down.svg → foldout-icon.svg} +0 -0
@@ -0,0 +1,2519 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2014 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ /**
8
+ * Object representing a workspace rendered as SVG.
9
+ *
10
+ * @class
11
+ */
12
+ // Former goog.module ID: Blockly.WorkspaceSvg
13
+
14
+ // Unused import preserved for side-effects. Remove if unneeded.
15
+ import './events/events_block_create.js';
16
+ // Unused import preserved for side-effects. Remove if unneeded.
17
+ import './events/events_theme_change.js';
18
+ // Unused import preserved for side-effects. Remove if unneeded.
19
+ import './events/events_viewport.js';
20
+
21
+ import type {Block} from './block.js';
22
+ import type {BlockSvg} from './block_svg.js';
23
+ import type {BlocklyOptions} from './blockly_options.js';
24
+ import * as browserEvents from './browser_events.js';
25
+ import * as common from './common.js';
26
+ import {ComponentManager} from './component_manager.js';
27
+ import {ConnectionDB} from './connection_db.js';
28
+ import * as ContextMenu from './contextmenu.js';
29
+ import {ContextMenuRegistry} from './contextmenu_registry.js';
30
+ import * as dropDownDiv from './dropdowndiv.js';
31
+ import * as eventUtils from './events/utils.js';
32
+ import {Flyout} from './flyout_base.js';
33
+ import type {FlyoutButton} from './flyout_button.js';
34
+ import {Gesture} from './gesture.js';
35
+ import {Grid} from './grid.js';
36
+ import type {IASTNodeLocationSvg} from './interfaces/i_ast_node_location_svg.js';
37
+ import type {IBoundedElement} from './interfaces/i_bounded_element.js';
38
+ import type {IDragTarget} from './interfaces/i_drag_target.js';
39
+ import type {IFlyout} from './interfaces/i_flyout.js';
40
+ import type {IMetricsManager} from './interfaces/i_metrics_manager.js';
41
+ import type {IToolbox} from './interfaces/i_toolbox.js';
42
+ import type {Cursor} from './keyboard_nav/cursor.js';
43
+ import type {Marker} from './keyboard_nav/marker.js';
44
+ import {MarkerManager} from './marker_manager.js';
45
+ import {Options} from './options.js';
46
+ import * as Procedures from './procedures.js';
47
+ import * as registry from './registry.js';
48
+ import * as blockRendering from './renderers/common/block_rendering.js';
49
+ import type {Renderer} from './renderers/common/renderer.js';
50
+ import type {ScrollbarPair} from './scrollbar_pair.js';
51
+ import type {Theme} from './theme.js';
52
+ import {Classic} from './theme/classic.js';
53
+ import {ThemeManager} from './theme_manager.js';
54
+ import * as Tooltip from './tooltip.js';
55
+ import type {Trashcan} from './trashcan.js';
56
+ import * as arrayUtils from './utils/array.js';
57
+ import {Coordinate} from './utils/coordinate.js';
58
+ import * as dom from './utils/dom.js';
59
+ import type {Metrics} from './utils/metrics.js';
60
+ import {Rect} from './utils/rect.js';
61
+ import {Size} from './utils/size.js';
62
+ import {Svg} from './utils/svg.js';
63
+ import * as svgMath from './utils/svg_math.js';
64
+ import * as toolbox from './utils/toolbox.js';
65
+ import * as userAgent from './utils/useragent.js';
66
+ import type {
67
+ IVariableModel,
68
+ IVariableState,
69
+ } from './interfaces/i_variable_model.js';
70
+ import * as Variables from './variables.js';
71
+ import * as VariablesDynamic from './variables_dynamic.js';
72
+ import * as WidgetDiv from './widgetdiv.js';
73
+ import {Workspace} from './workspace.js';
74
+ import {WorkspaceAudio} from './workspace_audio.js';
75
+ import {WorkspaceComment} from './comments/workspace_comment.js';
76
+ import {ZoomControls} from './zoom_controls.js';
77
+ import {ContextMenuOption} from './contextmenu_registry.js';
78
+ import * as renderManagement from './render_management.js';
79
+ import {LayerManager} from './layer_manager.js';
80
+ import {RenderedWorkspaceComment} from './comments/rendered_workspace_comment.js';
81
+
82
+ /** Margin around the top/bottom/left/right after a zoomToFit call. */
83
+ const ZOOM_TO_FIT_MARGIN = 20;
84
+
85
+ /**
86
+ * Class for a workspace. This is an onscreen area with optional trashcan,
87
+ * scrollbars, bubbles, and dragging.
88
+ */
89
+ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
90
+ /**
91
+ * A wrapper function called when a resize event occurs.
92
+ * You can pass the result to `eventHandling.unbind`.
93
+ */
94
+ private resizeHandlerWrapper: browserEvents.Data | null = null;
95
+
96
+ /**
97
+ * The render status of an SVG workspace.
98
+ * Returns `false` for headless workspaces and true for instances of
99
+ * `WorkspaceSvg`.
100
+ */
101
+ override rendered = true;
102
+
103
+ /**
104
+ * Whether the workspace is visible. False if the workspace has been hidden
105
+ * by calling `setVisible(false)`.
106
+ */
107
+ private isVisible_ = true;
108
+
109
+ /**
110
+ * Whether this workspace has resizes enabled.
111
+ * Disable during batch operations for a performance improvement.
112
+ */
113
+ private resizesEnabled = true;
114
+
115
+ /**
116
+ * Current horizontal scrolling offset in pixel units, relative to the
117
+ * workspace origin.
118
+ *
119
+ * It is useful to think about a view, and a canvas moving beneath that
120
+ * view. As the canvas moves right, this value becomes more positive, and
121
+ * the view is now "seeing" the left side of the canvas. As the canvas moves
122
+ * left, this value becomes more negative, and the view is now "seeing" the
123
+ * right side of the canvas.
124
+ *
125
+ * The confusing thing about this value is that it does not, and must not
126
+ * include the absoluteLeft offset. This is because it is used to calculate
127
+ * the viewLeft value.
128
+ *
129
+ * The viewLeft is relative to the workspace origin (although in pixel
130
+ * units). The workspace origin is the top-left corner of the workspace (at
131
+ * least when it is enabled). It is shifted from the top-left of the
132
+ * blocklyDiv so as not to be beneath the toolbox.
133
+ *
134
+ * When the workspace is enabled the viewLeft and workspace origin are at
135
+ * the same X location. As the canvas slides towards the right beneath the
136
+ * view this value (scrollX) becomes more positive, and the viewLeft becomes
137
+ * more negative relative to the workspace origin (imagine the workspace
138
+ * origin as a dot on the canvas sliding to the right as the canvas moves).
139
+ *
140
+ * So if the scrollX were to include the absoluteLeft this would in a way
141
+ * "unshift" the workspace origin. This means that the viewLeft would be
142
+ * representing the left edge of the blocklyDiv, rather than the left edge
143
+ * of the workspace.
144
+ */
145
+ scrollX = 0;
146
+
147
+ /**
148
+ * Current vertical scrolling offset in pixel units, relative to the
149
+ * workspace origin.
150
+ *
151
+ * It is useful to think about a view, and a canvas moving beneath that
152
+ * view. As the canvas moves down, this value becomes more positive, and the
153
+ * view is now "seeing" the upper part of the canvas. As the canvas moves
154
+ * up, this value becomes more negative, and the view is "seeing" the lower
155
+ * part of the canvas.
156
+ *
157
+ * This confusing thing about this value is that it does not, and must not
158
+ * include the absoluteTop offset. This is because it is used to calculate
159
+ * the viewTop value.
160
+ *
161
+ * The viewTop is relative to the workspace origin (although in pixel
162
+ * units). The workspace origin is the top-left corner of the workspace (at
163
+ * least when it is enabled). It is shifted from the top-left of the
164
+ * blocklyDiv so as not to be beneath the toolbox.
165
+ *
166
+ * When the workspace is enabled the viewTop and workspace origin are at the
167
+ * same Y location. As the canvas slides towards the bottom this value
168
+ * (scrollY) becomes more positive, and the viewTop becomes more negative
169
+ * relative to the workspace origin (image in the workspace origin as a dot
170
+ * on the canvas sliding downwards as the canvas moves).
171
+ *
172
+ * So if the scrollY were to include the absoluteTop this would in a way
173
+ * "unshift" the workspace origin. This means that the viewTop would be
174
+ * representing the top edge of the blocklyDiv, rather than the top edge of
175
+ * the workspace.
176
+ */
177
+ scrollY = 0;
178
+
179
+ /** Horizontal scroll value when scrolling started in pixel units. */
180
+ startScrollX = 0;
181
+
182
+ /** Vertical scroll value when scrolling started in pixel units. */
183
+ startScrollY = 0;
184
+
185
+ /** Distance from mouse to object being dragged. */
186
+ private dragDeltaXY: Coordinate | null = null;
187
+
188
+ /** Current scale. */
189
+ scale = 1;
190
+
191
+ /** Cached scale value. Used to detect changes in viewport. */
192
+ private oldScale = 1;
193
+
194
+ /** Cached viewport top value. Used to detect changes in viewport. */
195
+ private oldTop = 0;
196
+
197
+ /** Cached viewport left value. Used to detect changes in viewport. */
198
+ private oldLeft = 0;
199
+
200
+ /** The workspace's trashcan (if any). */
201
+ trashcan: Trashcan | null = null;
202
+
203
+ /** This workspace's scrollbars, if they exist. */
204
+ scrollbar: ScrollbarPair | null = null;
205
+
206
+ /**
207
+ * Fixed flyout providing blocks which may be dragged into this workspace.
208
+ */
209
+ private flyout: IFlyout | null = null;
210
+
211
+ /**
212
+ * Category-based toolbox providing blocks which may be dragged into this
213
+ * workspace.
214
+ */
215
+ private toolbox_: IToolbox | null = null;
216
+
217
+ /**
218
+ * The current gesture in progress on this workspace, if any.
219
+ *
220
+ * @internal
221
+ */
222
+ currentGesture_: Gesture | null = null;
223
+
224
+ /**
225
+ * The first parent div with 'injectionDiv' in the name, or null if not set.
226
+ * Access this with getInjectionDiv.
227
+ */
228
+ private injectionDiv: Element | null = null;
229
+
230
+ /**
231
+ * Last known position of the page scroll.
232
+ * This is used to determine whether we have recalculated screen coordinate
233
+ * stuff since the page scrolled.
234
+ */
235
+ private lastRecordedPageScroll: Coordinate | null = null;
236
+
237
+ /**
238
+ * Developers may define this function to add custom menu options to the
239
+ * workspace's context menu or edit the workspace-created set of menu
240
+ * options.
241
+ *
242
+ * @param options List of menu options to add to.
243
+ * @param e The right-click event that triggered the context menu.
244
+ */
245
+ configureContextMenu:
246
+ | ((menuOptions: ContextMenuOption[], e: Event) => void)
247
+ | null = null;
248
+
249
+ /**
250
+ * A dummy wheel event listener used as a workaround for a Safari scrolling issue.
251
+ * Set in createDom and used for removal in dispose to ensure proper cleanup.
252
+ */
253
+ private dummyWheelListener: (() => void) | null = null;
254
+
255
+ /**
256
+ * In a flyout, the target workspace where blocks should be placed after a
257
+ * drag. Otherwise null.
258
+ *
259
+ * @internal
260
+ */
261
+ targetWorkspace: WorkspaceSvg | null = null;
262
+
263
+ /** Inverted screen CTM, for use in mouseToSvg. */
264
+ private inverseScreenCTM: SVGMatrix | null = null;
265
+
266
+ /** Inverted screen CTM is dirty, recalculate it. */
267
+ private inverseScreenCTMDirty = true;
268
+ private metricsManager: IMetricsManager;
269
+ /** @internal */
270
+ getMetrics: () => Metrics;
271
+ /** @internal */
272
+ setMetrics: (p1: {x?: number; y?: number}) => void;
273
+ private readonly componentManager: ComponentManager;
274
+
275
+ /**
276
+ * List of currently highlighted blocks. Block highlighting is often used
277
+ * to visually mark blocks currently being executed.
278
+ */
279
+ private readonly highlightedBlocks: BlockSvg[] = [];
280
+ private audioManager: WorkspaceAudio;
281
+ private grid: Grid | null;
282
+ private markerManager: MarkerManager;
283
+
284
+ /**
285
+ * Map from function names to callbacks, for deciding what to do when a
286
+ * custom toolbox category is opened.
287
+ */
288
+ private toolboxCategoryCallbacks = new Map<
289
+ string,
290
+ (p1: WorkspaceSvg) => toolbox.FlyoutDefinition
291
+ >();
292
+
293
+ /**
294
+ * Map from function names to callbacks, for deciding what to do when a
295
+ * button is clicked.
296
+ */
297
+ private flyoutButtonCallbacks = new Map<string, (p1: FlyoutButton) => void>();
298
+ protected themeManager_: ThemeManager;
299
+ private readonly renderer: Renderer;
300
+
301
+ /** Cached parent SVG. */
302
+ private cachedParentSvg: SVGElement | null = null;
303
+
304
+ /** True if keyboard accessibility mode is on, false otherwise. */
305
+ keyboardAccessibilityMode = false;
306
+
307
+ /** The list of top-level bounded elements on the workspace. */
308
+ private topBoundedElements: IBoundedElement[] = [];
309
+
310
+ /** The recorded drag targets. */
311
+ private dragTargetAreas: Array<{component: IDragTarget; clientRect: Rect}> =
312
+ [];
313
+ private readonly cachedParentSvgSize: Size;
314
+ private layerManager: LayerManager | null = null;
315
+ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
316
+ svgGroup_!: SVGElement;
317
+ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
318
+ svgBackground_!: SVGElement;
319
+ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
320
+ svgBlockCanvas_!: SVGElement;
321
+ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
322
+ svgBubbleCanvas_!: SVGElement;
323
+ zoomControls_: ZoomControls | null = null;
324
+
325
+ /**
326
+ * @param options Dictionary of options.
327
+ */
328
+ constructor(options: Options) {
329
+ super(options);
330
+
331
+ const MetricsManagerClass = registry.getClassFromOptions(
332
+ registry.Type.METRICS_MANAGER,
333
+ options,
334
+ true,
335
+ );
336
+ /** Object in charge of calculating metrics for the workspace. */
337
+ this.metricsManager = new MetricsManagerClass!(this);
338
+
339
+ /** Method to get all the metrics that have to do with a workspace. */
340
+ this.getMetrics =
341
+ options.getMetrics ||
342
+ this.metricsManager.getMetrics.bind(this.metricsManager);
343
+
344
+ /** Translates the workspace. */
345
+ this.setMetrics =
346
+ options.setMetrics || WorkspaceSvg.setTopLevelWorkspaceMetrics_;
347
+
348
+ this.componentManager = new ComponentManager();
349
+
350
+ this.connectionDBList = ConnectionDB.init(this.connectionChecker);
351
+
352
+ /**
353
+ * Object in charge of loading, storing, and playing audio for a workspace.
354
+ */
355
+ this.audioManager = new WorkspaceAudio(
356
+ options.parentWorkspace as WorkspaceSvg,
357
+ );
358
+
359
+ /** This workspace's grid object or null. */
360
+ this.grid = this.options.gridPattern
361
+ ? new Grid(this.options.gridPattern, options.gridOptions)
362
+ : null;
363
+
364
+ /** Manager in charge of markers and cursors. */
365
+ this.markerManager = new MarkerManager(this);
366
+
367
+ if (Variables && Variables.flyoutCategory) {
368
+ this.registerToolboxCategoryCallback(
369
+ Variables.CATEGORY_NAME,
370
+ Variables.flyoutCategory,
371
+ );
372
+ }
373
+
374
+ if (VariablesDynamic && VariablesDynamic.flyoutCategory) {
375
+ this.registerToolboxCategoryCallback(
376
+ VariablesDynamic.CATEGORY_NAME,
377
+ VariablesDynamic.flyoutCategory,
378
+ );
379
+ }
380
+
381
+ if (Procedures && Procedures.flyoutCategory) {
382
+ this.registerToolboxCategoryCallback(
383
+ Procedures.CATEGORY_NAME,
384
+ Procedures.flyoutCategory,
385
+ );
386
+ this.addChangeListener(Procedures.mutatorOpenListener);
387
+ }
388
+
389
+ /** Object in charge of storing and updating the workspace theme. */
390
+ this.themeManager_ = this.options.parentWorkspace
391
+ ? this.options.parentWorkspace.getThemeManager()
392
+ : new ThemeManager(this, this.options.theme || Classic);
393
+ this.themeManager_.subscribeWorkspace(this);
394
+
395
+ /** The block renderer used for rendering blocks on this workspace. */
396
+ this.renderer = blockRendering.init(
397
+ this.options.renderer || 'geras',
398
+ this.getTheme(),
399
+ this.options.rendererOverrides ?? undefined,
400
+ );
401
+
402
+ /**
403
+ * The cached size of the parent svg element.
404
+ * Used to compute svg metrics.
405
+ */
406
+ this.cachedParentSvgSize = new Size(0, 0);
407
+ }
408
+
409
+ /**
410
+ * Get the marker manager for this workspace.
411
+ *
412
+ * @returns The marker manager.
413
+ */
414
+ getMarkerManager(): MarkerManager {
415
+ return this.markerManager;
416
+ }
417
+
418
+ /**
419
+ * Gets the metrics manager for this workspace.
420
+ *
421
+ * @returns The metrics manager.
422
+ */
423
+ getMetricsManager(): IMetricsManager {
424
+ return this.metricsManager;
425
+ }
426
+
427
+ /**
428
+ * Sets the metrics manager for the workspace.
429
+ *
430
+ * @param metricsManager The metrics manager.
431
+ * @internal
432
+ */
433
+ setMetricsManager(metricsManager: IMetricsManager) {
434
+ this.metricsManager = metricsManager;
435
+ this.getMetrics = this.metricsManager.getMetrics.bind(this.metricsManager);
436
+ }
437
+
438
+ /**
439
+ * Gets the component manager for this workspace.
440
+ *
441
+ * @returns The component manager.
442
+ */
443
+ getComponentManager(): ComponentManager {
444
+ return this.componentManager;
445
+ }
446
+
447
+ /**
448
+ * Add the cursor SVG to this workspaces SVG group.
449
+ *
450
+ * @param cursorSvg The SVG root of the cursor to be added to the workspace
451
+ * SVG group.
452
+ * @internal
453
+ */
454
+ setCursorSvg(cursorSvg: SVGElement) {
455
+ this.markerManager.setCursorSvg(cursorSvg);
456
+ }
457
+
458
+ /**
459
+ * Add the marker SVG to this workspaces SVG group.
460
+ *
461
+ * @param markerSvg The SVG root of the marker to be added to the workspace
462
+ * SVG group.
463
+ * @internal
464
+ */
465
+ setMarkerSvg(markerSvg: SVGElement) {
466
+ this.markerManager.setMarkerSvg(markerSvg);
467
+ }
468
+
469
+ /**
470
+ * Get the marker with the given ID.
471
+ *
472
+ * @param id The ID of the marker.
473
+ * @returns The marker with the given ID or null if no marker with the given
474
+ * ID exists.
475
+ * @internal
476
+ */
477
+ getMarker(id: string): Marker | null {
478
+ if (this.markerManager) {
479
+ return this.markerManager.getMarker(id);
480
+ }
481
+ return null;
482
+ }
483
+
484
+ /**
485
+ * The cursor for this workspace.
486
+ *
487
+ * @returns The cursor for the workspace.
488
+ */
489
+ getCursor(): Cursor | null {
490
+ if (this.markerManager) {
491
+ return this.markerManager.getCursor();
492
+ }
493
+ return null;
494
+ }
495
+
496
+ /**
497
+ * Get the block renderer attached to this workspace.
498
+ *
499
+ * @returns The renderer attached to this workspace.
500
+ */
501
+ getRenderer(): Renderer {
502
+ return this.renderer;
503
+ }
504
+
505
+ /**
506
+ * Get the theme manager for this workspace.
507
+ *
508
+ * @returns The theme manager for this workspace.
509
+ * @internal
510
+ */
511
+ getThemeManager(): ThemeManager {
512
+ return this.themeManager_;
513
+ }
514
+
515
+ /**
516
+ * Get the workspace theme object.
517
+ *
518
+ * @returns The workspace theme object.
519
+ */
520
+ getTheme(): Theme {
521
+ return this.themeManager_.getTheme();
522
+ }
523
+
524
+ /**
525
+ * Set the workspace theme object.
526
+ * If no theme is passed, default to the `Classic` theme.
527
+ *
528
+ * @param theme The workspace theme object.
529
+ */
530
+ setTheme(theme: Theme) {
531
+ if (!theme) {
532
+ theme = Classic as Theme;
533
+ }
534
+ this.themeManager_.setTheme(theme);
535
+ }
536
+
537
+ /**
538
+ * Refresh all blocks on the workspace after a theme update.
539
+ */
540
+ refreshTheme() {
541
+ if (this.svgGroup_) {
542
+ this.renderer.refreshDom(this.svgGroup_, this.getTheme());
543
+ }
544
+
545
+ // Update all blocks in workspace that have a style name.
546
+ this.updateBlockStyles_(
547
+ this.getAllBlocks(false).filter(function (block) {
548
+ return !!block.getStyleName();
549
+ }),
550
+ );
551
+
552
+ // Update current toolbox selection.
553
+ this.refreshToolboxSelection();
554
+ if (this.toolbox_) {
555
+ this.toolbox_.refreshTheme();
556
+ }
557
+
558
+ // Re-render if workspace is visible
559
+ if (this.isVisible()) {
560
+ this.setVisible(true);
561
+ }
562
+
563
+ const event = new (eventUtils.get(eventUtils.THEME_CHANGE))(
564
+ this.getTheme().name,
565
+ this.id,
566
+ );
567
+ eventUtils.fire(event);
568
+ }
569
+
570
+ /**
571
+ * Updates all the blocks with new style.
572
+ *
573
+ * @param blocks List of blocks to update the style on.
574
+ */
575
+ private updateBlockStyles_(blocks: Block[]) {
576
+ for (let i = 0, block; (block = blocks[i]); i++) {
577
+ const blockStyleName = block.getStyleName();
578
+ if (blockStyleName) {
579
+ const blockSvg = block as BlockSvg;
580
+ blockSvg.setStyle(blockStyleName);
581
+ }
582
+ }
583
+ }
584
+
585
+ /**
586
+ * Getter for the inverted screen CTM.
587
+ *
588
+ * @returns The matrix to use in mouseToSvg
589
+ */
590
+ getInverseScreenCTM(): SVGMatrix | null {
591
+ // Defer getting the screen CTM until we actually need it, this should
592
+ // avoid forced reflows from any calls to updateInverseScreenCTM.
593
+ if (this.inverseScreenCTMDirty) {
594
+ const ctm = this.getParentSvg().getScreenCTM();
595
+ if (ctm) {
596
+ this.inverseScreenCTM = ctm.inverse();
597
+ this.inverseScreenCTMDirty = false;
598
+ }
599
+ }
600
+
601
+ return this.inverseScreenCTM;
602
+ }
603
+
604
+ /** Mark the inverse screen CTM as dirty. */
605
+ updateInverseScreenCTM() {
606
+ this.inverseScreenCTMDirty = true;
607
+ }
608
+
609
+ /**
610
+ * Getter for isVisible
611
+ *
612
+ * @returns Whether the workspace is visible.
613
+ * False if the workspace has been hidden by calling `setVisible(false)`.
614
+ */
615
+ isVisible(): boolean {
616
+ return this.isVisible_;
617
+ }
618
+
619
+ /**
620
+ * Return the absolute coordinates of the top-left corner of this element,
621
+ * scales that after canvas SVG element, if it's a descendant.
622
+ * The origin (0,0) is the top-left corner of the Blockly SVG.
623
+ *
624
+ * @param element SVG element to find the coordinates of.
625
+ * @returns Object with .x and .y properties.
626
+ * @internal
627
+ */
628
+ getSvgXY(element: SVGElement): Coordinate {
629
+ let x = 0;
630
+ let y = 0;
631
+ let scale = 1;
632
+ if (
633
+ this.getCanvas().contains(element) ||
634
+ this.getBubbleCanvas().contains(element)
635
+ ) {
636
+ // Before the SVG canvas, scale the coordinates.
637
+ scale = this.scale;
638
+ }
639
+ do {
640
+ // Loop through this block and every parent.
641
+ const xy = svgMath.getRelativeXY(element);
642
+ if (element === this.getCanvas() || element === this.getBubbleCanvas()) {
643
+ // After the SVG canvas, don't scale the coordinates.
644
+ scale = 1;
645
+ }
646
+ x += xy.x * scale;
647
+ y += xy.y * scale;
648
+ element = element.parentNode as SVGElement;
649
+ } while (
650
+ element &&
651
+ element !== this.getParentSvg() &&
652
+ element !== this.getInjectionDiv()
653
+ );
654
+ return new Coordinate(x, y);
655
+ }
656
+
657
+ /**
658
+ * Gets the size of the workspace's parent SVG element.
659
+ *
660
+ * @returns The cached width and height of the workspace's parent SVG element.
661
+ * @internal
662
+ */
663
+ getCachedParentSvgSize(): Size {
664
+ const size = this.cachedParentSvgSize;
665
+ return new Size(size.width, size.height);
666
+ }
667
+
668
+ /**
669
+ * Return the position of the workspace origin relative to the injection div
670
+ * origin in pixels.
671
+ * The workspace origin is where a block would render at position (0, 0).
672
+ * It is not the upper left corner of the workspace SVG.
673
+ *
674
+ * @returns Offset in pixels.
675
+ * @internal
676
+ */
677
+ getOriginOffsetInPixels(): Coordinate {
678
+ return svgMath.getInjectionDivXY(this.getCanvas());
679
+ }
680
+
681
+ /**
682
+ * Return the injection div that is a parent of this workspace.
683
+ * Walks the DOM the first time it's called, then returns a cached value.
684
+ * Note: We assume this is only called after the workspace has been injected
685
+ * into the DOM.
686
+ *
687
+ * @returns The first parent div with 'injectionDiv' in the name.
688
+ * @internal
689
+ */
690
+ getInjectionDiv(): Element {
691
+ // NB: it would be better to pass this in at createDom, but is more likely
692
+ // to break existing uses of Blockly.
693
+ if (!this.injectionDiv) {
694
+ let element: Element = this.svgGroup_;
695
+ while (element) {
696
+ const classes = element.getAttribute('class') || '';
697
+ if ((' ' + classes + ' ').includes(' injectionDiv ')) {
698
+ this.injectionDiv = element;
699
+ break;
700
+ }
701
+ element = element.parentNode as Element;
702
+ }
703
+ }
704
+ return this.injectionDiv!;
705
+ }
706
+
707
+ /**
708
+ * Returns the SVG group for the workspace.
709
+ *
710
+ * @returns The SVG group for the workspace.
711
+ */
712
+ getSvgGroup(): Element {
713
+ return this.svgGroup_;
714
+ }
715
+
716
+ /**
717
+ * Get the SVG block canvas for the workspace.
718
+ *
719
+ * @returns The SVG group for the workspace.
720
+ * @internal
721
+ */
722
+ getBlockCanvas(): SVGElement | null {
723
+ return this.getCanvas();
724
+ }
725
+
726
+ /**
727
+ * Save resize handler data so we can delete it later in dispose.
728
+ *
729
+ * @param handler Data that can be passed to eventHandling.unbind.
730
+ */
731
+ setResizeHandlerWrapper(handler: browserEvents.Data) {
732
+ this.resizeHandlerWrapper = handler;
733
+ }
734
+
735
+ /**
736
+ * Create the workspace DOM elements.
737
+ *
738
+ * @param opt_backgroundClass Either 'blocklyMainBackground' or
739
+ * 'blocklyMutatorBackground'.
740
+ * @returns The workspace's SVG group.
741
+ */
742
+ createDom(opt_backgroundClass?: string, injectionDiv?: Element): Element {
743
+ if (!this.injectionDiv) {
744
+ this.injectionDiv = injectionDiv ?? null;
745
+ }
746
+
747
+ /**
748
+ * <g class="blocklyWorkspace">
749
+ * <rect class="blocklyMainBackground" height="100%" width="100%"></rect>
750
+ * [Trashcan and/or flyout may go here]
751
+ * <g class="blocklyBlockCanvas"></g>
752
+ * <g class="blocklyBubbleCanvas"></g>
753
+ * </g>
754
+ */
755
+ this.svgGroup_ = dom.createSvgElement(Svg.G, {'class': 'blocklyWorkspace'});
756
+
757
+ // Note that a <g> alone does not receive mouse events--it must have a
758
+ // valid target inside it. If no background class is specified, as in the
759
+ // flyout, the workspace will not receive mouse events.
760
+ if (opt_backgroundClass) {
761
+ this.svgBackground_ = dom.createSvgElement(
762
+ Svg.RECT,
763
+ {'height': '100%', 'width': '100%', 'class': opt_backgroundClass},
764
+ this.svgGroup_,
765
+ );
766
+
767
+ if (opt_backgroundClass === 'blocklyMainBackground' && this.grid) {
768
+ this.svgBackground_.style.fill =
769
+ 'url(#' + this.grid.getPatternId() + ')';
770
+ } else {
771
+ this.themeManager_.subscribe(
772
+ this.svgBackground_,
773
+ 'workspaceBackgroundColour',
774
+ 'fill',
775
+ );
776
+ }
777
+ }
778
+
779
+ this.layerManager = new LayerManager(this);
780
+ // Assign the canvases for backwards compatibility.
781
+ this.svgBlockCanvas_ = this.layerManager.getBlockLayer();
782
+ this.svgBubbleCanvas_ = this.layerManager.getBubbleLayer();
783
+
784
+ if (!this.isFlyout) {
785
+ browserEvents.conditionalBind(
786
+ this.svgGroup_,
787
+ 'pointerdown',
788
+ this,
789
+ this.onMouseDown_,
790
+ false,
791
+ );
792
+ // This no-op works around https://bugs.webkit.org/show_bug.cgi?id=226683,
793
+ // which otherwise prevents zoom/scroll events from being observed in
794
+ // Safari. Once that bug is fixed it should be removed.
795
+ this.dummyWheelListener = () => {};
796
+ document.body.addEventListener('wheel', this.dummyWheelListener);
797
+ browserEvents.conditionalBind(
798
+ this.svgGroup_,
799
+ 'wheel',
800
+ this,
801
+ this.onMouseWheel_,
802
+ );
803
+ }
804
+
805
+ // Determine if there needs to be a category tree, or a simple list of
806
+ // blocks. This cannot be changed later, since the UI is very different.
807
+ if (this.options.hasCategories) {
808
+ const ToolboxClass = registry.getClassFromOptions(
809
+ registry.Type.TOOLBOX,
810
+ this.options,
811
+ true,
812
+ );
813
+ this.toolbox_ = new ToolboxClass!(this);
814
+ }
815
+ if (this.grid) {
816
+ this.grid.update(this.scale);
817
+ }
818
+ this.recordDragTargets();
819
+ const CursorClass = registry.getClassFromOptions(
820
+ registry.Type.CURSOR,
821
+ this.options,
822
+ );
823
+
824
+ CursorClass && this.markerManager.setCursor(new CursorClass());
825
+
826
+ this.renderer.createDom(this.svgGroup_, this.getTheme());
827
+ return this.svgGroup_;
828
+ }
829
+
830
+ /**
831
+ * Dispose of this workspace.
832
+ * Unlink from all DOM elements to prevent memory leaks.
833
+ */
834
+ override dispose() {
835
+ // Stop rerendering.
836
+ this.rendered = false;
837
+ if (this.currentGesture_) {
838
+ this.currentGesture_.cancel();
839
+ }
840
+ if (this.svgGroup_) {
841
+ dom.removeNode(this.svgGroup_);
842
+ }
843
+ if (this.toolbox_) {
844
+ this.toolbox_.dispose();
845
+ this.toolbox_ = null;
846
+ }
847
+ if (this.flyout) {
848
+ this.flyout.dispose();
849
+ this.flyout = null;
850
+ }
851
+ if (this.trashcan) {
852
+ this.trashcan.dispose();
853
+ this.trashcan = null;
854
+ }
855
+ if (this.scrollbar) {
856
+ this.scrollbar.dispose();
857
+ this.scrollbar = null;
858
+ }
859
+ if (this.zoomControls_) {
860
+ this.zoomControls_.dispose();
861
+ }
862
+
863
+ if (this.audioManager) {
864
+ this.audioManager.dispose();
865
+ }
866
+
867
+ if (this.grid) {
868
+ this.grid = null;
869
+ }
870
+
871
+ this.renderer.dispose();
872
+
873
+ if (this.markerManager) {
874
+ this.markerManager.dispose();
875
+ }
876
+
877
+ super.dispose();
878
+
879
+ // Dispose of theme manager after all blocks and mutators are disposed of.
880
+ if (this.themeManager_) {
881
+ this.themeManager_.unsubscribeWorkspace(this);
882
+ this.themeManager_.unsubscribe(this.svgBackground_);
883
+ if (!this.options.parentWorkspace) {
884
+ this.themeManager_.dispose();
885
+ }
886
+ }
887
+
888
+ this.connectionDBList.length = 0;
889
+
890
+ this.toolboxCategoryCallbacks.clear();
891
+ this.flyoutButtonCallbacks.clear();
892
+
893
+ if (!this.options.parentWorkspace) {
894
+ // Top-most workspace. Dispose of the div that the
895
+ // SVG is injected into (i.e. injectionDiv).
896
+ const parentSvg = this.getParentSvg();
897
+ if (parentSvg && parentSvg.parentNode) {
898
+ dom.removeNode(parentSvg.parentNode);
899
+ }
900
+ }
901
+ if (this.resizeHandlerWrapper) {
902
+ browserEvents.unbind(this.resizeHandlerWrapper);
903
+ this.resizeHandlerWrapper = null;
904
+ }
905
+
906
+ // Remove the dummy wheel listener
907
+ if (this.dummyWheelListener) {
908
+ document.body.removeEventListener('wheel', this.dummyWheelListener);
909
+ this.dummyWheelListener = null;
910
+ }
911
+ }
912
+
913
+ /**
914
+ * Add a trashcan.
915
+ *
916
+ * @internal
917
+ */
918
+ addTrashcan() {
919
+ this.trashcan = WorkspaceSvg.newTrashcan(this);
920
+ const svgTrashcan = this.trashcan.createDom();
921
+ this.svgGroup_.insertBefore(svgTrashcan, this.getCanvas());
922
+ }
923
+
924
+ /**
925
+ * @param _workspace
926
+ * @internal
927
+ */
928
+ static newTrashcan(_workspace: WorkspaceSvg): Trashcan {
929
+ throw new Error(
930
+ 'The implementation of newTrashcan should be ' +
931
+ 'monkey-patched in by blockly.ts',
932
+ );
933
+ }
934
+
935
+ /**
936
+ * Add zoom controls.
937
+ *
938
+ * @internal
939
+ */
940
+ addZoomControls() {
941
+ this.zoomControls_ = new ZoomControls(this);
942
+ const svgZoomControls = this.zoomControls_.createDom();
943
+ this.svgGroup_.appendChild(svgZoomControls);
944
+ }
945
+
946
+ /**
947
+ * Add a flyout element in an element with the given tag name.
948
+ *
949
+ * @param tagName What type of tag the flyout belongs in.
950
+ * @returns The element containing the flyout DOM.
951
+ * @internal
952
+ */
953
+ addFlyout(tagName: string | Svg<SVGSVGElement> | Svg<SVGGElement>): Element {
954
+ const workspaceOptions = new Options({
955
+ 'parentWorkspace': this,
956
+ 'rtl': this.RTL,
957
+ 'oneBasedIndex': this.options.oneBasedIndex,
958
+ 'horizontalLayout': this.horizontalLayout,
959
+ 'renderer': this.options.renderer,
960
+ 'rendererOverrides': this.options.rendererOverrides,
961
+ 'move': {
962
+ 'scrollbars': true,
963
+ },
964
+ } as BlocklyOptions);
965
+ workspaceOptions.toolboxPosition = this.options.toolboxPosition;
966
+ if (this.horizontalLayout) {
967
+ const HorizontalFlyout = registry.getClassFromOptions(
968
+ registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX,
969
+ this.options,
970
+ true,
971
+ );
972
+ this.flyout = new HorizontalFlyout!(workspaceOptions);
973
+ } else {
974
+ const VerticalFlyout = registry.getClassFromOptions(
975
+ registry.Type.FLYOUTS_VERTICAL_TOOLBOX,
976
+ this.options,
977
+ true,
978
+ );
979
+ this.flyout = new VerticalFlyout!(workspaceOptions);
980
+ }
981
+ this.flyout.autoClose = false;
982
+ this.flyout.getWorkspace().setVisible(true);
983
+
984
+ // Return the element so that callers can place it in their desired
985
+ // spot in the DOM. For example, mutator flyouts do not go in the same
986
+ // place as main workspace flyouts.
987
+ return this.flyout.createDom(tagName);
988
+ }
989
+
990
+ /**
991
+ * Getter for the flyout associated with this workspace. This flyout may be
992
+ * owned by either the toolbox or the workspace, depending on toolbox
993
+ * configuration. It will be null if there is no flyout.
994
+ *
995
+ * @param opt_own Whether to only return the workspace's own flyout.
996
+ * @returns The flyout on this workspace.
997
+ */
998
+ getFlyout(opt_own?: boolean): IFlyout | null {
999
+ if (this.flyout || opt_own) {
1000
+ return this.flyout;
1001
+ }
1002
+ if (this.toolbox_) {
1003
+ return this.toolbox_.getFlyout();
1004
+ }
1005
+ return null;
1006
+ }
1007
+
1008
+ /**
1009
+ * Getter for the toolbox associated with this workspace, if one exists.
1010
+ *
1011
+ * @returns The toolbox on this workspace.
1012
+ */
1013
+ getToolbox(): IToolbox | null {
1014
+ return this.toolbox_;
1015
+ }
1016
+
1017
+ /**
1018
+ * Update items that use screen coordinate calculations
1019
+ * because something has changed (e.g. scroll position, window size).
1020
+ */
1021
+ private updateScreenCalculations_() {
1022
+ this.updateInverseScreenCTM();
1023
+ this.recordDragTargets();
1024
+ }
1025
+
1026
+ /**
1027
+ * If enabled, resize the parts of the workspace that change when the
1028
+ * workspace contents (e.g. block positions) change. This will also scroll
1029
+ * the workspace contents if needed.
1030
+ *
1031
+ * @internal
1032
+ */
1033
+ resizeContents() {
1034
+ if (!this.resizesEnabled || !this.rendered) {
1035
+ return;
1036
+ }
1037
+ if (this.scrollbar) {
1038
+ this.scrollbar.resize();
1039
+ }
1040
+ this.updateInverseScreenCTM();
1041
+ }
1042
+
1043
+ /**
1044
+ * Resize and reposition all of the workspace chrome (toolbox,
1045
+ * trash, scrollbars etc.)
1046
+ * This should be called when something changes that
1047
+ * requires recalculating dimensions and positions of the
1048
+ * trash, zoom, toolbox, etc. (e.g. window resize).
1049
+ */
1050
+ resize() {
1051
+ if (this.toolbox_) {
1052
+ this.toolbox_.position();
1053
+ } else if (this.flyout) {
1054
+ this.flyout.position();
1055
+ }
1056
+
1057
+ const positionables = this.componentManager.getComponents(
1058
+ ComponentManager.Capability.POSITIONABLE,
1059
+ true,
1060
+ );
1061
+ const metrics = this.getMetricsManager().getUiMetrics();
1062
+ const savedPositions = [];
1063
+ for (let i = 0, positionable; (positionable = positionables[i]); i++) {
1064
+ positionable.position(metrics, savedPositions);
1065
+ const boundingRect = positionable.getBoundingRectangle();
1066
+ if (boundingRect) {
1067
+ savedPositions.push(boundingRect);
1068
+ }
1069
+ }
1070
+
1071
+ if (this.scrollbar) {
1072
+ this.scrollbar.resize();
1073
+ }
1074
+ this.updateScreenCalculations_();
1075
+ }
1076
+
1077
+ /**
1078
+ * Resizes and repositions workspace chrome if the page has a new
1079
+ * scroll position.
1080
+ *
1081
+ * @internal
1082
+ */
1083
+ updateScreenCalculationsIfScrolled() {
1084
+ /* eslint-disable indent */
1085
+ const currScroll = svgMath.getDocumentScroll();
1086
+ if (!Coordinate.equals(this.lastRecordedPageScroll, currScroll)) {
1087
+ this.lastRecordedPageScroll = currScroll;
1088
+ this.updateScreenCalculations_();
1089
+ }
1090
+ }
1091
+ /* eslint-enable indent */
1092
+
1093
+ /**
1094
+ * @returns The layer manager for this workspace.
1095
+ */
1096
+ getLayerManager(): LayerManager | null {
1097
+ return this.layerManager;
1098
+ }
1099
+
1100
+ /**
1101
+ * Get the SVG element that forms the drawing surface.
1102
+ *
1103
+ * @returns SVG group element.
1104
+ */
1105
+ getCanvas(): SVGGElement {
1106
+ return this.layerManager!.getBlockLayer();
1107
+ }
1108
+
1109
+ /**
1110
+ * Caches the width and height of the workspace's parent SVG element for use
1111
+ * with getSvgMetrics.
1112
+ *
1113
+ * @param width The width of the parent SVG element.
1114
+ * @param height The height of the parent SVG element
1115
+ * @internal
1116
+ */
1117
+ setCachedParentSvgSize(width: number | null, height: number | null) {
1118
+ const svg = this.getParentSvg();
1119
+ if (width != null) {
1120
+ this.cachedParentSvgSize.width = width;
1121
+ // This is set to support the public (but deprecated) Blockly.svgSize
1122
+ // method.
1123
+ svg.setAttribute('data-cached-width', `${width}`);
1124
+ }
1125
+ if (height != null) {
1126
+ this.cachedParentSvgSize.height = height;
1127
+ // This is set to support the public (but deprecated) Blockly.svgSize
1128
+ // method.
1129
+ svg.setAttribute('data-cached-height', `${height}`);
1130
+ }
1131
+ }
1132
+
1133
+ /**
1134
+ * Get the SVG element that forms the bubble surface.
1135
+ *
1136
+ * @returns SVG group element.
1137
+ */
1138
+ getBubbleCanvas(): SVGGElement {
1139
+ return this.layerManager!.getBubbleLayer();
1140
+ }
1141
+
1142
+ /**
1143
+ * Get the SVG element that contains this workspace.
1144
+ * Note: We assume this is only called after the workspace has been injected
1145
+ * into the DOM.
1146
+ *
1147
+ * @returns SVG element.
1148
+ */
1149
+ getParentSvg(): SVGSVGElement {
1150
+ if (!this.cachedParentSvg) {
1151
+ let element = this.svgGroup_;
1152
+ while (element) {
1153
+ if (element.tagName === 'svg') {
1154
+ this.cachedParentSvg = element;
1155
+ break;
1156
+ }
1157
+ element = element.parentNode as SVGSVGElement;
1158
+ }
1159
+ }
1160
+ return this.cachedParentSvg as SVGSVGElement;
1161
+ }
1162
+
1163
+ /**
1164
+ * Fires a viewport event if events are enabled and there is a change in
1165
+ * viewport values.
1166
+ *
1167
+ * @internal
1168
+ */
1169
+ maybeFireViewportChangeEvent() {
1170
+ if (!eventUtils.isEnabled()) {
1171
+ return;
1172
+ }
1173
+ const scale = this.scale;
1174
+ const top = -this.scrollY;
1175
+ const left = -this.scrollX;
1176
+ if (
1177
+ scale === this.oldScale &&
1178
+ Math.abs(top - this.oldTop) < 1 &&
1179
+ Math.abs(left - this.oldLeft) < 1
1180
+ ) {
1181
+ // Ignore sub-pixel changes in top and left. Due to #4192 there are a lot
1182
+ // of negligible changes in viewport top/left.
1183
+ return;
1184
+ }
1185
+ const event = new (eventUtils.get(eventUtils.VIEWPORT_CHANGE))(
1186
+ top,
1187
+ left,
1188
+ scale,
1189
+ this.id,
1190
+ this.oldScale,
1191
+ );
1192
+ this.oldScale = scale;
1193
+ this.oldTop = top;
1194
+ this.oldLeft = left;
1195
+ eventUtils.fire(event);
1196
+ }
1197
+
1198
+ /**
1199
+ * Translate this workspace to new coordinates.
1200
+ *
1201
+ * @param x Horizontal translation, in pixel units relative to the top left of
1202
+ * the Blockly div.
1203
+ * @param y Vertical translation, in pixel units relative to the top left of
1204
+ * the Blockly div.
1205
+ */
1206
+ translate(x: number, y: number) {
1207
+ this.layerManager?.translateLayers(new Coordinate(x, y), this.scale);
1208
+ this.grid?.moveTo(x, y);
1209
+ this.maybeFireViewportChangeEvent();
1210
+ }
1211
+
1212
+ /**
1213
+ * Returns the horizontal offset of the workspace.
1214
+ * Intended for LTR/RTL compatibility in XML.
1215
+ *
1216
+ * @returns Width.
1217
+ */
1218
+ override getWidth(): number {
1219
+ const metrics = this.getMetrics();
1220
+ return metrics ? metrics.viewWidth / this.scale : 0;
1221
+ }
1222
+
1223
+ /**
1224
+ * Toggles the visibility of the workspace.
1225
+ * Currently only intended for main workspace.
1226
+ *
1227
+ * @param isVisible True if workspace should be visible.
1228
+ */
1229
+ setVisible(isVisible: boolean) {
1230
+ this.isVisible_ = isVisible;
1231
+ if (!this.svgGroup_) {
1232
+ return;
1233
+ }
1234
+
1235
+ // Tell the scrollbar whether its container is visible so it can
1236
+ // tell when to hide itself.
1237
+ if (this.scrollbar) {
1238
+ this.scrollbar.setContainerVisible(isVisible);
1239
+ }
1240
+
1241
+ // Tell the flyout whether its container is visible so it can
1242
+ // tell when to hide itself.
1243
+ if (this.getFlyout()) {
1244
+ this.getFlyout()!.setContainerVisible(isVisible);
1245
+ }
1246
+
1247
+ this.getParentSvg().style.display = isVisible ? 'block' : 'none';
1248
+ if (this.toolbox_) {
1249
+ // Currently does not support toolboxes in mutators.
1250
+ this.toolbox_.setVisible(isVisible);
1251
+ }
1252
+ if (!isVisible) {
1253
+ this.hideChaff(true);
1254
+ }
1255
+ }
1256
+
1257
+ /**
1258
+ * Render all blocks in workspace.
1259
+ */
1260
+ render() {
1261
+ // Generate list of all blocks.
1262
+ const blocks = this.getAllBlocks(false);
1263
+ // Render each block.
1264
+ for (let i = blocks.length - 1; i >= 0; i--) {
1265
+ blocks[i].queueRender();
1266
+ }
1267
+
1268
+ this.getTopBlocks()
1269
+ .flatMap((block) => block.getDescendants(false))
1270
+ .filter((block) => block.isInsertionMarker())
1271
+ .forEach((block) => block.queueRender());
1272
+
1273
+ renderManagement
1274
+ .finishQueuedRenders()
1275
+ .then(() => void this.markerManager.updateMarkers());
1276
+ }
1277
+
1278
+ /**
1279
+ * Highlight or unhighlight a block in the workspace. Block highlighting is
1280
+ * often used to visually mark blocks currently being executed.
1281
+ *
1282
+ * @param id ID of block to highlight/unhighlight, or null for no block (used
1283
+ * to unhighlight all blocks).
1284
+ * @param opt_state If undefined, highlight specified block and automatically
1285
+ * unhighlight all others. If true or false, manually
1286
+ * highlight/unhighlight the specified block.
1287
+ */
1288
+ highlightBlock(id: string | null, opt_state?: boolean) {
1289
+ if (opt_state === undefined) {
1290
+ // Unhighlight all blocks.
1291
+ for (let i = 0, block; (block = this.highlightedBlocks[i]); i++) {
1292
+ block.setHighlighted(false);
1293
+ }
1294
+ this.highlightedBlocks.length = 0;
1295
+ }
1296
+ // Highlight/unhighlight the specified block.
1297
+ const block = id ? this.getBlockById(id) : null;
1298
+ if (block) {
1299
+ const state = opt_state === undefined || opt_state;
1300
+ // Using Set here would be great, but at the cost of IE10 support.
1301
+ if (!state) {
1302
+ arrayUtils.removeElem(this.highlightedBlocks, block);
1303
+ } else if (!this.highlightedBlocks.includes(block)) {
1304
+ this.highlightedBlocks.push(block);
1305
+ }
1306
+ block.setHighlighted(state);
1307
+ }
1308
+ }
1309
+
1310
+ /**
1311
+ * Refresh the toolbox unless there's a drag in progress.
1312
+ *
1313
+ * @internal
1314
+ */
1315
+ refreshToolboxSelection() {
1316
+ const ws = this.isFlyout ? this.targetWorkspace : this;
1317
+ if (ws && !ws.currentGesture_ && ws.toolbox_ && ws.toolbox_.getFlyout()) {
1318
+ ws.toolbox_.refreshSelection();
1319
+ }
1320
+ }
1321
+
1322
+ /**
1323
+ * Rename a variable by updating its name in the variable map. Update the
1324
+ * flyout to show the renamed variable immediately.
1325
+ *
1326
+ * @param id ID of the variable to rename.
1327
+ * @param newName New variable name.
1328
+ */
1329
+ override renameVariableById(id: string, newName: string) {
1330
+ super.renameVariableById(id, newName);
1331
+ this.refreshToolboxSelection();
1332
+ }
1333
+
1334
+ /**
1335
+ * Delete a variable by the passed in ID. Update the flyout to show
1336
+ * immediately that the variable is deleted.
1337
+ *
1338
+ * @param id ID of variable to delete.
1339
+ */
1340
+ override deleteVariableById(id: string) {
1341
+ super.deleteVariableById(id);
1342
+ this.refreshToolboxSelection();
1343
+ }
1344
+
1345
+ /**
1346
+ * Create a new variable with the given name. Update the flyout to show the
1347
+ * new variable immediately.
1348
+ *
1349
+ * @param name The new variable's name.
1350
+ * @param opt_type The type of the variable like 'int' or 'string'.
1351
+ * Does not need to be unique. Field_variable can filter variables based
1352
+ * on their type. This will default to '' which is a specific type.
1353
+ * @param opt_id The unique ID of the variable. This will default to a UUID.
1354
+ * @returns The newly created variable.
1355
+ */
1356
+ override createVariable(
1357
+ name: string,
1358
+ opt_type?: string | null,
1359
+ opt_id?: string | null,
1360
+ ): IVariableModel<IVariableState> {
1361
+ const newVar = super.createVariable(name, opt_type, opt_id);
1362
+ this.refreshToolboxSelection();
1363
+ return newVar;
1364
+ }
1365
+
1366
+ /** Make a list of all the delete areas for this workspace. */
1367
+ recordDragTargets() {
1368
+ const dragTargets = this.componentManager.getComponents(
1369
+ ComponentManager.Capability.DRAG_TARGET,
1370
+ true,
1371
+ );
1372
+
1373
+ this.dragTargetAreas = [];
1374
+ for (let i = 0, targetArea; (targetArea = dragTargets[i]); i++) {
1375
+ const rect = targetArea.getClientRect();
1376
+ if (rect) {
1377
+ this.dragTargetAreas.push({
1378
+ component: targetArea,
1379
+ clientRect: rect,
1380
+ });
1381
+ }
1382
+ }
1383
+ }
1384
+ /* eslint-disable jsdoc/require-returns-check */
1385
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1386
+ /**
1387
+ * Obtain a newly created block.
1388
+ *
1389
+ * @param prototypeName Name of the language object containing type-specific
1390
+ * functions for this block.
1391
+ * @param opt_id Optional ID. Use this ID if provided, otherwise create a new
1392
+ * ID.
1393
+ * @returns The created block.
1394
+ */
1395
+ override newBlock(prototypeName: string, opt_id?: string): BlockSvg {
1396
+ throw new Error(
1397
+ 'The implementation of newBlock should be ' +
1398
+ 'monkey-patched in by blockly.ts',
1399
+ );
1400
+ }
1401
+
1402
+ /**
1403
+ * Obtain a newly created comment.
1404
+ *
1405
+ * @param id Optional ID. Use this ID if provided, otherwise create a new
1406
+ * ID.
1407
+ * @returns The created comment.
1408
+ */
1409
+ newComment(id?: string): WorkspaceComment {
1410
+ throw new Error(
1411
+ 'The implementation of newComment should be ' +
1412
+ 'monkey-patched in by blockly.ts',
1413
+ );
1414
+ }
1415
+ /* eslint-enable */
1416
+
1417
+ /**
1418
+ * Returns the drag target the pointer event is over.
1419
+ *
1420
+ * @param e Pointer move event.
1421
+ * @returns Null if not over a drag target, or the drag target the event is
1422
+ * over.
1423
+ */
1424
+ getDragTarget(e: PointerEvent): IDragTarget | null {
1425
+ for (let i = 0, targetArea; (targetArea = this.dragTargetAreas[i]); i++) {
1426
+ if (targetArea.clientRect.contains(e.clientX, e.clientY)) {
1427
+ return targetArea.component;
1428
+ }
1429
+ }
1430
+ return null;
1431
+ }
1432
+
1433
+ /**
1434
+ * Handle a pointerdown on SVG drawing surface.
1435
+ *
1436
+ * @param e Pointer down event.
1437
+ */
1438
+ private onMouseDown_(e: PointerEvent) {
1439
+ const gesture = this.getGesture(e);
1440
+ if (gesture) {
1441
+ gesture.handleWsStart(e, this);
1442
+ }
1443
+ }
1444
+
1445
+ /**
1446
+ * Start tracking a drag of an object on this workspace.
1447
+ *
1448
+ * @param e Pointer down event.
1449
+ * @param xy Starting location of object.
1450
+ */
1451
+ startDrag(e: PointerEvent, xy: Coordinate) {
1452
+ // Record the starting offset between the bubble's location and the mouse.
1453
+ const point = browserEvents.mouseToSvg(
1454
+ e,
1455
+ this.getParentSvg(),
1456
+ this.getInverseScreenCTM(),
1457
+ );
1458
+ // Fix scale of mouse event.
1459
+ point.x /= this.scale;
1460
+ point.y /= this.scale;
1461
+ this.dragDeltaXY = Coordinate.difference(xy, point);
1462
+ }
1463
+
1464
+ /**
1465
+ * Track a drag of an object on this workspace.
1466
+ *
1467
+ * @param e Pointer move event.
1468
+ * @returns New location of object.
1469
+ */
1470
+ moveDrag(e: PointerEvent): Coordinate {
1471
+ const point = browserEvents.mouseToSvg(
1472
+ e,
1473
+ this.getParentSvg(),
1474
+ this.getInverseScreenCTM(),
1475
+ );
1476
+ // Fix scale of mouse event.
1477
+ point.x /= this.scale;
1478
+ point.y /= this.scale;
1479
+ return Coordinate.sum(this.dragDeltaXY!, point);
1480
+ }
1481
+
1482
+ /**
1483
+ * Is the user currently dragging a block or scrolling the flyout/workspace?
1484
+ *
1485
+ * @returns True if currently dragging or scrolling.
1486
+ */
1487
+ isDragging(): boolean {
1488
+ return this.currentGesture_ !== null && this.currentGesture_.isDragging();
1489
+ }
1490
+
1491
+ /**
1492
+ * Is this workspace draggable?
1493
+ *
1494
+ * @returns True if this workspace may be dragged.
1495
+ */
1496
+ isDraggable(): boolean {
1497
+ return this.options.moveOptions && this.options.moveOptions.drag;
1498
+ }
1499
+
1500
+ /**
1501
+ * Is this workspace movable?
1502
+ *
1503
+ * This means the user can reposition the X Y coordinates of the workspace
1504
+ * through input. This can be through scrollbars, scroll wheel, dragging, or
1505
+ * through zooming with the scroll wheel or pinch (since the zoom is centered
1506
+ * on the mouse position). This does not include zooming with the zoom
1507
+ * controls since the X Y coordinates are decided programmatically.
1508
+ *
1509
+ * @returns True if the workspace is movable, false otherwise.
1510
+ */
1511
+ isMovable(): boolean {
1512
+ return (
1513
+ (this.options.moveOptions && !!this.options.moveOptions.scrollbars) ||
1514
+ (this.options.moveOptions && this.options.moveOptions.wheel) ||
1515
+ (this.options.moveOptions && this.options.moveOptions.drag) ||
1516
+ (this.options.zoomOptions && this.options.zoomOptions.wheel) ||
1517
+ (this.options.zoomOptions && this.options.zoomOptions.pinch)
1518
+ );
1519
+ }
1520
+
1521
+ /**
1522
+ * Is this workspace movable horizontally?
1523
+ *
1524
+ * @returns True if the workspace is movable horizontally, false otherwise.
1525
+ */
1526
+ isMovableHorizontally(): boolean {
1527
+ const hasScrollbars = !!this.scrollbar;
1528
+ return (
1529
+ this.isMovable() &&
1530
+ (!hasScrollbars ||
1531
+ (hasScrollbars && this.scrollbar!.canScrollHorizontally()))
1532
+ );
1533
+ }
1534
+
1535
+ /**
1536
+ * Is this workspace movable vertically?
1537
+ *
1538
+ * @returns True if the workspace is movable vertically, false otherwise.
1539
+ */
1540
+ isMovableVertically(): boolean {
1541
+ const hasScrollbars = !!this.scrollbar;
1542
+ return (
1543
+ this.isMovable() &&
1544
+ (!hasScrollbars ||
1545
+ (hasScrollbars && this.scrollbar!.canScrollVertically()))
1546
+ );
1547
+ }
1548
+
1549
+ /**
1550
+ * Handle a mouse-wheel on SVG drawing surface.
1551
+ *
1552
+ * @param e Mouse wheel event.
1553
+ */
1554
+ private onMouseWheel_(e: WheelEvent) {
1555
+ // Don't scroll or zoom anything if drag is in progress.
1556
+ if (Gesture.inProgress()) {
1557
+ e.preventDefault();
1558
+ e.stopPropagation();
1559
+ return;
1560
+ }
1561
+ const canWheelZoom =
1562
+ this.options.zoomOptions && this.options.zoomOptions.wheel;
1563
+ const canWheelMove =
1564
+ this.options.moveOptions && this.options.moveOptions.wheel;
1565
+ if (!canWheelZoom && !canWheelMove) {
1566
+ return;
1567
+ }
1568
+
1569
+ const scrollDelta = browserEvents.getScrollDeltaPixels(e);
1570
+
1571
+ // Zoom should also be enabled by the command key on Mac devices,
1572
+ // but not super on Unix.
1573
+ let commandKey;
1574
+ if (userAgent.MAC) {
1575
+ commandKey = e.metaKey;
1576
+ }
1577
+
1578
+ if (canWheelZoom && (e.ctrlKey || commandKey || !canWheelMove)) {
1579
+ // Zoom.
1580
+ // The vertical scroll distance that corresponds to a click of a zoom
1581
+ // button.
1582
+ const PIXELS_PER_ZOOM_STEP = 50;
1583
+ const delta = -scrollDelta.y / PIXELS_PER_ZOOM_STEP;
1584
+ const position = browserEvents.mouseToSvg(
1585
+ e,
1586
+ this.getParentSvg(),
1587
+ this.getInverseScreenCTM(),
1588
+ );
1589
+ this.zoom(position.x, position.y, delta);
1590
+ } else {
1591
+ // Scroll.
1592
+ let x = this.scrollX - scrollDelta.x;
1593
+ let y = this.scrollY - scrollDelta.y;
1594
+
1595
+ if (e.shiftKey && !scrollDelta.x) {
1596
+ // Scroll horizontally (based on vertical scroll delta).
1597
+ // This is needed as for some browser/system combinations which do not
1598
+ // set deltaX.
1599
+ x = this.scrollX - scrollDelta.y;
1600
+ y = this.scrollY; // Don't scroll vertically.
1601
+ }
1602
+ this.scroll(x, y);
1603
+ }
1604
+ e.preventDefault();
1605
+ }
1606
+
1607
+ /**
1608
+ * Calculate the bounding box for the blocks on the workspace.
1609
+ * Coordinate system: workspace coordinates.
1610
+ *
1611
+ * @returns Contains the position and size of the bounding box containing the
1612
+ * blocks on the workspace.
1613
+ */
1614
+ getBlocksBoundingBox(): Rect {
1615
+ const topElements = this.getTopBoundedElements();
1616
+ // There are no blocks, return empty rectangle.
1617
+ if (!topElements.length) {
1618
+ return new Rect(0, 0, 0, 0);
1619
+ }
1620
+
1621
+ // Initialize boundary using the first block.
1622
+ const boundary = topElements[0].getBoundingRectangle();
1623
+
1624
+ // Start at 1 since the 0th block was used for initialization.
1625
+ for (let i = 1; i < topElements.length; i++) {
1626
+ const topElement = topElements[i];
1627
+ if (
1628
+ (topElement as any).isInsertionMarker &&
1629
+ (topElement as any).isInsertionMarker()
1630
+ ) {
1631
+ continue;
1632
+ }
1633
+ const blockBoundary = topElement.getBoundingRectangle();
1634
+ if (blockBoundary.top < boundary.top) {
1635
+ boundary.top = blockBoundary.top;
1636
+ }
1637
+ if (blockBoundary.bottom > boundary.bottom) {
1638
+ boundary.bottom = blockBoundary.bottom;
1639
+ }
1640
+ if (blockBoundary.left < boundary.left) {
1641
+ boundary.left = blockBoundary.left;
1642
+ }
1643
+ if (blockBoundary.right > boundary.right) {
1644
+ boundary.right = blockBoundary.right;
1645
+ }
1646
+ }
1647
+ return boundary;
1648
+ }
1649
+
1650
+ /** Clean up the workspace by ordering all the blocks in a column. */
1651
+ cleanUp() {
1652
+ this.setResizesEnabled(false);
1653
+ eventUtils.setGroup(true);
1654
+ const topBlocks = this.getTopBlocks(true);
1655
+ let cursorY = 0;
1656
+ for (let i = 0, block; (block = topBlocks[i]); i++) {
1657
+ if (!block.isMovable()) {
1658
+ continue;
1659
+ }
1660
+ const xy = block.getRelativeToSurfaceXY();
1661
+ block.moveBy(-xy.x, cursorY - xy.y, ['cleanup']);
1662
+ block.snapToGrid();
1663
+ cursorY =
1664
+ block.getRelativeToSurfaceXY().y +
1665
+ block.getHeightWidth().height +
1666
+ this.renderer.getConstants().MIN_BLOCK_HEIGHT;
1667
+ }
1668
+ eventUtils.setGroup(false);
1669
+ this.setResizesEnabled(true);
1670
+ }
1671
+
1672
+ /**
1673
+ * Show the context menu for the workspace.
1674
+ *
1675
+ * @param e Mouse event.
1676
+ * @internal
1677
+ */
1678
+ showContextMenu(e: PointerEvent) {
1679
+ if (this.options.readOnly || this.isFlyout) {
1680
+ return;
1681
+ }
1682
+ const menuOptions = ContextMenuRegistry.registry.getContextMenuOptions(
1683
+ ContextMenuRegistry.ScopeType.WORKSPACE,
1684
+ {workspace: this},
1685
+ );
1686
+
1687
+ // Allow the developer to add or modify menuOptions.
1688
+ if (this.configureContextMenu) {
1689
+ this.configureContextMenu(menuOptions, e);
1690
+ }
1691
+
1692
+ ContextMenu.show(e, menuOptions, this.RTL, this);
1693
+ }
1694
+
1695
+ /**
1696
+ * Modify the block tree on the existing toolbox.
1697
+ *
1698
+ * @param toolboxDef DOM tree of toolbox contents, string of toolbox contents,
1699
+ * or JSON representing toolbox definition.
1700
+ */
1701
+ updateToolbox(toolboxDef: toolbox.ToolboxDefinition | null) {
1702
+ const parsedToolboxDef = toolbox.convertToolboxDefToJson(toolboxDef);
1703
+
1704
+ if (!parsedToolboxDef) {
1705
+ if (this.options.languageTree) {
1706
+ throw Error("Can't nullify an existing toolbox.");
1707
+ }
1708
+ return; // No change (null to null).
1709
+ }
1710
+ if (!this.options.languageTree) {
1711
+ throw Error("Existing toolbox is null. Can't create new toolbox.");
1712
+ }
1713
+
1714
+ if (toolbox.hasCategories(parsedToolboxDef)) {
1715
+ if (!this.toolbox_) {
1716
+ throw Error("Existing toolbox has no categories. Can't change mode.");
1717
+ }
1718
+ this.options.languageTree = parsedToolboxDef;
1719
+ this.toolbox_.render(parsedToolboxDef);
1720
+ } else {
1721
+ if (!this.flyout) {
1722
+ throw Error("Existing toolbox has categories. Can't change mode.");
1723
+ }
1724
+ this.options.languageTree = parsedToolboxDef;
1725
+ this.flyout.show(parsedToolboxDef);
1726
+ }
1727
+ }
1728
+
1729
+ /** Mark this workspace as the currently focused main workspace. */
1730
+ markFocused() {
1731
+ if (this.options.parentWorkspace) {
1732
+ this.options.parentWorkspace.markFocused();
1733
+ } else {
1734
+ common.setMainWorkspace(this);
1735
+ // We call e.preventDefault in many event handlers which means we
1736
+ // need to explicitly grab focus (e.g from a textarea) because
1737
+ // the browser will not do it for us.
1738
+ this.getParentSvg().focus({preventScroll: true});
1739
+ }
1740
+ }
1741
+
1742
+ /**
1743
+ * Zooms the workspace in or out relative to/centered on the given (x, y)
1744
+ * coordinate.
1745
+ *
1746
+ * @param x X coordinate of center, in pixel units relative to the top-left
1747
+ * corner of the parentSVG.
1748
+ * @param y Y coordinate of center, in pixel units relative to the top-left
1749
+ * corner of the parentSVG.
1750
+ * @param amount Amount of zooming. The formula for the new scale is newScale
1751
+ * = currentScale * (scaleSpeed^amount). scaleSpeed is set in the
1752
+ * workspace options. Negative amount values zoom out, and positive amount
1753
+ * values zoom in.
1754
+ */
1755
+ zoom(x: number, y: number, amount: number) {
1756
+ // Scale factor.
1757
+ const speed = this.options.zoomOptions.scaleSpeed;
1758
+ let scaleChange = Math.pow(speed, amount);
1759
+ const newScale = this.scale * scaleChange;
1760
+ if (this.scale === newScale) {
1761
+ return; // No change in zoom.
1762
+ }
1763
+
1764
+ // Clamp scale within valid range.
1765
+ if (newScale > this.options.zoomOptions.maxScale) {
1766
+ scaleChange = this.options.zoomOptions.maxScale / this.scale;
1767
+ } else if (newScale < this.options.zoomOptions.minScale) {
1768
+ scaleChange = this.options.zoomOptions.minScale / this.scale;
1769
+ }
1770
+
1771
+ // Transform the x/y coordinates from the parentSVG's space into the
1772
+ // canvas' space, so that they are in workspace units relative to the top
1773
+ // left of the visible portion of the workspace.
1774
+ let matrix = this.getCanvas().getCTM();
1775
+ let center = this.getParentSvg().createSVGPoint();
1776
+ center.x = x;
1777
+ center.y = y;
1778
+ center = center.matrixTransform(matrix!.inverse());
1779
+ x = center.x;
1780
+ y = center.y;
1781
+
1782
+ // Find the new scrollX/scrollY so that the center remains in the same
1783
+ // position (relative to the center) after we zoom.
1784
+ // newScale and matrix.a should be identical (within a rounding error).
1785
+ matrix = matrix!
1786
+ .translate(x * (1 - scaleChange), y * (1 - scaleChange))
1787
+ .scale(scaleChange);
1788
+ // scrollX and scrollY are in pixels.
1789
+ // The scrollX and scrollY still need to have absoluteLeft and absoluteTop
1790
+ // subtracted from them, but we'll leave that for setScale so that they're
1791
+ // correctly updated for the new flyout size if we have a simple toolbox.
1792
+ this.scrollX = matrix.e;
1793
+ this.scrollY = matrix.f;
1794
+ this.setScale(newScale);
1795
+ }
1796
+
1797
+ /**
1798
+ * Zooming the blocks centered in the center of view with zooming in or out.
1799
+ *
1800
+ * @param type Type of zooming (-1 zooming out and 1 zooming in).
1801
+ */
1802
+ zoomCenter(type: number) {
1803
+ const metrics = this.getMetrics();
1804
+ let x;
1805
+ let y;
1806
+ if (this.flyout) {
1807
+ // If you want blocks in the center of the view (visible portion of the
1808
+ // workspace) to stay centered when the size of the view decreases (i.e.
1809
+ // when the size of the flyout increases) you need the center of the
1810
+ // *blockly div* to stay in the same pixel-position.
1811
+ // Note: This only works because of how scrollCenter positions blocks.
1812
+ x = metrics.svgWidth ? metrics.svgWidth / 2 : 0;
1813
+ y = metrics.svgHeight ? metrics.svgHeight / 2 : 0;
1814
+ } else {
1815
+ x = metrics.viewWidth / 2 + metrics.absoluteLeft;
1816
+ y = metrics.viewHeight / 2 + metrics.absoluteTop;
1817
+ }
1818
+ this.zoom(x, y, type);
1819
+ }
1820
+
1821
+ /** Zoom the blocks to fit in the workspace if possible. */
1822
+ zoomToFit() {
1823
+ if (!this.isMovable()) {
1824
+ console.warn(
1825
+ 'Tried to move a non-movable workspace. This could result' +
1826
+ ' in blocks becoming inaccessible.',
1827
+ );
1828
+ return;
1829
+ }
1830
+
1831
+ const metrics = this.getMetrics();
1832
+ let workspaceWidth = metrics.viewWidth;
1833
+ let workspaceHeight = metrics.viewHeight;
1834
+ const blocksBox = this.getBlocksBoundingBox();
1835
+ const doubleMargin = ZOOM_TO_FIT_MARGIN * 2;
1836
+ let blocksWidth = blocksBox.right - blocksBox.left + doubleMargin;
1837
+ let blocksHeight = blocksBox.bottom - blocksBox.top + doubleMargin;
1838
+ if (!blocksWidth) {
1839
+ return; // Prevents zooming to infinity.
1840
+ }
1841
+ if (this.flyout) {
1842
+ // We have to add the flyout size to both the workspace size and the
1843
+ // block size because the blocks we want to resize include the blocks in
1844
+ // the flyout, and the area we want to fit them includes the portion of
1845
+ // the workspace that is behind the flyout.
1846
+ if (this.horizontalLayout) {
1847
+ workspaceHeight += this.flyout.getHeight();
1848
+ // Convert from pixels to workspace coordinates.
1849
+ blocksHeight += this.flyout.getHeight() / this.scale;
1850
+ } else {
1851
+ workspaceWidth += this.flyout.getWidth();
1852
+ // Convert from pixels to workspace coordinates.
1853
+ blocksWidth += this.flyout.getWidth() / this.scale;
1854
+ }
1855
+ }
1856
+
1857
+ // Scale Units: (pixels / workspaceUnit)
1858
+ const ratioX = workspaceWidth / blocksWidth;
1859
+ const ratioY = workspaceHeight / blocksHeight;
1860
+ eventUtils.disable();
1861
+ try {
1862
+ this.setScale(Math.min(ratioX, ratioY));
1863
+ this.scrollCenter();
1864
+ } finally {
1865
+ eventUtils.enable();
1866
+ }
1867
+ this.maybeFireViewportChangeEvent();
1868
+ }
1869
+
1870
+ /**
1871
+ * Add a transition class to the block and bubble canvas, to animate any
1872
+ * transform changes.
1873
+ *
1874
+ * @internal
1875
+ */
1876
+ beginCanvasTransition() {
1877
+ dom.addClass(this.getCanvas(), 'blocklyCanvasTransitioning');
1878
+ dom.addClass(this.getBubbleCanvas(), 'blocklyCanvasTransitioning');
1879
+ }
1880
+
1881
+ /**
1882
+ * Remove transition class from the block and bubble canvas.
1883
+ *
1884
+ * @internal
1885
+ */
1886
+ endCanvasTransition() {
1887
+ dom.removeClass(this.getCanvas(), 'blocklyCanvasTransitioning');
1888
+ dom.removeClass(this.getBubbleCanvas(), 'blocklyCanvasTransitioning');
1889
+ }
1890
+
1891
+ /** Center the workspace. */
1892
+ scrollCenter() {
1893
+ if (!this.isMovable()) {
1894
+ console.warn(
1895
+ 'Tried to move a non-movable workspace. This could result' +
1896
+ ' in blocks becoming inaccessible.',
1897
+ );
1898
+ return;
1899
+ }
1900
+
1901
+ const metrics = this.getMetrics();
1902
+ let x = (metrics.scrollWidth - metrics.viewWidth) / 2;
1903
+ let y = (metrics.scrollHeight - metrics.viewHeight) / 2;
1904
+
1905
+ // Convert from workspace directions to canvas directions.
1906
+ x = -x - metrics.scrollLeft;
1907
+ y = -y - metrics.scrollTop;
1908
+ this.scroll(x, y);
1909
+ }
1910
+
1911
+ /**
1912
+ * Scroll the workspace to center on the given block. If the block has other
1913
+ * blocks stacked below it, the workspace will be centered on the stack,
1914
+ * unless blockOnly is true.
1915
+ *
1916
+ * @param id ID of block center on.
1917
+ * @param blockOnly True to center only on the block itself, not its stack.
1918
+ */
1919
+ centerOnBlock(id: string | null, blockOnly?: boolean) {
1920
+ if (!this.isMovable()) {
1921
+ console.warn(
1922
+ 'Tried to move a non-movable workspace. This could result' +
1923
+ ' in blocks becoming inaccessible.',
1924
+ );
1925
+ return;
1926
+ }
1927
+
1928
+ const block = id ? this.getBlockById(id) : null;
1929
+ if (!block) {
1930
+ return;
1931
+ }
1932
+
1933
+ // XY is in workspace coordinates.
1934
+ const xy = block.getRelativeToSurfaceXY();
1935
+ // Height/width is in workspace units.
1936
+ const heightWidth = blockOnly
1937
+ ? {height: block.height, width: block.width}
1938
+ : block.getHeightWidth();
1939
+
1940
+ // Find the enter of the block in workspace units.
1941
+ const blockCenterY = xy.y + heightWidth.height / 2;
1942
+
1943
+ // In RTL the block's position is the top right of the block, not top left.
1944
+ const multiplier = this.RTL ? -1 : 1;
1945
+ const blockCenterX = xy.x + (multiplier * heightWidth.width) / 2;
1946
+
1947
+ // Workspace scale, used to convert from workspace coordinates to pixels.
1948
+ const scale = this.scale;
1949
+
1950
+ // Center of block in pixels, relative to workspace origin (center 0,0).
1951
+ // Scrolling to here would put the block in the top-left corner of the
1952
+ // visible workspace.
1953
+ const pixelX = blockCenterX * scale;
1954
+ const pixelY = blockCenterY * scale;
1955
+
1956
+ const metrics = this.getMetrics();
1957
+
1958
+ // viewHeight and viewWidth are in pixels.
1959
+ const halfViewWidth = metrics.viewWidth / 2;
1960
+ const halfViewHeight = metrics.viewHeight / 2;
1961
+
1962
+ // Put the block in the center of the visible workspace instead.
1963
+ const scrollToCenterX = pixelX - halfViewWidth;
1964
+ const scrollToCenterY = pixelY - halfViewHeight;
1965
+
1966
+ // Convert from workspace directions to canvas directions.
1967
+ const x = -scrollToCenterX;
1968
+ const y = -scrollToCenterY;
1969
+
1970
+ this.scroll(x, y);
1971
+ }
1972
+
1973
+ /**
1974
+ * Set the workspace's zoom factor.
1975
+ *
1976
+ * @param newScale Zoom factor. Units: (pixels / workspaceUnit).
1977
+ */
1978
+ setScale(newScale: number) {
1979
+ if (
1980
+ this.options.zoomOptions.maxScale &&
1981
+ newScale > this.options.zoomOptions.maxScale
1982
+ ) {
1983
+ newScale = this.options.zoomOptions.maxScale;
1984
+ } else if (
1985
+ this.options.zoomOptions.minScale &&
1986
+ newScale < this.options.zoomOptions.minScale
1987
+ ) {
1988
+ newScale = this.options.zoomOptions.minScale;
1989
+ }
1990
+ this.scale = newScale;
1991
+
1992
+ this.hideChaff(false);
1993
+ // Get the flyout, if any, whether our own or owned by the toolbox.
1994
+ const flyout = this.getFlyout(false);
1995
+ if (flyout && flyout.isVisible()) {
1996
+ flyout.reflow();
1997
+ this.recordDragTargets();
1998
+ }
1999
+ if (this.grid) {
2000
+ this.grid.update(this.scale);
2001
+ }
2002
+
2003
+ // We call scroll instead of scrollbar.resize() so that we can center the
2004
+ // zoom correctly without scrollbars, but scroll does not resize the
2005
+ // scrollbars so we have to call resizeView/resizeContent as well.
2006
+ const metrics = this.getMetrics();
2007
+
2008
+ this.scrollX -= metrics.absoluteLeft;
2009
+ this.scrollY -= metrics.absoluteTop;
2010
+ // The scroll values and the view values are additive inverses of
2011
+ // each other, so when we subtract from one we have to add to the other.
2012
+ metrics.viewLeft += metrics.absoluteLeft;
2013
+ metrics.viewTop += metrics.absoluteTop;
2014
+
2015
+ this.scroll(this.scrollX, this.scrollY);
2016
+ if (this.scrollbar) {
2017
+ if (this.flyout) {
2018
+ this.scrollbar.resizeView(metrics);
2019
+ } else {
2020
+ this.scrollbar.resizeContent(metrics);
2021
+ }
2022
+ }
2023
+ }
2024
+
2025
+ /**
2026
+ * Get the workspace's zoom factor.
2027
+ *
2028
+ * @returns The workspace zoom factor. Units: (pixels / workspaceUnit).
2029
+ */
2030
+ getScale(): number {
2031
+ return this.scale;
2032
+ }
2033
+
2034
+ /**
2035
+ * Returns the absolute scale of the workspace.
2036
+ *
2037
+ * Workspace scaling is multiplicative; if a workspace B (e.g. a mutator editor)
2038
+ * with scale Y is nested within a root workspace A with scale X, workspace B's
2039
+ * effective scale is X * Y, because, as a child of A, it is already transformed
2040
+ * by A's scaling factor, and then further transforms itself by its own scaling
2041
+ * factor. Normally this Just Works, but for global elements (e.g. field
2042
+ * editors) that are visually associated with a particular workspace but live at
2043
+ * the top level of the DOM rather than being a child of their associated
2044
+ * workspace, the absolute/effective scale may be needed to render
2045
+ * appropriately.
2046
+ *
2047
+ * @returns The absolute/effective scale of the given workspace.
2048
+ */
2049
+ getAbsoluteScale() {
2050
+ // Returns a workspace's own scale, without regard to multiplicative scaling.
2051
+ const getLocalScale = (workspace: WorkspaceSvg): number => {
2052
+ // Workspaces in flyouts may have a distinct scale; use this if relevant.
2053
+ if (workspace.isFlyout) {
2054
+ const flyout = workspace.targetWorkspace?.getFlyout();
2055
+ if (flyout instanceof Flyout) {
2056
+ return flyout.getFlyoutScale();
2057
+ }
2058
+ }
2059
+
2060
+ return workspace.getScale();
2061
+ };
2062
+
2063
+ const computeScale = (workspace: WorkspaceSvg, scale: number): number => {
2064
+ // If the workspace has no parent, or it does have a parent but is not
2065
+ // actually a child of its parent workspace in the DOM (this is the case for
2066
+ // flyouts in the main workspace), we're done; just return the scale so far
2067
+ // multiplied by the workspace's own scale.
2068
+ if (
2069
+ !workspace.options.parentWorkspace ||
2070
+ !workspace.options.parentWorkspace
2071
+ .getSvgGroup()
2072
+ .contains(workspace.getSvgGroup())
2073
+ ) {
2074
+ return scale * getLocalScale(workspace);
2075
+ }
2076
+
2077
+ // If there is a parent workspace, and this workspace is a child of it in
2078
+ // the DOM, scales are multiplicative, so recurse up the workspace
2079
+ // hierarchy.
2080
+ return computeScale(
2081
+ workspace.options.parentWorkspace,
2082
+ scale * getLocalScale(workspace),
2083
+ );
2084
+ };
2085
+
2086
+ return computeScale(this, 1);
2087
+ }
2088
+
2089
+ /**
2090
+ * Scroll the workspace to a specified offset (in pixels), keeping in the
2091
+ * workspace bounds. See comment on workspaceSvg.scrollX for more detail on
2092
+ * the meaning of these values.
2093
+ *
2094
+ * @param x Target X to scroll to.
2095
+ * @param y Target Y to scroll to.
2096
+ */
2097
+ scroll(x: number, y: number) {
2098
+ this.hideChaff(/* opt_onlyClosePopups= */ true);
2099
+
2100
+ // Keep scrolling within the bounds of the content.
2101
+ const metrics = this.getMetrics();
2102
+ // Canvas coordinates (aka scroll coordinates) have inverse directionality
2103
+ // to workspace coordinates so we have to inverse them.
2104
+ x = Math.min(x, -metrics.scrollLeft);
2105
+ y = Math.min(y, -metrics.scrollTop);
2106
+ const maxXDisplacement = Math.max(
2107
+ 0,
2108
+ metrics.scrollWidth - metrics.viewWidth,
2109
+ );
2110
+ const maxXScroll = metrics.scrollLeft + maxXDisplacement;
2111
+ const maxYDisplacement = Math.max(
2112
+ 0,
2113
+ metrics.scrollHeight - metrics.viewHeight,
2114
+ );
2115
+ const maxYScroll = metrics.scrollTop + maxYDisplacement;
2116
+ x = Math.max(x, -maxXScroll);
2117
+ y = Math.max(y, -maxYScroll);
2118
+ this.scrollX = x;
2119
+ this.scrollY = y;
2120
+
2121
+ if (this.scrollbar) {
2122
+ // The content position (displacement from the content's top-left to the
2123
+ // origin) plus the scroll position (displacement from the view's top-left
2124
+ // to the origin) gives us the distance from the view's top-left to the
2125
+ // content's top-left. Then we negate this so we get the displacement from
2126
+ // the content's top-left to the view's top-left, matching the
2127
+ // directionality of the scrollbars.
2128
+ this.scrollbar.set(
2129
+ -(x + metrics.scrollLeft),
2130
+ -(y + metrics.scrollTop),
2131
+ false,
2132
+ );
2133
+ }
2134
+ // We have to shift the translation so that when the canvas is at 0, 0 the
2135
+ // workspace origin is not underneath the toolbox.
2136
+ x += metrics.absoluteLeft;
2137
+ y += metrics.absoluteTop;
2138
+ this.translate(x, y);
2139
+ }
2140
+
2141
+ /**
2142
+ * Find the block on this workspace with the specified ID.
2143
+ *
2144
+ * @param id ID of block to find.
2145
+ * @returns The sought after block, or null if not found.
2146
+ */
2147
+ override getBlockById(id: string): BlockSvg | null {
2148
+ return super.getBlockById(id) as BlockSvg;
2149
+ }
2150
+
2151
+ /**
2152
+ * Find all blocks in workspace. Blocks are optionally sorted
2153
+ * by position; top to bottom (with slight LTR or RTL bias).
2154
+ *
2155
+ * @param ordered Sort the list if true.
2156
+ * @returns Array of blocks.
2157
+ */
2158
+ override getAllBlocks(ordered = false): BlockSvg[] {
2159
+ return super.getAllBlocks(ordered) as BlockSvg[];
2160
+ }
2161
+
2162
+ /**
2163
+ * Finds the top-level blocks and returns them. Blocks are optionally sorted
2164
+ * by position; top to bottom (with slight LTR or RTL bias).
2165
+ *
2166
+ * @param ordered Sort the list if true.
2167
+ * @returns The top-level block objects.
2168
+ */
2169
+ override getTopBlocks(ordered = false): BlockSvg[] {
2170
+ return super.getTopBlocks(ordered) as BlockSvg[];
2171
+ }
2172
+
2173
+ /**
2174
+ * Adds a block to the list of top blocks.
2175
+ *
2176
+ * @param block Block to add.
2177
+ */
2178
+ override addTopBlock(block: Block) {
2179
+ this.addTopBoundedElement(block as BlockSvg);
2180
+ super.addTopBlock(block);
2181
+ }
2182
+
2183
+ /**
2184
+ * Removes a block from the list of top blocks.
2185
+ *
2186
+ * @param block Block to remove.
2187
+ */
2188
+ override removeTopBlock(block: Block) {
2189
+ this.removeTopBoundedElement(block as BlockSvg);
2190
+ super.removeTopBlock(block);
2191
+ }
2192
+
2193
+ /**
2194
+ * Adds a comment to the list of top comments.
2195
+ *
2196
+ * @param comment comment to add.
2197
+ */
2198
+ override addTopComment(comment: WorkspaceComment) {
2199
+ this.addTopBoundedElement(comment as RenderedWorkspaceComment);
2200
+ super.addTopComment(comment);
2201
+ }
2202
+
2203
+ /**
2204
+ * Removes a comment from the list of top comments.
2205
+ *
2206
+ * @param comment comment to remove.
2207
+ */
2208
+ override removeTopComment(comment: WorkspaceComment) {
2209
+ this.removeTopBoundedElement(comment as RenderedWorkspaceComment);
2210
+ super.removeTopComment(comment);
2211
+ }
2212
+
2213
+ override getRootWorkspace(): WorkspaceSvg | null {
2214
+ return super.getRootWorkspace() as WorkspaceSvg | null;
2215
+ }
2216
+
2217
+ /**
2218
+ * Adds a bounded element to the list of top bounded elements.
2219
+ *
2220
+ * @param element Bounded element to add.
2221
+ */
2222
+ addTopBoundedElement(element: IBoundedElement) {
2223
+ this.topBoundedElements.push(element);
2224
+ }
2225
+
2226
+ /**
2227
+ * Removes a bounded element from the list of top bounded elements.
2228
+ *
2229
+ * @param element Bounded element to remove.
2230
+ */
2231
+ removeTopBoundedElement(element: IBoundedElement) {
2232
+ arrayUtils.removeElem(this.topBoundedElements, element);
2233
+ }
2234
+
2235
+ /**
2236
+ * Finds the top-level bounded elements and returns them.
2237
+ *
2238
+ * @returns The top-level bounded elements.
2239
+ */
2240
+ getTopBoundedElements(): IBoundedElement[] {
2241
+ return new Array<IBoundedElement>().concat(this.topBoundedElements);
2242
+ }
2243
+
2244
+ /**
2245
+ * Update whether this workspace has resizes enabled.
2246
+ * If enabled, workspace will resize when appropriate.
2247
+ * If disabled, workspace will not resize until re-enabled.
2248
+ * Use to avoid resizing during a batch operation, for performance.
2249
+ *
2250
+ * @param enabled Whether resizes should be enabled.
2251
+ */
2252
+ setResizesEnabled(enabled: boolean) {
2253
+ const reenabled = !this.resizesEnabled && enabled;
2254
+ this.resizesEnabled = enabled;
2255
+ if (reenabled) {
2256
+ // Newly enabled. Trigger a resize.
2257
+ this.resizeContents();
2258
+ }
2259
+ }
2260
+
2261
+ /**
2262
+ * Dispose of all blocks in workspace, with an optimization to prevent
2263
+ * resizes.
2264
+ */
2265
+ override clear() {
2266
+ this.setResizesEnabled(false);
2267
+ super.clear();
2268
+ this.topBoundedElements = [];
2269
+ this.setResizesEnabled(true);
2270
+ }
2271
+
2272
+ /**
2273
+ * Register a callback function associated with a given key, for clicks on
2274
+ * buttons and labels in the flyout.
2275
+ * For instance, a button specified by the XML
2276
+ * <button text="create variable" callbackKey="CREATE_VARIABLE"></button>
2277
+ * should be matched by a call to
2278
+ * registerButtonCallback("CREATE_VARIABLE", yourCallbackFunction).
2279
+ *
2280
+ * @param key The name to use to look up this function.
2281
+ * @param func The function to call when the given button is clicked.
2282
+ */
2283
+ registerButtonCallback(key: string, func: (p1: FlyoutButton) => void) {
2284
+ if (typeof func !== 'function') {
2285
+ throw TypeError('Button callbacks must be functions.');
2286
+ }
2287
+ this.flyoutButtonCallbacks.set(key, func);
2288
+ }
2289
+
2290
+ /**
2291
+ * Get the callback function associated with a given key, for clicks on
2292
+ * buttons and labels in the flyout.
2293
+ *
2294
+ * @param key The name to use to look up the function.
2295
+ * @returns The function corresponding to the given key for this workspace;
2296
+ * null if no callback is registered.
2297
+ */
2298
+ getButtonCallback(key: string): ((p1: FlyoutButton) => void) | null {
2299
+ return this.flyoutButtonCallbacks.get(key) ?? null;
2300
+ }
2301
+
2302
+ /**
2303
+ * Remove a callback for a click on a button in the flyout.
2304
+ *
2305
+ * @param key The name associated with the callback function.
2306
+ */
2307
+ removeButtonCallback(key: string) {
2308
+ this.flyoutButtonCallbacks.delete(key);
2309
+ }
2310
+
2311
+ /**
2312
+ * Register a callback function associated with a given key, for populating
2313
+ * custom toolbox categories in this workspace. See the variable and
2314
+ * procedure categories as an example.
2315
+ *
2316
+ * @param key The name to use to look up this function.
2317
+ * @param func The function to call when the given toolbox category is opened.
2318
+ */
2319
+ registerToolboxCategoryCallback(
2320
+ key: string,
2321
+ func: (p1: WorkspaceSvg) => toolbox.FlyoutDefinition,
2322
+ ) {
2323
+ if (typeof func !== 'function') {
2324
+ throw TypeError('Toolbox category callbacks must be functions.');
2325
+ }
2326
+ this.toolboxCategoryCallbacks.set(key, func);
2327
+ }
2328
+
2329
+ /**
2330
+ * Get the callback function associated with a given key, for populating
2331
+ * custom toolbox categories in this workspace.
2332
+ *
2333
+ * @param key The name to use to look up the function.
2334
+ * @returns The function corresponding to the given key for this workspace, or
2335
+ * null if no function is registered.
2336
+ */
2337
+ getToolboxCategoryCallback(
2338
+ key: string,
2339
+ ): ((p1: WorkspaceSvg) => toolbox.FlyoutDefinition) | null {
2340
+ return this.toolboxCategoryCallbacks.get(key) || null;
2341
+ }
2342
+
2343
+ /**
2344
+ * Remove a callback for a click on a custom category's name in the toolbox.
2345
+ *
2346
+ * @param key The name associated with the callback function.
2347
+ */
2348
+ removeToolboxCategoryCallback(key: string) {
2349
+ this.toolboxCategoryCallbacks.delete(key);
2350
+ }
2351
+
2352
+ /**
2353
+ * Look up the gesture that is tracking this touch stream on this workspace.
2354
+ * May create a new gesture.
2355
+ *
2356
+ * @param e Pointer event.
2357
+ * @returns The gesture that is tracking this touch stream, or null if no
2358
+ * valid gesture exists.
2359
+ * @internal
2360
+ */
2361
+ getGesture(e: PointerEvent): Gesture | null {
2362
+ const isStart = e.type === 'pointerdown';
2363
+
2364
+ const gesture = this.currentGesture_;
2365
+ if (gesture) {
2366
+ if (isStart && gesture.hasStarted()) {
2367
+ console.warn('Tried to start the same gesture twice.');
2368
+ // That's funny. We must have missed a mouse up.
2369
+ // Cancel it, rather than try to retrieve all of the state we need.
2370
+ gesture.cancel();
2371
+ return null;
2372
+ }
2373
+ return gesture;
2374
+ }
2375
+
2376
+ // No gesture existed on this workspace, but this looks like the start of a
2377
+ // new gesture.
2378
+ if (isStart) {
2379
+ this.currentGesture_ = new Gesture(e, this);
2380
+ return this.currentGesture_;
2381
+ }
2382
+ // No gesture existed and this event couldn't be the start of a new gesture.
2383
+ return null;
2384
+ }
2385
+
2386
+ /**
2387
+ * Clear the reference to the current gesture.
2388
+ *
2389
+ * @internal
2390
+ */
2391
+ clearGesture() {
2392
+ this.currentGesture_ = null;
2393
+ }
2394
+
2395
+ /**
2396
+ * Cancel the current gesture, if one exists.
2397
+ *
2398
+ * @internal
2399
+ */
2400
+ cancelCurrentGesture() {
2401
+ if (this.currentGesture_) {
2402
+ this.currentGesture_.cancel();
2403
+ }
2404
+ }
2405
+
2406
+ /**
2407
+ * Get the audio manager for this workspace.
2408
+ *
2409
+ * @returns The audio manager for this workspace.
2410
+ */
2411
+ getAudioManager(): WorkspaceAudio {
2412
+ return this.audioManager;
2413
+ }
2414
+
2415
+ /**
2416
+ * Get the grid object for this workspace, or null if there is none.
2417
+ *
2418
+ * @returns The grid object for this workspace.
2419
+ */
2420
+ getGrid(): Grid | null {
2421
+ return this.grid;
2422
+ }
2423
+
2424
+ /**
2425
+ * Close tooltips, context menus, dropdown selections, etc.
2426
+ *
2427
+ * @param onlyClosePopups Whether only popups should be closed. Defaults to
2428
+ * false.
2429
+ */
2430
+ hideChaff(onlyClosePopups = false) {
2431
+ Tooltip.hide();
2432
+ WidgetDiv.hideIfOwnerIsInWorkspace(this);
2433
+ dropDownDiv.hideWithoutAnimation();
2434
+
2435
+ this.hideComponents(onlyClosePopups);
2436
+ }
2437
+
2438
+ /**
2439
+ * Hide any autohideable components (like flyout, trashcan, and any
2440
+ * user-registered components).
2441
+ *
2442
+ * @param onlyClosePopups Whether only popups should be closed. Defaults to
2443
+ * false.
2444
+ */
2445
+ hideComponents(onlyClosePopups = false) {
2446
+ const autoHideables = this.getComponentManager().getComponents(
2447
+ ComponentManager.Capability.AUTOHIDEABLE,
2448
+ true,
2449
+ );
2450
+ autoHideables.forEach((autoHideable) =>
2451
+ autoHideable.autoHide(onlyClosePopups),
2452
+ );
2453
+ }
2454
+
2455
+ /**
2456
+ * Sets the X/Y translations of a top level workspace.
2457
+ *
2458
+ * @param xyRatio Contains an x and/or y property which is a float between 0
2459
+ * and 1 specifying the degree of scrolling.
2460
+ */
2461
+ private static setTopLevelWorkspaceMetrics_(
2462
+ this: WorkspaceSvg,
2463
+ xyRatio: {x?: number; y?: number},
2464
+ ) {
2465
+ const metrics = this.getMetrics();
2466
+
2467
+ if (typeof xyRatio.x === 'number') {
2468
+ this.scrollX = -(
2469
+ metrics.scrollLeft +
2470
+ (metrics.scrollWidth - metrics.viewWidth) * xyRatio.x
2471
+ );
2472
+ }
2473
+ if (typeof xyRatio.y === 'number') {
2474
+ this.scrollY = -(
2475
+ metrics.scrollTop +
2476
+ (metrics.scrollHeight - metrics.viewHeight) * xyRatio.y
2477
+ );
2478
+ }
2479
+ // We have to shift the translation so that when the canvas is at 0, 0 the
2480
+ // workspace origin is not underneath the toolbox.
2481
+ const x = this.scrollX + metrics.absoluteLeft;
2482
+ const y = this.scrollY + metrics.absoluteTop;
2483
+ // We could call scroll here, but that has extra checks we don't need to do.
2484
+ this.translate(x, y);
2485
+ }
2486
+
2487
+ /**
2488
+ * Adds a CSS class to the workspace.
2489
+ *
2490
+ * @param className Name of class to add.
2491
+ */
2492
+ addClass(className: string) {
2493
+ if (this.injectionDiv) {
2494
+ dom.addClass(this.injectionDiv, className);
2495
+ }
2496
+ }
2497
+
2498
+ /**
2499
+ * Removes a CSS class from the workspace.
2500
+ *
2501
+ * @param className Name of class to remove.
2502
+ */
2503
+ removeClass(className: string) {
2504
+ if (this.injectionDiv) {
2505
+ dom.removeClass(this.injectionDiv, className);
2506
+ }
2507
+ }
2508
+ }
2509
+
2510
+ /**
2511
+ * Size the workspace when the contents change. This also updates
2512
+ * scrollbars accordingly.
2513
+ *
2514
+ * @param workspace The workspace to resize.
2515
+ * @internal
2516
+ */
2517
+ export function resizeSvgContents(workspace: WorkspaceSvg) {
2518
+ workspace.resizeContents();
2519
+ }