@leafer-ui/data 1.0.5 → 1.0.6
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 +5 -5
- package/src/BoxData.ts +8 -1
- package/src/CanvasData.ts +6 -3
- package/src/EllipseData.ts +1 -1
- package/src/ImageData.ts +3 -3
- package/src/LeaferData.ts +3 -3
- package/src/PathData.ts +1 -1
- package/src/RectData.ts +1 -1
- package/src/UIData.ts +18 -37
- package/src/index.ts +1 -1
- package/types/index.d.ts +14 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/data",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "@leafer-ui/data",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.0.
|
|
26
|
-
"@leafer-ui/external": "1.0.
|
|
25
|
+
"@leafer/core": "1.0.6",
|
|
26
|
+
"@leafer-ui/external": "1.0.6"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.0.
|
|
30
|
-
"@leafer-ui/interface": "1.0.
|
|
29
|
+
"@leafer/interface": "1.0.6",
|
|
30
|
+
"@leafer-ui/interface": "1.0.6"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/BoxData.ts
CHANGED
|
@@ -4,5 +4,12 @@ import { GroupData } from "./GroupData"
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export class BoxData extends GroupData implements IBoxData {
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
public get __boxStroke(): boolean { return !(this as IBoxData).__pathInputed }
|
|
9
|
+
|
|
10
|
+
// 路径与圆角直接当溢出处理
|
|
11
|
+
public get __drawAfterFill(): boolean { return (this as IBoxData).overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length as unknown as boolean }
|
|
12
|
+
|
|
13
|
+
public get __clipAfterFill(): boolean { return this.__leaf.isOverflow || super.__clipAfterFill }
|
|
14
|
+
|
|
8
15
|
}
|
package/src/CanvasData.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { ICanvas, ICanvasData, ICanvasInputData, IObject } from '@leafer-ui/interface'
|
|
1
|
+
import { ICanvas, ICanvasData, ICanvasInputData, IObject, IJSONOptions } from '@leafer-ui/interface'
|
|
2
2
|
|
|
3
3
|
import { RectData } from './RectData'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export class CanvasData extends RectData implements ICanvasData {
|
|
7
7
|
|
|
8
|
-
public
|
|
9
|
-
|
|
8
|
+
public get __isCanvas(): boolean { return true }
|
|
9
|
+
public get __drawAfterFill(): boolean { return true }
|
|
10
|
+
|
|
11
|
+
public __getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject {
|
|
12
|
+
const data: ICanvasInputData = super.__getInputData(names, options)
|
|
10
13
|
data.url = (this.__leaf as ICanvas).canvas.toDataURL('image/png') as string
|
|
11
14
|
return data
|
|
12
15
|
}
|
package/src/EllipseData.ts
CHANGED
package/src/ImageData.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IImageData, IImageInputData, IImage, IObject } from '@leafer-ui/interface'
|
|
1
|
+
import { IImageData, IImageInputData, IImage, IObject, IJSONOptions } from '@leafer-ui/interface'
|
|
2
2
|
|
|
3
3
|
import { RectData } from './RectData'
|
|
4
4
|
|
|
@@ -25,8 +25,8 @@ export class ImageData extends RectData implements IImageData {
|
|
|
25
25
|
return data
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
public __getInputData(): IObject {
|
|
29
|
-
const data = super.__getInputData()
|
|
28
|
+
public __getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject {
|
|
29
|
+
const data = super.__getInputData(names, options)
|
|
30
30
|
delete data.fill
|
|
31
31
|
return data
|
|
32
32
|
}
|
package/src/LeaferData.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { canvasSizeAttrs } from '@leafer/core'
|
|
2
2
|
|
|
3
|
-
import { ILeaferData, IObject } from '@leafer-ui/interface'
|
|
3
|
+
import { ILeaferData, IObject, IJSONOptions } from '@leafer-ui/interface'
|
|
4
4
|
|
|
5
5
|
import { GroupData } from './GroupData'
|
|
6
6
|
|
|
7
7
|
export class LeaferData extends GroupData implements ILeaferData {
|
|
8
8
|
|
|
9
|
-
public __getInputData(): IObject {
|
|
10
|
-
const data = super.__getInputData()
|
|
9
|
+
public __getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject {
|
|
10
|
+
const data = super.__getInputData(names, options)
|
|
11
11
|
canvasSizeAttrs.forEach(key => delete (data as IObject)[key])
|
|
12
12
|
return data
|
|
13
13
|
}
|
package/src/PathData.ts
CHANGED
package/src/RectData.ts
CHANGED
package/src/UIData.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { INumber, IValue, IBoolean, IPathCommandData, IPathString, IPointData } from '@leafer/interface'
|
|
1
|
+
import { INumber, IValue, IBoolean, IPathCommandData, IPathString, IPointData, IPathCommandObject } from '@leafer/interface'
|
|
2
2
|
import { PathConvert, LeafData, Debug } from '@leafer/core'
|
|
3
3
|
|
|
4
|
-
import { IShadowEffect, IUI, IUIData,
|
|
4
|
+
import { IShadowEffect, IUI, IUIData, ILeafPaint } from '@leafer-ui/interface'
|
|
5
5
|
import { Paint, PaintImage } from '@leafer-ui/external'
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
const { parse } = PathConvert
|
|
8
|
+
const { parse, objectToCanvasData } = PathConvert
|
|
9
9
|
const emptyPaint: ILeafPaint = {}
|
|
10
10
|
const debug = Debug.get('UIData')
|
|
11
11
|
export class UIData extends LeafData implements IUIData {
|
|
@@ -26,14 +26,16 @@ export class UIData extends LeafData implements IUIData {
|
|
|
26
26
|
let { scaleX } = ui.__nowWorld || ui.__world
|
|
27
27
|
if (scaleX < 0) scaleX = -scaleX
|
|
28
28
|
return scaleX > 1 ? strokeWidth / scaleX : strokeWidth
|
|
29
|
-
} else
|
|
30
|
-
return strokeWidth
|
|
31
|
-
}
|
|
29
|
+
} else return strokeWidth
|
|
32
30
|
}
|
|
33
31
|
|
|
32
|
+
public get __hasStroke(): boolean { return (this as IUIData).stroke && (this as IUIData).strokeWidth as unknown as boolean }
|
|
33
|
+
|
|
34
34
|
public __pixelFill?: boolean // png / svg / webp
|
|
35
35
|
public __pixelStroke?: boolean
|
|
36
36
|
|
|
37
|
+
public get __clipAfterFill(): boolean { return ((this as IUIData).cornerRadius || (this as IUIData).__pathInputed) as unknown as boolean } // 用于 __drawAfterFill()
|
|
38
|
+
|
|
37
39
|
public __needComputePaint: boolean
|
|
38
40
|
|
|
39
41
|
protected _visible?: IBoolean
|
|
@@ -67,9 +69,7 @@ export class UIData extends LeafData implements IUIData {
|
|
|
67
69
|
this._width = -value
|
|
68
70
|
this.__leaf.scaleX *= -1
|
|
69
71
|
debug.warn('width < 0, instead -scaleX ', this)
|
|
70
|
-
} else
|
|
71
|
-
this._width = value
|
|
72
|
-
}
|
|
72
|
+
} else this._width = value
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
protected setHeight(value: INumber) {
|
|
@@ -77,9 +77,7 @@ export class UIData extends LeafData implements IUIData {
|
|
|
77
77
|
this._height = -value
|
|
78
78
|
this.__leaf.scaleY *= -1
|
|
79
79
|
debug.warn('height < 0, instead -scaleY', this)
|
|
80
|
-
} else
|
|
81
|
-
this._height = value
|
|
82
|
-
}
|
|
80
|
+
} else this._height = value
|
|
83
81
|
}
|
|
84
82
|
|
|
85
83
|
|
|
@@ -119,13 +117,14 @@ export class UIData extends LeafData implements IUIData {
|
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
|
|
122
|
-
protected setPath(value: IPathCommandData | IPathString) {
|
|
123
|
-
|
|
120
|
+
protected setPath(value: IPathCommandData | IPathCommandObject[] | IPathString) {
|
|
121
|
+
const isString = typeof value === 'string'
|
|
122
|
+
if (isString || (value && typeof value[0] === 'object')) {
|
|
124
123
|
this.__setInput('path', value)
|
|
125
|
-
this._path = parse(value)
|
|
124
|
+
this._path = isString ? parse(value) : objectToCanvasData(value as IPathCommandObject[])
|
|
126
125
|
} else {
|
|
127
126
|
if (this.__input) this.__removeInput('path')
|
|
128
|
-
this._path = value
|
|
127
|
+
this._path = value as IPathCommandData
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
130
|
|
|
@@ -135,11 +134,7 @@ export class UIData extends LeafData implements IUIData {
|
|
|
135
134
|
if (value instanceof Array) {
|
|
136
135
|
if (value.some((item: IShadowEffect) => item.visible === false)) value = value.filter((item: IShadowEffect) => item.visible !== false)
|
|
137
136
|
this._shadow = value.length ? value : null
|
|
138
|
-
} else
|
|
139
|
-
this._shadow = (value as IShadowEffect).visible === false ? null : [value]
|
|
140
|
-
} else {
|
|
141
|
-
this._shadow = null
|
|
142
|
-
}
|
|
137
|
+
} else this._shadow = value && (value as IShadowEffect).visible !== false ? [value] : null
|
|
143
138
|
}
|
|
144
139
|
|
|
145
140
|
protected setInnerShadow(value: IValue) {
|
|
@@ -147,11 +142,7 @@ export class UIData extends LeafData implements IUIData {
|
|
|
147
142
|
if (value instanceof Array) {
|
|
148
143
|
if (value.some((item: IShadowEffect) => item.visible === false)) value = value.filter((item: IShadowEffect) => item.visible !== false)
|
|
149
144
|
this._innerShadow = value.length ? value : null
|
|
150
|
-
} else
|
|
151
|
-
this._innerShadow = (value as IShadowEffect).visible === false ? null : [value]
|
|
152
|
-
} else {
|
|
153
|
-
this._innerShadow = null
|
|
154
|
-
}
|
|
145
|
+
} else this._innerShadow = value && (value as IShadowEffect).visible !== false ? [value] : null
|
|
155
146
|
}
|
|
156
147
|
|
|
157
148
|
// custom
|
|
@@ -163,14 +154,4 @@ export class UIData extends LeafData implements IUIData {
|
|
|
163
154
|
this.__needComputePaint = false
|
|
164
155
|
}
|
|
165
156
|
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
export const UnitConvert = {
|
|
170
|
-
|
|
171
|
-
number(value: number | IUnitData, percentRefer?: number): number {
|
|
172
|
-
if (typeof value === 'object') return value.type === 'percent' ? value.value * percentRefer : value.value
|
|
173
|
-
return value
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
}
|
|
157
|
+
}
|
package/src/index.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { INumber, IPointData, IBoolean, IValue, IPathCommandData, IPathString } from '@leafer/interface';
|
|
1
|
+
import { INumber, IPointData, IBoolean, IValue, IPathCommandData, IPathCommandObject, IPathString } from '@leafer/interface';
|
|
2
2
|
import { LeafData } from '@leafer/core';
|
|
3
|
-
import { IUIData, IUI,
|
|
3
|
+
import { IUIData, IUI, IGroupData, IBoxData, ILeaferData, IObject, IJSONOptions, IFrameData, ILineData, IRectData, IEllipseData, IPolygonData, IStarData, IPathData, IPenData, ITextData, IFontWeight, IImageData, IImage, ICanvasData } from '@leafer-ui/interface';
|
|
4
4
|
|
|
5
5
|
declare class UIData extends LeafData implements IUIData {
|
|
6
6
|
__leaf: IUI;
|
|
@@ -9,8 +9,10 @@ declare class UIData extends LeafData implements IUIData {
|
|
|
9
9
|
__isFills?: boolean;
|
|
10
10
|
__isStrokes?: boolean;
|
|
11
11
|
get __strokeWidth(): number;
|
|
12
|
+
get __hasStroke(): boolean;
|
|
12
13
|
__pixelFill?: boolean;
|
|
13
14
|
__pixelStroke?: boolean;
|
|
15
|
+
get __clipAfterFill(): boolean;
|
|
14
16
|
__needComputePaint: boolean;
|
|
15
17
|
protected _visible?: IBoolean;
|
|
16
18
|
protected _width?: INumber;
|
|
@@ -29,24 +31,23 @@ declare class UIData extends LeafData implements IUIData {
|
|
|
29
31
|
protected setHeight(value: INumber): void;
|
|
30
32
|
protected setFill(value: IValue): void;
|
|
31
33
|
protected setStroke(value: IValue): void;
|
|
32
|
-
protected setPath(value: IPathCommandData | IPathString): void;
|
|
34
|
+
protected setPath(value: IPathCommandData | IPathCommandObject[] | IPathString): void;
|
|
33
35
|
protected setShadow(value: IValue): void;
|
|
34
36
|
protected setInnerShadow(value: IValue): void;
|
|
35
37
|
__computePaint(): void;
|
|
36
38
|
}
|
|
37
|
-
declare const UnitConvert: {
|
|
38
|
-
number(value: number | IUnitData, percentRefer?: number): number;
|
|
39
|
-
};
|
|
40
39
|
|
|
41
40
|
declare class GroupData extends UIData implements IGroupData {
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
declare class BoxData extends GroupData implements IBoxData {
|
|
45
44
|
get __boxStroke(): boolean;
|
|
45
|
+
get __drawAfterFill(): boolean;
|
|
46
|
+
get __clipAfterFill(): boolean;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
declare class LeaferData extends GroupData implements ILeaferData {
|
|
49
|
-
__getInputData(): IObject;
|
|
50
|
+
__getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
declare class FrameData extends BoxData implements IFrameData {
|
|
@@ -70,6 +71,7 @@ declare class StarData extends UIData implements IStarData {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
declare class PathData extends UIData implements IPathData {
|
|
74
|
+
get __pathInputed(): number;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
declare class PenData extends GroupData implements IPenData {
|
|
@@ -87,11 +89,13 @@ declare class ImageData extends RectData implements IImageData {
|
|
|
87
89
|
protected setUrl(value: string): void;
|
|
88
90
|
__setImageFill(value: string): void;
|
|
89
91
|
__getData(): IObject;
|
|
90
|
-
__getInputData(): IObject;
|
|
92
|
+
__getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject;
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
declare class CanvasData extends RectData implements ICanvasData {
|
|
94
|
-
|
|
96
|
+
get __isCanvas(): boolean;
|
|
97
|
+
get __drawAfterFill(): boolean;
|
|
98
|
+
__getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
export { BoxData, CanvasData, EllipseData, FrameData, GroupData, ImageData, LeaferData, LineData, PathData, PenData, PolygonData, RectData, StarData, TextData, UIData
|
|
101
|
+
export { BoxData, CanvasData, EllipseData, FrameData, GroupData, ImageData, LeaferData, LineData, PathData, PenData, PolygonData, RectData, StarData, TextData, UIData };
|