jmchart 1.2.18 → 1.2.19
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/dist/jmchart.amd.js +628 -61
- package/dist/jmchart.cjs.js +628 -61
- package/dist/jmchart.esm.js +628 -61
- package/dist/jmchart.iife.js +628 -61
- package/dist/jmchart.system.js +628 -61
- package/package.json +2 -2
package/dist/jmchart.iife.js
CHANGED
|
@@ -153,11 +153,13 @@ var jmChart = (function (exports) {
|
|
|
153
153
|
darkseagreen: "#8fbc8f",
|
|
154
154
|
darkslateblue: "#483d8b",
|
|
155
155
|
darkslategray: "#2f4f4f",
|
|
156
|
+
darkslategrey: "#2f4f4f",
|
|
156
157
|
darkturquoise: "#00ced1",
|
|
157
158
|
darkviolet: "#9400d3",
|
|
158
159
|
deeppink: "#ff1493",
|
|
159
160
|
deepskyblue: "#00bfff",
|
|
160
161
|
dimgray: "#696969",
|
|
162
|
+
dimgrey: "#696969",
|
|
161
163
|
dodgerblue: "#1e90ff",
|
|
162
164
|
firebrick: "#b22222",
|
|
163
165
|
floralwhite: "#fffaf0",
|
|
@@ -192,6 +194,7 @@ var jmChart = (function (exports) {
|
|
|
192
194
|
lightseagreen: "#20b2aa",
|
|
193
195
|
lightskyblue: "#87cefa",
|
|
194
196
|
lightslategray: "#778899",
|
|
197
|
+
lightslategrey: "#778899",
|
|
195
198
|
lightsteelblue: "#b0c4de",
|
|
196
199
|
lightyellow: "#ffffe0",
|
|
197
200
|
lime: "#00ff00",
|
|
@@ -232,6 +235,7 @@ var jmChart = (function (exports) {
|
|
|
232
235
|
powderblue: "#b0e0e6",
|
|
233
236
|
purple: "#800080",
|
|
234
237
|
red: "#ff0000",
|
|
238
|
+
rebeccapurple: "#663399",
|
|
235
239
|
rosybrown: "#bc8f8f",
|
|
236
240
|
royalblue: "#4169e1",
|
|
237
241
|
saddlebrown: "#8b4513",
|
|
@@ -244,6 +248,7 @@ var jmChart = (function (exports) {
|
|
|
244
248
|
skyblue: "#87ceeb",
|
|
245
249
|
slateblue: "#6a5acd",
|
|
246
250
|
slategray: "#708090",
|
|
251
|
+
slategrey: "#708090",
|
|
247
252
|
snow: "#fffafa",
|
|
248
253
|
springgreen: "#00ff7f",
|
|
249
254
|
steelblue: "#4682b4",
|
|
@@ -258,7 +263,37 @@ var jmChart = (function (exports) {
|
|
|
258
263
|
whitesmoke: "#f5f5f5",
|
|
259
264
|
yellow: "#ffff00",
|
|
260
265
|
yellowgreen: "#9acd32",
|
|
261
|
-
transparent: "rgba(0,0,0,0)"
|
|
266
|
+
transparent: "rgba(0,0,0,0)",
|
|
267
|
+
// grey 别名(已有 darkslategrey/lightslategrey/slategrey/dimgrey)
|
|
268
|
+
// 以下为 CSS 系统颜色
|
|
269
|
+
activeborder: "#bfcaca",
|
|
270
|
+
activecaption: "#000080",
|
|
271
|
+
appworkspace: "#ababab",
|
|
272
|
+
background: "#636363",
|
|
273
|
+
buttonface: "#c0c0c0",
|
|
274
|
+
buttonhighlight: "#dedede",
|
|
275
|
+
buttonshadow: "#808080",
|
|
276
|
+
buttontext: "#000000",
|
|
277
|
+
captiontext: "#000000",
|
|
278
|
+
graytext: "#808080",
|
|
279
|
+
highlight: "#b3d4fc",
|
|
280
|
+
highlighttext: "#000000",
|
|
281
|
+
inactiveborder: "#d4d0c8",
|
|
282
|
+
inactivecaption: "#bfbbb0",
|
|
283
|
+
inactivecaptiontext: "#545454",
|
|
284
|
+
infobackground: "#fbfcc5",
|
|
285
|
+
infotext: "#000000",
|
|
286
|
+
menu: "#c0c0c0",
|
|
287
|
+
menutext: "#000000",
|
|
288
|
+
scrollbar: "#c0c0c0",
|
|
289
|
+
threeddarkshadow: "#696969",
|
|
290
|
+
threedface: "#c0c0c0",
|
|
291
|
+
threedhighlight: "#dfdfdf",
|
|
292
|
+
threedlightshadow: "#dcdcdc",
|
|
293
|
+
threedshadow: "#808080",
|
|
294
|
+
window: "#ffffff",
|
|
295
|
+
windowframe: "#646464",
|
|
296
|
+
windowtext: "#000000"
|
|
262
297
|
};
|
|
263
298
|
|
|
264
299
|
/**
|
|
@@ -1094,28 +1129,65 @@ var jmChart = (function (exports) {
|
|
|
1094
1129
|
d = location.radius * 2;
|
|
1095
1130
|
}
|
|
1096
1131
|
if(!d) {
|
|
1097
|
-
d = Math.min(location.width,location.height);
|
|
1132
|
+
d = Math.min(location.width || 0, location.height || 0);
|
|
1098
1133
|
}
|
|
1134
|
+
if(d <= 0) {
|
|
1135
|
+
d = Math.max(bounds.width || 0, bounds.height || 0, 100);
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
const width = bounds.width || d;
|
|
1139
|
+
const height = bounds.height || d;
|
|
1099
1140
|
|
|
1100
|
-
//let offsetLine = 1;//渐变长度或半径
|
|
1101
|
-
//处理百分比参数
|
|
1102
1141
|
if(jmUtils.checkPercent(x1)) {
|
|
1103
|
-
x1 = jmUtils.percentToNumber(x1) *
|
|
1142
|
+
x1 = jmUtils.percentToNumber(x1) * width;
|
|
1143
|
+
}
|
|
1144
|
+
else if(typeof x1 === 'number' && x1 >= 0 && x1 <= 1) {
|
|
1145
|
+
x1 = x1 * width;
|
|
1146
|
+
}
|
|
1147
|
+
else if(typeof x1 === 'string') {
|
|
1148
|
+
const num = parseFloat(x1);
|
|
1149
|
+
if(!isNaN(num)) x1 = num;
|
|
1104
1150
|
}
|
|
1105
1151
|
if(jmUtils.checkPercent(x2)) {
|
|
1106
|
-
x2 = jmUtils.percentToNumber(x2) *
|
|
1152
|
+
x2 = jmUtils.percentToNumber(x2) * width;
|
|
1153
|
+
}
|
|
1154
|
+
else if(typeof x2 === 'number' && x2 >= 0 && x2 <= 1) {
|
|
1155
|
+
x2 = x2 * width;
|
|
1156
|
+
}
|
|
1157
|
+
else if(typeof x2 === 'string') {
|
|
1158
|
+
const num = parseFloat(x2);
|
|
1159
|
+
if(!isNaN(num)) x2 = num;
|
|
1107
1160
|
}
|
|
1108
1161
|
if(jmUtils.checkPercent(y1)) {
|
|
1109
|
-
y1 = jmUtils.percentToNumber(y1) *
|
|
1162
|
+
y1 = jmUtils.percentToNumber(y1) * height;
|
|
1163
|
+
}
|
|
1164
|
+
else if(typeof y1 === 'number' && y1 >= 0 && y1 <= 1) {
|
|
1165
|
+
y1 = y1 * height;
|
|
1166
|
+
}
|
|
1167
|
+
else if(typeof y1 === 'string') {
|
|
1168
|
+
const num = parseFloat(y1);
|
|
1169
|
+
if(!isNaN(num)) y1 = num;
|
|
1110
1170
|
}
|
|
1111
1171
|
if(jmUtils.checkPercent(y2)) {
|
|
1112
|
-
y2 = jmUtils.percentToNumber(y2) *
|
|
1113
|
-
}
|
|
1172
|
+
y2 = jmUtils.percentToNumber(y2) * height;
|
|
1173
|
+
}
|
|
1174
|
+
else if(typeof y2 === 'number' && y2 >= 0 && y2 <= 1) {
|
|
1175
|
+
y2 = y2 * height;
|
|
1176
|
+
}
|
|
1177
|
+
else if(typeof y2 === 'string') {
|
|
1178
|
+
const num = parseFloat(y2);
|
|
1179
|
+
if(!isNaN(num)) y2 = num;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
x1 = Number(x1) || 0;
|
|
1183
|
+
y1 = Number(y1) || 0;
|
|
1184
|
+
x2 = Number(x2) || 0;
|
|
1185
|
+
y2 = Number(y2) || 0;
|
|
1114
1186
|
|
|
1115
|
-
let sx1 =
|
|
1116
|
-
let sy1 =
|
|
1117
|
-
let sx2 =
|
|
1118
|
-
let sy2 =
|
|
1187
|
+
let sx1 = x1 + (bounds.left || 0);
|
|
1188
|
+
let sy1 = y1 + (bounds.top || 0);
|
|
1189
|
+
let sx2 = x2 + (bounds.left || 0);
|
|
1190
|
+
let sy2 = y2 + (bounds.top || 0);
|
|
1119
1191
|
if(this.type === 'linear') {
|
|
1120
1192
|
if(control.mode === 'webgl' && control.webglControl) {
|
|
1121
1193
|
// WebGL 着色器中 v_text_coord 是绝对坐标,需要传递绝对坐标
|
|
@@ -1129,24 +1201,47 @@ var jmChart = (function (exports) {
|
|
|
1129
1201
|
else if(this.type === 'radial') {
|
|
1130
1202
|
let r1 = this.r1||0;
|
|
1131
1203
|
let r2 = this.r2;
|
|
1204
|
+
|
|
1205
|
+
if(d <= 0) {
|
|
1206
|
+
d = Math.max(bounds.width || 0, bounds.height || 0, 1);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1132
1209
|
if(jmUtils.checkPercent(r1)) {
|
|
1133
1210
|
r1 = jmUtils.percentToNumber(r1);
|
|
1134
1211
|
r1 = d * r1;
|
|
1135
1212
|
}
|
|
1213
|
+
else if(typeof r1 === 'number' && r1 >= 0 && r1 <= 1) {
|
|
1214
|
+
r1 = r1 * d;
|
|
1215
|
+
}
|
|
1216
|
+
else if(typeof r1 === 'string') {
|
|
1217
|
+
r1 = parseFloat(r1) || 0;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1136
1220
|
if(jmUtils.checkPercent(r2)) {
|
|
1137
1221
|
r2 = jmUtils.percentToNumber(r2);
|
|
1138
1222
|
r2 = d * r2;
|
|
1139
1223
|
}
|
|
1224
|
+
else if(typeof r2 === 'number' && r2 >= 0 && r2 <= 1) {
|
|
1225
|
+
r2 = r2 * d;
|
|
1226
|
+
}
|
|
1227
|
+
else if(typeof r2 === 'string') {
|
|
1228
|
+
r2 = parseFloat(r2);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
if(r2 === undefined || r2 === null || isNaN(Number(r2)) || Number(r2) <= 0) {
|
|
1232
|
+
r2 = d / 2;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
r1 = Number(r1) || 0;
|
|
1236
|
+
r2 = Number(r2) || d / 2;
|
|
1237
|
+
|
|
1140
1238
|
if(control.mode === 'webgl' && control.webglControl) {
|
|
1141
|
-
// WebGL 着色器中 v_text_coord 是绝对坐标,需要传递绝对坐标
|
|
1142
1239
|
gradient = control.webglControl.createRadialGradient(sx1, sy1, r1, sx2, sy2, r2, bounds);
|
|
1143
1240
|
gradient.key = this.toString();
|
|
1144
1241
|
}
|
|
1145
|
-
//offsetLine = Math.abs(r2 - r1);//二圆半径差
|
|
1146
1242
|
else if(context.createRadialGradient) {
|
|
1147
1243
|
gradient = context.createRadialGradient(sx1, sy1, r1, sx2, sy2, r2);
|
|
1148
1244
|
}
|
|
1149
|
-
//小程序的接口特殊
|
|
1150
1245
|
else if(context.createCircularGradient) {
|
|
1151
1246
|
gradient = context.createCircularGradient(sx1, sy1, r2);
|
|
1152
1247
|
}
|
|
@@ -1169,67 +1264,539 @@ var jmChart = (function (exports) {
|
|
|
1169
1264
|
}
|
|
1170
1265
|
|
|
1171
1266
|
/**
|
|
1172
|
-
*
|
|
1173
|
-
*
|
|
1174
|
-
* linear-gradient
|
|
1175
|
-
*
|
|
1267
|
+
* 解析渐变字符串
|
|
1268
|
+
* 支持的格式:
|
|
1269
|
+
* - linear-gradient(180deg, #8b5cf6 0%, #6366f1 50%, #4f46e5 100%)
|
|
1270
|
+
* - linear-gradient(to top, red, blue)
|
|
1271
|
+
* - linear-gradient(to right bottom, red, blue)
|
|
1272
|
+
* - linear-gradient(45deg, red, blue)
|
|
1273
|
+
* - linear-gradient(0.5turn, red, blue)
|
|
1274
|
+
* - radial-gradient(circle, red, blue)
|
|
1275
|
+
* - radial-gradient(ellipse at top, red, blue)
|
|
1176
1276
|
*
|
|
1177
1277
|
* @method fromString
|
|
1178
1278
|
* @for jmGradient
|
|
1179
|
-
* @
|
|
1279
|
+
* @param {string} s 渐变字符串
|
|
1180
1280
|
*/
|
|
1181
1281
|
fromString(s) {
|
|
1182
|
-
if(!s)
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1282
|
+
if(!s) {
|
|
1283
|
+
console.warn('jmGradient: 渐变字符串为空');
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
// 使用 [\s\S] 匹配任意字符(包括换行符),支持多行渐变字符串
|
|
1287
|
+
const gradientMatch = s.match(/(linear|radial)-gradient\s*\(\s*([\s\S]+)\)/i);
|
|
1288
|
+
if(!gradientMatch || gradientMatch.length < 3) {
|
|
1289
|
+
console.warn('jmGradient: 无效的渐变字符串格式: "' + s + '"');
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
const type = gradientMatch[1].toLowerCase();
|
|
1294
|
+
if(type !== 'linear' && type !== 'radial') {
|
|
1295
|
+
console.warn('jmGradient: 不支持的渐变类型 "' + type + '",仅支持 linear 和 radial');
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
this.type = type;
|
|
1300
|
+
const content = jmUtils.trim(gradientMatch[2]);
|
|
1301
|
+
|
|
1302
|
+
const splitIndex = this._findSplitIndex(content);
|
|
1303
|
+
if(splitIndex < 0) {
|
|
1304
|
+
console.warn('jmGradient: 无法解析渐变内容: "' + content + '"');
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
const params = content.substring(0, splitIndex).trim();
|
|
1309
|
+
const colorPart = content.substring(splitIndex + 1).trim();
|
|
1310
|
+
|
|
1311
|
+
if(!colorPart) {
|
|
1312
|
+
console.warn('jmGradient: 未找到颜色停止点');
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
if(this.type === 'linear') {
|
|
1317
|
+
this._parseLinearParams(params);
|
|
1318
|
+
}
|
|
1319
|
+
else {
|
|
1320
|
+
this._parseRadialParams(params);
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
const colorCount = this._parseColorStops(colorPart);
|
|
1324
|
+
if(colorCount === 0) {
|
|
1325
|
+
console.warn('jmGradient: 未找到有效的颜色停止点: "' + colorPart + '"');
|
|
1326
|
+
}
|
|
1327
|
+
else if(colorCount < 2) {
|
|
1328
|
+
console.warn('jmGradient: 颜色停止点至少需要2个,当前只有 ' + colorCount + ' 个');
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
/**
|
|
1333
|
+
* 找到参数和颜色的分割位置(第一个不在括号内的逗号)
|
|
1334
|
+
* @param {string} content 内容字符串
|
|
1335
|
+
* @returns {number} 分割位置索引
|
|
1336
|
+
*/
|
|
1337
|
+
_findSplitIndex(content) {
|
|
1338
|
+
let depth = 0;
|
|
1339
|
+
|
|
1340
|
+
for(let i = 0; i < content.length; i++) {
|
|
1341
|
+
const char = content[i];
|
|
1342
|
+
if(char === '(') {
|
|
1343
|
+
depth++;
|
|
1193
1344
|
}
|
|
1194
|
-
else {
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1345
|
+
else if(char === ')') {
|
|
1346
|
+
depth--;
|
|
1347
|
+
}
|
|
1348
|
+
else if(char === ',' && depth === 0) {
|
|
1349
|
+
return i;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
return -1;
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* 验证渐变配置是否有效
|
|
1358
|
+
* @returns {boolean} 是否有效
|
|
1359
|
+
*/
|
|
1360
|
+
isValid() {
|
|
1361
|
+
if(!this.type) return false;
|
|
1362
|
+
if(this.type === 'linear') {
|
|
1363
|
+
return typeof this.x1 !== 'undefined' ||
|
|
1364
|
+
typeof this.x2 !== 'undefined' ||
|
|
1365
|
+
typeof this._angle !== 'undefined';
|
|
1366
|
+
}
|
|
1367
|
+
if(this.type === 'radial') {
|
|
1368
|
+
return this.stops && this.stops.length >= 2;
|
|
1369
|
+
}
|
|
1370
|
+
return false;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* 解析线性渐变参数
|
|
1375
|
+
* @param {string} params 参数字符串
|
|
1376
|
+
*/
|
|
1377
|
+
_parseLinearParams(params) {
|
|
1378
|
+
const trimmed = jmUtils.trim(params);
|
|
1379
|
+
|
|
1380
|
+
if(trimmed.startsWith('to ')) {
|
|
1381
|
+
const direction = trimmed.substring(3).toLowerCase().trim();
|
|
1382
|
+
const dir = this._directionToAngle(direction);
|
|
1383
|
+
this._angle = dir.angle;
|
|
1384
|
+
this.x1 = dir.x1;
|
|
1385
|
+
this.y1 = dir.y1;
|
|
1386
|
+
this.x2 = dir.x2;
|
|
1387
|
+
this.y2 = dir.y2;
|
|
1388
|
+
}
|
|
1389
|
+
else if(this._hasAngleUnit(trimmed)) {
|
|
1390
|
+
const angle = this._parseAngle(trimmed);
|
|
1391
|
+
this._angle = angle;
|
|
1392
|
+
const coords = this._angleToCoords(angle);
|
|
1393
|
+
this.x1 = coords.x1;
|
|
1394
|
+
this.y1 = coords.y1;
|
|
1395
|
+
this.x2 = coords.x2;
|
|
1396
|
+
this.y2 = coords.y2;
|
|
1397
|
+
}
|
|
1398
|
+
else if(trimmed.startsWith('at ')) {
|
|
1399
|
+
const radialMatch = trimmed.match(/at\s+(.+)/i);
|
|
1400
|
+
if(radialMatch) {
|
|
1401
|
+
this._parseRadialParams(trimmed);
|
|
1199
1402
|
}
|
|
1200
1403
|
}
|
|
1201
|
-
//径向渐变
|
|
1202
1404
|
else {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
this.
|
|
1206
|
-
this.
|
|
1405
|
+
const parts = trimmed.split(/\s+/);
|
|
1406
|
+
if(parts.length >= 4) {
|
|
1407
|
+
this.x1 = parts[0];
|
|
1408
|
+
this.y1 = parts[1];
|
|
1409
|
+
this.x2 = parts[2];
|
|
1410
|
+
this.y2 = parts[3];
|
|
1207
1411
|
}
|
|
1208
|
-
else {
|
|
1209
|
-
this.x1 =
|
|
1210
|
-
this.y1 =
|
|
1211
|
-
this.
|
|
1212
|
-
this.
|
|
1213
|
-
|
|
1214
|
-
|
|
1412
|
+
else if(parts.length === 2) {
|
|
1413
|
+
this.x1 = 0;
|
|
1414
|
+
this.y1 = 0;
|
|
1415
|
+
this.x2 = parts[0];
|
|
1416
|
+
this.y2 = parts[1];
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
/**
|
|
1422
|
+
* 解析径向渐变参数
|
|
1423
|
+
* @param {string} params 参数字符串
|
|
1424
|
+
*/
|
|
1425
|
+
_parseRadialParams(params) {
|
|
1426
|
+
const trimmed = jmUtils.trim(params);
|
|
1427
|
+
|
|
1428
|
+
this.shape = 'ellipse';
|
|
1429
|
+
this.position = { x: '50%', y: '50%' };
|
|
1430
|
+
|
|
1431
|
+
const atMatch = trimmed.match(/^(.+?)\s+at\s+(.+)$/i);
|
|
1432
|
+
if(atMatch) {
|
|
1433
|
+
const shapePart = jmUtils.trim(atMatch[1]);
|
|
1434
|
+
const posPart = jmUtils.trim(atMatch[2]);
|
|
1435
|
+
this._parseRadialShape(shapePart);
|
|
1436
|
+
this._parseRadialPosition(posPart);
|
|
1437
|
+
}
|
|
1438
|
+
else if(trimmed.startsWith('circle') || trimmed.startsWith('ellipse')) {
|
|
1439
|
+
this._parseRadialShape(trimmed);
|
|
1440
|
+
this.x1 = '50%';
|
|
1441
|
+
this.y1 = '50%';
|
|
1442
|
+
this.x2 = '50%';
|
|
1443
|
+
this.y2 = '50%';
|
|
1444
|
+
}
|
|
1445
|
+
else {
|
|
1446
|
+
const parts = trimmed.split(/\s+/);
|
|
1447
|
+
if(parts.length >= 3) {
|
|
1448
|
+
this.x1 = parts[0];
|
|
1449
|
+
this.y1 = parts[1];
|
|
1450
|
+
this.r1 = parts[2];
|
|
1451
|
+
}
|
|
1452
|
+
if(parts.length >= 6) {
|
|
1453
|
+
this.x2 = parts[3];
|
|
1454
|
+
this.y2 = parts[4];
|
|
1455
|
+
this.r2 = parts[5];
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
if(this.x1 === undefined && this.y1 === undefined) {
|
|
1460
|
+
this.x1 = '50%';
|
|
1461
|
+
this.y1 = '50%';
|
|
1462
|
+
}
|
|
1463
|
+
if(this.x2 === undefined && this.y2 === undefined) {
|
|
1464
|
+
this.x2 = '50%';
|
|
1465
|
+
this.y2 = '50%';
|
|
1466
|
+
}
|
|
1467
|
+
if(this.r2 === undefined) {
|
|
1468
|
+
this.r2 = '50%';
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
/**
|
|
1473
|
+
* 解析径向渐变形状
|
|
1474
|
+
* @param {string} shapePart 形状描述
|
|
1475
|
+
*/
|
|
1476
|
+
_parseRadialShape(shapePart) {
|
|
1477
|
+
if(shapePart.startsWith('circle')) {
|
|
1478
|
+
this.shape = 'circle';
|
|
1479
|
+
const sizeMatch = shapePart.match(/circle\s*\(\s*([^)]+)\s*\)/i);
|
|
1480
|
+
if(sizeMatch) {
|
|
1481
|
+
this.r2 = jmUtils.trim(sizeMatch[1]);
|
|
1215
1482
|
}
|
|
1216
1483
|
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1484
|
+
else if(shapePart.startsWith('ellipse')) {
|
|
1485
|
+
this.shape = 'ellipse';
|
|
1486
|
+
const sizeMatch = shapePart.match(/ellipse\s*\(\s*([^)]+)\s*\)/i);
|
|
1487
|
+
if(sizeMatch) {
|
|
1488
|
+
const sizes = jmUtils.trim(sizeMatch[1]).split(/\s+/);
|
|
1489
|
+
if(sizes.length >= 2) {
|
|
1490
|
+
this.rx = sizes[0];
|
|
1491
|
+
this.ry = sizes[1];
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
/**
|
|
1498
|
+
* 解析径向渐变位置
|
|
1499
|
+
* @param {string} posPart 位置描述
|
|
1500
|
+
*/
|
|
1501
|
+
_parseRadialPosition(posPart) {
|
|
1502
|
+
const parts = posPart.split(/\s+/);
|
|
1503
|
+
if(parts.length >= 2) {
|
|
1504
|
+
this.x1 = parts[0];
|
|
1505
|
+
this.y1 = parts[1];
|
|
1506
|
+
this.x2 = parts[0];
|
|
1507
|
+
this.y2 = parts[1];
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
/**
|
|
1512
|
+
* 解析颜色停止点
|
|
1513
|
+
* @param {string} colorPart 颜色部分字符串
|
|
1514
|
+
* @returns {number} 成功解析的颜色数量
|
|
1515
|
+
*/
|
|
1516
|
+
_parseColorStops(colorPart) {
|
|
1517
|
+
if(!colorPart) {
|
|
1518
|
+
return 0;
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
const stops = this._splitColorStops(colorPart);
|
|
1522
|
+
let lastOffset = -1;
|
|
1523
|
+
let colorCount = 0;
|
|
1524
|
+
|
|
1525
|
+
for(let i = 0; i < stops.length; i++) {
|
|
1526
|
+
const stop = jmUtils.trim(stops[i]);
|
|
1527
|
+
if(!stop) continue;
|
|
1528
|
+
|
|
1529
|
+
const parsed = this._parseSingleColorStop(stop);
|
|
1530
|
+
if(!parsed) {
|
|
1531
|
+
continue;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
let { color, offset } = parsed;
|
|
1535
|
+
|
|
1536
|
+
if(color === 'transparent') {
|
|
1537
|
+
color = 'rgba(0,0,0,0)';
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
if(!this._isValidColor(color)) {
|
|
1541
|
+
console.warn('jmGradient: 无效的颜色格式 "' + color + '"');
|
|
1542
|
+
continue;
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
const normalizedOffset = this._normalizeOffset(offset);
|
|
1546
|
+
let finalOffset = normalizedOffset;
|
|
1547
|
+
|
|
1548
|
+
if(finalOffset === null) {
|
|
1549
|
+
if(i === 0) {
|
|
1550
|
+
finalOffset = 0;
|
|
1551
|
+
}
|
|
1552
|
+
else if(i === stops.length - 1) {
|
|
1553
|
+
finalOffset = 1;
|
|
1554
|
+
}
|
|
1555
|
+
else {
|
|
1556
|
+
const nextOffset = this._findNextOffset(stops, i);
|
|
1557
|
+
if(nextOffset !== null) {
|
|
1558
|
+
finalOffset = (lastOffset + nextOffset) / 2;
|
|
1559
|
+
}
|
|
1560
|
+
else {
|
|
1561
|
+
finalOffset = Math.min(1, lastOffset + (1 - lastOffset) / (stops.length - i));
|
|
1229
1562
|
}
|
|
1230
1563
|
}
|
|
1231
1564
|
}
|
|
1565
|
+
|
|
1566
|
+
if(finalOffset !== null) {
|
|
1567
|
+
if(finalOffset < 0 || finalOffset > 1) {
|
|
1568
|
+
console.warn('jmGradient: 颜色偏移量 ' + finalOffset + ' 超出有效范围 [0, 1],将调整为有效范围');
|
|
1569
|
+
finalOffset = Math.max(0, Math.min(1, finalOffset));
|
|
1570
|
+
}
|
|
1571
|
+
lastOffset = finalOffset;
|
|
1572
|
+
this.addStop(finalOffset, color);
|
|
1573
|
+
colorCount++;
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
return colorCount;
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
/**
|
|
1581
|
+
* 分割颜色停止点字符串
|
|
1582
|
+
* @param {string} colorPart 颜色部分字符串
|
|
1583
|
+
* @returns {string[]} 颜色停止点数组
|
|
1584
|
+
*/
|
|
1585
|
+
_splitColorStops(colorPart) {
|
|
1586
|
+
const stops = [];
|
|
1587
|
+
let depth = 0;
|
|
1588
|
+
let current = '';
|
|
1589
|
+
|
|
1590
|
+
for(let i = 0; i < colorPart.length; i++) {
|
|
1591
|
+
const char = colorPart[i];
|
|
1592
|
+
if(char === '(') {
|
|
1593
|
+
depth++;
|
|
1594
|
+
current += char;
|
|
1595
|
+
}
|
|
1596
|
+
else if(char === ')') {
|
|
1597
|
+
depth--;
|
|
1598
|
+
current += char;
|
|
1599
|
+
}
|
|
1600
|
+
else if(char === ',' && depth === 0) {
|
|
1601
|
+
stops.push(current.trim());
|
|
1602
|
+
current = '';
|
|
1603
|
+
}
|
|
1604
|
+
else {
|
|
1605
|
+
current += char;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
if(current.trim()) {
|
|
1610
|
+
stops.push(current.trim());
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
return stops;
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
/**
|
|
1617
|
+
* 解析单个颜色停止点
|
|
1618
|
+
* @param {string} stop 单个颜色停止点字符串
|
|
1619
|
+
* @returns {object|null} {color, offset} 或 null
|
|
1620
|
+
*/
|
|
1621
|
+
_parseSingleColorStop(stop) {
|
|
1622
|
+
const hexMatch = stop.match(/^(#[a-fA-F0-9]{3,8})\s*(\d+(?:\.\d+)?%?)?$/i);
|
|
1623
|
+
if(hexMatch) {
|
|
1624
|
+
return { color: hexMatch[1], offset: hexMatch[2] || null };
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
const rgbaMatch = stop.match(/^(rgba?\s*\([^)]+\))\s*(\d+(?:\.\d+)?%?)?$/i);
|
|
1628
|
+
if(rgbaMatch) {
|
|
1629
|
+
return { color: rgbaMatch[1], offset: rgbaMatch[2] || null };
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
const hslaMatch = stop.match(/^(hsla?\s*\([^)]+\))\s*(\d+(?:\.\d+)?%?)?$/i);
|
|
1633
|
+
if(hslaMatch) {
|
|
1634
|
+
return { color: hslaMatch[1], offset: hslaMatch[2] || null };
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
const namedMatch = stop.match(/^([a-zA-Z]+)\s*(\d+(?:\.\d+)?%?)?$/i);
|
|
1638
|
+
if(namedMatch && this._isValidColor(namedMatch[1])) {
|
|
1639
|
+
return { color: namedMatch[1], offset: namedMatch[2] || null };
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
return null;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
/**
|
|
1646
|
+
* 查找下一个有偏移量的颜色停止点
|
|
1647
|
+
* @param {string[]} stops 颜色停止点数组
|
|
1648
|
+
* @param {number} currentIndex 当前索引
|
|
1649
|
+
* @returns {number|null} 下一个偏移量或null
|
|
1650
|
+
*/
|
|
1651
|
+
_findNextOffset(stops, currentIndex) {
|
|
1652
|
+
for(let i = currentIndex + 1; i < stops.length; i++) {
|
|
1653
|
+
const parsed = this._parseSingleColorStop(jmUtils.trim(stops[i]));
|
|
1654
|
+
if(parsed && parsed.offset) {
|
|
1655
|
+
return this._normalizeOffset(parsed.offset);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
return null;
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
/**
|
|
1662
|
+
* 验证颜色格式是否有效
|
|
1663
|
+
* @param {string} color 颜色字符串
|
|
1664
|
+
* @returns {boolean} 是否有效
|
|
1665
|
+
*/
|
|
1666
|
+
_isValidColor(color) {
|
|
1667
|
+
if(!color) return false;
|
|
1668
|
+
|
|
1669
|
+
const hexPattern = /^#([a-fA-F0-9]{3,8})$/;
|
|
1670
|
+
if(hexPattern.test(color)) return true;
|
|
1671
|
+
|
|
1672
|
+
// 支持 rgba(r,g,b,a) 和 rgba(r, g, b, a) 等各种空格格式
|
|
1673
|
+
const rgbPattern = /^rgba?\s*\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*(,\s*[\d.]+\s*)?\)$/i;
|
|
1674
|
+
if(rgbPattern.test(color)) return true;
|
|
1675
|
+
|
|
1676
|
+
const hslPattern = /^hsla?\s*\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*(,\s*[\d.]+\s*)?\)$/i;
|
|
1677
|
+
if(hslPattern.test(color)) return true;
|
|
1678
|
+
|
|
1679
|
+
// 使用 jmUtils 中的完整 CSS 颜色关键字表
|
|
1680
|
+
if(colorKeywords && colorKeywords[color.toLowerCase()]) return true;
|
|
1681
|
+
|
|
1682
|
+
// 宽松处理:符合 CSS 关键字命名规则的字符串也视为有效颜色
|
|
1683
|
+
// (纯字母,可能在运行时被浏览器或其他环境解析)
|
|
1684
|
+
if(/^[a-zA-Z]+$/.test(color)) return true;
|
|
1685
|
+
|
|
1686
|
+
return false;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
/**
|
|
1690
|
+
* 标准化偏移值
|
|
1691
|
+
* @param {string} offset 偏移字符串
|
|
1692
|
+
* @returns {number|null} 0-1之间的数值或null
|
|
1693
|
+
*/
|
|
1694
|
+
_normalizeOffset(offset) {
|
|
1695
|
+
if(!offset) return null;
|
|
1696
|
+
offset = jmUtils.trim(offset);
|
|
1697
|
+
if(offset.endsWith('%')) {
|
|
1698
|
+
return parseFloat(offset) / 100;
|
|
1699
|
+
}
|
|
1700
|
+
const num = parseFloat(offset);
|
|
1701
|
+
if(isNaN(num)) return null;
|
|
1702
|
+
if(num > 1) {
|
|
1703
|
+
return num / 100;
|
|
1704
|
+
}
|
|
1705
|
+
return num;
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
/**
|
|
1709
|
+
* 检查字符串是否包含角度单位
|
|
1710
|
+
* @param {string} str 待检查字符串
|
|
1711
|
+
* @returns {boolean}
|
|
1712
|
+
*/
|
|
1713
|
+
_hasAngleUnit(str) {
|
|
1714
|
+
return /^-?\d+(\.\d+)?\s*(deg|rad|grad|turn)$/i.test(str);
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
/**
|
|
1718
|
+
* 解析角度值
|
|
1719
|
+
* @param {string} angleStr 角度字符串
|
|
1720
|
+
* @returns {number} 弧度值
|
|
1721
|
+
*/
|
|
1722
|
+
_parseAngle(angleStr) {
|
|
1723
|
+
angleStr = jmUtils.trim(angleStr);
|
|
1724
|
+
const match = angleStr.match(/^(-?\d+(\.\d+)?)\s*(deg|rad|grad|turn)?$/i);
|
|
1725
|
+
if(!match) return 0;
|
|
1726
|
+
|
|
1727
|
+
let value = parseFloat(match[1]);
|
|
1728
|
+
const unit = (match[3] || 'deg').toLowerCase();
|
|
1729
|
+
|
|
1730
|
+
switch(unit) {
|
|
1731
|
+
case 'deg':
|
|
1732
|
+
return value * Math.PI / 180;
|
|
1733
|
+
case 'rad':
|
|
1734
|
+
return value;
|
|
1735
|
+
case 'grad':
|
|
1736
|
+
return value * Math.PI / 200;
|
|
1737
|
+
case 'turn':
|
|
1738
|
+
return value * 2 * Math.PI;
|
|
1739
|
+
default:
|
|
1740
|
+
return value * Math.PI / 180;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
/**
|
|
1745
|
+
* 将角度转换为起点和终点坐标
|
|
1746
|
+
* @param {number} angle 弧度值
|
|
1747
|
+
* @returns {object} 坐标对象
|
|
1748
|
+
*/
|
|
1749
|
+
_angleToCoords(angle) {
|
|
1750
|
+
const x = Math.cos(angle);
|
|
1751
|
+
const y = -Math.sin(angle);
|
|
1752
|
+
|
|
1753
|
+
return {
|
|
1754
|
+
x1: Math.round((0.5 - x * 0.5) * 1000) / 1000,
|
|
1755
|
+
y1: Math.round((0.5 + y * 0.5) * 1000) / 1000,
|
|
1756
|
+
x2: Math.round((0.5 + x * 0.5) * 1000) / 1000,
|
|
1757
|
+
y2: Math.round((0.5 - y * 0.5) * 1000) / 1000
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
/**
|
|
1762
|
+
* 将方向关键词转换为角度和坐标
|
|
1763
|
+
* @param {string} direction 方向描述
|
|
1764
|
+
* @returns {object} 包含angle和坐标的对象
|
|
1765
|
+
*/
|
|
1766
|
+
_directionToAngle(direction) {
|
|
1767
|
+
const directions = {
|
|
1768
|
+
'to top': { angle: 0, x1: '50%', y1: '100%', x2: '50%', y2: '0%' },
|
|
1769
|
+
'to bottom': { angle: Math.PI, x1: '50%', y1: '0%', x2: '50%', y2: '100%' },
|
|
1770
|
+
'to left': { angle: -Math.PI / 2, x1: '100%', y1: '50%', x2: '0%', y2: '50%' },
|
|
1771
|
+
'to right': { angle: Math.PI / 2, x1: '0%', y1: '50%', x2: '100%', y2: '50%' },
|
|
1772
|
+
'to top left': { angle: -Math.PI * 3 / 4, x1: '100%', y1: '100%', x2: '0%', y2: '0%' },
|
|
1773
|
+
'to top right': { angle: -Math.PI / 4, x1: '0%', y1: '100%', x2: '100%', y2: '0%' },
|
|
1774
|
+
'to bottom left': { angle: Math.PI * 3 / 4, x1: '100%', y1: '0%', x2: '0%', y2: '100%' },
|
|
1775
|
+
'to bottom right': { angle: Math.PI / 4, x1: '0%', y1: '0%', x2: '100%', y2: '100%' },
|
|
1776
|
+
'top': { angle: 0, x1: '50%', y1: '100%', x2: '50%', y2: '0%' },
|
|
1777
|
+
'bottom': { angle: Math.PI, x1: '50%', y1: '0%', x2: '50%', y2: '100%' },
|
|
1778
|
+
'left': { angle: -Math.PI / 2, x1: '100%', y1: '50%', x2: '0%', y2: '50%' },
|
|
1779
|
+
'right': { angle: Math.PI / 2, x1: '0%', y1: '50%', x2: '100%', y2: '50%' }
|
|
1780
|
+
};
|
|
1781
|
+
|
|
1782
|
+
const dir = directions[direction];
|
|
1783
|
+
if(dir) {
|
|
1784
|
+
return dir;
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
const keywordMatch = direction.match(/to\s+(top|bottom|left|right)/i);
|
|
1788
|
+
if(keywordMatch) {
|
|
1789
|
+
const mainDir = keywordMatch[1].toLowerCase();
|
|
1790
|
+
const secDir = direction.replace(keywordMatch[0], '').trim();
|
|
1791
|
+
if(secDir) {
|
|
1792
|
+
const combined = `to ${mainDir} ${secDir}`;
|
|
1793
|
+
if(directions[combined]) {
|
|
1794
|
+
return directions[combined];
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1232
1797
|
}
|
|
1798
|
+
|
|
1799
|
+
return { angle: 0, x1: '50%', y1: '100%', x2: '50%', y2: '0%' };
|
|
1233
1800
|
}
|
|
1234
1801
|
|
|
1235
1802
|
/**
|