@leafer-ui/draw 1.6.7 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/draw.cjs +87 -59
- package/lib/draw.esm.js +88 -61
- package/lib/draw.esm.min.js +1 -1
- package/lib/draw.esm.min.js.map +1 -1
- package/lib/draw.min.cjs +1 -1
- package/lib/draw.min.cjs.map +1 -1
- package/package.json +6 -6
package/lib/draw.cjs
CHANGED
|
@@ -64,6 +64,11 @@ function zoomLayerType() {
|
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
+
function createAttr(defaultValue) {
|
|
68
|
+
return (target, key) => {
|
|
69
|
+
core.defineKey(target, key, core.createDescriptor(key, defaultValue));
|
|
70
|
+
};
|
|
71
|
+
}
|
|
67
72
|
|
|
68
73
|
function hasTransparent$1(color) {
|
|
69
74
|
if (!color || color.length === 7 || color.length === 4)
|
|
@@ -121,26 +126,9 @@ const emptyPaint = {};
|
|
|
121
126
|
const debug$1 = core.Debug.get('UIData');
|
|
122
127
|
class UIData extends core.LeafData {
|
|
123
128
|
get scale() { const { scaleX, scaleY } = this; return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX; }
|
|
124
|
-
get __strokeWidth() {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const ui = this.__leaf;
|
|
128
|
-
let { scaleX } = ui.__nowWorld || ui.__world;
|
|
129
|
-
if (scaleX < 0)
|
|
130
|
-
scaleX = -scaleX;
|
|
131
|
-
return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
|
|
132
|
-
}
|
|
133
|
-
else
|
|
134
|
-
return strokeWidth;
|
|
135
|
-
}
|
|
136
|
-
get __hasStroke() { return this.stroke && this.strokeWidth; }
|
|
137
|
-
get __hasHalf() { const t = this; return (t.stroke && t.strokeAlign === 'center' && t.strokeWidth % 2) || undefined; }
|
|
138
|
-
get __hasMultiPaint() {
|
|
139
|
-
const t = this;
|
|
140
|
-
if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
|
|
141
|
-
return true;
|
|
142
|
-
return t.fill && this.__hasStroke;
|
|
143
|
-
}
|
|
129
|
+
get __strokeWidth() { return this.__getRealStrokeWidth(); }
|
|
130
|
+
get __maxStrokeWidth() { const t = this; return t.__hasMultiStrokeStyle ? Math.max(t.__hasMultiStrokeStyle, t.strokeWidth) : t.strokeWidth; }
|
|
131
|
+
get __hasMultiPaint() { const t = this; return (t.fill && this.__useStroke) || (t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect; }
|
|
144
132
|
get __clipAfterFill() { const t = this; return (t.cornerRadius || t.innerShadow || t.__pathInputed); }
|
|
145
133
|
get __hasSurface() { const t = this; return (t.fill || t.stroke); }
|
|
146
134
|
get __autoWidth() { return !this._width; }
|
|
@@ -222,6 +210,21 @@ class UIData extends core.LeafData {
|
|
|
222
210
|
Paint.compute('stroke', this.__leaf);
|
|
223
211
|
this.__needComputePaint = undefined;
|
|
224
212
|
}
|
|
213
|
+
__getRealStrokeWidth(childStyle) {
|
|
214
|
+
let { strokeWidth, strokeWidthFixed } = this;
|
|
215
|
+
if (childStyle) {
|
|
216
|
+
if (childStyle.strokeWidth)
|
|
217
|
+
strokeWidth = childStyle.strokeWidth;
|
|
218
|
+
if (childStyle.strokeWidthFixed !== undefined)
|
|
219
|
+
strokeWidthFixed = childStyle.strokeWidthFixed;
|
|
220
|
+
}
|
|
221
|
+
if (strokeWidthFixed) {
|
|
222
|
+
const scale = this.__leaf.getClampRenderScale();
|
|
223
|
+
return scale > 1 ? strokeWidth / scale : strokeWidth;
|
|
224
|
+
}
|
|
225
|
+
else
|
|
226
|
+
return strokeWidth;
|
|
227
|
+
}
|
|
225
228
|
__setPaint(attrName, value) {
|
|
226
229
|
this.__setInput(attrName, value);
|
|
227
230
|
const layout = this.__leaf.__layout;
|
|
@@ -246,6 +249,7 @@ class UIData extends core.LeafData {
|
|
|
246
249
|
}
|
|
247
250
|
else {
|
|
248
251
|
stintSet$1(this, '__isAlphaPixelStroke', undefined);
|
|
252
|
+
stintSet$1(this, '__hasMultiStrokeStyle', undefined);
|
|
249
253
|
this._stroke = this.__isStrokes = undefined;
|
|
250
254
|
}
|
|
251
255
|
}
|
|
@@ -267,8 +271,8 @@ class GroupData extends UIData {
|
|
|
267
271
|
|
|
268
272
|
class BoxData extends GroupData {
|
|
269
273
|
get __boxStroke() { return !this.__pathInputed; }
|
|
270
|
-
get __drawAfterFill() { const t = this; return
|
|
271
|
-
get __clipAfterFill() { return
|
|
274
|
+
get __drawAfterFill() { const t = this; return t.__single || t.__clipAfterFill; }
|
|
275
|
+
get __clipAfterFill() { const t = this; return t.overflow === 'hide' && t.__leaf.children.length && (t.__leaf.isOverflow || super.__clipAfterFill); }
|
|
272
276
|
}
|
|
273
277
|
|
|
274
278
|
class LeaferData extends GroupData {
|
|
@@ -388,7 +392,7 @@ class CanvasData extends RectData {
|
|
|
388
392
|
const UIBounds = {
|
|
389
393
|
__updateStrokeSpread() {
|
|
390
394
|
let width = 0, boxWidth = 0;
|
|
391
|
-
const data = this.__, { strokeAlign, strokeWidth } = data, box = this.__box;
|
|
395
|
+
const data = this.__, { strokeAlign, __maxStrokeWidth: strokeWidth } = data, box = this.__box;
|
|
392
396
|
if ((data.stroke || data.hitStroke === 'all') && strokeWidth && strokeAlign !== 'inside') {
|
|
393
397
|
boxWidth = width = strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth;
|
|
394
398
|
if (!data.__boxStroke) {
|
|
@@ -408,13 +412,15 @@ const UIBounds = {
|
|
|
408
412
|
},
|
|
409
413
|
__updateRenderSpread() {
|
|
410
414
|
let width = 0;
|
|
411
|
-
const { shadow, innerShadow, blur, backgroundBlur, filter } = this.__;
|
|
415
|
+
const { shadow, innerShadow, blur, backgroundBlur, filter, renderSpread } = this.__;
|
|
412
416
|
if (shadow)
|
|
413
417
|
shadow.forEach(item => width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5));
|
|
414
418
|
if (blur)
|
|
415
419
|
width = Math.max(width, blur);
|
|
416
420
|
if (filter)
|
|
417
421
|
width += Filter.getSpread(filter);
|
|
422
|
+
if (renderSpread)
|
|
423
|
+
width += renderSpread;
|
|
418
424
|
let shapeWidth = width = Math.ceil(width);
|
|
419
425
|
if (innerShadow)
|
|
420
426
|
innerShadow.forEach(item => shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5));
|
|
@@ -430,15 +436,18 @@ const { stintSet } = core.DataHelper;
|
|
|
430
436
|
const UIRender = {
|
|
431
437
|
__updateChange() {
|
|
432
438
|
const data = this.__;
|
|
439
|
+
if (data.__useStroke) {
|
|
440
|
+
const useStroke = data.__useStroke = !!(data.stroke && data.strokeWidth);
|
|
441
|
+
stintSet(this.__world, 'half', useStroke && data.strokeAlign === 'center' && data.strokeWidth % 2);
|
|
442
|
+
stintSet(data, '__fillAfterStroke', useStroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
|
|
443
|
+
}
|
|
433
444
|
if (data.__useEffect) {
|
|
434
445
|
const { shadow, fill, stroke } = data, otherEffect = data.innerShadow || data.blur || data.backgroundBlur || data.filter;
|
|
435
|
-
stintSet(data, '__isFastShadow', shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread &&
|
|
446
|
+
stintSet(data, '__isFastShadow', shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread && fill && !data.__isTransparentFill && !(fill instanceof Array && fill.length > 1) && (this.useFastShadow || !stroke || (stroke && data.strokeAlign === 'inside')));
|
|
436
447
|
data.__useEffect = !!(shadow || otherEffect);
|
|
437
448
|
}
|
|
438
|
-
stintSet(this.__world, 'half', data.__hasHalf);
|
|
439
|
-
stintSet(data, '__fillAfterStroke', data.stroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
|
|
440
449
|
data.__checkSingle();
|
|
441
|
-
stintSet(data, '__complex', data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect);
|
|
450
|
+
stintSet(data, '__complex', (data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect));
|
|
442
451
|
},
|
|
443
452
|
__drawFast(canvas, options) {
|
|
444
453
|
drawFast(this, canvas, options);
|
|
@@ -496,18 +505,15 @@ const UIRender = {
|
|
|
496
505
|
this.__drawFast(canvas, options);
|
|
497
506
|
}
|
|
498
507
|
},
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
this.
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (stroke && !ignoreStroke)
|
|
509
|
-
this.__.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
|
|
510
|
-
}
|
|
508
|
+
__drawShape(canvas, options) {
|
|
509
|
+
this.__drawRenderPath(canvas);
|
|
510
|
+
const data = this.__, { fill, stroke } = data;
|
|
511
|
+
if (fill && !options.ignoreFill)
|
|
512
|
+
data.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
|
|
513
|
+
if (data.__isCanvas)
|
|
514
|
+
this.__drawAfterFill(canvas, options);
|
|
515
|
+
if (stroke && !options.ignoreStroke)
|
|
516
|
+
data.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
|
|
511
517
|
},
|
|
512
518
|
__drawAfterFill(canvas, options) {
|
|
513
519
|
if (this.__.__clipAfterFill) {
|
|
@@ -544,17 +550,17 @@ const RectRender = {
|
|
|
544
550
|
if (__drawAfterFill)
|
|
545
551
|
this.__drawAfterFill(canvas, options);
|
|
546
552
|
if (stroke) {
|
|
547
|
-
const { strokeAlign, __strokeWidth } = this.__;
|
|
548
|
-
if (!
|
|
553
|
+
const { strokeAlign, __strokeWidth: strokeWidth } = this.__;
|
|
554
|
+
if (!strokeWidth)
|
|
549
555
|
return;
|
|
550
|
-
canvas.setStroke(stroke,
|
|
551
|
-
const half =
|
|
556
|
+
canvas.setStroke(stroke, strokeWidth, this.__);
|
|
557
|
+
const half = strokeWidth / 2;
|
|
552
558
|
switch (strokeAlign) {
|
|
553
559
|
case 'center':
|
|
554
560
|
canvas.strokeRect(0, 0, width, height);
|
|
555
561
|
break;
|
|
556
562
|
case 'inside':
|
|
557
|
-
width -=
|
|
563
|
+
width -= strokeWidth, height -= strokeWidth;
|
|
558
564
|
if (width < 0 || height < 0) {
|
|
559
565
|
canvas.save();
|
|
560
566
|
this.__clip(canvas, options);
|
|
@@ -565,7 +571,7 @@ const RectRender = {
|
|
|
565
571
|
canvas.strokeRect(x + half, y + half, width, height);
|
|
566
572
|
break;
|
|
567
573
|
case 'outside':
|
|
568
|
-
canvas.strokeRect(x - half, y - half, width +
|
|
574
|
+
canvas.strokeRect(x - half, y - half, width + strokeWidth, height + strokeWidth);
|
|
569
575
|
break;
|
|
570
576
|
}
|
|
571
577
|
}
|
|
@@ -578,6 +584,8 @@ exports.UI = UI_1 = class UI extends core.Leaf {
|
|
|
578
584
|
get isFrame() { return false; }
|
|
579
585
|
set scale(value) { core.MathHelper.assignScale(this, value); }
|
|
580
586
|
get scale() { return this.__.scale; }
|
|
587
|
+
get isAutoWidth() { const t = this.__; return t.__autoWidth || t.autoWidth; }
|
|
588
|
+
get isAutoHeight() { const t = this.__; return t.__autoHeight || t.autoHeight; }
|
|
581
589
|
get pen() {
|
|
582
590
|
const { path } = this.__;
|
|
583
591
|
core.pen.set(this.path = path || []);
|
|
@@ -632,12 +640,14 @@ exports.UI = UI_1 = class UI extends core.Leaf {
|
|
|
632
640
|
}
|
|
633
641
|
}
|
|
634
642
|
__updateRenderPath() {
|
|
635
|
-
|
|
636
|
-
|
|
643
|
+
const data = this.__;
|
|
644
|
+
if (data.path) {
|
|
637
645
|
data.__pathForRender = data.cornerRadius ? core.PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path;
|
|
638
646
|
if (data.__useArrow)
|
|
639
647
|
PathArrow.addArrows(this, !data.cornerRadius);
|
|
640
648
|
}
|
|
649
|
+
else
|
|
650
|
+
data.__pathForRender && (data.__pathForRender = undefined);
|
|
641
651
|
}
|
|
642
652
|
__drawRenderPath(canvas) {
|
|
643
653
|
canvas.beginPath();
|
|
@@ -790,6 +800,9 @@ __decorate([
|
|
|
790
800
|
__decorate([
|
|
791
801
|
core.naturalBoundsType(1)
|
|
792
802
|
], exports.UI.prototype, "pixelRatio", void 0);
|
|
803
|
+
__decorate([
|
|
804
|
+
core.affectRenderBoundsType(0)
|
|
805
|
+
], exports.UI.prototype, "renderSpread", void 0);
|
|
793
806
|
__decorate([
|
|
794
807
|
core.pathInputType()
|
|
795
808
|
], exports.UI.prototype, "path", void 0);
|
|
@@ -848,13 +861,13 @@ __decorate([
|
|
|
848
861
|
core.surfaceType()
|
|
849
862
|
], exports.UI.prototype, "fill", void 0);
|
|
850
863
|
__decorate([
|
|
851
|
-
core.strokeType()
|
|
864
|
+
core.strokeType(undefined, true)
|
|
852
865
|
], exports.UI.prototype, "stroke", void 0);
|
|
853
866
|
__decorate([
|
|
854
867
|
core.strokeType('inside')
|
|
855
868
|
], exports.UI.prototype, "strokeAlign", void 0);
|
|
856
869
|
__decorate([
|
|
857
|
-
core.strokeType(1)
|
|
870
|
+
core.strokeType(1, true)
|
|
858
871
|
], exports.UI.prototype, "strokeWidth", void 0);
|
|
859
872
|
__decorate([
|
|
860
873
|
core.strokeType(false)
|
|
@@ -946,7 +959,8 @@ exports.Group = class Group extends exports.UI {
|
|
|
946
959
|
}
|
|
947
960
|
toJSON(options) {
|
|
948
961
|
const data = super.toJSON(options);
|
|
949
|
-
|
|
962
|
+
if (!this.childlessJSON)
|
|
963
|
+
data.children = this.children.map(child => child.toJSON(options));
|
|
950
964
|
return data;
|
|
951
965
|
}
|
|
952
966
|
pick(_hitPoint, _options) { return undefined; }
|
|
@@ -1281,7 +1295,7 @@ exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
|
|
|
1281
1295
|
list.push(item);
|
|
1282
1296
|
this.requestRender();
|
|
1283
1297
|
}
|
|
1284
|
-
zoom(_zoomType,
|
|
1298
|
+
zoom(_zoomType, _optionsOrPadding, _scroll, _transition) {
|
|
1285
1299
|
return core.Plugin.need('view');
|
|
1286
1300
|
}
|
|
1287
1301
|
getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
|
|
@@ -1326,7 +1340,7 @@ exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
|
|
|
1326
1340
|
Leafer_1.list.remove(this);
|
|
1327
1341
|
try {
|
|
1328
1342
|
this.stop();
|
|
1329
|
-
this.
|
|
1343
|
+
this.emitLeafer(core.LeaferEvent.END);
|
|
1330
1344
|
this.__removeListenEvents();
|
|
1331
1345
|
this.__controllers.forEach(item => !(this.parent && item === this.interaction) && item.destroy());
|
|
1332
1346
|
this.__controllers.length = 0;
|
|
@@ -1393,8 +1407,8 @@ exports.Box = class Box extends exports.Group {
|
|
|
1393
1407
|
__updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
|
|
1394
1408
|
__updateRectBoxBounds() { }
|
|
1395
1409
|
__updateBoxBounds(_secondLayout) {
|
|
1396
|
-
const data = this.__;
|
|
1397
1410
|
if (this.children.length && !this.pathInputed) {
|
|
1411
|
+
const data = this.__;
|
|
1398
1412
|
if (data.__autoSide) {
|
|
1399
1413
|
if (data.__hasSurface)
|
|
1400
1414
|
this.__extraUpdate();
|
|
@@ -1421,20 +1435,26 @@ exports.Box = class Box extends exports.Group {
|
|
|
1421
1435
|
__updateStrokeBounds() { }
|
|
1422
1436
|
__updateRenderBounds() {
|
|
1423
1437
|
let isOverflow;
|
|
1424
|
-
const { renderBounds } = this.__layout;
|
|
1425
1438
|
if (this.children.length) {
|
|
1439
|
+
const data = this.__, { renderBounds, boxBounds } = this.__layout;
|
|
1426
1440
|
super.__updateRenderBounds();
|
|
1427
1441
|
copy(childrenRenderBounds, renderBounds);
|
|
1428
1442
|
this.__updateRectRenderBounds();
|
|
1429
|
-
|
|
1430
|
-
|
|
1443
|
+
if (data.scrollY || data.scrollX) {
|
|
1444
|
+
childrenRenderBounds.x += data.scrollX;
|
|
1445
|
+
childrenRenderBounds.y += data.scrollY;
|
|
1446
|
+
}
|
|
1447
|
+
isOverflow = !includes$1(boxBounds, childrenRenderBounds);
|
|
1448
|
+
if (isOverflow && data.overflow !== 'hide')
|
|
1431
1449
|
add(renderBounds, childrenRenderBounds);
|
|
1432
1450
|
}
|
|
1433
1451
|
else
|
|
1434
1452
|
this.__updateRectRenderBounds();
|
|
1435
1453
|
core.DataHelper.stintSet(this, 'isOverflow', isOverflow);
|
|
1454
|
+
this.__updateScrollBar();
|
|
1436
1455
|
}
|
|
1437
1456
|
__updateRectRenderBounds() { }
|
|
1457
|
+
__updateScrollBar() { }
|
|
1438
1458
|
__updateRectChange() { }
|
|
1439
1459
|
__updateChange() {
|
|
1440
1460
|
super.__updateChange();
|
|
@@ -1451,10 +1471,12 @@ exports.Box = class Box extends exports.Group {
|
|
|
1451
1471
|
if (this.children.length)
|
|
1452
1472
|
this.__renderGroup(canvas, options);
|
|
1453
1473
|
}
|
|
1474
|
+
if (this.scrollBar)
|
|
1475
|
+
this.scrollBar.__render(canvas, options);
|
|
1454
1476
|
}
|
|
1455
1477
|
__drawContent(canvas, options) {
|
|
1456
1478
|
this.__renderGroup(canvas, options);
|
|
1457
|
-
if (this.__.
|
|
1479
|
+
if (this.__.__useStroke || this.__.__useEffect) {
|
|
1458
1480
|
canvas.setWorld(this.__nowWorld);
|
|
1459
1481
|
this.__drawRenderPath(canvas);
|
|
1460
1482
|
}
|
|
@@ -1674,8 +1696,8 @@ exports.Polygon = class Polygon extends exports.UI {
|
|
|
1674
1696
|
for (let i = 1; i < sides; i++) {
|
|
1675
1697
|
lineTo$1(path, rx + rx * sin$1((i * 2 * PI$1) / sides), ry - ry * cos$1((i * 2 * PI$1) / sides));
|
|
1676
1698
|
}
|
|
1699
|
+
closePath$1(path);
|
|
1677
1700
|
}
|
|
1678
|
-
closePath$1(path);
|
|
1679
1701
|
}
|
|
1680
1702
|
__updateRenderPath() { }
|
|
1681
1703
|
__updateBoxBounds() { }
|
|
@@ -1913,6 +1935,11 @@ exports.Text = class Text extends exports.UI {
|
|
|
1913
1935
|
return;
|
|
1914
1936
|
super.__draw(canvas, options, originCanvas);
|
|
1915
1937
|
}
|
|
1938
|
+
__drawShape(canvas, options) {
|
|
1939
|
+
if (options.shape)
|
|
1940
|
+
this.__box && this.__box.__drawShape(canvas, options);
|
|
1941
|
+
super.__drawShape(canvas, options);
|
|
1942
|
+
}
|
|
1916
1943
|
destroy() {
|
|
1917
1944
|
if (this.boxStyle)
|
|
1918
1945
|
this.boxStyle = null;
|
|
@@ -2101,6 +2128,7 @@ exports.UIBounds = UIBounds;
|
|
|
2101
2128
|
exports.UIData = UIData;
|
|
2102
2129
|
exports.UIRender = UIRender;
|
|
2103
2130
|
exports.UnitConvert = UnitConvert;
|
|
2131
|
+
exports.createAttr = createAttr;
|
|
2104
2132
|
exports.effectType = effectType;
|
|
2105
2133
|
exports.resizeType = resizeType;
|
|
2106
2134
|
exports.zoomLayerType = zoomLayerType;
|