blockly 7.20211209.4 → 8.0.0

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 (262) hide show
  1. package/blockly.d.ts +18963 -18432
  2. package/blockly.min.js +852 -844
  3. package/blockly_compressed.js +669 -664
  4. package/blockly_compressed.js.map +1 -1
  5. package/blocks/blocks.js +47 -0
  6. package/blocks/colour.js +13 -3
  7. package/blocks/lists.js +22 -13
  8. package/blocks/logic.js +13 -3
  9. package/blocks/loops.js +24 -11
  10. package/blocks/math.js +12 -3
  11. package/blocks/procedures.js +41 -27
  12. package/blocks/text.js +22 -13
  13. package/blocks/variables.js +14 -3
  14. package/blocks/variables_dynamic.js +13 -3
  15. package/blocks_compressed.js +146 -141
  16. package/blocks_compressed.js.map +1 -1
  17. package/core/block.js +1869 -1814
  18. package/core/block_drag_surface.js +201 -200
  19. package/core/block_dragger.js +377 -373
  20. package/core/block_svg.js +1593 -1479
  21. package/core/blockly.js +8 -22
  22. package/core/blocks.js +9 -2
  23. package/core/browser_events.js +22 -5
  24. package/core/bubble.js +841 -797
  25. package/core/bubble_dragger.js +213 -206
  26. package/core/bump_objects.js +2 -2
  27. package/core/clipboard.js +9 -9
  28. package/core/comment.js +353 -332
  29. package/core/common.js +46 -17
  30. package/core/component_manager.js +181 -174
  31. package/core/config.js +87 -0
  32. package/core/connection.js +595 -584
  33. package/core/connection_checker.js +242 -244
  34. package/core/connection_db.js +235 -230
  35. package/core/contextmenu.js +9 -6
  36. package/core/contextmenu_items.js +1 -2
  37. package/core/contextmenu_registry.js +93 -89
  38. package/core/css.js +474 -474
  39. package/core/delete_area.js +45 -42
  40. package/core/drag_target.js +57 -56
  41. package/core/dropdowndiv.js +153 -163
  42. package/core/events/events.js +2 -2
  43. package/core/events/events_abstract.js +89 -77
  44. package/core/events/events_block_base.js +37 -36
  45. package/core/events/events_block_change.js +130 -124
  46. package/core/events/events_block_create.js +73 -71
  47. package/core/events/events_block_delete.js +84 -82
  48. package/core/events/events_block_drag.js +50 -49
  49. package/core/events/events_block_move.js +147 -140
  50. package/core/events/events_bubble_open.js +51 -50
  51. package/core/events/events_click.js +48 -44
  52. package/core/events/events_comment_base.js +72 -69
  53. package/core/events/events_comment_change.js +63 -61
  54. package/core/events/events_comment_create.js +44 -42
  55. package/core/events/events_comment_delete.js +42 -40
  56. package/core/events/events_comment_move.js +106 -104
  57. package/core/events/events_marker_move.js +65 -64
  58. package/core/events/events_selected.js +46 -45
  59. package/core/events/events_theme_change.js +36 -35
  60. package/core/events/events_toolbox_item_select.js +46 -45
  61. package/core/events/events_trashcan_open.js +37 -36
  62. package/core/events/events_ui.js +47 -46
  63. package/core/events/events_ui_base.js +30 -29
  64. package/core/events/events_var_base.js +37 -36
  65. package/core/events/events_var_create.js +50 -48
  66. package/core/events/events_var_delete.js +50 -48
  67. package/core/events/events_var_rename.js +51 -49
  68. package/core/events/events_viewport.js +66 -65
  69. package/core/events/utils.js +29 -14
  70. package/core/events/workspace_events.js +49 -55
  71. package/core/extensions.js +4 -3
  72. package/core/field.js +1061 -997
  73. package/core/field_angle.js +462 -442
  74. package/core/field_checkbox.js +194 -182
  75. package/core/field_colour.js +519 -505
  76. package/core/field_dropdown.js +617 -598
  77. package/core/field_image.js +229 -220
  78. package/core/field_label.js +102 -91
  79. package/core/field_label_serializable.js +42 -41
  80. package/core/field_multilineinput.js +372 -358
  81. package/core/field_number.js +272 -253
  82. package/core/field_textinput.js +499 -467
  83. package/core/field_variable.js +458 -420
  84. package/core/flyout_base.js +1005 -952
  85. package/core/flyout_button.js +277 -260
  86. package/core/flyout_horizontal.js +304 -302
  87. package/core/flyout_metrics_manager.js +64 -64
  88. package/core/flyout_vertical.js +306 -300
  89. package/core/generator.js +459 -446
  90. package/core/gesture.js +829 -813
  91. package/core/grid.js +166 -163
  92. package/core/icon.js +168 -159
  93. package/core/inject.js +7 -5
  94. package/core/input.js +257 -248
  95. package/core/insertion_marker_manager.js +655 -624
  96. package/core/internal_constants.js +0 -129
  97. package/core/keyboard_nav/ast_node.js +605 -596
  98. package/core/keyboard_nav/basic_cursor.js +166 -165
  99. package/core/keyboard_nav/cursor.js +99 -97
  100. package/core/keyboard_nav/marker.js +83 -79
  101. package/core/keyboard_nav/tab_navigate_cursor.js +18 -23
  102. package/core/marker_manager.js +153 -141
  103. package/core/menu.js +377 -372
  104. package/core/menuitem.js +223 -217
  105. package/core/metrics_manager.js +403 -390
  106. package/core/mutator.js +468 -437
  107. package/core/names.js +229 -188
  108. package/core/options.js +290 -284
  109. package/core/procedures.js +29 -17
  110. package/core/registry.js +19 -16
  111. package/core/rendered_connection.js +482 -463
  112. package/core/renderers/common/block_rendering.js +9 -3
  113. package/core/renderers/common/constants.js +1119 -1112
  114. package/core/renderers/common/debug.js +14 -0
  115. package/core/renderers/common/debugger.js +338 -316
  116. package/core/renderers/common/drawer.js +380 -370
  117. package/core/renderers/common/i_path_object.js +2 -2
  118. package/core/renderers/common/info.js +626 -618
  119. package/core/renderers/common/marker_svg.js +579 -541
  120. package/core/renderers/common/path_object.js +203 -200
  121. package/core/renderers/common/renderer.js +220 -218
  122. package/core/renderers/geras/constants.js +36 -36
  123. package/core/renderers/geras/drawer.js +155 -147
  124. package/core/renderers/geras/highlight_constants.js +244 -238
  125. package/core/renderers/geras/highlighter.js +231 -179
  126. package/core/renderers/geras/info.js +392 -369
  127. package/core/renderers/geras/measurables/inline_input.js +25 -19
  128. package/core/renderers/geras/measurables/statement_input.js +23 -17
  129. package/core/renderers/geras/path_object.js +106 -121
  130. package/core/renderers/geras/renderer.js +96 -98
  131. package/core/renderers/measurables/base.js +30 -18
  132. package/core/renderers/measurables/bottom_row.js +83 -80
  133. package/core/renderers/measurables/connection.js +22 -15
  134. package/core/renderers/measurables/external_value_input.js +35 -22
  135. package/core/renderers/measurables/field.js +35 -20
  136. package/core/renderers/measurables/hat.js +18 -13
  137. package/core/renderers/measurables/icon.js +24 -17
  138. package/core/renderers/measurables/in_row_spacer.js +15 -13
  139. package/core/renderers/measurables/inline_input.js +43 -33
  140. package/core/renderers/measurables/input_connection.js +41 -28
  141. package/core/renderers/measurables/input_row.js +50 -44
  142. package/core/renderers/measurables/jagged_edge.js +14 -12
  143. package/core/renderers/measurables/next_connection.js +16 -14
  144. package/core/renderers/measurables/output_connection.js +26 -20
  145. package/core/renderers/measurables/previous_connection.js +16 -15
  146. package/core/renderers/measurables/round_corner.js +20 -18
  147. package/core/renderers/measurables/row.js +184 -168
  148. package/core/renderers/measurables/spacer_row.js +38 -23
  149. package/core/renderers/measurables/square_corner.js +18 -16
  150. package/core/renderers/measurables/statement_input.js +23 -20
  151. package/core/renderers/measurables/top_row.js +88 -85
  152. package/core/renderers/minimalist/constants.js +8 -7
  153. package/core/renderers/minimalist/drawer.js +11 -10
  154. package/core/renderers/minimalist/info.js +18 -18
  155. package/core/renderers/minimalist/renderer.js +40 -39
  156. package/core/renderers/thrasos/info.js +258 -248
  157. package/core/renderers/thrasos/renderer.js +20 -20
  158. package/core/renderers/zelos/constants.js +898 -873
  159. package/core/renderers/zelos/drawer.js +186 -169
  160. package/core/renderers/zelos/info.js +502 -479
  161. package/core/renderers/zelos/marker_svg.js +129 -115
  162. package/core/renderers/zelos/measurables/bottom_row.js +31 -30
  163. package/core/renderers/zelos/measurables/inputs.js +22 -21
  164. package/core/renderers/zelos/measurables/row_elements.js +14 -13
  165. package/core/renderers/zelos/measurables/top_row.js +34 -33
  166. package/core/renderers/zelos/path_object.js +181 -180
  167. package/core/renderers/zelos/renderer.js +91 -92
  168. package/core/scrollbar.js +759 -713
  169. package/core/scrollbar_pair.js +250 -245
  170. package/core/serialization/blocks.js +19 -9
  171. package/core/serialization/workspaces.js +3 -2
  172. package/core/shortcut_registry.js +286 -277
  173. package/core/sprites.js +31 -0
  174. package/core/theme.js +135 -141
  175. package/core/theme_manager.js +147 -143
  176. package/core/toolbox/category.js +602 -576
  177. package/core/toolbox/collapsible_category.js +226 -227
  178. package/core/toolbox/separator.js +70 -61
  179. package/core/toolbox/toolbox.js +934 -927
  180. package/core/toolbox/toolbox_item.js +115 -99
  181. package/core/tooltip.js +108 -35
  182. package/core/touch.js +8 -3
  183. package/core/touch_gesture.js +254 -251
  184. package/core/trashcan.js +606 -595
  185. package/core/utils/coordinate.js +97 -95
  186. package/core/utils/dom.js +2 -2
  187. package/core/utils/global.js +2 -0
  188. package/core/utils/rect.js +41 -37
  189. package/core/utils/sentinel.js +25 -0
  190. package/core/utils/size.js +30 -27
  191. package/core/utils/svg.js +18 -16
  192. package/core/variable_map.js +325 -341
  193. package/core/variable_model.js +55 -54
  194. package/core/variables.js +9 -2
  195. package/core/variables_dynamic.js +3 -1
  196. package/core/warning.js +126 -120
  197. package/core/widgetdiv.js +4 -4
  198. package/core/workspace.js +685 -664
  199. package/core/workspace_audio.js +124 -118
  200. package/core/workspace_comment.js +308 -298
  201. package/core/workspace_comment_svg.js +1029 -951
  202. package/core/workspace_drag_surface_svg.js +147 -140
  203. package/core/workspace_dragger.js +70 -71
  204. package/core/workspace_svg.js +2322 -2297
  205. package/core/xml.js +30 -20
  206. package/core/zoom_controls.js +431 -439
  207. package/dart_compressed.js +40 -43
  208. package/dart_compressed.js.map +1 -1
  209. package/generators/dart/colour.js +56 -64
  210. package/generators/dart/lists.js +61 -50
  211. package/generators/dart/math.js +160 -148
  212. package/generators/dart/text.js +83 -61
  213. package/generators/javascript/colour.js +37 -34
  214. package/generators/javascript/lists.js +50 -43
  215. package/generators/javascript/math.js +123 -139
  216. package/generators/javascript/text.js +67 -81
  217. package/generators/lua/colour.js +25 -23
  218. package/generators/lua/lists.js +97 -69
  219. package/generators/lua/logic.js +1 -2
  220. package/generators/lua/math.js +182 -144
  221. package/generators/lua/text.js +116 -99
  222. package/generators/php/colour.js +38 -32
  223. package/generators/php/lists.js +109 -89
  224. package/generators/php/math.js +90 -81
  225. package/generators/php/text.js +63 -61
  226. package/generators/python/colour.js +18 -18
  227. package/generators/python/lists.js +38 -30
  228. package/generators/python/loops.js +12 -8
  229. package/generators/python/math.js +104 -106
  230. package/generators/python/text.js +34 -30
  231. package/javascript_compressed.js +37 -39
  232. package/javascript_compressed.js.map +1 -1
  233. package/lua_compressed.js +39 -42
  234. package/lua_compressed.js.map +1 -1
  235. package/msg/az.js +2 -2
  236. package/msg/be.js +4 -4
  237. package/msg/cs.js +15 -15
  238. package/msg/de.js +1 -1
  239. package/msg/diq.js +1 -1
  240. package/msg/eo.js +1 -1
  241. package/msg/es.js +1 -1
  242. package/msg/fa.js +1 -1
  243. package/msg/fr.js +4 -4
  244. package/msg/he.js +1 -1
  245. package/msg/hr.js +2 -2
  246. package/msg/hy.js +2 -2
  247. package/msg/id.js +12 -12
  248. package/msg/inh.js +14 -14
  249. package/msg/ja.js +7 -7
  250. package/msg/lv.js +29 -29
  251. package/msg/pa.js +3 -3
  252. package/msg/smn.js +436 -0
  253. package/msg/te.js +1 -1
  254. package/msg/yue.js +1 -1
  255. package/msg/zh-hans.js +3 -3
  256. package/msg/zh-hant.js +3 -3
  257. package/package.json +7 -6
  258. package/php_compressed.js +38 -42
  259. package/php_compressed.js.map +1 -1
  260. package/python_compressed.js +26 -25
  261. package/python_compressed.js.map +1 -1
  262. package/blocks/all.js +0 -23
