@leafer-ui/draw 1.5.2 → 1.6.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 +102 -58
- package/lib/draw.cjs.map +1 -1
- package/lib/draw.esm.js +103 -59
- package/lib/draw.esm.js.map +1 -1
- 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.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineKey, decorateLeafAttr, attr, Plugin, PathConvert, Debug, LeafData, canvasSizeAttrs, dataProcessor, dataType, surfaceType, opacityType, visibleType, sortType, maskType, eraserType, positionType, boundsType, scaleType, rotationType, autoLayoutType, naturalBoundsType, pathInputType, pathType, hitType, strokeType, cursorType, rewrite, Leaf, useModule, rewriteAble, MathHelper, pen, PathCorner, PathDrawer, DataHelper,
|
|
1
|
+
import { defineKey, decorateLeafAttr, attr, Plugin, PathConvert, Debug, LeafData, canvasSizeAttrs, UICreator, dataProcessor, dataType, surfaceType, opacityType, visibleType, sortType, maskType, eraserType, positionType, boundsType, scaleType, rotationType, autoLayoutType, naturalBoundsType, pathInputType, pathType, hitType, strokeType, cursorType, rewrite, Leaf, useModule, rewriteAble, MathHelper, pen, PathCorner, PathDrawer, DataHelper, registerUI, Branch, LeafList, Resource, getBoundsData, Creator, CanvasManager, WaitHelper, LeaferEvent, Bounds, ResizeEvent, AutoBounds, Run, LayoutEvent, RenderEvent, WatchEvent, ImageManager, BoundsHelper, affectRenderBoundsType, PathCommandDataHelper, Platform, PointHelper, PathBounds, affectStrokeBoundsType, getPointData, ImageEvent, LeaferImage, Matrix, PathCreator } from '@leafer/core';
|
|
2
2
|
export * from '@leafer/core';
|
|
3
3
|
|
|
4
4
|
/******************************************************************************
|
|
@@ -108,6 +108,7 @@ class UIData extends LeafData {
|
|
|
108
108
|
return strokeWidth;
|
|
109
109
|
}
|
|
110
110
|
get __hasStroke() { return this.stroke && this.strokeWidth; }
|
|
111
|
+
get __hasHalf() { const t = this; return (t.stroke && t.strokeAlign === 'center' && t.strokeWidth % 2) || undefined; }
|
|
111
112
|
get __hasMultiPaint() {
|
|
112
113
|
const t = this;
|
|
113
114
|
if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
|
|
@@ -152,14 +153,14 @@ class UIData extends LeafData {
|
|
|
152
153
|
this.__removeInput('fill');
|
|
153
154
|
PaintImage.recycleImage('fill', this);
|
|
154
155
|
this.__isFills = false;
|
|
155
|
-
|
|
156
|
-
this.__pixelFill = false;
|
|
156
|
+
this.__pixelFill && (this.__pixelFill = false);
|
|
157
157
|
}
|
|
158
158
|
this._fill = value;
|
|
159
159
|
}
|
|
160
160
|
else if (typeof value === 'object') {
|
|
161
161
|
this.__setInput('fill', value);
|
|
162
|
-
|
|
162
|
+
const layout = this.__leaf.__layout;
|
|
163
|
+
layout.boxChanged || layout.boxChange();
|
|
163
164
|
this.__isFills = true;
|
|
164
165
|
this._fill || (this._fill = emptyPaint);
|
|
165
166
|
}
|
|
@@ -170,14 +171,14 @@ class UIData extends LeafData {
|
|
|
170
171
|
this.__removeInput('stroke');
|
|
171
172
|
PaintImage.recycleImage('stroke', this);
|
|
172
173
|
this.__isStrokes = false;
|
|
173
|
-
|
|
174
|
-
this.__pixelStroke = false;
|
|
174
|
+
this.__pixelStroke && (this.__pixelStroke = false);
|
|
175
175
|
}
|
|
176
176
|
this._stroke = value;
|
|
177
177
|
}
|
|
178
178
|
else if (typeof value === 'object') {
|
|
179
179
|
this.__setInput('stroke', value);
|
|
180
|
-
|
|
180
|
+
const layout = this.__leaf.__layout;
|
|
181
|
+
layout.boxChanged || layout.boxChange();
|
|
181
182
|
this.__isStrokes = true;
|
|
182
183
|
this._stroke || (this._stroke = emptyPaint);
|
|
183
184
|
}
|
|
@@ -292,6 +293,31 @@ class TextData extends UIData {
|
|
|
292
293
|
this._fontWeight = value;
|
|
293
294
|
}
|
|
294
295
|
}
|
|
296
|
+
setBoxStyle(value) {
|
|
297
|
+
let t = this.__leaf, box = t.__box;
|
|
298
|
+
if (value) {
|
|
299
|
+
const { boxStyle } = this;
|
|
300
|
+
if (box)
|
|
301
|
+
for (let key in boxStyle)
|
|
302
|
+
box[key] = undefined;
|
|
303
|
+
else
|
|
304
|
+
box = t.__box = UICreator.get('Rect', 0);
|
|
305
|
+
const layout = t.__layout, boxLayout = box.__layout;
|
|
306
|
+
if (!boxStyle)
|
|
307
|
+
box.parent = t, box.__world = t.__world, boxLayout.boxBounds = layout.boxBounds;
|
|
308
|
+
box.set(value);
|
|
309
|
+
if (boxLayout.strokeChanged)
|
|
310
|
+
layout.strokeChange();
|
|
311
|
+
if (boxLayout.renderChanged)
|
|
312
|
+
layout.renderChange();
|
|
313
|
+
box.__updateChange();
|
|
314
|
+
}
|
|
315
|
+
else if (box) {
|
|
316
|
+
t.__box = box.parent = null;
|
|
317
|
+
box.destroy();
|
|
318
|
+
}
|
|
319
|
+
this._boxStyle = value;
|
|
320
|
+
}
|
|
295
321
|
}
|
|
296
322
|
|
|
297
323
|
class ImageData extends RectData {
|
|
@@ -329,7 +355,7 @@ class CanvasData extends RectData {
|
|
|
329
355
|
const UIBounds = {
|
|
330
356
|
__updateStrokeSpread() {
|
|
331
357
|
let width = 0, boxWidth = 0;
|
|
332
|
-
const data = this.__, { strokeAlign, strokeWidth } = data;
|
|
358
|
+
const data = this.__, { strokeAlign, strokeWidth } = data, box = this.__box;
|
|
333
359
|
if ((data.stroke || data.hitStroke === 'all') && strokeWidth && strokeAlign !== 'inside') {
|
|
334
360
|
boxWidth = width = strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth;
|
|
335
361
|
if (!data.__boxStroke) {
|
|
@@ -340,6 +366,10 @@ const UIBounds = {
|
|
|
340
366
|
}
|
|
341
367
|
if (data.__useArrow)
|
|
342
368
|
width += strokeWidth * 5;
|
|
369
|
+
if (box) {
|
|
370
|
+
width = Math.max(box.__layout.strokeSpread = box.__updateStrokeSpread(), width);
|
|
371
|
+
boxWidth = box.__layout.strokeBoxSpread;
|
|
372
|
+
}
|
|
343
373
|
this.__layout.strokeBoxSpread = boxWidth;
|
|
344
374
|
return width;
|
|
345
375
|
},
|
|
@@ -358,25 +388,26 @@ const UIBounds = {
|
|
|
358
388
|
if (backgroundBlur)
|
|
359
389
|
shapeWidth = Math.max(shapeWidth, backgroundBlur);
|
|
360
390
|
this.__layout.renderShapeSpread = shapeWidth;
|
|
361
|
-
|
|
391
|
+
width += this.__layout.strokeSpread || 0;
|
|
392
|
+
return this.__box ? Math.max(this.__box.__updateRenderSpread(), width) : width;
|
|
362
393
|
}
|
|
363
394
|
};
|
|
364
395
|
|
|
365
396
|
const UIRender = {
|
|
366
397
|
__updateChange() {
|
|
367
|
-
const data = this.__;
|
|
398
|
+
const data = this.__, w = this.__world;
|
|
368
399
|
if (data.__useEffect) {
|
|
369
400
|
const { shadow, innerShadow, blur, backgroundBlur, filter } = this.__;
|
|
370
401
|
data.__useEffect = !!(shadow || innerShadow || blur || backgroundBlur || filter);
|
|
371
402
|
}
|
|
403
|
+
const half = data.__hasHalf;
|
|
404
|
+
w.half !== half && (w.half = half);
|
|
372
405
|
data.__checkSingle();
|
|
373
406
|
const complex = data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect;
|
|
374
|
-
if (complex)
|
|
407
|
+
if (complex)
|
|
375
408
|
data.__complex = true;
|
|
376
|
-
|
|
377
|
-
else {
|
|
409
|
+
else
|
|
378
410
|
data.__complex && (data.__complex = false);
|
|
379
|
-
}
|
|
380
411
|
},
|
|
381
412
|
__drawFast(canvas, options) {
|
|
382
413
|
drawFast(this, canvas, options);
|
|
@@ -463,10 +494,11 @@ function drawFast(ui, canvas, options) {
|
|
|
463
494
|
|
|
464
495
|
const RectRender = {
|
|
465
496
|
__drawFast(canvas, options) {
|
|
466
|
-
let {
|
|
497
|
+
let { x, y, width, height } = this.__layout.boxBounds;
|
|
498
|
+
const { fill, stroke, __drawAfterFill } = this.__;
|
|
467
499
|
if (fill) {
|
|
468
500
|
canvas.fillStyle = fill;
|
|
469
|
-
canvas.fillRect(
|
|
501
|
+
canvas.fillRect(x, y, width, height);
|
|
470
502
|
}
|
|
471
503
|
if (__drawAfterFill)
|
|
472
504
|
this.__drawAfterFill(canvas, options);
|
|
@@ -485,14 +517,14 @@ const RectRender = {
|
|
|
485
517
|
if (width < 0 || height < 0) {
|
|
486
518
|
canvas.save();
|
|
487
519
|
this.__clip(canvas, options);
|
|
488
|
-
canvas.strokeRect(half, half, width, height);
|
|
520
|
+
canvas.strokeRect(x + half, y + half, width, height);
|
|
489
521
|
canvas.restore();
|
|
490
522
|
}
|
|
491
523
|
else
|
|
492
|
-
canvas.strokeRect(half, half, width, height);
|
|
524
|
+
canvas.strokeRect(x + half, y + half, width, height);
|
|
493
525
|
break;
|
|
494
526
|
case 'outside':
|
|
495
|
-
canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
|
|
527
|
+
canvas.strokeRect(x - half, y - half, width + __strokeWidth, height + __strokeWidth);
|
|
496
528
|
break;
|
|
497
529
|
}
|
|
498
530
|
}
|
|
@@ -648,6 +680,12 @@ __decorate([
|
|
|
648
680
|
__decorate([
|
|
649
681
|
surfaceType(false)
|
|
650
682
|
], UI.prototype, "locked", void 0);
|
|
683
|
+
__decorate([
|
|
684
|
+
surfaceType(false)
|
|
685
|
+
], UI.prototype, "dim", void 0);
|
|
686
|
+
__decorate([
|
|
687
|
+
surfaceType(false)
|
|
688
|
+
], UI.prototype, "dimskip", void 0);
|
|
651
689
|
__decorate([
|
|
652
690
|
sortType(0)
|
|
653
691
|
], UI.prototype, "zIndex", void 0);
|
|
@@ -909,7 +947,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
|
|
|
909
947
|
start: true,
|
|
910
948
|
hittable: true,
|
|
911
949
|
smooth: true,
|
|
912
|
-
lazySpeard: 100
|
|
950
|
+
lazySpeard: 100,
|
|
913
951
|
};
|
|
914
952
|
this.leafs = 0;
|
|
915
953
|
this.__eventIds = [];
|
|
@@ -1333,13 +1371,13 @@ let Box = class Box extends Group {
|
|
|
1333
1371
|
super.__updateRenderBounds();
|
|
1334
1372
|
copy(childrenRenderBounds, renderBounds);
|
|
1335
1373
|
this.__updateRectRenderBounds();
|
|
1336
|
-
isOverflow = !includes$1(renderBounds, childrenRenderBounds);
|
|
1374
|
+
isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
|
|
1337
1375
|
if (isOverflow && this.__.overflow !== 'hide')
|
|
1338
1376
|
add(renderBounds, childrenRenderBounds);
|
|
1339
1377
|
}
|
|
1340
1378
|
else
|
|
1341
1379
|
this.__updateRectRenderBounds();
|
|
1342
|
-
|
|
1380
|
+
this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
|
|
1343
1381
|
}
|
|
1344
1382
|
__updateRectRenderBounds() { }
|
|
1345
1383
|
__updateRectChange() { }
|
|
@@ -1747,33 +1785,13 @@ Canvas = __decorate([
|
|
|
1747
1785
|
registerUI()
|
|
1748
1786
|
], Canvas);
|
|
1749
1787
|
|
|
1750
|
-
const { copyAndSpread, includes,
|
|
1788
|
+
const { copyAndSpread, includes, spread, setList } = BoundsHelper;
|
|
1751
1789
|
let Text = class Text extends UI {
|
|
1752
1790
|
get __tag() { return 'Text'; }
|
|
1753
|
-
get textDrawData() {
|
|
1754
|
-
this.__layout.update();
|
|
1755
|
-
return this.__.__textDrawData;
|
|
1756
|
-
}
|
|
1791
|
+
get textDrawData() { this.updateLayout(); return this.__.__textDrawData; }
|
|
1757
1792
|
constructor(data) {
|
|
1758
1793
|
super(data);
|
|
1759
1794
|
}
|
|
1760
|
-
__drawHitPath(canvas) {
|
|
1761
|
-
const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
|
|
1762
|
-
canvas.beginPath();
|
|
1763
|
-
if (this.__.__letterSpacing < 0) {
|
|
1764
|
-
this.__drawPathByData(canvas);
|
|
1765
|
-
}
|
|
1766
|
-
else {
|
|
1767
|
-
data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
__drawPathByData(drawer, _data) {
|
|
1771
|
-
const { x, y, width, height } = this.__layout.boxBounds;
|
|
1772
|
-
drawer.rect(x, y, width, height);
|
|
1773
|
-
}
|
|
1774
|
-
__drawRenderPath(canvas) {
|
|
1775
|
-
canvas.font = this.__.__font;
|
|
1776
|
-
}
|
|
1777
1795
|
__updateTextDrawData() {
|
|
1778
1796
|
const data = this.__;
|
|
1779
1797
|
const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data;
|
|
@@ -1790,15 +1808,16 @@ let Text = class Text extends UI {
|
|
|
1790
1808
|
const layout = this.__layout;
|
|
1791
1809
|
const { fontSize, italic, padding, __autoWidth: autoWidth, __autoHeight: autoHeight } = data;
|
|
1792
1810
|
this.__updateTextDrawData();
|
|
1793
|
-
const { bounds } = data.__textDrawData;
|
|
1811
|
+
const { bounds: contentBounds } = data.__textDrawData;
|
|
1794
1812
|
const b = layout.boxBounds;
|
|
1813
|
+
layout.contentBounds = contentBounds;
|
|
1795
1814
|
if (data.__lineHeight < fontSize)
|
|
1796
|
-
spread(
|
|
1815
|
+
spread(contentBounds, fontSize / 2);
|
|
1797
1816
|
if (autoWidth || autoHeight) {
|
|
1798
|
-
b.x = autoWidth ?
|
|
1799
|
-
b.y = autoHeight ?
|
|
1800
|
-
b.width = autoWidth ?
|
|
1801
|
-
b.height = autoHeight ?
|
|
1817
|
+
b.x = autoWidth ? contentBounds.x : 0;
|
|
1818
|
+
b.y = autoHeight ? contentBounds.y : 0;
|
|
1819
|
+
b.width = autoWidth ? contentBounds.width : data.width;
|
|
1820
|
+
b.height = autoHeight ? contentBounds.height : data.height;
|
|
1802
1821
|
if (padding) {
|
|
1803
1822
|
const [top, right, bottom, left] = data.__padding;
|
|
1804
1823
|
if (autoWidth)
|
|
@@ -1812,23 +1831,45 @@ let Text = class Text extends UI {
|
|
|
1812
1831
|
super.__updateBoxBounds();
|
|
1813
1832
|
if (italic)
|
|
1814
1833
|
b.width += fontSize * 0.16;
|
|
1815
|
-
const
|
|
1816
|
-
if (
|
|
1817
|
-
|
|
1818
|
-
layout.renderChanged = true;
|
|
1819
|
-
setList(data.__textBoxBounds = {}, [b, bounds]);
|
|
1820
|
-
}
|
|
1834
|
+
const isOverflow = !includes(b, contentBounds) || undefined;
|
|
1835
|
+
if (isOverflow)
|
|
1836
|
+
setList(data.__textBoxBounds = {}, [b, contentBounds]), layout.renderChanged = true;
|
|
1821
1837
|
else
|
|
1822
|
-
data.__textBoxBounds =
|
|
1838
|
+
data.__textBoxBounds = b;
|
|
1839
|
+
this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
|
|
1840
|
+
}
|
|
1841
|
+
__onUpdateSize() {
|
|
1842
|
+
if (this.__box)
|
|
1843
|
+
this.__box.__onUpdateSize();
|
|
1844
|
+
super.__onUpdateSize();
|
|
1823
1845
|
}
|
|
1824
1846
|
__updateRenderSpread() {
|
|
1825
1847
|
let width = super.__updateRenderSpread();
|
|
1826
1848
|
if (!width)
|
|
1827
|
-
width = this.
|
|
1849
|
+
width = this.isOverflow ? 1 : 0;
|
|
1828
1850
|
return width;
|
|
1829
1851
|
}
|
|
1830
1852
|
__updateRenderBounds() {
|
|
1831
|
-
|
|
1853
|
+
const { renderBounds, renderSpread } = this.__layout;
|
|
1854
|
+
copyAndSpread(renderBounds, this.__.__textBoxBounds, renderSpread);
|
|
1855
|
+
if (this.__box)
|
|
1856
|
+
this.__box.__layout.renderBounds = renderBounds;
|
|
1857
|
+
}
|
|
1858
|
+
__drawRenderPath(canvas) {
|
|
1859
|
+
canvas.font = this.__.__font;
|
|
1860
|
+
}
|
|
1861
|
+
__draw(canvas, options, originCanvas) {
|
|
1862
|
+
const box = this.__box;
|
|
1863
|
+
if (box)
|
|
1864
|
+
box.__nowWorld = this.__nowWorld, box.__draw(canvas, options, originCanvas);
|
|
1865
|
+
if (this.textEditing && !Export.running)
|
|
1866
|
+
return;
|
|
1867
|
+
super.__draw(canvas, options, originCanvas);
|
|
1868
|
+
}
|
|
1869
|
+
destroy() {
|
|
1870
|
+
if (this.boxStyle)
|
|
1871
|
+
this.boxStyle = null;
|
|
1872
|
+
super.destroy();
|
|
1832
1873
|
}
|
|
1833
1874
|
};
|
|
1834
1875
|
__decorate([
|
|
@@ -1840,6 +1881,9 @@ __decorate([
|
|
|
1840
1881
|
__decorate([
|
|
1841
1882
|
boundsType(0)
|
|
1842
1883
|
], Text.prototype, "height", void 0);
|
|
1884
|
+
__decorate([
|
|
1885
|
+
surfaceType()
|
|
1886
|
+
], Text.prototype, "boxStyle", void 0);
|
|
1843
1887
|
__decorate([
|
|
1844
1888
|
dataType(false)
|
|
1845
1889
|
], Text.prototype, "resizeFontSize", void 0);
|