File size: 15,642 Bytes
9ab1a44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
(window["webpackJsonpGUI"] = window["webpackJsonpGUI"] || []).push([["addon-entry-custom-block-shape"],{

/***/ "./src/addons/addons/custom-block-shape/_runtime_entry.js":
/*!****************************************************************!*\
  !*** ./src/addons/addons/custom-block-shape/_runtime_entry.js ***!
  \****************************************************************/
/*! exports provided: resources */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "resources", function() { return resources; });
/* harmony import */ var _userscript_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./userscript.js */ "./src/addons/addons/custom-block-shape/userscript.js");
/* generated by pull.js */

const resources = {
  "userscript.js": _userscript_js__WEBPACK_IMPORTED_MODULE_0__["default"]
};

/***/ }),

/***/ "./src/addons/addons/custom-block-shape/userscript.js":
/*!************************************************************!*\
  !*** ./src/addons/addons/custom-block-shape/userscript.js ***!
  \************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony default export */ __webpack_exports__["default"] = (async function (_ref) {
  let {
    addon,
    console
  } = _ref;
  var BlocklyInstance = await addon.tab.traps.getBlockly();
  (function (Blockly) {
    const BlockSvg = BlocklyInstance.BlockSvg;
    var vm = addon.tab.traps.vm;
    const {
      GRID_UNIT
    } = BlockSvg;
    function path2SegmentList(path) {
      const cmds = structuredClone(BlockSvg.CUSTOM_NOTCH_UTIL.supportedCommands);
      cmds.z = 0;
      const segment = /([astvzqmhlc])([^astvzqmhlc]*)/ig;
      const data = [];
      path.replace(segment, (_, command, args) => {
        let type = command.toLowerCase();
        const numbers = args.match(/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig);
        args = numbers ? numbers.map(Number) : [];
        if (type == "m" && args.length > 2) {
          data.push([command].concat(args.splice(0, 2)));
          type = "l";
          command = command == "m" ? "l" : "L";
        }
        while (true) {
          if (args.length == cmds[type]) {
            args.unshift(command);
            return data.push(args);
          }
          if (args.length < cmds[type]) throw new Error("malformed path data");
          data.push([command].concat(args.splice(0, cmds[type])));
        }
      });
      return data;
    }
    function scalePathXY(path, scaleX, scaleY) {
      const segments = path2SegmentList(path);
      return segments.map(segment => {
        const name = segment[0].toLowerCase();
        if (name === "v") {
          segment[1] *= scaleY;
          return segment;
        }
        if (name === "a") {
          segment[1] *= scaleX;
          segment[2] *= scaleY;
          segment[6] *= scaleX;
          segment[7] *= scaleY;
          return segment;
        }
        return segment.map((val, i) => {
          if (!i) return val;
          return val *= i % 2 ? scaleX : scaleY;
        });
      }).flat().join(" ");
    }
    function updateAllBlocks() {
      const workspace = Blockly.getMainWorkspace();
      if (workspace) {
        if (vm.editingTarget) {
          vm.emitWorkspaceUpdate();
        }
        const flyout = workspace.getFlyout();
        if (flyout) {
          const flyoutWorkspace = flyout.getWorkspace();
          Blockly.Xml.clearWorkspaceAndLoadFromXml(Blockly.Xml.workspaceToDom(flyoutWorkspace), flyoutWorkspace);
          workspace.getToolbox().refreshSelection();
          workspace.toolboxRefreshEnabled_ = true;
        }
      }
    }
    function applyChanges() {
      let paddingSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : addon.settings.get("paddingSize");
      let cornerSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : addon.settings.get("cornerSize");
      let notchSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : addon.settings.get("notchSize");
      let multiplier = paddingSize / 100;
      cornerSize = cornerSize / 100;
      notchSize = notchSize / 100;
      BlockSvg.SEP_SPACE_Y = 2 * GRID_UNIT * multiplier;
      BlockSvg.MIN_BLOCK_X = 16 * GRID_UNIT * multiplier;
      BlockSvg.MIN_BLOCK_X_OUTPUT = 12 * GRID_UNIT * multiplier;
      BlockSvg.MIN_BLOCK_X_SHADOW_OUTPUT = 10 * GRID_UNIT * multiplier;
      BlockSvg.MIN_BLOCK_Y = 12 * GRID_UNIT * multiplier;
      BlockSvg.EXTRA_STATEMENT_ROW_Y = 8 * GRID_UNIT * multiplier;
      BlockSvg.MIN_BLOCK_X_WITH_STATEMENT = 40 * GRID_UNIT * multiplier;
      BlockSvg.MIN_BLOCK_Y_SINGLE_FIELD_OUTPUT = 8 * GRID_UNIT * multiplier;
      BlockSvg.MIN_BLOCK_Y_REPORTER = 10 * GRID_UNIT * multiplier;
      BlockSvg.MIN_STATEMENT_INPUT_HEIGHT = 6 * GRID_UNIT * multiplier;
      BlockSvg.NOTCH_WIDTH = 8 * GRID_UNIT * multiplier;
      BlockSvg.NOTCH_HEIGHT = 2 * GRID_UNIT * multiplier * notchSize;
      BlockSvg.NOTCH_START_PADDING = 3 * GRID_UNIT; //* multiplier
      BlockSvg.ICON_SEPARATOR_HEIGHT = 10 * GRID_UNIT * multiplier;
      BlockSvg.NOTCH_PATH_LEFT = "c 2 0 3 ".concat(1 * notchSize, " 4 ").concat(2 * notchSize, " ") + "l ".concat(4 * multiplier * notchSize, " ").concat(4 * multiplier * notchSize, " ") + "c 1 ".concat(1 * notchSize, " 2 ").concat(2 * notchSize, " 4 ").concat(2 * notchSize, " ") + "h ".concat(24 * (multiplier - 0.5), " ") + "c 2 0 3 ".concat(-1 * notchSize, " 4 ").concat(-2 * notchSize, " ") + "l ".concat(4 * multiplier * notchSize, " ").concat(-4 * multiplier * notchSize, " ") + "c 1 ".concat(-1 * notchSize, " 2 ").concat(-2 * notchSize, " 4 ").concat(-2 * notchSize, " ");
      BlockSvg.NOTCH_PATH_RIGHT = "h ".concat(-4 * (cornerSize - 1) - 5 * (1 - notchSize), " ") + "c -2 0 -3 ".concat(1 * notchSize, " -4 ").concat(2 * notchSize, " ") + "l ".concat(-4 * multiplier * notchSize, " ").concat(4 * multiplier * notchSize, " ") + "c -1 ".concat(1 * notchSize, " -2 ").concat(2 * notchSize, " -4 ").concat(2 * notchSize, " ") + "h ".concat(-24 * (multiplier - 0.5), " ") + "c -2 0 -3 ".concat(-1 * notchSize, " -4 ").concat(-2 * notchSize, " ") + "l ".concat(-4 * multiplier * notchSize, " ").concat(-4 * multiplier * notchSize, " ") + "c -1 ".concat(-1 * notchSize, " -2 ").concat(-2 * notchSize, " -4 ").concat(-2 * notchSize, " ");

      /* Custom Notch API Support */
      const adjustedNotchSize = (multiplier > 1 ? multiplier - 0.05 : multiplier < 1 ? multiplier + 0.05 : multiplier) + (cornerSize - 1) / 10;
      BlockSvg.CUSTOM_NOTCHES.forEach(notch => {
        if (!notch.ogLeft) {
          notch.ogLeft = notch.left;
          notch.ogRight = notch.right;
        }
        notch.left = scalePathXY(notch.ogLeft, adjustedNotchSize, notchSize);
        notch.right = scalePathXY(notch.ogRight, adjustedNotchSize, notchSize);
      });

      /* Custom Shape API Support */
      BlockSvg.CUSTOM_SHAPES.forEach(shape => {
        if (!shape.ogEmptySize) {
          shape.ogEmptySize = shape.emptyInputWidth;
          shape.ogEmptyPath = shape.emptyInputPath;
        }
        shape.emptyInputWidth = shape.ogEmptySize * multiplier;
        shape.emptyInputPath = scalePathXY(shape.ogEmptyPath, multiplier, multiplier);
        if (shape.emptyInputPath[0] !== "M" && shape.emptyInputPath[0] !== "m") {
          shape.emptyInputPath = "M" + shape.emptyInputPath;
        }
      });
      BlockSvg.INPUT_SHAPE_HEXAGONAL_WIDTH = 12 * GRID_UNIT * multiplier;
      BlockSvg.INPUT_SHAPE_HEXAGONAL = "M " + 4 * GRID_UNIT * multiplier + ",0 " + " h " + 4 * GRID_UNIT + " l " + 4 * GRID_UNIT * multiplier + "," + 4 * GRID_UNIT * multiplier + " l " + -4 * GRID_UNIT * multiplier + "," + 4 * GRID_UNIT * multiplier + " h " + -4 * GRID_UNIT + " l " + -4 * GRID_UNIT * multiplier + "," + -4 * GRID_UNIT * multiplier + " l " + 4 * GRID_UNIT * multiplier + "," + -4 * GRID_UNIT * multiplier + " z";
      BlockSvg.INPUT_SHAPE_ROUND_WIDTH = 12 * GRID_UNIT * multiplier;
      BlockSvg.INPUT_SHAPE_ROUND = "M " + 4 * GRID_UNIT * multiplier + ",0" + " h " + 4 * GRID_UNIT * multiplier + " a " + 4 * GRID_UNIT * multiplier + " " + 4 * GRID_UNIT * multiplier + " 0 0 1 0 " + 8 * GRID_UNIT * multiplier + " h " + -4 * GRID_UNIT * multiplier + " a " + 4 * GRID_UNIT * multiplier + " " + 4 * GRID_UNIT * multiplier + " 0 0 1 0 -" + 8 * GRID_UNIT * multiplier + " z";
      BlockSvg.INPUT_SHAPE_SQUARE_WIDTH = 12 * GRID_UNIT * multiplier;
      BlockSvg.INPUT_SHAPE_SQUARE = 'm 0,4A 4,4 0 0,1 4,0' + ' h ' + (12 * GRID_UNIT * multiplier - 2 * 4) + 'a 4,4 0 0,1 4,4' + ' v ' + (8 * GRID_UNIT * multiplier - 2 * 4) + ' a 4,4 0 0,1 -4,4' + ' h ' + (-12 * GRID_UNIT * multiplier + 2 * 4) + 'a 4,4 0 0,1 -4,-4 z';
      BlockSvg.INPUT_SHAPE_LEAF_WIDTH = 12 * GRID_UNIT * multiplier;
      BlockSvg.INPUT_SHAPE_LEAF = "M ".concat(6 * GRID_UNIT * multiplier, " 0\n        l ").concat(2 * GRID_UNIT * multiplier, " 0\n        a ").concat(4 * GRID_UNIT * multiplier, " ").concat(4 * GRID_UNIT * multiplier, " 0 0 1 ").concat(4 * GRID_UNIT * multiplier, " ").concat(4 * GRID_UNIT * multiplier, "\n        l 0 ").concat(2.4 * GRID_UNIT * multiplier, "\n        a ").concat(1.6 * GRID_UNIT * multiplier, " ").concat(1.6 * GRID_UNIT * multiplier, " 0 0 1 -").concat(1.6 * GRID_UNIT * multiplier, " ").concat(1.6 * GRID_UNIT * multiplier, "\n        h -").concat(4 * GRID_UNIT * multiplier, "\n        l -").concat(2.4 * GRID_UNIT * multiplier, " 0\n        a ").concat(4 * GRID_UNIT * multiplier, " ").concat(4 * GRID_UNIT * multiplier, " 0 0 1 -").concat(4 * GRID_UNIT * multiplier, " -").concat(4 * GRID_UNIT * multiplier, "\n        l 0 -").concat(2.4 * GRID_UNIT * multiplier, "\n        a ").concat(1.6 * GRID_UNIT * multiplier, " ").concat(1.6 * GRID_UNIT * multiplier, " 0 0 1 ").concat(1.6 * GRID_UNIT * multiplier, " -").concat(1.6 * GRID_UNIT * multiplier, "\n        z");
      BlockSvg.INPUT_SHAPE_PLUS_WIDTH = 12 * GRID_UNIT * multiplier;
      BlockSvg.INPUT_SHAPE_PLUS = "M ".concat(9 * GRID_UNIT * multiplier, " 0\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 1 ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, "\n        l 0 2\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 0 ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, "\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 1 ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, "\n        l 0 4\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 1 -").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, "\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 0 -").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, "\n        l 0 2\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 1 -").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, "\n        h -").concat(6 * GRID_UNIT * multiplier, "\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 1 -").concat(GRID_UNIT * multiplier, " -").concat(GRID_UNIT * multiplier, "\n        l 0 -2\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 0 -").concat(GRID_UNIT * multiplier, " -").concat(GRID_UNIT * multiplier, "\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 1 -").concat(GRID_UNIT * multiplier, " -").concat(GRID_UNIT * multiplier, "\n        l 0 -4\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 1 ").concat(GRID_UNIT * multiplier, " -").concat(GRID_UNIT * multiplier, "\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 0 ").concat(GRID_UNIT * multiplier, " -").concat(GRID_UNIT * multiplier, "\n        l 0 -2\n        a ").concat(GRID_UNIT * multiplier, " ").concat(GRID_UNIT * multiplier, " 0 0 1 ").concat(GRID_UNIT * multiplier, " -").concat(GRID_UNIT * multiplier, " \n        z");
      BlockSvg.INPUT_SHAPE_HEIGHT = 8 * GRID_UNIT * multiplier;
      BlockSvg.FIELD_HEIGHT = 8 * GRID_UNIT * multiplier; // NOTE: Determines string input heights
      BlockSvg.FIELD_WIDTH = 6 * GRID_UNIT * Math.min(multiplier, 1) + 10 * GRID_UNIT * Math.max(multiplier - 1, 0);
      BlockSvg.FIELD_DEFAULT_CORNER_RADIUS = 4 * GRID_UNIT * multiplier;
      BlockSvg.EDITABLE_FIELD_PADDING = 1.5 * GRID_UNIT * multiplier;
      BlockSvg.BOX_FIELD_PADDING = 2 * GRID_UNIT * multiplier;
      BlockSvg.DROPDOWN_ARROW_PADDING = 2 * GRID_UNIT * multiplier;
      BlockSvg.FIELD_WIDTH_MIN_EDIT = 8 * GRID_UNIT * multiplier;
      BlockSvg.INPUT_AND_FIELD_MIN_X = 12 * GRID_UNIT * multiplier;
      BlockSvg.INLINE_PADDING_Y = 1 * GRID_UNIT * multiplier; // For when reporters are inside reporters
      BlockSvg.SHAPE_IN_SHAPE_PADDING[1][0] = 5 * GRID_UNIT * multiplier;
      BlockSvg.SHAPE_IN_SHAPE_PADDING[1][2] = 5 * GRID_UNIT * multiplier;
      BlockSvg.SHAPE_IN_SHAPE_PADDING[1][3] = 5 * GRID_UNIT * multiplier;
      var originalDropdownObject = BlocklyInstance.FieldDropdown.prototype.positionArrow;
      BlocklyInstance.FieldDropdown.prototype.positionArrow = function (x) {
        this.arrowY_ = 11 * multiplier;
        return originalDropdownObject.call(this, x);
      };

      // Corner setting
      BlockSvg.CORNER_RADIUS = 1 * GRID_UNIT * cornerSize * 100 / 100;
      BlockSvg.TOP_LEFT_CORNER_START = "m 0," + BlockSvg.CORNER_RADIUS;
      BlockSvg.TOP_LEFT_CORNER = "A " + BlockSvg.CORNER_RADIUS + "," + BlockSvg.CORNER_RADIUS + " 0 0,1 " + BlockSvg.CORNER_RADIUS + ",0";
      BlockSvg.TOP_RIGHT_CORNER = "a " + BlockSvg.CORNER_RADIUS + "," + BlockSvg.CORNER_RADIUS + " 0 0,1 " + BlockSvg.CORNER_RADIUS + "," + BlockSvg.CORNER_RADIUS;
      BlockSvg.BOTTOM_RIGHT_CORNER = " a " + BlockSvg.CORNER_RADIUS + "," + BlockSvg.CORNER_RADIUS + " 0 0,1 -" + BlockSvg.CORNER_RADIUS + "," + BlockSvg.CORNER_RADIUS;
      BlockSvg.BOTTOM_LEFT_CORNER = "a " + BlockSvg.CORNER_RADIUS + "," + BlockSvg.CORNER_RADIUS + " 0 0,1 -" + BlockSvg.CORNER_RADIUS + ",-" + BlockSvg.CORNER_RADIUS;
      BlockSvg.INNER_TOP_LEFT_CORNER = " a " + BlockSvg.CORNER_RADIUS + "," + BlockSvg.CORNER_RADIUS + " 0 0,0 -" + BlockSvg.CORNER_RADIUS + "," + BlockSvg.CORNER_RADIUS;
      BlockSvg.INNER_BOTTOM_LEFT_CORNER = "a " + BlockSvg.CORNER_RADIUS + "," + BlockSvg.CORNER_RADIUS + " 0 0,0 " + BlockSvg.CORNER_RADIUS + "," + BlockSvg.CORNER_RADIUS;
      BlockSvg.TOP_RIGHT_CORNER_DEFINE_HAT = "a " + BlockSvg.DEFINE_HAT_CORNER_RADIUS + "," + BlockSvg.DEFINE_HAT_CORNER_RADIUS + " 0 0,1 " + BlockSvg.DEFINE_HAT_CORNER_RADIUS + "," + BlockSvg.DEFINE_HAT_CORNER_RADIUS + " v " + (1 * GRID_UNIT - BlockSvg.CORNER_RADIUS);
      BlockSvg.STATEMENT_INPUT_INNER_SPACE = 2.8 * GRID_UNIT - 0.9 * GRID_UNIT * cornerSize;
    }
    function applyAndUpdate() {
      applyChanges(...arguments);
      updateAllBlocks();
    }
    addon.settings.addEventListener("change", () => applyAndUpdate());
    addon.self.addEventListener("disabled", () => {
      // Scratch 3.0 blocks
      applyAndUpdate(100, 100, 100);
    });
    addon.self.addEventListener("reenabled", () => applyAndUpdate());
    applyAndUpdate();
  })(window.Blockly);
});

/***/ })

}]);
//# sourceMappingURL=addon-entry-custom-block-shape.js.map