@idraw/core 0.2.0-y.0 → 0.3.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +4490 -2246
- package/dist/index.d.ts +8 -12
- package/dist/index.esm.js +5992 -0
- package/dist/index.global.js +4491 -2247
- package/dist/index.global.min.js +1 -0
- package/esm/default.d.ts +1 -0
- package/esm/default.js +2 -0
- package/esm/esm.d.ts +2 -0
- package/esm/esm.js +3 -0
- package/esm/index.js +195 -0
- package/esm/names.d.ts +15 -0
- package/esm/names.js +15 -0
- package/package.json +11 -7
- package/dist/index.es.js +0 -3748
package/dist/index.es.js
DELETED
|
@@ -1,3748 +0,0 @@
|
|
|
1
|
-
var __assign$1 = function() {
|
|
2
|
-
__assign$1 = Object.assign || function __assign(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
6
|
-
}
|
|
7
|
-
return t;
|
|
8
|
-
};
|
|
9
|
-
return __assign$1.apply(this, arguments);
|
|
10
|
-
};
|
|
11
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
12
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function __generator(thisArg, body) {
|
|
21
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
22
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
23
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
24
|
-
function step(op) {
|
|
25
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
26
|
-
while (_) try {
|
|
27
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
28
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
29
|
-
switch (op[0]) {
|
|
30
|
-
case 0: case 1: t = op; break;
|
|
31
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
32
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
33
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
34
|
-
default:
|
|
35
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
36
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
37
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
38
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
39
|
-
if (t[2]) _.ops.pop();
|
|
40
|
-
_.trys.pop(); continue;
|
|
41
|
-
}
|
|
42
|
-
op = body.call(thisArg, _);
|
|
43
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
44
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
var __assign = function() {
|
|
49
|
-
__assign = Object.assign || function __assign(t) {
|
|
50
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
51
|
-
s = arguments[i];
|
|
52
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
53
|
-
}
|
|
54
|
-
return t;
|
|
55
|
-
};
|
|
56
|
-
return __assign.apply(this, arguments);
|
|
57
|
-
};
|
|
58
|
-
function compose$1(middleware) {
|
|
59
|
-
return function (context, next) {
|
|
60
|
-
return dispatch(0);
|
|
61
|
-
function dispatch(i) {
|
|
62
|
-
var fn = middleware[i];
|
|
63
|
-
if (i === middleware.length && next) {
|
|
64
|
-
fn = next;
|
|
65
|
-
}
|
|
66
|
-
if (!fn)
|
|
67
|
-
return Promise.resolve();
|
|
68
|
-
try {
|
|
69
|
-
return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
|
|
70
|
-
}
|
|
71
|
-
catch (err) {
|
|
72
|
-
return Promise.reject(err);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function delay$1(time) {
|
|
78
|
-
return new Promise(function (resolve) {
|
|
79
|
-
setTimeout(function () {
|
|
80
|
-
resolve();
|
|
81
|
-
}, time);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function throttle$1(fn, timeout) {
|
|
85
|
-
var timer = -1;
|
|
86
|
-
return function () {
|
|
87
|
-
var args = [];
|
|
88
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
89
|
-
args[_i] = arguments[_i];
|
|
90
|
-
}
|
|
91
|
-
if (timer > 0) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
timer = setTimeout(function () {
|
|
95
|
-
fn.apply(void 0, args);
|
|
96
|
-
timer = -1;
|
|
97
|
-
}, timeout);
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function downloadImageFromCanvas$1(canvas, opts) {
|
|
101
|
-
var filename = opts.filename, _a = opts.type, type = _a === void 0 ? 'image/jpeg' : _a;
|
|
102
|
-
var stream = canvas.toDataURL(type);
|
|
103
|
-
var downloadLink = document.createElement('a');
|
|
104
|
-
downloadLink.href = stream;
|
|
105
|
-
downloadLink.download = filename;
|
|
106
|
-
var downloadClickEvent = document.createEvent('MouseEvents');
|
|
107
|
-
downloadClickEvent.initEvent('click', true, false);
|
|
108
|
-
downloadLink.dispatchEvent(downloadClickEvent);
|
|
109
|
-
}
|
|
110
|
-
function toColorHexNum$1(color) {
|
|
111
|
-
return parseInt(color.replace(/^\#/, '0x'));
|
|
112
|
-
}
|
|
113
|
-
function toColorHexStr$1(color) {
|
|
114
|
-
return '#' + color.toString(16);
|
|
115
|
-
}
|
|
116
|
-
function isColorStr$3(color) {
|
|
117
|
-
return typeof color === 'string' && /^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color);
|
|
118
|
-
}
|
|
119
|
-
function createUUID$3() {
|
|
120
|
-
function str4() {
|
|
121
|
-
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
122
|
-
}
|
|
123
|
-
return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
|
|
124
|
-
}
|
|
125
|
-
function deepClone$6(target) {
|
|
126
|
-
function _clone(t) {
|
|
127
|
-
var type = is$2(t);
|
|
128
|
-
if (['Null', 'Number', 'String', 'Boolean', 'Undefined'].indexOf(type) >= 0) {
|
|
129
|
-
return t;
|
|
130
|
-
}
|
|
131
|
-
else if (type === 'Array') {
|
|
132
|
-
var arr_1 = [];
|
|
133
|
-
t.forEach(function (item) {
|
|
134
|
-
arr_1.push(_clone(item));
|
|
135
|
-
});
|
|
136
|
-
return arr_1;
|
|
137
|
-
}
|
|
138
|
-
else if (type === 'Object') {
|
|
139
|
-
var obj_1 = {};
|
|
140
|
-
var keys = Object.keys(t);
|
|
141
|
-
keys.forEach(function (key) {
|
|
142
|
-
obj_1[key] = _clone(t[key]);
|
|
143
|
-
});
|
|
144
|
-
return obj_1;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return _clone(target);
|
|
148
|
-
}
|
|
149
|
-
function is$2(data) {
|
|
150
|
-
return Object.prototype.toString.call(data).replace(/[\]|\[]{1,1}/ig, '').split(' ')[1];
|
|
151
|
-
}
|
|
152
|
-
function parsePrototype$1(data) {
|
|
153
|
-
var typeStr = Object.prototype.toString.call(data) || '';
|
|
154
|
-
var result = typeStr.replace(/(\[object|\])/ig, '').trim();
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
var istype$2 = {
|
|
158
|
-
type: function (data, lowerCase) {
|
|
159
|
-
var result = parsePrototype$1(data);
|
|
160
|
-
return lowerCase === true ? result.toLocaleLowerCase() : result;
|
|
161
|
-
},
|
|
162
|
-
array: function (data) {
|
|
163
|
-
return parsePrototype$1(data) === 'Array';
|
|
164
|
-
},
|
|
165
|
-
json: function (data) {
|
|
166
|
-
return parsePrototype$1(data) === 'Object';
|
|
167
|
-
},
|
|
168
|
-
function: function (data) {
|
|
169
|
-
return parsePrototype$1(data) === 'Function';
|
|
170
|
-
},
|
|
171
|
-
asyncFunction: function (data) {
|
|
172
|
-
return parsePrototype$1(data) === 'AsyncFunction';
|
|
173
|
-
},
|
|
174
|
-
string: function (data) {
|
|
175
|
-
return parsePrototype$1(data) === 'String';
|
|
176
|
-
},
|
|
177
|
-
number: function (data) {
|
|
178
|
-
return parsePrototype$1(data) === 'Number';
|
|
179
|
-
},
|
|
180
|
-
undefined: function (data) {
|
|
181
|
-
return parsePrototype$1(data) === 'Undefined';
|
|
182
|
-
},
|
|
183
|
-
null: function (data) {
|
|
184
|
-
return parsePrototype$1(data) === 'Null';
|
|
185
|
-
},
|
|
186
|
-
promise: function (data) {
|
|
187
|
-
return parsePrototype$1(data) === 'Promise';
|
|
188
|
-
},
|
|
189
|
-
nodeList: function (data) {
|
|
190
|
-
return parsePrototype$1(data) === 'NodeList';
|
|
191
|
-
},
|
|
192
|
-
imageData: function (data) {
|
|
193
|
-
return parsePrototype$1(data) === 'ImageData';
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
var Image$1 = window.Image, Blob$1 = window.Blob, FileReader$1 = window.FileReader;
|
|
197
|
-
function loadImage$2(src) {
|
|
198
|
-
return new Promise(function (resolve, reject) {
|
|
199
|
-
var img = new Image$1;
|
|
200
|
-
img.onload = function () {
|
|
201
|
-
resolve(img);
|
|
202
|
-
};
|
|
203
|
-
img.onabort = reject;
|
|
204
|
-
img.onerror = reject;
|
|
205
|
-
img.src = src;
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
function loadSVG$2(svg) {
|
|
209
|
-
return new Promise(function (resolve, reject) {
|
|
210
|
-
var _svg = svg;
|
|
211
|
-
var image = new Image$1();
|
|
212
|
-
var blob = new Blob$1([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
213
|
-
var reader = new FileReader$1();
|
|
214
|
-
reader.readAsDataURL(blob);
|
|
215
|
-
reader.onload = function (event) {
|
|
216
|
-
var _a;
|
|
217
|
-
var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
218
|
-
image.onload = function () {
|
|
219
|
-
resolve(image);
|
|
220
|
-
};
|
|
221
|
-
image.src = base64;
|
|
222
|
-
};
|
|
223
|
-
reader.onerror = function (err) {
|
|
224
|
-
reject(err);
|
|
225
|
-
};
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
function loadHTML$2(html, opts) {
|
|
229
|
-
var width = opts.width, height = opts.height;
|
|
230
|
-
return new Promise(function (resolve, reject) {
|
|
231
|
-
var _svg = "\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" + (width || '') + "\" height = \"" + (height || '') + "\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n " + html + "\n </div>\n </foreignObject>\n </svg>\n ";
|
|
232
|
-
var image = new Image$1();
|
|
233
|
-
var blob = new Blob$1([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
234
|
-
var reader = new FileReader$1();
|
|
235
|
-
reader.readAsDataURL(blob);
|
|
236
|
-
reader.onload = function (event) {
|
|
237
|
-
var _a;
|
|
238
|
-
var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
239
|
-
image.onload = function () {
|
|
240
|
-
resolve(image);
|
|
241
|
-
};
|
|
242
|
-
image.src = base64;
|
|
243
|
-
};
|
|
244
|
-
reader.onerror = function (err) {
|
|
245
|
-
reject(err);
|
|
246
|
-
};
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
var index$1 = {
|
|
250
|
-
time: {
|
|
251
|
-
delay: delay$1,
|
|
252
|
-
compose: compose$1,
|
|
253
|
-
throttle: throttle$1,
|
|
254
|
-
},
|
|
255
|
-
loader: {
|
|
256
|
-
loadImage: loadImage$2,
|
|
257
|
-
loadSVG: loadSVG$2,
|
|
258
|
-
loadHTML: loadHTML$2,
|
|
259
|
-
},
|
|
260
|
-
file: {
|
|
261
|
-
downloadImageFromCanvas: downloadImageFromCanvas$1,
|
|
262
|
-
},
|
|
263
|
-
color: {
|
|
264
|
-
toColorHexStr: toColorHexStr$1,
|
|
265
|
-
toColorHexNum: toColorHexNum$1,
|
|
266
|
-
isColorStr: isColorStr$3,
|
|
267
|
-
},
|
|
268
|
-
uuid: {
|
|
269
|
-
createUUID: createUUID$3
|
|
270
|
-
},
|
|
271
|
-
istype: istype$2,
|
|
272
|
-
data: {
|
|
273
|
-
deepClone: deepClone$6,
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
var BoardEvent = (function () {
|
|
277
|
-
function BoardEvent() {
|
|
278
|
-
this._listeners = new Map();
|
|
279
|
-
}
|
|
280
|
-
BoardEvent.prototype.on = function (eventKey, callback) {
|
|
281
|
-
if (this._listeners.has(eventKey)) {
|
|
282
|
-
var callbacks = this._listeners.get(eventKey);
|
|
283
|
-
callbacks === null || callbacks === void 0 ? void 0 : callbacks.push(callback);
|
|
284
|
-
this._listeners.set(eventKey, callbacks || []);
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
this._listeners.set(eventKey, [callback]);
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
BoardEvent.prototype.off = function (eventKey, callback) {
|
|
291
|
-
if (this._listeners.has(eventKey)) {
|
|
292
|
-
var callbacks = this._listeners.get(eventKey);
|
|
293
|
-
if (Array.isArray(callbacks)) {
|
|
294
|
-
for (var i = 0; i < (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length); i++) {
|
|
295
|
-
if (callbacks[i] === callback) {
|
|
296
|
-
callbacks.splice(i, 1);
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
this._listeners.set(eventKey, callbacks || []);
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
BoardEvent.prototype.trigger = function (eventKey, arg) {
|
|
305
|
-
var callbacks = this._listeners.get(eventKey);
|
|
306
|
-
if (Array.isArray(callbacks)) {
|
|
307
|
-
callbacks.forEach(function (cb) {
|
|
308
|
-
cb(arg);
|
|
309
|
-
});
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
BoardEvent.prototype.has = function (name) {
|
|
317
|
-
if (this._listeners.has(name)) {
|
|
318
|
-
var list = this._listeners.get(name);
|
|
319
|
-
if (Array.isArray(list) && list.length > 0) {
|
|
320
|
-
return true;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return false;
|
|
324
|
-
};
|
|
325
|
-
return BoardEvent;
|
|
326
|
-
}());
|
|
327
|
-
var TempData$1 = (function () {
|
|
328
|
-
function TempData() {
|
|
329
|
-
this._temp = {
|
|
330
|
-
prevClickPoint: null
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
TempData.prototype.set = function (name, value) {
|
|
334
|
-
this._temp[name] = value;
|
|
335
|
-
};
|
|
336
|
-
TempData.prototype.get = function (name) {
|
|
337
|
-
return this._temp[name];
|
|
338
|
-
};
|
|
339
|
-
TempData.prototype.clear = function () {
|
|
340
|
-
this._temp = {
|
|
341
|
-
prevClickPoint: null,
|
|
342
|
-
};
|
|
343
|
-
};
|
|
344
|
-
return TempData;
|
|
345
|
-
}());
|
|
346
|
-
var Watcher = (function () {
|
|
347
|
-
function Watcher(canvas) {
|
|
348
|
-
this._isMoving = false;
|
|
349
|
-
this._temp = new TempData$1;
|
|
350
|
-
this._canvas = canvas;
|
|
351
|
-
this._isMoving = false;
|
|
352
|
-
this._initEvent();
|
|
353
|
-
this._event = new BoardEvent;
|
|
354
|
-
}
|
|
355
|
-
Watcher.prototype.on = function (name, callback) {
|
|
356
|
-
this._event.on(name, callback);
|
|
357
|
-
};
|
|
358
|
-
Watcher.prototype.off = function (name, callback) {
|
|
359
|
-
this._event.off(name, callback);
|
|
360
|
-
};
|
|
361
|
-
Watcher.prototype._initEvent = function () {
|
|
362
|
-
var canvas = this._canvas;
|
|
363
|
-
canvas.addEventListener('mousemove', this._listenHover.bind(this), true);
|
|
364
|
-
canvas.addEventListener('mousedown', this._listenMoveStart.bind(this), true);
|
|
365
|
-
canvas.addEventListener('mousemove', this._listenMove.bind(this), true);
|
|
366
|
-
canvas.addEventListener('mouseup', this._listenMoveEnd.bind(this), true);
|
|
367
|
-
canvas.addEventListener('mouseleave', this._listenMoveEnd.bind(this), true);
|
|
368
|
-
canvas.addEventListener('mouseleave', this._listenLeave.bind(this), true);
|
|
369
|
-
canvas.addEventListener('click', this._listenClick.bind(this), true);
|
|
370
|
-
canvas.addEventListener('wheel', this._listenWheel.bind(this), true);
|
|
371
|
-
canvas.addEventListener('touchstart', this._listenMoveStart.bind(this), true);
|
|
372
|
-
canvas.addEventListener('touchmove', this._listenMove.bind(this), true);
|
|
373
|
-
canvas.addEventListener('touchend', this._listenMoveEnd.bind(this), true);
|
|
374
|
-
};
|
|
375
|
-
Watcher.prototype._listenHover = function (e) {
|
|
376
|
-
e.preventDefault();
|
|
377
|
-
var p = this._getPosition(e);
|
|
378
|
-
if (this._isVaildPoint(p)) {
|
|
379
|
-
if (this._event.has('hover')) {
|
|
380
|
-
this._event.trigger('hover', p);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
this._isMoving = true;
|
|
384
|
-
};
|
|
385
|
-
Watcher.prototype._listenLeave = function (e) {
|
|
386
|
-
e.preventDefault();
|
|
387
|
-
if (this._event.has('leave')) {
|
|
388
|
-
this._event.trigger('leave', undefined);
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
Watcher.prototype._listenMoveStart = function (e) {
|
|
392
|
-
e.preventDefault();
|
|
393
|
-
var p = this._getPosition(e);
|
|
394
|
-
if (this._isVaildPoint(p)) {
|
|
395
|
-
if (this._event.has('point')) {
|
|
396
|
-
this._event.trigger('point', p);
|
|
397
|
-
}
|
|
398
|
-
if (this._event.has('moveStart')) {
|
|
399
|
-
this._event.trigger('moveStart', p);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
this._isMoving = true;
|
|
403
|
-
};
|
|
404
|
-
Watcher.prototype._listenMove = function (e) {
|
|
405
|
-
e.preventDefault();
|
|
406
|
-
e.stopPropagation();
|
|
407
|
-
if (this._event.has('move') && this._isMoving === true) {
|
|
408
|
-
var p = this._getPosition(e);
|
|
409
|
-
if (this._isVaildPoint(p)) {
|
|
410
|
-
this._event.trigger('move', p);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
Watcher.prototype._listenMoveEnd = function (e) {
|
|
415
|
-
e.preventDefault();
|
|
416
|
-
if (this._event.has('moveEnd')) {
|
|
417
|
-
var p = this._getPosition(e);
|
|
418
|
-
if (this._isVaildPoint(p)) {
|
|
419
|
-
this._event.trigger('moveEnd', p);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
this._isMoving = false;
|
|
423
|
-
};
|
|
424
|
-
Watcher.prototype._listenWheel = function (e) {
|
|
425
|
-
e.preventDefault();
|
|
426
|
-
if (this._event.has('wheelX') && (e.deltaX > 0 || e.deltaX < 0)) {
|
|
427
|
-
this._event.trigger('wheelX', e.deltaX);
|
|
428
|
-
}
|
|
429
|
-
if (this._event.has('wheelY') && (e.deltaY > 0 || e.deltaY < 0)) {
|
|
430
|
-
this._event.trigger('wheelY', e.deltaY);
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
Watcher.prototype._listenClick = function (e) {
|
|
434
|
-
e.preventDefault();
|
|
435
|
-
var maxLimitTime = 500;
|
|
436
|
-
var p = this._getPosition(e);
|
|
437
|
-
var t = Date.now();
|
|
438
|
-
if (this._isVaildPoint(p)) {
|
|
439
|
-
var preClickPoint = this._temp.get('prevClickPoint');
|
|
440
|
-
if (preClickPoint && (t - preClickPoint.t <= maxLimitTime)
|
|
441
|
-
&& Math.abs(preClickPoint.x - p.x) <= 5
|
|
442
|
-
&& Math.abs(preClickPoint.y - p.y) <= 5) {
|
|
443
|
-
if (this._event.has('doubleClick')) {
|
|
444
|
-
this._event.trigger('doubleClick', { x: p.x, y: p.y });
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
else {
|
|
448
|
-
this._temp.set('prevClickPoint', { x: p.x, y: p.y, t: t, });
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
Watcher.prototype._getPosition = function (e) {
|
|
453
|
-
var canvas = this._canvas;
|
|
454
|
-
var x = 0;
|
|
455
|
-
var y = 0;
|
|
456
|
-
if (e && e.touches && e.touches.length > 0) {
|
|
457
|
-
var touch = e.touches[0];
|
|
458
|
-
if (touch) {
|
|
459
|
-
x = touch.clientX;
|
|
460
|
-
y = touch.clientY;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
x = e.clientX;
|
|
465
|
-
y = e.clientY;
|
|
466
|
-
}
|
|
467
|
-
var p = {
|
|
468
|
-
x: x - canvas.getBoundingClientRect().left,
|
|
469
|
-
y: y - canvas.getBoundingClientRect().top,
|
|
470
|
-
t: Date.now(),
|
|
471
|
-
};
|
|
472
|
-
return p;
|
|
473
|
-
};
|
|
474
|
-
Watcher.prototype._isVaildPoint = function (p) {
|
|
475
|
-
return (p.x > 0 && p.y > 0);
|
|
476
|
-
};
|
|
477
|
-
return Watcher;
|
|
478
|
-
}());
|
|
479
|
-
function setStyle(dom, style) {
|
|
480
|
-
var originStyle = getStyle(dom);
|
|
481
|
-
var _style = __assign(__assign({}, originStyle), style);
|
|
482
|
-
var keys = Object.keys(_style);
|
|
483
|
-
var styleStr = '';
|
|
484
|
-
keys.forEach(function (key) {
|
|
485
|
-
styleStr += key + ":" + (_style[key] || '') + ";";
|
|
486
|
-
});
|
|
487
|
-
dom.setAttribute('style', styleStr);
|
|
488
|
-
}
|
|
489
|
-
function getStyle(dom) {
|
|
490
|
-
var styleObj = {};
|
|
491
|
-
var style = dom.getAttribute('style') || '';
|
|
492
|
-
var styleList = style.split(';');
|
|
493
|
-
styleList.forEach(function (item) {
|
|
494
|
-
var dataList = item.split(':');
|
|
495
|
-
if (dataList[0] && typeof dataList[0] === 'string') {
|
|
496
|
-
styleObj[dataList[0]] = dataList[1] || '';
|
|
497
|
-
}
|
|
498
|
-
});
|
|
499
|
-
return styleObj;
|
|
500
|
-
}
|
|
501
|
-
var Context = (function () {
|
|
502
|
-
function Context(ctx, opts) {
|
|
503
|
-
this._opts = opts;
|
|
504
|
-
this._ctx = ctx;
|
|
505
|
-
this._transform = {
|
|
506
|
-
scale: 1,
|
|
507
|
-
scrollX: 0,
|
|
508
|
-
scrollY: 0,
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
Context.prototype.resetSize = function (opts) {
|
|
512
|
-
this._opts = __assign(__assign({}, this._opts), opts);
|
|
513
|
-
};
|
|
514
|
-
Context.prototype.calcDeviceNum = function (num) {
|
|
515
|
-
return num * this._opts.devicePixelRatio;
|
|
516
|
-
};
|
|
517
|
-
Context.prototype.calcScreenNum = function (num) {
|
|
518
|
-
return num / this._opts.devicePixelRatio;
|
|
519
|
-
};
|
|
520
|
-
Context.prototype.getSize = function () {
|
|
521
|
-
return {
|
|
522
|
-
width: this._opts.width,
|
|
523
|
-
height: this._opts.height,
|
|
524
|
-
contextWidth: this._opts.contextWidth,
|
|
525
|
-
contextHeight: this._opts.contextHeight,
|
|
526
|
-
devicePixelRatio: this._opts.devicePixelRatio,
|
|
527
|
-
};
|
|
528
|
-
};
|
|
529
|
-
Context.prototype.setTransform = function (config) {
|
|
530
|
-
this._transform = __assign(__assign({}, this._transform), config);
|
|
531
|
-
};
|
|
532
|
-
Context.prototype.getTransform = function () {
|
|
533
|
-
return {
|
|
534
|
-
scale: this._transform.scale,
|
|
535
|
-
scrollX: this._transform.scrollX,
|
|
536
|
-
scrollY: this._transform.scrollY,
|
|
537
|
-
};
|
|
538
|
-
};
|
|
539
|
-
Context.prototype.setFillStyle = function (color) {
|
|
540
|
-
this._ctx.fillStyle = color;
|
|
541
|
-
};
|
|
542
|
-
Context.prototype.fill = function (fillRule) {
|
|
543
|
-
return this._ctx.fill(fillRule || 'nonzero');
|
|
544
|
-
};
|
|
545
|
-
Context.prototype.arc = function (x, y, radius, startAngle, endAngle, anticlockwise) {
|
|
546
|
-
return this._ctx.arc(this._doSize(x), this._doSize(y), this._doSize(radius), startAngle, endAngle, anticlockwise);
|
|
547
|
-
};
|
|
548
|
-
Context.prototype.rect = function (x, y, w, h) {
|
|
549
|
-
return this._ctx.rect(this._doSize(x), this._doSize(y), this._doSize(w), this._doSize(h));
|
|
550
|
-
};
|
|
551
|
-
Context.prototype.fillRect = function (x, y, w, h) {
|
|
552
|
-
return this._ctx.fillRect(this._doSize(x), this._doSize(y), this._doSize(w), this._doSize(h));
|
|
553
|
-
};
|
|
554
|
-
Context.prototype.clearRect = function (x, y, w, h) {
|
|
555
|
-
return this._ctx.clearRect(this._doSize(x), this._doSize(y), this._doSize(w), this._doSize(h));
|
|
556
|
-
};
|
|
557
|
-
Context.prototype.beginPath = function () {
|
|
558
|
-
return this._ctx.beginPath();
|
|
559
|
-
};
|
|
560
|
-
Context.prototype.closePath = function () {
|
|
561
|
-
return this._ctx.closePath();
|
|
562
|
-
};
|
|
563
|
-
Context.prototype.lineTo = function (x, y) {
|
|
564
|
-
return this._ctx.lineTo(this._doSize(x), this._doSize(y));
|
|
565
|
-
};
|
|
566
|
-
Context.prototype.moveTo = function (x, y) {
|
|
567
|
-
return this._ctx.moveTo(this._doSize(x), this._doSize(y));
|
|
568
|
-
};
|
|
569
|
-
Context.prototype.arcTo = function (x1, y1, x2, y2, radius) {
|
|
570
|
-
return this._ctx.arcTo(this._doSize(x1), this._doSize(y1), this._doSize(x2), this._doSize(y2), this._doSize(radius));
|
|
571
|
-
};
|
|
572
|
-
Context.prototype.setLineWidth = function (w) {
|
|
573
|
-
return this._ctx.lineWidth = this._doSize(w);
|
|
574
|
-
};
|
|
575
|
-
Context.prototype.setLineDash = function (nums) {
|
|
576
|
-
var _this = this;
|
|
577
|
-
return this._ctx.setLineDash(nums.map(function (n) { return _this._doSize(n); }));
|
|
578
|
-
};
|
|
579
|
-
Context.prototype.isPointInPath = function (x, y) {
|
|
580
|
-
return this._ctx.isPointInPath(this._doX(x), this._doY(y));
|
|
581
|
-
};
|
|
582
|
-
Context.prototype.isPointInPathWithoutScroll = function (x, y) {
|
|
583
|
-
return this._ctx.isPointInPath(this._doSize(x), this._doSize(y));
|
|
584
|
-
};
|
|
585
|
-
Context.prototype.setStrokeStyle = function (color) {
|
|
586
|
-
this._ctx.strokeStyle = color;
|
|
587
|
-
};
|
|
588
|
-
Context.prototype.stroke = function () {
|
|
589
|
-
return this._ctx.stroke();
|
|
590
|
-
};
|
|
591
|
-
Context.prototype.translate = function (x, y) {
|
|
592
|
-
return this._ctx.translate(this._doSize(x), this._doSize(y));
|
|
593
|
-
};
|
|
594
|
-
Context.prototype.rotate = function (angle) {
|
|
595
|
-
return this._ctx.rotate(angle);
|
|
596
|
-
};
|
|
597
|
-
Context.prototype.drawImage = function () {
|
|
598
|
-
var args = [];
|
|
599
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
600
|
-
args[_i] = arguments[_i];
|
|
601
|
-
}
|
|
602
|
-
var image = args[0];
|
|
603
|
-
var sx = args[1];
|
|
604
|
-
var sy = args[2];
|
|
605
|
-
var sw = args[3];
|
|
606
|
-
var sh = args[4];
|
|
607
|
-
var dx = args[args.length - 4];
|
|
608
|
-
var dy = args[args.length - 3];
|
|
609
|
-
var dw = args[args.length - 2];
|
|
610
|
-
var dh = args[args.length - 1];
|
|
611
|
-
if (args.length === 9) {
|
|
612
|
-
return this._ctx.drawImage(image, this._doSize(sx), this._doSize(sy), this._doSize(sw), this._doSize(sh), this._doSize(dx), this._doSize(dy), this._doSize(dw), this._doSize(dh));
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
return this._ctx.drawImage(image, this._doSize(dx), this._doSize(dy), this._doSize(dw), this._doSize(dh));
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
Context.prototype.createPattern = function (image, repetition) {
|
|
619
|
-
return this._ctx.createPattern(image, repetition);
|
|
620
|
-
};
|
|
621
|
-
Context.prototype.measureText = function (text) {
|
|
622
|
-
return this._ctx.measureText(text);
|
|
623
|
-
};
|
|
624
|
-
Context.prototype.setTextAlign = function (align) {
|
|
625
|
-
this._ctx.textAlign = align;
|
|
626
|
-
};
|
|
627
|
-
Context.prototype.fillText = function (text, x, y, maxWidth) {
|
|
628
|
-
if (maxWidth !== undefined) {
|
|
629
|
-
return this._ctx.fillText(text, this._doSize(x), this._doSize(y), this._doSize(maxWidth));
|
|
630
|
-
}
|
|
631
|
-
else {
|
|
632
|
-
return this._ctx.fillText(text, this._doSize(x), this._doSize(y));
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
Context.prototype.setFont = function (opts) {
|
|
636
|
-
var strList = [];
|
|
637
|
-
if (opts.fontWeight === 'bold') {
|
|
638
|
-
strList.push("" + opts.fontWeight);
|
|
639
|
-
}
|
|
640
|
-
strList.push(this._doSize(opts.fontSize || 12) + "px");
|
|
641
|
-
strList.push("" + (opts.fontFamily || 'sans-serif'));
|
|
642
|
-
this._ctx.font = "" + strList.join(' ');
|
|
643
|
-
};
|
|
644
|
-
Context.prototype.setTextBaseline = function (baseline) {
|
|
645
|
-
this._ctx.textBaseline = baseline;
|
|
646
|
-
};
|
|
647
|
-
Context.prototype.setGlobalAlpha = function (alpha) {
|
|
648
|
-
this._ctx.globalAlpha = alpha;
|
|
649
|
-
};
|
|
650
|
-
Context.prototype.save = function () {
|
|
651
|
-
this._ctx.save();
|
|
652
|
-
};
|
|
653
|
-
Context.prototype.restore = function () {
|
|
654
|
-
this._ctx.restore();
|
|
655
|
-
};
|
|
656
|
-
Context.prototype.scale = function (ratioX, ratioY) {
|
|
657
|
-
this._ctx.scale(ratioX, ratioY);
|
|
658
|
-
};
|
|
659
|
-
Context.prototype._doSize = function (num) {
|
|
660
|
-
return this._opts.devicePixelRatio * num;
|
|
661
|
-
};
|
|
662
|
-
Context.prototype._doX = function (x) {
|
|
663
|
-
var _a = this._transform, scale = _a.scale, scrollX = _a.scrollX;
|
|
664
|
-
var _x = (x - scrollX) / scale;
|
|
665
|
-
return this._doSize(_x);
|
|
666
|
-
};
|
|
667
|
-
Context.prototype._doY = function (y) {
|
|
668
|
-
var _a = this._transform, scale = _a.scale, scrollY = _a.scrollY;
|
|
669
|
-
var _y = (y - scrollY) / scale;
|
|
670
|
-
return this._doSize(_y);
|
|
671
|
-
};
|
|
672
|
-
return Context;
|
|
673
|
-
}());
|
|
674
|
-
var defaultScrollConfig = {
|
|
675
|
-
lineWidth: 12,
|
|
676
|
-
color: '#a0a0a0'
|
|
677
|
-
};
|
|
678
|
-
var Scroller = (function () {
|
|
679
|
-
function Scroller(ctx, opts) {
|
|
680
|
-
this._displayCtx = ctx;
|
|
681
|
-
this._opts = this._getOpts(opts);
|
|
682
|
-
}
|
|
683
|
-
Scroller.prototype.draw = function (position) {
|
|
684
|
-
var _a = this._opts, width = _a.width, height = _a.height;
|
|
685
|
-
var wrapper = this.calc(position);
|
|
686
|
-
var ctx = this._displayCtx;
|
|
687
|
-
if (wrapper.xSize > 0) {
|
|
688
|
-
ctx.globalAlpha = 0.2;
|
|
689
|
-
ctx.fillStyle = wrapper.color;
|
|
690
|
-
ctx.fillRect(0, this._doSize(height - wrapper.lineSize), this._doSize(width), this._doSize(wrapper.lineSize));
|
|
691
|
-
ctx.globalAlpha = 1;
|
|
692
|
-
drawBox$1(ctx, {
|
|
693
|
-
x: this._doSize(wrapper.translateX),
|
|
694
|
-
y: this._doSize(height - wrapper.lineSize),
|
|
695
|
-
w: this._doSize(wrapper.xSize),
|
|
696
|
-
h: this._doSize(wrapper.lineSize),
|
|
697
|
-
r: this._doSize(wrapper.lineSize / 2),
|
|
698
|
-
color: wrapper.color,
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
if (wrapper.ySize > 0) {
|
|
702
|
-
ctx.globalAlpha = 0.2;
|
|
703
|
-
ctx.fillStyle = wrapper.color;
|
|
704
|
-
ctx.fillRect(this._doSize(width - wrapper.lineSize), 0, this._doSize(wrapper.lineSize), this._doSize(height));
|
|
705
|
-
ctx.globalAlpha = 1;
|
|
706
|
-
drawBox$1(ctx, {
|
|
707
|
-
x: this._doSize(width - wrapper.lineSize),
|
|
708
|
-
y: this._doSize(wrapper.translateY),
|
|
709
|
-
w: this._doSize(wrapper.lineSize),
|
|
710
|
-
h: this._doSize(wrapper.ySize),
|
|
711
|
-
r: this._doSize(wrapper.lineSize / 2),
|
|
712
|
-
color: wrapper.color,
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
ctx.globalAlpha = 1;
|
|
716
|
-
};
|
|
717
|
-
Scroller.prototype.resetSize = function (opts) {
|
|
718
|
-
this._opts = __assign(__assign({}, this._opts), opts);
|
|
719
|
-
};
|
|
720
|
-
Scroller.prototype.isPointAtScrollY = function (p) {
|
|
721
|
-
var _a = this._opts, width = _a.width, height = _a.height, scrollConfig = _a.scrollConfig;
|
|
722
|
-
var ctx = this._displayCtx;
|
|
723
|
-
ctx.beginPath();
|
|
724
|
-
ctx.rect(this._doSize(width - scrollConfig.lineWidth), 0, this._doSize(scrollConfig.lineWidth), this._doSize(height));
|
|
725
|
-
ctx.closePath();
|
|
726
|
-
if (ctx.isPointInPath(this._doSize(p.x), this._doSize(p.y))) {
|
|
727
|
-
return true;
|
|
728
|
-
}
|
|
729
|
-
return false;
|
|
730
|
-
};
|
|
731
|
-
Scroller.prototype.isPointAtScrollX = function (p) {
|
|
732
|
-
var _a = this._opts, width = _a.width, height = _a.height, scrollConfig = _a.scrollConfig;
|
|
733
|
-
var ctx = this._displayCtx;
|
|
734
|
-
ctx.beginPath();
|
|
735
|
-
ctx.rect(0, this._doSize(height - scrollConfig.lineWidth), this._doSize(width - scrollConfig.lineWidth), this._doSize(scrollConfig.lineWidth));
|
|
736
|
-
ctx.closePath();
|
|
737
|
-
if (ctx.isPointInPath(this._doSize(p.x), this._doSize(p.y))) {
|
|
738
|
-
return true;
|
|
739
|
-
}
|
|
740
|
-
return false;
|
|
741
|
-
};
|
|
742
|
-
Scroller.prototype.getLineWidth = function () {
|
|
743
|
-
var lineWidth = this._opts.scrollConfig.lineWidth;
|
|
744
|
-
return lineWidth;
|
|
745
|
-
};
|
|
746
|
-
Scroller.prototype.calc = function (position) {
|
|
747
|
-
var _a = this._opts, width = _a.width, height = _a.height, scrollConfig = _a.scrollConfig;
|
|
748
|
-
var sliderMinSize = scrollConfig.lineWidth * 2.5;
|
|
749
|
-
var lineSize = scrollConfig.lineWidth;
|
|
750
|
-
var xSize = 0;
|
|
751
|
-
var ySize = 0;
|
|
752
|
-
if (position.left <= 0 && position.right <= 0) {
|
|
753
|
-
xSize = Math.max(sliderMinSize, width - (Math.abs(position.left) + Math.abs(position.right)));
|
|
754
|
-
if (xSize >= width)
|
|
755
|
-
xSize = 0;
|
|
756
|
-
}
|
|
757
|
-
if (position.top <= 0 || position.bottom <= 0) {
|
|
758
|
-
ySize = Math.max(sliderMinSize, height - (Math.abs(position.top) + Math.abs(position.bottom)));
|
|
759
|
-
if (ySize >= height)
|
|
760
|
-
ySize = 0;
|
|
761
|
-
}
|
|
762
|
-
var translateX = 0;
|
|
763
|
-
if (xSize > 0) {
|
|
764
|
-
translateX = xSize / 2 + (width - xSize) * Math.abs(position.left) / (Math.abs(position.left) + Math.abs(position.right));
|
|
765
|
-
translateX = Math.min(Math.max(0, translateX - xSize / 2), width - xSize);
|
|
766
|
-
}
|
|
767
|
-
var translateY = 0;
|
|
768
|
-
if (ySize > 0) {
|
|
769
|
-
translateY = ySize / 2 + (height - ySize) * Math.abs(position.top) / (Math.abs(position.top) + Math.abs(position.bottom));
|
|
770
|
-
translateY = Math.min(Math.max(0, translateY - ySize / 2), height - ySize);
|
|
771
|
-
}
|
|
772
|
-
var scrollWrapper = {
|
|
773
|
-
lineSize: lineSize,
|
|
774
|
-
xSize: xSize,
|
|
775
|
-
ySize: ySize,
|
|
776
|
-
translateY: translateY,
|
|
777
|
-
translateX: translateX,
|
|
778
|
-
color: this._opts.scrollConfig.color
|
|
779
|
-
};
|
|
780
|
-
return scrollWrapper;
|
|
781
|
-
};
|
|
782
|
-
Scroller.prototype._doSize = function (num) {
|
|
783
|
-
return num * this._opts.devicePixelRatio;
|
|
784
|
-
};
|
|
785
|
-
Scroller.prototype._getOpts = function (opts) {
|
|
786
|
-
var options = __assign({ scrollConfig: defaultScrollConfig }, opts);
|
|
787
|
-
if (!options.scrollConfig) {
|
|
788
|
-
options.scrollConfig = defaultScrollConfig;
|
|
789
|
-
}
|
|
790
|
-
if (!(options.scrollConfig.lineWidth > 0)) {
|
|
791
|
-
options.scrollConfig.lineWidth = defaultScrollConfig.lineWidth;
|
|
792
|
-
}
|
|
793
|
-
options.scrollConfig.lineWidth = Math.max(options.scrollConfig.lineWidth, defaultScrollConfig.lineWidth);
|
|
794
|
-
if (index$1.color.isColorStr(options.scrollConfig.color) !== true) {
|
|
795
|
-
options.scrollConfig.color = options.scrollConfig.color;
|
|
796
|
-
}
|
|
797
|
-
return options;
|
|
798
|
-
};
|
|
799
|
-
return Scroller;
|
|
800
|
-
}());
|
|
801
|
-
function drawBox$1(ctx, opts) {
|
|
802
|
-
var x = opts.x, y = opts.y, w = opts.w, h = opts.h, color = opts.color;
|
|
803
|
-
var r = opts.r;
|
|
804
|
-
r = Math.min(r, w / 2, h / 2);
|
|
805
|
-
if (w < r * 2 || h < r * 2) {
|
|
806
|
-
r = 0;
|
|
807
|
-
}
|
|
808
|
-
ctx.beginPath();
|
|
809
|
-
ctx.moveTo(x + r, y);
|
|
810
|
-
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
811
|
-
ctx.arcTo(x + w, y + h, x, y + h, r);
|
|
812
|
-
ctx.arcTo(x, y + h, x, y, r);
|
|
813
|
-
ctx.arcTo(x, y, x + w, y, r);
|
|
814
|
-
ctx.closePath();
|
|
815
|
-
ctx.fillStyle = color;
|
|
816
|
-
ctx.fill();
|
|
817
|
-
}
|
|
818
|
-
var _opts$1$1 = Symbol('_opts');
|
|
819
|
-
var _ctx$1 = Symbol('_ctx');
|
|
820
|
-
var Screen = (function () {
|
|
821
|
-
function Screen(ctx, opts) {
|
|
822
|
-
this[_opts$1$1] = opts;
|
|
823
|
-
this[_ctx$1] = ctx;
|
|
824
|
-
}
|
|
825
|
-
Screen.prototype.resetSize = function (opts) {
|
|
826
|
-
this[_opts$1$1] = __assign(__assign({}, this[_opts$1$1]), opts);
|
|
827
|
-
};
|
|
828
|
-
Screen.prototype.calcScreen = function () {
|
|
829
|
-
var scaleRatio = this[_ctx$1].getTransform().scale;
|
|
830
|
-
var _a = this[_opts$1$1], width = _a.width, height = _a.height, contextWidth = _a.contextWidth, contextHeight = _a.contextHeight, pxRatio = _a.devicePixelRatio;
|
|
831
|
-
if (contextWidth * scaleRatio <= width) {
|
|
832
|
-
this[_ctx$1].setTransform({
|
|
833
|
-
scrollX: (width - contextWidth * scaleRatio) / 2,
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
if (contextHeight * scaleRatio <= height) {
|
|
837
|
-
this[_ctx$1].setTransform({
|
|
838
|
-
scrollY: (height - contextHeight * scaleRatio) / 2,
|
|
839
|
-
});
|
|
840
|
-
}
|
|
841
|
-
if (contextWidth * scaleRatio >= width && this[_ctx$1].getTransform().scrollX > 0) {
|
|
842
|
-
this[_ctx$1].setTransform({
|
|
843
|
-
scrollX: 0,
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
if (contextHeight * scaleRatio >= height && this[_ctx$1].getTransform().scrollY > 0) {
|
|
847
|
-
this[_ctx$1].setTransform({
|
|
848
|
-
scrollY: 0,
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
var _b = this[_ctx$1].getTransform(), _scrollX = _b.scrollX, _scrollY = _b.scrollY;
|
|
852
|
-
if (_scrollX < 0 && Math.abs(_scrollX) > Math.abs(contextWidth * scaleRatio - width)) {
|
|
853
|
-
this[_ctx$1].setTransform({
|
|
854
|
-
scrollX: 0 - Math.abs(contextWidth * scaleRatio - width)
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
if (_scrollY < 0 && Math.abs(_scrollY) > Math.abs(contextHeight * scaleRatio - height)) {
|
|
858
|
-
this[_ctx$1].setTransform({
|
|
859
|
-
scrollY: 0 - Math.abs(contextHeight * scaleRatio - height)
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
var _c = this[_ctx$1].getTransform(), scrollX = _c.scrollX, scrollY = _c.scrollY;
|
|
863
|
-
var size = {
|
|
864
|
-
x: scrollX * scaleRatio,
|
|
865
|
-
y: scrollY * scaleRatio,
|
|
866
|
-
w: contextWidth * scaleRatio,
|
|
867
|
-
h: contextHeight * scaleRatio,
|
|
868
|
-
};
|
|
869
|
-
var deviceSize = {
|
|
870
|
-
x: scrollX * pxRatio,
|
|
871
|
-
y: scrollY * pxRatio,
|
|
872
|
-
w: contextWidth * pxRatio * scaleRatio,
|
|
873
|
-
h: contextHeight * pxRatio * scaleRatio,
|
|
874
|
-
};
|
|
875
|
-
var position = {
|
|
876
|
-
top: scrollY,
|
|
877
|
-
bottom: height - (contextHeight * scaleRatio + scrollY),
|
|
878
|
-
left: scrollX,
|
|
879
|
-
right: width - (contextWidth * scaleRatio + scrollX),
|
|
880
|
-
};
|
|
881
|
-
return {
|
|
882
|
-
size: size,
|
|
883
|
-
position: position,
|
|
884
|
-
deviceSize: deviceSize,
|
|
885
|
-
width: this[_opts$1$1].width,
|
|
886
|
-
height: this[_opts$1$1].height,
|
|
887
|
-
devicePixelRatio: this[_opts$1$1].devicePixelRatio,
|
|
888
|
-
};
|
|
889
|
-
};
|
|
890
|
-
Screen.prototype.calcScreenScroll = function (start, end, sliderSize, limitLen, moveDistance) {
|
|
891
|
-
var scrollDistance = start;
|
|
892
|
-
var scrollLen = limitLen - sliderSize;
|
|
893
|
-
if (start <= 0 && end <= 0) {
|
|
894
|
-
scrollLen = Math.abs(start) + Math.abs(end);
|
|
895
|
-
}
|
|
896
|
-
var unit = 1;
|
|
897
|
-
if (scrollLen > 0) {
|
|
898
|
-
unit = scrollLen / (limitLen - sliderSize);
|
|
899
|
-
}
|
|
900
|
-
scrollDistance = 0 - unit * moveDistance;
|
|
901
|
-
return scrollDistance;
|
|
902
|
-
};
|
|
903
|
-
return Screen;
|
|
904
|
-
}());
|
|
905
|
-
var _canvas = Symbol('_canvas');
|
|
906
|
-
var _displayCanvas = Symbol('_displayCanvas');
|
|
907
|
-
var _mount = Symbol('_mount');
|
|
908
|
-
var _opts$2 = Symbol('_opts');
|
|
909
|
-
var _hasRendered = Symbol('_hasRendered');
|
|
910
|
-
var _ctx = Symbol('_ctx');
|
|
911
|
-
var _displayCtx = Symbol('_displayCtx');
|
|
912
|
-
var _originCtx = Symbol('_originCtx');
|
|
913
|
-
var _watcher = Symbol('_watcher');
|
|
914
|
-
var _render = Symbol('_render');
|
|
915
|
-
var _parsePrivateOptions = Symbol('_parsePrivateOptions');
|
|
916
|
-
var _scroller = Symbol('_scroller');
|
|
917
|
-
var _initEvent = Symbol('_initEvent');
|
|
918
|
-
var _doScrollX = Symbol('_doScrollX');
|
|
919
|
-
var _doScrollY = Symbol('_doScrollY');
|
|
920
|
-
var _doMoveScroll = Symbol('_doMoveScroll');
|
|
921
|
-
var _resetContext = Symbol('_resetContext');
|
|
922
|
-
var _screen = Symbol('_screen');
|
|
923
|
-
var _a$1;
|
|
924
|
-
var throttle$2 = index$1.time.throttle;
|
|
925
|
-
var Board = (function () {
|
|
926
|
-
function Board(mount, opts) {
|
|
927
|
-
this[_a$1] = false;
|
|
928
|
-
this[_mount] = mount;
|
|
929
|
-
this[_canvas] = document.createElement('canvas');
|
|
930
|
-
this[_displayCanvas] = document.createElement('canvas');
|
|
931
|
-
this[_mount].appendChild(this[_displayCanvas]);
|
|
932
|
-
this[_opts$2] = this[_parsePrivateOptions](opts);
|
|
933
|
-
this[_originCtx] = this[_canvas].getContext('2d');
|
|
934
|
-
this[_displayCtx] = this[_displayCanvas].getContext('2d');
|
|
935
|
-
this[_ctx] = new Context(this[_originCtx], this[_opts$2]);
|
|
936
|
-
this[_screen] = new Screen(this[_ctx], this[_opts$2]);
|
|
937
|
-
this[_watcher] = new Watcher(this[_displayCanvas]);
|
|
938
|
-
this[_scroller] = new Scroller(this[_displayCtx], {
|
|
939
|
-
width: opts.width,
|
|
940
|
-
height: opts.height,
|
|
941
|
-
devicePixelRatio: opts.devicePixelRatio || 1,
|
|
942
|
-
scrollConfig: opts.scrollConfig,
|
|
943
|
-
});
|
|
944
|
-
this[_render]();
|
|
945
|
-
}
|
|
946
|
-
Board.prototype.getDisplayContext = function () {
|
|
947
|
-
return this[_displayCtx];
|
|
948
|
-
};
|
|
949
|
-
Board.prototype.getOriginContext = function () {
|
|
950
|
-
return this[_originCtx];
|
|
951
|
-
};
|
|
952
|
-
Board.prototype.getContext = function () {
|
|
953
|
-
return this[_ctx];
|
|
954
|
-
};
|
|
955
|
-
Board.prototype.scale = function (scaleRatio) {
|
|
956
|
-
if (scaleRatio > 0) {
|
|
957
|
-
this[_ctx].setTransform({ scale: scaleRatio });
|
|
958
|
-
}
|
|
959
|
-
var _b = this[_screen].calcScreen(), position = _b.position, size = _b.size;
|
|
960
|
-
return { position: position, size: size };
|
|
961
|
-
};
|
|
962
|
-
Board.prototype.scrollX = function (x) {
|
|
963
|
-
if (x >= 0 || x < 0) {
|
|
964
|
-
this[_ctx].setTransform({ scrollX: x });
|
|
965
|
-
}
|
|
966
|
-
var _b = this[_screen].calcScreen(), position = _b.position, size = _b.size;
|
|
967
|
-
return { position: position, size: size };
|
|
968
|
-
};
|
|
969
|
-
Board.prototype.scrollY = function (y) {
|
|
970
|
-
if (y >= 0 || y < 0) {
|
|
971
|
-
this[_ctx].setTransform({ scrollY: y });
|
|
972
|
-
}
|
|
973
|
-
var _b = this[_screen].calcScreen(), position = _b.position, size = _b.size;
|
|
974
|
-
return { position: position, size: size };
|
|
975
|
-
};
|
|
976
|
-
Board.prototype.getTransform = function () {
|
|
977
|
-
return this[_ctx].getTransform();
|
|
978
|
-
};
|
|
979
|
-
Board.prototype.draw = function () {
|
|
980
|
-
this.clear();
|
|
981
|
-
var _b = this[_screen].calcScreen(), position = _b.position, deviceSize = _b.deviceSize, size = _b.size;
|
|
982
|
-
this[_displayCtx].drawImage(this[_canvas], deviceSize.x, deviceSize.y, deviceSize.w, deviceSize.h);
|
|
983
|
-
if (this[_opts$2].canScroll === true) {
|
|
984
|
-
this[_scroller].draw(position);
|
|
985
|
-
}
|
|
986
|
-
return { position: position, size: size };
|
|
987
|
-
};
|
|
988
|
-
Board.prototype.clear = function () {
|
|
989
|
-
this[_displayCtx].clearRect(0, 0, this[_displayCanvas].width, this[_displayCanvas].height);
|
|
990
|
-
};
|
|
991
|
-
Board.prototype.on = function (name, callback) {
|
|
992
|
-
this[_watcher].on(name, callback);
|
|
993
|
-
};
|
|
994
|
-
Board.prototype.off = function (name, callback) {
|
|
995
|
-
this[_watcher].off(name, callback);
|
|
996
|
-
};
|
|
997
|
-
Board.prototype.getScreenInfo = function () {
|
|
998
|
-
return this[_screen].calcScreen();
|
|
999
|
-
};
|
|
1000
|
-
Board.prototype.setCursor = function (cursor) {
|
|
1001
|
-
this[_displayCanvas].style.cursor = cursor;
|
|
1002
|
-
};
|
|
1003
|
-
Board.prototype.resetCursor = function () {
|
|
1004
|
-
this[_displayCanvas].style.cursor = 'auto';
|
|
1005
|
-
};
|
|
1006
|
-
Board.prototype.resetSize = function (opts) {
|
|
1007
|
-
this[_opts$2] = __assign(__assign({}, this[_opts$2]), opts);
|
|
1008
|
-
this[_resetContext]();
|
|
1009
|
-
this[_ctx].resetSize(opts);
|
|
1010
|
-
this[_screen].resetSize(opts);
|
|
1011
|
-
this[_scroller].resetSize({
|
|
1012
|
-
width: this[_opts$2].width,
|
|
1013
|
-
height: this[_opts$2].height,
|
|
1014
|
-
devicePixelRatio: this[_opts$2].devicePixelRatio
|
|
1015
|
-
});
|
|
1016
|
-
this.draw();
|
|
1017
|
-
};
|
|
1018
|
-
Board.prototype.getScrollLineWidth = function () {
|
|
1019
|
-
var lineWidth = 0;
|
|
1020
|
-
if (this[_opts$2].canScroll === true) {
|
|
1021
|
-
lineWidth = this[_scroller].getLineWidth();
|
|
1022
|
-
}
|
|
1023
|
-
return lineWidth;
|
|
1024
|
-
};
|
|
1025
|
-
Board.prototype.pointScreenToContext = function (screenPoint) {
|
|
1026
|
-
var _b = this.getTransform(), scrollX = _b.scrollX, scrollY = _b.scrollY, scale = _b.scale;
|
|
1027
|
-
var ctxPoint = {
|
|
1028
|
-
x: (screenPoint.x - scrollX) / scale,
|
|
1029
|
-
y: (screenPoint.y - scrollY) / scale,
|
|
1030
|
-
};
|
|
1031
|
-
return ctxPoint;
|
|
1032
|
-
};
|
|
1033
|
-
Board.prototype.pointContextToScreen = function (ctxPoint) {
|
|
1034
|
-
var _b = this.getTransform(), scrollX = _b.scrollX, scrollY = _b.scrollY, scale = _b.scale;
|
|
1035
|
-
var screenPoint = {
|
|
1036
|
-
x: ctxPoint.x * scale + scrollX,
|
|
1037
|
-
y: ctxPoint.y * scale + scrollY,
|
|
1038
|
-
};
|
|
1039
|
-
return screenPoint;
|
|
1040
|
-
};
|
|
1041
|
-
Board.prototype[(_a$1 = _hasRendered, _render)] = function () {
|
|
1042
|
-
if (this[_hasRendered] === true) {
|
|
1043
|
-
return;
|
|
1044
|
-
}
|
|
1045
|
-
this[_resetContext]();
|
|
1046
|
-
this[_initEvent]();
|
|
1047
|
-
this[_hasRendered] = true;
|
|
1048
|
-
};
|
|
1049
|
-
Board.prototype[_resetContext] = function () {
|
|
1050
|
-
var _b = this[_opts$2], width = _b.width, height = _b.height, contextWidth = _b.contextWidth, contextHeight = _b.contextHeight, devicePixelRatio = _b.devicePixelRatio;
|
|
1051
|
-
this[_canvas].width = contextWidth * devicePixelRatio;
|
|
1052
|
-
this[_canvas].height = contextHeight * devicePixelRatio;
|
|
1053
|
-
this[_displayCanvas].width = width * devicePixelRatio;
|
|
1054
|
-
this[_displayCanvas].height = height * devicePixelRatio;
|
|
1055
|
-
setStyle(this[_displayCanvas], {
|
|
1056
|
-
width: width + "px",
|
|
1057
|
-
height: height + "px",
|
|
1058
|
-
});
|
|
1059
|
-
};
|
|
1060
|
-
Board.prototype[_parsePrivateOptions] = function (opts) {
|
|
1061
|
-
var defaultOpts = {
|
|
1062
|
-
devicePixelRatio: 1,
|
|
1063
|
-
};
|
|
1064
|
-
return __assign(__assign({}, defaultOpts), opts);
|
|
1065
|
-
};
|
|
1066
|
-
Board.prototype[_initEvent] = function () {
|
|
1067
|
-
var _this = this;
|
|
1068
|
-
if (this[_hasRendered] === true) {
|
|
1069
|
-
return;
|
|
1070
|
-
}
|
|
1071
|
-
if (this[_opts$2].canScroll === true) {
|
|
1072
|
-
this.on('wheelX', throttle$2(function (deltaX) {
|
|
1073
|
-
_this[_doScrollX](deltaX);
|
|
1074
|
-
}, 16));
|
|
1075
|
-
this.on('wheelY', throttle$2(function (deltaY) {
|
|
1076
|
-
_this[_doScrollY](deltaY);
|
|
1077
|
-
}, 16));
|
|
1078
|
-
var scrollType_1 = null;
|
|
1079
|
-
this.on('moveStart', throttle$2(function (p) {
|
|
1080
|
-
if (_this[_scroller].isPointAtScrollX(p)) {
|
|
1081
|
-
scrollType_1 = 'x';
|
|
1082
|
-
}
|
|
1083
|
-
else if (_this[_scroller].isPointAtScrollY(p)) {
|
|
1084
|
-
scrollType_1 = 'y';
|
|
1085
|
-
}
|
|
1086
|
-
}, 16));
|
|
1087
|
-
this.on('move', throttle$2(function (p) {
|
|
1088
|
-
if (scrollType_1) {
|
|
1089
|
-
_this[_doMoveScroll](scrollType_1, p);
|
|
1090
|
-
}
|
|
1091
|
-
}, 16));
|
|
1092
|
-
this.on('moveEnd', throttle$2(function (p) {
|
|
1093
|
-
if (scrollType_1) {
|
|
1094
|
-
_this[_doMoveScroll](scrollType_1, p);
|
|
1095
|
-
}
|
|
1096
|
-
scrollType_1 = null;
|
|
1097
|
-
}, 16));
|
|
1098
|
-
}
|
|
1099
|
-
};
|
|
1100
|
-
Board.prototype[_doScrollX] = function (dx, prevScrollX) {
|
|
1101
|
-
var width = this[_opts$2].width;
|
|
1102
|
-
var scrollX = prevScrollX;
|
|
1103
|
-
if (!(typeof scrollX === 'number' && (scrollX > 0 || scrollX <= 0))) {
|
|
1104
|
-
scrollX = this[_ctx].getTransform().scrollX;
|
|
1105
|
-
}
|
|
1106
|
-
var position = this[_screen].calcScreen().position;
|
|
1107
|
-
var xSize = this[_scroller].calc(position).xSize;
|
|
1108
|
-
var moveX = this[_screen].calcScreenScroll(position.left, position.right, xSize, width, dx);
|
|
1109
|
-
this.scrollX(scrollX + moveX);
|
|
1110
|
-
this.draw();
|
|
1111
|
-
};
|
|
1112
|
-
Board.prototype[_doScrollY] = function (dy, prevScrollY) {
|
|
1113
|
-
var height = this[_opts$2].height;
|
|
1114
|
-
var scrollY = prevScrollY;
|
|
1115
|
-
if (!(typeof scrollY === 'number' && (scrollY > 0 || scrollY <= 0))) {
|
|
1116
|
-
scrollY = this[_ctx].getTransform().scrollY;
|
|
1117
|
-
}
|
|
1118
|
-
var position = this[_screen].calcScreen().position;
|
|
1119
|
-
var ySize = this[_scroller].calc(position).ySize;
|
|
1120
|
-
var moveY = this[_screen].calcScreenScroll(position.top, position.bottom, ySize, height, dy);
|
|
1121
|
-
this.scrollY(scrollY + moveY);
|
|
1122
|
-
this.draw();
|
|
1123
|
-
};
|
|
1124
|
-
Board.prototype[_doMoveScroll] = function (scrollType, point) {
|
|
1125
|
-
if (!scrollType) {
|
|
1126
|
-
return;
|
|
1127
|
-
}
|
|
1128
|
-
var position = this[_screen].calcScreen().position;
|
|
1129
|
-
var _b = this[_scroller].calc(position), xSize = _b.xSize, ySize = _b.ySize;
|
|
1130
|
-
if (scrollType === 'x') {
|
|
1131
|
-
this[_doScrollX](point.x - xSize / 2, 0);
|
|
1132
|
-
}
|
|
1133
|
-
else if (scrollType === 'y') {
|
|
1134
|
-
this[_doScrollY](point.y - ySize / 2, 0);
|
|
1135
|
-
}
|
|
1136
|
-
};
|
|
1137
|
-
return Board;
|
|
1138
|
-
}());
|
|
1139
|
-
|
|
1140
|
-
function compose(middleware) {
|
|
1141
|
-
return function (context, next) {
|
|
1142
|
-
return dispatch(0);
|
|
1143
|
-
function dispatch(i) {
|
|
1144
|
-
var fn = middleware[i];
|
|
1145
|
-
if (i === middleware.length && next) {
|
|
1146
|
-
fn = next;
|
|
1147
|
-
}
|
|
1148
|
-
if (!fn)
|
|
1149
|
-
return Promise.resolve();
|
|
1150
|
-
try {
|
|
1151
|
-
return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
|
|
1152
|
-
}
|
|
1153
|
-
catch (err) {
|
|
1154
|
-
return Promise.reject(err);
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
};
|
|
1158
|
-
}
|
|
1159
|
-
function delay(time) {
|
|
1160
|
-
return new Promise(function (resolve) {
|
|
1161
|
-
setTimeout(function () {
|
|
1162
|
-
resolve();
|
|
1163
|
-
}, time);
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
function throttle(fn, timeout) {
|
|
1167
|
-
var timer = -1;
|
|
1168
|
-
return function () {
|
|
1169
|
-
var args = [];
|
|
1170
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1171
|
-
args[_i] = arguments[_i];
|
|
1172
|
-
}
|
|
1173
|
-
if (timer > 0) {
|
|
1174
|
-
return;
|
|
1175
|
-
}
|
|
1176
|
-
timer = setTimeout(function () {
|
|
1177
|
-
fn.apply(void 0, args);
|
|
1178
|
-
timer = -1;
|
|
1179
|
-
}, timeout);
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
function downloadImageFromCanvas(canvas, opts) {
|
|
1183
|
-
var filename = opts.filename, _a = opts.type, type = _a === void 0 ? 'image/jpeg' : _a;
|
|
1184
|
-
var stream = canvas.toDataURL(type);
|
|
1185
|
-
var downloadLink = document.createElement('a');
|
|
1186
|
-
downloadLink.href = stream;
|
|
1187
|
-
downloadLink.download = filename;
|
|
1188
|
-
var downloadClickEvent = document.createEvent('MouseEvents');
|
|
1189
|
-
downloadClickEvent.initEvent('click', true, false);
|
|
1190
|
-
downloadLink.dispatchEvent(downloadClickEvent);
|
|
1191
|
-
}
|
|
1192
|
-
function toColorHexNum(color) {
|
|
1193
|
-
return parseInt(color.replace(/^\#/, '0x'));
|
|
1194
|
-
}
|
|
1195
|
-
function toColorHexStr(color) {
|
|
1196
|
-
return '#' + color.toString(16);
|
|
1197
|
-
}
|
|
1198
|
-
function isColorStr$2(color) {
|
|
1199
|
-
return typeof color === 'string' && /^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color);
|
|
1200
|
-
}
|
|
1201
|
-
function createUUID$2() {
|
|
1202
|
-
function str4() {
|
|
1203
|
-
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
1204
|
-
}
|
|
1205
|
-
return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
|
|
1206
|
-
}
|
|
1207
|
-
function deepClone$5(target) {
|
|
1208
|
-
function _clone(t) {
|
|
1209
|
-
var type = is$1(t);
|
|
1210
|
-
if (['Null', 'Number', 'String', 'Boolean', 'Undefined'].indexOf(type) >= 0) {
|
|
1211
|
-
return t;
|
|
1212
|
-
}
|
|
1213
|
-
else if (type === 'Array') {
|
|
1214
|
-
var arr_1 = [];
|
|
1215
|
-
t.forEach(function (item) {
|
|
1216
|
-
arr_1.push(_clone(item));
|
|
1217
|
-
});
|
|
1218
|
-
return arr_1;
|
|
1219
|
-
}
|
|
1220
|
-
else if (type === 'Object') {
|
|
1221
|
-
var obj_1 = {};
|
|
1222
|
-
var keys = Object.keys(t);
|
|
1223
|
-
keys.forEach(function (key) {
|
|
1224
|
-
obj_1[key] = _clone(t[key]);
|
|
1225
|
-
});
|
|
1226
|
-
return obj_1;
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
return _clone(target);
|
|
1230
|
-
}
|
|
1231
|
-
function is$1(data) {
|
|
1232
|
-
return Object.prototype.toString.call(data).replace(/[\]|\[]{1,1}/ig, '').split(' ')[1];
|
|
1233
|
-
}
|
|
1234
|
-
function parsePrototype(data) {
|
|
1235
|
-
var typeStr = Object.prototype.toString.call(data) || '';
|
|
1236
|
-
var result = typeStr.replace(/(\[object|\])/ig, '').trim();
|
|
1237
|
-
return result;
|
|
1238
|
-
}
|
|
1239
|
-
var istype$1 = {
|
|
1240
|
-
type: function (data, lowerCase) {
|
|
1241
|
-
var result = parsePrototype(data);
|
|
1242
|
-
return lowerCase === true ? result.toLocaleLowerCase() : result;
|
|
1243
|
-
},
|
|
1244
|
-
array: function (data) {
|
|
1245
|
-
return parsePrototype(data) === 'Array';
|
|
1246
|
-
},
|
|
1247
|
-
json: function (data) {
|
|
1248
|
-
return parsePrototype(data) === 'Object';
|
|
1249
|
-
},
|
|
1250
|
-
function: function (data) {
|
|
1251
|
-
return parsePrototype(data) === 'Function';
|
|
1252
|
-
},
|
|
1253
|
-
asyncFunction: function (data) {
|
|
1254
|
-
return parsePrototype(data) === 'AsyncFunction';
|
|
1255
|
-
},
|
|
1256
|
-
string: function (data) {
|
|
1257
|
-
return parsePrototype(data) === 'String';
|
|
1258
|
-
},
|
|
1259
|
-
number: function (data) {
|
|
1260
|
-
return parsePrototype(data) === 'Number';
|
|
1261
|
-
},
|
|
1262
|
-
undefined: function (data) {
|
|
1263
|
-
return parsePrototype(data) === 'Undefined';
|
|
1264
|
-
},
|
|
1265
|
-
null: function (data) {
|
|
1266
|
-
return parsePrototype(data) === 'Null';
|
|
1267
|
-
},
|
|
1268
|
-
promise: function (data) {
|
|
1269
|
-
return parsePrototype(data) === 'Promise';
|
|
1270
|
-
},
|
|
1271
|
-
nodeList: function (data) {
|
|
1272
|
-
return parsePrototype(data) === 'NodeList';
|
|
1273
|
-
},
|
|
1274
|
-
imageData: function (data) {
|
|
1275
|
-
return parsePrototype(data) === 'ImageData';
|
|
1276
|
-
}
|
|
1277
|
-
};
|
|
1278
|
-
var Image = window.Image, Blob = window.Blob, FileReader = window.FileReader;
|
|
1279
|
-
function loadImage$1(src) {
|
|
1280
|
-
return new Promise(function (resolve, reject) {
|
|
1281
|
-
var img = new Image;
|
|
1282
|
-
img.onload = function () {
|
|
1283
|
-
resolve(img);
|
|
1284
|
-
};
|
|
1285
|
-
img.onabort = reject;
|
|
1286
|
-
img.onerror = reject;
|
|
1287
|
-
img.src = src;
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
function loadSVG$1(svg) {
|
|
1291
|
-
return new Promise(function (resolve, reject) {
|
|
1292
|
-
var _svg = svg;
|
|
1293
|
-
var image = new Image();
|
|
1294
|
-
var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
1295
|
-
var reader = new FileReader();
|
|
1296
|
-
reader.readAsDataURL(blob);
|
|
1297
|
-
reader.onload = function (event) {
|
|
1298
|
-
var _a;
|
|
1299
|
-
var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
1300
|
-
image.onload = function () {
|
|
1301
|
-
resolve(image);
|
|
1302
|
-
};
|
|
1303
|
-
image.src = base64;
|
|
1304
|
-
};
|
|
1305
|
-
reader.onerror = function (err) {
|
|
1306
|
-
reject(err);
|
|
1307
|
-
};
|
|
1308
|
-
});
|
|
1309
|
-
}
|
|
1310
|
-
function loadHTML$1(html, opts) {
|
|
1311
|
-
var width = opts.width, height = opts.height;
|
|
1312
|
-
return new Promise(function (resolve, reject) {
|
|
1313
|
-
var _svg = "\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" + (width || '') + "\" height = \"" + (height || '') + "\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n " + html + "\n </div>\n </foreignObject>\n </svg>\n ";
|
|
1314
|
-
var image = new Image();
|
|
1315
|
-
var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
1316
|
-
var reader = new FileReader();
|
|
1317
|
-
reader.readAsDataURL(blob);
|
|
1318
|
-
reader.onload = function (event) {
|
|
1319
|
-
var _a;
|
|
1320
|
-
var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
1321
|
-
image.onload = function () {
|
|
1322
|
-
resolve(image);
|
|
1323
|
-
};
|
|
1324
|
-
image.src = base64;
|
|
1325
|
-
};
|
|
1326
|
-
reader.onerror = function (err) {
|
|
1327
|
-
reject(err);
|
|
1328
|
-
};
|
|
1329
|
-
});
|
|
1330
|
-
}
|
|
1331
|
-
var index = {
|
|
1332
|
-
time: {
|
|
1333
|
-
delay: delay,
|
|
1334
|
-
compose: compose,
|
|
1335
|
-
throttle: throttle,
|
|
1336
|
-
},
|
|
1337
|
-
loader: {
|
|
1338
|
-
loadImage: loadImage$1,
|
|
1339
|
-
loadSVG: loadSVG$1,
|
|
1340
|
-
loadHTML: loadHTML$1,
|
|
1341
|
-
},
|
|
1342
|
-
file: {
|
|
1343
|
-
downloadImageFromCanvas: downloadImageFromCanvas,
|
|
1344
|
-
},
|
|
1345
|
-
color: {
|
|
1346
|
-
toColorHexStr: toColorHexStr,
|
|
1347
|
-
toColorHexNum: toColorHexNum,
|
|
1348
|
-
isColorStr: isColorStr$2,
|
|
1349
|
-
},
|
|
1350
|
-
uuid: {
|
|
1351
|
-
createUUID: createUUID$2
|
|
1352
|
-
},
|
|
1353
|
-
istype: istype$1,
|
|
1354
|
-
data: {
|
|
1355
|
-
deepClone: deepClone$5,
|
|
1356
|
-
}
|
|
1357
|
-
};
|
|
1358
|
-
|
|
1359
|
-
var isColorStr$1 = index.color.isColorStr;
|
|
1360
|
-
function number(value) {
|
|
1361
|
-
return (typeof value === 'number' && (value > 0 || value <= 0));
|
|
1362
|
-
}
|
|
1363
|
-
function x(value) {
|
|
1364
|
-
return number(value);
|
|
1365
|
-
}
|
|
1366
|
-
function y(value) {
|
|
1367
|
-
return number(value);
|
|
1368
|
-
}
|
|
1369
|
-
function w(value) {
|
|
1370
|
-
return (typeof value === 'number' && value >= 0);
|
|
1371
|
-
}
|
|
1372
|
-
function h(value) {
|
|
1373
|
-
return (typeof value === 'number' && value >= 0);
|
|
1374
|
-
}
|
|
1375
|
-
function angle(value) {
|
|
1376
|
-
return (typeof value === 'number' && value >= -360 && value <= 360);
|
|
1377
|
-
}
|
|
1378
|
-
function borderWidth(value) {
|
|
1379
|
-
return w(value);
|
|
1380
|
-
}
|
|
1381
|
-
function borderRadius(value) {
|
|
1382
|
-
return number(value) && value >= 0;
|
|
1383
|
-
}
|
|
1384
|
-
function color$1(value) {
|
|
1385
|
-
return isColorStr$1(value);
|
|
1386
|
-
}
|
|
1387
|
-
function imageURL(value) {
|
|
1388
|
-
return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("" + value));
|
|
1389
|
-
}
|
|
1390
|
-
function imageBase64(value) {
|
|
1391
|
-
return (typeof value === 'string' && /^(data:image\/)/.test("" + value));
|
|
1392
|
-
}
|
|
1393
|
-
function imageSrc(value) {
|
|
1394
|
-
return (imageBase64(value) || imageURL(value));
|
|
1395
|
-
}
|
|
1396
|
-
function svg(value) {
|
|
1397
|
-
return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(("" + value).trim()) && /<\/[\s]{0,}svg>$/i.test(("" + value).trim()));
|
|
1398
|
-
}
|
|
1399
|
-
function html(value) {
|
|
1400
|
-
var result = false;
|
|
1401
|
-
if (typeof value === 'string') {
|
|
1402
|
-
var div = document.createElement('div');
|
|
1403
|
-
div.innerHTML = value;
|
|
1404
|
-
if (div.children.length > 0) {
|
|
1405
|
-
result = true;
|
|
1406
|
-
}
|
|
1407
|
-
div = null;
|
|
1408
|
-
}
|
|
1409
|
-
return result;
|
|
1410
|
-
}
|
|
1411
|
-
function text(value) {
|
|
1412
|
-
return typeof value === 'string';
|
|
1413
|
-
}
|
|
1414
|
-
function fontSize(value) {
|
|
1415
|
-
return number(value) && value > 0;
|
|
1416
|
-
}
|
|
1417
|
-
function lineHeight(value) {
|
|
1418
|
-
return number(value) && value > 0;
|
|
1419
|
-
}
|
|
1420
|
-
function textAlign(value) {
|
|
1421
|
-
return ['center', 'left', 'right'].includes(value);
|
|
1422
|
-
}
|
|
1423
|
-
function fontFamily(value) {
|
|
1424
|
-
return typeof value === 'string' && value.length > 0;
|
|
1425
|
-
}
|
|
1426
|
-
function fontWeight(value) {
|
|
1427
|
-
return ['bold'].includes(value);
|
|
1428
|
-
}
|
|
1429
|
-
var is = {
|
|
1430
|
-
x: x,
|
|
1431
|
-
y: y,
|
|
1432
|
-
w: w,
|
|
1433
|
-
h: h,
|
|
1434
|
-
angle: angle,
|
|
1435
|
-
number: number,
|
|
1436
|
-
borderWidth: borderWidth,
|
|
1437
|
-
borderRadius: borderRadius,
|
|
1438
|
-
color: color$1,
|
|
1439
|
-
imageSrc: imageSrc,
|
|
1440
|
-
imageURL: imageURL,
|
|
1441
|
-
imageBase64: imageBase64,
|
|
1442
|
-
svg: svg,
|
|
1443
|
-
html: html,
|
|
1444
|
-
text: text,
|
|
1445
|
-
fontSize: fontSize,
|
|
1446
|
-
lineHeight: lineHeight,
|
|
1447
|
-
textAlign: textAlign,
|
|
1448
|
-
fontFamily: fontFamily,
|
|
1449
|
-
fontWeight: fontWeight,
|
|
1450
|
-
};
|
|
1451
|
-
|
|
1452
|
-
function attrs(attrs) {
|
|
1453
|
-
var x = attrs.x, y = attrs.y, w = attrs.w, h = attrs.h, angle = attrs.angle;
|
|
1454
|
-
if (!(is.x(x) && is.y(y) && is.w(w) && is.h(h) && is.angle(angle))) {
|
|
1455
|
-
return false;
|
|
1456
|
-
}
|
|
1457
|
-
if (!(angle >= -360 && angle <= 360)) {
|
|
1458
|
-
return false;
|
|
1459
|
-
}
|
|
1460
|
-
return true;
|
|
1461
|
-
}
|
|
1462
|
-
function box(desc) {
|
|
1463
|
-
if (desc === void 0) { desc = {}; }
|
|
1464
|
-
var borderColor = desc.borderColor, borderRadius = desc.borderRadius, borderWidth = desc.borderWidth;
|
|
1465
|
-
if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
|
|
1466
|
-
return false;
|
|
1467
|
-
}
|
|
1468
|
-
if (desc.hasOwnProperty('borderRadius') && !is.number(borderRadius)) {
|
|
1469
|
-
return false;
|
|
1470
|
-
}
|
|
1471
|
-
if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
|
|
1472
|
-
return false;
|
|
1473
|
-
}
|
|
1474
|
-
return true;
|
|
1475
|
-
}
|
|
1476
|
-
function rectDesc(desc) {
|
|
1477
|
-
var bgColor = desc.bgColor;
|
|
1478
|
-
if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
|
|
1479
|
-
return false;
|
|
1480
|
-
}
|
|
1481
|
-
if (!box(desc)) {
|
|
1482
|
-
return false;
|
|
1483
|
-
}
|
|
1484
|
-
return true;
|
|
1485
|
-
}
|
|
1486
|
-
function circleDesc(desc) {
|
|
1487
|
-
var bgColor = desc.bgColor, borderColor = desc.borderColor, borderWidth = desc.borderWidth;
|
|
1488
|
-
if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
|
|
1489
|
-
return false;
|
|
1490
|
-
}
|
|
1491
|
-
if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
|
|
1492
|
-
return false;
|
|
1493
|
-
}
|
|
1494
|
-
if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
|
|
1495
|
-
return false;
|
|
1496
|
-
}
|
|
1497
|
-
return true;
|
|
1498
|
-
}
|
|
1499
|
-
function imageDesc(desc) {
|
|
1500
|
-
var src = desc.src;
|
|
1501
|
-
if (!is.imageSrc(src)) {
|
|
1502
|
-
return false;
|
|
1503
|
-
}
|
|
1504
|
-
return true;
|
|
1505
|
-
}
|
|
1506
|
-
function svgDesc(desc) {
|
|
1507
|
-
var svg = desc.svg;
|
|
1508
|
-
if (!is.svg(svg)) {
|
|
1509
|
-
return false;
|
|
1510
|
-
}
|
|
1511
|
-
return true;
|
|
1512
|
-
}
|
|
1513
|
-
function htmlDesc(desc) {
|
|
1514
|
-
var html = desc.html;
|
|
1515
|
-
if (!is.html(html)) {
|
|
1516
|
-
return false;
|
|
1517
|
-
}
|
|
1518
|
-
return true;
|
|
1519
|
-
}
|
|
1520
|
-
function textDesc(desc) {
|
|
1521
|
-
var text = desc.text, color = desc.color, fontSize = desc.fontSize, lineHeight = desc.lineHeight, fontFamily = desc.fontFamily, textAlign = desc.textAlign, fontWeight = desc.fontWeight, bgColor = desc.bgColor;
|
|
1522
|
-
if (!is.text(text)) {
|
|
1523
|
-
return false;
|
|
1524
|
-
}
|
|
1525
|
-
if (!is.color(color)) {
|
|
1526
|
-
return false;
|
|
1527
|
-
}
|
|
1528
|
-
if (!is.fontSize(fontSize)) {
|
|
1529
|
-
return false;
|
|
1530
|
-
}
|
|
1531
|
-
if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
|
|
1532
|
-
return false;
|
|
1533
|
-
}
|
|
1534
|
-
if (desc.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)) {
|
|
1535
|
-
return false;
|
|
1536
|
-
}
|
|
1537
|
-
if (desc.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)) {
|
|
1538
|
-
return false;
|
|
1539
|
-
}
|
|
1540
|
-
if (desc.hasOwnProperty('fontFamily') && !is.fontFamily(fontFamily)) {
|
|
1541
|
-
return false;
|
|
1542
|
-
}
|
|
1543
|
-
if (desc.hasOwnProperty('textAlign') && !is.textAlign(textAlign)) {
|
|
1544
|
-
return false;
|
|
1545
|
-
}
|
|
1546
|
-
if (!box(desc)) {
|
|
1547
|
-
return false;
|
|
1548
|
-
}
|
|
1549
|
-
return true;
|
|
1550
|
-
}
|
|
1551
|
-
var check = {
|
|
1552
|
-
attrs: attrs,
|
|
1553
|
-
textDesc: textDesc,
|
|
1554
|
-
rectDesc: rectDesc,
|
|
1555
|
-
circleDesc: circleDesc,
|
|
1556
|
-
imageDesc: imageDesc,
|
|
1557
|
-
svgDesc: svgDesc,
|
|
1558
|
-
htmlDesc: htmlDesc,
|
|
1559
|
-
};
|
|
1560
|
-
|
|
1561
|
-
function parseRadianToAngle(radian) {
|
|
1562
|
-
return radian / Math.PI * 180;
|
|
1563
|
-
}
|
|
1564
|
-
function parseAngleToRadian(angle) {
|
|
1565
|
-
return angle / 180 * Math.PI;
|
|
1566
|
-
}
|
|
1567
|
-
function calcElementCenter(elem) {
|
|
1568
|
-
var p = {
|
|
1569
|
-
x: elem.x + elem.w / 2,
|
|
1570
|
-
y: elem.y + elem.h / 2,
|
|
1571
|
-
};
|
|
1572
|
-
return p;
|
|
1573
|
-
}
|
|
1574
|
-
function calcRadian(center, start, end) {
|
|
1575
|
-
var startAngle = calcLineAngle(center, start);
|
|
1576
|
-
var endAngle = calcLineAngle(center, end);
|
|
1577
|
-
if (endAngle !== null && startAngle !== null) {
|
|
1578
|
-
if (startAngle > Math.PI * 3 / 2 && endAngle < Math.PI / 2) {
|
|
1579
|
-
return endAngle + (Math.PI * 2 - startAngle);
|
|
1580
|
-
}
|
|
1581
|
-
else if (endAngle > Math.PI * 3 / 2 && startAngle < Math.PI / 2) {
|
|
1582
|
-
return startAngle + (Math.PI * 2 - endAngle);
|
|
1583
|
-
}
|
|
1584
|
-
else {
|
|
1585
|
-
return endAngle - startAngle;
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
else {
|
|
1589
|
-
return 0;
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
function calcLineAngle(center, p) {
|
|
1593
|
-
var x = p.x - center.x;
|
|
1594
|
-
var y = center.y - p.y;
|
|
1595
|
-
if (x === 0) {
|
|
1596
|
-
if (y < 0) {
|
|
1597
|
-
return Math.PI / 2;
|
|
1598
|
-
}
|
|
1599
|
-
else if (y > 0) {
|
|
1600
|
-
return Math.PI * (3 / 2);
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
else if (y === 0) {
|
|
1604
|
-
if (x < 0) {
|
|
1605
|
-
return Math.PI;
|
|
1606
|
-
}
|
|
1607
|
-
else if (x > 0) {
|
|
1608
|
-
return 0;
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
if (x > 0 && y < 0) {
|
|
1612
|
-
return Math.atan(Math.abs(y) / Math.abs(x));
|
|
1613
|
-
}
|
|
1614
|
-
else if (x < 0 && y < 0) {
|
|
1615
|
-
return Math.PI - Math.atan(Math.abs(y) / Math.abs(x));
|
|
1616
|
-
}
|
|
1617
|
-
else if (x < 0 && y > 0) {
|
|
1618
|
-
return Math.PI + Math.atan(Math.abs(y) / Math.abs(x));
|
|
1619
|
-
}
|
|
1620
|
-
else if (x > 0 && y > 0) {
|
|
1621
|
-
return Math.PI * 2 - Math.atan(Math.abs(y) / Math.abs(x));
|
|
1622
|
-
}
|
|
1623
|
-
return null;
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
function rotateElement(ctx, elem, callback) {
|
|
1627
|
-
var center = calcElementCenter(elem);
|
|
1628
|
-
var radian = parseAngleToRadian(elem.angle || 0);
|
|
1629
|
-
return rotateContext(ctx, center, radian || 0, callback);
|
|
1630
|
-
}
|
|
1631
|
-
function rotateContext(ctx, center, radian, callback) {
|
|
1632
|
-
if (center && (radian > 0 || radian < 0)) {
|
|
1633
|
-
ctx.translate(center.x, center.y);
|
|
1634
|
-
ctx.rotate(radian);
|
|
1635
|
-
ctx.translate(-center.x, -center.y);
|
|
1636
|
-
}
|
|
1637
|
-
callback(ctx);
|
|
1638
|
-
if (center && (radian > 0 || radian < 0)) {
|
|
1639
|
-
ctx.translate(center.x, center.y);
|
|
1640
|
-
ctx.rotate(-radian);
|
|
1641
|
-
ctx.translate(-center.x, -center.y);
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
var istype = index.istype, color = index.color;
|
|
1646
|
-
function clearContext(ctx) {
|
|
1647
|
-
ctx.setFillStyle('#000000');
|
|
1648
|
-
ctx.setStrokeStyle('#000000');
|
|
1649
|
-
ctx.setLineDash([]);
|
|
1650
|
-
ctx.setGlobalAlpha(1);
|
|
1651
|
-
}
|
|
1652
|
-
function drawBgColor(ctx, color) {
|
|
1653
|
-
var size = ctx.getSize();
|
|
1654
|
-
ctx.setFillStyle(color);
|
|
1655
|
-
ctx.fillRect(0, 0, size.contextWidth, size.contextHeight);
|
|
1656
|
-
}
|
|
1657
|
-
function drawBox(ctx, elem, pattern) {
|
|
1658
|
-
clearContext(ctx);
|
|
1659
|
-
drawBoxBorder(ctx, elem);
|
|
1660
|
-
rotateElement(ctx, elem, function () {
|
|
1661
|
-
var x = elem.x, y = elem.y, w = elem.w, h = elem.h;
|
|
1662
|
-
var r = elem.desc.borderRadius || 0;
|
|
1663
|
-
r = Math.min(r, w / 2, h / 2);
|
|
1664
|
-
if (w < r * 2 || h < r * 2) {
|
|
1665
|
-
r = 0;
|
|
1666
|
-
}
|
|
1667
|
-
ctx.beginPath();
|
|
1668
|
-
ctx.moveTo(x + r, y);
|
|
1669
|
-
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
1670
|
-
ctx.arcTo(x + w, y + h, x, y + h, r);
|
|
1671
|
-
ctx.arcTo(x, y + h, x, y, r);
|
|
1672
|
-
ctx.arcTo(x, y, x + w, y, r);
|
|
1673
|
-
ctx.closePath();
|
|
1674
|
-
if (typeof pattern === 'string') {
|
|
1675
|
-
ctx.setFillStyle(pattern);
|
|
1676
|
-
}
|
|
1677
|
-
else if (['CanvasPattern'].includes(istype.type(pattern))) {
|
|
1678
|
-
ctx.setFillStyle(pattern);
|
|
1679
|
-
}
|
|
1680
|
-
ctx.fill();
|
|
1681
|
-
});
|
|
1682
|
-
}
|
|
1683
|
-
function drawBoxBorder(ctx, elem) {
|
|
1684
|
-
clearContext(ctx);
|
|
1685
|
-
rotateElement(ctx, elem, function () {
|
|
1686
|
-
if (!(elem.desc.borderWidth && elem.desc.borderWidth > 0)) {
|
|
1687
|
-
return;
|
|
1688
|
-
}
|
|
1689
|
-
var bw = elem.desc.borderWidth;
|
|
1690
|
-
var borderColor = '#000000';
|
|
1691
|
-
if (color.isColorStr(elem.desc.borderColor) === true) {
|
|
1692
|
-
borderColor = elem.desc.borderColor;
|
|
1693
|
-
}
|
|
1694
|
-
var x = elem.x - bw / 2;
|
|
1695
|
-
var y = elem.y - bw / 2;
|
|
1696
|
-
var w = elem.w + bw;
|
|
1697
|
-
var h = elem.h + bw;
|
|
1698
|
-
var r = elem.desc.borderRadius || 0;
|
|
1699
|
-
r = Math.min(r, w / 2, h / 2);
|
|
1700
|
-
if (r < w / 2 && r < h / 2) {
|
|
1701
|
-
r = r + bw / 2;
|
|
1702
|
-
}
|
|
1703
|
-
ctx.beginPath();
|
|
1704
|
-
ctx.setLineWidth(bw);
|
|
1705
|
-
ctx.setStrokeStyle(borderColor);
|
|
1706
|
-
ctx.moveTo(x + r, y);
|
|
1707
|
-
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
1708
|
-
ctx.arcTo(x + w, y + h, x, y + h, r);
|
|
1709
|
-
ctx.arcTo(x, y + h, x, y, r);
|
|
1710
|
-
ctx.arcTo(x, y, x + w, y, r);
|
|
1711
|
-
ctx.closePath();
|
|
1712
|
-
ctx.stroke();
|
|
1713
|
-
});
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
|
-
function drawRect(ctx, elem) {
|
|
1717
|
-
drawBox(ctx, elem, elem.desc.bgColor);
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
function drawImage(ctx, elem, loader) {
|
|
1721
|
-
var content = loader.getContent(elem.uuid);
|
|
1722
|
-
rotateElement(ctx, elem, function () {
|
|
1723
|
-
if (content) {
|
|
1724
|
-
ctx.drawImage(content, elem.x, elem.y, elem.w, elem.h);
|
|
1725
|
-
}
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
function drawSVG(ctx, elem, loader) {
|
|
1730
|
-
var content = loader.getContent(elem.uuid);
|
|
1731
|
-
rotateElement(ctx, elem, function () {
|
|
1732
|
-
if (content) {
|
|
1733
|
-
ctx.drawImage(content, elem.x, elem.y, elem.w, elem.h);
|
|
1734
|
-
}
|
|
1735
|
-
});
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
function drawHTML(ctx, elem, loader) {
|
|
1739
|
-
var content = loader.getContent(elem.uuid);
|
|
1740
|
-
rotateElement(ctx, elem, function () {
|
|
1741
|
-
if (content) {
|
|
1742
|
-
ctx.drawImage(content, elem.x, elem.y, elem.w, elem.h);
|
|
1743
|
-
}
|
|
1744
|
-
});
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
function drawText(ctx, elem, loader, helperConfig) {
|
|
1748
|
-
clearContext(ctx);
|
|
1749
|
-
drawBox(ctx, elem, elem.desc.bgColor || 'transparent');
|
|
1750
|
-
rotateElement(ctx, elem, function () {
|
|
1751
|
-
var desc = __assign$1({
|
|
1752
|
-
fontSize: 12,
|
|
1753
|
-
fontFamily: 'sans-serif',
|
|
1754
|
-
textAlign: 'center',
|
|
1755
|
-
}, elem.desc);
|
|
1756
|
-
ctx.setFillStyle(elem.desc.color);
|
|
1757
|
-
ctx.setTextBaseline('top');
|
|
1758
|
-
ctx.setFont({
|
|
1759
|
-
fontWeight: desc.fontWeight,
|
|
1760
|
-
fontSize: desc.fontSize,
|
|
1761
|
-
fontFamily: desc.fontFamily
|
|
1762
|
-
});
|
|
1763
|
-
var descText = desc.text.replace(/\r\n/ig, '\n');
|
|
1764
|
-
var fontHeight = desc.lineHeight || desc.fontSize;
|
|
1765
|
-
var descTextList = descText.split('\n');
|
|
1766
|
-
var lines = [];
|
|
1767
|
-
descTextList.forEach(function (tempText) {
|
|
1768
|
-
var lineText = '';
|
|
1769
|
-
var lineNum = 0;
|
|
1770
|
-
for (var i = 0; i < tempText.length; i++) {
|
|
1771
|
-
if (ctx.measureText(lineText + (tempText[i] || '')).width < ctx.calcDeviceNum(elem.w)) {
|
|
1772
|
-
lineText += (tempText[i] || '');
|
|
1773
|
-
}
|
|
1774
|
-
else {
|
|
1775
|
-
lines.push({
|
|
1776
|
-
text: lineText,
|
|
1777
|
-
width: ctx.calcScreenNum(ctx.measureText(lineText).width),
|
|
1778
|
-
});
|
|
1779
|
-
lineText = (tempText[i] || '');
|
|
1780
|
-
lineNum++;
|
|
1781
|
-
}
|
|
1782
|
-
if ((lineNum + 1) * fontHeight > elem.h) {
|
|
1783
|
-
break;
|
|
1784
|
-
}
|
|
1785
|
-
if (lineText && tempText.length - 1 === i) {
|
|
1786
|
-
if ((lineNum + 1) * fontHeight < elem.h) {
|
|
1787
|
-
lines.push({
|
|
1788
|
-
text: lineText,
|
|
1789
|
-
width: ctx.calcScreenNum(ctx.measureText(lineText).width),
|
|
1790
|
-
});
|
|
1791
|
-
break;
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
});
|
|
1796
|
-
var _y = elem.y;
|
|
1797
|
-
if (lines.length * fontHeight < elem.h) {
|
|
1798
|
-
_y += ((elem.h - lines.length * fontHeight) / 2);
|
|
1799
|
-
}
|
|
1800
|
-
lines.forEach(function (line, i) {
|
|
1801
|
-
var _x = elem.x;
|
|
1802
|
-
if (desc.textAlign === 'center') {
|
|
1803
|
-
_x = elem.x + (elem.w - line.width) / 2;
|
|
1804
|
-
}
|
|
1805
|
-
else if (desc.textAlign === 'right') {
|
|
1806
|
-
_x = elem.x + (elem.w - line.width);
|
|
1807
|
-
}
|
|
1808
|
-
ctx.fillText(line.text, _x, _y + fontHeight * i);
|
|
1809
|
-
});
|
|
1810
|
-
});
|
|
1811
|
-
}
|
|
1812
|
-
|
|
1813
|
-
function drawCircle(ctx, elem) {
|
|
1814
|
-
rotateElement(ctx, elem, function (ctx) {
|
|
1815
|
-
var x = elem.x, y = elem.y, w = elem.w, h = elem.h, desc = elem.desc;
|
|
1816
|
-
var _a = desc.bgColor, bgColor = _a === void 0 ? '#000000' : _a, _b = desc.borderColor, borderColor = _b === void 0 ? '#000000' : _b, borderWidth = desc.borderWidth;
|
|
1817
|
-
var a = w / 2;
|
|
1818
|
-
var b = h / 2;
|
|
1819
|
-
var centerX = x + a;
|
|
1820
|
-
var centerY = y + b;
|
|
1821
|
-
var unit = (a > b) ? 1 / a : 1 / b;
|
|
1822
|
-
if (borderWidth && borderWidth > 0) {
|
|
1823
|
-
var ba = borderWidth / 2 + a;
|
|
1824
|
-
var bb = borderWidth / 2 + b;
|
|
1825
|
-
ctx.beginPath();
|
|
1826
|
-
ctx.setStrokeStyle(borderColor);
|
|
1827
|
-
ctx.setLineWidth(borderWidth);
|
|
1828
|
-
ctx.moveTo(centerX + ba, centerY);
|
|
1829
|
-
for (var i = 0; i < 2 * Math.PI; i += unit) {
|
|
1830
|
-
ctx.lineTo(centerX + ba * Math.cos(i), centerY + bb * Math.sin(i));
|
|
1831
|
-
}
|
|
1832
|
-
ctx.lineTo(centerX + ba, centerY);
|
|
1833
|
-
ctx.stroke();
|
|
1834
|
-
}
|
|
1835
|
-
ctx.beginPath();
|
|
1836
|
-
ctx.setFillStyle(bgColor);
|
|
1837
|
-
ctx.moveTo(centerX + a, centerY);
|
|
1838
|
-
for (var i = 0; i < 2 * Math.PI; i += unit) {
|
|
1839
|
-
ctx.lineTo(centerX + a * Math.cos(i), centerY + b * Math.sin(i));
|
|
1840
|
-
}
|
|
1841
|
-
ctx.closePath();
|
|
1842
|
-
ctx.fill();
|
|
1843
|
-
});
|
|
1844
|
-
}
|
|
1845
|
-
|
|
1846
|
-
function drawElementWrapper(ctx, config) {
|
|
1847
|
-
if (!(config === null || config === void 0 ? void 0 : config.selectedElementWrapper)) {
|
|
1848
|
-
return;
|
|
1849
|
-
}
|
|
1850
|
-
var wrapper = config.selectedElementWrapper;
|
|
1851
|
-
clearContext(ctx);
|
|
1852
|
-
rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
|
|
1853
|
-
ctx.beginPath();
|
|
1854
|
-
ctx.setLineDash(wrapper.lineDash);
|
|
1855
|
-
ctx.setLineWidth(wrapper.lineWidth);
|
|
1856
|
-
ctx.setStrokeStyle(wrapper.color);
|
|
1857
|
-
ctx.moveTo(wrapper.dots.topLeft.x, wrapper.dots.topLeft.y);
|
|
1858
|
-
ctx.lineTo(wrapper.dots.topRight.x, wrapper.dots.topRight.y);
|
|
1859
|
-
ctx.lineTo(wrapper.dots.bottomRight.x, wrapper.dots.bottomRight.y);
|
|
1860
|
-
ctx.lineTo(wrapper.dots.bottomLeft.x, wrapper.dots.bottomLeft.y);
|
|
1861
|
-
ctx.lineTo(wrapper.dots.topLeft.x, wrapper.dots.topLeft.y - wrapper.lineWidth / 2);
|
|
1862
|
-
ctx.stroke();
|
|
1863
|
-
ctx.closePath();
|
|
1864
|
-
if (wrapper.lock !== true) {
|
|
1865
|
-
ctx.beginPath();
|
|
1866
|
-
ctx.moveTo(wrapper.dots.top.x, wrapper.dots.top.y);
|
|
1867
|
-
ctx.lineTo(wrapper.dots.rotate.x, wrapper.dots.rotate.y + wrapper.dotSize);
|
|
1868
|
-
ctx.stroke();
|
|
1869
|
-
ctx.closePath();
|
|
1870
|
-
ctx.beginPath();
|
|
1871
|
-
ctx.setLineDash([]);
|
|
1872
|
-
ctx.setLineWidth(wrapper.dotSize / 2);
|
|
1873
|
-
ctx.arc(wrapper.dots.rotate.x, wrapper.dots.rotate.y, wrapper.dotSize * 0.8, Math.PI / 6, Math.PI * 2);
|
|
1874
|
-
ctx.stroke();
|
|
1875
|
-
ctx.closePath();
|
|
1876
|
-
ctx.setFillStyle(wrapper.color);
|
|
1877
|
-
[
|
|
1878
|
-
wrapper.dots.topLeft, wrapper.dots.top, wrapper.dots.topRight, wrapper.dots.right,
|
|
1879
|
-
wrapper.dots.bottomRight, wrapper.dots.bottom, wrapper.dots.bottomLeft, wrapper.dots.left,
|
|
1880
|
-
].forEach(function (dot) {
|
|
1881
|
-
ctx.beginPath();
|
|
1882
|
-
ctx.arc(dot.x, dot.y, wrapper.dotSize, 0, Math.PI * 2);
|
|
1883
|
-
ctx.fill();
|
|
1884
|
-
ctx.closePath();
|
|
1885
|
-
});
|
|
1886
|
-
}
|
|
1887
|
-
else {
|
|
1888
|
-
clearContext(ctx);
|
|
1889
|
-
ctx.setStrokeStyle(wrapper.color);
|
|
1890
|
-
[
|
|
1891
|
-
wrapper.dots.topLeft, wrapper.dots.top, wrapper.dots.topRight, wrapper.dots.right,
|
|
1892
|
-
wrapper.dots.bottomRight, wrapper.dots.bottom, wrapper.dots.bottomLeft, wrapper.dots.left,
|
|
1893
|
-
].forEach(function (dot) {
|
|
1894
|
-
ctx.beginPath();
|
|
1895
|
-
ctx.moveTo(dot.x - wrapper.dotSize / 2, dot.y - wrapper.dotSize / 2);
|
|
1896
|
-
ctx.lineTo(dot.x + wrapper.dotSize / 2, dot.y + wrapper.dotSize / 2);
|
|
1897
|
-
ctx.stroke();
|
|
1898
|
-
ctx.closePath();
|
|
1899
|
-
ctx.beginPath();
|
|
1900
|
-
ctx.moveTo(dot.x + wrapper.dotSize / 2, dot.y - wrapper.dotSize / 2);
|
|
1901
|
-
ctx.lineTo(dot.x - wrapper.dotSize / 2, dot.y + wrapper.dotSize / 2);
|
|
1902
|
-
ctx.stroke();
|
|
1903
|
-
ctx.closePath();
|
|
1904
|
-
});
|
|
1905
|
-
}
|
|
1906
|
-
});
|
|
1907
|
-
}
|
|
1908
|
-
function drawAreaWrapper(ctx, config) {
|
|
1909
|
-
if (!(config === null || config === void 0 ? void 0 : config.selectedAreaWrapper)) {
|
|
1910
|
-
return;
|
|
1911
|
-
}
|
|
1912
|
-
var wrapper = config.selectedAreaWrapper;
|
|
1913
|
-
if (wrapper && wrapper.w > 0 && wrapper.h > 0) {
|
|
1914
|
-
clearContext(ctx);
|
|
1915
|
-
ctx.setGlobalAlpha(0.3);
|
|
1916
|
-
ctx.setFillStyle(wrapper.color);
|
|
1917
|
-
ctx.fillRect(wrapper.x, wrapper.y, wrapper.w, wrapper.h);
|
|
1918
|
-
clearContext(ctx);
|
|
1919
|
-
ctx.beginPath();
|
|
1920
|
-
ctx.setLineDash(wrapper.lineDash);
|
|
1921
|
-
ctx.setLineWidth(wrapper.lineWidth);
|
|
1922
|
-
ctx.setStrokeStyle(wrapper.color);
|
|
1923
|
-
ctx.moveTo(wrapper.x, wrapper.y);
|
|
1924
|
-
ctx.lineTo(wrapper.x + wrapper.w, wrapper.y);
|
|
1925
|
-
ctx.lineTo(wrapper.x + wrapper.w, wrapper.y + wrapper.h);
|
|
1926
|
-
ctx.lineTo(wrapper.x, wrapper.y + wrapper.h);
|
|
1927
|
-
ctx.lineTo(wrapper.x, wrapper.y);
|
|
1928
|
-
ctx.stroke();
|
|
1929
|
-
ctx.closePath();
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
function drawElementListWrappers(ctx, config) {
|
|
1933
|
-
if (!Array.isArray(config === null || config === void 0 ? void 0 : config.selectedElementListWrappers)) {
|
|
1934
|
-
return;
|
|
1935
|
-
}
|
|
1936
|
-
var wrapperList = config.selectedElementListWrappers;
|
|
1937
|
-
wrapperList === null || wrapperList === void 0 ? void 0 : wrapperList.forEach(function (wrapper) {
|
|
1938
|
-
clearContext(ctx);
|
|
1939
|
-
rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
|
|
1940
|
-
clearContext(ctx);
|
|
1941
|
-
ctx.setGlobalAlpha(0.05);
|
|
1942
|
-
ctx.setFillStyle(wrapper.color);
|
|
1943
|
-
ctx.fillRect(wrapper.dots.topLeft.x, wrapper.dots.topLeft.y, wrapper.dots.bottomRight.x - wrapper.dots.topLeft.x, wrapper.dots.bottomRight.y - wrapper.dots.topLeft.y);
|
|
1944
|
-
clearContext(ctx);
|
|
1945
|
-
ctx.beginPath();
|
|
1946
|
-
ctx.setLineDash(wrapper.lineDash);
|
|
1947
|
-
ctx.setLineWidth(wrapper.lineWidth);
|
|
1948
|
-
ctx.setStrokeStyle(wrapper.color);
|
|
1949
|
-
ctx.moveTo(wrapper.dots.topLeft.x, wrapper.dots.topLeft.y);
|
|
1950
|
-
ctx.lineTo(wrapper.dots.topRight.x, wrapper.dots.topRight.y);
|
|
1951
|
-
ctx.lineTo(wrapper.dots.bottomRight.x, wrapper.dots.bottomRight.y);
|
|
1952
|
-
ctx.lineTo(wrapper.dots.bottomLeft.x, wrapper.dots.bottomLeft.y);
|
|
1953
|
-
ctx.lineTo(wrapper.dots.topLeft.x, wrapper.dots.topLeft.y - wrapper.lineWidth / 2);
|
|
1954
|
-
ctx.stroke();
|
|
1955
|
-
ctx.closePath();
|
|
1956
|
-
if (wrapper.lock === true) {
|
|
1957
|
-
clearContext(ctx);
|
|
1958
|
-
ctx.setStrokeStyle(wrapper.color);
|
|
1959
|
-
[
|
|
1960
|
-
wrapper.dots.topLeft, wrapper.dots.top, wrapper.dots.topRight, wrapper.dots.right,
|
|
1961
|
-
wrapper.dots.bottomRight, wrapper.dots.bottom, wrapper.dots.bottomLeft, wrapper.dots.left,
|
|
1962
|
-
].forEach(function (dot) {
|
|
1963
|
-
ctx.beginPath();
|
|
1964
|
-
ctx.moveTo(dot.x - wrapper.dotSize / 2, dot.y - wrapper.dotSize / 2);
|
|
1965
|
-
ctx.lineTo(dot.x + wrapper.dotSize / 2, dot.y + wrapper.dotSize / 2);
|
|
1966
|
-
ctx.stroke();
|
|
1967
|
-
ctx.closePath();
|
|
1968
|
-
ctx.beginPath();
|
|
1969
|
-
ctx.moveTo(dot.x + wrapper.dotSize / 2, dot.y - wrapper.dotSize / 2);
|
|
1970
|
-
ctx.lineTo(dot.x - wrapper.dotSize / 2, dot.y + wrapper.dotSize / 2);
|
|
1971
|
-
ctx.stroke();
|
|
1972
|
-
ctx.closePath();
|
|
1973
|
-
});
|
|
1974
|
-
}
|
|
1975
|
-
});
|
|
1976
|
-
});
|
|
1977
|
-
}
|
|
1978
|
-
|
|
1979
|
-
var isColorStr = index.color.isColorStr;
|
|
1980
|
-
function drawContext(ctx, data, helperConfig, loader) {
|
|
1981
|
-
var _a;
|
|
1982
|
-
clearContext(ctx);
|
|
1983
|
-
var size = ctx.getSize();
|
|
1984
|
-
ctx.clearRect(0, 0, size.contextWidth, size.contextHeight);
|
|
1985
|
-
if (typeof data.bgColor === 'string' && isColorStr(data.bgColor)) {
|
|
1986
|
-
drawBgColor(ctx, data.bgColor);
|
|
1987
|
-
}
|
|
1988
|
-
if (!(data.elements.length > 0)) {
|
|
1989
|
-
return;
|
|
1990
|
-
}
|
|
1991
|
-
for (var i = 0; i < data.elements.length; i++) {
|
|
1992
|
-
var elem = data.elements[i];
|
|
1993
|
-
if (((_a = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
|
|
1994
|
-
continue;
|
|
1995
|
-
}
|
|
1996
|
-
switch (elem.type) {
|
|
1997
|
-
case 'rect': {
|
|
1998
|
-
drawRect(ctx, elem);
|
|
1999
|
-
break;
|
|
2000
|
-
}
|
|
2001
|
-
case 'text': {
|
|
2002
|
-
drawText(ctx, elem);
|
|
2003
|
-
break;
|
|
2004
|
-
}
|
|
2005
|
-
case 'image': {
|
|
2006
|
-
drawImage(ctx, elem, loader);
|
|
2007
|
-
break;
|
|
2008
|
-
}
|
|
2009
|
-
case 'svg': {
|
|
2010
|
-
drawSVG(ctx, elem, loader);
|
|
2011
|
-
break;
|
|
2012
|
-
}
|
|
2013
|
-
case 'html': {
|
|
2014
|
-
drawHTML(ctx, elem, loader);
|
|
2015
|
-
break;
|
|
2016
|
-
}
|
|
2017
|
-
case 'circle': {
|
|
2018
|
-
drawCircle(ctx, elem);
|
|
2019
|
-
break;
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
drawElementWrapper(ctx, helperConfig);
|
|
2024
|
-
drawAreaWrapper(ctx, helperConfig);
|
|
2025
|
-
drawElementListWrappers(ctx, helperConfig);
|
|
2026
|
-
}
|
|
2027
|
-
|
|
2028
|
-
var defaultConfig = {
|
|
2029
|
-
elementWrapper: {
|
|
2030
|
-
color: '#2ab6f1',
|
|
2031
|
-
lockColor: '#aaaaaa',
|
|
2032
|
-
dotSize: 6,
|
|
2033
|
-
lineWidth: 1,
|
|
2034
|
-
lineDash: [4, 3],
|
|
2035
|
-
}
|
|
2036
|
-
};
|
|
2037
|
-
function mergeConfig(config) {
|
|
2038
|
-
var result = index.data.deepClone(defaultConfig);
|
|
2039
|
-
if (config) {
|
|
2040
|
-
if (config.elementWrapper) {
|
|
2041
|
-
result.elementWrapper = __assign$1(__assign$1({}, result.elementWrapper), config.elementWrapper);
|
|
2042
|
-
}
|
|
2043
|
-
}
|
|
2044
|
-
return result;
|
|
2045
|
-
}
|
|
2046
|
-
|
|
2047
|
-
var CoreEvent = (function () {
|
|
2048
|
-
function CoreEvent() {
|
|
2049
|
-
this._listeners = new Map();
|
|
2050
|
-
}
|
|
2051
|
-
CoreEvent.prototype.on = function (eventKey, callback) {
|
|
2052
|
-
if (this._listeners.has(eventKey)) {
|
|
2053
|
-
var callbacks = this._listeners.get(eventKey);
|
|
2054
|
-
callbacks === null || callbacks === void 0 ? void 0 : callbacks.push(callback);
|
|
2055
|
-
this._listeners.set(eventKey, callbacks || []);
|
|
2056
|
-
}
|
|
2057
|
-
else {
|
|
2058
|
-
this._listeners.set(eventKey, [callback]);
|
|
2059
|
-
}
|
|
2060
|
-
};
|
|
2061
|
-
CoreEvent.prototype.off = function (eventKey, callback) {
|
|
2062
|
-
if (this._listeners.has(eventKey)) {
|
|
2063
|
-
var callbacks = this._listeners.get(eventKey);
|
|
2064
|
-
if (Array.isArray(callbacks)) {
|
|
2065
|
-
for (var i = 0; i < (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length); i++) {
|
|
2066
|
-
if (callbacks[i] === callback) {
|
|
2067
|
-
callbacks.splice(i, 1);
|
|
2068
|
-
break;
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
this._listeners.set(eventKey, callbacks || []);
|
|
2073
|
-
}
|
|
2074
|
-
};
|
|
2075
|
-
CoreEvent.prototype.trigger = function (eventKey, arg) {
|
|
2076
|
-
var callbacks = this._listeners.get(eventKey);
|
|
2077
|
-
if (Array.isArray(callbacks)) {
|
|
2078
|
-
callbacks.forEach(function (cb) {
|
|
2079
|
-
cb(arg);
|
|
2080
|
-
});
|
|
2081
|
-
return true;
|
|
2082
|
-
}
|
|
2083
|
-
else {
|
|
2084
|
-
return false;
|
|
2085
|
-
}
|
|
2086
|
-
};
|
|
2087
|
-
CoreEvent.prototype.has = function (name) {
|
|
2088
|
-
if (this._listeners.has(name)) {
|
|
2089
|
-
var list = this._listeners.get(name);
|
|
2090
|
-
if (Array.isArray(list) && list.length > 0) {
|
|
2091
|
-
return true;
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
return false;
|
|
2095
|
-
};
|
|
2096
|
-
return CoreEvent;
|
|
2097
|
-
}());
|
|
2098
|
-
|
|
2099
|
-
function isChangeImageElementResource(before, after) {
|
|
2100
|
-
var _a, _b;
|
|
2101
|
-
return (((_a = before === null || before === void 0 ? void 0 : before.desc) === null || _a === void 0 ? void 0 : _a.src) !== ((_b = after === null || after === void 0 ? void 0 : after.desc) === null || _b === void 0 ? void 0 : _b.src));
|
|
2102
|
-
}
|
|
2103
|
-
function isChangeSVGElementResource(before, after) {
|
|
2104
|
-
var _a, _b;
|
|
2105
|
-
return (((_a = before === null || before === void 0 ? void 0 : before.desc) === null || _a === void 0 ? void 0 : _a.svg) !== ((_b = after === null || after === void 0 ? void 0 : after.desc) === null || _b === void 0 ? void 0 : _b.svg));
|
|
2106
|
-
}
|
|
2107
|
-
function isChangeHTMLElementResource(before, after) {
|
|
2108
|
-
var _a, _b, _c, _d, _e, _f;
|
|
2109
|
-
return (((_a = before === null || before === void 0 ? void 0 : before.desc) === null || _a === void 0 ? void 0 : _a.html) !== ((_b = after === null || after === void 0 ? void 0 : after.desc) === null || _b === void 0 ? void 0 : _b.html)
|
|
2110
|
-
|| ((_c = before === null || before === void 0 ? void 0 : before.desc) === null || _c === void 0 ? void 0 : _c.width) !== ((_d = after === null || after === void 0 ? void 0 : after.desc) === null || _d === void 0 ? void 0 : _d.width)
|
|
2111
|
-
|| ((_e = before === null || before === void 0 ? void 0 : before.desc) === null || _e === void 0 ? void 0 : _e.height) !== ((_f = after === null || after === void 0 ? void 0 : after.desc) === null || _f === void 0 ? void 0 : _f.height));
|
|
2112
|
-
}
|
|
2113
|
-
function diffElementResourceChange(before, after) {
|
|
2114
|
-
var result = null;
|
|
2115
|
-
var isChange = false;
|
|
2116
|
-
switch (after.type) {
|
|
2117
|
-
case 'image': {
|
|
2118
|
-
isChange = isChangeImageElementResource(before, after);
|
|
2119
|
-
break;
|
|
2120
|
-
}
|
|
2121
|
-
case 'svg': {
|
|
2122
|
-
isChange = isChangeSVGElementResource(before, after);
|
|
2123
|
-
break;
|
|
2124
|
-
}
|
|
2125
|
-
case 'html': {
|
|
2126
|
-
isChange = isChangeHTMLElementResource(before, after);
|
|
2127
|
-
break;
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
if (isChange === true) {
|
|
2131
|
-
result = after.uuid;
|
|
2132
|
-
}
|
|
2133
|
-
return result;
|
|
2134
|
-
}
|
|
2135
|
-
function diffElementResourceChangeList(before, after) {
|
|
2136
|
-
var _a;
|
|
2137
|
-
var uuids = [];
|
|
2138
|
-
var beforeMap = parseDataElementMap(before);
|
|
2139
|
-
var afterMap = parseDataElementMap(after);
|
|
2140
|
-
for (var uuid in afterMap) {
|
|
2141
|
-
if (['image', 'svg', 'html'].includes((_a = afterMap[uuid]) === null || _a === void 0 ? void 0 : _a.type) !== true) {
|
|
2142
|
-
continue;
|
|
2143
|
-
}
|
|
2144
|
-
if (beforeMap[uuid]) {
|
|
2145
|
-
var isChange = false;
|
|
2146
|
-
switch (beforeMap[uuid].type) {
|
|
2147
|
-
case 'image': {
|
|
2148
|
-
isChange = isChangeImageElementResource(beforeMap[uuid], afterMap[uuid]);
|
|
2149
|
-
break;
|
|
2150
|
-
}
|
|
2151
|
-
case 'svg': {
|
|
2152
|
-
isChange = isChangeSVGElementResource(beforeMap[uuid], afterMap[uuid]);
|
|
2153
|
-
break;
|
|
2154
|
-
}
|
|
2155
|
-
case 'html': {
|
|
2156
|
-
isChange = isChangeHTMLElementResource(beforeMap[uuid], afterMap[uuid]);
|
|
2157
|
-
break;
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
if (isChange === true) {
|
|
2161
|
-
uuids.push(uuid);
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
else {
|
|
2165
|
-
uuids.push(uuid);
|
|
2166
|
-
}
|
|
2167
|
-
}
|
|
2168
|
-
return uuids;
|
|
2169
|
-
}
|
|
2170
|
-
function parseDataElementMap(data) {
|
|
2171
|
-
var elemMap = {};
|
|
2172
|
-
data.elements.forEach(function (elem) {
|
|
2173
|
-
elemMap[elem.uuid] = elem;
|
|
2174
|
-
});
|
|
2175
|
-
return elemMap;
|
|
2176
|
-
}
|
|
2177
|
-
|
|
2178
|
-
function limitNum(num) {
|
|
2179
|
-
var numStr = num.toFixed(2);
|
|
2180
|
-
return parseFloat(numStr);
|
|
2181
|
-
}
|
|
2182
|
-
function limitAngle(angle) {
|
|
2183
|
-
return limitNum(angle % 360);
|
|
2184
|
-
}
|
|
2185
|
-
|
|
2186
|
-
var createUUID$1 = index.uuid.createUUID;
|
|
2187
|
-
var Element = (function () {
|
|
2188
|
-
function Element(ctx) {
|
|
2189
|
-
this._ctx = ctx;
|
|
2190
|
-
}
|
|
2191
|
-
Element.prototype.initData = function (data) {
|
|
2192
|
-
data.elements.forEach(function (elem) {
|
|
2193
|
-
if (!(elem.uuid && typeof elem.uuid === 'string')) {
|
|
2194
|
-
elem.uuid = createUUID$1();
|
|
2195
|
-
}
|
|
2196
|
-
});
|
|
2197
|
-
return data;
|
|
2198
|
-
};
|
|
2199
|
-
Element.prototype.isPointInElement = function (p, data) {
|
|
2200
|
-
var _a;
|
|
2201
|
-
var ctx = this._ctx;
|
|
2202
|
-
var idx = -1;
|
|
2203
|
-
var uuid = null;
|
|
2204
|
-
var _loop_1 = function (i) {
|
|
2205
|
-
var ele = data.elements[i];
|
|
2206
|
-
var bw = 0;
|
|
2207
|
-
if (((_a = ele.desc) === null || _a === void 0 ? void 0 : _a.borderWidth) > 0) {
|
|
2208
|
-
bw = ele.desc.borderWidth;
|
|
2209
|
-
}
|
|
2210
|
-
rotateElement(ctx, ele, function () {
|
|
2211
|
-
ctx.beginPath();
|
|
2212
|
-
ctx.moveTo(ele.x - bw, ele.y - bw);
|
|
2213
|
-
ctx.lineTo(ele.x + ele.w + bw, ele.y - bw);
|
|
2214
|
-
ctx.lineTo(ele.x + ele.w + bw, ele.y + ele.h + bw);
|
|
2215
|
-
ctx.lineTo(ele.x - bw, ele.y + ele.h + bw);
|
|
2216
|
-
ctx.lineTo(ele.x, ele.y);
|
|
2217
|
-
ctx.rect(ele.x, ele.y, ele.w, ele.h);
|
|
2218
|
-
ctx.closePath();
|
|
2219
|
-
if (ctx.isPointInPath(p.x, p.y)) {
|
|
2220
|
-
idx = i;
|
|
2221
|
-
uuid = ele.uuid;
|
|
2222
|
-
}
|
|
2223
|
-
});
|
|
2224
|
-
if (idx >= 0) {
|
|
2225
|
-
return "break";
|
|
2226
|
-
}
|
|
2227
|
-
};
|
|
2228
|
-
for (var i = data.elements.length - 1; i >= 0; i--) {
|
|
2229
|
-
var state_1 = _loop_1(i);
|
|
2230
|
-
if (state_1 === "break")
|
|
2231
|
-
break;
|
|
2232
|
-
}
|
|
2233
|
-
return [idx, uuid];
|
|
2234
|
-
};
|
|
2235
|
-
Element.prototype.dragElement = function (data, uuid, point, prevPoint, scale) {
|
|
2236
|
-
var index = this.getElementIndex(data, uuid);
|
|
2237
|
-
if (!data.elements[index]) {
|
|
2238
|
-
return;
|
|
2239
|
-
}
|
|
2240
|
-
var moveX = point.x - prevPoint.x;
|
|
2241
|
-
var moveY = point.y - prevPoint.y;
|
|
2242
|
-
data.elements[index].x += (moveX / scale);
|
|
2243
|
-
data.elements[index].y += (moveY / scale);
|
|
2244
|
-
this.limitElementAttrs(data.elements[index]);
|
|
2245
|
-
};
|
|
2246
|
-
Element.prototype.transformElement = function (data, uuid, point, prevPoint, scale, direction) {
|
|
2247
|
-
var _a, _b;
|
|
2248
|
-
var index = this.getElementIndex(data, uuid);
|
|
2249
|
-
if (!data.elements[index]) {
|
|
2250
|
-
return null;
|
|
2251
|
-
}
|
|
2252
|
-
if (((_b = (_a = data.elements[index]) === null || _a === void 0 ? void 0 : _a.operation) === null || _b === void 0 ? void 0 : _b.lock) === true) {
|
|
2253
|
-
return null;
|
|
2254
|
-
}
|
|
2255
|
-
var moveX = (point.x - prevPoint.x) / scale;
|
|
2256
|
-
var moveY = (point.y - prevPoint.y) / scale;
|
|
2257
|
-
var elem = data.elements[index];
|
|
2258
|
-
switch (direction) {
|
|
2259
|
-
case 'top-left': {
|
|
2260
|
-
if (elem.w - moveX > 0 && elem.h - moveY > 0) {
|
|
2261
|
-
elem.x += moveX;
|
|
2262
|
-
elem.y += moveY;
|
|
2263
|
-
elem.w -= moveX;
|
|
2264
|
-
elem.h -= moveY;
|
|
2265
|
-
}
|
|
2266
|
-
break;
|
|
2267
|
-
}
|
|
2268
|
-
case 'top': {
|
|
2269
|
-
if (elem.h - moveY > 0) {
|
|
2270
|
-
elem.y += moveY;
|
|
2271
|
-
elem.h -= moveY;
|
|
2272
|
-
}
|
|
2273
|
-
break;
|
|
2274
|
-
}
|
|
2275
|
-
case 'top-right': {
|
|
2276
|
-
if (elem.h - moveY > 0 && elem.w + moveX > 0) {
|
|
2277
|
-
elem.y += moveY;
|
|
2278
|
-
elem.w += moveX;
|
|
2279
|
-
elem.h -= moveY;
|
|
2280
|
-
}
|
|
2281
|
-
break;
|
|
2282
|
-
}
|
|
2283
|
-
case 'right': {
|
|
2284
|
-
if (elem.w + moveX > 0) {
|
|
2285
|
-
elem.w += moveX;
|
|
2286
|
-
}
|
|
2287
|
-
break;
|
|
2288
|
-
}
|
|
2289
|
-
case 'bottom-right': {
|
|
2290
|
-
if (elem.w + moveX > 0 && elem.h + moveY > 0) {
|
|
2291
|
-
elem.w += moveX;
|
|
2292
|
-
elem.h += moveY;
|
|
2293
|
-
}
|
|
2294
|
-
break;
|
|
2295
|
-
}
|
|
2296
|
-
case 'bottom': {
|
|
2297
|
-
if (elem.h + moveY > 0) {
|
|
2298
|
-
elem.h += moveY;
|
|
2299
|
-
}
|
|
2300
|
-
break;
|
|
2301
|
-
}
|
|
2302
|
-
case 'bottom-left': {
|
|
2303
|
-
if (elem.w - moveX > 0 && elem.h + moveY > 0) {
|
|
2304
|
-
elem.x += moveX;
|
|
2305
|
-
elem.w -= moveX;
|
|
2306
|
-
elem.h += moveY;
|
|
2307
|
-
}
|
|
2308
|
-
break;
|
|
2309
|
-
}
|
|
2310
|
-
case 'left': {
|
|
2311
|
-
if (elem.w - moveX > 0) {
|
|
2312
|
-
elem.x += moveX;
|
|
2313
|
-
elem.w -= moveX;
|
|
2314
|
-
}
|
|
2315
|
-
break;
|
|
2316
|
-
}
|
|
2317
|
-
case 'rotate': {
|
|
2318
|
-
var center = calcElementCenter(elem);
|
|
2319
|
-
var radian = calcRadian(center, prevPoint, point);
|
|
2320
|
-
elem.angle = (elem.angle || 0) + parseRadianToAngle(radian);
|
|
2321
|
-
break;
|
|
2322
|
-
}
|
|
2323
|
-
}
|
|
2324
|
-
this.limitElementAttrs(elem);
|
|
2325
|
-
return {
|
|
2326
|
-
width: limitNum(elem.w),
|
|
2327
|
-
height: limitNum(elem.h),
|
|
2328
|
-
angle: limitAngle(elem.angle || 0),
|
|
2329
|
-
};
|
|
2330
|
-
};
|
|
2331
|
-
Element.prototype.getElementIndex = function (data, uuid) {
|
|
2332
|
-
var idx = -1;
|
|
2333
|
-
for (var i = 0; i < data.elements.length; i++) {
|
|
2334
|
-
if (data.elements[i].uuid === uuid) {
|
|
2335
|
-
idx = i;
|
|
2336
|
-
break;
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
return idx;
|
|
2340
|
-
};
|
|
2341
|
-
Element.prototype.limitElementAttrs = function (elem) {
|
|
2342
|
-
elem.x = limitNum(elem.x);
|
|
2343
|
-
elem.y = limitNum(elem.y);
|
|
2344
|
-
elem.w = limitNum(elem.w);
|
|
2345
|
-
elem.h = limitNum(elem.h);
|
|
2346
|
-
elem.angle = limitAngle(elem.angle || 0);
|
|
2347
|
-
};
|
|
2348
|
-
return Element;
|
|
2349
|
-
}());
|
|
2350
|
-
|
|
2351
|
-
var deepClone$4 = index.data.deepClone;
|
|
2352
|
-
var Helper = (function () {
|
|
2353
|
-
function Helper(board, config) {
|
|
2354
|
-
this._areaStart = { x: 0, y: 0 };
|
|
2355
|
-
this._areaEnd = { x: 0, y: 0 };
|
|
2356
|
-
this._board = board;
|
|
2357
|
-
this._ctx = this._board.getContext();
|
|
2358
|
-
this._coreConfig = config;
|
|
2359
|
-
this._helperConfig = {
|
|
2360
|
-
elementIndexMap: {}
|
|
2361
|
-
};
|
|
2362
|
-
}
|
|
2363
|
-
Helper.prototype.updateConfig = function (data, opts) {
|
|
2364
|
-
this._updateElementIndex(data);
|
|
2365
|
-
this._updateSelectedElementWrapper(data, opts);
|
|
2366
|
-
this._updateSelectedElementListWrapper(data, opts);
|
|
2367
|
-
};
|
|
2368
|
-
Helper.prototype.getConfig = function () {
|
|
2369
|
-
return deepClone$4(this._helperConfig);
|
|
2370
|
-
};
|
|
2371
|
-
Helper.prototype.getElementIndexByUUID = function (uuid) {
|
|
2372
|
-
var index = this._helperConfig.elementIndexMap[uuid];
|
|
2373
|
-
if (index >= 0) {
|
|
2374
|
-
return index;
|
|
2375
|
-
}
|
|
2376
|
-
return null;
|
|
2377
|
-
};
|
|
2378
|
-
Helper.prototype.isPointInElementWrapperDot = function (p) {
|
|
2379
|
-
var _a, _b;
|
|
2380
|
-
var ctx = this._ctx;
|
|
2381
|
-
var uuid = (_b = (_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementWrapper) === null || _b === void 0 ? void 0 : _b.uuid;
|
|
2382
|
-
var direction = null;
|
|
2383
|
-
if (!this._helperConfig.selectedElementWrapper) {
|
|
2384
|
-
return [null, null];
|
|
2385
|
-
}
|
|
2386
|
-
var wrapper = this._helperConfig.selectedElementWrapper;
|
|
2387
|
-
var dots = [
|
|
2388
|
-
wrapper.dots.topLeft, wrapper.dots.top, wrapper.dots.topRight, wrapper.dots.right,
|
|
2389
|
-
wrapper.dots.bottomRight, wrapper.dots.bottom, wrapper.dots.bottomLeft, wrapper.dots.left,
|
|
2390
|
-
wrapper.dots.rotate,
|
|
2391
|
-
];
|
|
2392
|
-
var directionNames = [
|
|
2393
|
-
'top-left', 'top', 'top-right', 'right',
|
|
2394
|
-
'bottom-right', 'bottom', 'bottom-left', 'left',
|
|
2395
|
-
'rotate',
|
|
2396
|
-
];
|
|
2397
|
-
rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
|
|
2398
|
-
for (var i = 0; i < dots.length; i++) {
|
|
2399
|
-
var dot = dots[i];
|
|
2400
|
-
ctx.beginPath();
|
|
2401
|
-
ctx.arc(dot.x, dot.y, wrapper.dotSize, 0, Math.PI * 2);
|
|
2402
|
-
ctx.closePath();
|
|
2403
|
-
if (ctx.isPointInPath(p.x, p.y)) {
|
|
2404
|
-
direction = directionNames[i];
|
|
2405
|
-
}
|
|
2406
|
-
if (direction) {
|
|
2407
|
-
break;
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
});
|
|
2411
|
-
return [uuid, direction];
|
|
2412
|
-
};
|
|
2413
|
-
Helper.prototype.isPointInElementList = function (p, data) {
|
|
2414
|
-
var _a, _b;
|
|
2415
|
-
var ctx = this._ctx;
|
|
2416
|
-
var idx = -1;
|
|
2417
|
-
var uuid = null;
|
|
2418
|
-
var wrapperList = ((_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementListWrappers) || [];
|
|
2419
|
-
var _loop_1 = function (i) {
|
|
2420
|
-
var wrapper = wrapperList[i];
|
|
2421
|
-
var elemIdx = this_1._helperConfig.elementIndexMap[wrapper.uuid];
|
|
2422
|
-
var ele = data.elements[elemIdx];
|
|
2423
|
-
if (!ele)
|
|
2424
|
-
return "continue";
|
|
2425
|
-
var bw = 0;
|
|
2426
|
-
if (((_b = ele.desc) === null || _b === void 0 ? void 0 : _b.borderWidth) > 0) {
|
|
2427
|
-
bw = ele.desc.borderWidth;
|
|
2428
|
-
}
|
|
2429
|
-
rotateElement(ctx, ele, function () {
|
|
2430
|
-
ctx.beginPath();
|
|
2431
|
-
ctx.moveTo(ele.x - bw, ele.y - bw);
|
|
2432
|
-
ctx.lineTo(ele.x + ele.w + bw, ele.y - bw);
|
|
2433
|
-
ctx.lineTo(ele.x + ele.w + bw, ele.y + ele.h + bw);
|
|
2434
|
-
ctx.lineTo(ele.x - bw, ele.y + ele.h + bw);
|
|
2435
|
-
ctx.lineTo(ele.x, ele.y);
|
|
2436
|
-
ctx.rect(ele.x, ele.y, ele.w, ele.h);
|
|
2437
|
-
ctx.closePath();
|
|
2438
|
-
if (ctx.isPointInPath(p.x, p.y)) {
|
|
2439
|
-
idx = i;
|
|
2440
|
-
uuid = ele.uuid;
|
|
2441
|
-
}
|
|
2442
|
-
});
|
|
2443
|
-
if (idx >= 0) {
|
|
2444
|
-
return "break";
|
|
2445
|
-
}
|
|
2446
|
-
};
|
|
2447
|
-
var this_1 = this;
|
|
2448
|
-
for (var i = 0; i < wrapperList.length; i++) {
|
|
2449
|
-
var state_1 = _loop_1(i);
|
|
2450
|
-
if (state_1 === "break")
|
|
2451
|
-
break;
|
|
2452
|
-
}
|
|
2453
|
-
if (uuid && idx >= 0) {
|
|
2454
|
-
return true;
|
|
2455
|
-
}
|
|
2456
|
-
else {
|
|
2457
|
-
return false;
|
|
2458
|
-
}
|
|
2459
|
-
};
|
|
2460
|
-
Helper.prototype.startSelectArea = function (p) {
|
|
2461
|
-
this._areaStart = p;
|
|
2462
|
-
this._areaEnd = p;
|
|
2463
|
-
};
|
|
2464
|
-
Helper.prototype.changeSelectArea = function (p) {
|
|
2465
|
-
this._areaEnd = p;
|
|
2466
|
-
this._calcSelectedArea();
|
|
2467
|
-
};
|
|
2468
|
-
Helper.prototype.clearSelectedArea = function () {
|
|
2469
|
-
this._areaStart = { x: 0, y: 0 };
|
|
2470
|
-
this._areaEnd = { x: 0, y: 0 };
|
|
2471
|
-
this._calcSelectedArea();
|
|
2472
|
-
};
|
|
2473
|
-
Helper.prototype.calcSelectedElements = function (data) {
|
|
2474
|
-
var transform = this._ctx.getTransform();
|
|
2475
|
-
var _a = transform.scale, scale = _a === void 0 ? 1 : _a, _b = transform.scrollX, scrollX = _b === void 0 ? 0 : _b, _c = transform.scrollY, scrollY = _c === void 0 ? 0 : _c;
|
|
2476
|
-
var start = this._areaStart;
|
|
2477
|
-
var end = this._areaEnd;
|
|
2478
|
-
var x = (Math.min(start.x, end.x) - scrollX) / scale;
|
|
2479
|
-
var y = (Math.min(start.y, end.y) - scrollY) / scale;
|
|
2480
|
-
var w = Math.abs(end.x - start.x) / scale;
|
|
2481
|
-
var h = Math.abs(end.y - start.y) / scale;
|
|
2482
|
-
var uuids = [];
|
|
2483
|
-
var ctx = this._ctx;
|
|
2484
|
-
ctx.beginPath();
|
|
2485
|
-
ctx.moveTo(x, y);
|
|
2486
|
-
ctx.lineTo(x + w, y);
|
|
2487
|
-
ctx.lineTo(x + w, y + h);
|
|
2488
|
-
ctx.lineTo(x, y + h);
|
|
2489
|
-
ctx.lineTo(x, y);
|
|
2490
|
-
ctx.closePath();
|
|
2491
|
-
data.elements.forEach(function (elem) {
|
|
2492
|
-
var _a;
|
|
2493
|
-
if (((_a = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _a === void 0 ? void 0 : _a.invisible) !== true) {
|
|
2494
|
-
var centerX = elem.x + elem.w / 2;
|
|
2495
|
-
var centerY = elem.y + elem.h / 2;
|
|
2496
|
-
if (ctx.isPointInPathWithoutScroll(centerX, centerY)) {
|
|
2497
|
-
uuids.push(elem.uuid);
|
|
2498
|
-
}
|
|
2499
|
-
}
|
|
2500
|
-
});
|
|
2501
|
-
return uuids;
|
|
2502
|
-
};
|
|
2503
|
-
Helper.prototype._calcSelectedArea = function () {
|
|
2504
|
-
var start = this._areaStart;
|
|
2505
|
-
var end = this._areaEnd;
|
|
2506
|
-
var transform = this._ctx.getTransform();
|
|
2507
|
-
var _a = transform.scale, scale = _a === void 0 ? 1 : _a, _b = transform.scrollX, scrollX = _b === void 0 ? 0 : _b, _c = transform.scrollY, scrollY = _c === void 0 ? 0 : _c;
|
|
2508
|
-
var elemWrapper = this._coreConfig.elementWrapper;
|
|
2509
|
-
var lineWidth = elemWrapper.lineWidth / scale;
|
|
2510
|
-
var lineDash = elemWrapper.lineDash.map(function (n) { return (n / scale); });
|
|
2511
|
-
this._helperConfig.selectedAreaWrapper = {
|
|
2512
|
-
x: (Math.min(start.x, end.x) - scrollX) / scale,
|
|
2513
|
-
y: (Math.min(start.y, end.y) - scrollY) / scale,
|
|
2514
|
-
w: Math.abs(end.x - start.x) / scale,
|
|
2515
|
-
h: Math.abs(end.y - start.y) / scale,
|
|
2516
|
-
startPoint: { x: start.x, y: start.y },
|
|
2517
|
-
endPoint: { x: end.x, y: end.y },
|
|
2518
|
-
lineWidth: lineWidth,
|
|
2519
|
-
lineDash: lineDash,
|
|
2520
|
-
color: elemWrapper.color,
|
|
2521
|
-
};
|
|
2522
|
-
};
|
|
2523
|
-
Helper.prototype._updateElementIndex = function (data) {
|
|
2524
|
-
var _this = this;
|
|
2525
|
-
this._helperConfig.elementIndexMap = {};
|
|
2526
|
-
data.elements.forEach(function (elem, i) {
|
|
2527
|
-
_this._helperConfig.elementIndexMap[elem.uuid] = i;
|
|
2528
|
-
});
|
|
2529
|
-
};
|
|
2530
|
-
Helper.prototype._updateSelectedElementWrapper = function (data, opts) {
|
|
2531
|
-
var _a;
|
|
2532
|
-
var uuid = opts.selectedUUID;
|
|
2533
|
-
if (!(typeof uuid === 'string' && this._helperConfig.elementIndexMap[uuid] >= 0)) {
|
|
2534
|
-
delete this._helperConfig.selectedElementWrapper;
|
|
2535
|
-
return;
|
|
2536
|
-
}
|
|
2537
|
-
var index = this._helperConfig.elementIndexMap[uuid];
|
|
2538
|
-
var elem = data.elements[index];
|
|
2539
|
-
if (((_a = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
|
|
2540
|
-
return;
|
|
2541
|
-
}
|
|
2542
|
-
var wrapper = this._createSelectedElementWrapper(elem, opts);
|
|
2543
|
-
this._helperConfig.selectedElementWrapper = wrapper;
|
|
2544
|
-
};
|
|
2545
|
-
Helper.prototype._updateSelectedElementListWrapper = function (data, opts) {
|
|
2546
|
-
var _this = this;
|
|
2547
|
-
var selectedUUIDList = opts.selectedUUIDList;
|
|
2548
|
-
var wrapperList = [];
|
|
2549
|
-
data.elements.forEach(function (elem, i) {
|
|
2550
|
-
if (selectedUUIDList === null || selectedUUIDList === void 0 ? void 0 : selectedUUIDList.includes(elem.uuid)) {
|
|
2551
|
-
var wrapper = _this._createSelectedElementWrapper(elem, opts);
|
|
2552
|
-
wrapperList.push(wrapper);
|
|
2553
|
-
}
|
|
2554
|
-
});
|
|
2555
|
-
this._helperConfig.selectedElementListWrappers = wrapperList;
|
|
2556
|
-
};
|
|
2557
|
-
Helper.prototype._createSelectedElementWrapper = function (elem, opts) {
|
|
2558
|
-
var _a, _b, _c;
|
|
2559
|
-
var scale = opts.scale;
|
|
2560
|
-
var elemWrapper = this._coreConfig.elementWrapper;
|
|
2561
|
-
var dotSize = elemWrapper.dotSize / scale;
|
|
2562
|
-
var lineWidth = elemWrapper.lineWidth / scale;
|
|
2563
|
-
var lineDash = elemWrapper.lineDash.map(function (n) { return (n / scale); });
|
|
2564
|
-
var rotateLimit = 12;
|
|
2565
|
-
var bw = ((_a = elem.desc) === null || _a === void 0 ? void 0 : _a.borderWidth) || 0;
|
|
2566
|
-
var wrapper = {
|
|
2567
|
-
uuid: elem.uuid,
|
|
2568
|
-
dotSize: dotSize,
|
|
2569
|
-
lock: ((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.lock) === true,
|
|
2570
|
-
dots: {
|
|
2571
|
-
topLeft: {
|
|
2572
|
-
x: elem.x - dotSize - bw,
|
|
2573
|
-
y: elem.y - dotSize - bw,
|
|
2574
|
-
},
|
|
2575
|
-
top: {
|
|
2576
|
-
x: elem.x + elem.w / 2,
|
|
2577
|
-
y: elem.y - dotSize - bw,
|
|
2578
|
-
},
|
|
2579
|
-
topRight: {
|
|
2580
|
-
x: elem.x + elem.w + dotSize + bw,
|
|
2581
|
-
y: elem.y - dotSize - bw,
|
|
2582
|
-
},
|
|
2583
|
-
right: {
|
|
2584
|
-
x: elem.x + elem.w + dotSize + bw,
|
|
2585
|
-
y: elem.y + elem.h / 2,
|
|
2586
|
-
},
|
|
2587
|
-
bottomRight: {
|
|
2588
|
-
x: elem.x + elem.w + dotSize + bw,
|
|
2589
|
-
y: elem.y + elem.h + dotSize + bw,
|
|
2590
|
-
},
|
|
2591
|
-
bottom: {
|
|
2592
|
-
x: elem.x + elem.w / 2,
|
|
2593
|
-
y: elem.y + elem.h + dotSize + bw,
|
|
2594
|
-
},
|
|
2595
|
-
bottomLeft: {
|
|
2596
|
-
x: elem.x - dotSize - bw,
|
|
2597
|
-
y: elem.y + elem.h + dotSize + bw,
|
|
2598
|
-
},
|
|
2599
|
-
left: {
|
|
2600
|
-
x: elem.x - dotSize - bw,
|
|
2601
|
-
y: elem.y + elem.h / 2,
|
|
2602
|
-
},
|
|
2603
|
-
rotate: {
|
|
2604
|
-
x: elem.x + elem.w / 2,
|
|
2605
|
-
y: elem.y - dotSize - (dotSize * 2 + rotateLimit) - bw,
|
|
2606
|
-
}
|
|
2607
|
-
},
|
|
2608
|
-
lineWidth: lineWidth,
|
|
2609
|
-
lineDash: lineDash,
|
|
2610
|
-
color: ((_c = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _c === void 0 ? void 0 : _c.lock) === true ? elemWrapper.lockColor : elemWrapper.color,
|
|
2611
|
-
};
|
|
2612
|
-
if (typeof elem.angle === 'number' && (elem.angle > 0 || elem.angle < 0)) {
|
|
2613
|
-
wrapper.radian = parseAngleToRadian(elem.angle);
|
|
2614
|
-
wrapper.translate = calcElementCenter(elem);
|
|
2615
|
-
}
|
|
2616
|
-
return wrapper;
|
|
2617
|
-
};
|
|
2618
|
-
return Helper;
|
|
2619
|
-
}());
|
|
2620
|
-
|
|
2621
|
-
var LoaderEvent = (function () {
|
|
2622
|
-
function LoaderEvent() {
|
|
2623
|
-
this._listeners = new Map();
|
|
2624
|
-
}
|
|
2625
|
-
LoaderEvent.prototype.on = function (eventKey, callback) {
|
|
2626
|
-
if (this._listeners.has(eventKey)) {
|
|
2627
|
-
var callbacks = this._listeners.get(eventKey);
|
|
2628
|
-
callbacks === null || callbacks === void 0 ? void 0 : callbacks.push(callback);
|
|
2629
|
-
this._listeners.set(eventKey, callbacks || []);
|
|
2630
|
-
}
|
|
2631
|
-
else {
|
|
2632
|
-
this._listeners.set(eventKey, [callback]);
|
|
2633
|
-
}
|
|
2634
|
-
};
|
|
2635
|
-
LoaderEvent.prototype.off = function (eventKey, callback) {
|
|
2636
|
-
if (this._listeners.has(eventKey)) {
|
|
2637
|
-
var callbacks = this._listeners.get(eventKey);
|
|
2638
|
-
if (Array.isArray(callbacks)) {
|
|
2639
|
-
for (var i = 0; i < (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length); i++) {
|
|
2640
|
-
if (callbacks[i] === callback) {
|
|
2641
|
-
callbacks.splice(i, 1);
|
|
2642
|
-
break;
|
|
2643
|
-
}
|
|
2644
|
-
}
|
|
2645
|
-
}
|
|
2646
|
-
this._listeners.set(eventKey, callbacks || []);
|
|
2647
|
-
}
|
|
2648
|
-
};
|
|
2649
|
-
LoaderEvent.prototype.trigger = function (eventKey, arg) {
|
|
2650
|
-
var callbacks = this._listeners.get(eventKey);
|
|
2651
|
-
if (Array.isArray(callbacks)) {
|
|
2652
|
-
callbacks.forEach(function (cb) {
|
|
2653
|
-
cb(arg);
|
|
2654
|
-
});
|
|
2655
|
-
return true;
|
|
2656
|
-
}
|
|
2657
|
-
else {
|
|
2658
|
-
return false;
|
|
2659
|
-
}
|
|
2660
|
-
};
|
|
2661
|
-
LoaderEvent.prototype.has = function (name) {
|
|
2662
|
-
if (this._listeners.has(name)) {
|
|
2663
|
-
var list = this._listeners.get(name);
|
|
2664
|
-
if (Array.isArray(list) && list.length > 0) {
|
|
2665
|
-
return true;
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
return false;
|
|
2669
|
-
};
|
|
2670
|
-
return LoaderEvent;
|
|
2671
|
-
}());
|
|
2672
|
-
|
|
2673
|
-
function filterScript(html) {
|
|
2674
|
-
return html.replace(/<script[\s\S]*?<\/script>/ig, '');
|
|
2675
|
-
}
|
|
2676
|
-
|
|
2677
|
-
var _a = index.loader, loadImage = _a.loadImage, loadSVG = _a.loadSVG, loadHTML = _a.loadHTML;
|
|
2678
|
-
var LoaderStatus;
|
|
2679
|
-
(function (LoaderStatus) {
|
|
2680
|
-
LoaderStatus["FREE"] = "free";
|
|
2681
|
-
LoaderStatus["LOADING"] = "loading";
|
|
2682
|
-
LoaderStatus["COMPLETE"] = "complete";
|
|
2683
|
-
})(LoaderStatus || (LoaderStatus = {}));
|
|
2684
|
-
var Loader = (function () {
|
|
2685
|
-
function Loader(opts) {
|
|
2686
|
-
this._currentLoadData = {};
|
|
2687
|
-
this._currentUUIDQueue = [];
|
|
2688
|
-
this._storageLoadData = {};
|
|
2689
|
-
this._status = LoaderStatus.FREE;
|
|
2690
|
-
this._waitingLoadQueue = [];
|
|
2691
|
-
this._opts = opts;
|
|
2692
|
-
this._event = new LoaderEvent();
|
|
2693
|
-
this._waitingLoadQueue = [];
|
|
2694
|
-
}
|
|
2695
|
-
Loader.prototype.load = function (data, changeResourceUUIDs) {
|
|
2696
|
-
var _a = this._resetLoadData(data, changeResourceUUIDs), uuidQueue = _a[0], loadData = _a[1];
|
|
2697
|
-
if (this._status === LoaderStatus.FREE || this._status === LoaderStatus.COMPLETE) {
|
|
2698
|
-
this._currentUUIDQueue = uuidQueue;
|
|
2699
|
-
this._currentLoadData = loadData;
|
|
2700
|
-
this._loadTask();
|
|
2701
|
-
}
|
|
2702
|
-
else if (this._status === LoaderStatus.LOADING && uuidQueue.length > 0) {
|
|
2703
|
-
this._waitingLoadQueue.push({
|
|
2704
|
-
uuidQueue: uuidQueue,
|
|
2705
|
-
loadData: loadData,
|
|
2706
|
-
});
|
|
2707
|
-
}
|
|
2708
|
-
};
|
|
2709
|
-
Loader.prototype.on = function (name, callback) {
|
|
2710
|
-
this._event.on(name, callback);
|
|
2711
|
-
};
|
|
2712
|
-
Loader.prototype.off = function (name, callback) {
|
|
2713
|
-
this._event.off(name, callback);
|
|
2714
|
-
};
|
|
2715
|
-
Loader.prototype.isComplete = function () {
|
|
2716
|
-
return this._status === LoaderStatus.COMPLETE;
|
|
2717
|
-
};
|
|
2718
|
-
Loader.prototype.getContent = function (uuid) {
|
|
2719
|
-
var _a;
|
|
2720
|
-
if (((_a = this._storageLoadData[uuid]) === null || _a === void 0 ? void 0 : _a.status) === 'loaded') {
|
|
2721
|
-
return this._storageLoadData[uuid].content;
|
|
2722
|
-
}
|
|
2723
|
-
return null;
|
|
2724
|
-
};
|
|
2725
|
-
Loader.prototype._resetLoadData = function (data, changeResourceUUIDs) {
|
|
2726
|
-
var loadData = {};
|
|
2727
|
-
var uuidQueue = [];
|
|
2728
|
-
var storageLoadData = this._storageLoadData;
|
|
2729
|
-
for (var i = data.elements.length - 1; i >= 0; i--) {
|
|
2730
|
-
var elem = data.elements[i];
|
|
2731
|
-
if (['image', 'svg', 'html',].includes(elem.type)) {
|
|
2732
|
-
if (!storageLoadData[elem.uuid]) {
|
|
2733
|
-
loadData[elem.uuid] = this._createEmptyLoadItem(elem);
|
|
2734
|
-
uuidQueue.push(elem.uuid);
|
|
2735
|
-
}
|
|
2736
|
-
else {
|
|
2737
|
-
if (changeResourceUUIDs.includes(elem.uuid)) {
|
|
2738
|
-
loadData[elem.uuid] = this._createEmptyLoadItem(elem);
|
|
2739
|
-
uuidQueue.push(elem.uuid);
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
return [uuidQueue, loadData];
|
|
2745
|
-
};
|
|
2746
|
-
Loader.prototype._createEmptyLoadItem = function (elem) {
|
|
2747
|
-
var source = '';
|
|
2748
|
-
var type = elem.type;
|
|
2749
|
-
var elemW = elem.w;
|
|
2750
|
-
var elemH = elem.h;
|
|
2751
|
-
if (elem.type === 'image') {
|
|
2752
|
-
var _elem = elem;
|
|
2753
|
-
source = _elem.desc.src || '';
|
|
2754
|
-
}
|
|
2755
|
-
else if (elem.type === 'svg') {
|
|
2756
|
-
var _elem = elem;
|
|
2757
|
-
source = _elem.desc.svg || '';
|
|
2758
|
-
}
|
|
2759
|
-
else if (elem.type === 'html') {
|
|
2760
|
-
var _elem = elem;
|
|
2761
|
-
source = filterScript(_elem.desc.html || '');
|
|
2762
|
-
elemW = _elem.desc.width || elem.w;
|
|
2763
|
-
elemH = _elem.desc.height || elem.h;
|
|
2764
|
-
}
|
|
2765
|
-
return {
|
|
2766
|
-
type: type,
|
|
2767
|
-
status: 'null',
|
|
2768
|
-
content: null,
|
|
2769
|
-
source: source,
|
|
2770
|
-
elemW: elemW,
|
|
2771
|
-
elemH: elemH,
|
|
2772
|
-
};
|
|
2773
|
-
};
|
|
2774
|
-
Loader.prototype._loadTask = function () {
|
|
2775
|
-
var _this = this;
|
|
2776
|
-
if (this._status === LoaderStatus.LOADING) {
|
|
2777
|
-
return;
|
|
2778
|
-
}
|
|
2779
|
-
this._status = LoaderStatus.LOADING;
|
|
2780
|
-
if (this._currentUUIDQueue.length === 0) {
|
|
2781
|
-
if (this._waitingLoadQueue.length === 0) {
|
|
2782
|
-
this._status = LoaderStatus.COMPLETE;
|
|
2783
|
-
this._event.trigger('complete', undefined);
|
|
2784
|
-
return;
|
|
2785
|
-
}
|
|
2786
|
-
else {
|
|
2787
|
-
var waitingItem = this._waitingLoadQueue.shift();
|
|
2788
|
-
if (waitingItem) {
|
|
2789
|
-
var uuidQueue = waitingItem.uuidQueue, loadData = waitingItem.loadData;
|
|
2790
|
-
this._currentLoadData = loadData;
|
|
2791
|
-
this._currentUUIDQueue = uuidQueue;
|
|
2792
|
-
}
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
var maxParallelNum = this._opts.maxParallelNum;
|
|
2796
|
-
var uuids = this._currentUUIDQueue.splice(0, maxParallelNum);
|
|
2797
|
-
var uuidMap = {};
|
|
2798
|
-
uuids.forEach(function (url, i) {
|
|
2799
|
-
uuidMap[url] = i;
|
|
2800
|
-
});
|
|
2801
|
-
var loadUUIDList = [];
|
|
2802
|
-
var _loadAction = function () {
|
|
2803
|
-
if (loadUUIDList.length >= maxParallelNum) {
|
|
2804
|
-
return false;
|
|
2805
|
-
}
|
|
2806
|
-
if (uuids.length === 0) {
|
|
2807
|
-
return true;
|
|
2808
|
-
}
|
|
2809
|
-
var _loop_1 = function (i) {
|
|
2810
|
-
var uuid = uuids.shift();
|
|
2811
|
-
if (uuid === undefined) {
|
|
2812
|
-
return "break";
|
|
2813
|
-
}
|
|
2814
|
-
loadUUIDList.push(uuid);
|
|
2815
|
-
_this._loadElementSource(_this._currentLoadData[uuid]).then(function (image) {
|
|
2816
|
-
loadUUIDList.splice(loadUUIDList.indexOf(uuid), 1);
|
|
2817
|
-
var status = _loadAction();
|
|
2818
|
-
_this._storageLoadData[uuid] = {
|
|
2819
|
-
type: _this._currentLoadData[uuid].type,
|
|
2820
|
-
status: 'loaded',
|
|
2821
|
-
content: image,
|
|
2822
|
-
source: _this._currentLoadData[uuid].source,
|
|
2823
|
-
elemW: _this._currentLoadData[uuid].elemW,
|
|
2824
|
-
elemH: _this._currentLoadData[uuid].elemH,
|
|
2825
|
-
};
|
|
2826
|
-
if (loadUUIDList.length === 0 && uuids.length === 0 && status === true) {
|
|
2827
|
-
_this._status = LoaderStatus.FREE;
|
|
2828
|
-
_this._loadTask();
|
|
2829
|
-
}
|
|
2830
|
-
_this._event.trigger('load', {
|
|
2831
|
-
type: _this._storageLoadData[uuid].type,
|
|
2832
|
-
status: _this._storageLoadData[uuid].status,
|
|
2833
|
-
content: _this._storageLoadData[uuid].content,
|
|
2834
|
-
source: _this._storageLoadData[uuid].source,
|
|
2835
|
-
elemW: _this._storageLoadData[uuid].elemW,
|
|
2836
|
-
elemH: _this._storageLoadData[uuid].elemH,
|
|
2837
|
-
});
|
|
2838
|
-
}).catch(function (err) {
|
|
2839
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2840
|
-
console.warn(err);
|
|
2841
|
-
loadUUIDList.splice(loadUUIDList.indexOf(uuid), 1);
|
|
2842
|
-
var status = _loadAction();
|
|
2843
|
-
if (_this._currentLoadData[uuid]) {
|
|
2844
|
-
_this._storageLoadData[uuid] = {
|
|
2845
|
-
type: (_a = _this._currentLoadData[uuid]) === null || _a === void 0 ? void 0 : _a.type,
|
|
2846
|
-
status: 'fail',
|
|
2847
|
-
content: null,
|
|
2848
|
-
error: err,
|
|
2849
|
-
source: (_b = _this._currentLoadData[uuid]) === null || _b === void 0 ? void 0 : _b.source,
|
|
2850
|
-
elemW: (_c = _this._currentLoadData[uuid]) === null || _c === void 0 ? void 0 : _c.elemW,
|
|
2851
|
-
elemH: (_d = _this._currentLoadData[uuid]) === null || _d === void 0 ? void 0 : _d.elemH,
|
|
2852
|
-
};
|
|
2853
|
-
}
|
|
2854
|
-
if (loadUUIDList.length === 0 && uuids.length === 0 && status === true) {
|
|
2855
|
-
_this._status = LoaderStatus.FREE;
|
|
2856
|
-
_this._loadTask();
|
|
2857
|
-
}
|
|
2858
|
-
if (_this._currentLoadData[uuid]) {
|
|
2859
|
-
_this._event.trigger('error', {
|
|
2860
|
-
type: (_e = _this._storageLoadData[uuid]) === null || _e === void 0 ? void 0 : _e.type,
|
|
2861
|
-
status: (_f = _this._storageLoadData[uuid]) === null || _f === void 0 ? void 0 : _f.status,
|
|
2862
|
-
content: (_g = _this._storageLoadData[uuid]) === null || _g === void 0 ? void 0 : _g.content,
|
|
2863
|
-
source: (_h = _this._storageLoadData[uuid]) === null || _h === void 0 ? void 0 : _h.source,
|
|
2864
|
-
elemW: (_j = _this._storageLoadData[uuid]) === null || _j === void 0 ? void 0 : _j.elemW,
|
|
2865
|
-
elemH: (_k = _this._storageLoadData[uuid]) === null || _k === void 0 ? void 0 : _k.elemH,
|
|
2866
|
-
});
|
|
2867
|
-
}
|
|
2868
|
-
});
|
|
2869
|
-
};
|
|
2870
|
-
for (var i = loadUUIDList.length; i < maxParallelNum; i++) {
|
|
2871
|
-
var state_1 = _loop_1();
|
|
2872
|
-
if (state_1 === "break")
|
|
2873
|
-
break;
|
|
2874
|
-
}
|
|
2875
|
-
return false;
|
|
2876
|
-
};
|
|
2877
|
-
_loadAction();
|
|
2878
|
-
};
|
|
2879
|
-
Loader.prototype._loadElementSource = function (params) {
|
|
2880
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2881
|
-
var image, image, image;
|
|
2882
|
-
return __generator(this, function (_a) {
|
|
2883
|
-
switch (_a.label) {
|
|
2884
|
-
case 0:
|
|
2885
|
-
if (!(params && params.type === 'image')) return [3, 2];
|
|
2886
|
-
return [4, loadImage(params.source)];
|
|
2887
|
-
case 1:
|
|
2888
|
-
image = _a.sent();
|
|
2889
|
-
return [2, image];
|
|
2890
|
-
case 2:
|
|
2891
|
-
if (!(params && params.type === 'svg')) return [3, 4];
|
|
2892
|
-
return [4, loadSVG(params.source)];
|
|
2893
|
-
case 3:
|
|
2894
|
-
image = _a.sent();
|
|
2895
|
-
return [2, image];
|
|
2896
|
-
case 4:
|
|
2897
|
-
if (!(params && params.type === 'html')) return [3, 6];
|
|
2898
|
-
return [4, loadHTML(params.source, {
|
|
2899
|
-
width: params.elemW, height: params.elemH
|
|
2900
|
-
})];
|
|
2901
|
-
case 5:
|
|
2902
|
-
image = _a.sent();
|
|
2903
|
-
return [2, image];
|
|
2904
|
-
case 6: throw Error('Element\'s source is not support!');
|
|
2905
|
-
}
|
|
2906
|
-
});
|
|
2907
|
-
});
|
|
2908
|
-
};
|
|
2909
|
-
return Loader;
|
|
2910
|
-
}());
|
|
2911
|
-
|
|
2912
|
-
var _board$1 = Symbol('_displayCtx');
|
|
2913
|
-
var _helper$1 = Symbol('_helper');
|
|
2914
|
-
var _element$1 = Symbol('_element');
|
|
2915
|
-
var _opts$1 = Symbol('_opts');
|
|
2916
|
-
var Mapper = (function () {
|
|
2917
|
-
function Mapper(opts) {
|
|
2918
|
-
this[_opts$1] = opts;
|
|
2919
|
-
this[_board$1] = this[_opts$1].board;
|
|
2920
|
-
this[_element$1] = this[_opts$1].element;
|
|
2921
|
-
this[_helper$1] = this[_opts$1].helper;
|
|
2922
|
-
}
|
|
2923
|
-
Mapper.prototype.isEffectivePoint = function (p) {
|
|
2924
|
-
var scrollLineWidth = this[_board$1].getScrollLineWidth();
|
|
2925
|
-
var screenInfo = this[_board$1].getScreenInfo();
|
|
2926
|
-
if (p.x <= (screenInfo.width - scrollLineWidth) && p.y <= (screenInfo.height - scrollLineWidth)) {
|
|
2927
|
-
return true;
|
|
2928
|
-
}
|
|
2929
|
-
return false;
|
|
2930
|
-
};
|
|
2931
|
-
Mapper.prototype.judgePointCursor = function (p, data) {
|
|
2932
|
-
var cursor = 'auto';
|
|
2933
|
-
var elementUUID = null;
|
|
2934
|
-
if (!this.isEffectivePoint(p)) {
|
|
2935
|
-
return { cursor: cursor, elementUUID: elementUUID };
|
|
2936
|
-
}
|
|
2937
|
-
var _a = this[_helper$1].isPointInElementWrapperDot(p), uuid = _a[0], direction = _a[1];
|
|
2938
|
-
if (uuid && direction) {
|
|
2939
|
-
switch (direction) {
|
|
2940
|
-
case 'top-left': {
|
|
2941
|
-
cursor = 'nw-resize';
|
|
2942
|
-
break;
|
|
2943
|
-
}
|
|
2944
|
-
case 'top': {
|
|
2945
|
-
cursor = 'n-resize';
|
|
2946
|
-
break;
|
|
2947
|
-
}
|
|
2948
|
-
case 'top-right': {
|
|
2949
|
-
cursor = 'ne-resize';
|
|
2950
|
-
break;
|
|
2951
|
-
}
|
|
2952
|
-
case 'right': {
|
|
2953
|
-
cursor = 'e-resize';
|
|
2954
|
-
break;
|
|
2955
|
-
}
|
|
2956
|
-
case 'bottom-right': {
|
|
2957
|
-
cursor = 'se-resize';
|
|
2958
|
-
break;
|
|
2959
|
-
}
|
|
2960
|
-
case 'bottom': {
|
|
2961
|
-
cursor = 's-resize';
|
|
2962
|
-
break;
|
|
2963
|
-
}
|
|
2964
|
-
case 'bottom-left': {
|
|
2965
|
-
cursor = 'sw-resize';
|
|
2966
|
-
break;
|
|
2967
|
-
}
|
|
2968
|
-
case 'left': {
|
|
2969
|
-
cursor = 'w-resize';
|
|
2970
|
-
break;
|
|
2971
|
-
}
|
|
2972
|
-
case 'rotate': {
|
|
2973
|
-
cursor = 'grab';
|
|
2974
|
-
break;
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
if (uuid) {
|
|
2978
|
-
elementUUID = uuid;
|
|
2979
|
-
}
|
|
2980
|
-
}
|
|
2981
|
-
else {
|
|
2982
|
-
var _b = this[_element$1].isPointInElement(p, data), index = _b[0], uuid_1 = _b[1];
|
|
2983
|
-
if (index >= 0) {
|
|
2984
|
-
cursor = 'move';
|
|
2985
|
-
}
|
|
2986
|
-
if (uuid_1) {
|
|
2987
|
-
elementUUID = uuid_1;
|
|
2988
|
-
}
|
|
2989
|
-
}
|
|
2990
|
-
return {
|
|
2991
|
-
cursor: cursor,
|
|
2992
|
-
elementUUID: elementUUID,
|
|
2993
|
-
};
|
|
2994
|
-
};
|
|
2995
|
-
return Mapper;
|
|
2996
|
-
}());
|
|
2997
|
-
|
|
2998
|
-
var elementTypes = {
|
|
2999
|
-
'text': {},
|
|
3000
|
-
'rect': {},
|
|
3001
|
-
'image': {},
|
|
3002
|
-
'svg': {},
|
|
3003
|
-
'circle': {},
|
|
3004
|
-
'html': {},
|
|
3005
|
-
};
|
|
3006
|
-
var elementNames = Object.keys(elementTypes);
|
|
3007
|
-
|
|
3008
|
-
function parseData(data) {
|
|
3009
|
-
var result = {
|
|
3010
|
-
elements: [],
|
|
3011
|
-
};
|
|
3012
|
-
if (Array.isArray(data === null || data === void 0 ? void 0 : data.elements)) {
|
|
3013
|
-
data === null || data === void 0 ? void 0 : data.elements.forEach(function (elem) {
|
|
3014
|
-
if (elem === void 0) { elem = {}; }
|
|
3015
|
-
if (isElement(elem)) {
|
|
3016
|
-
result.elements.push(elem);
|
|
3017
|
-
}
|
|
3018
|
-
});
|
|
3019
|
-
}
|
|
3020
|
-
if (typeof data.bgColor === 'string') {
|
|
3021
|
-
result.bgColor = data.bgColor;
|
|
3022
|
-
}
|
|
3023
|
-
return result;
|
|
3024
|
-
}
|
|
3025
|
-
function isElement(elem) {
|
|
3026
|
-
if (!(isNumber(elem.x) && isNumber(elem.y) && isNumber(elem.w) && isNumber(elem.h))) {
|
|
3027
|
-
return false;
|
|
3028
|
-
}
|
|
3029
|
-
if (!(typeof elem.type === 'string' && elementNames.includes(elem.type))) {
|
|
3030
|
-
return false;
|
|
3031
|
-
}
|
|
3032
|
-
return true;
|
|
3033
|
-
}
|
|
3034
|
-
function isNumber(num) {
|
|
3035
|
-
return (num >= 0 || num < 0);
|
|
3036
|
-
}
|
|
3037
|
-
|
|
3038
|
-
var requestAnimationFrame = window.requestAnimationFrame;
|
|
3039
|
-
var deepClone$3 = index.data.deepClone;
|
|
3040
|
-
var DrawStatus;
|
|
3041
|
-
(function (DrawStatus) {
|
|
3042
|
-
DrawStatus["FREE"] = "free";
|
|
3043
|
-
DrawStatus["DRAWING"] = "drawing";
|
|
3044
|
-
})(DrawStatus || (DrawStatus = {}));
|
|
3045
|
-
var Renderer = (function () {
|
|
3046
|
-
function Renderer(board) {
|
|
3047
|
-
var _this = this;
|
|
3048
|
-
this._queue = [];
|
|
3049
|
-
this._status = DrawStatus.FREE;
|
|
3050
|
-
this._board = board;
|
|
3051
|
-
this._loader = new Loader({
|
|
3052
|
-
board: board,
|
|
3053
|
-
maxParallelNum: 6
|
|
3054
|
-
});
|
|
3055
|
-
this._loader.on('load', function (res) {
|
|
3056
|
-
_this._drawFrame();
|
|
3057
|
-
});
|
|
3058
|
-
this._loader.on('error', function (res) {
|
|
3059
|
-
console.log('Loader Error: ', res);
|
|
3060
|
-
});
|
|
3061
|
-
this._loader.on('complete', function (res) {
|
|
3062
|
-
});
|
|
3063
|
-
}
|
|
3064
|
-
Renderer.prototype.render = function (data, helper, changeResourceUUIDs) {
|
|
3065
|
-
var _data = deepClone$3({ data: data, helper: helper });
|
|
3066
|
-
this._queue.push(_data);
|
|
3067
|
-
if (this._status !== DrawStatus.DRAWING) {
|
|
3068
|
-
this._status = DrawStatus.DRAWING;
|
|
3069
|
-
this._drawFrame();
|
|
3070
|
-
}
|
|
3071
|
-
this._loader.load(data, changeResourceUUIDs);
|
|
3072
|
-
};
|
|
3073
|
-
Renderer.prototype._drawFrame = function () {
|
|
3074
|
-
var _this = this;
|
|
3075
|
-
requestAnimationFrame(function () {
|
|
3076
|
-
var ctx = _this._board.getContext();
|
|
3077
|
-
var item = _this._queue[0];
|
|
3078
|
-
var isLastFrame = false;
|
|
3079
|
-
if (_this._queue.length > 1) {
|
|
3080
|
-
item = _this._queue.shift();
|
|
3081
|
-
}
|
|
3082
|
-
else {
|
|
3083
|
-
isLastFrame = true;
|
|
3084
|
-
}
|
|
3085
|
-
if (_this._loader.isComplete() !== true) {
|
|
3086
|
-
_this._drawFrame();
|
|
3087
|
-
if (item) {
|
|
3088
|
-
drawContext(ctx, item.data, item.helper, _this._loader);
|
|
3089
|
-
_this._board.draw();
|
|
3090
|
-
}
|
|
3091
|
-
}
|
|
3092
|
-
else if (item) {
|
|
3093
|
-
drawContext(ctx, item.data, item.helper, _this._loader);
|
|
3094
|
-
_this._board.draw();
|
|
3095
|
-
_this._retainQueueOneItem();
|
|
3096
|
-
if (!isLastFrame) {
|
|
3097
|
-
_this._drawFrame();
|
|
3098
|
-
}
|
|
3099
|
-
else {
|
|
3100
|
-
_this._status = DrawStatus.FREE;
|
|
3101
|
-
}
|
|
3102
|
-
}
|
|
3103
|
-
else {
|
|
3104
|
-
_this._status = DrawStatus.FREE;
|
|
3105
|
-
}
|
|
3106
|
-
});
|
|
3107
|
-
};
|
|
3108
|
-
Renderer.prototype._retainQueueOneItem = function () {
|
|
3109
|
-
if (this._queue.length <= 1) {
|
|
3110
|
-
return;
|
|
3111
|
-
}
|
|
3112
|
-
var lastOne = deepClone$3(this._queue[this._queue.length - 1]);
|
|
3113
|
-
this._queue = [lastOne];
|
|
3114
|
-
};
|
|
3115
|
-
return Renderer;
|
|
3116
|
-
}());
|
|
3117
|
-
|
|
3118
|
-
var Mode;
|
|
3119
|
-
(function (Mode) {
|
|
3120
|
-
Mode["NULL"] = "null";
|
|
3121
|
-
Mode["SELECT_ELEMENT"] = "select-element";
|
|
3122
|
-
Mode["SELECT_ELEMENT_LIST"] = "select-element-list";
|
|
3123
|
-
Mode["SELECT_ELEMENT_WRAPPER_DOT"] = "select-element-wrapper-dot";
|
|
3124
|
-
Mode["SELECT_AREA"] = "select-area";
|
|
3125
|
-
})(Mode || (Mode = {}));
|
|
3126
|
-
var CursorStatus;
|
|
3127
|
-
(function (CursorStatus) {
|
|
3128
|
-
CursorStatus["DRAGGING"] = "dragging";
|
|
3129
|
-
CursorStatus["NULL"] = "null";
|
|
3130
|
-
})(CursorStatus || (CursorStatus = {}));
|
|
3131
|
-
|
|
3132
|
-
function createData() {
|
|
3133
|
-
return {
|
|
3134
|
-
onlyRender: false,
|
|
3135
|
-
hasInited: false,
|
|
3136
|
-
mode: Mode.NULL,
|
|
3137
|
-
cursorStatus: CursorStatus.NULL,
|
|
3138
|
-
selectedUUID: null,
|
|
3139
|
-
selectedUUIDList: [],
|
|
3140
|
-
hoverUUID: null,
|
|
3141
|
-
selectedDotDirection: null,
|
|
3142
|
-
prevPoint: null,
|
|
3143
|
-
};
|
|
3144
|
-
}
|
|
3145
|
-
var TempData = (function () {
|
|
3146
|
-
function TempData() {
|
|
3147
|
-
this._temp = createData();
|
|
3148
|
-
}
|
|
3149
|
-
TempData.prototype.set = function (name, value) {
|
|
3150
|
-
this._temp[name] = value;
|
|
3151
|
-
};
|
|
3152
|
-
TempData.prototype.get = function (name) {
|
|
3153
|
-
return this._temp[name];
|
|
3154
|
-
};
|
|
3155
|
-
TempData.prototype.clear = function () {
|
|
3156
|
-
this._temp = createData();
|
|
3157
|
-
};
|
|
3158
|
-
return TempData;
|
|
3159
|
-
}());
|
|
3160
|
-
|
|
3161
|
-
var _board = Symbol('_board');
|
|
3162
|
-
var _data = Symbol('_data');
|
|
3163
|
-
var _opts = Symbol('_opts');
|
|
3164
|
-
var _config = Symbol('_config');
|
|
3165
|
-
var _renderer = Symbol('_renderer');
|
|
3166
|
-
var _element = Symbol('_element');
|
|
3167
|
-
var _helper = Symbol('_helper');
|
|
3168
|
-
var _tempData = Symbol('_tempData');
|
|
3169
|
-
var _draw = Symbol('_draw');
|
|
3170
|
-
var _coreEvent = Symbol('_coreEvent');
|
|
3171
|
-
var _mapper = Symbol('_mapper');
|
|
3172
|
-
var _emitChangeScreen = Symbol('_emitChangeScreen');
|
|
3173
|
-
var _emitChangeData = Symbol('_emitChangeData');
|
|
3174
|
-
var _todo = Symbol('_todo');
|
|
3175
|
-
|
|
3176
|
-
var deepClone$2 = index.data.deepClone;
|
|
3177
|
-
var createUUID = index.uuid.createUUID;
|
|
3178
|
-
function getSelectedElements(core) {
|
|
3179
|
-
var elems = [];
|
|
3180
|
-
var list = [];
|
|
3181
|
-
var uuid = core[_tempData].get('selectedUUID');
|
|
3182
|
-
if (typeof uuid === 'string' && uuid) {
|
|
3183
|
-
list.push(uuid);
|
|
3184
|
-
}
|
|
3185
|
-
else {
|
|
3186
|
-
list = core[_tempData].get('selectedUUIDList');
|
|
3187
|
-
}
|
|
3188
|
-
list.forEach(function (uuid) {
|
|
3189
|
-
var _a;
|
|
3190
|
-
var index = core[_helper].getElementIndexByUUID(uuid);
|
|
3191
|
-
if (index !== null && index >= 0) {
|
|
3192
|
-
var elem = (_a = core[_data]) === null || _a === void 0 ? void 0 : _a.elements[index];
|
|
3193
|
-
if (elem)
|
|
3194
|
-
elems.push(elem);
|
|
3195
|
-
}
|
|
3196
|
-
});
|
|
3197
|
-
return deepClone$2(elems);
|
|
3198
|
-
}
|
|
3199
|
-
function getElement(core, uuid) {
|
|
3200
|
-
var elem = null;
|
|
3201
|
-
var index = core[_helper].getElementIndexByUUID(uuid);
|
|
3202
|
-
if (index !== null && core[_data].elements[index]) {
|
|
3203
|
-
elem = deepClone$2(core[_data].elements[index]);
|
|
3204
|
-
}
|
|
3205
|
-
return elem;
|
|
3206
|
-
}
|
|
3207
|
-
function getElementByIndex(core, index) {
|
|
3208
|
-
var elem = null;
|
|
3209
|
-
if (index >= 0 && core[_data].elements[index]) {
|
|
3210
|
-
elem = deepClone$2(core[_data].elements[index]);
|
|
3211
|
-
}
|
|
3212
|
-
return elem;
|
|
3213
|
-
}
|
|
3214
|
-
function updateElement(core, elem) {
|
|
3215
|
-
var _a;
|
|
3216
|
-
var _elem = deepClone$2(elem);
|
|
3217
|
-
var data = core[_data];
|
|
3218
|
-
var resourceChangeUUIDs = [];
|
|
3219
|
-
for (var i = 0; i < data.elements.length; i++) {
|
|
3220
|
-
if (_elem.uuid === ((_a = data.elements[i]) === null || _a === void 0 ? void 0 : _a.uuid)) {
|
|
3221
|
-
var result = diffElementResourceChange(data.elements[i], _elem);
|
|
3222
|
-
if (typeof result === 'string') {
|
|
3223
|
-
resourceChangeUUIDs.push(result);
|
|
3224
|
-
}
|
|
3225
|
-
data.elements[i] = _elem;
|
|
3226
|
-
break;
|
|
3227
|
-
}
|
|
3228
|
-
}
|
|
3229
|
-
core[_emitChangeData]();
|
|
3230
|
-
core[_draw]({ resourceChangeUUIDs: resourceChangeUUIDs });
|
|
3231
|
-
}
|
|
3232
|
-
function selectElementByIndex(core, index, opts) {
|
|
3233
|
-
if (core[_tempData].get('onlyRender') === true)
|
|
3234
|
-
return;
|
|
3235
|
-
if (core[_data].elements[index]) {
|
|
3236
|
-
var uuid = core[_data].elements[index].uuid;
|
|
3237
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.useMode) === true) {
|
|
3238
|
-
core[_tempData].set('mode', Mode.SELECT_ELEMENT);
|
|
3239
|
-
}
|
|
3240
|
-
else {
|
|
3241
|
-
core[_tempData].set('mode', Mode.NULL);
|
|
3242
|
-
}
|
|
3243
|
-
if (typeof uuid === 'string') {
|
|
3244
|
-
core[_tempData].set('selectedUUID', uuid);
|
|
3245
|
-
core[_tempData].set('selectedUUIDList', []);
|
|
3246
|
-
}
|
|
3247
|
-
core[_draw]();
|
|
3248
|
-
}
|
|
3249
|
-
}
|
|
3250
|
-
function selectElement(core, uuid, opts) {
|
|
3251
|
-
if (core[_tempData].get('onlyRender') === true)
|
|
3252
|
-
return;
|
|
3253
|
-
var index = core[_helper].getElementIndexByUUID(uuid);
|
|
3254
|
-
if (typeof index === 'number' && index >= 0) {
|
|
3255
|
-
core.selectElementByIndex(index, opts);
|
|
3256
|
-
}
|
|
3257
|
-
}
|
|
3258
|
-
function moveUpElement(core, uuid) {
|
|
3259
|
-
var index = core[_helper].getElementIndexByUUID(uuid);
|
|
3260
|
-
if (typeof index === 'number' && index >= 0 && index < core[_data].elements.length - 1) {
|
|
3261
|
-
var temp = core[_data].elements[index];
|
|
3262
|
-
core[_data].elements[index] = core[_data].elements[index + 1];
|
|
3263
|
-
core[_data].elements[index + 1] = temp;
|
|
3264
|
-
}
|
|
3265
|
-
core[_emitChangeData]();
|
|
3266
|
-
core[_draw]();
|
|
3267
|
-
}
|
|
3268
|
-
function moveDownElement(core, uuid) {
|
|
3269
|
-
var index = core[_helper].getElementIndexByUUID(uuid);
|
|
3270
|
-
if (typeof index === 'number' && index > 0 && index < core[_data].elements.length) {
|
|
3271
|
-
var temp = core[_data].elements[index];
|
|
3272
|
-
core[_data].elements[index] = core[_data].elements[index - 1];
|
|
3273
|
-
core[_data].elements[index - 1] = temp;
|
|
3274
|
-
}
|
|
3275
|
-
core[_emitChangeData]();
|
|
3276
|
-
core[_draw]();
|
|
3277
|
-
}
|
|
3278
|
-
function addElement(core, elem) {
|
|
3279
|
-
var _elem = deepClone$2(elem);
|
|
3280
|
-
_elem.uuid = createUUID();
|
|
3281
|
-
core[_data].elements.push(_elem);
|
|
3282
|
-
core[_emitChangeData]();
|
|
3283
|
-
core[_draw]();
|
|
3284
|
-
return _elem.uuid;
|
|
3285
|
-
}
|
|
3286
|
-
function deleteElement(core, uuid) {
|
|
3287
|
-
var index = core[_element].getElementIndex(core[_data], uuid);
|
|
3288
|
-
if (index >= 0) {
|
|
3289
|
-
core[_data].elements.splice(index, 1);
|
|
3290
|
-
core[_emitChangeData]();
|
|
3291
|
-
core[_draw]();
|
|
3292
|
-
}
|
|
3293
|
-
}
|
|
3294
|
-
function insertElementBefore(core, elem, beforeUUID) {
|
|
3295
|
-
var index = core[_helper].getElementIndexByUUID(beforeUUID);
|
|
3296
|
-
if (index !== null) {
|
|
3297
|
-
return core.insertElementBeforeIndex(elem, index);
|
|
3298
|
-
}
|
|
3299
|
-
return null;
|
|
3300
|
-
}
|
|
3301
|
-
function insertElementBeforeIndex(core, elem, index) {
|
|
3302
|
-
var _elem = deepClone$2(elem);
|
|
3303
|
-
_elem.uuid = createUUID();
|
|
3304
|
-
if (index >= 0) {
|
|
3305
|
-
core[_data].elements.splice(index, 0, _elem);
|
|
3306
|
-
core[_emitChangeData]();
|
|
3307
|
-
core[_draw]();
|
|
3308
|
-
return _elem.uuid;
|
|
3309
|
-
}
|
|
3310
|
-
return null;
|
|
3311
|
-
}
|
|
3312
|
-
function insertElementAfter(core, elem, beforeUUID) {
|
|
3313
|
-
var index = core[_helper].getElementIndexByUUID(beforeUUID);
|
|
3314
|
-
if (index !== null) {
|
|
3315
|
-
return core.insertElementAfterIndex(elem, index);
|
|
3316
|
-
}
|
|
3317
|
-
return null;
|
|
3318
|
-
}
|
|
3319
|
-
function insertElementAfterIndex(core, elem, index) {
|
|
3320
|
-
var _elem = deepClone$2(elem);
|
|
3321
|
-
_elem.uuid = createUUID();
|
|
3322
|
-
if (index >= 0) {
|
|
3323
|
-
core[_data].elements.splice(index + 1, 0, _elem);
|
|
3324
|
-
core[_emitChangeData]();
|
|
3325
|
-
core[_draw]();
|
|
3326
|
-
return _elem.uuid;
|
|
3327
|
-
}
|
|
3328
|
-
return null;
|
|
3329
|
-
}
|
|
3330
|
-
|
|
3331
|
-
var time = index.time;
|
|
3332
|
-
var deepClone$1 = index.data.deepClone;
|
|
3333
|
-
function initEvent(core) {
|
|
3334
|
-
if (core[_tempData].get('hasInited') === true) {
|
|
3335
|
-
return;
|
|
3336
|
-
}
|
|
3337
|
-
core[_board].on('hover', time.throttle(handleHover(core), 32));
|
|
3338
|
-
core[_board].on('leave', time.throttle(handleLeave(core), 32));
|
|
3339
|
-
core[_board].on('point', time.throttle(handleClick(core), 16));
|
|
3340
|
-
core[_board].on('doubleClick', handleDoubleClick(core));
|
|
3341
|
-
if (core[_tempData].get('onlyRender') === true) {
|
|
3342
|
-
return;
|
|
3343
|
-
}
|
|
3344
|
-
core[_board].on('point', handlePoint(core));
|
|
3345
|
-
core[_board].on('moveStart', handleMoveStart(core));
|
|
3346
|
-
core[_board].on('move', time.throttle(handleMove(core), 16));
|
|
3347
|
-
core[_board].on('moveEnd', handleMoveEnd(core));
|
|
3348
|
-
core[_tempData].set('hasInited', true);
|
|
3349
|
-
}
|
|
3350
|
-
function handleDoubleClick(core) {
|
|
3351
|
-
return function (point) {
|
|
3352
|
-
var _a, _b, _c;
|
|
3353
|
-
var _d = core[_element].isPointInElement(point, core[_data]), index = _d[0], uuid = _d[1];
|
|
3354
|
-
if (index >= 0 && uuid) {
|
|
3355
|
-
var elem = deepClone$1((_a = core[_data].elements) === null || _a === void 0 ? void 0 : _a[index]);
|
|
3356
|
-
if (((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.invisible) !== true) {
|
|
3357
|
-
core[_coreEvent].trigger('screenDoubleClickElement', { index: index, uuid: uuid, element: deepClone$1((_c = core[_data].elements) === null || _c === void 0 ? void 0 : _c[index]) });
|
|
3358
|
-
}
|
|
3359
|
-
}
|
|
3360
|
-
core[_draw]();
|
|
3361
|
-
};
|
|
3362
|
-
}
|
|
3363
|
-
function handlePoint(core) {
|
|
3364
|
-
return function (point) {
|
|
3365
|
-
var _a, _b, _c;
|
|
3366
|
-
if (!core[_mapper].isEffectivePoint(point)) {
|
|
3367
|
-
return;
|
|
3368
|
-
}
|
|
3369
|
-
if (core[_helper].isPointInElementList(point, core[_data])) {
|
|
3370
|
-
core[_tempData].set('mode', Mode.SELECT_ELEMENT_LIST);
|
|
3371
|
-
}
|
|
3372
|
-
else {
|
|
3373
|
-
var _d = core[_helper].isPointInElementWrapperDot(point), uuid = _d[0], direction = _d[1];
|
|
3374
|
-
if (uuid && direction) {
|
|
3375
|
-
core[_tempData].set('mode', Mode.SELECT_ELEMENT_WRAPPER_DOT);
|
|
3376
|
-
core[_tempData].set('selectedDotDirection', direction);
|
|
3377
|
-
core[_tempData].set('selectedUUID', uuid);
|
|
3378
|
-
}
|
|
3379
|
-
else {
|
|
3380
|
-
var _e = core[_element].isPointInElement(point, core[_data]), index = _e[0], uuid_1 = _e[1];
|
|
3381
|
-
if (index >= 0 && ((_b = (_a = core[_data].elements[index]) === null || _a === void 0 ? void 0 : _a.operation) === null || _b === void 0 ? void 0 : _b.invisible) !== true) {
|
|
3382
|
-
core.selectElementByIndex(index, { useMode: true });
|
|
3383
|
-
if (typeof uuid_1 === 'string' && core[_coreEvent].has('screenSelectElement')) {
|
|
3384
|
-
core[_coreEvent].trigger('screenSelectElement', { index: index, uuid: uuid_1, element: deepClone$1((_c = core[_data].elements) === null || _c === void 0 ? void 0 : _c[index]) });
|
|
3385
|
-
core[_emitChangeScreen]();
|
|
3386
|
-
}
|
|
3387
|
-
core[_tempData].set('mode', Mode.SELECT_ELEMENT);
|
|
3388
|
-
}
|
|
3389
|
-
else {
|
|
3390
|
-
core[_tempData].set('selectedUUIDList', []);
|
|
3391
|
-
core[_tempData].set('mode', Mode.SELECT_AREA);
|
|
3392
|
-
}
|
|
3393
|
-
}
|
|
3394
|
-
}
|
|
3395
|
-
core[_draw]();
|
|
3396
|
-
};
|
|
3397
|
-
}
|
|
3398
|
-
function handleClick(core) {
|
|
3399
|
-
return function (point) {
|
|
3400
|
-
var _a;
|
|
3401
|
-
var _b = core[_element].isPointInElement(point, core[_data]), index = _b[0], uuid = _b[1];
|
|
3402
|
-
if (index >= 0 && uuid) {
|
|
3403
|
-
core[_coreEvent].trigger('screenClickElement', { index: index, uuid: uuid, element: deepClone$1((_a = core[_data].elements) === null || _a === void 0 ? void 0 : _a[index]) });
|
|
3404
|
-
}
|
|
3405
|
-
core[_draw]();
|
|
3406
|
-
};
|
|
3407
|
-
}
|
|
3408
|
-
function handleMoveStart(core) {
|
|
3409
|
-
return function (point) {
|
|
3410
|
-
core[_tempData].set('prevPoint', point);
|
|
3411
|
-
var uuid = core[_tempData].get('selectedUUID');
|
|
3412
|
-
if (core[_tempData].get('mode') === Mode.SELECT_ELEMENT_LIST) ;
|
|
3413
|
-
else if (core[_tempData].get('mode') === Mode.SELECT_ELEMENT) {
|
|
3414
|
-
if (typeof uuid === 'string' && core[_coreEvent].has('screenMoveElementStart')) {
|
|
3415
|
-
core[_coreEvent].trigger('screenMoveElementStart', {
|
|
3416
|
-
index: core[_element].getElementIndex(core[_data], uuid),
|
|
3417
|
-
uuid: uuid,
|
|
3418
|
-
x: point.x,
|
|
3419
|
-
y: point.y
|
|
3420
|
-
});
|
|
3421
|
-
}
|
|
3422
|
-
}
|
|
3423
|
-
else if (core[_tempData].get('mode') === Mode.SELECT_AREA) {
|
|
3424
|
-
core[_helper].startSelectArea(point);
|
|
3425
|
-
}
|
|
3426
|
-
};
|
|
3427
|
-
}
|
|
3428
|
-
function handleMove(core) {
|
|
3429
|
-
return function (point) {
|
|
3430
|
-
if (core[_tempData].get('mode') === Mode.SELECT_ELEMENT_LIST) {
|
|
3431
|
-
dragElements(core, core[_tempData].get('selectedUUIDList'), point, core[_tempData].get('prevPoint'));
|
|
3432
|
-
core[_draw]();
|
|
3433
|
-
core[_tempData].set('cursorStatus', CursorStatus.DRAGGING);
|
|
3434
|
-
}
|
|
3435
|
-
else if (typeof core[_tempData].get('selectedUUID') === 'string') {
|
|
3436
|
-
if (core[_tempData].get('mode') === Mode.SELECT_ELEMENT) {
|
|
3437
|
-
dragElements(core, [core[_tempData].get('selectedUUID')], point, core[_tempData].get('prevPoint'));
|
|
3438
|
-
core[_draw]();
|
|
3439
|
-
core[_tempData].set('cursorStatus', CursorStatus.DRAGGING);
|
|
3440
|
-
}
|
|
3441
|
-
else if (core[_tempData].get('mode') === Mode.SELECT_ELEMENT_WRAPPER_DOT && core[_tempData].get('selectedDotDirection')) {
|
|
3442
|
-
transfromElement(core, core[_tempData].get('selectedUUID'), point, core[_tempData].get('prevPoint'), core[_tempData].get('selectedDotDirection'));
|
|
3443
|
-
core[_tempData].set('cursorStatus', CursorStatus.DRAGGING);
|
|
3444
|
-
}
|
|
3445
|
-
}
|
|
3446
|
-
else if (core[_tempData].get('mode') === Mode.SELECT_AREA) {
|
|
3447
|
-
core[_helper].changeSelectArea(point);
|
|
3448
|
-
core[_draw]();
|
|
3449
|
-
}
|
|
3450
|
-
core[_tempData].set('prevPoint', point);
|
|
3451
|
-
};
|
|
3452
|
-
}
|
|
3453
|
-
function dragElements(core, uuids, point, prevPoint) {
|
|
3454
|
-
if (!prevPoint) {
|
|
3455
|
-
return;
|
|
3456
|
-
}
|
|
3457
|
-
uuids.forEach(function (uuid) {
|
|
3458
|
-
var _a, _b;
|
|
3459
|
-
var idx = core[_helper].getElementIndexByUUID(uuid);
|
|
3460
|
-
if (idx === null)
|
|
3461
|
-
return;
|
|
3462
|
-
var elem = core[_data].elements[idx];
|
|
3463
|
-
if (((_a = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _a === void 0 ? void 0 : _a.lock) !== true && ((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.invisible) !== true) {
|
|
3464
|
-
core[_element].dragElement(core[_data], uuid, point, prevPoint, core[_board].getContext().getTransform().scale);
|
|
3465
|
-
}
|
|
3466
|
-
});
|
|
3467
|
-
core[_draw]();
|
|
3468
|
-
}
|
|
3469
|
-
function handleMoveEnd(core) {
|
|
3470
|
-
return function (point) {
|
|
3471
|
-
var uuid = core[_tempData].get('selectedUUID');
|
|
3472
|
-
if (typeof uuid === 'string') {
|
|
3473
|
-
var index = core[_element].getElementIndex(core[_data], uuid);
|
|
3474
|
-
var elem = core[_data].elements[index];
|
|
3475
|
-
if (elem) {
|
|
3476
|
-
if (core[_coreEvent].has('screenMoveElementEnd')) {
|
|
3477
|
-
core[_coreEvent].trigger('screenMoveElementEnd', {
|
|
3478
|
-
index: index,
|
|
3479
|
-
uuid: uuid,
|
|
3480
|
-
x: point.x,
|
|
3481
|
-
y: point.y
|
|
3482
|
-
});
|
|
3483
|
-
}
|
|
3484
|
-
if (core[_coreEvent].has('screenChangeElement')) {
|
|
3485
|
-
core[_coreEvent].trigger('screenChangeElement', {
|
|
3486
|
-
index: index,
|
|
3487
|
-
uuid: uuid,
|
|
3488
|
-
width: elem.w,
|
|
3489
|
-
height: elem.h,
|
|
3490
|
-
angle: elem.angle || 0
|
|
3491
|
-
});
|
|
3492
|
-
}
|
|
3493
|
-
core[_emitChangeData]();
|
|
3494
|
-
}
|
|
3495
|
-
}
|
|
3496
|
-
else if (core[_tempData].get('mode') === Mode.SELECT_AREA) {
|
|
3497
|
-
var uuids = core[_helper].calcSelectedElements(core[_data]);
|
|
3498
|
-
if (uuids.length > 0) {
|
|
3499
|
-
core[_tempData].set('selectedUUIDList', uuids);
|
|
3500
|
-
core[_tempData].set('selectedUUID', null);
|
|
3501
|
-
}
|
|
3502
|
-
else {
|
|
3503
|
-
core[_tempData].set('mode', Mode.NULL);
|
|
3504
|
-
}
|
|
3505
|
-
core[_helper].clearSelectedArea();
|
|
3506
|
-
core[_draw]();
|
|
3507
|
-
}
|
|
3508
|
-
if (core[_tempData].get('mode') !== Mode.SELECT_ELEMENT) {
|
|
3509
|
-
core[_tempData].set('selectedUUID', null);
|
|
3510
|
-
}
|
|
3511
|
-
core[_tempData].set('cursorStatus', CursorStatus.NULL);
|
|
3512
|
-
core[_tempData].set('mode', Mode.NULL);
|
|
3513
|
-
};
|
|
3514
|
-
}
|
|
3515
|
-
function handleHover(core) {
|
|
3516
|
-
return function (point) {
|
|
3517
|
-
var _a, _b;
|
|
3518
|
-
var isMouseOverElement = false;
|
|
3519
|
-
if (core[_tempData].get('mode') === Mode.SELECT_AREA) {
|
|
3520
|
-
if (core[_tempData].get('onlyRender') !== true)
|
|
3521
|
-
core[_board].resetCursor();
|
|
3522
|
-
}
|
|
3523
|
-
else if (core[_tempData].get('cursorStatus') === CursorStatus.NULL) {
|
|
3524
|
-
var _c = core[_mapper].judgePointCursor(point, core[_data]), cursor = _c.cursor, elementUUID = _c.elementUUID;
|
|
3525
|
-
if (core[_tempData].get('onlyRender') !== true)
|
|
3526
|
-
core[_board].setCursor(cursor);
|
|
3527
|
-
if (elementUUID) {
|
|
3528
|
-
var index = core[_helper].getElementIndexByUUID(elementUUID);
|
|
3529
|
-
if (index !== null && index >= 0) {
|
|
3530
|
-
var elem = core[_data].elements[index];
|
|
3531
|
-
if (((_a = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _a === void 0 ? void 0 : _a.lock) === true || ((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.invisible) === true) {
|
|
3532
|
-
core[_board].resetCursor();
|
|
3533
|
-
return;
|
|
3534
|
-
}
|
|
3535
|
-
if (core[_tempData].get('hoverUUID') !== elem.uuid) {
|
|
3536
|
-
var preIndex = core[_helper].getElementIndexByUUID(core[_tempData].get('hoverUUID') || '');
|
|
3537
|
-
if (preIndex !== null && core[_data].elements[preIndex]) {
|
|
3538
|
-
core[_coreEvent].trigger('mouseLeaveElement', {
|
|
3539
|
-
uuid: core[_tempData].get('hoverUUID'),
|
|
3540
|
-
index: preIndex,
|
|
3541
|
-
element: core[_data].elements[preIndex]
|
|
3542
|
-
});
|
|
3543
|
-
}
|
|
3544
|
-
}
|
|
3545
|
-
if (elem) {
|
|
3546
|
-
core[_coreEvent].trigger('mouseOverElement', { uuid: elem.uuid, index: index, element: elem, });
|
|
3547
|
-
core[_tempData].set('hoverUUID', elem.uuid);
|
|
3548
|
-
isMouseOverElement = true;
|
|
3549
|
-
}
|
|
3550
|
-
}
|
|
3551
|
-
}
|
|
3552
|
-
}
|
|
3553
|
-
if (isMouseOverElement !== true && core[_tempData].get('hoverUUID') !== null) {
|
|
3554
|
-
var uuid = core[_tempData].get('hoverUUID');
|
|
3555
|
-
var index = core[_helper].getElementIndexByUUID(uuid || '');
|
|
3556
|
-
if (index !== null)
|
|
3557
|
-
core[_coreEvent].trigger('mouseLeaveElement', { uuid: uuid, index: index, element: core[_data].elements[index] });
|
|
3558
|
-
core[_tempData].set('hoverUUID', null);
|
|
3559
|
-
}
|
|
3560
|
-
if (core[_coreEvent].has('mouseOverScreen'))
|
|
3561
|
-
core[_coreEvent].trigger('mouseOverScreen', point);
|
|
3562
|
-
};
|
|
3563
|
-
}
|
|
3564
|
-
function handleLeave(core) {
|
|
3565
|
-
return function () {
|
|
3566
|
-
if (core[_coreEvent].has('mouseLeaveScreen')) {
|
|
3567
|
-
core[_coreEvent].trigger('mouseLeaveScreen', undefined);
|
|
3568
|
-
}
|
|
3569
|
-
};
|
|
3570
|
-
}
|
|
3571
|
-
function transfromElement(core, uuid, point, prevPoint, direction) {
|
|
3572
|
-
if (!prevPoint) {
|
|
3573
|
-
return null;
|
|
3574
|
-
}
|
|
3575
|
-
var result = core[_element].transformElement(core[_data], uuid, point, prevPoint, core[_board].getContext().getTransform().scale, direction);
|
|
3576
|
-
core[_draw]();
|
|
3577
|
-
return result;
|
|
3578
|
-
}
|
|
3579
|
-
|
|
3580
|
-
var deepClone = index.data.deepClone;
|
|
3581
|
-
var Core = (function () {
|
|
3582
|
-
function Core(mount, opts, config) {
|
|
3583
|
-
var _c, _d, _e;
|
|
3584
|
-
this[_a] = new CoreEvent();
|
|
3585
|
-
this[_b] = new TempData();
|
|
3586
|
-
this[_data] = { elements: [] };
|
|
3587
|
-
this[_opts] = opts;
|
|
3588
|
-
this[_tempData].set('onlyRender', opts.onlyRender === true);
|
|
3589
|
-
this[_config] = mergeConfig(config || {});
|
|
3590
|
-
this[_board] = new Board(mount, __assign$1(__assign$1({}, this[_opts]), { canScroll: (_c = config === null || config === void 0 ? void 0 : config.scrollWrapper) === null || _c === void 0 ? void 0 : _c.use, scrollConfig: {
|
|
3591
|
-
color: ((_d = config === null || config === void 0 ? void 0 : config.scrollWrapper) === null || _d === void 0 ? void 0 : _d.color) || '#a0a0a0',
|
|
3592
|
-
lineWidth: ((_e = config === null || config === void 0 ? void 0 : config.scrollWrapper) === null || _e === void 0 ? void 0 : _e.lineWidth) || 12,
|
|
3593
|
-
} }));
|
|
3594
|
-
this[_renderer] = new Renderer(this[_board]);
|
|
3595
|
-
this[_element] = new Element(this[_board].getContext());
|
|
3596
|
-
this[_helper] = new Helper(this[_board], this[_config]);
|
|
3597
|
-
this[_mapper] = new Mapper({
|
|
3598
|
-
board: this[_board],
|
|
3599
|
-
helper: this[_helper],
|
|
3600
|
-
element: this[_element]
|
|
3601
|
-
});
|
|
3602
|
-
initEvent(this);
|
|
3603
|
-
}
|
|
3604
|
-
Core.prototype[(_a = _coreEvent, _b = _tempData, _draw)] = function (opts) {
|
|
3605
|
-
var _c, _d;
|
|
3606
|
-
var transfrom = this[_board].getTransform();
|
|
3607
|
-
this[_helper].updateConfig(this[_data], {
|
|
3608
|
-
width: this[_opts].width,
|
|
3609
|
-
height: this[_opts].height,
|
|
3610
|
-
canScroll: ((_d = (_c = this[_config]) === null || _c === void 0 ? void 0 : _c.scrollWrapper) === null || _d === void 0 ? void 0 : _d.use) === true,
|
|
3611
|
-
selectedUUID: this[_tempData].get('selectedUUID'),
|
|
3612
|
-
selectedUUIDList: this[_tempData].get('selectedUUIDList'),
|
|
3613
|
-
devicePixelRatio: this[_opts].devicePixelRatio,
|
|
3614
|
-
scale: transfrom.scale,
|
|
3615
|
-
scrollX: transfrom.scrollX,
|
|
3616
|
-
scrollY: transfrom.scrollY,
|
|
3617
|
-
});
|
|
3618
|
-
this[_renderer].render(this[_data], this[_helper].getConfig(), (opts === null || opts === void 0 ? void 0 : opts.resourceChangeUUIDs) || []);
|
|
3619
|
-
};
|
|
3620
|
-
Core.prototype.getElement = function (uuid) {
|
|
3621
|
-
return getElement(this, uuid);
|
|
3622
|
-
};
|
|
3623
|
-
Core.prototype.getElementByIndex = function (index) {
|
|
3624
|
-
return getElementByIndex(this, index);
|
|
3625
|
-
};
|
|
3626
|
-
Core.prototype.selectElementByIndex = function (index, opts) {
|
|
3627
|
-
return selectElementByIndex(this, index, opts);
|
|
3628
|
-
};
|
|
3629
|
-
Core.prototype.selectElement = function (uuid, opts) {
|
|
3630
|
-
return selectElement(this, uuid, opts);
|
|
3631
|
-
};
|
|
3632
|
-
Core.prototype.moveUpElement = function (uuid) {
|
|
3633
|
-
return moveUpElement(this, uuid);
|
|
3634
|
-
};
|
|
3635
|
-
Core.prototype.moveDownElement = function (uuid) {
|
|
3636
|
-
return moveDownElement(this, uuid);
|
|
3637
|
-
};
|
|
3638
|
-
Core.prototype.updateElement = function (elem) {
|
|
3639
|
-
return updateElement(this, elem);
|
|
3640
|
-
};
|
|
3641
|
-
Core.prototype.addElement = function (elem) {
|
|
3642
|
-
return addElement(this, elem);
|
|
3643
|
-
};
|
|
3644
|
-
Core.prototype.deleteElement = function (uuid) {
|
|
3645
|
-
return deleteElement(this, uuid);
|
|
3646
|
-
};
|
|
3647
|
-
Core.prototype.insertElementBefore = function (elem, beforeUUID) {
|
|
3648
|
-
return insertElementBefore(this, elem, beforeUUID);
|
|
3649
|
-
};
|
|
3650
|
-
Core.prototype.insertElementBeforeIndex = function (elem, index) {
|
|
3651
|
-
return insertElementBeforeIndex(this, elem, index);
|
|
3652
|
-
};
|
|
3653
|
-
Core.prototype.getSelectedElements = function () {
|
|
3654
|
-
return getSelectedElements(this);
|
|
3655
|
-
};
|
|
3656
|
-
Core.prototype.insertElementAfter = function (elem, beforeUUID) {
|
|
3657
|
-
return insertElementAfter(this, elem, beforeUUID);
|
|
3658
|
-
};
|
|
3659
|
-
Core.prototype.insertElementAfterIndex = function (elem, index) {
|
|
3660
|
-
return insertElementAfterIndex(this, elem, index);
|
|
3661
|
-
};
|
|
3662
|
-
Core.prototype.resetSize = function (opts) {
|
|
3663
|
-
this[_opts] = __assign$1(__assign$1({}, this[_opts]), opts);
|
|
3664
|
-
this[_board].resetSize(opts);
|
|
3665
|
-
this[_draw]();
|
|
3666
|
-
};
|
|
3667
|
-
Core.prototype.scale = function (ratio) {
|
|
3668
|
-
var screen = this[_board].scale(ratio);
|
|
3669
|
-
this[_draw]();
|
|
3670
|
-
this[_emitChangeScreen]();
|
|
3671
|
-
return screen;
|
|
3672
|
-
};
|
|
3673
|
-
Core.prototype.scrollLeft = function (left) {
|
|
3674
|
-
var screen = this[_board].scrollX(0 - left);
|
|
3675
|
-
this[_draw]();
|
|
3676
|
-
this[_emitChangeScreen]();
|
|
3677
|
-
return screen;
|
|
3678
|
-
};
|
|
3679
|
-
Core.prototype.scrollTop = function (top) {
|
|
3680
|
-
var screen = this[_board].scrollY(0 - top);
|
|
3681
|
-
this[_draw]();
|
|
3682
|
-
this[_emitChangeScreen]();
|
|
3683
|
-
return screen;
|
|
3684
|
-
};
|
|
3685
|
-
Core.prototype.getScreenTransform = function () {
|
|
3686
|
-
var transform = this[_board].getTransform();
|
|
3687
|
-
return {
|
|
3688
|
-
scale: transform.scale,
|
|
3689
|
-
scrollTop: Math.max(0, 0 - transform.scrollY),
|
|
3690
|
-
scrollLeft: Math.max(0, 0 - transform.scrollX),
|
|
3691
|
-
};
|
|
3692
|
-
};
|
|
3693
|
-
Core.prototype.getData = function () {
|
|
3694
|
-
return deepClone(this[_data]);
|
|
3695
|
-
};
|
|
3696
|
-
Core.prototype.setData = function (data, opts) {
|
|
3697
|
-
var resourceChangeUUIDs = diffElementResourceChangeList(this[_data], data);
|
|
3698
|
-
this[_data] = this[_element].initData(deepClone(parseData(data)));
|
|
3699
|
-
if (opts && opts.triggerChangeEvent === true) {
|
|
3700
|
-
this[_emitChangeData]();
|
|
3701
|
-
}
|
|
3702
|
-
this[_draw]({ resourceChangeUUIDs: resourceChangeUUIDs });
|
|
3703
|
-
};
|
|
3704
|
-
Core.prototype.clearOperation = function () {
|
|
3705
|
-
this[_tempData].clear();
|
|
3706
|
-
this[_draw]();
|
|
3707
|
-
};
|
|
3708
|
-
Core.prototype.on = function (key, callback) {
|
|
3709
|
-
this[_coreEvent].on(key, callback);
|
|
3710
|
-
};
|
|
3711
|
-
Core.prototype.off = function (key, callback) {
|
|
3712
|
-
this[_coreEvent].off(key, callback);
|
|
3713
|
-
};
|
|
3714
|
-
Core.prototype.pointScreenToContext = function (p) {
|
|
3715
|
-
return this[_board].pointScreenToContext(p);
|
|
3716
|
-
};
|
|
3717
|
-
Core.prototype.pointContextToScreen = function (p) {
|
|
3718
|
-
return this[_board].pointContextToScreen(p);
|
|
3719
|
-
};
|
|
3720
|
-
Core.prototype.__getBoardContext = function () {
|
|
3721
|
-
return this[_board].getContext();
|
|
3722
|
-
};
|
|
3723
|
-
Core.prototype.__getDisplayContext = function () {
|
|
3724
|
-
return this[_board].getDisplayContext();
|
|
3725
|
-
};
|
|
3726
|
-
Core.prototype.__getOriginContext = function () {
|
|
3727
|
-
return this[_board].getOriginContext();
|
|
3728
|
-
};
|
|
3729
|
-
Core.prototype[_emitChangeScreen] = function () {
|
|
3730
|
-
if (this[_coreEvent].has('changeScreen')) {
|
|
3731
|
-
this[_coreEvent].trigger('changeScreen', __assign$1({}, this.getScreenTransform()));
|
|
3732
|
-
}
|
|
3733
|
-
};
|
|
3734
|
-
Core.prototype[_emitChangeData] = function () {
|
|
3735
|
-
if (this[_coreEvent].has('changeData')) {
|
|
3736
|
-
this[_coreEvent].trigger('changeData', deepClone(this[_data]));
|
|
3737
|
-
}
|
|
3738
|
-
};
|
|
3739
|
-
Core.prototype[_todo] = function () {
|
|
3740
|
-
console.log(this[_mapper]);
|
|
3741
|
-
};
|
|
3742
|
-
var _a, _b;
|
|
3743
|
-
Core.is = is;
|
|
3744
|
-
Core.check = check;
|
|
3745
|
-
return Core;
|
|
3746
|
-
}());
|
|
3747
|
-
|
|
3748
|
-
export { Core as default };
|