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