jmgraph 3.2.16 → 3.2.18
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/LICENSE +21 -21
- package/README.md +251 -428
- package/build/gulpfile.js +142 -142
- package/build/package-lock.json +10666 -0
- package/build/package.json +71 -71
- package/dev.js +9 -9
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +3500 -2668
- package/dist/jmgraph.min.js +1 -1
- package/example/ball.html +216 -216
- package/example/base.html +111 -111
- package/example/canvas.html +53 -53
- package/example/cell.html +283 -283
- package/example/controls/arc.html +128 -128
- package/example/controls/arrowline.html +77 -77
- package/example/controls/bezier.html +298 -298
- package/example/controls/img.html +96 -96
- package/example/controls/label.html +86 -86
- package/example/controls/line.html +172 -172
- package/example/controls/prismatic.html +62 -62
- package/example/controls/rect.html +63 -63
- package/example/controls/resize.html +111 -111
- package/example/controls/test.html +359 -359
- package/example/es.html +69 -69
- package/example/es5module.html +62 -63
- package/example/heartarc.html +115 -115
- package/example/index.html +46 -46
- package/example/js/require.js +4 -4
- package/example/love/img/bling/bling.tps +265 -265
- package/example/love/img/bling.json +87 -87
- package/example/love/img/bling.tps +295 -295
- package/example/love/img/love.json +95 -95
- package/example/love/img/love.tps +315 -315
- package/example/love/img/qq/qq.tps +399 -399
- package/example/love/img/qq.json +242 -242
- package/example/love/index.html +40 -40
- package/example/love/js/game.js +558 -558
- package/example/music.html +210 -210
- package/example/node/test.js +137 -137
- package/example/pdf.html +186 -186
- package/example/progress.html +172 -172
- package/example/pso.html +147 -147
- package/example/sort.html +804 -815
- package/example/tweenjs.html +83 -83
- package/example/webgl.html +278 -278
- package/example/xfj/index.html +331 -331
- package/example/xfj/shake.js +48 -48
- package/example/xfj/testori.html +75 -75
- package/index.js +99 -99
- package/package.json +58 -56
- package/src/core/jmControl.js +1376 -1531
- package/src/core/jmEvents.js +240 -281
- package/src/core/jmGradient.js +231 -231
- package/src/core/jmGraph.js +569 -569
- package/src/core/jmList.js +92 -157
- package/src/core/jmObject.js +83 -103
- package/src/core/jmPath.js +35 -35
- package/src/core/jmProperty.js +71 -110
- package/src/core/jmShadow.js +65 -65
- package/src/core/jmUtils.js +906 -919
- package/src/lib/earcut.js +680 -680
- package/src/lib/earcut.md +73 -73
- package/src/lib/webgl/base.js +522 -452
- package/src/lib/webgl/core/buffer.js +48 -48
- package/src/lib/webgl/core/mapSize.js +40 -40
- package/src/lib/webgl/core/mapType.js +43 -43
- package/src/lib/webgl/core/program.js +138 -138
- package/src/lib/webgl/core/shader.js +13 -13
- package/src/lib/webgl/core/texture.js +60 -60
- package/src/lib/webgl/gradient.js +168 -168
- package/src/lib/webgl/index.js +137 -11
- package/src/lib/webgl/path.js +568 -561
- package/src/shapes/jmArrowLine.js +36 -36
- package/src/shapes/jmImage.js +244 -244
- package/src/shapes/jmLabel.js +271 -271
- package/src/shapes/jmResize.js +332 -330
package/src/core/jmGradient.js
CHANGED
|
@@ -1,231 +1,231 @@
|
|
|
1
|
-
import {jmUtils} from "./jmUtils.js";
|
|
2
|
-
import {jmList} from "./jmList.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 渐变类
|
|
6
|
-
*
|
|
7
|
-
* @class jmGradient
|
|
8
|
-
* @param {object} op 渐变参数,type:[linear= 线性渐变,radial=放射性渐变]
|
|
9
|
-
*/
|
|
10
|
-
export default class jmGradient {
|
|
11
|
-
constructor(opt) {
|
|
12
|
-
this.stops = new jmList();
|
|
13
|
-
|
|
14
|
-
if(opt && typeof opt == 'object') {
|
|
15
|
-
for(let k in opt) {
|
|
16
|
-
if(k === 'stops') continue;
|
|
17
|
-
this[k] = opt[k];
|
|
18
|
-
}
|
|
19
|
-
if(opt.stops && Array.isArray(opt.stops)) {
|
|
20
|
-
this.stops.push(...opt.stops);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
//解析字符串格式
|
|
24
|
-
//linear-gradient(direction, color-stop1, color-stop2, ...);
|
|
25
|
-
//radial-gradient(center, shape size, start-color, ..., last-color);
|
|
26
|
-
else if(typeof opt == 'string') {
|
|
27
|
-
this.fromString(opt);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 添加渐变色
|
|
32
|
-
*
|
|
33
|
-
* @method addStop
|
|
34
|
-
* @for jmGradient
|
|
35
|
-
* @param {number} offset 放射渐变颜色偏移,可为百分比参数。
|
|
36
|
-
* @param {string} color 当前偏移颜色值
|
|
37
|
-
*/
|
|
38
|
-
addStop(offset, color) {
|
|
39
|
-
this.stops.add({
|
|
40
|
-
offset: Number(offset),
|
|
41
|
-
color: color
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 生成为canvas的渐变对象
|
|
47
|
-
*
|
|
48
|
-
* @method toGradient
|
|
49
|
-
* @for jmGradient
|
|
50
|
-
* @param {jmControl} control 当前渐变对应的控件
|
|
51
|
-
* @return {gradient} canvas渐变对象
|
|
52
|
-
*/
|
|
53
|
-
toGradient(control) {
|
|
54
|
-
let gradient;
|
|
55
|
-
let context = control.context || control;
|
|
56
|
-
let bounds = control.absoluteBounds?control.absoluteBounds:control.getAbsoluteBounds();
|
|
57
|
-
let x1 = this.x1||0;
|
|
58
|
-
let y1 = this.y1||0;
|
|
59
|
-
let x2 = this.x2;
|
|
60
|
-
let y2 = this.y2;
|
|
61
|
-
|
|
62
|
-
let location = control.getLocation();
|
|
63
|
-
|
|
64
|
-
let d = 0;
|
|
65
|
-
if(location.radius) {
|
|
66
|
-
d = location.radius * 2;
|
|
67
|
-
}
|
|
68
|
-
if(!d) {
|
|
69
|
-
d = Math.min(location.width,location.height);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
//let offsetLine = 1;//渐变长度或半径
|
|
73
|
-
//处理百分比参数
|
|
74
|
-
if(jmUtils.checkPercent(x1)) {
|
|
75
|
-
x1 = jmUtils.percentToNumber(x1) * (bounds.width || d);
|
|
76
|
-
}
|
|
77
|
-
if(jmUtils.checkPercent(x2)) {
|
|
78
|
-
x2 = jmUtils.percentToNumber(x2) * (bounds.width || d);
|
|
79
|
-
}
|
|
80
|
-
if(jmUtils.checkPercent(y1)) {
|
|
81
|
-
y1 = jmUtils.percentToNumber(y1) * (bounds.height || d);
|
|
82
|
-
}
|
|
83
|
-
if(jmUtils.checkPercent(y2)) {
|
|
84
|
-
y2 = jmUtils.percentToNumber(y2) * (bounds.height || d);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let sx1 = Number(x1) + bounds.left;
|
|
88
|
-
let sy1 = Number(y1) + bounds.top;
|
|
89
|
-
let sx2 = Number(x2) + bounds.left;
|
|
90
|
-
let sy2 = Number(y2) + bounds.top;
|
|
91
|
-
if(this.type === 'linear') {
|
|
92
|
-
if(control.mode === 'webgl' && control.webglControl) {
|
|
93
|
-
gradient = control.webglControl.createLinearGradient(x1, y1, x2, y2, bounds);
|
|
94
|
-
gradient.key = this.toString();
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
context.createLinearGradient && (gradient = context.createLinearGradient(sx1, sy1, sx2, sy2));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
else if(this.type === 'radial') {
|
|
101
|
-
let r1 = this.r1||0;
|
|
102
|
-
let r2 = this.r2;
|
|
103
|
-
if(jmUtils.checkPercent(r1)) {
|
|
104
|
-
r1 = jmUtils.percentToNumber(r1);
|
|
105
|
-
r1 = d * r1;
|
|
106
|
-
}
|
|
107
|
-
if(jmUtils.checkPercent(r2)) {
|
|
108
|
-
r2 = jmUtils.percentToNumber(r2);
|
|
109
|
-
r2 = d * r2;
|
|
110
|
-
}
|
|
111
|
-
if(control.mode === 'webgl' && control.webglControl) {
|
|
112
|
-
gradient = control.webglControl.createRadialGradient(x1, y1, r1, x2, y2, r2, bounds);
|
|
113
|
-
gradient.key = this.toString();
|
|
114
|
-
}
|
|
115
|
-
//offsetLine = Math.abs(r2 - r1);//二圆半径差
|
|
116
|
-
else if(context.createRadialGradient) {
|
|
117
|
-
gradient = context.createRadialGradient(sx1, sy1, r1, sx2, sy2, r2);
|
|
118
|
-
}
|
|
119
|
-
//小程序的接口特殊
|
|
120
|
-
else if(context.createCircularGradient) {
|
|
121
|
-
gradient = context.createCircularGradient(sx1, sy1, r2);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
//颜色渐变
|
|
126
|
-
if(gradient) {
|
|
127
|
-
this.stops.each(function(i,s) {
|
|
128
|
-
let c = jmUtils.toColor(s.color);
|
|
129
|
-
//s.offset 0.0 ~ 1.0
|
|
130
|
-
gradient && gradient.addColorStop(s.offset, c);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
const s = this.stops.get(0);
|
|
135
|
-
return (s && s.color) || '#000';
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return gradient;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* 变换为字条串格式
|
|
143
|
-
* linear-gradient(x1 y1 x2 y2, color1 step, color2 step, ...); //radial-gradient(x1 y1 r1 x2 y2 r2, color1 step,color2 step, ...);
|
|
144
|
-
* linear-gradient线性渐变,x1 y1表示起点,x2 y2表示结束点,color表颜色,step为当前颜色偏移
|
|
145
|
-
* radial-gradient径向渐变,x1 y1 r1分别表示内圆中心和半径,x2 y2 r2为结束圆 中心和半径,颜色例似线性渐变 step为0-1之间
|
|
146
|
-
*
|
|
147
|
-
* @method fromString
|
|
148
|
-
* @for jmGradient
|
|
149
|
-
* @return {string}
|
|
150
|
-
*/
|
|
151
|
-
fromString(s) {
|
|
152
|
-
if(!s) return;
|
|
153
|
-
let ms = s.match(/(linear|radial)-gradient\s*\(\s*([^,]+)\s*,\s*((.|\s)+)\)/i);
|
|
154
|
-
if(!ms || ms.length < 3) return;
|
|
155
|
-
this.type = ms[1].toLowerCase();
|
|
156
|
-
|
|
157
|
-
const ps = jmUtils.trim(ms[2]).split(/\s+/);
|
|
158
|
-
//线性渐变
|
|
159
|
-
if(this.type == 'linear') {
|
|
160
|
-
if(ps.length <= 2) {
|
|
161
|
-
this.x2 = ps[0];
|
|
162
|
-
this.y2 = ps[1]||0;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
this.x1 = ps[0];
|
|
166
|
-
this.y1 = ps[1];
|
|
167
|
-
this.x2 = ps[2];
|
|
168
|
-
this.y2 = ps[3];
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
//径向渐变
|
|
172
|
-
else {
|
|
173
|
-
if(ps.length <= 3) {
|
|
174
|
-
this.x2 = ps[0];
|
|
175
|
-
this.y2 = ps[1]||0;
|
|
176
|
-
this.r2 = ps[2]||0;
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
this.x1 = ps[0];
|
|
180
|
-
this.y1 = ps[1];
|
|
181
|
-
this.r1 = ps[2];
|
|
182
|
-
this.x2 = ps[3];
|
|
183
|
-
this.y2 = ps[3];
|
|
184
|
-
this.r2 = ps[3];
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
//解析颜色偏移
|
|
188
|
-
//color step
|
|
189
|
-
const pars = ms[3].match(/((rgb(a)?\s*\([\d,\.\s]+\))|(#[a-zA-Z\d]+))\s+([\d\.]+)/ig);
|
|
190
|
-
if(pars && pars.length) {
|
|
191
|
-
for(let i=0;i<pars.length;i++) {
|
|
192
|
-
const par = jmUtils.trim(pars[i]);
|
|
193
|
-
const spindex = par.lastIndexOf(' ');
|
|
194
|
-
if(spindex > -1) {
|
|
195
|
-
const offset = Number(par.substr(spindex + 1));
|
|
196
|
-
const color = jmUtils.trim(par.substr(0, spindex));
|
|
197
|
-
if(!isNaN(offset) && color) {
|
|
198
|
-
this.addStop(offset, color);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* 转换为渐变的字符串表达
|
|
207
|
-
*
|
|
208
|
-
* @method toString
|
|
209
|
-
* @for jmGradient
|
|
210
|
-
* @return {string} linear-gradient(x1 y1 x2 y2, color1 step, color2 step, ...); //radial-gradient(x1 y1 r1 x2 y2 r2, color1 step,color2 step, ...);
|
|
211
|
-
*/
|
|
212
|
-
toString() {
|
|
213
|
-
let str = this.type + '-gradient(';
|
|
214
|
-
if(this.type == 'linear') {
|
|
215
|
-
str += this.x1 + ' ' + this.y1 + ' ' + this.x2 + ' ' + this.y2;
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
str += this.x1 + ' ' + this.y1 + ' ' + this.r1 + ' ' + this.x2 + ' ' + this.y2 + ' ' + this.r2;
|
|
219
|
-
}
|
|
220
|
-
//颜色渐变
|
|
221
|
-
this.stops.each(function(i,s) {
|
|
222
|
-
str += ',' + s.color + ' ' + s.offset;
|
|
223
|
-
});
|
|
224
|
-
return str + ')';
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export { jmGradient };
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
1
|
+
import {jmUtils} from "./jmUtils.js";
|
|
2
|
+
import {jmList} from "./jmList.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 渐变类
|
|
6
|
+
*
|
|
7
|
+
* @class jmGradient
|
|
8
|
+
* @param {object} op 渐变参数,type:[linear= 线性渐变,radial=放射性渐变]
|
|
9
|
+
*/
|
|
10
|
+
export default class jmGradient {
|
|
11
|
+
constructor(opt) {
|
|
12
|
+
this.stops = new jmList();
|
|
13
|
+
|
|
14
|
+
if(opt && typeof opt == 'object') {
|
|
15
|
+
for(let k in opt) {
|
|
16
|
+
if(k === 'stops') continue;
|
|
17
|
+
this[k] = opt[k];
|
|
18
|
+
}
|
|
19
|
+
if(opt.stops && Array.isArray(opt.stops)) {
|
|
20
|
+
this.stops.push(...opt.stops);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//解析字符串格式
|
|
24
|
+
//linear-gradient(direction, color-stop1, color-stop2, ...);
|
|
25
|
+
//radial-gradient(center, shape size, start-color, ..., last-color);
|
|
26
|
+
else if(typeof opt == 'string') {
|
|
27
|
+
this.fromString(opt);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 添加渐变色
|
|
32
|
+
*
|
|
33
|
+
* @method addStop
|
|
34
|
+
* @for jmGradient
|
|
35
|
+
* @param {number} offset 放射渐变颜色偏移,可为百分比参数。
|
|
36
|
+
* @param {string} color 当前偏移颜色值
|
|
37
|
+
*/
|
|
38
|
+
addStop(offset, color) {
|
|
39
|
+
this.stops.add({
|
|
40
|
+
offset: Number(offset),
|
|
41
|
+
color: color
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 生成为canvas的渐变对象
|
|
47
|
+
*
|
|
48
|
+
* @method toGradient
|
|
49
|
+
* @for jmGradient
|
|
50
|
+
* @param {jmControl} control 当前渐变对应的控件
|
|
51
|
+
* @return {gradient} canvas渐变对象
|
|
52
|
+
*/
|
|
53
|
+
toGradient(control) {
|
|
54
|
+
let gradient;
|
|
55
|
+
let context = control.context || control;
|
|
56
|
+
let bounds = control.absoluteBounds?control.absoluteBounds:control.getAbsoluteBounds();
|
|
57
|
+
let x1 = this.x1||0;
|
|
58
|
+
let y1 = this.y1||0;
|
|
59
|
+
let x2 = this.x2;
|
|
60
|
+
let y2 = this.y2;
|
|
61
|
+
|
|
62
|
+
let location = control.getLocation();
|
|
63
|
+
|
|
64
|
+
let d = 0;
|
|
65
|
+
if(location.radius) {
|
|
66
|
+
d = location.radius * 2;
|
|
67
|
+
}
|
|
68
|
+
if(!d) {
|
|
69
|
+
d = Math.min(location.width,location.height);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//let offsetLine = 1;//渐变长度或半径
|
|
73
|
+
//处理百分比参数
|
|
74
|
+
if(jmUtils.checkPercent(x1)) {
|
|
75
|
+
x1 = jmUtils.percentToNumber(x1) * (bounds.width || d);
|
|
76
|
+
}
|
|
77
|
+
if(jmUtils.checkPercent(x2)) {
|
|
78
|
+
x2 = jmUtils.percentToNumber(x2) * (bounds.width || d);
|
|
79
|
+
}
|
|
80
|
+
if(jmUtils.checkPercent(y1)) {
|
|
81
|
+
y1 = jmUtils.percentToNumber(y1) * (bounds.height || d);
|
|
82
|
+
}
|
|
83
|
+
if(jmUtils.checkPercent(y2)) {
|
|
84
|
+
y2 = jmUtils.percentToNumber(y2) * (bounds.height || d);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let sx1 = Number(x1) + bounds.left;
|
|
88
|
+
let sy1 = Number(y1) + bounds.top;
|
|
89
|
+
let sx2 = Number(x2) + bounds.left;
|
|
90
|
+
let sy2 = Number(y2) + bounds.top;
|
|
91
|
+
if(this.type === 'linear') {
|
|
92
|
+
if(control.mode === 'webgl' && control.webglControl) {
|
|
93
|
+
gradient = control.webglControl.createLinearGradient(x1, y1, x2, y2, bounds);
|
|
94
|
+
gradient.key = this.toString();
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
context.createLinearGradient && (gradient = context.createLinearGradient(sx1, sy1, sx2, sy2));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if(this.type === 'radial') {
|
|
101
|
+
let r1 = this.r1||0;
|
|
102
|
+
let r2 = this.r2;
|
|
103
|
+
if(jmUtils.checkPercent(r1)) {
|
|
104
|
+
r1 = jmUtils.percentToNumber(r1);
|
|
105
|
+
r1 = d * r1;
|
|
106
|
+
}
|
|
107
|
+
if(jmUtils.checkPercent(r2)) {
|
|
108
|
+
r2 = jmUtils.percentToNumber(r2);
|
|
109
|
+
r2 = d * r2;
|
|
110
|
+
}
|
|
111
|
+
if(control.mode === 'webgl' && control.webglControl) {
|
|
112
|
+
gradient = control.webglControl.createRadialGradient(x1, y1, r1, x2, y2, r2, bounds);
|
|
113
|
+
gradient.key = this.toString();
|
|
114
|
+
}
|
|
115
|
+
//offsetLine = Math.abs(r2 - r1);//二圆半径差
|
|
116
|
+
else if(context.createRadialGradient) {
|
|
117
|
+
gradient = context.createRadialGradient(sx1, sy1, r1, sx2, sy2, r2);
|
|
118
|
+
}
|
|
119
|
+
//小程序的接口特殊
|
|
120
|
+
else if(context.createCircularGradient) {
|
|
121
|
+
gradient = context.createCircularGradient(sx1, sy1, r2);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//颜色渐变
|
|
126
|
+
if(gradient) {
|
|
127
|
+
this.stops.each(function(i,s) {
|
|
128
|
+
let c = jmUtils.toColor(s.color);
|
|
129
|
+
//s.offset 0.0 ~ 1.0
|
|
130
|
+
gradient && gradient.addColorStop(s.offset, c);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const s = this.stops.get(0);
|
|
135
|
+
return (s && s.color) || '#000';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return gradient;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 变换为字条串格式
|
|
143
|
+
* linear-gradient(x1 y1 x2 y2, color1 step, color2 step, ...); //radial-gradient(x1 y1 r1 x2 y2 r2, color1 step,color2 step, ...);
|
|
144
|
+
* linear-gradient线性渐变,x1 y1表示起点,x2 y2表示结束点,color表颜色,step为当前颜色偏移
|
|
145
|
+
* radial-gradient径向渐变,x1 y1 r1分别表示内圆中心和半径,x2 y2 r2为结束圆 中心和半径,颜色例似线性渐变 step为0-1之间
|
|
146
|
+
*
|
|
147
|
+
* @method fromString
|
|
148
|
+
* @for jmGradient
|
|
149
|
+
* @return {string}
|
|
150
|
+
*/
|
|
151
|
+
fromString(s) {
|
|
152
|
+
if(!s) return;
|
|
153
|
+
let ms = s.match(/(linear|radial)-gradient\s*\(\s*([^,]+)\s*,\s*((.|\s)+)\)/i);
|
|
154
|
+
if(!ms || ms.length < 3) return;
|
|
155
|
+
this.type = ms[1].toLowerCase();
|
|
156
|
+
|
|
157
|
+
const ps = jmUtils.trim(ms[2]).split(/\s+/);
|
|
158
|
+
//线性渐变
|
|
159
|
+
if(this.type == 'linear') {
|
|
160
|
+
if(ps.length <= 2) {
|
|
161
|
+
this.x2 = ps[0];
|
|
162
|
+
this.y2 = ps[1]||0;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
this.x1 = ps[0];
|
|
166
|
+
this.y1 = ps[1];
|
|
167
|
+
this.x2 = ps[2];
|
|
168
|
+
this.y2 = ps[3];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//径向渐变
|
|
172
|
+
else {
|
|
173
|
+
if(ps.length <= 3) {
|
|
174
|
+
this.x2 = ps[0];
|
|
175
|
+
this.y2 = ps[1]||0;
|
|
176
|
+
this.r2 = ps[2]||0;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.x1 = ps[0];
|
|
180
|
+
this.y1 = ps[1];
|
|
181
|
+
this.r1 = ps[2];
|
|
182
|
+
this.x2 = ps[3];
|
|
183
|
+
this.y2 = ps[3];
|
|
184
|
+
this.r2 = ps[3];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//解析颜色偏移
|
|
188
|
+
//color step
|
|
189
|
+
const pars = ms[3].match(/((rgb(a)?\s*\([\d,\.\s]+\))|(#[a-zA-Z\d]+))\s+([\d\.]+)/ig);
|
|
190
|
+
if(pars && pars.length) {
|
|
191
|
+
for(let i=0;i<pars.length;i++) {
|
|
192
|
+
const par = jmUtils.trim(pars[i]);
|
|
193
|
+
const spindex = par.lastIndexOf(' ');
|
|
194
|
+
if(spindex > -1) {
|
|
195
|
+
const offset = Number(par.substr(spindex + 1));
|
|
196
|
+
const color = jmUtils.trim(par.substr(0, spindex));
|
|
197
|
+
if(!isNaN(offset) && color) {
|
|
198
|
+
this.addStop(offset, color);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 转换为渐变的字符串表达
|
|
207
|
+
*
|
|
208
|
+
* @method toString
|
|
209
|
+
* @for jmGradient
|
|
210
|
+
* @return {string} linear-gradient(x1 y1 x2 y2, color1 step, color2 step, ...); //radial-gradient(x1 y1 r1 x2 y2 r2, color1 step,color2 step, ...);
|
|
211
|
+
*/
|
|
212
|
+
toString() {
|
|
213
|
+
let str = this.type + '-gradient(';
|
|
214
|
+
if(this.type == 'linear') {
|
|
215
|
+
str += this.x1 + ' ' + this.y1 + ' ' + this.x2 + ' ' + this.y2;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
str += this.x1 + ' ' + this.y1 + ' ' + this.r1 + ' ' + this.x2 + ' ' + this.y2 + ' ' + this.r2;
|
|
219
|
+
}
|
|
220
|
+
//颜色渐变
|
|
221
|
+
this.stops.each(function(i,s) {
|
|
222
|
+
str += ',' + s.color + ' ' + s.offset;
|
|
223
|
+
});
|
|
224
|
+
return str + ')';
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { jmGradient };
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|