@leafer-ui/data 1.0.0-beta.8 → 1.0.0-rc.10
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 +10 -6
- package/src/ArrowData.ts +8 -0
- package/src/ImageData.ts +26 -1
- package/src/UIData.ts +93 -21
- package/src/index.ts +1 -0
- package/types/index.d.ts +95 -0
package/package.json
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/data",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.10",
|
|
4
4
|
"description": "@leafer-ui/data",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
8
9
|
"files": [
|
|
9
|
-
"src"
|
|
10
|
+
"src",
|
|
11
|
+
"types",
|
|
12
|
+
"dist"
|
|
10
13
|
],
|
|
11
14
|
"repository": {
|
|
12
15
|
"type": "git",
|
|
13
16
|
"url": "https://github.com/leaferjs/ui.git"
|
|
14
17
|
},
|
|
15
|
-
"homepage": "https://github.com/leaferjs/ui/tree/main/packages/data",
|
|
18
|
+
"homepage": "https://github.com/leaferjs/ui/tree/main/packages/display-module/data",
|
|
16
19
|
"bugs": "https://github.com/leaferjs/ui/issues",
|
|
17
20
|
"keywords": [
|
|
18
21
|
"leafer-ui",
|
|
19
22
|
"leaferjs"
|
|
20
23
|
],
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"@leafer/core": "1.0.0-
|
|
25
|
+
"@leafer/core": "1.0.0-rc.10",
|
|
26
|
+
"@leafer-ui/external": "1.0.0-rc.10"
|
|
23
27
|
},
|
|
24
28
|
"devDependencies": {
|
|
25
|
-
"@leafer/interface": "1.0.0-
|
|
26
|
-
"@leafer-ui/interface": "1.0.0-
|
|
29
|
+
"@leafer/interface": "1.0.0-rc.10",
|
|
30
|
+
"@leafer-ui/interface": "1.0.0-rc.10"
|
|
27
31
|
}
|
|
28
32
|
}
|
package/src/ArrowData.ts
ADDED
package/src/ImageData.ts
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
|
-
import { IImageData } from '@leafer-ui/interface'
|
|
1
|
+
import { IImageData, IImageInputData, IImage, IObject } from '@leafer-ui/interface'
|
|
2
2
|
|
|
3
3
|
import { RectData } from './RectData'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export class ImageData extends RectData implements IImageData {
|
|
7
7
|
|
|
8
|
+
declare public __leaf: IImage
|
|
9
|
+
|
|
10
|
+
protected _url: string
|
|
11
|
+
|
|
12
|
+
protected setUrl(value: string) {
|
|
13
|
+
this.__setImageFill(value)
|
|
14
|
+
this._url = value
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public __setImageFill(value: string): void {
|
|
18
|
+
if (this.__leaf.image) this.__leaf.image = null;
|
|
19
|
+
(this as IImageInputData).fill = value ? { type: 'image', mode: 'strench', url: value } : undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public __getData(): IObject {
|
|
23
|
+
const data = super.__getData()
|
|
24
|
+
delete data.fill
|
|
25
|
+
return data
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public __getInputData(): IObject {
|
|
29
|
+
const data = super.__getInputData()
|
|
30
|
+
delete data.fill
|
|
31
|
+
return data
|
|
32
|
+
}
|
|
8
33
|
}
|
package/src/UIData.ts
CHANGED
|
@@ -1,52 +1,115 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LeafData } from '@leafer/core'
|
|
1
|
+
import { INumber, IValue, IBoolean } from '@leafer/interface'
|
|
2
|
+
import { LeafData, Debug } from '@leafer/core'
|
|
3
3
|
|
|
4
|
-
import { IShadowEffect, IUI, IUIData, IUnitData } from '@leafer-ui/interface'
|
|
5
|
-
import { Paint } from '@leafer-ui/external'
|
|
4
|
+
import { IShadowEffect, IUI, IUIData, IUnitData, ILeafPaint } from '@leafer-ui/interface'
|
|
5
|
+
import { Paint, PaintImage } from '@leafer-ui/external'
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
const emptyPaint: ILeafPaint = {}
|
|
9
|
+
const debug = Debug.get('UIData')
|
|
8
10
|
export class UIData extends LeafData implements IUIData {
|
|
9
11
|
|
|
10
|
-
public __leaf: IUI
|
|
12
|
+
declare public __leaf: IUI
|
|
11
13
|
|
|
12
|
-
public __blendLayer?: boolean
|
|
14
|
+
public __blendLayer?: boolean // 非元素属性必须以两个下划线开头
|
|
13
15
|
|
|
14
16
|
public __isFills?: boolean
|
|
15
17
|
public __isStrokes?: boolean
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
public get __strokeWidth(): number {
|
|
20
|
+
const { strokeWidth, strokeWidthFixed } = this as IUIData
|
|
21
|
+
if (strokeWidthFixed) {
|
|
22
|
+
let { scaleX } = this.__leaf.__world
|
|
23
|
+
if (scaleX < 0) scaleX = -scaleX
|
|
24
|
+
return scaleX > 1 ? strokeWidth / scaleX : strokeWidth
|
|
25
|
+
} else {
|
|
26
|
+
return strokeWidth
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public __pixelFill?: boolean // png / svg / webp
|
|
31
|
+
public __pixelStroke?: boolean
|
|
32
|
+
|
|
33
|
+
public __needComputePaint: boolean
|
|
34
|
+
|
|
35
|
+
protected _visible?: IBoolean
|
|
36
|
+
|
|
37
|
+
protected _width?: INumber
|
|
38
|
+
protected _height?: INumber
|
|
19
39
|
|
|
20
|
-
protected
|
|
21
|
-
protected
|
|
40
|
+
protected _fill?: IValue
|
|
41
|
+
protected _stroke?: IValue
|
|
22
42
|
|
|
43
|
+
protected _shadow?: IValue
|
|
44
|
+
protected _innerShadow?: IValue
|
|
23
45
|
|
|
24
|
-
|
|
46
|
+
public get __autoWidth() { return !this._width }
|
|
47
|
+
public get __autoHeight() { return !this._height }
|
|
48
|
+
public get __autoBounds() { return !this._width && !this._height }
|
|
49
|
+
|
|
50
|
+
protected setVisible(value: IBoolean) {
|
|
51
|
+
if (this.__leaf.leafer) this.__leaf.leafer.watcher.hasVisible = true
|
|
52
|
+
this._visible = value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
protected setWidth(value: INumber) {
|
|
56
|
+
if (value < 0) {
|
|
57
|
+
this._width = -value
|
|
58
|
+
this.__leaf.scaleX *= -1
|
|
59
|
+
debug.warn('width < 0, instead -scaleX ', this)
|
|
60
|
+
} else {
|
|
61
|
+
this._width = value
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected setHeight(value: INumber) {
|
|
66
|
+
if (value < 0) {
|
|
67
|
+
this._height = -value
|
|
68
|
+
this.__leaf.scaleY *= -1
|
|
69
|
+
debug.warn('height < 0, instead -scaleY', this)
|
|
70
|
+
} else {
|
|
71
|
+
this._height = value
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
protected setFill(value: IValue) {
|
|
77
|
+
if (this.__naturalWidth) this.__naturalWidth = this.__naturalHeight = undefined
|
|
25
78
|
if (typeof value === 'string' || !value) {
|
|
79
|
+
if (this.__isFills) {
|
|
80
|
+
this.__removeInput('fill')
|
|
81
|
+
PaintImage.recycleImage('fill', this)
|
|
82
|
+
this.__isFills = false
|
|
83
|
+
if (this.__pixelFill) this.__pixelFill = false
|
|
84
|
+
}
|
|
26
85
|
this._fill = value
|
|
27
|
-
if (this.__input) this.__removeInput('fill')
|
|
28
|
-
this.__isFills && (this.__isFills = false)
|
|
29
86
|
} else if (typeof value === 'object') {
|
|
30
87
|
this.__setInput('fill', value)
|
|
31
|
-
this.__leaf.__layout.boxChanged
|
|
88
|
+
this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange()
|
|
32
89
|
this.__isFills = true
|
|
90
|
+
this._fill || (this._fill = emptyPaint)
|
|
33
91
|
}
|
|
34
|
-
if (this.__naturalWidth) this.__naturalWidth = this.__naturalHeight = undefined
|
|
35
92
|
}
|
|
36
93
|
|
|
37
|
-
protected setStroke(value:
|
|
94
|
+
protected setStroke(value: IValue) {
|
|
38
95
|
if (typeof value === 'string' || !value) {
|
|
96
|
+
if (this.__isStrokes) {
|
|
97
|
+
this.__removeInput('stroke')
|
|
98
|
+
PaintImage.recycleImage('stroke', this)
|
|
99
|
+
this.__isStrokes = false
|
|
100
|
+
if (this.__pixelStroke) this.__pixelStroke = false
|
|
101
|
+
}
|
|
39
102
|
this._stroke = value
|
|
40
|
-
if (this.__input) this.__removeInput('stroke')
|
|
41
|
-
this.__isStrokes && (this.__isStrokes = false)
|
|
42
103
|
} else if (typeof value === 'object') {
|
|
43
104
|
this.__setInput('stroke', value)
|
|
44
|
-
this.__leaf.__layout.boxChanged
|
|
105
|
+
this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange()
|
|
45
106
|
this.__isStrokes = true
|
|
107
|
+
this._stroke || (this._stroke = emptyPaint)
|
|
46
108
|
}
|
|
47
109
|
}
|
|
48
110
|
|
|
49
|
-
|
|
111
|
+
|
|
112
|
+
protected setShadow(value: IValue) {
|
|
50
113
|
this.__setInput('shadow', value)
|
|
51
114
|
if (value instanceof Array) {
|
|
52
115
|
if (value.some((item: IShadowEffect) => item.visible === false)) value = value.filter((item: IShadowEffect) => item.visible !== false)
|
|
@@ -58,7 +121,7 @@ export class UIData extends LeafData implements IUIData {
|
|
|
58
121
|
}
|
|
59
122
|
}
|
|
60
123
|
|
|
61
|
-
protected setInnerShadow(value:
|
|
124
|
+
protected setInnerShadow(value: IValue) {
|
|
62
125
|
this.__setInput('innerShadow', value)
|
|
63
126
|
if (value instanceof Array) {
|
|
64
127
|
if (value.some((item: IShadowEffect) => item.visible === false)) value = value.filter((item: IShadowEffect) => item.visible !== false)
|
|
@@ -70,6 +133,15 @@ export class UIData extends LeafData implements IUIData {
|
|
|
70
133
|
}
|
|
71
134
|
}
|
|
72
135
|
|
|
136
|
+
// custom
|
|
137
|
+
|
|
138
|
+
public __computePaint(): void {
|
|
139
|
+
const { fill, stroke } = this.__input
|
|
140
|
+
if (fill) Paint.compute('fill', this.__leaf)
|
|
141
|
+
if (stroke) Paint.compute('stroke', this.__leaf)
|
|
142
|
+
this.__needComputePaint = false
|
|
143
|
+
}
|
|
144
|
+
|
|
73
145
|
}
|
|
74
146
|
|
|
75
147
|
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { LeaferData } from './LeaferData'
|
|
|
6
6
|
export { FrameData } from './FrameData'
|
|
7
7
|
|
|
8
8
|
export { LineData } from './LineData'
|
|
9
|
+
export { ArrowData } from './ArrowData'
|
|
9
10
|
export { RectData } from './RectData'
|
|
10
11
|
export { EllipseData } from './EllipseData'
|
|
11
12
|
export { PolygonData } from './PolygonData'
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { IBoolean, INumber, IValue, IPathCommandData } from '@leafer/interface';
|
|
2
|
+
import { LeafData } from '@leafer/core';
|
|
3
|
+
import { IUIData, IUI, IUnitData, IGroupData, IBoxData, ILeaferData, IFrameData, ILineData, IArrowData, IRectData, IEllipseData, IPolygonData, IStarData, IPathString, IPenData, ITextData, IFontWeight, IImageData, IImage, IObject, ICanvasData } from '@leafer-ui/interface';
|
|
4
|
+
|
|
5
|
+
declare class UIData extends LeafData implements IUIData {
|
|
6
|
+
__leaf: IUI;
|
|
7
|
+
__blendLayer?: boolean;
|
|
8
|
+
__isFills?: boolean;
|
|
9
|
+
__isStrokes?: boolean;
|
|
10
|
+
get __strokeWidth(): number;
|
|
11
|
+
__pixelFill?: boolean;
|
|
12
|
+
__pixelStroke?: boolean;
|
|
13
|
+
__needComputePaint: boolean;
|
|
14
|
+
protected _visible?: IBoolean;
|
|
15
|
+
protected _width?: INumber;
|
|
16
|
+
protected _height?: INumber;
|
|
17
|
+
protected _fill?: IValue;
|
|
18
|
+
protected _stroke?: IValue;
|
|
19
|
+
protected _shadow?: IValue;
|
|
20
|
+
protected _innerShadow?: IValue;
|
|
21
|
+
get __autoWidth(): boolean;
|
|
22
|
+
get __autoHeight(): boolean;
|
|
23
|
+
get __autoBounds(): boolean;
|
|
24
|
+
protected setVisible(value: IBoolean): void;
|
|
25
|
+
protected setWidth(value: INumber): void;
|
|
26
|
+
protected setHeight(value: INumber): void;
|
|
27
|
+
protected setFill(value: IValue): void;
|
|
28
|
+
protected setStroke(value: IValue): void;
|
|
29
|
+
protected setShadow(value: IValue): void;
|
|
30
|
+
protected setInnerShadow(value: IValue): void;
|
|
31
|
+
__computePaint(): void;
|
|
32
|
+
}
|
|
33
|
+
declare const UnitConvert: {
|
|
34
|
+
number(value: number | IUnitData, percentRefer?: number): number;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
declare class GroupData extends UIData implements IGroupData {
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare class BoxData extends GroupData implements IBoxData {
|
|
41
|
+
get __boxStroke(): boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare class LeaferData extends GroupData implements ILeaferData {
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare class FrameData extends BoxData implements IFrameData {
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class LineData extends UIData implements ILineData {
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare class ArrowData extends LineData implements IArrowData {
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare class RectData extends UIData implements IRectData {
|
|
57
|
+
get __boxStroke(): boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare class EllipseData extends UIData implements IEllipseData {
|
|
61
|
+
get __boxStroke(): boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare class PolygonData extends UIData implements IPolygonData {
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare class StarData extends UIData implements IStarData {
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare class PathData extends UIData {
|
|
71
|
+
protected _path: IPathCommandData;
|
|
72
|
+
protected setPath(value: IPathCommandData | IPathString): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare class PenData extends GroupData implements IPenData {
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
declare class TextData extends UIData implements ITextData {
|
|
79
|
+
protected _fontWeight?: number;
|
|
80
|
+
setFontWeight(value: IFontWeight): void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare class ImageData extends RectData implements IImageData {
|
|
84
|
+
__leaf: IImage;
|
|
85
|
+
protected _url: string;
|
|
86
|
+
protected setUrl(value: string): void;
|
|
87
|
+
__setImageFill(value: string): void;
|
|
88
|
+
__getData(): IObject;
|
|
89
|
+
__getInputData(): IObject;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare class CanvasData extends RectData implements ICanvasData {
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { ArrowData, BoxData, CanvasData, EllipseData, FrameData, GroupData, ImageData, LeaferData, LineData, PathData, PenData, PolygonData, RectData, StarData, TextData, UIData, UnitConvert };
|