xyc
2025-02-21 664db98c9e8595ce4dd636a27f480e3a08b81ff5
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
var svgEditorExtension_helloworld = (function () {
  'use strict';
 
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
    try {
      var info = gen[key](arg);
      var value = info.value;
    } catch (error) {
      reject(error);
      return;
    }
 
    if (info.done) {
      resolve(value);
    } else {
      Promise.resolve(value).then(_next, _throw);
    }
  }
 
  function _asyncToGenerator(fn) {
    return function () {
      var self = this,
          args = arguments;
      return new Promise(function (resolve, reject) {
        var gen = fn.apply(self, args);
 
        function _next(value) {
          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
        }
 
        function _throw(err) {
          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
        }
 
        _next(undefined);
      });
    };
  }
 
  function _slicedToArray(arr, i) {
    return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
  }
 
  function _arrayWithHoles(arr) {
    if (Array.isArray(arr)) return arr;
  }
 
  function _iterableToArrayLimit(arr, i) {
    var _arr = [];
    var _n = true;
    var _d = false;
    var _e = undefined;
 
    try {
      for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
        _arr.push(_s.value);
 
        if (i && _arr.length === i) break;
      }
    } catch (err) {
      _d = true;
      _e = err;
    } finally {
      try {
        if (!_n && _i["return"] != null) _i["return"]();
      } finally {
        if (_d) throw _e;
      }
    }
 
    return _arr;
  }
 
  function _nonIterableRest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance");
  }
 
  /* globals jQuery */
 
  /**
   * ext-helloworld.js
   *
   * @license MIT
   *
   * @copyright 2010 Alexis Deveria
   *
   */
 
  /**
  * This is a very basic SVG-Edit extension. It adds a "Hello World" button in
  *  the left ("mode") panel. Clicking on the button, and then the canvas
  *  will show the user the point on the canvas that was clicked on.
  */
  var extHelloworld = {
    name: 'helloworld',
    init: function () {
      var _init = _asyncToGenerator(
      /*#__PURE__*/
      regeneratorRuntime.mark(function _callee(_ref) {
        var importLocale, strings, svgEditor, $, svgCanvas;
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                importLocale = _ref.importLocale;
                _context.next = 3;
                return importLocale();
 
              case 3:
                strings = _context.sent;
                svgEditor = this;
                $ = jQuery;
                svgCanvas = svgEditor.canvas;
                return _context.abrupt("return", {
                  name: strings.name,
                  // For more notes on how to make an icon file, see the source of
                  // the helloworld-icon.xml
                  svgicons: svgEditor.curConfig.extIconsPath + 'helloworld-icon.xml',
                  // Multiple buttons can be added in this array
                  buttons: [{
                    // Must match the icon ID in helloworld-icon.xml
                    id: 'hello_world',
                    // Fallback, e.g., for `file:///` access
                    icon: svgEditor.curConfig.extIconsPath + 'helloworld.png',
                    // This indicates that the button will be added to the "mode"
                    // button panel on the left side
                    type: 'mode',
                    // Tooltip text
                    title: strings.buttons[0].title,
                    // Events
                    events: {
                      click: function click() {
                        // The action taken when the button is clicked on.
                        // For "mode" buttons, any other button will
                        // automatically be de-pressed.
                        svgCanvas.setMode('hello_world');
                      }
                    }
                  }],
                  // This is triggered when the main mouse button is pressed down
                  // on the editor canvas (not the tool panels)
                  mouseDown: function mouseDown() {
                    // Check the mode on mousedown
                    if (svgCanvas.getMode() === 'hello_world') {
                      // The returned object must include "started" with
                      // a value of true in order for mouseUp to be triggered
                      return {
                        started: true
                      };
                    }
                  },
                  // This is triggered from anywhere, but "started" must have been set
                  // to true (see above). Note that "opts" is an object with event info
                  mouseUp: function mouseUp(opts) {
                    // Check the mode on mouseup
                    if (svgCanvas.getMode() === 'hello_world') {
                      var zoom = svgCanvas.getZoom(); // Get the actual coordinate by dividing by the zoom value
 
                      var x = opts.mouse_x / zoom;
                      var y = opts.mouse_y / zoom; // We do our own formatting
 
                      var text = strings.text;
                      [['x', x], ['y', y]].forEach(function (_ref2) {
                        var _ref3 = _slicedToArray(_ref2, 2),
                            prop = _ref3[0],
                            val = _ref3[1];
 
                        text = text.replace('{' + prop + '}', val);
                      }); // Show the text using the custom alert function
 
                      $.alert(text);
                    }
                  }
                });
 
              case 8:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this);
      }));
 
      return function init(_x) {
        return _init.apply(this, arguments);
      };
    }()
  };
 
  return extHelloworld;
 
}());