@vvfx/sdk 0.1.19-alpha.8 → 0.2.0
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/LICENSE +22 -0
- package/dist/index.js +96633 -14
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +96736 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src/config.d.ts +855 -0
- package/dist/src/exporter/config.d.ts +18 -0
- package/dist/src/exporter/const.d.ts +71 -0
- package/dist/src/exporter/export-media.d.ts +68 -0
- package/dist/src/exporter/exporter.d.ts +22 -0
- package/dist/src/exporter/index.d.ts +2 -0
- package/dist/src/exporter/types.d.ts +194 -0
- package/dist/src/exporter/utils.d.ts +22 -0
- package/dist/src/exporter/wav-audio.d.ts +27 -0
- package/dist/src/gesture-handler/gizmo/adsorption-gizmo.d.ts +68 -0
- package/dist/src/gesture-handler/gizmo/control-gizmo.d.ts +67 -0
- package/dist/src/gesture-handler/gizmo/gizmo.d.ts +59 -0
- package/dist/src/gesture-handler/gizmo/icon-gizmo.d.ts +44 -0
- package/dist/src/gesture-handler/gizmo/index.d.ts +6 -0
- package/dist/src/gesture-handler/gizmo/item-create-gizmo.d.ts +43 -0
- package/dist/src/gesture-handler/gizmo/loading-gizmo.d.ts +48 -0
- package/dist/src/gesture-handler/gizmo/mask-gizmo.d.ts +113 -0
- package/dist/src/gesture-handler/gizmo/picture-cut-gizmo.d.ts +94 -0
- package/dist/src/gesture-handler/gizmo/picture-expand-gizmo.d.ts +57 -0
- package/dist/src/gesture-handler/gizmo/preference-gizmo.d.ts +32 -0
- package/dist/src/gesture-handler/gizmo/selector-gizmo.d.ts +101 -0
- package/dist/src/gesture-handler/gizmo/sprite-text-edit-gizmo.d.ts +36 -0
- package/dist/src/gesture-handler/gizmo/text-gizmo.d.ts +128 -0
- package/dist/src/gesture-handler/gizmo/transform-gizmo.d.ts +233 -0
- package/dist/src/gesture-handler/gizmo/type.d.ts +402 -0
- package/dist/src/gesture-handler/index.d.ts +3 -0
- package/dist/src/gesture-handler/src/gesture-handler.d.ts +143 -0
- package/dist/src/gesture-handler/src/icons.d.ts +7 -0
- package/dist/src/gesture-handler/utils.d.ts +2 -0
- package/dist/src/html-overlay/auto-height-runtime.d.ts +13 -0
- package/dist/src/html-overlay/document-runtime.d.ts +4 -0
- package/dist/src/html-overlay/document-transform.d.ts +7 -0
- package/dist/src/html-overlay/dom-order.d.ts +1 -0
- package/dist/src/html-overlay/host-message-runtime.d.ts +3 -0
- package/dist/src/html-overlay/html-viewport-style.d.ts +1 -0
- package/dist/src/html-overlay/index.d.ts +1 -0
- package/dist/src/html-overlay/manager.d.ts +77 -0
- package/dist/src/html-overlay/mime-utils.d.ts +2 -0
- package/dist/src/html-overlay/overlay-transform.d.ts +13 -0
- package/dist/src/html-overlay/path-utils.d.ts +8 -0
- package/dist/src/html-overlay/shell-runtime.d.ts +6 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/math/box2.d.ts +166 -0
- package/dist/src/math/circle.d.ts +82 -0
- package/dist/src/math/euler.d.ts +20 -0
- package/dist/src/math/index.d.ts +13 -0
- package/dist/src/math/line2.d.ts +93 -0
- package/dist/src/math/line3.d.ts +17 -0
- package/dist/src/math/matrix4.d.ts +28 -0
- package/dist/src/math/plane.d.ts +14 -0
- package/dist/src/math/quaternion.d.ts +3 -0
- package/dist/src/math/ray-caster.d.ts +10 -0
- package/dist/src/math/ray.d.ts +18 -0
- package/dist/src/math/type.d.ts +32 -0
- package/dist/src/math/utils.d.ts +19 -0
- package/dist/src/math/vector2.d.ts +30 -0
- package/dist/src/math/vector3.d.ts +29 -0
- package/dist/src/screen-shot/index.d.ts +1 -0
- package/dist/src/screen-shot/screen-shot.d.ts +35 -0
- package/dist/src/sdk-item/base-item.d.ts +126 -0
- package/dist/src/sdk-item/card-item.d.ts +67 -0
- package/dist/src/sdk-item/effects-item.d.ts +70 -0
- package/dist/src/sdk-item/frame-item.d.ts +112 -0
- package/dist/src/sdk-item/generator-item.d.ts +86 -0
- package/dist/src/sdk-item/group-item.d.ts +57 -0
- package/dist/src/sdk-item/index.d.ts +36 -0
- package/dist/src/sdk-item/sprite-item.d.ts +67 -0
- package/dist/src/sdk-item/text-item.d.ts +107 -0
- package/dist/src/sdk-item/types.d.ts +153 -0
- package/dist/src/sdk-item/video-item.d.ts +87 -0
- package/dist/src/sdk.d.ts +589 -0
- package/dist/src/service/UndoRedo.d.ts +48 -0
- package/dist/src/shared/index.d.ts +1 -0
- package/dist/src/shared/player.d.ts +9 -0
- package/dist/src/size-adapte/index.d.ts +1 -0
- package/dist/src/size-adapte/size-adapt.d.ts +28 -0
- package/dist/src/types.d.ts +1298 -0
- package/dist/src/utils/background-manager.d.ts +72 -0
- package/dist/src/utils/common-utils.d.ts +28 -0
- package/dist/src/utils/index.d.ts +8 -0
- package/dist/src/utils/interaction-utils.d.ts +60 -0
- package/dist/src/utils/json-data-utils.d.ts +165 -0
- package/dist/src/utils/layout-utils.d.ts +219 -0
- package/dist/src/utils/page-data-utils.d.ts +372 -0
- package/dist/src/utils/player-data-utils.d.ts +11 -0
- package/dist/src/utils/types.d.ts +114 -0
- package/dist/src/wireframe/common/box.d.ts +1 -0
- package/dist/src/wireframe/common/dashed-line.d.ts +1 -0
- package/dist/src/wireframe/common/line.d.ts +1 -0
- package/dist/src/wireframe/common/pixi-ext.d.ts +11 -0
- package/dist/src/wireframe/common/pixi.d.ts +18 -0
- package/dist/src/wireframe/index.d.ts +4 -0
- package/package.json +42 -22
- package/dist/index.cjs +0 -14
- package/dist/index.d.cts +0 -3485
- package/dist/index.d.ts +0 -3485
- package/dist/index.global.js +0 -333
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { BackgroundGridConfig, BackgroundPreset } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @description 背景管理器
|
|
4
|
+
* 负责管理画布背景的配置、渲染和跟随变换
|
|
5
|
+
*/
|
|
6
|
+
export declare class BackgroundManager {
|
|
7
|
+
/**
|
|
8
|
+
* @description 默认网格配置
|
|
9
|
+
*/
|
|
10
|
+
static readonly DEFAULT_GRID_CONFIG: BackgroundGridConfig;
|
|
11
|
+
/**
|
|
12
|
+
* @description 背景预设配置
|
|
13
|
+
*/
|
|
14
|
+
static readonly PRESETS: Record<string, BackgroundPreset>;
|
|
15
|
+
private container;
|
|
16
|
+
private config;
|
|
17
|
+
/**
|
|
18
|
+
* @description 当前背景位置(用于跟随移动)
|
|
19
|
+
*/
|
|
20
|
+
private offsetX;
|
|
21
|
+
private offsetY;
|
|
22
|
+
constructor(config?: Partial<BackgroundGridConfig>);
|
|
23
|
+
/**
|
|
24
|
+
* @description 绑定容器元素
|
|
25
|
+
* @param element 画布容器元素
|
|
26
|
+
*/
|
|
27
|
+
attach(element: HTMLElement): void;
|
|
28
|
+
/**
|
|
29
|
+
* @description 解绑容器元素
|
|
30
|
+
*/
|
|
31
|
+
detach(): void;
|
|
32
|
+
/**
|
|
33
|
+
* @description 应用背景预设
|
|
34
|
+
* @param presetName 预设名称
|
|
35
|
+
* @param color 可选的背景色覆盖
|
|
36
|
+
*/
|
|
37
|
+
applyPreset(presetName: string, color?: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* @description 设置纯色背景
|
|
40
|
+
* @param color 颜色值
|
|
41
|
+
*/
|
|
42
|
+
setColorBackground(color: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* @description 设置图片背景
|
|
45
|
+
* @param url 图片 URL
|
|
46
|
+
*/
|
|
47
|
+
setImageBackground(url: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* @description 更新背景变换(跟随画布移动和缩放)
|
|
50
|
+
* @param shift 画布移动的偏移量
|
|
51
|
+
* @param zoom 当前缩放比例
|
|
52
|
+
*/
|
|
53
|
+
updateTransform(shift: {
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
}, zoom: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* @description 重置背景位置和大小
|
|
59
|
+
*/
|
|
60
|
+
reset(): void;
|
|
61
|
+
/**
|
|
62
|
+
* @description 清除背景样式
|
|
63
|
+
*/
|
|
64
|
+
private clearBackground;
|
|
65
|
+
/**
|
|
66
|
+
* @description 计算循环缩放比例
|
|
67
|
+
* zoom 在 [1, 2) 时,bgZoom = zoom
|
|
68
|
+
* zoom 在 [2, 4) 时,bgZoom = zoom / 2
|
|
69
|
+
* zoom 在 [0.5, 1) 时,bgZoom = zoom / 0.5
|
|
70
|
+
*/
|
|
71
|
+
private calculateZoomCycle;
|
|
72
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Vector2, Vector3 } from '../math';
|
|
2
|
+
export declare function arrAdd<T>(arr: T[], item: T): void;
|
|
3
|
+
export declare function isObj(item: any): item is object;
|
|
4
|
+
export declare function deepEquals<T>(a: T, b: T): boolean;
|
|
5
|
+
export declare function deepClone<T>(target: T): T;
|
|
6
|
+
export declare function getColorByNormalizeColor(color: [number, number, number, number]): [number, number, number, number];
|
|
7
|
+
export declare function getNormalizeColorByColor(color: [number, number, number, number]): [number, number, number, number];
|
|
8
|
+
export declare function getTransformRatioByViewAndCamera(viewSize: Vector2, cameraPosition: Vector3, cameraFov: number, cameraNear: number, cameraFar: number, isReverse: boolean): {
|
|
9
|
+
xRatio: number;
|
|
10
|
+
yRatio: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function assertExist<T>(item: T | undefined | null, msg?: string): asserts item is T;
|
|
13
|
+
export declare function asserts(condition: any, msg?: string): asserts condition;
|
|
14
|
+
/**
|
|
15
|
+
* @example
|
|
16
|
+
* Input: logger('log', ['VVFX', 'SDK'], 'xx is required');
|
|
17
|
+
* Output: [VVFX SDK] xx is required
|
|
18
|
+
*/
|
|
19
|
+
type Level = 'error' | 'info' | 'debug' | 'warn' | 'log';
|
|
20
|
+
export declare function logger(level: Level, prefixs: string[], ...args: any[]): void;
|
|
21
|
+
export declare function loadScriptAsync(src: string, attrs?: Record<string, string>): Promise<unknown>;
|
|
22
|
+
export declare function downloadBlob(buffer: BlobPart | BlobPart[], filename: string, mimeType?: string): void;
|
|
23
|
+
export declare function getUniqueName(name: string, names: string[]): string;
|
|
24
|
+
/**
|
|
25
|
+
* 深度比较两个值是否相等
|
|
26
|
+
*/
|
|
27
|
+
export declare function isEqual(a: unknown, b: unknown): boolean;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './common-utils';
|
|
2
|
+
export * from './background-manager';
|
|
3
|
+
export * from './interaction-utils';
|
|
4
|
+
export * from './json-data-utils';
|
|
5
|
+
export * from './layout-utils';
|
|
6
|
+
export * from './types';
|
|
7
|
+
export * from './player-data-utils';
|
|
8
|
+
export * from './page-data-utils';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Ray, Euler, Plane, Vector2, Vector3 } from '../math';
|
|
2
|
+
import type { PageDataUtils } from './page-data-utils';
|
|
3
|
+
import type { CameraInteractionParam, ViewInteractionParam } from './types';
|
|
4
|
+
export declare class InteractionUtils {
|
|
5
|
+
/**
|
|
6
|
+
* @description 交互平面
|
|
7
|
+
*/
|
|
8
|
+
plane: Plane;
|
|
9
|
+
/**
|
|
10
|
+
* @description 交互射线
|
|
11
|
+
*/
|
|
12
|
+
ray: Ray;
|
|
13
|
+
/**
|
|
14
|
+
* @description 交互状态视图信息
|
|
15
|
+
*/
|
|
16
|
+
viewportParam: ViewInteractionParam;
|
|
17
|
+
/**
|
|
18
|
+
* @description 交互状态相机信息
|
|
19
|
+
*/
|
|
20
|
+
cameraParam: CameraInteractionParam;
|
|
21
|
+
pageDataUtils: PageDataUtils;
|
|
22
|
+
constructor(utils: PageDataUtils);
|
|
23
|
+
refreshViewParam(): void;
|
|
24
|
+
refreshCameraParam(): void;
|
|
25
|
+
refrehCameraParamByCameraInfo(camera: any): void;
|
|
26
|
+
initInteractionPlane(position?: Vector3, rotation?: Euler): void;
|
|
27
|
+
/**
|
|
28
|
+
* @description 根据视图空间大小获取空间大小
|
|
29
|
+
* @param viewSize 视图空间大小
|
|
30
|
+
* @param isWorld 是否依赖于世界坐标系 - 世界坐标系下,以当前相机锁定平面为基准进行运算;本地坐标系下,以元素坐标系进行运算[用于决定交互平面]
|
|
31
|
+
* @param targetItem 目标元素
|
|
32
|
+
*/
|
|
33
|
+
getWorldSizeByViewSize(viewSize: Vector2, isWorld?: boolean, itemId?: string): Vector3;
|
|
34
|
+
/**
|
|
35
|
+
* @description 获取 template 模式下视图与场景的缩放比 (viewportWidth / sceneWidth)
|
|
36
|
+
* 场景未就绪时回退到 1,并打印一次 warning
|
|
37
|
+
*/
|
|
38
|
+
getTemplateViewScale(): number;
|
|
39
|
+
getViewSizeByPixelSize(pixelSize: Vector2): Vector2;
|
|
40
|
+
/**
|
|
41
|
+
* @description 对空间坐标进行投影
|
|
42
|
+
* @param point 空间坐标
|
|
43
|
+
* @param isGestureHandlerView 是否投影到辅助视图下 - 辅助试图与实际视图大小可能会有区别
|
|
44
|
+
*/
|
|
45
|
+
projectPoint(point: Vector3): Vector2;
|
|
46
|
+
/**
|
|
47
|
+
* @description 通过屏幕坐标获取世界坐标
|
|
48
|
+
* @param point 屏幕坐标
|
|
49
|
+
* @returns 世界坐标
|
|
50
|
+
*/
|
|
51
|
+
getWorldPositionByViewPoint(point: Vector2): Vector3 | undefined;
|
|
52
|
+
getNDCPositionByScreenPosition(point: Vector2): Vector2;
|
|
53
|
+
getNDCSizeByPixelSize(pixelSize: Vector2): Vector2;
|
|
54
|
+
getViewPositionWWithOutTransform(point: Vector2): Vector2;
|
|
55
|
+
getViewPositionByPixelPoint(point: Vector2): Vector2;
|
|
56
|
+
getPixelPositionByViewPoint(point: Vector2): Vector2;
|
|
57
|
+
getPixelSizeByWorldSize(worldSize: Vector3): Vector2;
|
|
58
|
+
getPixelSizeByNDCSize(ndcSize: Vector2): Vector2;
|
|
59
|
+
getPixelSizeByViewSize(viewSize: Vector2): Vector2;
|
|
60
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Vector2, Vector3 } from '../math';
|
|
2
|
+
import { spec } from '../shared';
|
|
3
|
+
import { ItemJSONInfo } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* @description 创建 Frame 元素的内部合成场景
|
|
6
|
+
* @param frameId Frame 元素ID(用于标识)
|
|
7
|
+
* @param size 场景尺寸 [width, height]
|
|
8
|
+
* @param name 场景名称
|
|
9
|
+
* @returns Frame 内部的合成场景
|
|
10
|
+
*/
|
|
11
|
+
export declare function createFrameCompositionScene(frameId: string, size: spec.vec2, name: string): spec.JSONScene;
|
|
12
|
+
/**
|
|
13
|
+
* @description 创建基础场景信息
|
|
14
|
+
* @param viewSize 画布大小
|
|
15
|
+
* @returns 场景信息
|
|
16
|
+
*/
|
|
17
|
+
export declare function getBasicScene(viewSize?: number[], name?: string): spec.JSONScene;
|
|
18
|
+
export declare function createSpriteItemJSON(spriteId: string, position: Vector3, rotation: Vector3, size: Vector2, scale: Vector3, name: string, texture?: string): ItemJSONInfo;
|
|
19
|
+
/**
|
|
20
|
+
* @description 创建视频生成器 Item JSON
|
|
21
|
+
* @description 以 SpriteItem 形式渲染,但设置透明颜色
|
|
22
|
+
* @description 在 content 中存储 isVideoGenerator 标记
|
|
23
|
+
*/
|
|
24
|
+
export declare function createVideoGeneratorItemJSON(id: string, position: Vector3, rotation: Vector3, size: Vector2, scale: Vector3, name: string): ItemJSONInfo;
|
|
25
|
+
export declare function createNullItemJSON(nullId: string, name: string, position: Vector3, scale?: Vector2, rotation?: Vector3, worldSize?: Vector2): ItemJSONInfo;
|
|
26
|
+
export declare function createTextItemJSON(textId: string, name: string, position: Vector3, rotation: Vector3, size: Vector2, fontInfo: spec.TextContentOptions): ItemJSONInfo;
|
|
27
|
+
export declare function createVideoItemJSON(videoId: string, position: Vector3, rotation: Vector3, size: Vector2, scale: Vector3, name: string, isMuted?: boolean, transparent?: boolean, volume?: number, playbackRate?: number, texture?: string, video?: string): ItemJSONInfo;
|
|
28
|
+
/**
|
|
29
|
+
* @description 创建预合成元素
|
|
30
|
+
* @param effectsId 预合成元素ID
|
|
31
|
+
* @param position 位置信息
|
|
32
|
+
* @param rotation 旋转信息
|
|
33
|
+
* @param scale 缩放信息
|
|
34
|
+
* @param name 名称
|
|
35
|
+
*/
|
|
36
|
+
export declare function createCompositionItemJSON(effectsId: string, position: Vector3, rotation: Vector3, scale: Vector3, name: string): {
|
|
37
|
+
item: spec.VFXItemData;
|
|
38
|
+
components: never[];
|
|
39
|
+
tracks: {
|
|
40
|
+
id: string;
|
|
41
|
+
dataType: spec.DataType;
|
|
42
|
+
children: never[];
|
|
43
|
+
clips: {
|
|
44
|
+
start: number;
|
|
45
|
+
duration: number;
|
|
46
|
+
endBehavior: spec.EndBehavior;
|
|
47
|
+
asset: {
|
|
48
|
+
id: string;
|
|
49
|
+
};
|
|
50
|
+
}[];
|
|
51
|
+
}[];
|
|
52
|
+
playableAssets: {
|
|
53
|
+
id: string;
|
|
54
|
+
dataType: spec.DataType;
|
|
55
|
+
}[];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* @description 添加元素信息到JSON
|
|
59
|
+
* @param scene 场景信息
|
|
60
|
+
* @param itemInfo 元素信息
|
|
61
|
+
*/
|
|
62
|
+
export declare function addItemInfoToScene(scene: spec.JSONScene, itemInfo: ItemJSONInfo): void;
|
|
63
|
+
/**
|
|
64
|
+
* @description 设置元素父节点信息
|
|
65
|
+
* @param scene 场景信息
|
|
66
|
+
* @param itemId 元素Id
|
|
67
|
+
* @param parentId 父节点Id
|
|
68
|
+
*/
|
|
69
|
+
export declare function setItemJSONParentId(scene: spec.JSONScene, itemId: string, parentId: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* @description 清理元素父节点信息
|
|
72
|
+
* @param scene 场景信息
|
|
73
|
+
* @param itemId 元素Id
|
|
74
|
+
*/
|
|
75
|
+
export declare function clearItemParentInfo(scene: spec.JSONScene, itemId: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* @description 删除元素信息
|
|
78
|
+
* @param scene 场景信息
|
|
79
|
+
* @param itemId 元素Id
|
|
80
|
+
*/
|
|
81
|
+
export declare function deleteItemInfoFromScene(scene: spec.JSONScene, itemId: string): spec.JSONScene | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* @description 从场景中移除并获取元素的完整 ItemJSONInfo
|
|
84
|
+
* @param scene 场景信息
|
|
85
|
+
* @param itemId 元素ID
|
|
86
|
+
* @returns ItemJSONInfo 或 undefined(如果元素不存在)
|
|
87
|
+
*/
|
|
88
|
+
export declare function removeItemInfoFromScene(scene: spec.JSONScene, itemId: string): ItemJSONInfo | undefined;
|
|
89
|
+
export declare function getTextureUrlById(scene: spec.JSONScene, itemId: string): string | undefined;
|
|
90
|
+
export declare function addCompositionItemByComposition(main: spec.JSONScene, inputChild: spec.JSONScene, compositionItemId: string, parentId?: string): spec.JSONScene;
|
|
91
|
+
/**
|
|
92
|
+
* @description 删除预合成数据
|
|
93
|
+
* @param scene 场景数据
|
|
94
|
+
* @param itemId 预合成ID
|
|
95
|
+
* @returns 场景数据
|
|
96
|
+
*/
|
|
97
|
+
export declare function deleteCompositionItemFromScene(scene: spec.JSONScene, itemIds: string[]): spec.JSONScene;
|
|
98
|
+
/**
|
|
99
|
+
* @description 删除合成信息
|
|
100
|
+
* @param scene 场景数据
|
|
101
|
+
* @param compositionId 合成ID
|
|
102
|
+
*/
|
|
103
|
+
export declare function deleteCompositionFromScene(scene: spec.JSONScene, compositionId: string): void;
|
|
104
|
+
/**
|
|
105
|
+
* @description 重置元素ID - 加载时会新建guid,需要保持一致
|
|
106
|
+
* @param scene 场景数据
|
|
107
|
+
* @param idMap id名称列表
|
|
108
|
+
*/
|
|
109
|
+
export declare function resetSubCompositionItemId(scene: spec.JSONScene, idMap: Map<string, string>): void;
|
|
110
|
+
/**
|
|
111
|
+
* @description 设置场景中元素名称
|
|
112
|
+
* @param scene 场景数据
|
|
113
|
+
* @param itemId 元素ID
|
|
114
|
+
* @param name 名称
|
|
115
|
+
*/
|
|
116
|
+
export declare function setJSONItemName(scene: spec.JSONScene, itemId: string, name: string): void;
|
|
117
|
+
/**
|
|
118
|
+
* @description 元素变换选项
|
|
119
|
+
*/
|
|
120
|
+
export type MoveItemTransformOptions = {
|
|
121
|
+
position?: {
|
|
122
|
+
x: number;
|
|
123
|
+
y: number;
|
|
124
|
+
z: number;
|
|
125
|
+
};
|
|
126
|
+
size?: {
|
|
127
|
+
x: number;
|
|
128
|
+
y: number;
|
|
129
|
+
};
|
|
130
|
+
scale?: {
|
|
131
|
+
x: number;
|
|
132
|
+
y: number;
|
|
133
|
+
z: number;
|
|
134
|
+
};
|
|
135
|
+
rotation?: {
|
|
136
|
+
x: number;
|
|
137
|
+
y: number;
|
|
138
|
+
z: number;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* @description 将元素从一个合成移动到另一个合成
|
|
143
|
+
* @param scene 场景数据
|
|
144
|
+
* @param itemId 元素ID
|
|
145
|
+
* @param targetCompositionId 目标合成ID,为null时表示移动到主合成
|
|
146
|
+
* @param options 可选的位置、大小、缩放、旋转信息
|
|
147
|
+
* @returns 是否移动成功
|
|
148
|
+
*/
|
|
149
|
+
export declare function moveItemBetweenCompositions(scene: spec.JSONScene, itemId: string, targetCompositionId: string | null, options?: MoveItemTransformOptions): boolean;
|
|
150
|
+
export declare function getCompositionIdByRefCompositionItemId(scene: spec.JSONScene, compositionItemId: string): any;
|
|
151
|
+
/**
|
|
152
|
+
* @description 获取预合成元素所指向的合成数据
|
|
153
|
+
* @param scene 场景数据
|
|
154
|
+
* @param compositionItemId 预合成元素ID
|
|
155
|
+
* @returns 对应的合成数据 (CompositionData),如果未找到则返回 undefined
|
|
156
|
+
*/
|
|
157
|
+
export declare function getCompositionDataByRefCompositionItemId(scene: spec.JSONScene, compositionItemId: string): spec.CompositionData | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* @description 提取子合成元素及其所有关联资源为独立的 JSONScene
|
|
160
|
+
* @param scene 主场景数据
|
|
161
|
+
* @param compositionItemId 预合成元素ID(子合成元素ID)
|
|
162
|
+
* @returns 独立的子合成场景 JSONScene,如果未找到则返回 undefined
|
|
163
|
+
*/
|
|
164
|
+
export declare function extractSubCompositionToScene(scene: spec.JSONScene, compositionItemId: string): spec.JSONScene | undefined;
|
|
165
|
+
export declare function fixStandardJSON(scene: spec.JSONScene): void;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { Box2 } from '../math/box2';
|
|
2
|
+
import { Line2, Vector2 } from '../math';
|
|
3
|
+
import type { AutoLayoutConfig, LayoutInfo } from '../types';
|
|
4
|
+
import type { SDKItem, FrameItem } from '../sdk-item';
|
|
5
|
+
/**
|
|
6
|
+
* @description 自动布局指示器数据
|
|
7
|
+
*/
|
|
8
|
+
export type AutoLayoutIndicator = {
|
|
9
|
+
frameId: string;
|
|
10
|
+
insertIndex: number;
|
|
11
|
+
insertDirection: 'before' | 'after';
|
|
12
|
+
targetSiblingId?: string;
|
|
13
|
+
line: Line2;
|
|
14
|
+
targetRow?: number;
|
|
15
|
+
targetColumn?: number;
|
|
16
|
+
} | null;
|
|
17
|
+
/**
|
|
18
|
+
* @description 布局位置信息
|
|
19
|
+
*/
|
|
20
|
+
export type LayoutPosition = {
|
|
21
|
+
row: number;
|
|
22
|
+
column: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* @description 插入位置信息
|
|
26
|
+
*/
|
|
27
|
+
export type InsertPosition = {
|
|
28
|
+
index: number;
|
|
29
|
+
direction: 'before' | 'after';
|
|
30
|
+
siblingId?: string;
|
|
31
|
+
row: number;
|
|
32
|
+
column: number;
|
|
33
|
+
rowChange?: {
|
|
34
|
+
fromRow: number;
|
|
35
|
+
toRow: number;
|
|
36
|
+
rowBounds?: {
|
|
37
|
+
minY: number;
|
|
38
|
+
maxY: number;
|
|
39
|
+
minX: number;
|
|
40
|
+
maxX: number;
|
|
41
|
+
};
|
|
42
|
+
isRowChange: boolean;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @description 兄弟元素布局信息
|
|
47
|
+
*/
|
|
48
|
+
export type SiblingWithInfo = {
|
|
49
|
+
item: SDKItem;
|
|
50
|
+
box: Box2;
|
|
51
|
+
row: number;
|
|
52
|
+
column: number;
|
|
53
|
+
centerX: number;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* @description 布局元素信息
|
|
57
|
+
*/
|
|
58
|
+
export type LayoutItem = {
|
|
59
|
+
id: string;
|
|
60
|
+
box: Box2;
|
|
61
|
+
row?: number;
|
|
62
|
+
column?: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* @description 布局结果项
|
|
66
|
+
*/
|
|
67
|
+
export type LayoutResultItem = {
|
|
68
|
+
id: string;
|
|
69
|
+
position: [number, number];
|
|
70
|
+
row: number;
|
|
71
|
+
column: number;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* @description 自动排布配置
|
|
75
|
+
*/
|
|
76
|
+
export type AutoLayoutOptions = {
|
|
77
|
+
padding?: number;
|
|
78
|
+
gap?: number;
|
|
79
|
+
config?: AutoLayoutConfig;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* @description 自动排布结果
|
|
83
|
+
*/
|
|
84
|
+
export type AutoLayoutResult = {
|
|
85
|
+
items: LayoutResultItem[];
|
|
86
|
+
size: [number, number];
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* @description 全局自适应排布元素
|
|
90
|
+
*/
|
|
91
|
+
export type LayoutElement = {
|
|
92
|
+
id: string;
|
|
93
|
+
box: Box2;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* @description 全局自适应排布结果
|
|
97
|
+
*/
|
|
98
|
+
export type GlobalAutoLayoutResult = {
|
|
99
|
+
items: {
|
|
100
|
+
id: string;
|
|
101
|
+
position: [number, number];
|
|
102
|
+
}[];
|
|
103
|
+
boundingBox: Box2;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* @description 全局自适应排布配置
|
|
107
|
+
*/
|
|
108
|
+
export type GlobalAutoLayoutOptions = {
|
|
109
|
+
/**
|
|
110
|
+
* @description 元素间隔(默认10)
|
|
111
|
+
*/
|
|
112
|
+
gap?: number;
|
|
113
|
+
/**
|
|
114
|
+
* @description 目标宽高比(默认1:1正方形)
|
|
115
|
+
*/
|
|
116
|
+
targetAspectRatio?: number;
|
|
117
|
+
/**
|
|
118
|
+
* @description 排布模式
|
|
119
|
+
* - 'adaptive': 基于元素包围盒自适应排布(MaxRects算法,更紧凑)
|
|
120
|
+
* - 'ordered': 基于元素顺序的行列排布(保持输入顺序,流式行排布,行优先)
|
|
121
|
+
*/
|
|
122
|
+
mode?: GlobalLayoutMode;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* @description 全局自适应排布模式
|
|
126
|
+
*/
|
|
127
|
+
export type GlobalLayoutMode = 'adaptive' | 'ordered';
|
|
128
|
+
/**
|
|
129
|
+
* @description 自动排布函数
|
|
130
|
+
* 根据元素信息中的行列数参数进行排布:
|
|
131
|
+
* - 如果元素有 row/column,则按指定行列排布
|
|
132
|
+
* - 如果元素没有 row/column,则使用 Shelf 算法自动生成行列数,再排布
|
|
133
|
+
*
|
|
134
|
+
* @param canvasBox 画布范围(Box2),min为左上角,max为右下角
|
|
135
|
+
* @param items 元素信息列表(包含 ID、Box2、可选的 row/column)
|
|
136
|
+
* @param options 可选配置(padding, gap)
|
|
137
|
+
* @returns 各元素的位置信息和整体尺寸
|
|
138
|
+
*/
|
|
139
|
+
export declare function autoLayout(items: LayoutItem[], options?: AutoLayoutOptions): AutoLayoutResult;
|
|
140
|
+
/**
|
|
141
|
+
* @description 计算元素到目标位置的位移
|
|
142
|
+
* @param currentPosition 当前位置 [x, y]
|
|
143
|
+
* @param targetPosition 目标位置 [x, y]
|
|
144
|
+
* @returns 位移向量 [dx, dy]
|
|
145
|
+
*/
|
|
146
|
+
export declare function calculateDisplacement(currentPosition: [number, number], targetPosition: [number, number]): [number, number];
|
|
147
|
+
/**
|
|
148
|
+
* @description 为 autoLayout 结果计算位移信息
|
|
149
|
+
* @param items 元素列表(包含当前位置)
|
|
150
|
+
* @param layoutResult autoLayout 的返回结果
|
|
151
|
+
* @returns 每个元素的位移信息
|
|
152
|
+
*/
|
|
153
|
+
export declare function calculateLayoutDisplacements(items: {
|
|
154
|
+
id: string;
|
|
155
|
+
currentPosition: [number, number];
|
|
156
|
+
}[], layoutResult: AutoLayoutResult): {
|
|
157
|
+
id: string;
|
|
158
|
+
displacement: [number, number];
|
|
159
|
+
targetPosition: [number, number];
|
|
160
|
+
}[];
|
|
161
|
+
/**
|
|
162
|
+
* @description 计算自动布局指示线位置
|
|
163
|
+
* @param position 插入位置信息
|
|
164
|
+
* @param getViewBoxById 获取元素包围盒的函数
|
|
165
|
+
* @returns 主指示线
|
|
166
|
+
*/
|
|
167
|
+
export declare function calculateAutoLayoutIndicatorLine(position: InsertPosition, getViewBoxById: (id: string) => Box2): Line2;
|
|
168
|
+
/**
|
|
169
|
+
* @description 基于鼠标位置计算布局位置(row 和 column)
|
|
170
|
+
* @param mousePoint 鼠标位置
|
|
171
|
+
* @param allItems 所有子元素
|
|
172
|
+
* @param getViewBoxById 获取元素包围盒的函数
|
|
173
|
+
* @param getLayoutInfo 获取元素布局信息的函数
|
|
174
|
+
* @param excludeItemId 需要排除的元素ID(被拖拽的元素)
|
|
175
|
+
* @returns 布局位置信息 { row: number, column: number }
|
|
176
|
+
*/
|
|
177
|
+
export declare function calculateAutoLayoutPositionByMouse(mousePoint: Vector2, allItems: SDKItem[], getViewBoxById: (id: string) => Box2, getLayoutInfo: (item: SDKItem) => LayoutInfo | undefined, excludeItemId: string): LayoutPosition | null;
|
|
178
|
+
/**
|
|
179
|
+
* @description 基于鼠标位置计算插入位置(用于显示指示器)
|
|
180
|
+
* @param mousePoint 鼠标位置
|
|
181
|
+
* @param allItems 所有子元素
|
|
182
|
+
* @param excludeItemId 需要排除的元素ID(被拖拽的元素)
|
|
183
|
+
* @param parent 父画板
|
|
184
|
+
* @param originalRow 原始行号
|
|
185
|
+
* @param getSelectedItemsBox 获取选中项包围盒的函数
|
|
186
|
+
* @returns 插入位置信息和计算出的行列位置
|
|
187
|
+
*/
|
|
188
|
+
export declare function calculateInsertPositionFromLayout(mousePoint: Vector2, allItems: SDKItem[], excludeItemId: string, parent: FrameItem, originalRow: number, getViewBoxById: (id: string) => Box2, getSelectedItemsBox: () => Box2): InsertPosition;
|
|
189
|
+
/**
|
|
190
|
+
* @description 更新元素的 layoutInfo
|
|
191
|
+
* @param item 要更新的元素
|
|
192
|
+
* @param parent 父画板
|
|
193
|
+
* @param layoutPosition 新的布局位置
|
|
194
|
+
*/
|
|
195
|
+
export declare function updateItemLayoutInfo(item: SDKItem, parent: FrameItem, layoutPosition: LayoutPosition): void;
|
|
196
|
+
/**
|
|
197
|
+
* @description 全局自适应排布
|
|
198
|
+
* 支持两种模式:
|
|
199
|
+
* 1. 'adaptive'(默认): 基于元素包围盒自适应排布(MaxRects算法,更紧凑)
|
|
200
|
+
* 2. 'ordered': 基于元素顺序的流式行排布(保持输入顺序,每行尽可能多放元素)
|
|
201
|
+
*
|
|
202
|
+
* @param elements 元素列表(包含ID和包围盒)
|
|
203
|
+
* @param options 配置选项
|
|
204
|
+
* @returns 各元素位置和整体包围盒
|
|
205
|
+
*/
|
|
206
|
+
export declare function globalAutoLayout(elements: LayoutElement[], options?: GlobalAutoLayoutOptions): GlobalAutoLayoutResult;
|
|
207
|
+
/**
|
|
208
|
+
* @description 调整其他元素的行列信息
|
|
209
|
+
* 当被拖拽元素移动到新位置时,需要调整其他受影响的元素:
|
|
210
|
+
* 1. 同行内移动:原位置到新位置之间的元素需要相应调整列号
|
|
211
|
+
* 2. 跨行移动:原行中后面的元素前移,目标行中后面的元素后移
|
|
212
|
+
* @param parent 父画板
|
|
213
|
+
* @param draggedItemId 被拖拽的元素ID
|
|
214
|
+
* @param fromRow 原始行号
|
|
215
|
+
* @param fromColumn 原始列号
|
|
216
|
+
* @param toRow 目标行号
|
|
217
|
+
* @param toColumn 目标列号
|
|
218
|
+
*/
|
|
219
|
+
export declare function adjustOtherElementsLayoutInfo(parent: FrameItem, draggedItemId: string, fromRow: number, fromColumn: number, toRow: number, toColumn: number, getSDKItem: (id: string) => SDKItem | undefined): void;
|