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