@@ -31,1213 +31,1220 @@ const {Theme} = goog.requireType('Blockly.Theme');
31
31
 
32
32
  /**
33
33
  * An object that provides constants for rendering blocks.
34
- * @constructor
35
- * @package
36
34
  * @alias Blockly.blockRendering.ConstantProvider
37
35
  */
38
- const ConstantProvider = function() {
36
+ class ConstantProvider {
39
37
  /**
40
- * The size of an empty spacer.
41
- * @type {number}
42
- */
43
- this.NO_PADDING = 0;
44
-
45
- /**
46
- * The size of small padding.
47
- * @type {number}
48
- */
49
- this.SMALL_PADDING = 3;
50
-
51
- /**
52
- * The size of medium padding.
53
- * @type {number}
54
- */
55
- this.MEDIUM_PADDING = 5;
56
-
57
- /**
58
- * The size of medium-large padding.
59
- * @type {number}
60
- */
61
- this.MEDIUM_LARGE_PADDING = 8;
62
-
63
- /**
64
- * The size of large padding.
65
- * @type {number}
66
- */
67
- this.LARGE_PADDING = 10;
68
-
69
- /**
70
- * Offset from the top of the row for placing fields on inline input rows
71
- * and statement input rows.
72
- * Matches existing rendering (in 2019).
73
- * @type {number}
74
- */
75
- this.TALL_INPUT_FIELD_OFFSET_Y = this.MEDIUM_PADDING;
76
-
77
- /**
78
- * The height of the puzzle tab used for input and output connections.
79
- * @type {number}
80
- */
81
- this.TAB_HEIGHT = 15;
82
-
83
- /**
84
- * The offset from the top of the block at which a puzzle tab is positioned.
85
- * @type {number}
86
- */
87
- this.TAB_OFFSET_FROM_TOP = 5;
88
-
89
- /**
90
- * Vertical overlap of the puzzle tab, used to make it look more like a puzzle
91
- * piece.
92
- * @type {number}
93
- */
94
- this.TAB_VERTICAL_OVERLAP = 2.5;
95
-
96
- /**
97
- * The width of the puzzle tab used for input and output connections.
98
- * @type {number}
99
- */
100
- this.TAB_WIDTH = 8;
101
-
102
- /**
103
- * The width of the notch used for previous and next connections.
104
- * @type {number}
105
- */
106
- this.NOTCH_WIDTH = 15;
107
-
108
- /**
109
- * The height of the notch used for previous and next connections.
110
- * @type {number}
111
- */
112
- this.NOTCH_HEIGHT = 4;
113
-
114
- /**
115
- * The minimum width of the block.
116
- * @type {number}
117
- */
118
- this.MIN_BLOCK_WIDTH = 12;
119
-
120
- this.EMPTY_BLOCK_SPACER_HEIGHT = 16;
121
-
122
- /**
123
- * The minimum height of a dummy input row.
124
- * @type {number}
125
- */
126
- this.DUMMY_INPUT_MIN_HEIGHT = this.TAB_HEIGHT;
127
-
128
- /**
129
- * The minimum height of a dummy input row in a shadow block.
130
- * @type {number}
131
- */
132
- this.DUMMY_INPUT_SHADOW_MIN_HEIGHT = this.TAB_HEIGHT;
133
-
134
- /**
135
- * Rounded corner radius.
136
- * @type {number}
137
- */
138
- this.CORNER_RADIUS = 8;
139
-
140
- /**
141
- * Offset from the left side of a block or the inside of a statement input to
142
- * the left side of the notch.
143
- * @type {number}
144
- */
145
- this.NOTCH_OFFSET_LEFT = 15;
146
-
147
- /**
148
- * Additional offset added to the statement input's width to account for the
149
- * notch.
150
- * @type {number}
151
- */
152
- this.STATEMENT_INPUT_NOTCH_OFFSET = this.NOTCH_OFFSET_LEFT;
153
-
154
- this.STATEMENT_BOTTOM_SPACER = 0;
155
- this.STATEMENT_INPUT_PADDING_LEFT = 20;
156
-
157
- /**
158
- * Vertical padding between consecutive statement inputs.
159
- * @type {number}
160
- */
161
- this.BETWEEN_STATEMENT_PADDING_Y = 4;
162
-
163
- /**
164
- * The top row's minimum height.
165
- * @type {number}
166
- */
167
- this.TOP_ROW_MIN_HEIGHT = this.MEDIUM_PADDING;
168
-
169
- /**
170
- * The top row's minimum height if it precedes a statement.
171
- * @type {number}
172
- */
173
- this.TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT = this.LARGE_PADDING;
174
-
175
- /**
176
- * The bottom row's minimum height.
177
- * @type {number}
178
- */
179
- this.BOTTOM_ROW_MIN_HEIGHT = this.MEDIUM_PADDING;
180
-
181
- /**
182
- * The bottom row's minimum height if it follows a statement input.
183
- * @type {number}
184
- */
185
- this.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT = this.LARGE_PADDING;
186
-
187
- /**
188
- * Whether to add a 'hat' on top of all blocks with no previous or output
189
- * connections. Can be overridden by 'hat' property on Theme.BlockStyle.
190
- * @type {boolean}
191
- */
192
- this.ADD_START_HATS = false;
193
-
194
- /**
195
- * Height of the top hat.
196
- * @type {number}
197
- */
198
- this.START_HAT_HEIGHT = 15;
199
-
200
- /**
201
- * Width of the top hat.
202
- * @type {number}
203
- */
204
- this.START_HAT_WIDTH = 100;
205
-
206
- this.SPACER_DEFAULT_HEIGHT = 15;
207
-
208
- this.MIN_BLOCK_HEIGHT = 24;
209
-
210
- this.EMPTY_INLINE_INPUT_PADDING = 14.5;
211
-
212
- /**
213
- * The height of an empty inline input.
214
- * @type {number}
215
- */
216
- this.EMPTY_INLINE_INPUT_HEIGHT = this.TAB_HEIGHT + 11;
217
-
218
- this.EXTERNAL_VALUE_INPUT_PADDING = 2;
219
-
220
- /**
221
- * The height of an empty statement input. Note that in the old rendering
222
- * this varies slightly depending on whether the block has external or inline
223
- * inputs. In the new rendering this is consistent. It seems unlikely that
224
- * the old behaviour was intentional.
225
- * @type {number}
226
- */
227
- this.EMPTY_STATEMENT_INPUT_HEIGHT = this.MIN_BLOCK_HEIGHT;
228
-
229
- this.START_POINT = svgPaths.moveBy(0, 0);
230
-
231
- /**
232
- * Height of SVG path for jagged teeth at the end of collapsed blocks.
233
- * @type {number}
234
- */
235
- this.JAGGED_TEETH_HEIGHT = 12;
236
-
237
- /**
238
- * Width of SVG path for jagged teeth at the end of collapsed blocks.
239
- * @type {number}
240
- */
241
- this.JAGGED_TEETH_WIDTH = 6;
242
-
243
- /**
244
- * Point size of text.
245
- * @type {number}
246
- */
247
- this.FIELD_TEXT_FONTSIZE = 11;
248
-
249
- /**
250
- * Text font weight.
251
- * @type {string}
252
- */
253
- this.FIELD_TEXT_FONTWEIGHT = 'normal';
254
-
255
- /**
256
- * Text font family.
257
- * @type {string}
258
- */
259
- this.FIELD_TEXT_FONTFAMILY = 'sans-serif';
260
-
261
- /**
262
- * Height of text. This constant is dynamically set in ``setFontConstants_``
263
- * to be the height of the text based on the font used.
264
- * @type {number}
265
- */
266
- this.FIELD_TEXT_HEIGHT = -1; // Dynamically set.
267
-
268
- /**
269
- * Text baseline. This constant is dynamically set in ``setFontConstants_``
270
- * to be the baseline of the text based on the font used.
271
- * @type {number}
272
- */
273
- this.FIELD_TEXT_BASELINE = -1; // Dynamically set.
274
-
275
- /**
276
- * A field's border rect corner radius.
277
- * @type {number}
278
- */
279
- this.FIELD_BORDER_RECT_RADIUS = 4;
280
-
281
- /**
282
- * A field's border rect default height.
283
- * @type {number}
284
- */
285
- this.FIELD_BORDER_RECT_HEIGHT = 16;
286
-
287
- /**
288
- * A field's border rect X padding.
289
- * @type {number}
290
- */
291
- this.FIELD_BORDER_RECT_X_PADDING = 5;
292
-
293
- /**
294
- * A field's border rect Y padding.
295
- * @type {number}
296
- */
297
- this.FIELD_BORDER_RECT_Y_PADDING = 3;
298
-
299
- /**
300
- * The backing colour of a field's border rect.
301
- * @type {string}
302
38
  * @package
303
39
  */
304
- this.FIELD_BORDER_RECT_COLOUR = '#fff';
305
-
306
- /**
307
- * A field's text element's dominant baseline.
308
- * @type {boolean}
309
- */
310
- this.FIELD_TEXT_BASELINE_CENTER = !userAgent.IE && !userAgent.EDGE;
311
-
312
- /**
313
- * A dropdown field's border rect height.
314
- * @type {number}
315
- */
316
- this.FIELD_DROPDOWN_BORDER_RECT_HEIGHT = this.FIELD_BORDER_RECT_HEIGHT;
317
-
318
- /**
319
- * Whether or not a dropdown field should add a border rect when in a shadow
320
- * block.
321
- * @type {boolean}
322
- */
323
- this.FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW = false;
324
-
325
- /**
326
- * Whether or not a dropdown field's div should be coloured to match the
327
- * block colours.
328
- * @type {boolean}
329
- */
330
- this.FIELD_DROPDOWN_COLOURED_DIV = false;
331
-
332
- /**
333
- * Whether or not a dropdown field uses a text or SVG arrow.
334
- * @type {boolean}
335
- */
336
- this.FIELD_DROPDOWN_SVG_ARROW = false;
337
-
338
- /**
339
- * A dropdown field's SVG arrow padding.
340
- * @type {number}
341
- */
342
- this.FIELD_DROPDOWN_SVG_ARROW_PADDING = this.FIELD_BORDER_RECT_X_PADDING;
40
+ constructor() {
41
+ /**
42
+ * The size of an empty spacer.
43
+ * @type {number}
44
+ */
45
+ this.NO_PADDING = 0;
46
+
47
+ /**
48
+ * The size of small padding.
49
+ * @type {number}
50
+ */
51
+ this.SMALL_PADDING = 3;
52
+
53
+ /**
54
+ * The size of medium padding.
55
+ * @type {number}
56
+ */
57
+ this.MEDIUM_PADDING = 5;
58
+
59
+ /**
60
+ * The size of medium-large padding.
61
+ * @type {number}
62
+ */
63
+ this.MEDIUM_LARGE_PADDING = 8;
64
+
65
+ /**
66
+ * The size of large padding.
67
+ * @type {number}
68
+ */
69
+ this.LARGE_PADDING = 10;
70
+
71
+ /**
72
+ * Offset from the top of the row for placing fields on inline input rows
73
+ * and statement input rows.
74
+ * Matches existing rendering (in 2019).
75
+ * @type {number}
76
+ */
77
+ this.TALL_INPUT_FIELD_OFFSET_Y = this.MEDIUM_PADDING;
78
+
79
+ /**
80
+ * The height of the puzzle tab used for input and output connections.
81
+ * @type {number}
82
+ */
83
+ this.TAB_HEIGHT = 15;
84
+
85
+ /**
86
+ * The offset from the top of the block at which a puzzle tab is positioned.
87
+ * @type {number}
88
+ */
89
+ this.TAB_OFFSET_FROM_TOP = 5;
90
+
91
+ /**
92
+ * Vertical overlap of the puzzle tab, used to make it look more like a
93
+ * puzzle piece.
94
+ * @type {number}
95
+ */
96
+ this.TAB_VERTICAL_OVERLAP = 2.5;
97
+
98
+ /**
99
+ * The width of the puzzle tab used for input and output connections.
100
+ * @type {number}
101
+ */
102
+ this.TAB_WIDTH = 8;
103
+
104
+ /**
105
+ * The width of the notch used for previous and next connections.
106
+ * @type {number}
107
+ */
108
+ this.NOTCH_WIDTH = 15;
109
+
110
+ /**
111
+ * The height of the notch used for previous and next connections.
112
+ * @type {number}
113
+ */
114
+ this.NOTCH_HEIGHT = 4;
115
+
116
+ /**
117
+ * The minimum width of the block.
118
+ * @type {number}
119
+ */
120
+ this.MIN_BLOCK_WIDTH = 12;
121
+
122
+ this.EMPTY_BLOCK_SPACER_HEIGHT = 16;
123
+
124
+ /**
125
+ * The minimum height of a dummy input row.
126
+ * @type {number}
127
+ */
128
+ this.DUMMY_INPUT_MIN_HEIGHT = this.TAB_HEIGHT;
129
+
130
+ /**
131
+ * The minimum height of a dummy input row in a shadow block.
132
+ * @type {number}
133
+ */
134
+ this.DUMMY_INPUT_SHADOW_MIN_HEIGHT = this.TAB_HEIGHT;
135
+
136
+ /**
137
+ * Rounded corner radius.
138
+ * @type {number}
139
+ */
140
+ this.CORNER_RADIUS = 8;
141
+
142
+ /**
143
+ * Offset from the left side of a block or the inside of a statement input
144
+ * to the left side of the notch.
145
+ * @type {number}
146
+ */
147
+ this.NOTCH_OFFSET_LEFT = 15;
148
+
149
+ /**
150
+ * Additional offset added to the statement input's width to account for the
151
+ * notch.
152
+ * @type {number}
153
+ */
154
+ this.STATEMENT_INPUT_NOTCH_OFFSET = this.NOTCH_OFFSET_LEFT;
155
+
156
+ this.STATEMENT_BOTTOM_SPACER = 0;
157
+ this.STATEMENT_INPUT_PADDING_LEFT = 20;
158
+
159
+ /**
160
+ * Vertical padding between consecutive statement inputs.
161
+ * @type {number}
162
+ */
163
+ this.BETWEEN_STATEMENT_PADDING_Y = 4;
164
+
165
+ /**
166
+ * The top row's minimum height.
167
+ * @type {number}
168
+ */
169
+ this.TOP_ROW_MIN_HEIGHT = this.MEDIUM_PADDING;
170
+
171
+ /**
172
+ * The top row's minimum height if it precedes a statement.
173
+ * @type {number}
174
+ */
175
+ this.TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT = this.LARGE_PADDING;
176
+
177
+ /**
178
+ * The bottom row's minimum height.
179
+ * @type {number}
180
+ */
181
+ this.BOTTOM_ROW_MIN_HEIGHT = this.MEDIUM_PADDING;
182
+
183
+ /**
184
+ * The bottom row's minimum height if it follows a statement input.
185
+ * @type {number}
186
+ */
187
+ this.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT = this.LARGE_PADDING;
188
+
189
+ /**
190
+ * Whether to add a 'hat' on top of all blocks with no previous or output
191
+ * connections. Can be overridden by 'hat' property on Theme.BlockStyle.
192
+ * @type {boolean}
193
+ */
194
+ this.ADD_START_HATS = false;
195
+
196
+ /**
197
+ * Height of the top hat.
198
+ * @type {number}
199
+ */
200
+ this.START_HAT_HEIGHT = 15;
201
+
202
+ /**
203
+ * Width of the top hat.
204
+ * @type {number}
205
+ */
206
+ this.START_HAT_WIDTH = 100;
207
+
208
+ this.SPACER_DEFAULT_HEIGHT = 15;
209
+
210
+ this.MIN_BLOCK_HEIGHT = 24;
211
+
212
+ this.EMPTY_INLINE_INPUT_PADDING = 14.5;
213
+
214
+ /**
215
+ * The height of an empty inline input.
216
+ * @type {number}
217
+ */
218
+ this.EMPTY_INLINE_INPUT_HEIGHT = this.TAB_HEIGHT + 11;
219
+
220
+ this.EXTERNAL_VALUE_INPUT_PADDING = 2;
221
+
222
+ /**
223
+ * The height of an empty statement input. Note that in the old rendering
224
+ * this varies slightly depending on whether the block has external or
225
+ * inline inputs. In the new rendering this is consistent. It seems
226
+ * unlikely that the old behaviour was intentional.
227
+ * @type {number}
228
+ */
229
+ this.EMPTY_STATEMENT_INPUT_HEIGHT = this.MIN_BLOCK_HEIGHT;
230
+
231
+ this.START_POINT = svgPaths.moveBy(0, 0);
232
+
233
+ /**
234
+ * Height of SVG path for jagged teeth at the end of collapsed blocks.
235
+ * @type {number}
236
+ */
237
+ this.JAGGED_TEETH_HEIGHT = 12;
238
+
239
+ /**
240
+ * Width of SVG path for jagged teeth at the end of collapsed blocks.
241
+ * @type {number}
242
+ */
243
+ this.JAGGED_TEETH_WIDTH = 6;
244
+
245
+ /**
246
+ * Point size of text.
247
+ * @type {number}
248
+ */
249
+ this.FIELD_TEXT_FONTSIZE = 11;
250
+
251
+ /**
252
+ * Text font weight.
253
+ * @type {string}
254
+ */
255
+ this.FIELD_TEXT_FONTWEIGHT = 'normal';
256
+
257
+ /**
258
+ * Text font family.
259
+ * @type {string}
260
+ */
261
+ this.FIELD_TEXT_FONTFAMILY = 'sans-serif';
262
+
263
+ /**
264
+ * Height of text. This constant is dynamically set in
265
+ * ``setFontConstants_`` to be the height of the text based on the font
266
+ * used.
267
+ * @type {number}
268
+ */
269
+ this.FIELD_TEXT_HEIGHT = -1; // Dynamically set.
270
+
271
+ /**
272
+ * Text baseline. This constant is dynamically set in ``setFontConstants_``
273
+ * to be the baseline of the text based on the font used.
274
+ * @type {number}
275
+ */
276
+ this.FIELD_TEXT_BASELINE = -1; // Dynamically set.
277
+
278
+ /**
279
+ * A field's border rect corner radius.
280
+ * @type {number}
281
+ */
282
+ this.FIELD_BORDER_RECT_RADIUS = 4;
283
+
284
+ /**
285
+ * A field's border rect default height.
286
+ * @type {number}
287
+ */
288
+ this.FIELD_BORDER_RECT_HEIGHT = 16;
289
+
290
+ /**
291
+ * A field's border rect X padding.
292
+ * @type {number}
293
+ */
294
+ this.FIELD_BORDER_RECT_X_PADDING = 5;
295
+
296
+ /**
297
+ * A field's border rect Y padding.
298
+ * @type {number}
299
+ */
300
+ this.FIELD_BORDER_RECT_Y_PADDING = 3;
301
+
302
+ /**
303
+ * The backing colour of a field's border rect.
304
+ * @type {string}
305
+ * @package
306
+ */
307
+ this.FIELD_BORDER_RECT_COLOUR = '#fff';
308
+
309
+ /**
310
+ * A field's text element's dominant baseline.
311
+ * @type {boolean}
312
+ */
313
+ this.FIELD_TEXT_BASELINE_CENTER = !userAgent.IE && !userAgent.EDGE;
314
+
315
+ /**
316
+ * A dropdown field's border rect height.
317
+ * @type {number}
318
+ */
319
+ this.FIELD_DROPDOWN_BORDER_RECT_HEIGHT = this.FIELD_BORDER_RECT_HEIGHT;
320
+
321
+ /**
322
+ * Whether or not a dropdown field should add a border rect when in a shadow
323
+ * block.
324
+ * @type {boolean}
325
+ */
326
+ this.FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW = false;
327
+
328
+ /**
329
+ * Whether or not a dropdown field's div should be coloured to match the
330
+ * block colours.
331
+ * @type {boolean}
332
+ */
333
+ this.FIELD_DROPDOWN_COLOURED_DIV = false;
334
+
335
+ /**
336
+ * Whether or not a dropdown field uses a text or SVG arrow.
337
+ * @type {boolean}
338
+ */
339
+ this.FIELD_DROPDOWN_SVG_ARROW = false;
340
+
341
+ /**
342
+ * A dropdown field's SVG arrow padding.
343
+ * @type {number}
344
+ */
345
+ this.FIELD_DROPDOWN_SVG_ARROW_PADDING = this.FIELD_BORDER_RECT_X_PADDING;
346
+
347
+ /**
348
+ * A dropdown field's SVG arrow size.
349
+ * @type {number}
350
+ */
351
+ this.FIELD_DROPDOWN_SVG_ARROW_SIZE = 12;
352
+
353
+ /**
354
+ * A dropdown field's SVG arrow datauri.
355
+ * @type {string}
356
+ */
357
+ this.FIELD_DROPDOWN_SVG_ARROW_DATAURI =
358
+ 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllci' +
359
+ 'AxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaG' +
360
+ 'VpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLW' +
361
+ 'Fycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuND' +
362
+ 'EsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTD' +
363
+ 'AuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNz' +
364
+ 'FDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMC' +
365
+ 'wxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNz' +
366
+ 'lhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYz' +
367
+ 'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' +
368
+ 'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4=';
369
+
370
+ /**
371
+ * Whether or not to show a box shadow around the widget div. This is only a
372
+ * feature of full block fields.
373
+ * @type {boolean}
374
+ */
375
+ this.FIELD_TEXTINPUT_BOX_SHADOW = false;
376
+
377
+ /**
378
+ * Whether or not the colour field should display its colour value on the
379
+ * entire block.
380
+ * @type {boolean}
381
+ */
382
+ this.FIELD_COLOUR_FULL_BLOCK = false;
383
+
384
+ /**
385
+ * A colour field's default width.
386
+ * @type {number}
387
+ */
388
+ this.FIELD_COLOUR_DEFAULT_WIDTH = 26;
389
+
390
+ /**
391
+ * A colour field's default height.
392
+ * @type {number}
393
+ */
394
+ this.FIELD_COLOUR_DEFAULT_HEIGHT = this.FIELD_BORDER_RECT_HEIGHT;
395
+
396
+ /**
397
+ * A checkbox field's X offset.
398
+ * @type {number}
399
+ */
400
+ this.FIELD_CHECKBOX_X_OFFSET = this.FIELD_BORDER_RECT_X_PADDING - 3;
401
+
402
+ /**
403
+ * A random identifier used to ensure a unique ID is used for each
404
+ * filter/pattern for the case of multiple Blockly instances on a page.
405
+ * @type {string}
406
+ * @package
407
+ */
408
+ this.randomIdentifier = String(Math.random()).substring(2);
409
+
410
+ /**
411
+ * The defs tag that contains all filters and patterns for this Blockly
412
+ * instance.
413
+ * @type {?SVGElement}
414
+ * @private
415
+ */
416
+ this.defs_ = null;
417
+
418
+ /**
419
+ * The ID of the emboss filter, or the empty string if no filter is set.
420
+ * @type {string}
421
+ * @package
422
+ */
423
+ this.embossFilterId = '';
424
+
425
+ /**
426
+ * The <filter> element to use for highlighting, or null if not set.
427
+ * @type {SVGElement}
428
+ * @private
429
+ */
430
+ this.embossFilter_ = null;
431
+
432
+ /**
433
+ * The ID of the disabled pattern, or the empty string if no pattern is set.
434
+ * @type {string}
435
+ * @package
436
+ */
437
+ this.disabledPatternId = '';
438
+
439
+ /**
440
+ * The <pattern> element to use for disabled blocks, or null if not set.
441
+ * @type {SVGElement}
442
+ * @private
443
+ */
444
+ this.disabledPattern_ = null;
445
+
446
+ /**
447
+ * The ID of the debug filter, or the empty string if no pattern is set.
448
+ * @type {string}
449
+ * @package
450
+ */
451
+ this.debugFilterId = '';
452
+
453
+ /**
454
+ * The <filter> element to use for a debug highlight, or null if not set.
455
+ * @type {SVGElement}
456
+ * @private
457
+ */
458
+ this.debugFilter_ = null;
459
+
460
+ /**
461
+ * The <style> element to use for injecting renderer specific CSS.
462
+ * @type {HTMLStyleElement}
463
+ * @private
464
+ */
465
+ this.cssNode_ = null;
466
+
467
+ /**
468
+ * Cursor colour.
469
+ * @type {string}
470
+ * @package
471
+ */
472
+ this.CURSOR_COLOUR = '#cc0a0a';
473
+
474
+ /**
475
+ * Immovable marker colour.
476
+ * @type {string}
477
+ * @package
478
+ */
479
+ this.MARKER_COLOUR = '#4286f4';
480
+
481
+ /**
482
+ * Width of the horizontal cursor.
483
+ * @type {number}
484
+ * @package
485
+ */
486
+ this.CURSOR_WS_WIDTH = 100;
487
+
488
+ /**
489
+ * Height of the horizontal cursor.
490
+ * @type {number}
491
+ * @package
492
+ */
493
+ this.WS_CURSOR_HEIGHT = 5;
494
+
495
+ /**
496
+ * Padding around a stack.
497
+ * @type {number}
498
+ * @package
499
+ */
500
+ this.CURSOR_STACK_PADDING = 10;
501
+
502
+ /**
503
+ * Padding around a block.
504
+ * @type {number}
505
+ * @package
506
+ */
507
+ this.CURSOR_BLOCK_PADDING = 2;
508
+
509
+ /**
510
+ * Stroke of the cursor.
511
+ * @type {number}
512
+ * @package
513
+ */
514
+ this.CURSOR_STROKE_WIDTH = 4;
515
+
516
+ /**
517
+ * Whether text input and colour fields fill up the entire source block.
518
+ * @type {boolean}
519
+ * @package
520
+ */
521
+ this.FULL_BLOCK_FIELDS = false;
522
+
523
+ /**
524
+ * The main colour of insertion markers, in hex. The block is rendered a
525
+ * transparent grey by changing the fill opacity in CSS.
526
+ * @type {string}
527
+ * @package
528
+ */
529
+ this.INSERTION_MARKER_COLOUR = '#000000';
530
+
531
+ /**
532
+ * The insertion marker opacity.
533
+ * @type {number}
534
+ * @package
535
+ */
536
+ this.INSERTION_MARKER_OPACITY = 0.2;
537
+
538
+ /**
539
+ * Enum for connection shapes.
540
+ * @enum {number}
541
+ */
542
+ this.SHAPES = {PUZZLE: 1, NOTCH: 2};
543
+ }
343
544
 
344
545
  /**
345
- * A dropdown field's SVG arrow size.
346
- * @type {number}
546
+ * Initialize shape objects based on the constants set in the constructor.
547
+ * @package
347
548
  */
348
- this.FIELD_DROPDOWN_SVG_ARROW_SIZE = 12;
549
+ init() {
550
+ /**
551
+ * An object containing sizing and path information about collapsed block
552
+ * indicators.
553
+ * @type {!Object}
554
+ */
555
+ this.JAGGED_TEETH = this.makeJaggedTeeth();
556
+
557
+ /**
558
+ * An object containing sizing and path information about notches.
559
+ * @type {!Object}
560
+ */
561
+ this.NOTCH = this.makeNotch();
562
+
563
+ /**
564
+ * An object containing sizing and path information about start hats
565
+ * @type {!Object}
566
+ */
567
+ this.START_HAT = this.makeStartHat();
568
+
569
+ /**
570
+ * An object containing sizing and path information about puzzle tabs.
571
+ * @type {!Object}
572
+ */
573
+ this.PUZZLE_TAB = this.makePuzzleTab();
574
+
575
+ /**
576
+ * An object containing sizing and path information about inside corners
577
+ * @type {!Object}
578
+ */
579
+ this.INSIDE_CORNERS = this.makeInsideCorners();
580
+
581
+ /**
582
+ * An object containing sizing and path information about outside corners.
583
+ * @type {!Object}
584
+ */
585
+ this.OUTSIDE_CORNERS = this.makeOutsideCorners();
586
+ }
349
587
 
350
588
  /**
351
- * A dropdown field's SVG arrow datauri.
352
- * @type {string}
589
+ * Refresh constants properties that depend on the theme.
590
+ * @param {!Theme} theme The current workspace theme.
591
+ * @package
353
592
  */
354
- this.FIELD_DROPDOWN_SVG_ARROW_DATAURI =
355
- 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllci' +
356
- 'AxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaG' +
357
- 'VpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLW' +
358
- 'Fycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuND' +
359
- 'EsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTD' +
360
- 'AuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNz' +
361
- 'FDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMC' +
362
- 'wxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNz' +
363
- 'lhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYz' +
364
- 'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' +
365
- 'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4=';
593
+ setTheme(theme) {
594
+ /**
595
+ * The block styles map.
596
+ * @type {Object<string, !Theme.BlockStyle>}
597
+ * @package
598
+ */
599
+ this.blockStyles = Object.create(null);
366
600
 
367
- /**
368
- * Whether or not to show a box shadow around the widget div. This is only a
369
- * feature of full block fields.
370
- * @type {boolean}
371
- */
372
- this.FIELD_TEXTINPUT_BOX_SHADOW = false;
601
+ const blockStyles = theme.blockStyles;
602
+ for (const key in blockStyles) {
603
+ this.blockStyles[key] = this.validatedBlockStyle_(blockStyles[key]);
604
+ }
373
605
 
374
- /**
375
- * Whether or not the colour field should display its colour value on the
376
- * entire block.
377
- * @type {boolean}
378
- */
379
- this.FIELD_COLOUR_FULL_BLOCK = false;
606
+ this.setDynamicProperties_(theme);
607
+ }
380
608
 
381
609
  /**
382
- * A colour field's default width.
383
- * @type {number}
610
+ * Sets dynamic properties that depend on other values or theme properties.
611
+ * @param {!Theme} theme The current workspace theme.
612
+ * @protected
384
613
  */
385
- this.FIELD_COLOUR_DEFAULT_WIDTH = 26;
614
+ setDynamicProperties_(theme) {
615
+ this.setFontConstants_(theme);
616
+ this.setComponentConstants_(theme);
386
617
 
387
- /**
388
- * A colour field's default height.
389
- * @type {number}
390
- */
391
- this.FIELD_COLOUR_DEFAULT_HEIGHT = this.FIELD_BORDER_RECT_HEIGHT;
618
+ this.ADD_START_HATS =
619
+ theme.startHats !== null ? theme.startHats : this.ADD_START_HATS;
620
+ }
392
621
 
393
622
  /**
394
- * A checkbox field's X offset.
395
- * @type {number}
623
+ * Set constants related to fonts.
624
+ * @param {!Theme} theme The current workspace theme.
625
+ * @protected
396
626
  */
397
- this.FIELD_CHECKBOX_X_OFFSET = this.FIELD_BORDER_RECT_X_PADDING - 3;
627
+ setFontConstants_(theme) {
628
+ if (theme.fontStyle && theme.fontStyle['family']) {
629
+ this.FIELD_TEXT_FONTFAMILY = theme.fontStyle['family'];
630
+ }
398
631
 
399
- /**
400
- * A random identifier used to ensure a unique ID is used for each
401
- * filter/pattern for the case of multiple Blockly instances on a page.
402
- * @type {string}
403
- * @package
404
- */
405
- this.randomIdentifier = String(Math.random()).substring(2);
632
+ if (theme.fontStyle && theme.fontStyle['weight']) {
633
+ this.FIELD_TEXT_FONTWEIGHT = theme.fontStyle['weight'];
634
+ }
406
635
 
407
- /**
408
- * The defs tag that contains all filters and patterns for this Blockly
409
- * instance.
410
- * @type {?SVGElement}
411
- * @private
412
- */
413
- this.defs_ = null;
636
+ if (theme.fontStyle && theme.fontStyle['size']) {
637
+ this.FIELD_TEXT_FONTSIZE = theme.fontStyle['size'];
638
+ }
414
639
 
415
- /**
416
- * The ID of the emboss filter, or the empty string if no filter is set.
417
- * @type {string}
418
- * @package
419
- */
420
- this.embossFilterId = '';
640
+ const fontMetrics = dom.measureFontMetrics(
641
+ 'Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT,
642
+ this.FIELD_TEXT_FONTFAMILY);
421
643
 
422
- /**
423
- * The <filter> element to use for highlighting, or null if not set.
424
- * @type {SVGElement}
425
- * @private
426
- */
427
- this.embossFilter_ = null;
428
-
429
- /**
430
- * The ID of the disabled pattern, or the empty string if no pattern is set.
431
- * @type {string}
432
- * @package
433
- */
434
- this.disabledPatternId = '';
644
+ this.FIELD_TEXT_HEIGHT = fontMetrics.height;
645
+ this.FIELD_TEXT_BASELINE = fontMetrics.baseline;
646
+ }
435
647
 
436
648
  /**
437
- * The <pattern> element to use for disabled blocks, or null if not set.
438
- * @type {SVGElement}
439
- * @private
440
- */
441
- this.disabledPattern_ = null;
649
+ * Set constants from a theme's component styles.
650
+ * @param {!Theme} theme The current workspace theme.
651
+ * @protected
652
+ */
653
+ setComponentConstants_(theme) {
654
+ this.CURSOR_COLOUR =
655
+ theme.getComponentStyle('cursorColour') || this.CURSOR_COLOUR;
656
+ this.MARKER_COLOUR =
657
+ theme.getComponentStyle('markerColour') || this.MARKER_COLOUR;
658
+ this.INSERTION_MARKER_COLOUR =
659
+ theme.getComponentStyle('insertionMarkerColour') ||
660
+ this.INSERTION_MARKER_COLOUR;
661
+ this.INSERTION_MARKER_OPACITY =
662
+ Number(theme.getComponentStyle('insertionMarkerOpacity')) ||
663
+ this.INSERTION_MARKER_OPACITY;
664
+ }
442
665
 
443
666
  /**
444
- * The ID of the debug filter, or the empty string if no pattern is set.
445
- * @type {string}
667
+ * Get or create a block style based on a single colour value. Generate a
668
+ * name for the style based on the colour.
669
+ * @param {string} colour #RRGGBB colour string.
670
+ * @return {{style: !Theme.BlockStyle, name: string}} An object
671
+ * containing the style and an autogenerated name for that style.
446
672
  * @package
447
673
  */
448
- this.debugFilterId = '';
674
+ getBlockStyleForColour(colour) {
675
+ const name = 'auto_' + colour;
676
+ if (!this.blockStyles[name]) {
677
+ this.blockStyles[name] = this.createBlockStyle_(colour);
678
+ }
679
+ return {style: this.blockStyles[name], name: name};
680
+ }
449
681
 
450
682
  /**
451
- * The <filter> element to use for a debug highlight, or null if not set.
452
- * @type {SVGElement}
453
- * @private
683
+ * Gets the BlockStyle for the given block style name.
684
+ * @param {?string} blockStyleName The name of the block style.
685
+ * @return {!Theme.BlockStyle} The named block style, or a default style
686
+ * if no style with the given name was found.
454
687
  */
455
- this.debugFilter_ = null;
688
+ getBlockStyle(blockStyleName) {
689
+ return this.blockStyles[blockStyleName || ''] ||
690
+ (blockStyleName && blockStyleName.indexOf('auto_') === 0 ?
691
+ this.getBlockStyleForColour(blockStyleName.substring(5)).style :
692
+ this.createBlockStyle_('#000000'));
693
+ }
456
694
 
457
695
  /**
458
- * The <style> element to use for injecting renderer specific CSS.
459
- * @type {HTMLStyleElement}
460
- * @private
696
+ * Create a block style object based on the given colour.
697
+ * @param {string} colour #RRGGBB colour string.
698
+ * @return {!Theme.BlockStyle} A populated block style based on the
699
+ * given colour.
700
+ * @protected
461
701
  */
462
- this.cssNode_ = null;
702
+ createBlockStyle_(colour) {
703
+ return this.validatedBlockStyle_({'colourPrimary': colour});
704
+ }
463
705
 
464
706
  /**
465
- * Cursor colour.
466
- * @type {string}
467
- * @package
468
- */
469
- this.CURSOR_COLOUR = '#cc0a0a';
707
+ * Get a full block style object based on the input style object. Populate
708
+ * any missing values.
709
+ * @param {{
710
+ * colourPrimary:string,
711
+ * colourSecondary:(string|undefined),
712
+ * colourTertiary:(string|undefined),
713
+ * hat:(string|undefined)
714
+ * }} blockStyle A full or partial block style object.
715
+
716
+ * @return {!Theme.BlockStyle} A full block style object, with all
717
+ * required properties populated.
718
+ * @protected
719
+ */
720
+ validatedBlockStyle_(blockStyle) {
721
+ // Make a new object with all of the same properties.
722
+ const valid = /** @type {!Theme.BlockStyle} */ ({});
723
+ if (blockStyle) {
724
+ object.mixin(valid, blockStyle);
725
+ }
726
+ // Validate required properties.
727
+ const parsedColour =
728
+ parsing.parseBlockColour(valid['colourPrimary'] || '#000');
729
+ valid.colourPrimary = parsedColour.hex;
730
+ valid.colourSecondary = valid['colourSecondary'] ?
731
+ parsing.parseBlockColour(valid['colourSecondary']).hex :
732
+ this.generateSecondaryColour_(valid.colourPrimary);
733
+ valid.colourTertiary = valid['colourTertiary'] ?
734
+ parsing.parseBlockColour(valid['colourTertiary']).hex :
735
+ this.generateTertiaryColour_(valid.colourPrimary);
736
+
737
+ valid.hat = valid['hat'] || '';
738
+ return valid;
739
+ }
470
740
 
471
741
  /**
472
- * Immovable marker colour.
473
- * @type {string}
474
- * @package
742
+ * Generate a secondary colour from the passed in primary colour.
743
+ * @param {string} inputColour Primary colour.
744
+ * @return {string} The generated secondary colour.
745
+ * @protected
475
746
  */
476
- this.MARKER_COLOUR = '#4286f4';
747
+ generateSecondaryColour_(inputColour) {
748
+ return colour.blend('#fff', inputColour, 0.6) || inputColour;
749
+ }
477
750
 
478
751
  /**
479
- * Width of the horizontal cursor.
480
- * @type {number}
481
- * @package
752
+ * Generate a tertiary colour from the passed in primary colour.
753
+ * @param {string} inputColour Primary colour.
754
+ * @return {string} The generated tertiary colour.
755
+ * @protected
482
756
  */
483
- this.CURSOR_WS_WIDTH = 100;
757
+ generateTertiaryColour_(inputColour) {
758
+ return colour.blend('#fff', inputColour, 0.3) || inputColour;
759
+ }
484
760
 
485
761
  /**
486
- * Height of the horizontal cursor.
487
- * @type {number}
762
+ * Dispose of this constants provider.
763
+ * Delete all DOM elements that this provider created.
488
764
  * @package
489
765
  */
490
- this.WS_CURSOR_HEIGHT = 5;
766
+ dispose() {
767
+ if (this.embossFilter_) {
768
+ dom.removeNode(this.embossFilter_);
769
+ }
770
+ if (this.disabledPattern_) {
771
+ dom.removeNode(this.disabledPattern_);
772
+ }
773
+ if (this.debugFilter_) {
774
+ dom.removeNode(this.debugFilter_);
775
+ }
776
+ this.cssNode_ = null;
777
+ }
491
778
 
492
779
  /**
493
- * Padding around a stack.
494
- * @type {number}
780
+ * @return {!Object} An object containing sizing and path information about
781
+ * collapsed block indicators.
495
782
  * @package
496
783
  */
497
- this.CURSOR_STACK_PADDING = 10;
784
+ makeJaggedTeeth() {
785
+ const height = this.JAGGED_TEETH_HEIGHT;
786
+ const width = this.JAGGED_TEETH_WIDTH;
498
787
 
499
- /**
500
- * Padding around a block.
501
- * @type {number}
502
- * @package
503
- */
504
- this.CURSOR_BLOCK_PADDING = 2;
788
+ const mainPath = svgPaths.line([
789
+ svgPaths.point(width, height / 4),
790
+ svgPaths.point(-width * 2, height / 2),
791
+ svgPaths.point(width, height / 4),
792
+ ]);
793
+ return {height: height, width: width, path: mainPath};
794
+ }
505
795
 
506
796
  /**
507
- * Stroke of the cursor.
508
- * @type {number}
797
+ * @return {!Object} An object containing sizing and path information about
798
+ * start hats.
509
799
  * @package
510
800
  */
511
- this.CURSOR_STROKE_WIDTH = 4;
801
+ makeStartHat() {
802
+ const height = this.START_HAT_HEIGHT;
803
+ const width = this.START_HAT_WIDTH;
512
804
 
513
- /**
514
- * Whether text input and colour fields fill up the entire source block.
515
- * @type {boolean}
516
- * @package
517
- */
518
- this.FULL_BLOCK_FIELDS = false;
805
+ const mainPath = svgPaths.curve('c', [
806
+ svgPaths.point(30, -height),
807
+ svgPaths.point(70, -height),
808
+ svgPaths.point(width, 0),
809
+ ]);
810
+ return {height: height, width: width, path: mainPath};
811
+ }
519
812
 
520
813
  /**
521
- * The main colour of insertion markers, in hex. The block is rendered a
522
- * transparent grey by changing the fill opacity in CSS.
523
- * @type {string}
814
+ * @return {!Object} An object containing sizing and path information about
815
+ * puzzle tabs.
524
816
  * @package
525
817
  */
526
- this.INSERTION_MARKER_COLOUR = '#000000';
818
+ makePuzzleTab() {
819
+ const width = this.TAB_WIDTH;
820
+ const height = this.TAB_HEIGHT;
821
+
822
+ /**
823
+ * Make the main path for the puzzle tab made out of a few curves (c and s).
824
+ * Those curves are defined with relative positions. The 'up' and 'down'
825
+ * versions of the paths are the same, but the Y sign flips. Forward and
826
+ * back are the signs to use to move the cursor in the direction that the
827
+ * path is being drawn.
828
+ * @param {boolean} up True if the path should be drawn from bottom to top,
829
+ * false otherwise.
830
+ * @return {string} A path fragment describing a puzzle tab.
831
+ */
832
+ function makeMainPath(up) {
833
+ const forward = up ? -1 : 1;
834
+ const back = -forward;
835
+
836
+ const overlap = 2.5;
837
+ const halfHeight = height / 2;
838
+ const control1Y = halfHeight + overlap;
839
+ const control2Y = halfHeight + 0.5;
840
+ const control3Y = overlap; // 2.5
841
+
842
+ const endPoint1 = svgPaths.point(-width, forward * halfHeight);
843
+ const endPoint2 = svgPaths.point(width, forward * halfHeight);
844
+
845
+ return svgPaths.curve(
846
+ 'c',
847
+ [
848
+ svgPaths.point(0, forward * control1Y),
849
+ svgPaths.point(-width, back * control2Y),
850
+ endPoint1,
851
+ ]) +
852
+ svgPaths.curve(
853
+ 's', [svgPaths.point(width, back * control3Y), endPoint2]);
854
+ }
855
+
856
+ // c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5
857
+ const pathUp = makeMainPath(true);
858
+ // c 0,10 -8,-8 -8,7.5 s 8,-2.5 8,7.5
859
+ const pathDown = makeMainPath(false);
860
+
861
+ return {
862
+ type: this.SHAPES.PUZZLE,
863
+ width: width,
864
+ height: height,
865
+ pathDown: pathDown,
866
+ pathUp: pathUp,
867
+ };
868
+ }
527
869
 
528
870
  /**
529
- * The insertion marker opacity.
530
- * @type {number}
871
+ * @return {!Object} An object containing sizing and path information about
872
+ * notches.
531
873
  * @package
532
874
  */
533
- this.INSERTION_MARKER_OPACITY = 0.2;
534
-
535
- /**
536
- * Enum for connection shapes.
537
- * @enum {number}
538
- */
539
- this.SHAPES = {PUZZLE: 1, NOTCH: 2};
540
- };
541
-
542
- /**
543
- * Initialize shape objects based on the constants set in the constructor.
544
- * @package
545
- */
546
- ConstantProvider.prototype.init = function() {
547
- /**
548
- * An object containing sizing and path information about collapsed block
549
- * indicators.
550
- * @type {!Object}
551
- */
552
- this.JAGGED_TEETH = this.makeJaggedTeeth();
553
-
554
- /**
555
- * An object containing sizing and path information about notches.
556
- * @type {!Object}
557
- */
558
- this.NOTCH = this.makeNotch();
559
-
560
- /**
561
- * An object containing sizing and path information about start hats
562
- * @type {!Object}
563
- */
564
- this.START_HAT = this.makeStartHat();
565
-
566
- /**
567
- * An object containing sizing and path information about puzzle tabs.
568
- * @type {!Object}
569
- */
570
- this.PUZZLE_TAB = this.makePuzzleTab();
571
-
572
- /**
573
- * An object containing sizing and path information about inside corners
574
- * @type {!Object}
575
- */
576
- this.INSIDE_CORNERS = this.makeInsideCorners();
577
-
578
- /**
579
- * An object containing sizing and path information about outside corners.
580
- * @type {!Object}
581
- */
582
- this.OUTSIDE_CORNERS = this.makeOutsideCorners();
583
- };
875
+ makeNotch() {
876
+ const width = this.NOTCH_WIDTH;
877
+ const height = this.NOTCH_HEIGHT;
878
+ const innerWidth = 3;
879
+ const outerWidth = (width - innerWidth) / 2;
880
+
881
+ /**
882
+ * Make the main path for the notch.
883
+ * @param {number} dir Direction multiplier to apply to horizontal offsets
884
+ * along the path. Either 1 or -1.
885
+ * @return {string} A path fragment describing a notch.
886
+ */
887
+ function makeMainPath(dir) {
888
+ return svgPaths.line([
889
+ svgPaths.point(dir * outerWidth, height),
890
+ svgPaths.point(dir * innerWidth, 0),
891
+ svgPaths.point(dir * outerWidth, -height),
892
+ ]);
893
+ }
894
+ const pathLeft = makeMainPath(1);
895
+ const pathRight = makeMainPath(-1);
896
+
897
+ return {
898
+ type: this.SHAPES.NOTCH,
899
+ width: width,
900
+ height: height,
901
+ pathLeft: pathLeft,
902
+ pathRight: pathRight,
903
+ };
904
+ }
584
905
 
585
- /**
586
- * Refresh constants properties that depend on the theme.
587
- * @param {!Theme} theme The current workspace theme.
588
- * @package
589
- */
590
- ConstantProvider.prototype.setTheme = function(theme) {
591
906
  /**
592
- * The block styles map.
593
- * @type {Object<string, !Theme.BlockStyle>}
907
+ * @return {!Object} An object containing sizing and path information about
908
+ * inside corners.
594
909
  * @package
595
910
  */
596
- this.blockStyles = Object.create(null);
911
+ makeInsideCorners() {
912
+ const radius = this.CORNER_RADIUS;
597
913
 
598
- const blockStyles = theme.blockStyles;
599
- for (const key in blockStyles) {
600
- this.blockStyles[key] = this.validatedBlockStyle_(blockStyles[key]);
601
- }
914
+ const innerTopLeftCorner =
915
+ svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius));
602
916
 
603
- this.setDynamicProperties_(theme);
604
- };
917
+ const innerBottomLeftCorner =
918
+ svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius));
605
919
 
