-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathindex.d.ts
More file actions
983 lines (878 loc) · 24.1 KB
/
Copy pathindex.d.ts
File metadata and controls
983 lines (878 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
// Type definitions for jmgraph
// ========================
/**
* 基础坐标点
*/
export interface Point {
x: number;
y: number;
m?: boolean;
}
/**
* 边界对象
*/
export interface Bounds {
left: number;
top: number;
right: number;
bottom: number;
width: number;
height: number;
}
/**
* 位置对象
*/
export interface Position {
left: number;
top: number;
width?: number;
height?: number;
right?: number;
bottom?: number;
}
/**
* 圆角配置(支持数字或四角独立配置)
*/
export type Radius = number | {
topLeft?: number;
topRight?: number;
bottomRight?: number;
bottomLeft?: number;
};
/**
* 规范化的圆角(四角独立)
*/
export interface NormalizedRadius {
topLeft: number;
topRight: number;
bottomRight: number;
bottomLeft: number;
}
/**
* 阴影样式
*/
export interface ShadowStyle {
x: number;
y: number;
blur: number;
color: string;
}
/**
* 渐变色停止点
*
* @example
* // 偏移量支持 0~1 小数 或 0%~100% 百分比
* { offset: 0, color: '#e94560' }
* { offset: 0.5, color: 'rgba(233,69,96,0.8)' }
* { offset: 1, color: 'blue' }
*
* // 字符串格式中,偏移量也可以直接用数值(内部会自动归一化)
* // 'rgba(233,69,96,0.8) 50' 等价于 { offset: 0.5, color: 'rgba(233,69,96,0.8)' }
* // '#e94560 50%' 等价于 { offset: 0.5, color: '#e94560' }
*/
export interface GradientStop {
offset: number;
color: string;
}
/**
* 渐变配置(线性或径向)
*
* @example
* // 线性渐变 - 方式一:方向关键词
* { type: 'linear', x1: '50%', y1: '0%', x2: '50%', y2: '100%' }
*
* // 线性渐变 - 方式二:绝对坐标(相对于控件边界)
* { type: 'linear', x1: 0, y1: 0, x2: 0, y2: 200 }
*
* // 径向渐变
* { type: 'radial', x1: '50%', y1: '50%', x2: '50%', y2: '50%', r1: 0, r2: '50%' }
*/
export interface GradientOptions {
type?: 'linear' | 'radial';
/** 起点 x 坐标,支持数字(像素)、百分比字符串(如 '50%')、小数(0~1 自动乘以尺寸) */
x1?: number | string;
/** 起点 y 坐标 */
y1?: number | string;
/** 终点 x 坐标 */
x2?: number | string;
/** 终点 y 坐标 */
y2?: number | string;
/** 径向渐变起始半径 */
r1?: number | string;
/** 径向渐变结束半径 */
r2?: number | string;
/** 形状参数(径向渐变) */
shape?: 'circle' | 'ellipse';
/** 位置参数(径向渐变) */
position?: { x: string | number; y: string | number };
/** 渐变颜色停止点 */
stops?: GradientStop[];
}
/**
* 变换配置
*/
export interface TransformStyle {
scaleX?: number;
skewX?: number;
skewY?: number;
scaleY?: number;
offsetX?: number;
offsetY?: number;
}
/**
* 旋转配置
*/
export interface RotationStyle {
angle: number;
x?: number | string;
y?: number | string;
}
/**
* 控件样式
*/
export interface jmStyle {
fill?: string | jmGradient;
fillImage?: string;
fillStyle?: string;
stroke?: string;
strokeStyle?: string;
close?: boolean;
lineWidth?: number;
miterLimit?: number;
font?: string;
fontSize?: number;
fontFamily?: string;
opacity?: number;
globalAlpha?: number;
textAlign?: CanvasTextAlign;
textBaseline?: CanvasTextBaseline;
shadow?: string | ShadowStyle;
shadowBlur?: number;
shadowColor?: string;
shadowOffsetX?: number;
shadowOffsetY?: number;
lineJoin?: CanvasLineJoin;
lineCap?: CanvasLineCap;
lineDash?: number[] | string;
lineDashOffset?: number;
lineType?: 'solid' | 'dotted';
dashLength?: number;
filter?: string | jmFilter;
globalCompositeOperation?: GlobalCompositeOperation;
rotation?: RotationStyle;
translate?: { x: number | string; y: number | string };
transform?: number[] | TransformStyle;
clipPath?: jmControl;
mask?: jmControl;
cursor?: string;
close?: boolean;
zIndex?: number | string;
margin?: {
left?: number;
top?: number;
right?: number;
bottom?: number;
};
touchPadding?: number;
maxWidth?: number;
lineHeight?: number;
radius?: number;
borderRadius?: number;
lineJoin?: CanvasLineJoin;
lineCap?: CanvasLineCap;
color?: string;
image?: string;
[key: string]: any;
}
/**
* jmGraph 构造选项
*/
export interface jmGraphOptions {
width?: number;
height?: number;
mode?: '2d' | 'webgl';
autoRefresh?: boolean;
interactive?: boolean;
style?: jmStyle;
shapes?: Record<string, new (...args: any[]) => any>;
[key: string]: any;
}
/**
* 控件构造参数
*/
export interface jmControlParams {
style?: jmStyle;
width?: number | string;
height?: number | string;
position?: Point;
center?: Point;
start?: Point;
end?: Point;
graph?: jmGraph;
zIndex?: number;
interactive?: boolean;
hitArea?: { x: number; y: number; width: number; height: number };
isRegular?: boolean;
needCut?: boolean;
points?: Point[];
mode?: string;
radius?: Radius;
[key: string]: any;
}
/**
* 路径构造参数
*/
export interface jmPathParams extends jmControlParams {
points?: Point[];
}
/**
* 事件参数
*/
export interface jmEventArgs {
position: Point & {
pageX: number;
pageY: number;
clientX: number;
clientY: number;
offsetX: number;
offsetY: number;
layerX: number;
layerY: number;
screenX: number;
screenY: number;
x: number;
y: number;
isTouch: boolean;
touches?: TouchList;
isWXMiniApp?: boolean;
};
button?: number;
keyCode?: number;
ctrlKey?: boolean;
cancel?: boolean;
event: Event;
srcElement?: Element;
target?: jmControl;
path?: jmControl[];
eventName?: string;
offsetX?: number;
offsetY?: number;
trans?: boolean;
}
/**
* 事件属性变更参数
*/
export interface PropertyChangeArgs {
oldValue: any;
newValue: any;
}
/**
* 基础对象类
*/
export declare class jmObject {
id: number;
graph?: jmGraph;
constructor(g?: any);
is(type: string | (new (...args: any[]) => any)): boolean;
animate(handle: (...args: any[]) => boolean | void, millisec?: number, ...params: any[]): void;
}
/**
* 列表类,扩展自Array
*/
export declare class jmList<T = any> extends Array<T> {
option: Record<string, any>;
type: string;
constructor(items?: T[]);
add(obj: T | T[]): T | T[];
remove(obj: T): void;
removeAt(index: number): void;
contain(obj: T): boolean;
get(index: number | ((item: T, index: number) => boolean)): T | undefined;
each(cb: (index: number, item: T) => boolean | void, inverse?: boolean): void;
count(handler?: (item: T) => boolean): number;
clear(): void;
sort(compareFn?: (a: T, b: T) => number): number;
splice(start: number, deleteCount?: number, ...items: T[]): T[];
includes(searchElement: T, fromIndex?: number): boolean;
find(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): T | undefined;
}
/**
* 属性基类
*/
export declare class jmProperty extends jmObject {
constructor(params?: { mode?: string });
property(name: string): any;
property(name: string, value: any): any;
needUpdate: boolean;
graph: jmGraph;
mode: '2d' | 'webgl';
requestAnimationFrame(handler: FrameRequestCallback): number;
cancelAnimationFrame(handler: number): void;
on(name: string, handle: (...args: any[]) => any): void;
bind(name: string, handle: (...args: any[]) => any): void;
unbind(name: string, handle?: (...args: any[]) => any): void;
emit(name: string, ...args: any[]): this;
getEvent(name: string): jmList;
runEventHandle(name: string, args: any[]): boolean | undefined;
}
/**
* 控件基类
*/
export declare class jmControl extends jmProperty {
constructor(params?: jmControlParams, t?: string);
readonly type: string;
context: CanvasRenderingContext2D;
style: jmStyle;
visible: boolean;
interactive: boolean;
hitArea: { x: number; y: number; width: number; height: number } | null;
children: jmList<jmControl>;
width: number | string;
height: number | string;
zIndex: number;
parent: jmControl | null;
option: jmControlParams;
cursor: string;
focused?: boolean;
bounds: Bounds | null;
absoluteBounds: Bounds | null;
location: any;
points?: Point[];
destroyed?: boolean;
initializing(): void;
setStyle(style?: jmStyle): void;
getBounds(isReset?: boolean): Bounds;
getRotationBounds(rotation?: any, bounds?: Bounds | null): Bounds & { oldBounds?: Bounds };
getLocation(reset?: boolean): any;
getRotation(rotation?: any, bounds?: Bounds | null): { angle: number; x?: number; y?: number; bounds?: Bounds };
getTranslate(translate?: any, bounds?: Bounds | null): { x: number; y: number };
remove(): void;
offset(x: number, y: number, trans?: boolean, evt?: any): void;
getAbsoluteBounds(): Bounds;
toAbsolutePoint(point: Point): Point;
toLocalPosition(point: Point): Point | false;
beginDraw(): void;
endDraw(): void;
draw(): void;
paint(v?: boolean): void;
initPoints?(): Point[];
bind(name: string, handle: (...args: any[]) => any): void;
on(name: string, handle: (...args: any[]) => any): void;
unbind(name: string, handle?: (...args: any[]) => any): void;
emit(name: string, ...args: any[]): this;
getEvent(name: string): jmList;
runEventHandle(name: string, args: any[]): boolean | undefined;
checkPoint(p: Point, pad?: number): boolean;
raiseEvent(name: string, args: any): boolean | undefined;
runEventAndPopEvent(name: string, args: any): void;
clearEvents(name: string): void;
findParent(type: string | (new (...args: any[]) => any)): jmControl | null;
canMove(m: boolean, graph?: jmGraph): this;
}
/**
* 基础路径类
*/
export declare class jmPath extends jmControl {
constructor(params?: jmPathParams, t?: string);
points: Point[];
toSVG(): string;
}
/**
* 圆弧图形
*/
export declare class jmArc extends jmPath {
constructor(params?: jmControlParams & {
center?: Point;
radius?: number;
start?: number;
startAngle?: number;
end?: number;
endAngle?: number;
anticlockwise?: boolean;
isFan?: boolean;
}, t?: string);
center: Point;
radius: number;
startAngle: number;
endAngle: number;
anticlockwise: boolean;
isFan: boolean;
initPoints(): Point[];
}
/**
* 空心圆弧
*/
export declare class jmHArc extends jmArc {
constructor(params?: jmControlParams & {
minRadius?: number;
maxRadius?: number;
}, t?: string);
minRadius: number;
maxRadius: number;
}
/**
* 圆形
*/
export declare class jmCircle extends jmArc {
constructor(params?: jmControlParams & {
center?: Point;
radius?: number;
width?: number;
height?: number;
}, t?: string);
initPoints(): Point[];
draw(): void;
}
/**
* 椭圆
*/
export declare class jmEllipse extends jmArc {
constructor(params?: jmControlParams & {
center?: Point;
width?: number;
height?: number;
startAngle?: number;
endAngle?: number;
anticlockwise?: boolean;
}, t?: string);
initPoints(): Point[];
}
/**
* 直线
*/
export declare class jmLine extends jmPath {
constructor(params?: jmControlParams & {
start?: Point;
end?: Point;
lineType?: 'solid' | 'dotted';
dashLength?: number;
}, t?: string);
start: Point;
end: Point;
initPoints(): Point[];
}
/**
* 矩形
*/
export declare class jmRect extends jmPath {
constructor(params?: jmControlParams & {
radius?: Radius;
}, t?: string);
radius: Radius;
position: Point;
getNormalizedRadius(): NormalizedRadius;
hasRadius(): boolean;
getBounds(isReset?: boolean): Bounds;
initPoints(): Point[];
}
/**
* 箭头
*/
export declare class jmArrow extends jmPath {
constructor(params?: jmControlParams & {
start?: Point;
end?: Point;
angle?: number;
offsetX?: number;
offsetY?: number;
}, t?: string);
start: Point;
end: Point;
angle: number;
offsetX: number;
offsetY: number;
initPoints(): Point[];
}
/**
* 带箭头直线
*/
export declare class jmArrowLine extends jmLine {
constructor(params?: jmControlParams & {
start?: Point;
end?: Point;
}, t?: string);
arrow: jmArrow;
arrowVisible?: boolean;
initPoints(): Point[];
}
/**
* 贝塞尔曲线
*/
export declare class jmBezier extends jmPath {
constructor(params?: jmPathParams, t?: string);
cpoints: Point[];
initPoints(): Point[];
getPoint(ps: Point[], t: number): Point;
offset(x: number, y: number, trans?: boolean): void;
}
/**
* 棱形
*/
export declare class jmPrismatic extends jmPath {
constructor(params?: jmControlParams & {
center?: Point;
}, t?: string);
center: Point;
initPoints(): Point[];
}
/**
* 文字标签
*/
export declare class jmLabel extends jmControl {
constructor(params?: jmControlParams & {
text?: string;
value?: string;
center?: Point;
}, t?: string);
text: string;
center: Point | null;
position: Point;
getLocation(): any;
initPoints(): Point[];
testSize(): { width: number; height: number };
wrapText(text: string, maxWidth: number): string[];
draw(): void;
endDraw(): void;
}
/**
* 图片控件
*/
export declare class jmImage extends jmControl {
constructor(params?: jmControlParams & {
image?: string | HTMLImageElement;
sourcePosition?: Point;
sourceWidth?: number;
sourceHeight?: number;
fill?: string;
}, t?: string);
sourcePosition: Point;
sourceWidth: number;
sourceHeight: number;
image: string | HTMLImageElement;
}
/**
* 可缩放控件
*/
export declare class jmResize extends jmRect {
constructor(params?: jmControlParams & {
resizable?: boolean;
movable?: boolean;
rectSize?: number;
}, t?: string);
resizable: boolean;
movable: boolean;
rectSize: number;
}
/**
* 多边形
*/
export declare class jmPolygon extends jmPath {
constructor(params?: jmControlParams & {
sides?: number;
radius?: number;
center?: Point;
}, t?: string);
sides: number;
radius: number;
center: Point;
initPoints(): Point[];
}
/**
* 星形
*/
export declare class jmStar extends jmPath {
constructor(params?: jmControlParams & {
points?: number;
radius?: number;
innerRadius?: number;
center?: Point;
}, t?: string);
pointsCount: number;
radius: number;
innerRadius: number;
center: Point;
initPoints(): Point[];
}
/**
* 阴影对象
*/
export declare class jmShadow {
x: number;
y: number;
blur: number;
color: string;
constructor(x: number | string, y?: number, blur?: number, color?: string);
fromString(s: string): this;
toString(): string;
}
/**
* 渐变对象
*
* 支持完整的 CSS 渐变语法解析,同时也可以通过对象参数或方法链式调用创建渐变。
*
* @example
* // ===== 方式一:CSS 字符串格式 =====
*
* // 角度格式(deg/rad/grad/turn)
* const g1 = new jmGradient('linear-gradient(180deg, #8b5cf6 0%, #6366f1 50%, #4f46e5 100%)');
*
* // 方向关键词
* const g2 = new jmGradient('linear-gradient(to top, #e94560, #00d4ff)');
* const g3 = new jmGradient('linear-gradient(to right bottom, #ffd93d, #e94560)');
*
* // 坐标格式(x1 y1 x2 y2)—— 注意坐标用空格分隔
* const g4 = new jmGradient('linear-gradient(50% 0 50% 100%, rgba(36,159,218,0) 1, rgba(36,159,218,0.8) 0)');
*
* // 径向渐变
* const g5 = new jmGradient('radial-gradient(circle, #e94560, #8b5cf6)');
* const g6 = new jmGradient('radial-gradient(ellipse at top, #06b6d4, #8b5cf6)');
*
* // ===== 方式二:对象参数 =====
* const g7 = new jmGradient({
* type: 'linear',
* x1: '50%', y1: '0%',
* x2: '50%', y2: '100%',
* stops: [
* { offset: 0, color: 'rgba(36,159,218,0)' },
* { offset: 1, color: 'rgba(36,159,218,0.8)' }
* ]
* });
*
* // ===== 方式三:链式调用 =====
* const g8 = new jmGradient();
* g8.type = 'linear';
* g8.x1 = '50%'; g8.y1 = '0%';
* g8.x2 = '50%'; g8.y2 = '100%';
* g8.addStop(0, '#e94560');
* g8.addStop(1, '#00d4ff');
*
* // ===== 方式四:使用 jmGraph 便捷方法 =====
* const lg = graph.createLinearGradient(0, 0, 0, 100);
* lg.addStop(0, '#e94560');
* lg.addStop(1, '#00d4ff');
*
* const rg = graph.createRadialGradient(100, 100, 0, 100, 100, 50);
* rg.addStop(0, '#ffd93d');
* rg.addStop(1, '#f59e0b');
*
* @example
* // ===== 应用到图形样式 =====
* const rect = graph.createShape('rect', {
* position: { x: 100, y: 100 }, width: 200, height: 100,
* style: { fill: 'linear-gradient(180deg, #e94560 0%, #00d4ff 100%)' }
* });
*
* // 也可以传 jmGradient 实例
* rect.style.fill = g1;
*/
export declare class jmGradient {
/** 渐变类型:'linear' 线性渐变 | 'radial' 径向渐变 */
type: 'linear' | 'radial';
/**
* 起点/终点坐标,支持多种格式:
* - 数字:绝对像素值
* - 百分比字符串(如 '50%'):相对于控件边界尺寸
* - 0~1 小数:自动乘以控件尺寸
*/
x1?: number | string;
y1?: number | string;
x2?: number | string;
y2?: number | string;
/** 径向渐变半径 */
r1?: number | string;
r2?: number | string;
/** 径向渐变形状('circle' | 'ellipse') */
shape?: string;
/** 径向渐变中心位置 */
position?: { x: string | number; y: string | number };
/** 颜色停止点列表 */
stops: jmList<GradientStop>;
/**
* 构造函数
* @param opt 渐变字符串(CSS格式)或渐变配置对象
*
* @example
* new jmGradient('linear-gradient(180deg, #e94560 0%, #00d4ff 100%)')
* new jmGradient({ type: 'linear', x1: 0, y1: 0, x2: 0, y2: 100, stops: [...] })
*/
constructor(opt?: string | GradientOptions);
/**
* 添加颜色停止点
* @param offset 偏移量(0~1 之间)
* @param color 颜色值,支持 hex、rgb/rgba、hsl/hsla、命名颜色
*/
addStop(offset: number, color: string): void;
/**
* 生成 canvas/WebGL 可用的渐变对象
* @param control 当前渐变对应的控件
*/
toGradient(control: jmControl): any;
/**
* 从 CSS 渐变字符串解析渐变参数
* @param s CSS 渐变字符串
*
* @example
* gradient.fromString('linear-gradient(180deg, #e94560 0%, #00d4ff 100%)');
* gradient.fromString('radial-gradient(circle, #e94560, #8b5cf6)');
* gradient.fromString('linear-gradient(50% 0 50% 100%, rgba(36,159,218,0) 1, rgba(36,159,218,0.8) 0)');
*/
fromString(s: string): void;
/**
* 转换为渐变字符串表达
* @returns 线性: 'linear-gradient(x1 y1 x2 y2, color1 offset, color2 offset, ...)'
* 径向: 'radial-gradient(x1 y1 r1 x2 y2 r2, color1 offset, color2 offset, ...)'
*/
toString(): string;
/**
* 验证渐变配置是否有效
* @returns 是否包含必要的渐变参数和至少一个颜色停止点
*/
isValid(): boolean;
}
/**
* CSS滤镜对象
*/
export declare class jmFilter {
filters: Array<{ name: string; value: number }>;
constructor(opt?: string | Record<string, number>);
addFilter(name: string, value: number | string): void;
fromString(s: string): void;
toString(): string;
toCanvasFilter(): string;
has(name: string): boolean;
get(name: string): number | undefined;
remove(name: string): void;
clear(): void;
}
/**
* 工具类
*/
export declare class jmUtils {
static clone(source: any, target?: any | boolean, deep?: boolean, copyHandler?: Function): any;
static bindEvent(target: any, name: string, fun: EventListener, opt?: any): { name: string; target: any; fun: EventListener };
static removeEvent(target: any, name: string, fun: EventListener): void;
static getElementPosition(el: Element): { top: number; left: number };
static getEventPosition(evt: any, scale?: Point): Point & {
pageX: number;
pageY: number;
clientX: number;
clientY: number;
offsetX: number;
offsetY: number;
layerX: number;
layerY: number;
screenX: number;
screenY: number;
isTouch: boolean;
touches?: TouchList;
isWXMiniApp?: boolean;
};
static isType(target: any, type: new (...args: any[]) => any): boolean;
static pointInPolygon(pt: Point, polygon: Point[], offset?: number): number;
static pointOnLine(pt: Point, p1: Point, p2: Point, offset: number): number;
static checkOutSide(parentBounds: Bounds, targetBounds: Bounds, offset: Point): { left: number; right: number; top: number; bottom: number };
static rotatePoints(p: Point[] | Point, rp: Point, r: number): Point[] | Point;
static trimStart(source: string, c?: string): string;
static trimEnd(source: string, c?: string): string;
static trim(source: string, c?: string): string;
static checkPercent(per: string): string | undefined;
static percentToNumber(per: string): number;
static hexToNumber(h: string): number;
static numberToHex(v: number): string;
static hexToRGBA(hex: string): string | { r: number; g: number; b: number; a: number };
static rgbToDecimal(color: { r: number; g: number; b: number; a: number }): { r: number; g: number; b: number; a: number };
static toColor(r: string | number | { r: number; g: number; b: number; a?: number }, g?: number, b?: number, a?: number): string;
static requestAnimationFrame(callback: FrameRequestCallback, win?: any): number;
static cancelAnimationFrame(handler: number, win?: any): void;
}
/**
* 事件处理器
*/
export declare class jmEvents {
container: jmGraph;
target: any;
constructor(container: jmGraph, target?: any);
touchStart(evt: any): boolean | undefined;
touchMove(evt: any): boolean | undefined;
touchEnd(evt: any): boolean | undefined;
touchCancel(evt: any): boolean | undefined;
tap(evt: any): boolean | undefined;
destroy(): void;
}
/**
* 已注册的图形类型映射
*/
export type ShapeTypes = {
'path': typeof jmPath;
'arc': typeof jmArc;
'arrow': typeof jmArrow;
'arrowline': typeof jmArrowLine;
'bezier': typeof jmBezier;
'circle': typeof jmCircle;
'harc': typeof jmHArc;
'line': typeof jmLine;
'prismatic': typeof jmPrismatic;
'rect': typeof jmRect;
'image': typeof jmImage;
'img': typeof jmImage;
'label': typeof jmLabel;
'resize': typeof jmResize;
'ellipse': typeof jmEllipse;
'polygon': typeof jmPolygon;
'star': typeof jmStar;
};
/**
* jmGraph 画图类库主类
*/
export declare class jmGraph extends jmControl {
constructor(canvas: HTMLElement | string, option?: jmGraphOptions | ((graph: jmGraph) => void), callback?: (graph: jmGraph) => void);
option: jmGraphOptions & Record<string, any>;
canvas: HTMLCanvasElement;
container: HTMLElement;
mode: '2d' | 'webgl';
scaleFactor: number;
translation: Point;
devicePixelRatio: number;
dprScaleSize: number;
isWXMiniApp?: boolean;
shapes: Record<string, new (...args: any[]) => any>;
eventHandler: jmEvents;
util: typeof jmUtils;
utils: typeof jmUtils;
normalSize?: { width: number; height: number };
scaleSize?: { x: number; y: number };
destroyed?: boolean;
static create(...args: ConstructorParameters<typeof jmGraph>): jmGraph;
resize(w?: number, h?: number): void;
getPosition(): Position;
registerShape(name: string, shape: new (...args: any[]) => any): void;
createShape<T extends jmControl = jmControl>(shape: string | (new (...args: any[]) => T), args?: any): T;
createShadow(x: number, y: number, blur: number, color: string): jmShadow;
createLinearGradient(x1: number, y1: number, x2: number, y2: number, stops?: GradientStop[]): jmGradient;
createRadialGradient(x1: number, y1: number, r1: number, x2: number, y2: number, r2: number, stops?: GradientStop[]): jmGradient;
refresh(): void;
redraw(w?: number, h?: number): void;
clear(w?: number, h?: number): void;
css(name: string, value?: string): string | undefined;
createPath(points: Point[], style?: jmStyle, option?: object): jmPath;
createLine(start: Point, end: Point, style?: jmStyle): jmLine;
zoomOut(): void;
zoomIn(): void;
zoomActual(): void;
scale(dx: number, dy: number): void;
setZoom(zoom: number, x?: number, y?: number): this;
pan(dx: number, dy: number): this;
resetTransform(): this;
toDataURL(): string;
exportToPNG(fileName?: string, format?: string, quality?: number): void;
exportToJPEG(fileName?: string, quality?: number): void;
exportToSVG(fileName?: string): void;
toSVG(): string;
autoRefresh(callback?: () => void): this;
destroy(): void;
}
/**
* 创建 jmGraph 实例的便捷函数
*/
export declare function create(...args: ConstructorParameters<typeof jmGraph>): jmGraph;
export default jmGraph;