jmgraph 3.2.26 → 3.2.27
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/README.md +188 -0
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +52 -10
- package/dist/jmgraph.min.js +1 -1
- package/index.d.ts +142 -1
- package/package.json +1 -1
- package/src/core/jmGradient.js +12 -6
- package/src/core/jmUtils.js +38 -2
package/index.d.ts
CHANGED
|
@@ -66,6 +66,16 @@ export interface ShadowStyle {
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* 渐变色停止点
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* // 偏移量支持 0~1 小数 或 0%~100% 百分比
|
|
72
|
+
* { offset: 0, color: '#e94560' }
|
|
73
|
+
* { offset: 0.5, color: 'rgba(233,69,96,0.8)' }
|
|
74
|
+
* { offset: 1, color: 'blue' }
|
|
75
|
+
*
|
|
76
|
+
* // 字符串格式中,偏移量也可以直接用数值(内部会自动归一化)
|
|
77
|
+
* // 'rgba(233,69,96,0.8) 50' 等价于 { offset: 0.5, color: 'rgba(233,69,96,0.8)' }
|
|
78
|
+
* // '#e94560 50%' 等价于 { offset: 0.5, color: '#e94560' }
|
|
69
79
|
*/
|
|
70
80
|
export interface GradientStop {
|
|
71
81
|
offset: number;
|
|
@@ -73,16 +83,37 @@ export interface GradientStop {
|
|
|
73
83
|
}
|
|
74
84
|
|
|
75
85
|
/**
|
|
76
|
-
*
|
|
86
|
+
* 渐变配置(线性或径向)
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* // 线性渐变 - 方式一:方向关键词
|
|
90
|
+
* { type: 'linear', x1: '50%', y1: '0%', x2: '50%', y2: '100%' }
|
|
91
|
+
*
|
|
92
|
+
* // 线性渐变 - 方式二:绝对坐标(相对于控件边界)
|
|
93
|
+
* { type: 'linear', x1: 0, y1: 0, x2: 0, y2: 200 }
|
|
94
|
+
*
|
|
95
|
+
* // 径向渐变
|
|
96
|
+
* { type: 'radial', x1: '50%', y1: '50%', x2: '50%', y2: '50%', r1: 0, r2: '50%' }
|
|
77
97
|
*/
|
|
78
98
|
export interface GradientOptions {
|
|
79
99
|
type?: 'linear' | 'radial';
|
|
100
|
+
/** 起点 x 坐标,支持数字(像素)、百分比字符串(如 '50%')、小数(0~1 自动乘以尺寸) */
|
|
80
101
|
x1?: number | string;
|
|
102
|
+
/** 起点 y 坐标 */
|
|
81
103
|
y1?: number | string;
|
|
104
|
+
/** 终点 x 坐标 */
|
|
82
105
|
x2?: number | string;
|
|
106
|
+
/** 终点 y 坐标 */
|
|
83
107
|
y2?: number | string;
|
|
108
|
+
/** 径向渐变起始半径 */
|
|
84
109
|
r1?: number | string;
|
|
110
|
+
/** 径向渐变结束半径 */
|
|
85
111
|
r2?: number | string;
|
|
112
|
+
/** 形状参数(径向渐变) */
|
|
113
|
+
shape?: 'circle' | 'ellipse';
|
|
114
|
+
/** 位置参数(径向渐变) */
|
|
115
|
+
position?: { x: string | number; y: string | number };
|
|
116
|
+
/** 渐变颜色停止点 */
|
|
86
117
|
stops?: GradientStop[];
|
|
87
118
|
}
|
|
88
119
|
|
|
@@ -661,23 +692,133 @@ export declare class jmShadow {
|
|
|
661
692
|
|
|
662
693
|
/**
|
|
663
694
|
* 渐变对象
|
|
695
|
+
*
|
|
696
|
+
* 支持完整的 CSS 渐变语法解析,同时也可以通过对象参数或方法链式调用创建渐变。
|
|
697
|
+
*
|
|
698
|
+
* @example
|
|
699
|
+
* // ===== 方式一:CSS 字符串格式 =====
|
|
700
|
+
*
|
|
701
|
+
* // 角度格式(deg/rad/grad/turn)
|
|
702
|
+
* const g1 = new jmGradient('linear-gradient(180deg, #8b5cf6 0%, #6366f1 50%, #4f46e5 100%)');
|
|
703
|
+
*
|
|
704
|
+
* // 方向关键词
|
|
705
|
+
* const g2 = new jmGradient('linear-gradient(to top, #e94560, #00d4ff)');
|
|
706
|
+
* const g3 = new jmGradient('linear-gradient(to right bottom, #ffd93d, #e94560)');
|
|
707
|
+
*
|
|
708
|
+
* // 坐标格式(x1 y1 x2 y2)—— 注意坐标用空格分隔
|
|
709
|
+
* const g4 = new jmGradient('linear-gradient(50% 0 50% 100%, rgba(36,159,218,0) 1, rgba(36,159,218,0.8) 0)');
|
|
710
|
+
*
|
|
711
|
+
* // 径向渐变
|
|
712
|
+
* const g5 = new jmGradient('radial-gradient(circle, #e94560, #8b5cf6)');
|
|
713
|
+
* const g6 = new jmGradient('radial-gradient(ellipse at top, #06b6d4, #8b5cf6)');
|
|
714
|
+
*
|
|
715
|
+
* // ===== 方式二:对象参数 =====
|
|
716
|
+
* const g7 = new jmGradient({
|
|
717
|
+
* type: 'linear',
|
|
718
|
+
* x1: '50%', y1: '0%',
|
|
719
|
+
* x2: '50%', y2: '100%',
|
|
720
|
+
* stops: [
|
|
721
|
+
* { offset: 0, color: 'rgba(36,159,218,0)' },
|
|
722
|
+
* { offset: 1, color: 'rgba(36,159,218,0.8)' }
|
|
723
|
+
* ]
|
|
724
|
+
* });
|
|
725
|
+
*
|
|
726
|
+
* // ===== 方式三:链式调用 =====
|
|
727
|
+
* const g8 = new jmGradient();
|
|
728
|
+
* g8.type = 'linear';
|
|
729
|
+
* g8.x1 = '50%'; g8.y1 = '0%';
|
|
730
|
+
* g8.x2 = '50%'; g8.y2 = '100%';
|
|
731
|
+
* g8.addStop(0, '#e94560');
|
|
732
|
+
* g8.addStop(1, '#00d4ff');
|
|
733
|
+
*
|
|
734
|
+
* // ===== 方式四:使用 jmGraph 便捷方法 =====
|
|
735
|
+
* const lg = graph.createLinearGradient(0, 0, 0, 100);
|
|
736
|
+
* lg.addStop(0, '#e94560');
|
|
737
|
+
* lg.addStop(1, '#00d4ff');
|
|
738
|
+
*
|
|
739
|
+
* const rg = graph.createRadialGradient(100, 100, 0, 100, 100, 50);
|
|
740
|
+
* rg.addStop(0, '#ffd93d');
|
|
741
|
+
* rg.addStop(1, '#f59e0b');
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* // ===== 应用到图形样式 =====
|
|
745
|
+
* const rect = graph.createShape('rect', {
|
|
746
|
+
* position: { x: 100, y: 100 }, width: 200, height: 100,
|
|
747
|
+
* style: { fill: 'linear-gradient(180deg, #e94560 0%, #00d4ff 100%)' }
|
|
748
|
+
* });
|
|
749
|
+
*
|
|
750
|
+
* // 也可以传 jmGradient 实例
|
|
751
|
+
* rect.style.fill = g1;
|
|
664
752
|
*/
|
|
665
753
|
export declare class jmGradient {
|
|
754
|
+
/** 渐变类型:'linear' 线性渐变 | 'radial' 径向渐变 */
|
|
666
755
|
type: 'linear' | 'radial';
|
|
756
|
+
/**
|
|
757
|
+
* 起点/终点坐标,支持多种格式:
|
|
758
|
+
* - 数字:绝对像素值
|
|
759
|
+
* - 百分比字符串(如 '50%'):相对于控件边界尺寸
|
|
760
|
+
* - 0~1 小数:自动乘以控件尺寸
|
|
761
|
+
*/
|
|
667
762
|
x1?: number | string;
|
|
668
763
|
y1?: number | string;
|
|
669
764
|
x2?: number | string;
|
|
670
765
|
y2?: number | string;
|
|
766
|
+
/** 径向渐变半径 */
|
|
671
767
|
r1?: number | string;
|
|
672
768
|
r2?: number | string;
|
|
769
|
+
/** 径向渐变形状('circle' | 'ellipse') */
|
|
770
|
+
shape?: string;
|
|
771
|
+
/** 径向渐变中心位置 */
|
|
772
|
+
position?: { x: string | number; y: string | number };
|
|
773
|
+
/** 颜色停止点列表 */
|
|
673
774
|
stops: jmList<GradientStop>;
|
|
674
775
|
|
|
776
|
+
/**
|
|
777
|
+
* 构造函数
|
|
778
|
+
* @param opt 渐变字符串(CSS格式)或渐变配置对象
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* new jmGradient('linear-gradient(180deg, #e94560 0%, #00d4ff 100%)')
|
|
782
|
+
* new jmGradient({ type: 'linear', x1: 0, y1: 0, x2: 0, y2: 100, stops: [...] })
|
|
783
|
+
*/
|
|
675
784
|
constructor(opt?: string | GradientOptions);
|
|
676
785
|
|
|
786
|
+
/**
|
|
787
|
+
* 添加颜色停止点
|
|
788
|
+
* @param offset 偏移量(0~1 之间)
|
|
789
|
+
* @param color 颜色值,支持 hex、rgb/rgba、hsl/hsla、命名颜色
|
|
790
|
+
*/
|
|
677
791
|
addStop(offset: number, color: string): void;
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* 生成 canvas/WebGL 可用的渐变对象
|
|
795
|
+
* @param control 当前渐变对应的控件
|
|
796
|
+
*/
|
|
678
797
|
toGradient(control: jmControl): any;
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* 从 CSS 渐变字符串解析渐变参数
|
|
801
|
+
* @param s CSS 渐变字符串
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* gradient.fromString('linear-gradient(180deg, #e94560 0%, #00d4ff 100%)');
|
|
805
|
+
* gradient.fromString('radial-gradient(circle, #e94560, #8b5cf6)');
|
|
806
|
+
* gradient.fromString('linear-gradient(50% 0 50% 100%, rgba(36,159,218,0) 1, rgba(36,159,218,0.8) 0)');
|
|
807
|
+
*/
|
|
679
808
|
fromString(s: string): void;
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* 转换为渐变字符串表达
|
|
812
|
+
* @returns 线性: 'linear-gradient(x1 y1 x2 y2, color1 offset, color2 offset, ...)'
|
|
813
|
+
* 径向: 'radial-gradient(x1 y1 r1 x2 y2 r2, color1 offset, color2 offset, ...)'
|
|
814
|
+
*/
|
|
680
815
|
toString(): string;
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* 验证渐变配置是否有效
|
|
819
|
+
* @returns 是否包含必要的渐变参数和至少一个颜色停止点
|
|
820
|
+
*/
|
|
821
|
+
isValid(): boolean;
|
|
681
822
|
}
|
|
682
823
|
|
|
683
824
|
/**
|
package/package.json
CHANGED
package/src/core/jmGradient.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {jmUtils} from "./jmUtils.js";
|
|
1
|
+
import {jmUtils, colorKeywords} from "./jmUtils.js";
|
|
2
2
|
import {jmList} from "./jmList.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -220,7 +220,8 @@ export default class jmGradient {
|
|
|
220
220
|
console.warn('jmGradient: 渐变字符串为空');
|
|
221
221
|
return;
|
|
222
222
|
}
|
|
223
|
-
|
|
223
|
+
// 使用 [\s\S] 匹配任意字符(包括换行符),支持多行渐变字符串
|
|
224
|
+
const gradientMatch = s.match(/(linear|radial)-gradient\s*\(\s*([\s\S]+)\)/i);
|
|
224
225
|
if(!gradientMatch || gradientMatch.length < 3) {
|
|
225
226
|
console.warn('jmGradient: 无效的渐变字符串格式: "' + s + '"');
|
|
226
227
|
return;
|
|
@@ -605,14 +606,19 @@ export default class jmGradient {
|
|
|
605
606
|
const hexPattern = /^#([a-fA-F0-9]{3,8})$/;
|
|
606
607
|
if(hexPattern.test(color)) return true;
|
|
607
608
|
|
|
608
|
-
|
|
609
|
+
// 支持 rgba(r,g,b,a) 和 rgba(r, g, b, a) 等各种空格格式
|
|
610
|
+
const rgbPattern = /^rgba?\s*\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*(,\s*[\d.]+\s*)?\)$/i;
|
|
609
611
|
if(rgbPattern.test(color)) return true;
|
|
610
612
|
|
|
611
|
-
const hslPattern = /^hsla?\s*\(\s
|
|
613
|
+
const hslPattern = /^hsla?\s*\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*(,\s*[\d.]+\s*)?\)$/i;
|
|
612
614
|
if(hslPattern.test(color)) return true;
|
|
613
615
|
|
|
614
|
-
|
|
615
|
-
if(
|
|
616
|
+
// 使用 jmUtils 中的完整 CSS 颜色关键字表
|
|
617
|
+
if(colorKeywords && colorKeywords[color.toLowerCase()]) return true;
|
|
618
|
+
|
|
619
|
+
// 宽松处理:符合 CSS 关键字命名规则的字符串也视为有效颜色
|
|
620
|
+
// (纯字母,可能在运行时被浏览器或其他环境解析)
|
|
621
|
+
if(/^[a-zA-Z]+$/.test(color)) return true;
|
|
616
622
|
|
|
617
623
|
return false;
|
|
618
624
|
}
|
package/src/core/jmUtils.js
CHANGED
|
@@ -38,11 +38,13 @@ const colorKeywords = {
|
|
|
38
38
|
darkseagreen: "#8fbc8f",
|
|
39
39
|
darkslateblue: "#483d8b",
|
|
40
40
|
darkslategray: "#2f4f4f",
|
|
41
|
+
darkslategrey: "#2f4f4f",
|
|
41
42
|
darkturquoise: "#00ced1",
|
|
42
43
|
darkviolet: "#9400d3",
|
|
43
44
|
deeppink: "#ff1493",
|
|
44
45
|
deepskyblue: "#00bfff",
|
|
45
46
|
dimgray: "#696969",
|
|
47
|
+
dimgrey: "#696969",
|
|
46
48
|
dodgerblue: "#1e90ff",
|
|
47
49
|
firebrick: "#b22222",
|
|
48
50
|
floralwhite: "#fffaf0",
|
|
@@ -77,6 +79,7 @@ const colorKeywords = {
|
|
|
77
79
|
lightseagreen: "#20b2aa",
|
|
78
80
|
lightskyblue: "#87cefa",
|
|
79
81
|
lightslategray: "#778899",
|
|
82
|
+
lightslategrey: "#778899",
|
|
80
83
|
lightsteelblue: "#b0c4de",
|
|
81
84
|
lightyellow: "#ffffe0",
|
|
82
85
|
lime: "#00ff00",
|
|
@@ -117,6 +120,7 @@ const colorKeywords = {
|
|
|
117
120
|
powderblue: "#b0e0e6",
|
|
118
121
|
purple: "#800080",
|
|
119
122
|
red: "#ff0000",
|
|
123
|
+
rebeccapurple: "#663399",
|
|
120
124
|
rosybrown: "#bc8f8f",
|
|
121
125
|
royalblue: "#4169e1",
|
|
122
126
|
saddlebrown: "#8b4513",
|
|
@@ -129,6 +133,7 @@ const colorKeywords = {
|
|
|
129
133
|
skyblue: "#87ceeb",
|
|
130
134
|
slateblue: "#6a5acd",
|
|
131
135
|
slategray: "#708090",
|
|
136
|
+
slategrey: "#708090",
|
|
132
137
|
snow: "#fffafa",
|
|
133
138
|
springgreen: "#00ff7f",
|
|
134
139
|
steelblue: "#4682b4",
|
|
@@ -143,7 +148,37 @@ const colorKeywords = {
|
|
|
143
148
|
whitesmoke: "#f5f5f5",
|
|
144
149
|
yellow: "#ffff00",
|
|
145
150
|
yellowgreen: "#9acd32",
|
|
146
|
-
transparent: "rgba(0,0,0,0)"
|
|
151
|
+
transparent: "rgba(0,0,0,0)",
|
|
152
|
+
// grey 别名(已有 darkslategrey/lightslategrey/slategrey/dimgrey)
|
|
153
|
+
// 以下为 CSS 系统颜色
|
|
154
|
+
activeborder: "#bfcaca",
|
|
155
|
+
activecaption: "#000080",
|
|
156
|
+
appworkspace: "#ababab",
|
|
157
|
+
background: "#636363",
|
|
158
|
+
buttonface: "#c0c0c0",
|
|
159
|
+
buttonhighlight: "#dedede",
|
|
160
|
+
buttonshadow: "#808080",
|
|
161
|
+
buttontext: "#000000",
|
|
162
|
+
captiontext: "#000000",
|
|
163
|
+
graytext: "#808080",
|
|
164
|
+
highlight: "#b3d4fc",
|
|
165
|
+
highlighttext: "#000000",
|
|
166
|
+
inactiveborder: "#d4d0c8",
|
|
167
|
+
inactivecaption: "#bfbbb0",
|
|
168
|
+
inactivecaptiontext: "#545454",
|
|
169
|
+
infobackground: "#fbfcc5",
|
|
170
|
+
infotext: "#000000",
|
|
171
|
+
menu: "#c0c0c0",
|
|
172
|
+
menutext: "#000000",
|
|
173
|
+
scrollbar: "#c0c0c0",
|
|
174
|
+
threeddarkshadow: "#696969",
|
|
175
|
+
threedface: "#c0c0c0",
|
|
176
|
+
threedhighlight: "#dfdfdf",
|
|
177
|
+
threedlightshadow: "#dcdcdc",
|
|
178
|
+
threedshadow: "#808080",
|
|
179
|
+
window: "#ffffff",
|
|
180
|
+
windowframe: "#646464",
|
|
181
|
+
windowtext: "#000000"
|
|
147
182
|
};
|
|
148
183
|
|
|
149
184
|
/**
|
|
@@ -913,4 +948,5 @@ export default class jmUtils {
|
|
|
913
948
|
return fun(handler);
|
|
914
949
|
}
|
|
915
950
|
}
|
|
916
|
-
export { jmUtils };
|
|
951
|
+
export { jmUtils };
|
|
952
|
+
export { colorKeywords };
|