@idraw/renderer 0.4.0-beta.3 → 0.4.0-beta.30
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/README.md +2 -2
- package/dist/esm/draw/box.d.ts +14 -3
- package/dist/esm/draw/box.js +82 -34
- package/dist/esm/draw/circle.js +57 -31
- package/dist/esm/draw/elements.js +5 -2
- package/dist/esm/draw/global.d.ts +2 -0
- package/dist/esm/draw/global.js +9 -0
- package/dist/esm/draw/group.js +20 -8
- package/dist/esm/draw/html.js +7 -7
- package/dist/esm/draw/image.js +50 -9
- package/dist/esm/draw/index.d.ts +2 -0
- package/dist/esm/draw/index.js +2 -0
- package/dist/esm/draw/layout.d.ts +2 -0
- package/dist/esm/draw/layout.js +44 -0
- package/dist/esm/draw/path.js +48 -8
- package/dist/esm/draw/rect.js +4 -3
- package/dist/esm/draw/svg.js +7 -7
- package/dist/esm/draw/text.js +123 -66
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +38 -7
- package/dist/esm/loader.d.ts +6 -11
- package/dist/esm/loader.js +120 -83
- package/dist/index.global.js +683 -261
- package/dist/index.global.min.js +1 -1
- package/package.json +3 -3
package/dist/index.global.js
CHANGED
|
@@ -22,7 +22,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
22
22
|
return method;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
var _opts, _loader, _init, init_fn;
|
|
25
|
+
var _loadFuncMap, _currentLoadItemMap, _storageLoadItemMap, _hasDestroyed, _registerLoadFunc, registerLoadFunc_fn, _getLoadElementSource, getLoadElementSource_fn, _createLoadItem, createLoadItem_fn, _emitLoad, emitLoad_fn, _emitError, emitError_fn, _loadResource, loadResource_fn, _isExistingErrorStorage, isExistingErrorStorage_fn, _opts, _loader, _hasDestroyed2, _init, init_fn;
|
|
26
26
|
function isColorStr(color2) {
|
|
27
27
|
return typeof color2 === "string" && (/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color2) || /^[a-z]{1,}$/i.test(color2));
|
|
28
28
|
}
|
|
@@ -100,6 +100,9 @@ var __privateMethod = (obj, member, method) => {
|
|
|
100
100
|
asyncFunction(data) {
|
|
101
101
|
return parsePrototype(data) === "AsyncFunction";
|
|
102
102
|
},
|
|
103
|
+
boolean(data) {
|
|
104
|
+
return parsePrototype(data) === "Boolean";
|
|
105
|
+
},
|
|
103
106
|
string(data) {
|
|
104
107
|
return parsePrototype(data) === "String";
|
|
105
108
|
},
|
|
@@ -333,22 +336,40 @@ var __privateMethod = (obj, member, method) => {
|
|
|
333
336
|
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
334
337
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
335
338
|
});
|
|
339
|
+
var __classPrivateFieldSet = function(receiver, state, value, kind, f) {
|
|
340
|
+
if (kind === "m")
|
|
341
|
+
throw new TypeError("Private method is not writable");
|
|
342
|
+
if (kind === "a" && !f)
|
|
343
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
344
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
345
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
346
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
347
|
+
};
|
|
348
|
+
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
349
|
+
if (kind === "a" && !f)
|
|
350
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
351
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
352
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
353
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
354
|
+
};
|
|
355
|
+
var _EventEmitter_listeners;
|
|
336
356
|
class EventEmitter {
|
|
337
357
|
constructor() {
|
|
338
|
-
this
|
|
358
|
+
_EventEmitter_listeners.set(this, void 0);
|
|
359
|
+
__classPrivateFieldSet(this, _EventEmitter_listeners, /* @__PURE__ */ new Map(), "f");
|
|
339
360
|
}
|
|
340
361
|
on(eventKey, callback) {
|
|
341
|
-
if (this.
|
|
342
|
-
const callbacks = this.
|
|
362
|
+
if (__classPrivateFieldGet(this, _EventEmitter_listeners, "f").has(eventKey)) {
|
|
363
|
+
const callbacks = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(eventKey) || [];
|
|
343
364
|
callbacks === null || callbacks === void 0 ? void 0 : callbacks.push(callback);
|
|
344
|
-
this.
|
|
365
|
+
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(eventKey, callbacks);
|
|
345
366
|
} else {
|
|
346
|
-
this.
|
|
367
|
+
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(eventKey, [callback]);
|
|
347
368
|
}
|
|
348
369
|
}
|
|
349
370
|
off(eventKey, callback) {
|
|
350
|
-
if (this.
|
|
351
|
-
const callbacks = this.
|
|
371
|
+
if (__classPrivateFieldGet(this, _EventEmitter_listeners, "f").has(eventKey)) {
|
|
372
|
+
const callbacks = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(eventKey);
|
|
352
373
|
if (Array.isArray(callbacks)) {
|
|
353
374
|
for (let i = 0; i < (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length); i++) {
|
|
354
375
|
if (callbacks[i] === callback) {
|
|
@@ -357,11 +378,11 @@ var __privateMethod = (obj, member, method) => {
|
|
|
357
378
|
}
|
|
358
379
|
}
|
|
359
380
|
}
|
|
360
|
-
this.
|
|
381
|
+
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(eventKey, callbacks || []);
|
|
361
382
|
}
|
|
362
383
|
}
|
|
363
384
|
trigger(eventKey, e) {
|
|
364
|
-
const callbacks = this.
|
|
385
|
+
const callbacks = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(eventKey);
|
|
365
386
|
if (Array.isArray(callbacks)) {
|
|
366
387
|
callbacks.forEach((cb) => {
|
|
367
388
|
cb(e);
|
|
@@ -372,15 +393,38 @@ var __privateMethod = (obj, member, method) => {
|
|
|
372
393
|
}
|
|
373
394
|
}
|
|
374
395
|
has(name) {
|
|
375
|
-
if (this.
|
|
376
|
-
const list = this.
|
|
396
|
+
if (__classPrivateFieldGet(this, _EventEmitter_listeners, "f").has(name)) {
|
|
397
|
+
const list = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(name);
|
|
377
398
|
if (Array.isArray(list) && list.length > 0) {
|
|
378
399
|
return true;
|
|
379
400
|
}
|
|
380
401
|
}
|
|
381
402
|
return false;
|
|
382
403
|
}
|
|
404
|
+
destroy() {
|
|
405
|
+
this.clear();
|
|
406
|
+
}
|
|
407
|
+
clear() {
|
|
408
|
+
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").clear();
|
|
409
|
+
}
|
|
383
410
|
}
|
|
411
|
+
_EventEmitter_listeners = /* @__PURE__ */ new WeakMap();
|
|
412
|
+
(function(receiver, state, value, kind, f) {
|
|
413
|
+
if (kind === "m")
|
|
414
|
+
throw new TypeError("Private method is not writable");
|
|
415
|
+
if (kind === "a" && !f)
|
|
416
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
417
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
418
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
419
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
420
|
+
});
|
|
421
|
+
(function(receiver, state, kind, f) {
|
|
422
|
+
if (kind === "a" && !f)
|
|
423
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
424
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
425
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
426
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
427
|
+
});
|
|
384
428
|
function parseAngleToRadian(angle2) {
|
|
385
429
|
return angle2 / 180 * Math.PI;
|
|
386
430
|
}
|
|
@@ -411,6 +455,19 @@ var __privateMethod = (obj, member, method) => {
|
|
|
411
455
|
};
|
|
412
456
|
return p;
|
|
413
457
|
}
|
|
458
|
+
function calcViewElementSize(size, opts) {
|
|
459
|
+
const { viewScaleInfo } = opts;
|
|
460
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = size;
|
|
461
|
+
const { scale, offsetTop, offsetLeft } = viewScaleInfo;
|
|
462
|
+
const newSize = {
|
|
463
|
+
x: x2 * scale + offsetLeft,
|
|
464
|
+
y: y2 * scale + offsetTop,
|
|
465
|
+
w: w2 * scale,
|
|
466
|
+
h: h2 * scale,
|
|
467
|
+
angle: angle2
|
|
468
|
+
};
|
|
469
|
+
return newSize;
|
|
470
|
+
}
|
|
414
471
|
function generateSVGPath(commands) {
|
|
415
472
|
let path = "";
|
|
416
473
|
commands.forEach((item) => {
|
|
@@ -434,9 +491,10 @@ var __privateMethod = (obj, member, method) => {
|
|
|
434
491
|
textAlign: "left",
|
|
435
492
|
verticalAlign: "top",
|
|
436
493
|
fontSize: 16,
|
|
437
|
-
lineHeight: 20,
|
|
438
494
|
fontFamily: "sans-serif",
|
|
439
495
|
fontWeight: 400,
|
|
496
|
+
minInlineSize: "auto",
|
|
497
|
+
wordBreak: "break-all",
|
|
440
498
|
overflow: "hidden"
|
|
441
499
|
};
|
|
442
500
|
return config;
|
|
@@ -445,9 +503,10 @@ var __privateMethod = (obj, member, method) => {
|
|
|
445
503
|
function calcViewBoxSize(viewElem, opts) {
|
|
446
504
|
const { viewScaleInfo } = opts;
|
|
447
505
|
const { scale } = viewScaleInfo;
|
|
448
|
-
let { borderRadius: borderRadius2 } = viewElem.detail;
|
|
506
|
+
let { borderRadius: borderRadius2, borderDash } = viewElem.detail;
|
|
507
|
+
const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;
|
|
449
508
|
const { boxSizing = defaultElemConfig$1.boxSizing, borderWidth: borderWidth2 } = viewElem.detail;
|
|
450
|
-
if (
|
|
509
|
+
if (Array.isArray(borderWidth2)) {
|
|
451
510
|
borderRadius2 = 0;
|
|
452
511
|
}
|
|
453
512
|
let { x: x2, y: y2, w: w2, h: h2 } = viewElem;
|
|
@@ -462,7 +521,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
462
521
|
if (typeof borderWidth2 === "number") {
|
|
463
522
|
bw = (borderWidth2 || 0) * scale;
|
|
464
523
|
}
|
|
465
|
-
if (boxSizing === "border-box") {
|
|
524
|
+
if (boxSizing === "border-box" && !hasBorderDash) {
|
|
466
525
|
x2 = viewElem.x + bw / 2;
|
|
467
526
|
y2 = viewElem.y + bw / 2;
|
|
468
527
|
w2 = viewElem.w - bw;
|
|
@@ -491,6 +550,22 @@ var __privateMethod = (obj, member, method) => {
|
|
|
491
550
|
radiusList
|
|
492
551
|
};
|
|
493
552
|
}
|
|
553
|
+
const baseFontFamilyList = ["-apple-system", '"system-ui"', ' "Segoe UI"', " Roboto", '"Helvetica Neue"', "Arial", '"Noto Sans"', " sans-serif"];
|
|
554
|
+
function enhanceFontFamliy(fontFamily2) {
|
|
555
|
+
return [fontFamily2, ...baseFontFamilyList].join(", ");
|
|
556
|
+
}
|
|
557
|
+
(function(s, e) {
|
|
558
|
+
var t = {};
|
|
559
|
+
for (var p in s)
|
|
560
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
561
|
+
t[p] = s[p];
|
|
562
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
563
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
564
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
565
|
+
t[p[i]] = s[p[i]];
|
|
566
|
+
}
|
|
567
|
+
return t;
|
|
568
|
+
});
|
|
494
569
|
function createColorStyle(ctx, color2, opts) {
|
|
495
570
|
if (typeof color2 === "string") {
|
|
496
571
|
return color2;
|
|
@@ -535,30 +610,52 @@ var __privateMethod = (obj, member, method) => {
|
|
|
535
610
|
return "#000000";
|
|
536
611
|
}
|
|
537
612
|
const defaultElemConfig = getDefaultElementDetailConfig();
|
|
613
|
+
function getOpacity(elem) {
|
|
614
|
+
var _a, _b, _c, _d;
|
|
615
|
+
let opacity = 1;
|
|
616
|
+
if (((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.opacity) !== void 0 && ((_b = elem == null ? void 0 : elem.detail) == null ? void 0 : _b.opacity) >= 0 && ((_c = elem == null ? void 0 : elem.detail) == null ? void 0 : _c.opacity) <= 1) {
|
|
617
|
+
opacity = (_d = elem == null ? void 0 : elem.detail) == null ? void 0 : _d.opacity;
|
|
618
|
+
}
|
|
619
|
+
return opacity;
|
|
620
|
+
}
|
|
538
621
|
function drawBox(ctx, viewElem, opts) {
|
|
539
622
|
const { pattern, renderContent, originElem, calcElemSize, viewScaleInfo, viewSizeInfo } = opts || {};
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
623
|
+
const { parentOpacity } = opts;
|
|
624
|
+
const opacity = getOpacity(originElem) * parentOpacity;
|
|
625
|
+
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = originElem.detail;
|
|
626
|
+
const mainRender = () => {
|
|
627
|
+
ctx.globalAlpha = opacity;
|
|
628
|
+
drawBoxBackground(ctx, viewElem, { pattern, viewScaleInfo, viewSizeInfo });
|
|
629
|
+
renderContent == null ? void 0 : renderContent();
|
|
630
|
+
drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
631
|
+
ctx.globalAlpha = parentOpacity;
|
|
632
|
+
};
|
|
633
|
+
if (clipPath) {
|
|
634
|
+
drawClipPath(ctx, viewElem, {
|
|
635
|
+
originElem,
|
|
636
|
+
calcElemSize,
|
|
637
|
+
viewScaleInfo,
|
|
638
|
+
viewSizeInfo,
|
|
639
|
+
renderContent: () => {
|
|
640
|
+
mainRender();
|
|
551
641
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
642
|
+
});
|
|
643
|
+
if (typeof clipPathStrokeWidth === "number" && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
|
|
644
|
+
drawClipPathStroke(ctx, viewElem, {
|
|
645
|
+
originElem,
|
|
646
|
+
calcElemSize,
|
|
647
|
+
viewScaleInfo,
|
|
648
|
+
viewSizeInfo,
|
|
649
|
+
parentOpacity
|
|
650
|
+
});
|
|
556
651
|
}
|
|
557
|
-
}
|
|
652
|
+
} else {
|
|
653
|
+
mainRender();
|
|
654
|
+
}
|
|
558
655
|
}
|
|
559
656
|
function drawClipPath(ctx, viewElem, opts) {
|
|
560
|
-
const { renderContent, originElem, calcElemSize,
|
|
561
|
-
const totalScale =
|
|
657
|
+
const { renderContent, originElem, calcElemSize, viewSizeInfo } = opts;
|
|
658
|
+
const totalScale = viewSizeInfo.devicePixelRatio;
|
|
562
659
|
const { clipPath } = (originElem == null ? void 0 : originElem.detail) || {};
|
|
563
660
|
if (clipPath && calcElemSize && clipPath.commands) {
|
|
564
661
|
const { x: x2, y: y2, w: w2, h: h2 } = calcElemSize;
|
|
@@ -585,12 +682,42 @@ var __privateMethod = (obj, member, method) => {
|
|
|
585
682
|
renderContent == null ? void 0 : renderContent();
|
|
586
683
|
}
|
|
587
684
|
}
|
|
685
|
+
function drawClipPathStroke(ctx, viewElem, opts) {
|
|
686
|
+
const { renderContent, originElem, calcElemSize, viewSizeInfo, parentOpacity } = opts;
|
|
687
|
+
const totalScale = viewSizeInfo.devicePixelRatio;
|
|
688
|
+
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = (originElem == null ? void 0 : originElem.detail) || {};
|
|
689
|
+
if (clipPath && calcElemSize && clipPath.commands && typeof clipPathStrokeWidth === "number" && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
|
|
690
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcElemSize;
|
|
691
|
+
const { originW, originH, originX, originY } = clipPath;
|
|
692
|
+
const scaleW = w2 / originW;
|
|
693
|
+
const scaleH = h2 / originH;
|
|
694
|
+
const viewOriginX = originX * scaleW;
|
|
695
|
+
const viewOriginY = originY * scaleH;
|
|
696
|
+
const internalX = x2 - viewOriginX;
|
|
697
|
+
const internalY = y2 - viewOriginY;
|
|
698
|
+
ctx.save();
|
|
699
|
+
ctx.globalAlpha = parentOpacity;
|
|
700
|
+
ctx.translate(internalX, internalY);
|
|
701
|
+
ctx.scale(totalScale * scaleW, totalScale * scaleH);
|
|
702
|
+
const pathStr = generateSVGPath(clipPath.commands || []);
|
|
703
|
+
const path2d = new Path2D(pathStr);
|
|
704
|
+
ctx.strokeStyle = clipPathStrokeColor;
|
|
705
|
+
ctx.lineWidth = clipPathStrokeWidth;
|
|
706
|
+
ctx.stroke(path2d);
|
|
707
|
+
ctx.translate(0 - internalX, 0 - internalY);
|
|
708
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
709
|
+
rotateElement(ctx, { ...viewElem }, () => {
|
|
710
|
+
renderContent == null ? void 0 : renderContent();
|
|
711
|
+
});
|
|
712
|
+
ctx.restore();
|
|
713
|
+
} else {
|
|
714
|
+
renderContent == null ? void 0 : renderContent();
|
|
715
|
+
}
|
|
716
|
+
}
|
|
588
717
|
function drawBoxBackground(ctx, viewElem, opts) {
|
|
589
718
|
var _a, _b;
|
|
590
719
|
const { pattern, viewScaleInfo, viewSizeInfo } = opts;
|
|
591
720
|
const transform = [];
|
|
592
|
-
viewElem.detail;
|
|
593
|
-
viewElem.detail;
|
|
594
721
|
if (viewElem.detail.background || pattern) {
|
|
595
722
|
const { x: x2, y: y2, w: w2, h: h2, radiusList } = calcViewBoxSize(viewElem, {
|
|
596
723
|
viewScaleInfo,
|
|
@@ -643,18 +770,12 @@ var __privateMethod = (obj, member, method) => {
|
|
|
643
770
|
}
|
|
644
771
|
}
|
|
645
772
|
function drawBoxBorder(ctx, viewElem, opts) {
|
|
646
|
-
var _a, _b;
|
|
647
773
|
if (viewElem.detail.borderWidth === 0) {
|
|
648
774
|
return;
|
|
649
775
|
}
|
|
650
776
|
if (!isColorStr(viewElem.detail.borderColor)) {
|
|
651
777
|
return;
|
|
652
778
|
}
|
|
653
|
-
if (((_a = viewElem == null ? void 0 : viewElem.detail) == null ? void 0 : _a.opacity) !== void 0 && ((_b = viewElem == null ? void 0 : viewElem.detail) == null ? void 0 : _b.opacity) >= 0) {
|
|
654
|
-
ctx.globalAlpha = viewElem.detail.opacity;
|
|
655
|
-
} else {
|
|
656
|
-
ctx.globalAlpha = 1;
|
|
657
|
-
}
|
|
658
779
|
const { viewScaleInfo } = opts;
|
|
659
780
|
const { scale } = viewScaleInfo;
|
|
660
781
|
let borderColor = defaultElemConfig.borderColor;
|
|
@@ -778,7 +899,6 @@ var __privateMethod = (obj, member, method) => {
|
|
|
778
899
|
ctx.arcTo(x2, y2, x2 + w2, y2, radiusList[0]);
|
|
779
900
|
ctx.closePath();
|
|
780
901
|
ctx.stroke();
|
|
781
|
-
ctx.globalAlpha = 1;
|
|
782
902
|
}
|
|
783
903
|
ctx.setLineDash([]);
|
|
784
904
|
}
|
|
@@ -795,58 +915,88 @@ var __privateMethod = (obj, member, method) => {
|
|
|
795
915
|
renderContent();
|
|
796
916
|
ctx.restore();
|
|
797
917
|
} else {
|
|
918
|
+
ctx.save();
|
|
919
|
+
ctx.shadowColor = "transparent";
|
|
920
|
+
ctx.shadowOffsetX = 0;
|
|
921
|
+
ctx.shadowOffsetY = 0;
|
|
922
|
+
ctx.shadowBlur = 0;
|
|
798
923
|
renderContent();
|
|
924
|
+
ctx.restore();
|
|
799
925
|
}
|
|
800
926
|
}
|
|
801
927
|
function drawCircle(ctx, elem, opts) {
|
|
802
928
|
const { detail, angle: angle2 } = elem;
|
|
803
|
-
const {
|
|
804
|
-
const {
|
|
805
|
-
|
|
929
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
930
|
+
const { background = "#000000", borderColor = "#000000", boxSizing, borderWidth: borderWidth2 = 0, borderDash } = detail;
|
|
931
|
+
let bw = 0;
|
|
932
|
+
if (typeof borderWidth2 === "number" && borderWidth2 > 0) {
|
|
933
|
+
bw = borderWidth2;
|
|
934
|
+
} else if (Array.isArray(borderWidth2) && typeof borderWidth2[0] === "number" && borderWidth2[0] > 0) {
|
|
935
|
+
bw = borderWidth2[0];
|
|
936
|
+
}
|
|
937
|
+
bw = bw * viewScaleInfo.scale;
|
|
938
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h }, { viewScaleInfo }) || elem;
|
|
806
939
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
807
940
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
808
941
|
drawBoxShadow(ctx, viewElem, {
|
|
809
942
|
viewScaleInfo,
|
|
810
943
|
viewSizeInfo,
|
|
811
944
|
renderContent: () => {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
const b = h2 / 2;
|
|
945
|
+
let a = w2 / 2;
|
|
946
|
+
let b = h2 / 2;
|
|
815
947
|
const centerX = x2 + a;
|
|
816
948
|
const centerY = y2 + b;
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
949
|
+
const radiusA = a;
|
|
950
|
+
const radiusB = b;
|
|
951
|
+
if (bw > 0) {
|
|
952
|
+
if (boxSizing === "content-box") {
|
|
953
|
+
a = a;
|
|
954
|
+
b = b;
|
|
955
|
+
} else if (boxSizing === "center-line") {
|
|
956
|
+
a = a - bw / 2;
|
|
957
|
+
b = b - bw / 2;
|
|
958
|
+
} else {
|
|
959
|
+
a = a - bw;
|
|
960
|
+
b = b - bw;
|
|
961
|
+
}
|
|
821
962
|
}
|
|
822
|
-
if (
|
|
823
|
-
const
|
|
824
|
-
|
|
963
|
+
if (a >= 0 && b >= 0) {
|
|
964
|
+
const opacity = getOpacity(viewElem) * parentOpacity;
|
|
965
|
+
ctx.globalAlpha = opacity;
|
|
825
966
|
ctx.beginPath();
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
967
|
+
const fillStyle = createColorStyle(ctx, background, {
|
|
968
|
+
viewElementSize: { x: x2, y: y2, w: w2, h: h2 },
|
|
969
|
+
viewScaleInfo,
|
|
970
|
+
opacity: ctx.globalAlpha
|
|
971
|
+
});
|
|
972
|
+
ctx.fillStyle = fillStyle;
|
|
973
|
+
ctx.circle(centerX, centerY, radiusA, radiusB, 0, 0, 2 * Math.PI);
|
|
829
974
|
ctx.closePath();
|
|
830
|
-
ctx.
|
|
975
|
+
ctx.fill();
|
|
976
|
+
ctx.globalAlpha = parentOpacity;
|
|
977
|
+
if (typeof bw === "number" && bw > 0) {
|
|
978
|
+
const ba = bw / 2 + a;
|
|
979
|
+
const bb = bw / 2 + b;
|
|
980
|
+
ctx.beginPath();
|
|
981
|
+
if (borderDash) {
|
|
982
|
+
const lineDash = borderDash.map((n) => n * viewScaleInfo.scale);
|
|
983
|
+
ctx.setLineDash(lineDash);
|
|
984
|
+
}
|
|
985
|
+
ctx.strokeStyle = borderColor;
|
|
986
|
+
ctx.lineWidth = bw;
|
|
987
|
+
ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI);
|
|
988
|
+
ctx.closePath();
|
|
989
|
+
ctx.stroke();
|
|
990
|
+
ctx.setLineDash([]);
|
|
991
|
+
}
|
|
831
992
|
}
|
|
832
|
-
ctx.beginPath();
|
|
833
|
-
const fillStyle = createColorStyle(ctx, background, {
|
|
834
|
-
viewElementSize: { x: x2, y: y2, w: w2, h: h2 },
|
|
835
|
-
viewScaleInfo,
|
|
836
|
-
opacity: ctx.globalAlpha
|
|
837
|
-
});
|
|
838
|
-
ctx.fillStyle = fillStyle;
|
|
839
|
-
ctx.circle(centerX, centerY, a, b, 0, 0, 2 * Math.PI);
|
|
840
|
-
ctx.closePath();
|
|
841
|
-
ctx.fill();
|
|
842
|
-
ctx.globalAlpha = 1;
|
|
843
993
|
}
|
|
844
994
|
});
|
|
845
995
|
});
|
|
846
996
|
}
|
|
847
997
|
function drawRect(ctx, elem, opts) {
|
|
848
|
-
const {
|
|
849
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
998
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
999
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
850
1000
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
851
1001
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
852
1002
|
drawBoxShadow(ctx, viewElem, {
|
|
@@ -858,6 +1008,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
858
1008
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
859
1009
|
viewScaleInfo,
|
|
860
1010
|
viewSizeInfo,
|
|
1011
|
+
parentOpacity,
|
|
861
1012
|
renderContent: () => {
|
|
862
1013
|
}
|
|
863
1014
|
});
|
|
@@ -867,8 +1018,8 @@ var __privateMethod = (obj, member, method) => {
|
|
|
867
1018
|
}
|
|
868
1019
|
function drawImage(ctx, elem, opts) {
|
|
869
1020
|
const content = opts.loader.getContent(elem);
|
|
870
|
-
const {
|
|
871
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1021
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1022
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
872
1023
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
873
1024
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
874
1025
|
drawBoxShadow(ctx, viewElem, {
|
|
@@ -880,17 +1031,21 @@ var __privateMethod = (obj, member, method) => {
|
|
|
880
1031
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
881
1032
|
viewScaleInfo,
|
|
882
1033
|
viewSizeInfo,
|
|
1034
|
+
parentOpacity,
|
|
883
1035
|
renderContent: () => {
|
|
884
|
-
if (!content) {
|
|
1036
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
885
1037
|
opts.loader.load(elem, opts.elementAssets || {});
|
|
886
1038
|
}
|
|
887
1039
|
if (elem.type === "image" && content) {
|
|
888
|
-
|
|
889
|
-
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1040
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
890
1041
|
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem, {
|
|
891
1042
|
viewScaleInfo,
|
|
892
1043
|
viewSizeInfo
|
|
893
1044
|
});
|
|
1045
|
+
const { detail } = elem;
|
|
1046
|
+
const { scaleMode, originW = 0, originH = 0 } = detail;
|
|
1047
|
+
const imageW = ctx.$undoPixelRatio(originW);
|
|
1048
|
+
const imageH = ctx.$undoPixelRatio(originH);
|
|
894
1049
|
ctx.save();
|
|
895
1050
|
ctx.fillStyle = "transparent";
|
|
896
1051
|
ctx.beginPath();
|
|
@@ -902,8 +1057,42 @@ var __privateMethod = (obj, member, method) => {
|
|
|
902
1057
|
ctx.closePath();
|
|
903
1058
|
ctx.fill();
|
|
904
1059
|
ctx.clip();
|
|
905
|
-
|
|
906
|
-
|
|
1060
|
+
if (scaleMode && originH && originW) {
|
|
1061
|
+
let sx = 0;
|
|
1062
|
+
let sy = 0;
|
|
1063
|
+
let sWidth = imageW;
|
|
1064
|
+
let sHeight = imageH;
|
|
1065
|
+
const dx = x22;
|
|
1066
|
+
const dy = y22;
|
|
1067
|
+
const dWidth = w22;
|
|
1068
|
+
const dHeight = h22;
|
|
1069
|
+
if (imageW > elem.w || imageH > elem.h) {
|
|
1070
|
+
if (scaleMode === "fill") {
|
|
1071
|
+
const sourceScale = Math.max(elem.w / imageW, elem.h / imageH);
|
|
1072
|
+
const newImageWidth = imageW * sourceScale;
|
|
1073
|
+
const newImageHeight = imageH * sourceScale;
|
|
1074
|
+
sx = (newImageWidth - elem.w) / 2 / sourceScale;
|
|
1075
|
+
sy = (newImageHeight - elem.h) / 2 / sourceScale;
|
|
1076
|
+
sWidth = elem.w / sourceScale;
|
|
1077
|
+
sHeight = elem.h / sourceScale;
|
|
1078
|
+
} else if (scaleMode === "tile") {
|
|
1079
|
+
sx = 0;
|
|
1080
|
+
sy = 0;
|
|
1081
|
+
sWidth = elem.w;
|
|
1082
|
+
sHeight = elem.h;
|
|
1083
|
+
} else if (scaleMode === "fit") {
|
|
1084
|
+
const sourceScale = Math.min(elem.w / imageW, elem.h / imageH);
|
|
1085
|
+
sx = (imageW - elem.w / sourceScale) / 2;
|
|
1086
|
+
sy = (imageH - elem.h / sourceScale) / 2;
|
|
1087
|
+
sWidth = elem.w / sourceScale;
|
|
1088
|
+
sHeight = elem.h / sourceScale;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
ctx.drawImage(content, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
|
|
1092
|
+
} else {
|
|
1093
|
+
ctx.drawImage(content, x22, y22, w22, h22);
|
|
1094
|
+
}
|
|
1095
|
+
ctx.globalAlpha = parentOpacity;
|
|
907
1096
|
ctx.restore();
|
|
908
1097
|
}
|
|
909
1098
|
}
|
|
@@ -914,85 +1103,133 @@ var __privateMethod = (obj, member, method) => {
|
|
|
914
1103
|
}
|
|
915
1104
|
function drawSVG(ctx, elem, opts) {
|
|
916
1105
|
const content = opts.loader.getContent(elem);
|
|
917
|
-
const {
|
|
918
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1106
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1107
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
|
|
919
1108
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
920
|
-
if (!content) {
|
|
1109
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
921
1110
|
opts.loader.load(elem, opts.elementAssets || {});
|
|
922
1111
|
}
|
|
923
1112
|
if (elem.type === "svg" && content) {
|
|
924
|
-
|
|
925
|
-
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1113
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
926
1114
|
ctx.drawImage(content, x2, y2, w2, h2);
|
|
927
|
-
ctx.globalAlpha =
|
|
1115
|
+
ctx.globalAlpha = parentOpacity;
|
|
928
1116
|
}
|
|
929
1117
|
});
|
|
930
1118
|
}
|
|
931
1119
|
function drawHTML(ctx, elem, opts) {
|
|
932
1120
|
const content = opts.loader.getContent(elem);
|
|
933
|
-
const {
|
|
934
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1121
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1122
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
|
|
935
1123
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
936
|
-
if (!content) {
|
|
1124
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
937
1125
|
opts.loader.load(elem, opts.elementAssets || {});
|
|
938
1126
|
}
|
|
939
1127
|
if (elem.type === "html" && content) {
|
|
940
|
-
|
|
941
|
-
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1128
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
942
1129
|
ctx.drawImage(content, x2, y2, w2, h2);
|
|
943
|
-
ctx.globalAlpha =
|
|
1130
|
+
ctx.globalAlpha = parentOpacity;
|
|
944
1131
|
}
|
|
945
1132
|
});
|
|
946
1133
|
}
|
|
947
1134
|
const detailConfig = getDefaultElementDetailConfig();
|
|
1135
|
+
function isTextWidthWithinErrorRange(w0, w1, scale) {
|
|
1136
|
+
if (scale < 0.5) {
|
|
1137
|
+
if (w0 < w1 && (w0 - w1) / w0 > -0.15) {
|
|
1138
|
+
return true;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
return w0 >= w1;
|
|
1142
|
+
}
|
|
948
1143
|
function drawText(ctx, elem, opts) {
|
|
949
|
-
const {
|
|
950
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1144
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1145
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
951
1146
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
952
1147
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
953
|
-
|
|
954
|
-
originElem: elem,
|
|
955
|
-
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1148
|
+
drawBoxShadow(ctx, viewElem, {
|
|
956
1149
|
viewScaleInfo,
|
|
957
1150
|
viewSizeInfo,
|
|
958
1151
|
renderContent: () => {
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
ctx.fillStyle = elem.detail.color || detailConfig.color;
|
|
966
|
-
ctx.textBaseline = "top";
|
|
967
|
-
ctx.$setFont({
|
|
968
|
-
fontWeight: detail.fontWeight,
|
|
969
|
-
fontSize: fontSize2,
|
|
970
|
-
fontFamily: detail.fontFamily
|
|
1152
|
+
drawBox(ctx, viewElem, {
|
|
1153
|
+
originElem: elem,
|
|
1154
|
+
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1155
|
+
viewScaleInfo,
|
|
1156
|
+
viewSizeInfo,
|
|
1157
|
+
parentOpacity
|
|
971
1158
|
});
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1159
|
+
}
|
|
1160
|
+
});
|
|
1161
|
+
{
|
|
1162
|
+
const detail = {
|
|
1163
|
+
...detailConfig,
|
|
1164
|
+
...elem.detail
|
|
1165
|
+
};
|
|
1166
|
+
const originFontSize = detail.fontSize || detailConfig.fontSize;
|
|
1167
|
+
const fontSize2 = originFontSize * viewScaleInfo.scale;
|
|
1168
|
+
if (fontSize2 < 2) {
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
const originLineHeight = detail.lineHeight || originFontSize;
|
|
1172
|
+
const lineHeight2 = originLineHeight * viewScaleInfo.scale;
|
|
1173
|
+
ctx.fillStyle = elem.detail.color || detailConfig.color;
|
|
1174
|
+
ctx.textBaseline = "top";
|
|
1175
|
+
ctx.$setFont({
|
|
1176
|
+
fontWeight: detail.fontWeight,
|
|
1177
|
+
fontSize: fontSize2,
|
|
1178
|
+
fontFamily: enhanceFontFamliy(detail.fontFamily)
|
|
1179
|
+
});
|
|
1180
|
+
let detailText = detail.text.replace(/\r\n/gi, "\n");
|
|
1181
|
+
if (detail.textTransform === "lowercase") {
|
|
1182
|
+
detailText = detailText.toLowerCase();
|
|
1183
|
+
} else if (detail.textTransform === "uppercase") {
|
|
1184
|
+
detailText = detailText.toUpperCase();
|
|
1185
|
+
}
|
|
1186
|
+
const fontHeight = lineHeight2;
|
|
1187
|
+
const detailTextList = detailText.split("\n");
|
|
1188
|
+
const lines = [];
|
|
1189
|
+
let lineNum = 0;
|
|
1190
|
+
detailTextList.forEach((itemText, idx) => {
|
|
1191
|
+
if (detail.minInlineSize === "maxContent") {
|
|
1192
|
+
lines.push({
|
|
1193
|
+
text: itemText,
|
|
1194
|
+
width: ctx.$undoPixelRatio(ctx.measureText(itemText).width)
|
|
1195
|
+
});
|
|
1196
|
+
} else {
|
|
978
1197
|
let lineText = "";
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1198
|
+
let splitStr = "";
|
|
1199
|
+
let tempStrList = itemText.split(splitStr);
|
|
1200
|
+
if (detail.wordBreak === "normal") {
|
|
1201
|
+
const splitStr2 = " ";
|
|
1202
|
+
const wordList = itemText.split(splitStr2);
|
|
1203
|
+
tempStrList = [];
|
|
1204
|
+
wordList.forEach((word, idx2) => {
|
|
1205
|
+
tempStrList.push(word);
|
|
1206
|
+
if (idx2 < wordList.length - 1) {
|
|
1207
|
+
tempStrList.push(splitStr2);
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
if (tempStrList.length === 1 && detail.overflow === "visible") {
|
|
1212
|
+
lines.push({
|
|
1213
|
+
text: tempStrList[0],
|
|
1214
|
+
width: ctx.$undoPixelRatio(ctx.measureText(tempStrList[0]).width)
|
|
1215
|
+
});
|
|
1216
|
+
} else if (tempStrList.length > 0) {
|
|
1217
|
+
for (let i = 0; i < tempStrList.length; i++) {
|
|
1218
|
+
if (isTextWidthWithinErrorRange(ctx.$doPixelRatio(w2), ctx.measureText(lineText + tempStrList[i]).width, viewScaleInfo.scale)) {
|
|
1219
|
+
lineText += tempStrList[i] || "";
|
|
983
1220
|
} else {
|
|
984
1221
|
lines.push({
|
|
985
1222
|
text: lineText,
|
|
986
1223
|
width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
|
|
987
1224
|
});
|
|
988
|
-
lineText =
|
|
1225
|
+
lineText = tempStrList[i] || "";
|
|
989
1226
|
lineNum++;
|
|
990
1227
|
}
|
|
991
|
-
if ((lineNum + 1) * fontHeight > h2) {
|
|
1228
|
+
if ((lineNum + 1) * fontHeight > h2 && detail.overflow === "hidden") {
|
|
992
1229
|
break;
|
|
993
1230
|
}
|
|
994
|
-
if (
|
|
995
|
-
if ((lineNum + 1) * fontHeight
|
|
1231
|
+
if (tempStrList.length - 1 === i) {
|
|
1232
|
+
if ((lineNum + 1) * fontHeight <= h2) {
|
|
996
1233
|
lines.push({
|
|
997
1234
|
text: lineText,
|
|
998
1235
|
width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
|
|
@@ -1010,64 +1247,96 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1010
1247
|
width: 0
|
|
1011
1248
|
});
|
|
1012
1249
|
}
|
|
1013
|
-
});
|
|
1014
|
-
let startY = 0;
|
|
1015
|
-
if (lines.length * fontHeight < h2) {
|
|
1016
|
-
if (elem.detail.verticalAlign === "top") {
|
|
1017
|
-
startY = 0;
|
|
1018
|
-
} else if (elem.detail.verticalAlign === "bottom") {
|
|
1019
|
-
startY += h2 - lines.length * fontHeight;
|
|
1020
|
-
} else {
|
|
1021
|
-
startY += (h2 - lines.length * fontHeight) / 2;
|
|
1022
|
-
}
|
|
1023
1250
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
}
|
|
1038
|
-
lines.forEach((line, i) => {
|
|
1039
|
-
let _x = x2;
|
|
1040
|
-
if (detail.textAlign === "center") {
|
|
1041
|
-
_x = x2 + (w2 - line.width) / 2;
|
|
1042
|
-
} else if (detail.textAlign === "right") {
|
|
1043
|
-
_x = x2 + (w2 - line.width);
|
|
1044
|
-
}
|
|
1045
|
-
ctx.fillText(line.text, _x, _y + fontHeight * i);
|
|
1046
|
-
});
|
|
1251
|
+
});
|
|
1252
|
+
let startY = 0;
|
|
1253
|
+
let eachLineStartY = 0;
|
|
1254
|
+
if (fontHeight > fontSize2) {
|
|
1255
|
+
eachLineStartY = (fontHeight - fontSize2) / 2;
|
|
1256
|
+
}
|
|
1257
|
+
if (lines.length * fontHeight < h2) {
|
|
1258
|
+
if (elem.detail.verticalAlign === "top") {
|
|
1259
|
+
startY = 0;
|
|
1260
|
+
} else if (elem.detail.verticalAlign === "bottom") {
|
|
1261
|
+
startY += h2 - lines.length * fontHeight;
|
|
1262
|
+
} else {
|
|
1263
|
+
startY += (h2 - lines.length * fontHeight) / 2;
|
|
1047
1264
|
}
|
|
1048
1265
|
}
|
|
1049
|
-
|
|
1266
|
+
{
|
|
1267
|
+
const _y = y2 + startY;
|
|
1268
|
+
if (detail.textShadowColor !== void 0 && isColorStr(detail.textShadowColor)) {
|
|
1269
|
+
ctx.shadowColor = detail.textShadowColor;
|
|
1270
|
+
}
|
|
1271
|
+
if (detail.textShadowOffsetX !== void 0 && is.number(detail.textShadowOffsetX)) {
|
|
1272
|
+
ctx.shadowOffsetX = detail.textShadowOffsetX;
|
|
1273
|
+
}
|
|
1274
|
+
if (detail.textShadowOffsetY !== void 0 && is.number(detail.textShadowOffsetY)) {
|
|
1275
|
+
ctx.shadowOffsetY = detail.textShadowOffsetY;
|
|
1276
|
+
}
|
|
1277
|
+
if (detail.textShadowBlur !== void 0 && is.number(detail.textShadowBlur)) {
|
|
1278
|
+
ctx.shadowBlur = detail.textShadowBlur;
|
|
1279
|
+
}
|
|
1280
|
+
lines.forEach((line, i) => {
|
|
1281
|
+
let _x = x2;
|
|
1282
|
+
if (detail.textAlign === "center") {
|
|
1283
|
+
_x = x2 + (w2 - line.width) / 2;
|
|
1284
|
+
} else if (detail.textAlign === "right") {
|
|
1285
|
+
_x = x2 + (w2 - line.width);
|
|
1286
|
+
}
|
|
1287
|
+
ctx.fillText(line.text, _x, _y + fontHeight * i + eachLineStartY);
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1050
1291
|
});
|
|
1051
1292
|
}
|
|
1052
1293
|
function drawPath(ctx, elem, opts) {
|
|
1294
|
+
var _a, _b;
|
|
1053
1295
|
const { detail } = elem;
|
|
1054
|
-
const { originX, originY, originW, originH } = detail;
|
|
1055
|
-
const {
|
|
1056
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1296
|
+
const { originX, originY, originW, originH, fillRule } = detail;
|
|
1297
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1298
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
1057
1299
|
const scaleW = w2 / originW;
|
|
1058
1300
|
const scaleH = h2 / originH;
|
|
1059
1301
|
const viewOriginX = originX * scaleW;
|
|
1060
1302
|
const viewOriginY = originY * scaleH;
|
|
1061
1303
|
const internalX = x2 - viewOriginX;
|
|
1062
1304
|
const internalY = y2 - viewOriginY;
|
|
1305
|
+
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth, ...restDetail } = elem.detail;
|
|
1063
1306
|
const scaleNum = viewScaleInfo.scale * viewSizeInfo.devicePixelRatio;
|
|
1064
1307
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1308
|
+
let boxViewElem = { ...viewElem };
|
|
1309
|
+
boxViewElem.detail = restDetail;
|
|
1310
|
+
let boxOriginElem = { ...elem };
|
|
1311
|
+
boxOriginElem.detail = restDetail;
|
|
1312
|
+
if (detail.fill && detail.fill !== "string" && ((_b = (_a = detail.fill) == null ? void 0 : _a.type) == null ? void 0 : _b.includes("gradient"))) {
|
|
1313
|
+
boxViewElem = {
|
|
1314
|
+
...viewElem,
|
|
1315
|
+
...{
|
|
1316
|
+
detail: {
|
|
1317
|
+
...viewElem.detail,
|
|
1318
|
+
...{
|
|
1319
|
+
background: detail.fill,
|
|
1320
|
+
clipPath: {
|
|
1321
|
+
commands: detail.commands,
|
|
1322
|
+
originX,
|
|
1323
|
+
originY,
|
|
1324
|
+
originW,
|
|
1325
|
+
originH
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
};
|
|
1331
|
+
boxOriginElem.detail = { ...boxViewElem.detail };
|
|
1332
|
+
}
|
|
1065
1333
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
1066
|
-
drawBox(ctx,
|
|
1067
|
-
originElem:
|
|
1334
|
+
drawBox(ctx, boxViewElem, {
|
|
1335
|
+
originElem: boxOriginElem,
|
|
1068
1336
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1069
1337
|
viewScaleInfo,
|
|
1070
1338
|
viewSizeInfo,
|
|
1339
|
+
parentOpacity,
|
|
1071
1340
|
renderContent: () => {
|
|
1072
1341
|
drawBoxShadow(ctx, viewElem, {
|
|
1073
1342
|
viewScaleInfo,
|
|
@@ -1079,8 +1348,14 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1079
1348
|
const pathStr = generateSVGPath(detail.commands || []);
|
|
1080
1349
|
const path2d = new Path2D(pathStr);
|
|
1081
1350
|
if (detail.fill) {
|
|
1082
|
-
|
|
1083
|
-
|
|
1351
|
+
if (typeof detail.fill === "string") {
|
|
1352
|
+
ctx.fillStyle = detail.fill;
|
|
1353
|
+
} else {
|
|
1354
|
+
ctx.fillStyle = "transparent";
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
if (detail.fill) {
|
|
1358
|
+
ctx.fill(path2d, fillRule);
|
|
1084
1359
|
}
|
|
1085
1360
|
if (detail.stroke && detail.strokeWidth !== 0) {
|
|
1086
1361
|
ctx.strokeStyle = detail.stroke;
|
|
@@ -1096,11 +1371,21 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1096
1371
|
});
|
|
1097
1372
|
});
|
|
1098
1373
|
}
|
|
1374
|
+
const visiableMinSize = 0.4;
|
|
1099
1375
|
function drawElement(ctx, elem, opts) {
|
|
1100
|
-
var _a;
|
|
1376
|
+
var _a, _b, _c;
|
|
1101
1377
|
if (((_a = elem == null ? void 0 : elem.operations) == null ? void 0 : _a.invisible) === true) {
|
|
1102
1378
|
return;
|
|
1103
1379
|
}
|
|
1380
|
+
const { w: w2, h: h2 } = elem;
|
|
1381
|
+
const { scale } = opts.viewScaleInfo;
|
|
1382
|
+
if (scale < 1 && (w2 * scale < visiableMinSize || h2 * scale < visiableMinSize) || opts.parentOpacity === 0) {
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
const { overrideElementMap } = opts;
|
|
1386
|
+
if ((_c = (_b = overrideElementMap == null ? void 0 : overrideElementMap[elem.uuid]) == null ? void 0 : _b.operations) == null ? void 0 : _c.invisible) {
|
|
1387
|
+
return;
|
|
1388
|
+
}
|
|
1104
1389
|
try {
|
|
1105
1390
|
switch (elem.type) {
|
|
1106
1391
|
case "rect": {
|
|
@@ -1151,10 +1436,11 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1151
1436
|
}
|
|
1152
1437
|
}
|
|
1153
1438
|
function drawGroup(ctx, elem, opts) {
|
|
1154
|
-
const {
|
|
1155
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1439
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1440
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, { viewScaleInfo }) || elem;
|
|
1156
1441
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1157
1442
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
1443
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
1158
1444
|
drawBoxShadow(ctx, viewElem, {
|
|
1159
1445
|
viewScaleInfo,
|
|
1160
1446
|
viewSizeInfo,
|
|
@@ -1164,6 +1450,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1164
1450
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1165
1451
|
viewScaleInfo,
|
|
1166
1452
|
viewSizeInfo,
|
|
1453
|
+
parentOpacity,
|
|
1167
1454
|
renderContent: () => {
|
|
1168
1455
|
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem, {
|
|
1169
1456
|
viewScaleInfo,
|
|
@@ -1191,7 +1478,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1191
1478
|
h: elem.h || parentSize.h,
|
|
1192
1479
|
angle: elem.angle
|
|
1193
1480
|
};
|
|
1194
|
-
const { calculator
|
|
1481
|
+
const { calculator } = opts;
|
|
1195
1482
|
for (let i = 0; i < elem.detail.children.length; i++) {
|
|
1196
1483
|
let child = elem.detail.children[i];
|
|
1197
1484
|
child = {
|
|
@@ -1202,31 +1489,32 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1202
1489
|
}
|
|
1203
1490
|
};
|
|
1204
1491
|
if (opts.forceDrawAll !== true) {
|
|
1205
|
-
if (!(
|
|
1492
|
+
if (!(calculator == null ? void 0 : calculator.needRender(child))) {
|
|
1206
1493
|
continue;
|
|
1207
1494
|
}
|
|
1208
1495
|
}
|
|
1209
1496
|
try {
|
|
1210
|
-
drawElement(ctx, child, { ...opts });
|
|
1497
|
+
drawElement(ctx, child, { ...opts, ...{ parentOpacity: parentOpacity * getOpacity(elem) } });
|
|
1211
1498
|
} catch (err) {
|
|
1212
1499
|
console.error(err);
|
|
1213
1500
|
}
|
|
1214
1501
|
}
|
|
1215
1502
|
}
|
|
1216
1503
|
if (elem.detail.overflow === "hidden") {
|
|
1217
|
-
ctx.globalAlpha = 1;
|
|
1218
1504
|
ctx.restore();
|
|
1219
1505
|
}
|
|
1220
1506
|
}
|
|
1221
1507
|
});
|
|
1222
1508
|
}
|
|
1223
1509
|
});
|
|
1510
|
+
ctx.globalAlpha = parentOpacity;
|
|
1224
1511
|
});
|
|
1225
1512
|
}
|
|
1226
1513
|
const defaultDetail = getDefaultElementDetailConfig();
|
|
1227
1514
|
function drawElementList(ctx, data, opts) {
|
|
1228
1515
|
var _a;
|
|
1229
1516
|
const { elements = [] } = data;
|
|
1517
|
+
const { parentOpacity } = opts;
|
|
1230
1518
|
for (let i = 0; i < elements.length; i++) {
|
|
1231
1519
|
const element = elements[i];
|
|
1232
1520
|
const elem = {
|
|
@@ -1239,17 +1527,73 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1239
1527
|
}
|
|
1240
1528
|
};
|
|
1241
1529
|
if (opts.forceDrawAll !== true) {
|
|
1242
|
-
if (!((_a = opts.calculator) == null ? void 0 : _a.
|
|
1530
|
+
if (!((_a = opts.calculator) == null ? void 0 : _a.needRender(elem))) {
|
|
1243
1531
|
continue;
|
|
1244
1532
|
}
|
|
1245
1533
|
}
|
|
1246
1534
|
try {
|
|
1247
|
-
drawElement(ctx, elem,
|
|
1535
|
+
drawElement(ctx, elem, {
|
|
1536
|
+
...opts,
|
|
1537
|
+
...{
|
|
1538
|
+
parentOpacity
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1248
1541
|
} catch (err) {
|
|
1249
1542
|
console.error(err);
|
|
1250
1543
|
}
|
|
1251
1544
|
}
|
|
1252
1545
|
}
|
|
1546
|
+
function drawLayout(ctx, layout, opts, renderContent) {
|
|
1547
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1548
|
+
const elem = { uuid: "layout", type: "group", ...layout };
|
|
1549
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
1550
|
+
const angle2 = 0;
|
|
1551
|
+
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1552
|
+
ctx.globalAlpha = 1;
|
|
1553
|
+
drawBoxShadow(ctx, viewElem, {
|
|
1554
|
+
viewScaleInfo,
|
|
1555
|
+
viewSizeInfo,
|
|
1556
|
+
renderContent: () => {
|
|
1557
|
+
drawBoxBackground(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
if (layout.detail.overflow === "hidden") {
|
|
1561
|
+
const { viewScaleInfo: viewScaleInfo2, viewSizeInfo: viewSizeInfo2 } = opts;
|
|
1562
|
+
const elem2 = { uuid: "layout", type: "group", ...layout };
|
|
1563
|
+
const viewElemSize = calcViewElementSize(elem2, { viewScaleInfo: viewScaleInfo2 }) || elem2;
|
|
1564
|
+
const viewElem2 = { ...elem2, ...viewElemSize };
|
|
1565
|
+
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem2, {
|
|
1566
|
+
viewScaleInfo: viewScaleInfo2,
|
|
1567
|
+
viewSizeInfo: viewSizeInfo2
|
|
1568
|
+
});
|
|
1569
|
+
ctx.save();
|
|
1570
|
+
ctx.fillStyle = "transparent";
|
|
1571
|
+
ctx.beginPath();
|
|
1572
|
+
ctx.moveTo(x22 + radiusList[0], y22);
|
|
1573
|
+
ctx.arcTo(x22 + w22, y22, x22 + w22, y22 + h22, radiusList[1]);
|
|
1574
|
+
ctx.arcTo(x22 + w22, y22 + h22, x22, y22 + h22, radiusList[2]);
|
|
1575
|
+
ctx.arcTo(x22, y22 + h22, x22, y22, radiusList[3]);
|
|
1576
|
+
ctx.arcTo(x22, y22, x22 + w22, y22, radiusList[0]);
|
|
1577
|
+
ctx.closePath();
|
|
1578
|
+
ctx.fill();
|
|
1579
|
+
ctx.clip();
|
|
1580
|
+
}
|
|
1581
|
+
renderContent(ctx);
|
|
1582
|
+
if (layout.detail.overflow === "hidden") {
|
|
1583
|
+
ctx.restore();
|
|
1584
|
+
}
|
|
1585
|
+
drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
1586
|
+
ctx.globalAlpha = parentOpacity;
|
|
1587
|
+
}
|
|
1588
|
+
function drawGlobalBackground(ctx, global, opts) {
|
|
1589
|
+
if (typeof (global == null ? void 0 : global.background) === "string") {
|
|
1590
|
+
const { viewSizeInfo } = opts;
|
|
1591
|
+
const { width, height } = viewSizeInfo;
|
|
1592
|
+
ctx.globalAlpha = 1;
|
|
1593
|
+
ctx.fillStyle = global.background;
|
|
1594
|
+
ctx.fillRect(0, 0, width, height);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1253
1597
|
const supportElementTypes = ["image", "svg", "html"];
|
|
1254
1598
|
const getAssetIdFromElement = (element) => {
|
|
1255
1599
|
var _a, _b, _c;
|
|
@@ -1272,10 +1616,18 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1272
1616
|
class Loader extends EventEmitter {
|
|
1273
1617
|
constructor() {
|
|
1274
1618
|
super();
|
|
1275
|
-
this
|
|
1276
|
-
this
|
|
1277
|
-
this
|
|
1278
|
-
this
|
|
1619
|
+
__privateAdd(this, _registerLoadFunc);
|
|
1620
|
+
__privateAdd(this, _getLoadElementSource);
|
|
1621
|
+
__privateAdd(this, _createLoadItem);
|
|
1622
|
+
__privateAdd(this, _emitLoad);
|
|
1623
|
+
__privateAdd(this, _emitError);
|
|
1624
|
+
__privateAdd(this, _loadResource);
|
|
1625
|
+
__privateAdd(this, _isExistingErrorStorage);
|
|
1626
|
+
__privateAdd(this, _loadFuncMap, {});
|
|
1627
|
+
__privateAdd(this, _currentLoadItemMap, {});
|
|
1628
|
+
__privateAdd(this, _storageLoadItemMap, {});
|
|
1629
|
+
__privateAdd(this, _hasDestroyed, false);
|
|
1630
|
+
__privateMethod(this, _registerLoadFunc, registerLoadFunc_fn).call(this, "image", async (elem, assets) => {
|
|
1279
1631
|
var _a;
|
|
1280
1632
|
const src = ((_a = assets[elem.detail.src]) == null ? void 0 : _a.value) || elem.detail.src;
|
|
1281
1633
|
const content = await loadImage(src);
|
|
@@ -1285,12 +1637,12 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1285
1637
|
content
|
|
1286
1638
|
};
|
|
1287
1639
|
});
|
|
1288
|
-
this.
|
|
1640
|
+
__privateMethod(this, _registerLoadFunc, registerLoadFunc_fn).call(this, "html", async (elem, assets) => {
|
|
1289
1641
|
var _a;
|
|
1290
1642
|
const html2 = ((_a = assets[elem.detail.html]) == null ? void 0 : _a.value) || elem.detail.html;
|
|
1291
1643
|
const content = await loadHTML(html2, {
|
|
1292
|
-
width: elem.detail.
|
|
1293
|
-
height: elem.detail.
|
|
1644
|
+
width: elem.detail.originW || elem.w,
|
|
1645
|
+
height: elem.detail.originH || elem.h
|
|
1294
1646
|
});
|
|
1295
1647
|
return {
|
|
1296
1648
|
uuid: elem.uuid,
|
|
@@ -1298,7 +1650,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1298
1650
|
content
|
|
1299
1651
|
};
|
|
1300
1652
|
});
|
|
1301
|
-
this.
|
|
1653
|
+
__privateMethod(this, _registerLoadFunc, registerLoadFunc_fn).call(this, "svg", async (elem, assets) => {
|
|
1302
1654
|
var _a;
|
|
1303
1655
|
const svg2 = ((_a = assets[elem.detail.svg]) == null ? void 0 : _a.value) || elem.detail.svg;
|
|
1304
1656
|
const content = await loadSVG(svg2);
|
|
@@ -1309,120 +1661,168 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1309
1661
|
};
|
|
1310
1662
|
});
|
|
1311
1663
|
}
|
|
1312
|
-
|
|
1313
|
-
this
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1664
|
+
isDestroyed() {
|
|
1665
|
+
return __privateGet(this, _hasDestroyed);
|
|
1666
|
+
}
|
|
1667
|
+
destroy() {
|
|
1668
|
+
__privateSet(this, _hasDestroyed, true);
|
|
1669
|
+
this.clear();
|
|
1670
|
+
__privateSet(this, _loadFuncMap, null);
|
|
1671
|
+
__privateSet(this, _currentLoadItemMap, null);
|
|
1672
|
+
__privateSet(this, _storageLoadItemMap, null);
|
|
1673
|
+
}
|
|
1674
|
+
load(element, assets) {
|
|
1675
|
+
if (__privateGet(this, _hasDestroyed) === true) {
|
|
1676
|
+
return;
|
|
1324
1677
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
element,
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1678
|
+
if (__privateMethod(this, _isExistingErrorStorage, isExistingErrorStorage_fn).call(this, element)) {
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
if (supportElementTypes.includes(element.type)) {
|
|
1682
|
+
__privateMethod(this, _loadResource, loadResource_fn).call(this, element, assets);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
getContent(element) {
|
|
1686
|
+
var _a, _b;
|
|
1687
|
+
const assetId = getAssetIdFromElement(element);
|
|
1688
|
+
return ((_b = (_a = __privateGet(this, _storageLoadItemMap)) == null ? void 0 : _a[assetId]) == null ? void 0 : _b.content) || null;
|
|
1689
|
+
}
|
|
1690
|
+
getLoadItemMap() {
|
|
1691
|
+
return __privateGet(this, _storageLoadItemMap);
|
|
1692
|
+
}
|
|
1693
|
+
setLoadItemMap(itemMap) {
|
|
1694
|
+
__privateSet(this, _storageLoadItemMap, itemMap);
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
_loadFuncMap = new WeakMap();
|
|
1698
|
+
_currentLoadItemMap = new WeakMap();
|
|
1699
|
+
_storageLoadItemMap = new WeakMap();
|
|
1700
|
+
_hasDestroyed = new WeakMap();
|
|
1701
|
+
_registerLoadFunc = new WeakSet();
|
|
1702
|
+
registerLoadFunc_fn = function(type, func) {
|
|
1703
|
+
__privateGet(this, _loadFuncMap)[type] = func;
|
|
1704
|
+
};
|
|
1705
|
+
_getLoadElementSource = new WeakSet();
|
|
1706
|
+
getLoadElementSource_fn = function(element) {
|
|
1707
|
+
var _a, _b, _c;
|
|
1708
|
+
let source = null;
|
|
1709
|
+
if (element.type === "image") {
|
|
1710
|
+
source = ((_a = element == null ? void 0 : element.detail) == null ? void 0 : _a.src) || null;
|
|
1711
|
+
} else if (element.type === "svg") {
|
|
1712
|
+
source = ((_b = element == null ? void 0 : element.detail) == null ? void 0 : _b.svg) || null;
|
|
1713
|
+
} else if (element.type === "html") {
|
|
1714
|
+
source = ((_c = element == null ? void 0 : element.detail) == null ? void 0 : _c.html) || null;
|
|
1337
1715
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1716
|
+
return source;
|
|
1717
|
+
};
|
|
1718
|
+
_createLoadItem = new WeakSet();
|
|
1719
|
+
createLoadItem_fn = function(element) {
|
|
1720
|
+
return {
|
|
1721
|
+
element,
|
|
1722
|
+
status: "null",
|
|
1723
|
+
content: null,
|
|
1724
|
+
error: null,
|
|
1725
|
+
startTime: -1,
|
|
1726
|
+
endTime: -1,
|
|
1727
|
+
source: __privateMethod(this, _getLoadElementSource, getLoadElementSource_fn).call(this, element)
|
|
1728
|
+
};
|
|
1729
|
+
};
|
|
1730
|
+
_emitLoad = new WeakSet();
|
|
1731
|
+
emitLoad_fn = function(item) {
|
|
1732
|
+
const assetId = getAssetIdFromElement(item.element);
|
|
1733
|
+
const storageItem = __privateGet(this, _storageLoadItemMap)[assetId];
|
|
1734
|
+
if (!__privateGet(this, _hasDestroyed)) {
|
|
1341
1735
|
if (storageItem) {
|
|
1342
1736
|
if (storageItem.startTime < item.startTime) {
|
|
1343
|
-
this
|
|
1737
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1344
1738
|
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
1345
1739
|
}
|
|
1346
1740
|
} else {
|
|
1347
|
-
this
|
|
1741
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1348
1742
|
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
1349
1743
|
}
|
|
1350
1744
|
}
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1745
|
+
};
|
|
1746
|
+
_emitError = new WeakSet();
|
|
1747
|
+
emitError_fn = function(item) {
|
|
1748
|
+
var _a;
|
|
1749
|
+
const assetId = getAssetIdFromElement(item.element);
|
|
1750
|
+
const storageItem = (_a = __privateGet(this, _storageLoadItemMap)) == null ? void 0 : _a[assetId];
|
|
1751
|
+
if (!__privateGet(this, _hasDestroyed)) {
|
|
1354
1752
|
if (storageItem) {
|
|
1355
1753
|
if (storageItem.startTime < item.startTime) {
|
|
1356
|
-
this
|
|
1754
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1357
1755
|
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
1358
1756
|
}
|
|
1359
1757
|
} else {
|
|
1360
|
-
this
|
|
1758
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1361
1759
|
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
1362
1760
|
}
|
|
1363
1761
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1762
|
+
};
|
|
1763
|
+
_loadResource = new WeakSet();
|
|
1764
|
+
loadResource_fn = function(element, assets) {
|
|
1765
|
+
const item = __privateMethod(this, _createLoadItem, createLoadItem_fn).call(this, element);
|
|
1766
|
+
const assetId = getAssetIdFromElement(element);
|
|
1767
|
+
if (__privateGet(this, _currentLoadItemMap)[assetId]) {
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
__privateGet(this, _currentLoadItemMap)[assetId] = item;
|
|
1771
|
+
const loadFunc = __privateGet(this, _loadFuncMap)[element.type];
|
|
1772
|
+
if (typeof loadFunc === "function" && !__privateGet(this, _hasDestroyed)) {
|
|
1773
|
+
item.startTime = Date.now();
|
|
1774
|
+
loadFunc(element, assets).then((result) => {
|
|
1775
|
+
if (!__privateGet(this, _hasDestroyed)) {
|
|
1372
1776
|
item.content = result.content;
|
|
1373
1777
|
item.endTime = Date.now();
|
|
1374
1778
|
item.status = "load";
|
|
1375
|
-
this.
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
_isExistingErrorStorage(element) {
|
|
1386
|
-
var _a;
|
|
1387
|
-
const assetId = getAssetIdFromElement(element);
|
|
1388
|
-
const existItem = (_a = this._currentLoadItemMap) == null ? void 0 : _a[assetId];
|
|
1389
|
-
if (existItem && existItem.status === "error" && existItem.source && existItem.source === this._getLoadElementSource(element)) {
|
|
1390
|
-
return true;
|
|
1391
|
-
}
|
|
1392
|
-
return false;
|
|
1393
|
-
}
|
|
1394
|
-
load(element, assets) {
|
|
1395
|
-
if (this._isExistingErrorStorage(element)) {
|
|
1396
|
-
return;
|
|
1397
|
-
}
|
|
1398
|
-
if (supportElementTypes.includes(element.type)) {
|
|
1399
|
-
this._loadResource(element, assets);
|
|
1400
|
-
}
|
|
1779
|
+
__privateMethod(this, _emitLoad, emitLoad_fn).call(this, item);
|
|
1780
|
+
}
|
|
1781
|
+
}).catch((err) => {
|
|
1782
|
+
console.warn(`Load element source "${item.source}" fail`, err, element);
|
|
1783
|
+
item.endTime = Date.now();
|
|
1784
|
+
item.status = "error";
|
|
1785
|
+
item.error = err;
|
|
1786
|
+
__privateMethod(this, _emitError, emitError_fn).call(this, item);
|
|
1787
|
+
});
|
|
1401
1788
|
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1789
|
+
};
|
|
1790
|
+
_isExistingErrorStorage = new WeakSet();
|
|
1791
|
+
isExistingErrorStorage_fn = function(element) {
|
|
1792
|
+
var _a;
|
|
1793
|
+
const assetId = getAssetIdFromElement(element);
|
|
1794
|
+
const existItem = (_a = __privateGet(this, _currentLoadItemMap)) == null ? void 0 : _a[assetId];
|
|
1795
|
+
if (existItem && existItem.status === "error" && existItem.source && existItem.source === __privateMethod(this, _getLoadElementSource, getLoadElementSource_fn).call(this, element)) {
|
|
1796
|
+
return true;
|
|
1406
1797
|
}
|
|
1407
|
-
|
|
1798
|
+
return false;
|
|
1799
|
+
};
|
|
1408
1800
|
class Renderer extends EventEmitter {
|
|
1409
|
-
// private _draftContextTop: CanvasRenderingContext2D;
|
|
1410
|
-
// private _draftContextMiddle: CanvasRenderingContext2D;
|
|
1411
|
-
// private _draftContextBottom: CanvasRenderingContext2D;
|
|
1412
1801
|
constructor(opts) {
|
|
1413
1802
|
super();
|
|
1414
1803
|
__privateAdd(this, _init);
|
|
1415
1804
|
__privateAdd(this, _opts, void 0);
|
|
1416
1805
|
__privateAdd(this, _loader, new Loader());
|
|
1806
|
+
__privateAdd(this, _hasDestroyed2, false);
|
|
1417
1807
|
__privateSet(this, _opts, opts);
|
|
1418
1808
|
__privateMethod(this, _init, init_fn).call(this);
|
|
1419
1809
|
}
|
|
1810
|
+
isDestroyed() {
|
|
1811
|
+
return __privateGet(this, _hasDestroyed2);
|
|
1812
|
+
}
|
|
1813
|
+
destroy() {
|
|
1814
|
+
this.clear();
|
|
1815
|
+
__privateSet(this, _opts, null);
|
|
1816
|
+
__privateGet(this, _loader).destroy();
|
|
1817
|
+
__privateSet(this, _loader, null);
|
|
1818
|
+
__privateSet(this, _hasDestroyed2, true);
|
|
1819
|
+
}
|
|
1420
1820
|
updateOptions(opts) {
|
|
1421
1821
|
__privateSet(this, _opts, opts);
|
|
1422
1822
|
}
|
|
1423
1823
|
drawData(data, opts) {
|
|
1424
1824
|
const loader = __privateGet(this, _loader);
|
|
1425
|
-
const { calculator } = __privateGet(this, _opts);
|
|
1825
|
+
const { calculator, sharer } = __privateGet(this, _opts);
|
|
1426
1826
|
const viewContext = __privateGet(this, _opts).viewContext;
|
|
1427
1827
|
viewContext.clearRect(0, 0, viewContext.canvas.width, viewContext.canvas.height);
|
|
1428
1828
|
const parentElementSize = {
|
|
@@ -1431,13 +1831,23 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1431
1831
|
w: opts.viewSizeInfo.width,
|
|
1432
1832
|
h: opts.viewSizeInfo.height
|
|
1433
1833
|
};
|
|
1434
|
-
|
|
1834
|
+
const drawOpts = {
|
|
1435
1835
|
loader,
|
|
1436
1836
|
calculator,
|
|
1437
1837
|
parentElementSize,
|
|
1438
1838
|
elementAssets: data.assets,
|
|
1839
|
+
parentOpacity: 1,
|
|
1840
|
+
overrideElementMap: sharer == null ? void 0 : sharer.getActiveOverrideElemenentMap(),
|
|
1439
1841
|
...opts
|
|
1440
|
-
}
|
|
1842
|
+
};
|
|
1843
|
+
drawGlobalBackground(viewContext, data.global, drawOpts);
|
|
1844
|
+
if (data.layout) {
|
|
1845
|
+
drawLayout(viewContext, data.layout, drawOpts, () => {
|
|
1846
|
+
drawElementList(viewContext, data, drawOpts);
|
|
1847
|
+
});
|
|
1848
|
+
} else {
|
|
1849
|
+
drawElementList(viewContext, data, drawOpts);
|
|
1850
|
+
}
|
|
1441
1851
|
}
|
|
1442
1852
|
scale(num) {
|
|
1443
1853
|
const { sharer } = __privateGet(this, _opts);
|
|
@@ -1464,19 +1874,31 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1464
1874
|
});
|
|
1465
1875
|
}
|
|
1466
1876
|
}
|
|
1877
|
+
setLoadItemMap(itemMap) {
|
|
1878
|
+
__privateGet(this, _loader).setLoadItemMap(itemMap);
|
|
1879
|
+
}
|
|
1880
|
+
getLoadItemMap() {
|
|
1881
|
+
return __privateGet(this, _loader).getLoadItemMap();
|
|
1882
|
+
}
|
|
1883
|
+
getLoader() {
|
|
1884
|
+
return __privateGet(this, _loader);
|
|
1885
|
+
}
|
|
1467
1886
|
}
|
|
1468
1887
|
_opts = new WeakMap();
|
|
1469
1888
|
_loader = new WeakMap();
|
|
1889
|
+
_hasDestroyed2 = new WeakMap();
|
|
1470
1890
|
_init = new WeakSet();
|
|
1471
1891
|
init_fn = function() {
|
|
1472
1892
|
const loader = __privateGet(this, _loader);
|
|
1473
1893
|
loader.on("load", (e) => {
|
|
1474
1894
|
this.trigger("load", e);
|
|
1475
1895
|
});
|
|
1476
|
-
loader.on("error", () => {
|
|
1896
|
+
loader.on("error", (e) => {
|
|
1897
|
+
console.error(e);
|
|
1477
1898
|
});
|
|
1478
1899
|
};
|
|
1479
1900
|
exports.Renderer = Renderer;
|
|
1901
|
+
exports.drawRect = drawRect;
|
|
1480
1902
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1481
1903
|
return exports;
|
|
1482
1904
|
}({});
|