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