@leafer-ui/display 1.5.3 → 1.6.1
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/package.json +8 -8
- package/src/Box.ts +2 -2
- package/src/Leafer.ts +2 -1
- package/src/Text.ts +53 -46
- package/src/UI.ts +8 -0
- package/types/index.d.ts +11 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/display",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "@leafer-ui/display",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.
|
|
26
|
-
"@leafer-ui/data": "1.
|
|
27
|
-
"@leafer-ui/display-module": "1.
|
|
28
|
-
"@leafer-ui/decorator": "1.
|
|
29
|
-
"@leafer-ui/external": "1.
|
|
25
|
+
"@leafer/core": "1.6.1",
|
|
26
|
+
"@leafer-ui/data": "1.6.1",
|
|
27
|
+
"@leafer-ui/display-module": "1.6.1",
|
|
28
|
+
"@leafer-ui/decorator": "1.6.1",
|
|
29
|
+
"@leafer-ui/external": "1.6.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@leafer/interface": "1.
|
|
33
|
-
"@leafer-ui/interface": "1.
|
|
32
|
+
"@leafer/interface": "1.6.1",
|
|
33
|
+
"@leafer-ui/interface": "1.6.1"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/Box.ts
CHANGED
|
@@ -102,11 +102,11 @@ export class Box extends Group implements IBox {
|
|
|
102
102
|
copy(childrenRenderBounds, renderBounds)
|
|
103
103
|
this.__updateRectRenderBounds()
|
|
104
104
|
|
|
105
|
-
isOverflow = !includes(renderBounds, childrenRenderBounds)
|
|
105
|
+
isOverflow = !includes(renderBounds, childrenRenderBounds) || undefined
|
|
106
106
|
if (isOverflow && this.__.overflow !== 'hide') add(renderBounds, childrenRenderBounds)
|
|
107
107
|
} else this.__updateRectRenderBounds()
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
this.isOverflow !== isOverflow && (this.isOverflow = isOverflow) // 节省赋值
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
@rewrite(rect.__updateRenderBounds)
|
package/src/Leafer.ts
CHANGED
package/src/Text.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ILeaferCanvas,
|
|
1
|
+
import { ILeaferCanvas, IBoolean, INumber, IString, IBoundsData, IUnitData, IRenderOptions } from '@leafer/interface'
|
|
2
2
|
import { BoundsHelper, boundsType, surfaceType, dataProcessor, registerUI, affectStrokeBoundsType, dataType, hitType, MathHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
|
-
import { IFill, IText, IFontWeight, ITextCase, ITextDecoration, ITextData, ITextInputData, ITextAlign, IVerticalAlign, ITextDrawData, IOverflow, IStrokeAlign, IHitType, ITextWrap, IWritingMode } from '@leafer-ui/interface'
|
|
4
|
+
import { IFill, IText, IFontWeight, ITextCase, ITextDecoration, ITextData, ITextInputData, ITextAlign, IVerticalAlign, ITextDrawData, IOverflow, IStrokeAlign, IHitType, ITextWrap, IWritingMode, IBackgroundBoxStyle } from '@leafer-ui/interface'
|
|
5
5
|
import { TextData } from '@leafer-ui/data'
|
|
6
6
|
|
|
7
|
-
import { TextConvert, UnitConvert } from '@leafer-ui/external'
|
|
7
|
+
import { TextConvert, UnitConvert, Export } from '@leafer-ui/external'
|
|
8
8
|
|
|
9
9
|
import { UI } from './UI'
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
const { copyAndSpread, includes,
|
|
12
|
+
const { copyAndSpread, includes, spread, setList } = BoundsHelper
|
|
13
13
|
|
|
14
14
|
@registerUI()
|
|
15
15
|
export class Text extends UI implements IText {
|
|
@@ -26,6 +26,9 @@ export class Text extends UI implements IText {
|
|
|
26
26
|
@boundsType(0)
|
|
27
27
|
declare public height?: INumber
|
|
28
28
|
|
|
29
|
+
@surfaceType()
|
|
30
|
+
public boxStyle: IBackgroundBoxStyle
|
|
31
|
+
|
|
29
32
|
@dataType(false)
|
|
30
33
|
public resizeFontSize?: IBoolean
|
|
31
34
|
|
|
@@ -89,35 +92,16 @@ export class Text extends UI implements IText {
|
|
|
89
92
|
@boundsType('show')
|
|
90
93
|
public textOverflow?: IOverflow | string
|
|
91
94
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return this.__.__textDrawData
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
constructor(data?: ITextInputData) {
|
|
99
|
-
super(data)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public __drawHitPath(canvas: ILeaferCanvas): void {
|
|
103
|
-
const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__
|
|
95
|
+
// @leafer-in/text-editor rewrite
|
|
96
|
+
public textEditing: boolean
|
|
104
97
|
|
|
105
|
-
|
|
98
|
+
public isOverflow: boolean
|
|
106
99
|
|
|
107
|
-
|
|
108
|
-
this.__drawPathByData(canvas)
|
|
109
|
-
} else {
|
|
110
|
-
data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight))
|
|
111
|
-
}
|
|
112
|
-
}
|
|
100
|
+
public get textDrawData(): ITextDrawData { this.updateLayout(); return this.__.__textDrawData }
|
|
113
101
|
|
|
114
|
-
public __drawPathByData(drawer: IPathDrawer, _data?: IPathCommandData): void {
|
|
115
|
-
const { x, y, width, height } = this.__layout.boxBounds
|
|
116
|
-
drawer.rect(x, y, width, height)
|
|
117
|
-
}
|
|
118
102
|
|
|
119
|
-
|
|
120
|
-
|
|
103
|
+
constructor(data?: ITextInputData) {
|
|
104
|
+
super(data)
|
|
121
105
|
}
|
|
122
106
|
|
|
123
107
|
public __updateTextDrawData(): void {
|
|
@@ -134,7 +118,7 @@ export class Text extends UI implements IText {
|
|
|
134
118
|
data.__textDrawData = TextConvert.getDrawData(data.text, this.__)
|
|
135
119
|
}
|
|
136
120
|
|
|
137
|
-
|
|
121
|
+
override __updateBoxBounds(): void {
|
|
138
122
|
|
|
139
123
|
const data = this.__
|
|
140
124
|
const layout = this.__layout
|
|
@@ -142,16 +126,18 @@ export class Text extends UI implements IText {
|
|
|
142
126
|
|
|
143
127
|
this.__updateTextDrawData() // layout text
|
|
144
128
|
|
|
145
|
-
const { bounds } = data.__textDrawData
|
|
129
|
+
const { bounds: contentBounds } = data.__textDrawData
|
|
146
130
|
const b = layout.boxBounds
|
|
147
131
|
|
|
148
|
-
|
|
132
|
+
layout.contentBounds = contentBounds
|
|
133
|
+
|
|
134
|
+
if (data.__lineHeight < fontSize) spread(contentBounds, fontSize / 2)
|
|
149
135
|
|
|
150
136
|
if (autoWidth || autoHeight) {
|
|
151
|
-
b.x = autoWidth ?
|
|
152
|
-
b.y = autoHeight ?
|
|
153
|
-
b.width = autoWidth ?
|
|
154
|
-
b.height = autoHeight ?
|
|
137
|
+
b.x = autoWidth ? contentBounds.x : 0
|
|
138
|
+
b.y = autoHeight ? contentBounds.y : 0
|
|
139
|
+
b.width = autoWidth ? contentBounds.width : data.width
|
|
140
|
+
b.height = autoHeight ? contentBounds.height : data.height
|
|
155
141
|
|
|
156
142
|
if (padding) {
|
|
157
143
|
const [top, right, bottom, left] = data.__padding
|
|
@@ -163,23 +149,44 @@ export class Text extends UI implements IText {
|
|
|
163
149
|
|
|
164
150
|
if (italic) b.width += fontSize * 0.16 // 倾斜会导致文本的bounds增大
|
|
165
151
|
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
152
|
+
const isOverflow = !includes(b, contentBounds) || undefined
|
|
153
|
+
if (isOverflow) setList(data.__textBoxBounds = {} as IBoundsData, [b, contentBounds]), layout.renderChanged = true
|
|
154
|
+
else data.__textBoxBounds = b
|
|
155
|
+
|
|
156
|
+
this.isOverflow !== isOverflow && (this.isOverflow = isOverflow) // 节省赋值
|
|
157
|
+
}
|
|
172
158
|
|
|
159
|
+
override __onUpdateSize(): void {
|
|
160
|
+
if (this.__box) this.__box.__onUpdateSize()
|
|
161
|
+
super.__onUpdateSize()
|
|
173
162
|
}
|
|
174
163
|
|
|
175
|
-
|
|
164
|
+
override __updateRenderSpread(): number {
|
|
176
165
|
let width = super.__updateRenderSpread()
|
|
177
|
-
if (!width) width = this.
|
|
166
|
+
if (!width) width = this.isOverflow ? 1 : 0
|
|
178
167
|
return width
|
|
179
168
|
}
|
|
180
169
|
|
|
181
|
-
|
|
182
|
-
|
|
170
|
+
override __updateRenderBounds(): void {
|
|
171
|
+
const { renderBounds, renderSpread } = this.__layout
|
|
172
|
+
copyAndSpread(renderBounds, this.__.__textBoxBounds, renderSpread)
|
|
173
|
+
if (this.__box) this.__box.__layout.renderBounds = renderBounds
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
override __drawRenderPath(canvas: ILeaferCanvas): void {
|
|
177
|
+
canvas.font = this.__.__font
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
override __draw(canvas: ILeaferCanvas, options: IRenderOptions, originCanvas?: ILeaferCanvas): void {
|
|
181
|
+
const box = this.__box
|
|
182
|
+
if (box) box.__nowWorld = this.__nowWorld, box.__draw(canvas, options, originCanvas)
|
|
183
|
+
if (this.textEditing && !Export.running) return
|
|
184
|
+
super.__draw(canvas, options, originCanvas)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
override destroy(): void {
|
|
188
|
+
if (this.boxStyle) this.boxStyle = null
|
|
189
|
+
super.destroy()
|
|
183
190
|
}
|
|
184
191
|
|
|
185
192
|
}
|
package/src/UI.ts
CHANGED
|
@@ -61,6 +61,13 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
|
|
|
61
61
|
public locked?: IBoolean
|
|
62
62
|
|
|
63
63
|
|
|
64
|
+
@surfaceType(false)
|
|
65
|
+
public dim?: IBoolean | INumber // 是否弱化内容,可设置具体透明度
|
|
66
|
+
|
|
67
|
+
@surfaceType(false)
|
|
68
|
+
public dimskip?: IBoolean // 跳过弱化,突出显示内容,不受dim影响
|
|
69
|
+
|
|
70
|
+
|
|
64
71
|
@sortType(0)
|
|
65
72
|
public zIndex?: INumber
|
|
66
73
|
|
|
@@ -353,6 +360,7 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
|
|
|
353
360
|
public set scale(value: INumber | IPointData) { MathHelper.assignScale(this as IScaleData, value) }
|
|
354
361
|
public get scale(): INumber | IPointData { return this.__.scale }
|
|
355
362
|
|
|
363
|
+
public __box?: IUI // 背景box, 一般用于文本背景框
|
|
356
364
|
public __animate?: IAnimate
|
|
357
365
|
|
|
358
366
|
public get pen(): IPathCreator {
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IString, INumber, IBoolean, IMaskType, IEraserType, IAlign, IUnitPointData, IPathCommandData, IPathCommandObject, IPathString, IWindingRule, IFlowType, IFourNumber, IGap, IPointGap, IFlowAlign, IFlowAxisAlign, IFlowWrap, IFlowBoxType, IAutoSize, IAutoBoxData, IConstraint, IRangeSize, IAxis, IBoundsData, IHitType, ICursorType, IFilter, ITransition, IUnitData, IObject, IPointData, IPathCreator, IValue, IFindCondition, ILeaferCanvas, IPathDrawer, IExportFileType, IJSONOptions, IPickOptions, IPickResult, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IBounds, IEventListenerId, ITimer, IControl, ILeaferType, IScreenSizeData, IResizeEvent, IZoomType, IClientPointData, IRenderOptions, ILeaferImage, ICanvasContext2DSettings, ICanvasContext2D } from '@leafer/interface';
|
|
2
2
|
import { Leaf, LeafList } from '@leafer/core';
|
|
3
|
-
import { IUI, IUIData, IUIInputData, ILeafer, IGroup, IBlendMode, IFill, IStroke, IStrokeAlign, IStrokeWidthString, IStrokeCap, IStrokeJoin, IDashPatternString, IArrowType, ICornerRadiusString, IShadowEffect, IShadowString, IBlurEffect, IGrayscaleEffect, IAnimation, IStates, IStateName, IStateStyle, IAnimate, IEditorConfig, IFindUIMethod, IKeyframe, IAnimateType, IExportOptions, IExportResult, IEditorConfigFunction, IEditToolFunction, IGroupData, IGroupInputData, IUIJSONData, IFindCondition as IFindCondition$1, ILeaferData, IApp, IEditorBase, IFunction, ILeaferInputData, IBox, IBoxData, IOverflow, IBoxInputData, IFrame, IFrameData, IFrameInputData, IRect, IRectData, IRectInputData, IEllipse, IEllipseData, IEllipseInputData, IPolygon, IPolygonData, IPolygonInputData, IStar, IStarData, IStarInputData, ILine, ILineData, ILineInputData, IImage, IImageData, IImageInputData, ICanvas, ICanvasData, ICanvasInputData, IText, ITextData, IHitType as IHitType$1, IFontWeight, ITextCase, ITextDecoration, IWritingMode, ITextAlign, IVerticalAlign, ITextWrap, ITextDrawData, ITextInputData, IPath, IPathData, IPathInputData, IPen, IPenData, IPathCommandData as IPathCommandData$1, IPenInputData, IPointData as IPointData$1 } from '@leafer-ui/interface';
|
|
3
|
+
import { IUI, IUIData, IUIInputData, ILeafer, IGroup, IBlendMode, IFill, IStroke, IStrokeAlign, IStrokeWidthString, IStrokeCap, IStrokeJoin, IDashPatternString, IArrowType, ICornerRadiusString, IShadowEffect, IShadowString, IBlurEffect, IGrayscaleEffect, IAnimation, IStates, IStateName, IStateStyle, IAnimate, IEditorConfig, IFindUIMethod, IKeyframe, IAnimateType, IExportOptions, IExportResult, IEditorConfigFunction, IEditToolFunction, IGroupData, IGroupInputData, IUIJSONData, IFindCondition as IFindCondition$1, ILeaferData, IApp, IEditorBase, IFunction, ILeaferInputData, IBox, IBoxData, IOverflow, IBoxInputData, IFrame, IFrameData, IFrameInputData, IRect, IRectData, IRectInputData, IEllipse, IEllipseData, IEllipseInputData, IPolygon, IPolygonData, IPolygonInputData, IStar, IStarData, IStarInputData, ILine, ILineData, ILineInputData, IImage, IImageData, IImageInputData, ICanvas, ICanvasData, ICanvasInputData, IText, ITextData, IBackgroundBoxStyle, IHitType as IHitType$1, IFontWeight, ITextCase, ITextDecoration, IWritingMode, ITextAlign, IVerticalAlign, ITextWrap, ITextDrawData, ITextInputData, IPath, IPathData, IPathInputData, IPen, IPenData, IPathCommandData as IPathCommandData$1, IPenInputData, IPointData as IPointData$1 } from '@leafer-ui/interface';
|
|
4
4
|
|
|
5
5
|
declare class UI extends Leaf implements IUI {
|
|
6
6
|
__: IUIData;
|
|
@@ -19,6 +19,8 @@ declare class UI extends Leaf implements IUI {
|
|
|
19
19
|
opacity?: INumber;
|
|
20
20
|
visible?: IBoolean | 0;
|
|
21
21
|
locked?: IBoolean;
|
|
22
|
+
dim?: IBoolean | INumber;
|
|
23
|
+
dimskip?: IBoolean;
|
|
22
24
|
zIndex?: INumber;
|
|
23
25
|
mask?: IBoolean | IMaskType;
|
|
24
26
|
eraser?: IBoolean | IEraserType;
|
|
@@ -109,6 +111,7 @@ declare class UI extends Leaf implements IUI {
|
|
|
109
111
|
data: IObject;
|
|
110
112
|
set scale(value: INumber | IPointData);
|
|
111
113
|
get scale(): INumber | IPointData;
|
|
114
|
+
__box?: IUI;
|
|
112
115
|
__animate?: IAnimate;
|
|
113
116
|
get pen(): IPathCreator;
|
|
114
117
|
editConfig: IEditorConfig;
|
|
@@ -390,6 +393,7 @@ declare class Text extends UI implements IText {
|
|
|
390
393
|
__: ITextData;
|
|
391
394
|
width?: INumber;
|
|
392
395
|
height?: INumber;
|
|
396
|
+
boxStyle: IBackgroundBoxStyle;
|
|
393
397
|
resizeFontSize?: IBoolean;
|
|
394
398
|
fill?: IFill;
|
|
395
399
|
strokeAlign?: IStrokeAlign;
|
|
@@ -411,15 +415,18 @@ declare class Text extends UI implements IText {
|
|
|
411
415
|
autoSizeAlign?: IBoolean;
|
|
412
416
|
textWrap?: ITextWrap;
|
|
413
417
|
textOverflow?: IOverflow | string;
|
|
418
|
+
textEditing: boolean;
|
|
419
|
+
isOverflow: boolean;
|
|
414
420
|
get textDrawData(): ITextDrawData;
|
|
415
421
|
constructor(data?: ITextInputData);
|
|
416
|
-
__drawHitPath(canvas: ILeaferCanvas): void;
|
|
417
|
-
__drawPathByData(drawer: IPathDrawer, _data?: IPathCommandData): void;
|
|
418
|
-
__drawRenderPath(canvas: ILeaferCanvas): void;
|
|
419
422
|
__updateTextDrawData(): void;
|
|
420
423
|
__updateBoxBounds(): void;
|
|
424
|
+
__onUpdateSize(): void;
|
|
421
425
|
__updateRenderSpread(): number;
|
|
422
426
|
__updateRenderBounds(): void;
|
|
427
|
+
__drawRenderPath(canvas: ILeaferCanvas): void;
|
|
428
|
+
__draw(canvas: ILeaferCanvas, options: IRenderOptions, originCanvas?: ILeaferCanvas): void;
|
|
429
|
+
destroy(): void;
|
|
423
430
|
}
|
|
424
431
|
|
|
425
432
|
declare class Path extends UI implements IPath {
|