jmgraph 3.2.25 → 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 +769 -63
- package/dist/jmgraph.min.js +1 -1
- package/index.d.ts +142 -1
- package/package.json +1 -1
- package/src/core/jmGradient.js +595 -63
- 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
|
/**
|