606
- /**
607
- * Sets dynamic properties that depend on other values or theme properties.
608
- * @param {!Theme} theme The current workspace theme.
609
- * @protected
610
- */
611
- ConstantProvider.prototype.setDynamicProperties_ = function(theme) {
612
- this.setFontConstants_(theme);
613
- this.setComponentConstants_(theme);
614
-
615
- this.ADD_START_HATS =
616
- theme.startHats !== null ? theme.startHats : this.ADD_START_HATS;
617
- };
618
-
619
- /**
620
- * Set constants related to fonts.
621
- * @param {!Theme} theme The current workspace theme.
622
- * @protected
623
- */
624
- ConstantProvider.prototype.setFontConstants_ = function(theme) {
625
- this.FIELD_TEXT_FONTFAMILY =
626
- theme.fontStyle && theme.fontStyle['family'] !== undefined ?
627
- theme.fontStyle['family'] :
628
- this.FIELD_TEXT_FONTFAMILY;
629
- this.FIELD_TEXT_FONTWEIGHT =
630
- theme.fontStyle && theme.fontStyle['weight'] !== undefined ?
631
- theme.fontStyle['weight'] :
632
- this.FIELD_TEXT_FONTWEIGHT;
633
- this.FIELD_TEXT_FONTSIZE =
634
- theme.fontStyle && theme.fontStyle['size'] !== undefined ?
635
- theme.fontStyle['size'] :
636
- this.FIELD_TEXT_FONTSIZE;
637
-
638
- const fontMetrics = dom.measureFontMetrics(
639
- 'Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT,
640
- this.FIELD_TEXT_FONTFAMILY);
641
-
642
- this.FIELD_TEXT_HEIGHT = fontMetrics.height;
643
- this.FIELD_TEXT_BASELINE = fontMetrics.baseline;
644
- };
645
-
646
- /**
647
- * Set constants from a theme's component styles.
648
- * @param {!Theme} theme The current workspace theme.
649
- * @protected
650
- */
651
- ConstantProvider.prototype.setComponentConstants_ = function(theme) {
652
- this.CURSOR_COLOUR =
653
- theme.getComponentStyle('cursorColour') || this.CURSOR_COLOUR;
654
- this.MARKER_COLOUR =
655
- theme.getComponentStyle('markerColour') || this.MARKER_COLOUR;
656
- this.INSERTION_MARKER_COLOUR =
657
- theme.getComponentStyle('insertionMarkerColour') ||
658
- this.INSERTION_MARKER_COLOUR;
659
- this.INSERTION_MARKER_OPACITY =
660
- Number(theme.getComponentStyle('insertionMarkerOpacity')) ||
661
- this.INSERTION_MARKER_OPACITY;
662
- };
663
-
664
- /**
665
- * Get or create a block style based on a single colour value. Generate a name
666
- * for the style based on the colour.
667
- * @param {string} colour #RRGGBB colour string.
668
- * @return {{style: !Theme.BlockStyle, name: string}} An object
669
- * containing the style and an autogenerated name for that style.
670
- * @package
671
- */
672
- ConstantProvider.prototype.getBlockStyleForColour = function(colour) {
673
- const name = 'auto_' + colour;
674
- if (!this.blockStyles[name]) {
675
- this.blockStyles[name] = this.createBlockStyle_(colour);
920
+ return {
921
+ width: radius,
922
+ height: radius,
923
+ pathTop: innerTopLeftCorner,
924
+ pathBottom: innerBottomLeftCorner,
925
+ };
676
926
  }
677
- return {style: this.blockStyles[name], name: name};
678
- };
679
-
680
- /**
681
- * Gets the BlockStyle for the given block style name.
682
- * @param {?string} blockStyleName The name of the block style.
683
- * @return {!Theme.BlockStyle} The named block style, or a default style
684
- * if no style with the given name was found.
685
- */
686
- ConstantProvider.prototype.getBlockStyle = function(blockStyleName) {
687
- return this.blockStyles[blockStyleName || ''] ||
688
- (blockStyleName && blockStyleName.indexOf('auto_') === 0 ?
689
- this.getBlockStyleForColour(blockStyleName.substring(5)).style :
690
- this.createBlockStyle_('#000000'));
691
- };
692
-
693
- /**
694
- * Create a block style object based on the given colour.
695
- * @param {string} colour #RRGGBB colour string.
696
- * @return {!Theme.BlockStyle} A populated block style based on the
697
- * given colour.
698
- * @protected
699
- */
700
- ConstantProvider.prototype.createBlockStyle_ = function(colour) {
701
- return this.validatedBlockStyle_({'colourPrimary': colour});
702
- };
703
-
704
- /**
705
- * Get a full block style object based on the input style object. Populate
706
- * any missing values.
707
- * @param {{
708
- * colourPrimary:string,
709
- * colourSecondary:(string|undefined),
710
- * colourTertiary:(string|undefined),
711
- * hat:(string|undefined)
712
- * }} blockStyle A full or partial block style object.
713
-
714
- * @return {!Theme.BlockStyle} A full block style object, with all
715
- * required properties populated.
716
- * @protected
717
- */
718
- ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) {
719
- // Make a new object with all of the same properties.
720
- const valid = /** @type {!Theme.BlockStyle} */ ({});
721
- if (blockStyle) {
722
- object.mixin(valid, blockStyle);
723
- }
724
- // Validate required properties.
725
- const parsedColour =
726
- parsing.parseBlockColour(valid['colourPrimary'] || '#000');
727
- valid.colourPrimary = parsedColour.hex;
728
- valid.colourSecondary = valid['colourSecondary'] ?
729
- parsing.parseBlockColour(valid['colourSecondary']).hex :
730
- this.generateSecondaryColour_(valid.colourPrimary);
731
- valid.colourTertiary = valid['colourTertiary'] ?
732
- parsing.parseBlockColour(valid['colourTertiary']).hex :
733
- this.generateTertiaryColour_(valid.colourPrimary);
734
-
735
- valid.hat = valid['hat'] || '';
736
- return valid;
737
- };
738
-
739
- /**
740
- * Generate a secondary colour from the passed in primary colour.
741
- * @param {string} inputColour Primary colour.
742
- * @return {string} The generated secondary colour.
743
- * @protected
744
- */
745
- ConstantProvider.prototype.generateSecondaryColour_ = function(inputColour) {
746
- return colour.blend('#fff', inputColour, 0.6) || inputColour;
747
- };
748
-
749
- /**
750
- * Generate a tertiary colour from the passed in primary colour.
751
- * @param {string} inputColour Primary colour.
752
- * @return {string} The generated tertiary colour.
753
- * @protected
754
- */
755
- ConstantProvider.prototype.generateTertiaryColour_ = function(inputColour) {
756
- return colour.blend('#fff', inputColour, 0.3) || inputColour;
757
- };
758
-
759
-
760
- /**
761
- * Dispose of this constants provider.
762
- * Delete all DOM elements that this provider created.
763
- * @package
764
- */
765
- ConstantProvider.prototype.dispose = function() {
766
- if (this.embossFilter_) {
767
- dom.removeNode(this.embossFilter_);
768
- }
769
- if (this.disabledPattern_) {
770
- dom.removeNode(this.disabledPattern_);
771
- }
772
- if (this.debugFilter_) {
773
- dom.removeNode(this.debugFilter_);
774
- }
775
- this.cssNode_ = null;
776
- };
777
-
778
- /**
779
- * @return {!Object} An object containing sizing and path information about
780
- * collapsed block indicators.
781
- * @package
782
- */
783
- ConstantProvider.prototype.makeJaggedTeeth = function() {
784
- const height = this.JAGGED_TEETH_HEIGHT;
785
- const width = this.JAGGED_TEETH_WIDTH;
786
-
787
- const mainPath = svgPaths.line([
788
- svgPaths.point(width, height / 4),
789
- svgPaths.point(-width * 2, height / 2),
790
- svgPaths.point(width, height / 4),
791
- ]);
792
- return {height: height, width: width, path: mainPath};
793
- };
794
-
795
- /**
796
- * @return {!Object} An object containing sizing and path information about
797
- * start hats.
798
- * @package
799
- */
800
- ConstantProvider.prototype.makeStartHat = function() {
801
- const height = this.START_HAT_HEIGHT;
802
- const width = this.START_HAT_WIDTH;
803
-
804
- const mainPath = svgPaths.curve('c', [
805
- svgPaths.point(30, -height),
806
- svgPaths.point(70, -height),
807
- svgPaths.point(width, 0),
808
- ]);
809
- return {height: height, width: width, path: mainPath};
810
- };
811
-
812
- /**
813
- * @return {!Object} An object containing sizing and path information about
814
- * puzzle tabs.
815
- * @package
816
- */
817
- ConstantProvider.prototype.makePuzzleTab = function() {
818
- const width = this.TAB_WIDTH;
819
- const height = this.TAB_HEIGHT;
820
927
 
821
928
  /**
822
- * Make the main path for the puzzle tab made out of a few curves (c and s).
823
- * Those curves are defined with relative positions. The 'up' and 'down'
824
- * versions of the paths are the same, but the Y sign flips. Forward and back
825
- * are the signs to use to move the cursor in the direction that the path is
826
- * being drawn.
827
- * @param {boolean} up True if the path should be drawn from bottom to top,
828
- * false otherwise.
829
- * @return {string} A path fragment describing a puzzle tab.
929
+ * @return {!Object} An object containing sizing and path information about
930
+ * outside corners.
931
+ * @package
830
932
  */
831
- function makeMainPath(up) {
832
- const forward = up ? -1 : 1;
833
- const back = -forward;
834
-
835
- const overlap = 2.5;
836
- const halfHeight = height / 2;
837
- const control1Y = halfHeight + overlap;
838
- const control2Y = halfHeight + 0.5;
839
- const control3Y = overlap; // 2.5
840
-
841
- const endPoint1 = svgPaths.point(-width, forward * halfHeight);
842
- const endPoint2 = svgPaths.point(width, forward * halfHeight);
843
-
844
- return svgPaths.curve(
845
- 'c',
846
- [
847
- svgPaths.point(0, forward * control1Y),
848
- svgPaths.point(-width, back * control2Y),
849
- endPoint1,
850
- ]) +
851
- svgPaths.curve(
852
- 's', [svgPaths.point(width, back * control3Y), endPoint2]);
933
+ makeOutsideCorners() {
934
+ const radius = this.CORNER_RADIUS;
935
+ /**
936
+ * SVG path for drawing the rounded top-left corner.
937
+ * @const
938
+ */
939
+ const topLeft = svgPaths.moveBy(0, radius) +
940
+ svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, -radius));
941
+
942
+ /**
943
+ * SVG path for drawing the rounded top-right corner.
944
+ * @const
945
+ */
946
+ const topRight =
947
+ svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius));
948
+
949
+ /**
950
+ * SVG path for drawing the rounded bottom-left corner.
951
+ * @const
952
+ */
953
+ const bottomLeft =
954
+ svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, -radius));
955
+
956
+ /**
957
+ * SVG path for drawing the rounded bottom-right corner.
958
+ * @const
959
+ */
960
+ const bottomRight =
961
+ svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius));
962
+
963
+ return {
964
+ topLeft: topLeft,
965
+ topRight: topRight,
966
+ bottomRight: bottomRight,
967
+ bottomLeft: bottomLeft,
968
+ rightHeight: radius,
969
+ };
853
970
  }
