-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Pattern.ts
83 lines (67 loc) · 2.05 KB
/
Pattern.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { ImageLike } from '../core/types';
import { SVGVNode } from '../svg/core';
type ImagePatternRepeat = 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat'
export interface PatternObjectBase {
id?: number
// type is now unused, so make it optional
type?: 'pattern'
x?: number
y?: number
rotation?: number
scaleX?: number
scaleY?: number
}
export interface ImagePatternObject extends PatternObjectBase {
image: ImageLike | string
repeat?: ImagePatternRepeat
/**
* Width and height of image.
* `imageWidth` and `imageHeight` are only used in svg-ssr renderer.
* Because we can't get the size of image in svg-ssr renderer.
* They need to be give explictly.
*/
imageWidth?: number
imageHeight?: number
}
export interface InnerImagePatternObject extends ImagePatternObject {
// Cached image. Which is created in the canvas painter.
__image?: ImageLike
}
export interface SVGPatternObject extends PatternObjectBase {
/**
* svg vnode can only be used in svg renderer currently.
* svgWidth, svgHeight defines width and height used for pattern.
*/
svgElement?: SVGVNode
svgWidth?: number
svgHeight?: number
}
export type PatternObject = ImagePatternObject | SVGPatternObject
class Pattern {
type: 'pattern'
image: ImageLike | string
/**
* svg element can only be used in svg renderer currently.
*
* Will be string if using SSR rendering.
*/
svgElement: SVGElement | string
repeat: ImagePatternRepeat
x: number
y: number
rotation: number
scaleX: number
scaleY: number
constructor(image: ImageLike | string, repeat: ImagePatternRepeat) {
// Should do nothing more in this constructor. Because gradient can be
// declard by `color: {image: ...}`, where this constructor will not be called.
this.image = image;
this.repeat = repeat;
this.x = 0;
this.y = 0;
this.rotation = 0;
this.scaleX = 1;
this.scaleY = 1;
}
}
export default Pattern;