forked from software-mansion/react-native-svg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.web.js
217 lines (184 loc) · 4.36 KB
/
index.web.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import { createElement } from 'react-native-web';
import { resolve } from './lib/resolve';
import { Component } from 'react';
/**
* `react-native-svg` supports additional props that aren't defined in the spec.
* This function replaces them in a spec conforming manner.
*
* @param {Object} props Properties given to us.
* @returns {Object} Cleaned object.
* @private
*/
function prepare(props) {
const {
translate,
scale,
rotation,
skewX,
skewY,
originX,
originY,
fontFamily,
fontSize,
fontWeight,
fontStyle,
style,
...clean
} = props;
const transform = [];
if (originX != null || originY != null) {
transform.push(`translate(${originX || 0}, ${originY || 0})`);
}
if (translate != null) {
transform.push(`translate(${translate})`);
}
if (scale != null) {
transform.push(`scale(${scale})`);
}
// rotation maps to rotate, not to collide with the text rotate attribute (which acts per glyph rather than block)
if (rotation != null) {
transform.push(`rotate(${rotation})`);
}
if (skewX != null) {
transform.push(`skewX(${skewX})`);
}
if (skewY != null) {
transform.push(`skewY(${skewY})`);
}
if (originX != null || originY != null) {
transform.push(`translate(${-originX || 0}, ${-originY || 0})`);
}
if (transform.length) {
clean.transform = transform.join(' ');
}
const styles = {};
if (fontFamily != null) {
styles.fontFamily = fontFamily;
}
if (fontSize != null) {
styles.fontSize = fontSize;
}
if (fontWeight != null) {
styles.fontWeight = fontWeight;
}
if (fontStyle != null) {
styles.fontStyle = fontStyle;
}
clean.style = resolve(style, styles);
return clean;
}
export class Circle extends Component {
render() {
return createElement('circle', prepare(this.props));
}
}
export class ClipPath extends Component {
render() {
return createElement('clipPath', prepare(this.props));
}
}
export class Defs extends Component {
render() {
return createElement('defs', prepare(this.props));
}
}
export class Ellipse extends Component {
render() {
return createElement('ellipse', prepare(this.props));
}
}
export class G extends Component {
render() {
const { x, y, ...rest } = this.props;
if ((x || y) && !rest.translate) {
rest.translate = `${x || 0}, ${y || 0}`;
}
return createElement('g', prepare(rest));
}
}
export class Image extends Component {
render() {
return createElement('image', prepare(this.props));
}
}
export class Line extends Component {
render() {
return createElement('line', prepare(this.props));
}
}
export class LinearGradient extends Component {
render() {
return createElement('linearGradient', prepare(this.props));
}
}
export class Path extends Component {
render() {
return createElement('path', prepare(this.props));
}
}
export class Polygon extends Component {
render() {
return createElement('polygon', prepare(this.props));
}
}
export class Polyline extends Component {
render() {
return createElement('polyline', prepare(this.props));
}
}
export class RadialGradient extends Component {
render() {
return createElement('radialGradient', prepare(this.props));
}
}
export class Rect extends Component {
render() {
return createElement('rect', prepare(this.props));
}
}
export class Stop extends Component {
render() {
return createElement('stop', prepare(this.props));
}
}
export class Svg extends Component {
render() {
return createElement('svg', prepare(this.props));
}
}
export class Symbol extends Component {
render() {
return createElement('symbol', prepare(this.props));
}
}
export class Text extends Component {
render() {
return createElement('text', prepare(this.props));
}
}
export class TSpan extends Component {
render() {
return createElement('tspan', prepare(this.props));
}
}
export class TextPath extends Component {
render() {
return createElement('textPath', prepare(this.props));
}
}
export class Use extends Component {
render() {
return createElement('use', prepare(this.props));
}
}
export class Mask extends Component {
render() {
return createElement('mask', prepare(this.props));
}
}
export class Pattern extends Component {
render() {
return createElement('pattern', prepare(this.props));
}
}
export default Svg;