@antv/g6 5.0.30 → 5.0.31
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/g6.min.js +29 -29
- package/dist/lib/animations/types.d.ts +7 -1
- package/dist/lib/elements/base-element.d.ts +3 -2
- package/dist/lib/elements/edges/base-edge.d.ts +3 -3
- package/dist/lib/elements/nodes/base-node.d.ts +3 -3
- package/dist/lib/elements/shapes/badge.d.ts +1 -1
- package/dist/lib/elements/shapes/base-shape.d.ts +1 -1
- package/dist/lib/exports.d.ts +1 -1
- package/dist/lib/plugins/legend.d.ts +22 -14
- package/dist/lib/plugins/minimap/index.d.ts +2 -4
- package/dist/lib/plugins/timebar.d.ts +1 -2
- package/dist/lib/plugins/utils/canvas.d.ts +31 -0
- package/dist/lib/plugins/utils/dom.d.ts +22 -0
- package/dist/lib/types/element.d.ts +0 -8
- package/dist/lib/utils/dom.d.ts +0 -26
- package/dist/lib/utils/style.d.ts +1 -1
- package/dist/lib/version.d.ts +1 -1
- package/esm/animations/types.d.ts +7 -1
- package/esm/elements/base-element.d.ts +3 -2
- package/esm/elements/base-element.js +2 -1
- package/esm/elements/base-element.js.map +1 -1
- package/esm/elements/combos/base-combo.js +6 -6
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/edges/base-edge.d.ts +3 -3
- package/esm/elements/edges/base-edge.js +4 -4
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/nodes/base-node.d.ts +3 -3
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/shapes/badge.d.ts +1 -1
- package/esm/elements/shapes/base-shape.d.ts +1 -1
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/exports.d.ts +1 -1
- package/esm/plugins/background/index.js +1 -1
- package/esm/plugins/background/index.js.map +1 -1
- package/esm/plugins/contextmenu/index.js +1 -1
- package/esm/plugins/contextmenu/index.js.map +1 -1
- package/esm/plugins/grid-line.js +5 -3
- package/esm/plugins/grid-line.js.map +1 -1
- package/esm/plugins/legend.d.ts +22 -14
- package/esm/plugins/legend.js +39 -51
- package/esm/plugins/legend.js.map +1 -1
- package/esm/plugins/minimap/index.d.ts +2 -4
- package/esm/plugins/minimap/index.js +13 -30
- package/esm/plugins/minimap/index.js.map +1 -1
- package/esm/plugins/timebar.d.ts +1 -2
- package/esm/plugins/timebar.js +15 -47
- package/esm/plugins/timebar.js.map +1 -1
- package/esm/plugins/toolbar/index.js +1 -1
- package/esm/plugins/toolbar/index.js.map +1 -1
- package/esm/plugins/utils/canvas.d.ts +31 -0
- package/esm/plugins/utils/canvas.js +55 -0
- package/esm/plugins/utils/canvas.js.map +1 -0
- package/esm/plugins/utils/dom.d.ts +22 -0
- package/esm/plugins/utils/dom.js +52 -0
- package/esm/plugins/utils/dom.js.map +1 -0
- package/esm/plugins/watermark/index.js +1 -1
- package/esm/plugins/watermark/index.js.map +1 -1
- package/esm/runtime/animation.js +5 -2
- package/esm/runtime/animation.js.map +1 -1
- package/esm/runtime/element.js +5 -9
- package/esm/runtime/element.js.map +1 -1
- package/esm/types/element.d.ts +0 -8
- package/esm/utils/dom.d.ts +0 -26
- package/esm/utils/dom.js +0 -65
- package/esm/utils/dom.js.map +1 -1
- package/esm/utils/style.d.ts +1 -1
- package/esm/utils/style.js +2 -2
- package/esm/utils/style.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/animations/types.d.ts +7 -1
- package/lib/elements/base-element.d.ts +3 -2
- package/lib/elements/base-element.js +2 -1
- package/lib/elements/base-element.js.map +1 -1
- package/lib/elements/combos/base-combo.js +6 -6
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/edges/base-edge.d.ts +3 -3
- package/lib/elements/edges/base-edge.js +4 -4
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/nodes/base-node.d.ts +3 -3
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/shapes/badge.d.ts +1 -1
- package/lib/elements/shapes/base-shape.d.ts +1 -1
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/exports.d.ts +1 -1
- package/lib/plugins/background/index.js +1 -1
- package/lib/plugins/background/index.js.map +1 -1
- package/lib/plugins/contextmenu/index.js +1 -1
- package/lib/plugins/contextmenu/index.js.map +1 -1
- package/lib/plugins/grid-line.js +5 -3
- package/lib/plugins/grid-line.js.map +1 -1
- package/lib/plugins/legend.d.ts +22 -14
- package/lib/plugins/legend.js +38 -50
- package/lib/plugins/legend.js.map +1 -1
- package/lib/plugins/minimap/index.d.ts +2 -4
- package/lib/plugins/minimap/index.js +13 -30
- package/lib/plugins/minimap/index.js.map +1 -1
- package/lib/plugins/timebar.d.ts +1 -2
- package/lib/plugins/timebar.js +15 -47
- package/lib/plugins/timebar.js.map +1 -1
- package/lib/plugins/toolbar/index.js +1 -1
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/utils/canvas.d.ts +31 -0
- package/lib/plugins/utils/canvas.js +58 -0
- package/lib/plugins/utils/canvas.js.map +1 -0
- package/lib/plugins/utils/dom.d.ts +22 -0
- package/lib/plugins/utils/dom.js +56 -0
- package/lib/plugins/utils/dom.js.map +1 -0
- package/lib/plugins/watermark/index.js +1 -1
- package/lib/plugins/watermark/index.js.map +1 -1
- package/lib/runtime/animation.js +5 -2
- package/lib/runtime/animation.js.map +1 -1
- package/lib/runtime/element.js +5 -9
- package/lib/runtime/element.js.map +1 -1
- package/lib/types/element.d.ts +0 -8
- package/lib/utils/dom.d.ts +0 -26
- package/lib/utils/dom.js +0 -68
- package/lib/utils/dom.js.map +1 -1
- package/lib/utils/style.d.ts +1 -1
- package/lib/utils/style.js +2 -2
- package/lib/utils/style.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/animations/types.ts +7 -1
- package/src/elements/base-element.ts +5 -3
- package/src/elements/combos/base-combo.ts +6 -6
- package/src/elements/edges/base-edge.ts +6 -7
- package/src/elements/nodes/base-node.ts +2 -3
- package/src/elements/shapes/base-shape.ts +1 -4
- package/src/exports.ts +0 -1
- package/src/global.d.ts +5 -0
- package/src/plugins/background/index.ts +1 -1
- package/src/plugins/contextmenu/index.ts +1 -1
- package/src/plugins/grid-line.ts +5 -3
- package/src/plugins/legend.ts +67 -55
- package/src/plugins/minimap/index.ts +16 -52
- package/src/plugins/timebar.ts +16 -47
- package/src/plugins/toolbar/index.ts +1 -1
- package/src/plugins/utils/canvas.ts +89 -0
- package/src/plugins/utils/dom.ts +65 -0
- package/src/plugins/watermark/index.ts +1 -1
- package/src/runtime/animation.ts +5 -2
- package/src/runtime/element.ts +4 -9
- package/src/types/element.ts +0 -9
- package/src/utils/dom.ts +0 -80
- package/src/utils/style.ts +3 -6
- package/src/version.ts +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { RuntimeContext } from '../../runtime/types';
|
|
2
2
|
import type { CornerPlacement } from '../../types';
|
|
3
|
-
import { createPluginContainer, insertDOM } from '../../utils/dom';
|
|
4
3
|
import type { BasePluginOptions } from '../base-plugin';
|
|
5
4
|
import { BasePlugin } from '../base-plugin';
|
|
5
|
+
import { createPluginContainer, insertDOM } from '../utils/dom';
|
|
6
6
|
import type { ToolbarItem } from './util';
|
|
7
7
|
import { BUILD_IN_SVG_ICON, TOOLBAR_CSS, parsePositionToStyle } from './util';
|
|
8
8
|
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { IRenderer } from '@antv/g';
|
|
2
|
+
import { Canvas as GCanvas } from '@antv/g';
|
|
3
|
+
import { Renderer } from '@antv/g-canvas';
|
|
4
|
+
import { Canvas } from '../../runtime/canvas';
|
|
5
|
+
import type { Placement } from '../../types';
|
|
6
|
+
import { parsePlacement } from '../../utils/placement';
|
|
7
|
+
import { createPluginContainer } from './dom';
|
|
8
|
+
|
|
9
|
+
interface Options {
|
|
10
|
+
/** <zh/> 插件宽度 | <en/> Plugin width */
|
|
11
|
+
width: number;
|
|
12
|
+
/** <zh/> 插件高度 | <en/> Plugin height */
|
|
13
|
+
height: number;
|
|
14
|
+
/** <zh/> 渲染器 | <en/> Render */
|
|
15
|
+
renderer?: IRenderer;
|
|
16
|
+
/** <zh/> 插件放置位置 | <en/> Plugin placement */
|
|
17
|
+
placement: Placement;
|
|
18
|
+
/** <zh/> 插件类名 | <en/> Plugin class name */
|
|
19
|
+
className: string;
|
|
20
|
+
/** <zh/> 指定插件放置容器 | <en/> Specify the plugin placement container */
|
|
21
|
+
container?: string | HTMLElement;
|
|
22
|
+
/** <zh/> 容器样式 | <en/> Container style */
|
|
23
|
+
containerStyle?: Partial<CSSStyleDeclaration>;
|
|
24
|
+
/** <zh/> G6 画布 | <en/> G6 canvas */
|
|
25
|
+
graphCanvas: Canvas;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* <zh/> 创建插件画布
|
|
30
|
+
*
|
|
31
|
+
* <en/> Create a plugin canvas
|
|
32
|
+
* @param options - <zh/> 配置项 | <en/> options
|
|
33
|
+
* @returns <zh/> [容器, 画布] | <en/> [container, canvas]
|
|
34
|
+
*/
|
|
35
|
+
export function createPluginCanvas(options: Options): [HTMLElement, GCanvas] {
|
|
36
|
+
const { width, height, renderer, containerStyle } = options;
|
|
37
|
+
const $container = getContainer(options);
|
|
38
|
+
const [x, y] = computePosition(options);
|
|
39
|
+
|
|
40
|
+
Object.assign($container.style, {
|
|
41
|
+
position: 'absolute',
|
|
42
|
+
left: x + 'px',
|
|
43
|
+
top: y + 'px',
|
|
44
|
+
width: width + 'px',
|
|
45
|
+
height: height + 'px',
|
|
46
|
+
...containerStyle,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const canvas = new GCanvas({
|
|
50
|
+
width,
|
|
51
|
+
height,
|
|
52
|
+
container: $container,
|
|
53
|
+
renderer: renderer || new Renderer(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return [$container, canvas];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* <zh/> 获取容器
|
|
61
|
+
*
|
|
62
|
+
* <en/> Get container
|
|
63
|
+
* @param options - <zh/> 配置项 | <en/> options
|
|
64
|
+
* @returns <zh/> 容器 | <en/> container
|
|
65
|
+
*/
|
|
66
|
+
function getContainer(options: Options) {
|
|
67
|
+
const { container, className, graphCanvas } = options;
|
|
68
|
+
if (container) {
|
|
69
|
+
return typeof container === 'string' ? document.getElementById(container)! : container;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const $container = createPluginContainer(className, false);
|
|
73
|
+
graphCanvas.getContainer()?.appendChild($container);
|
|
74
|
+
return $container;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* <zh/> 计算容器位置
|
|
79
|
+
*
|
|
80
|
+
* <en/> Compute the position of the container
|
|
81
|
+
* @param options - <zh/> 配置项 | <en/> options
|
|
82
|
+
* @returns <zh/> 位置 | <en/> position
|
|
83
|
+
*/
|
|
84
|
+
function computePosition(options: Options) {
|
|
85
|
+
const { width, height, placement, graphCanvas } = options;
|
|
86
|
+
const [W, H] = graphCanvas.getSize();
|
|
87
|
+
const [xRatio, yRatio] = parsePlacement(placement);
|
|
88
|
+
return [xRatio * (W - width), yRatio * (H - height)];
|
|
89
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <zh/> 创建插件容器
|
|
3
|
+
*
|
|
4
|
+
* <en/> Create a plugin container
|
|
5
|
+
* @param type - <zh/> 插件类型 | <en/> plugin type
|
|
6
|
+
* @param cover - <zh/> 容器是否覆盖整个画布 | <en/> Whether the container covers the entire canvas
|
|
7
|
+
* @param style - <zh/> 额外样式 | <en/> Additional style
|
|
8
|
+
* @returns <zh/> 插件容器 | <en/> plugin container
|
|
9
|
+
*/
|
|
10
|
+
export function createPluginContainer(type: string, cover = true, style?: Partial<CSSStyleDeclaration>): HTMLElement {
|
|
11
|
+
const container = document.createElement('div');
|
|
12
|
+
|
|
13
|
+
container.setAttribute('class', `g6-${type}`);
|
|
14
|
+
|
|
15
|
+
Object.assign(container.style, {
|
|
16
|
+
position: 'absolute',
|
|
17
|
+
display: 'block',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (cover) {
|
|
21
|
+
Object.assign(container.style, {
|
|
22
|
+
inset: '0px',
|
|
23
|
+
height: '100%',
|
|
24
|
+
width: '100%',
|
|
25
|
+
overflow: 'hidden',
|
|
26
|
+
pointerEvents: 'none',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (style) Object.assign(container.style, style);
|
|
31
|
+
|
|
32
|
+
return container;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* <zh/> 创建 DOM 元素,如果存在则删除,再创建一个新的
|
|
37
|
+
*
|
|
38
|
+
* <en/> Create a DOM element, if exists, remove it and create a new one.
|
|
39
|
+
* @param id - <zh/> id | <en/> id
|
|
40
|
+
* @param tag - <zh/> 标签 | <en/> tag
|
|
41
|
+
* @param style - <zh/> 样式 | <en/> style
|
|
42
|
+
* @param innerHTML - <zh/> 内容 | <en/> innerHTML
|
|
43
|
+
* @param container - <zh/> 容器 | <en/> container
|
|
44
|
+
* @returns <zh/> 创建的 DOM 元素 | <en/> created DOM element
|
|
45
|
+
*/
|
|
46
|
+
export function insertDOM(
|
|
47
|
+
id: string,
|
|
48
|
+
tag = 'div',
|
|
49
|
+
style: Partial<CSSStyleDeclaration> = {},
|
|
50
|
+
innerHTML = '',
|
|
51
|
+
container: HTMLElement = document.body,
|
|
52
|
+
) {
|
|
53
|
+
const dom = document.getElementById(id);
|
|
54
|
+
if (dom) dom.remove();
|
|
55
|
+
|
|
56
|
+
const div = document.createElement(tag);
|
|
57
|
+
div.innerHTML = innerHTML;
|
|
58
|
+
div.id = id;
|
|
59
|
+
|
|
60
|
+
Object.assign(div.style, style);
|
|
61
|
+
|
|
62
|
+
container.appendChild(div);
|
|
63
|
+
|
|
64
|
+
return div;
|
|
65
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RuntimeContext } from '../../runtime/types';
|
|
2
|
-
import { createPluginContainer } from '../../utils/dom';
|
|
3
2
|
import type { BasePluginOptions } from '../base-plugin';
|
|
4
3
|
import { BasePlugin } from '../base-plugin';
|
|
4
|
+
import { createPluginContainer } from '../utils/dom';
|
|
5
5
|
import { getImageWatermark, getTextWatermark } from './util';
|
|
6
6
|
|
|
7
7
|
/**
|
package/src/runtime/animation.ts
CHANGED
|
@@ -39,7 +39,7 @@ export class Animation {
|
|
|
39
39
|
const { element, elementType, stage } = context;
|
|
40
40
|
const options = getElementAnimationOptions(this.context.options, elementType, stage, localAnimation);
|
|
41
41
|
cb?.before?.();
|
|
42
|
-
const animation = executor(element, this.inferStyle(context, extendOptions), options);
|
|
42
|
+
const animation = options.length ? executor(element, this.inferStyle(context, extendOptions), options) : null;
|
|
43
43
|
|
|
44
44
|
if (animation) {
|
|
45
45
|
cb?.beforeAnimate?.(animation);
|
|
@@ -83,7 +83,10 @@ export class Animation {
|
|
|
83
83
|
context: AnimationContext,
|
|
84
84
|
options?: ExtendOptions,
|
|
85
85
|
): [Record<string, unknown>, Record<string, unknown>] {
|
|
86
|
-
const { element, elementType, stage, originalStyle,
|
|
86
|
+
const { element, elementType, stage, originalStyle, updatedStyle = {} } = context;
|
|
87
|
+
|
|
88
|
+
if (!context.modifiedStyle) context.modifiedStyle = { ...originalStyle, ...updatedStyle };
|
|
89
|
+
const { modifiedStyle } = context;
|
|
87
90
|
|
|
88
91
|
const fromStyle: Record<string, unknown> = {};
|
|
89
92
|
const toStyle: Record<string, unknown> = {};
|
package/src/runtime/element.ts
CHANGED
|
@@ -387,16 +387,11 @@ export class ElementController {
|
|
|
387
387
|
|
|
388
388
|
this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_CREATE, elementType, datum), context);
|
|
389
389
|
|
|
390
|
-
// if (context.stage === 'expand') {
|
|
391
|
-
// // 如果是展开的元素,需要将其 zIndex 提升至目标元素的上层
|
|
392
|
-
// const targetZIndex = this.getElementZIndex(context.target!);
|
|
393
|
-
// if (!style.zIndex || style.zIndex < targetZIndex) style.zIndex = targetZIndex + (style.zIndex ?? 0);
|
|
394
|
-
// }
|
|
395
390
|
const element = this.container.appendChild(
|
|
396
391
|
new Ctor({
|
|
397
392
|
id,
|
|
393
|
+
context: this.context,
|
|
398
394
|
style: {
|
|
399
|
-
context: this.context,
|
|
400
395
|
...style,
|
|
401
396
|
},
|
|
402
397
|
}),
|
|
@@ -413,7 +408,7 @@ export class ElementController {
|
|
|
413
408
|
elementType,
|
|
414
409
|
stage,
|
|
415
410
|
originalStyle: { ...element.attributes },
|
|
416
|
-
|
|
411
|
+
updatedStyle: style,
|
|
417
412
|
},
|
|
418
413
|
{
|
|
419
414
|
after: () => {
|
|
@@ -486,7 +481,7 @@ export class ElementController {
|
|
|
486
481
|
elementType,
|
|
487
482
|
stage: exactStage,
|
|
488
483
|
originalStyle: { ...element.attributes },
|
|
489
|
-
|
|
484
|
+
updatedStyle: style,
|
|
490
485
|
},
|
|
491
486
|
{
|
|
492
487
|
before: () => {
|
|
@@ -559,7 +554,7 @@ export class ElementController {
|
|
|
559
554
|
elementType,
|
|
560
555
|
stage,
|
|
561
556
|
originalStyle: { ...element.attributes },
|
|
562
|
-
|
|
557
|
+
updatedStyle: {},
|
|
563
558
|
},
|
|
564
559
|
{
|
|
565
560
|
after: () => {
|
package/src/types/element.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { DisplayObject } from '@antv/g';
|
|
2
|
-
import { BaseShapeStyleProps } from '../elements/shapes';
|
|
3
|
-
import type { RuntimeContext } from '../runtime/types';
|
|
4
2
|
import type { ComboOptions, EdgeOptions, NodeOptions } from '../spec';
|
|
5
3
|
import type { Point, Port } from '../types';
|
|
6
4
|
|
|
@@ -67,13 +65,6 @@ export type ElementType = 'node' | 'edge' | 'combo';
|
|
|
67
65
|
|
|
68
66
|
export type ElementOptions = NodeOptions | EdgeOptions | ComboOptions;
|
|
69
67
|
|
|
70
|
-
export interface BaseElementStyleProps extends BaseShapeStyleProps {
|
|
71
|
-
/**
|
|
72
|
-
* @internal
|
|
73
|
-
*/
|
|
74
|
-
context?: RuntimeContext;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
68
|
/**
|
|
78
69
|
* <zh/> 元素方法
|
|
79
70
|
*
|
package/src/utils/dom.ts
CHANGED
|
@@ -44,83 +44,3 @@ export function sizeOf(container: HTMLElement | null): [number, number] {
|
|
|
44
44
|
Math.max(isNumber(effectiveHeight) ? effectiveHeight : MIN_CHART_HEIGHT, MIN_CHART_HEIGHT),
|
|
45
45
|
];
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* <zh/> 创建插件容器
|
|
50
|
-
*
|
|
51
|
-
* <en/> Create a plugin container
|
|
52
|
-
* @param type - <zh/> 插件类型 | <en/> plugin type
|
|
53
|
-
* @param cover - <zh/> 容器是否覆盖整个画布 | <en/> Whether the container covers the entire canvas
|
|
54
|
-
* @param style - <zh/> 额外样式 | <en/> Additional style
|
|
55
|
-
* @returns <zh/> 插件容器 | <en/> plugin container
|
|
56
|
-
*/
|
|
57
|
-
export function createPluginContainer(type: string, cover = true, style?: Partial<CSSStyleDeclaration>): HTMLElement {
|
|
58
|
-
const container = document.createElement('div');
|
|
59
|
-
|
|
60
|
-
container.setAttribute('class', `g6-${type}`);
|
|
61
|
-
|
|
62
|
-
Object.assign(container.style, {
|
|
63
|
-
position: 'absolute',
|
|
64
|
-
display: 'block',
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
if (cover) {
|
|
68
|
-
Object.assign(container.style, {
|
|
69
|
-
inset: '0px',
|
|
70
|
-
height: '100%',
|
|
71
|
-
width: '100%',
|
|
72
|
-
overflow: 'hidden',
|
|
73
|
-
pointerEvents: 'none',
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (style) Object.assign(container.style, style);
|
|
78
|
-
|
|
79
|
-
return container;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Create a DOM element, if exists, remove it and create a new one.
|
|
84
|
-
* @param id - id
|
|
85
|
-
* @param tag - tag
|
|
86
|
-
* @param style - style
|
|
87
|
-
* @param innerHTML - innerHTML
|
|
88
|
-
* @param container - container
|
|
89
|
-
* @returns new DOM element
|
|
90
|
-
*/
|
|
91
|
-
export function insertDOM(
|
|
92
|
-
id: string,
|
|
93
|
-
tag = 'div',
|
|
94
|
-
style: Partial<CSSStyleDeclaration> = {},
|
|
95
|
-
innerHTML = '',
|
|
96
|
-
container: HTMLElement = document.body,
|
|
97
|
-
) {
|
|
98
|
-
// 如果存在则删除
|
|
99
|
-
const dom = document.getElementById(id);
|
|
100
|
-
if (dom) dom.remove();
|
|
101
|
-
|
|
102
|
-
// 重新创建
|
|
103
|
-
const div = document.createElement(tag);
|
|
104
|
-
div.innerHTML = innerHTML;
|
|
105
|
-
div.id = id;
|
|
106
|
-
|
|
107
|
-
Object.assign(div.style, style);
|
|
108
|
-
|
|
109
|
-
container.appendChild(div);
|
|
110
|
-
|
|
111
|
-
return div;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Insert a DOM element before the first child of the container.
|
|
116
|
-
* @param container - container
|
|
117
|
-
* @param element - element
|
|
118
|
-
*/
|
|
119
|
-
export function insertBefore(container: HTMLElement, element: HTMLElement) {
|
|
120
|
-
const firstChild = container.firstChild;
|
|
121
|
-
if (firstChild) {
|
|
122
|
-
container.insertBefore(element, firstChild);
|
|
123
|
-
} else {
|
|
124
|
-
container.appendChild(element);
|
|
125
|
-
}
|
|
126
|
-
}
|
package/src/utils/style.ts
CHANGED
|
@@ -43,7 +43,7 @@ export function mergeOptions(opt1: DisplayObjectConfig<any>, opt2: DisplayObject
|
|
|
43
43
|
const s1 = opt1?.style || {};
|
|
44
44
|
const s2 = opt2?.style || {};
|
|
45
45
|
return Object.assign({}, opt1, opt2, {
|
|
46
|
-
style: Object.assign({}, s1, s2),
|
|
46
|
+
style: opt1?.style ? Object.assign({}, s1, s2) : s2,
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -61,10 +61,7 @@ export function mergeOptions(opt1: DisplayObjectConfig<any>, opt2: DisplayObject
|
|
|
61
61
|
*/
|
|
62
62
|
export function getSubShapeStyle<T extends Record<string, any>>(
|
|
63
63
|
style: T,
|
|
64
|
-
): Omit<
|
|
65
|
-
|
|
66
|
-
'x' | 'y' | 'z' | 'transform' | 'transformOrigin' | 'className' | 'class' | 'context' | 'zIndex' | 'visibility'
|
|
67
|
-
> {
|
|
68
|
-
const { x, y, z, class: cls, className, transform, transformOrigin, context, zIndex, visibility, ...rest } = style;
|
|
64
|
+
): Omit<T, 'x' | 'y' | 'z' | 'transform' | 'transformOrigin' | 'className' | 'class' | 'zIndex' | 'visibility'> {
|
|
65
|
+
const { x, y, z, class: cls, className, transform, transformOrigin, zIndex, visibility, ...rest } = style;
|
|
69
66
|
return rest;
|
|
70
67
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.0.31';
|