854
971
 
855
- // c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5
856
- const pathUp = makeMainPath(true);
857
- // c 0,10 -8,-8 -8,7.5 s 8,-2.5 8,7.5
858
- const pathDown = makeMainPath(false);
859
-
860
- return {
861
- type: this.SHAPES.PUZZLE,
862
- width: width,
863
- height: height,
864
- pathDown: pathDown,
865
- pathUp: pathUp,
866
- };
867
- };
868
-
869
- /**
870
- * @return {!Object} An object containing sizing and path information about
871
- * notches.
872
- * @package
873
- */
874
- ConstantProvider.prototype.makeNotch = function() {
875
- const width = this.NOTCH_WIDTH;
876
- const height = this.NOTCH_HEIGHT;
877
- const innerWidth = 3;
878
- const outerWidth = (width - innerWidth) / 2;
879
-
880
972
  /**
881
- * Make the main path for the notch.
882
- * @param {number} dir Direction multiplier to apply to horizontal offsets
883
- * along the path. Either 1 or -1.
884
- * @return {string} A path fragment describing a notch.
973
+ * Get an object with connection shape and sizing information based on the
974
+ * type of the connection.
975
+ * @param {!RenderedConnection} connection The connection to find a
976
+ * shape object for
977
+ * @return {!Object} The shape object for the connection.
978
+ * @package
885
979
  */
886
- function makeMainPath(dir) {
887
- return svgPaths.line([
888
- svgPaths.point(dir * outerWidth, height),
889
- svgPaths.point(dir * innerWidth, 0),
890
- svgPaths.point(dir * outerWidth, -height),
891
- ]);
980
+ shapeFor(connection) {
981
+ switch (connection.type) {
982
+ case ConnectionType.INPUT_VALUE:
983
+ case ConnectionType.OUTPUT_VALUE:
984
+ return this.PUZZLE_TAB;
985
+ case ConnectionType.PREVIOUS_STATEMENT:
986
+ case ConnectionType.NEXT_STATEMENT:
987
+ return this.NOTCH;
988
+ default:
989
+ throw Error('Unknown connection type');
990
+ }
892
991
  }
893
- const pathLeft = makeMainPath(1);
894
- const pathRight = makeMainPath(-1);
895
-
896
- return {
897
- type: this.SHAPES.NOTCH,
898
- width: width,
899
- height: height,
900
- pathLeft: pathLeft,
901
- pathRight: pathRight,
902
- };
903
- };
904
992
 
905
- /**
906
- * @return {!Object} An object containing sizing and path information about
907
- * inside corners.
908
- * @package
909
- */
910
- ConstantProvider.prototype.makeInsideCorners = function() {
911
- const radius = this.CORNER_RADIUS;
912
-
913
- const innerTopLeftCorner =
914
- svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius));
915
-
916
- const innerBottomLeftCorner =
917
- svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius));
918
-
919
- return {
920
- width: radius,
921
- height: radius,
922
- pathTop: innerTopLeftCorner,
923
- pathBottom: innerBottomLeftCorner,
924
- };
925
- };
926
-
927
- /**
928
- * @return {!Object} An object containing sizing and path information about
929
- * outside corners.
930
- * @package
931
- */
932
- ConstantProvider.prototype.makeOutsideCorners = function() {
933
- const radius = this.CORNER_RADIUS;
934
993
  /**
935
- * SVG path for drawing the rounded top-left corner.
936
- * @const
937
- */
938
- const topLeft = svgPaths.moveBy(0, radius) +
939
- svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, -radius));
940
-
941
- /**
942
- * SVG path for drawing the rounded top-right corner.
943
- * @const
944
- */
945
- const topRight =
946
- svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius));
947
-
948
- /**
949
- * SVG path for drawing the rounded bottom-left corner.
950
- * @const
951
- */
952
- const bottomLeft =
953
- svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, -radius));
954
-
955
- /**
956
- * SVG path for drawing the rounded bottom-right corner.
957
- * @const
994
+ * Create any DOM elements that this renderer needs (filters, patterns, etc).
995
+ * @param {!SVGElement} svg The root of the workspace's SVG.
996
+ * @param {string} tagName The name to use for the CSS style tag.
997
+ * @param {string} selector The CSS selector to use.
998
+ * @suppress {strictModuleDepCheck} Debug renderer only included in
999
+ * playground.
1000
+ * @package
958
1001
  */
959
- const bottomRight =
960
- svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius));
961
-
962
- return {
963
- topLeft: topLeft,
964
- topRight: topRight,
965
- bottomRight: bottomRight,
966
- bottomLeft: bottomLeft,
967
- rightHeight: radius,
968
- };
969
- };
970
-
971
- /**
972
- * Get an object with connection shape and sizing information based on the type
973
- * of the connection.
974
- * @param {!RenderedConnection} connection The connection to find a
975
- * shape object for
976
- * @return {!Object} The shape object for the connection.
977
- * @package
978
- */
979
- ConstantProvider.prototype.shapeFor = function(connection) {
980
- switch (connection.type) {
981
- case ConnectionType.INPUT_VALUE:
982
- case ConnectionType.OUTPUT_VALUE:
983
- return this.PUZZLE_TAB;
984
- case ConnectionType.PREVIOUS_STATEMENT:
985
- case ConnectionType.NEXT_STATEMENT:
986
- return this.NOTCH;
987
- default:
988
- throw Error('Unknown connection type');
989
- }
990
- };
991
-
992
- /**
993
- * Create any DOM elements that this renderer needs (filters, patterns, etc).
994
- * @param {!SVGElement} svg The root of the workspace's SVG.
995
- * @param {string} tagName The name to use for the CSS style tag.
996
- * @param {string} selector The CSS selector to use.
997
- * @suppress {strictModuleDepCheck} Debug renderer only included in playground.
998
- * @package
999
- */
1000
- ConstantProvider.prototype.createDom = function(svg, tagName, selector) {
1001
- this.injectCSS_(tagName, selector);
1002
-
1003
- /*
1004
- <defs>
1005
- ... filters go here ...
1006
- </defs>
1007
- */
1008
- this.defs_ = dom.createSvgElement(Svg.DEFS, {}, svg);
1009
- /*
1010
- <filter id="blocklyEmbossFilter837493">
1011
- <feGaussianBlur in="SourceAlpha" stdDeviation="1" result="blur" />
1012
- <feSpecularLighting in="blur" surfaceScale="1" specularConstant="0.5"
1013
- specularExponent="10" lighting-color="white"
1014
- result="specOut">
1015
- <fePointLight x="-5000" y="-10000" z="20000" />
1016
- </feSpecularLighting>
1017
- <feComposite in="specOut" in2="SourceAlpha" operator="in"
1018
- result="specOut" />
1019
- <feComposite in="SourceGraphic" in2="specOut" operator="arithmetic"
1020
- k1="0" k2="1" k3="1" k4="0" />
1021
- </filter>
1022
- */
1023
- const embossFilter = dom.createSvgElement(
1024
- Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier},
1025
- this.defs_);
1026
- dom.createSvgElement(
1027
- Svg.FEGAUSSIANBLUR,
1028
- {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter);
1029
- const feSpecularLighting = dom.createSvgElement(
1030
- Svg.FESPECULARLIGHTING, {
1031
- 'in': 'blur',
1032
- 'surfaceScale': 1,
1033
- 'specularConstant': 0.5,
1034
- 'specularExponent': 10,
1035
- 'lighting-color': 'white',
1036
- 'result': 'specOut',
1037
- },
1038
- embossFilter);
1039
- dom.createSvgElement(
1040
- Svg.FEPOINTLIGHT, {'x': -5000, 'y': -10000, 'z': 20000},
1041
- feSpecularLighting);
1042
- dom.createSvgElement(
1043
- Svg.FECOMPOSITE, {
1044
- 'in': 'specOut',
1045
- 'in2': 'SourceAlpha',
1046
- 'operator': 'in',
1047
- 'result': 'specOut',
1048
- },
1049
- embossFilter);
1050
- dom.createSvgElement(
1051
- Svg.FECOMPOSITE, {
1052
- 'in': 'SourceGraphic',
1053
- 'in2': 'specOut',
1054
- 'operator': 'arithmetic',
1055
- 'k1': 0,
1056
- 'k2': 1,
1057
- 'k3': 1,
1058
- 'k4': 0,
1059
- },
1060
- embossFilter);
1061
- this.embossFilterId = embossFilter.id;
1062
- this.embossFilter_ = embossFilter;
1063
-
1064
- /*
1065
- <pattern id="blocklyDisabledPattern837493" patternUnits="userSpaceOnUse"
1066
- width="10" height="10">
1067
- <rect width="10" height="10" fill="#aaa" />
1068
- <path d="M 0 0 L 10 10 M 10 0 L 0 10" stroke="#cc0" />
1069
- </pattern>
1070
- */
1071
- const disabledPattern = dom.createSvgElement(
1072
- Svg.PATTERN, {
1073
- 'id': 'blocklyDisabledPattern' + this.randomIdentifier,
1074
- 'patternUnits': 'userSpaceOnUse',
1075
- 'width': 10,
1076
- 'height': 10,
1077
- },
1078
- this.defs_);
1079
- dom.createSvgElement(
1080
- Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern);
1081
- dom.createSvgElement(
1082
- Svg.PATH, {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'},
1083
- disabledPattern);
1084
- this.disabledPatternId = disabledPattern.id;
1085
- this.disabledPattern_ = disabledPattern;
1086
-
1087
- this.createDebugFilter();
1088
- };
1089
-
1090
- /**
1091
- * Create a filter for highlighting the currently rendering block during
1092
- * render debugging.
1093
- * @private
1094
- */
1095
- ConstantProvider.prototype.createDebugFilter = function() {
1096
- // Only create the debug filter once.
1097
- if (!this.debugFilter_) {
1098
- const debugFilter = dom.createSvgElement(
1099
- Svg.FILTER, {
1100
- 'id': 'blocklyDebugFilter' + this.randomIdentifier,
1101
- 'height': '160%',
1102
- 'width': '180%',
1103
- 'y': '-30%',
1104
- 'x': '-40%',
1105
- },
1002
+ createDom(svg, tagName, selector) {
1003
+ this.injectCSS_(tagName, selector);
1004
+
1005
+ /*
1006
+ <defs>
1007
+ ... filters go here ...
1008
+ </defs>
1009
+ */
1010
+ this.defs_ = dom.createSvgElement(Svg.DEFS, {}, svg);
1011
+ /*
1012
+ <filter id="blocklyEmbossFilter837493">
1013
+ <feGaussianBlur in="SourceAlpha" stdDeviation="1" result="blur" />
1014
+ <feSpecularLighting in="blur" surfaceScale="1" specularConstant="0.5"
1015
+ specularExponent="10" lighting-color="white"
1016
+ result="specOut">
1017
+ <fePointLight x="-5000" y="-10000" z="20000" />
1018
+ </feSpecularLighting>
1019
+ <feComposite in="specOut" in2="SourceAlpha" operator="in"
1020
+ result="specOut" />
1021
+ <feComposite in="SourceGraphic" in2="specOut" operator="arithmetic"
1022
+ k1="0" k2="1" k3="1" k4="0" />
1023
+ </filter>
1024
+ */
1025
+ const embossFilter = dom.createSvgElement(
1026
+ Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier},
1106
1027
  this.defs_);
1107
- // Set all gaussian blur pixels to 1 opacity before applying flood
1108
- const debugComponentTransfer = dom.createSvgElement(
1109
- Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter);
1110
1028
  dom.createSvgElement(
1111
- Svg.FEFUNCA,
1112
- {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'},
1113
- debugComponentTransfer);
1114
- // Color the highlight
1029
+ Svg.FEGAUSSIANBLUR,
1030
+ {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'},
1031
+ embossFilter);
1032
+ const feSpecularLighting = dom.createSvgElement(
1033
+ Svg.FESPECULARLIGHTING, {
1034
+ 'in': 'blur',
1035
+ 'surfaceScale': 1,
1036
+ 'specularConstant': 0.5,
1037
+ 'specularExponent': 10,
1038
+ 'lighting-color': 'white',
1039
+ 'result': 'specOut',
1040
+ },
1041
+ embossFilter);
1115
1042
  dom.createSvgElement(
1116
- Svg.FEFLOOD,
1117
- {'flood-color': '#ff0000', 'flood-opacity': 0.5, 'result': 'outColor'},
1118
- debugFilter);
1043
+ Svg.FEPOINTLIGHT, {'x': -5000, 'y': -10000, 'z': 20000},
1044
+ feSpecularLighting);
1119
1045
  dom.createSvgElement(
1120
1046
  Svg.FECOMPOSITE, {
1121
- 'in': 'outColor',
1122
- 'in2': 'outBlur',
1047
+ 'in': 'specOut',
1048
+ 'in2': 'SourceAlpha',
1123
1049
  'operator': 'in',
1124
- 'result': 'outGlow',
1050
+ 'result': 'specOut',
1125
1051
  },
1126
- debugFilter);
1127
- this.debugFilterId = debugFilter.id;
1128
- this.debugFilter_ = debugFilter;
1052
+ embossFilter);
1053
+ dom.createSvgElement(
1054
+ Svg.FECOMPOSITE, {
1055
+ 'in': 'SourceGraphic',
1056
+ 'in2': 'specOut',
1057
+ 'operator': 'arithmetic',
1058
+ 'k1': 0,
1059
+ 'k2': 1,
1060
+ 'k3': 1,
1061
+ 'k4': 0,
1062
+ },
1063
+ embossFilter);
1064
+ this.embossFilterId = embossFilter.id;
1065
+ this.embossFilter_ = embossFilter;
1066
+
1067
+ /*
1068
+ <pattern id="blocklyDisabledPattern837493" patternUnits="userSpaceOnUse"
1069
+ width="10" height="10">
1070
+ <rect width="10" height="10" fill="#aaa" />
1071
+ <path d="M 0 0 L 10 10 M 10 0 L 0 10" stroke="#cc0" />
1072
+ </pattern>
1073
+ */
1074
+ const disabledPattern = dom.createSvgElement(
1075
+ Svg.PATTERN, {
1076
+ 'id': 'blocklyDisabledPattern' + this.randomIdentifier,
1077
+ 'patternUnits': 'userSpaceOnUse',
1078
+ 'width': 10,
1079
+ 'height': 10,
1080
+ },
1081
+ this.defs_);
1082
+ dom.createSvgElement(
1083
+ Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern);
1084
+ dom.createSvgElement(
1085
+ Svg.PATH, {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'},
1086
+ disabledPattern);
1087
+ this.disabledPatternId = disabledPattern.id;
1088
+ this.disabledPattern_ = disabledPattern;
1089
+
1090
+ this.createDebugFilter();
1129
1091
  }
1130
- };
1131
1092
 
1132
- /**
1133
- * Inject renderer specific CSS into the page.
1134
- * @param {string} tagName The name of the style tag to use.
1135
- * @param {string} selector The CSS selector to use.
1136
- * @protected
1137
- */
1138
- ConstantProvider.prototype.injectCSS_ = function(tagName, selector) {
1139
- const cssArray = this.getCSS_(selector);
1140
- const cssNodeId = 'blockly-renderer-style-' + tagName;
1141
- this.cssNode_ =
1142
- /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId));
1143
- const text = cssArray.join('\n');
1144
- if (this.cssNode_) {
1145
- // Already injected, update if the theme changed.
1146
- this.cssNode_.firstChild.textContent = text;
1147
- return;
1093
+ /**
1094
+ * Create a filter for highlighting the currently rendering block during
1095
+ * render debugging.
1096
+ * @private
1097
+ */
1098
+ createDebugFilter() {
1099
+ // Only create the debug filter once.
1100
+ if (!this.debugFilter_) {
1101
+ const debugFilter = dom.createSvgElement(
1102
+ Svg.FILTER, {
1103
+ 'id': 'blocklyDebugFilter' + this.randomIdentifier,
1104
+ 'height': '160%',
1105
+ 'width': '180%',
1106
+ 'y': '-30%',
1107
+ 'x': '-40%',
1108
+ },
1109
+ this.defs_);
1110
+ // Set all gaussian blur pixels to 1 opacity before applying flood
1111
+ const debugComponentTransfer = dom.createSvgElement(
1112
+ Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter);
1113
+ dom.createSvgElement(
1114
+ Svg.FEFUNCA,
1115
+ {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'},
1116
+ debugComponentTransfer);
1117
+ // Color the highlight
1118
+ dom.createSvgElement(
1119
+ Svg.FEFLOOD, {
1120
+ 'flood-color': '#ff0000',
1121
+ 'flood-opacity': 0.5,
1122
+ 'result': 'outColor',
1123
+ },
1124
+ debugFilter);
1125
+ dom.createSvgElement(
1126
+ Svg.FECOMPOSITE, {
1127
+ 'in': 'outColor',
1128
+ 'in2': 'outBlur',
1129
+ 'operator': 'in',
1130
+ 'result': 'outGlow',
1131
+ },
1132
+ debugFilter);
1133
+ this.debugFilterId = debugFilter.id;
1134
+ this.debugFilter_ = debugFilter;
1135
+ }
1148
1136
  }
1149
- // Inject CSS tag at start of head.
1150
- const cssNode =
1151
- /** @type {!HTMLStyleElement} */ (document.createElement('style'));
1152
- cssNode.id = cssNodeId;
1153
- const cssTextNode = document.createTextNode(text);
1154
- cssNode.appendChild(cssTextNode);
1155
- document.head.insertBefore(cssNode, document.head.firstChild);
1156
- this.cssNode_ = cssNode;
1157
- };
1158
1137
 
1159
- /**
1160
- * Get any renderer specific CSS to inject when the renderer is initialized.
1161
- * @param {string} selector CSS selector to use.
1162
- * @return {!Array<string>} Array of CSS strings.
1163
- * @protected
1164
- */
1165
- ConstantProvider.prototype.getCSS_ = function(selector) {
1166
- return [
1167
- /* eslint-disable indent */
1168
- /* clang-format off */
1169
- // Text.
1170
- selector + ' .blocklyText, ',
1171
- selector + ' .blocklyFlyoutLabelText {',
1172
- 'font: ' + this.FIELD_TEXT_FONTWEIGHT + ' ' +
1173
- this.FIELD_TEXT_FONTSIZE + 'pt ' + this.FIELD_TEXT_FONTFAMILY + ';',
1174
- '}',
1175
-
1176
- // Fields.
1177
- selector + ' .blocklyText {',
1178
- 'fill: #fff;',
1179
- '}',
1180
- selector + ' .blocklyNonEditableText>rect,',
1181
- selector + ' .blocklyEditableText>rect {',
1182
- 'fill: ' + this.FIELD_BORDER_RECT_COLOUR + ';',
1183
- 'fill-opacity: .6;',
1184
- 'stroke: none;',
1185
- '}',
1186
- selector + ' .blocklyNonEditableText>text,',
1187
- selector + ' .blocklyEditableText>text {',
1188
- 'fill: #000;',
1189
- '}',
1190
-
1191
- // Flyout labels.
1192
- selector + ' .blocklyFlyoutLabelText {',
1193
- 'fill: #000;',
1194
- '}',
1195
-
1196
- // Bubbles.
1197
- selector + ' .blocklyText.blocklyBubbleText {',
1198
- 'fill: #000;',
1199
- '}',
1200
-
1201
- // Editable field hover.
1202
- selector + ' .blocklyEditableText:not(.editing):hover>rect {',
1203
- 'stroke: #fff;',
1204
- 'stroke-width: 2;',
1205
- '}',
1206
-
1207
- // Text field input.
1208
- selector + ' .blocklyHtmlInput {',
1209
- 'font-family: ' + this.FIELD_TEXT_FONTFAMILY + ';',
1210
- 'font-weight: ' + this.FIELD_TEXT_FONTWEIGHT + ';',
1211
- '}',
1212
-
1213
- // Selection highlight.
1214
- selector + ' .blocklySelected>.blocklyPath {',
1215
- 'stroke: #fc3;',
1216
- 'stroke-width: 3px;',
1217
- '}',
1218
-
1219
- // Connection highlight.
1220
- selector + ' .blocklyHighlightedConnectionPath {',
1221
- 'stroke: #fc3;',
1222
- '}',
1223
-
1224
- // Replaceable highlight.
1225
- selector + ' .blocklyReplaceable .blocklyPath {',
1226
- 'fill-opacity: .5;',
1227
- '}',
1228
- selector + ' .blocklyReplaceable .blocklyPathLight,',
1229
- selector + ' .blocklyReplaceable .blocklyPathDark {',
1230
- 'display: none;',
1231
- '}',
1232
-
1233
- // Insertion marker.
1234
- selector + ' .blocklyInsertionMarker>.blocklyPath {',
1235
- 'fill-opacity: ' + this.INSERTION_MARKER_OPACITY + ';',
1236
- 'stroke: none;',
1237
- '}',
1238
- /* clang-format on */
1239
- /* eslint-enable indent */
1240
- ];
1241
- };
1138
+ /**
1139
+ * Inject renderer specific CSS into the page.
1140
+ * @param {string} tagName The name of the style tag to use.
1141
+ * @param {string} selector The CSS selector to use.
1142
+ * @protected
1143
+ */
1144
+ injectCSS_(tagName, selector) {
1145
+ const cssArray = this.getCSS_(selector);
1146
+ const cssNodeId = 'blockly-renderer-style-' + tagName;
1147
+ this.cssNode_ =
1148
+ /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId));
1149
+ const text = cssArray.join('\n');
1150
+ if (this.cssNode_) {
1151
+ // Already injected, update if the theme changed.
1152
+ this.cssNode_.firstChild.textContent = text;
1153
+ return;
1154
+ }
1155
+ // Inject CSS tag at start of head.
1156
+ const cssNode =
1157
+ /** @type {!HTMLStyleElement} */ (document.createElement('style'));
1158
+ cssNode.id = cssNodeId;
1159
+ const cssTextNode = document.createTextNode(text);
1160
+ cssNode.appendChild(cssTextNode);
1161
+ document.head.insertBefore(cssNode, document.head.firstChild);
1162
+ this.cssNode_ = cssNode;
1163
+ }
1164
+
1165
+ /**
1166
+ * Get any renderer specific CSS to inject when the renderer is initialized.
1167
+ * @param {string} selector CSS selector to use.
1168
+ * @return {!Array<string>} Array of CSS strings.
1169
+ * @protected
1170
+ */
1171
+ getCSS_(selector) {
1172
+ return [
1173
+ /* eslint-disable indent */
1174
+ /* clang-format off */
1175
+ // Text.
1176
+ selector + ' .blocklyText, ',
1177
+ selector + ' .blocklyFlyoutLabelText {',
1178
+ 'font: ' + this.FIELD_TEXT_FONTWEIGHT + ' ' +
1179
+ this.FIELD_TEXT_FONTSIZE + 'pt ' + this.FIELD_TEXT_FONTFAMILY + ';',
1180
+ '}',
1181
+
1182
+ // Fields.
1183
+ selector + ' .blocklyText {',
1184
+ 'fill: #fff;',
1185
+ '}',
1186
+ selector + ' .blocklyNonEditableText>rect,',
1187
+ selector + ' .blocklyEditableText>rect {',
1188
+ 'fill: ' + this.FIELD_BORDER_RECT_COLOUR + ';',
1189
+ 'fill-opacity: .6;',
1190
+ 'stroke: none;',
1191
+ '}',
1192
+ selector + ' .blocklyNonEditableText>text,',
1193
+ selector + ' .blocklyEditableText>text {',
1194
+ 'fill: #000;',
1195
+ '}',
1196
+
1197
+ // Flyout labels.
1198
+ selector + ' .blocklyFlyoutLabelText {',
1199
+ 'fill: #000;',
1200
+ '}',
1201
+
1202
+ // Bubbles.
1203
+ selector + ' .blocklyText.blocklyBubbleText {',
1204
+ 'fill: #000;',
1205
+ '}',
1206
+
1207
+ // Editable field hover.
1208
+ selector + ' .blocklyEditableText:not(.editing):hover>rect {',
1209
+ 'stroke: #fff;',
1210
+ 'stroke-width: 2;',
1211
+ '}',
1212
+
1213
+ // Text field input.
1214
+ selector + ' .blocklyHtmlInput {',
1215
+ 'font-family: ' + this.FIELD_TEXT_FONTFAMILY + ';',
1216
+ 'font-weight: ' + this.FIELD_TEXT_FONTWEIGHT + ';',
1217
+ '}',
1218
+
1219
+ // Selection highlight.
1220
+ selector + ' .blocklySelected>.blocklyPath {',
1221
+ 'stroke: #fc3;',
1222
+ 'stroke-width: 3px;',
1223
+ '}',
1224
+
1225
+ // Connection highlight.
1226
+ selector + ' .blocklyHighlightedConnectionPath {',
1227
+ 'stroke: #fc3;',
1228
+ '}',
1229
+
1230
+ // Replaceable highlight.
1231
+ selector + ' .blocklyReplaceable .blocklyPath {',
1232
+ 'fill-opacity: .5;',
1233
+ '}',
1234
+ selector + ' .blocklyReplaceable .blocklyPathLight,',
1235
+ selector + ' .blocklyReplaceable .blocklyPathDark {',
1236
+ 'display: none;',
1237
+ '}',
1238
+
1239
+ // Insertion marker.
1240
+ selector + ' .blocklyInsertionMarker>.blocklyPath {',
1241
+ 'fill-opacity: ' + this.INSERTION_MARKER_OPACITY + ';',
1242
+ 'stroke: none;',
1243
+ '}',
1244
+ /* clang-format on */
1245
+ /* eslint-enable indent */
1246
+ ];
1247
+ }
1248
+ }
1242
1249
 
1243
1250
  exports.ConstantProvider = ConstantProvider;