@jetprint/editor-sdk 1.0.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/dist/assets/perspective.wasm +0 -0
- package/dist/assets/wasm_exec.js +553 -0
- package/dist/components/Editor/assets/editorIcons.d.ts +32 -0
- package/dist/components/Editor/components/CanvasSection.vue.d.ts +253 -0
- package/dist/components/Editor/components/CanvasZoomToolbar.vue.d.ts +23 -0
- package/dist/components/Editor/components/EditorAddToCartDialog.vue.d.ts +28 -0
- package/dist/components/Editor/components/EditorDefaultCanvasAxisLines.vue.d.ts +34 -0
- package/dist/components/Editor/components/EditorDefaultCanvasRulers.vue.d.ts +44 -0
- package/dist/components/Editor/components/EditorIcon.vue.d.ts +7 -0
- package/dist/components/Editor/components/EditorSelectionShortcutFab.vue.d.ts +56 -0
- package/dist/components/Editor/components/EditorSidebar.vue.d.ts +548 -0
- package/dist/components/Editor/components/EditorTopbar.vue.d.ts +363 -0
- package/dist/components/Editor/components/EditorTopbarMockupScope.vue.d.ts +12 -0
- package/dist/components/Editor/components/GalleryPanel.vue.d.ts +9 -0
- package/dist/components/Editor/components/LiveThreePreviewPane.vue.d.ts +30 -0
- package/dist/components/Editor/components/PreviewPanel.vue.d.ts +312 -0
- package/dist/components/Editor/components/ShortcutSettingsModal.vue.d.ts +11 -0
- package/dist/components/Editor/components/SplitPieceHandAlignPanel.vue.d.ts +14 -0
- package/dist/components/Editor/components/TemplateModal.vue.d.ts +35 -0
- package/dist/components/Editor/components/Theme1AddTextPanel.vue.d.ts +190 -0
- package/dist/components/Editor/components/Theme1UploadPanel.vue.d.ts +120 -0
- package/dist/components/Editor/composables/index.d.ts +56 -0
- package/dist/components/Editor/composables/useCanvasEventWiring.d.ts +40 -0
- package/dist/components/Editor/composables/useCanvasHistory.d.ts +18 -0
- package/dist/components/Editor/composables/useCanvasManager.d.ts +29 -0
- package/dist/components/Editor/composables/useCanvasObjectHelpers.d.ts +34 -0
- package/dist/components/Editor/composables/useCanvasStateByDiecut.d.ts +50 -0
- package/dist/components/Editor/composables/useCanvasViewport.d.ts +89 -0
- package/dist/components/Editor/composables/useClearCanvas.d.ts +32 -0
- package/dist/components/Editor/composables/useCompleteScreenshot.d.ts +68 -0
- package/dist/components/Editor/composables/useCopyToDiecuts.d.ts +56 -0
- package/dist/components/Editor/composables/useDiecutManager.d.ts +46 -0
- package/dist/components/Editor/composables/useDiecutScreenshot.d.ts +50 -0
- package/dist/components/Editor/composables/useDownloadPng.d.ts +11 -0
- package/dist/components/Editor/composables/useEditorReset.d.ts +21 -0
- package/dist/components/Editor/composables/useEditorShortcuts.d.ts +80 -0
- package/dist/components/Editor/composables/useEditorTopbarContext.d.ts +3 -0
- package/dist/components/Editor/composables/useEditorWatchers.d.ts +99 -0
- package/dist/components/Editor/composables/useEventHandlers.d.ts +13 -0
- package/dist/components/Editor/composables/useFontLoader.d.ts +8 -0
- package/dist/components/Editor/composables/useGuideResources.d.ts +38 -0
- package/dist/components/Editor/composables/useImageHandler.d.ts +10 -0
- package/dist/components/Editor/composables/useLayerOperations.d.ts +52 -0
- package/dist/components/Editor/composables/useLayerSync.d.ts +32 -0
- package/dist/components/Editor/composables/useLicense.d.ts +11 -0
- package/dist/components/Editor/composables/useObjectAdder.d.ts +76 -0
- package/dist/components/Editor/composables/usePatternHandler.d.ts +31 -0
- package/dist/components/Editor/composables/usePreviewManager.d.ts +240 -0
- package/dist/components/Editor/composables/usePreviewRenderer.d.ts +111 -0
- package/dist/components/Editor/composables/usePreviewUpdateQueue.d.ts +62 -0
- package/dist/components/Editor/composables/useProductData.d.ts +166 -0
- package/dist/components/Editor/composables/useSplitPieceHandTool.d.ts +34 -0
- package/dist/components/Editor/composables/useTemplateLoader.d.ts +36 -0
- package/dist/components/Editor/composables/useTemplateManager.d.ts +48 -0
- package/dist/components/Editor/composables/useTextHandler.d.ts +19 -0
- package/dist/components/Editor/composables/useToolState.d.ts +101 -0
- package/dist/components/Editor/composables/useToolStateSync.d.ts +49 -0
- package/dist/components/Editor/composables/useWorkerManager.d.ts +11 -0
- package/dist/components/Editor/config/fontConfig.d.ts +8 -0
- package/dist/components/Editor/editorCanvasGuides.d.ts +22 -0
- package/dist/components/Editor/fabric/PatternLayer.d.ts +104 -0
- package/dist/components/Editor/index.vue.d.ts +167 -0
- package/dist/components/Editor/liveRender/ThreeRenderViewer.vue.d.ts +31 -0
- package/dist/components/Editor/liveRender/dataAdapter.d.ts +2 -0
- package/dist/components/Editor/liveRender/prefetch.worker.d.ts +15 -0
- package/dist/components/Editor/liveRender/render.worker.d.ts +1 -0
- package/dist/components/Editor/liveRender/types.d.ts +130 -0
- package/dist/components/Editor/utils/blob.d.ts +5 -0
- package/dist/components/Editor/utils/buildSplitPieceDesignClipBlobs.d.ts +75 -0
- package/dist/components/Editor/utils/colorLabels.d.ts +6 -0
- package/dist/components/Editor/utils/dataBuilders.d.ts +108 -0
- package/dist/components/Editor/utils/designRestoreScale.d.ts +42 -0
- package/dist/components/Editor/utils/editorShortcutChord.d.ts +9 -0
- package/dist/components/Editor/utils/editorShortcutIds.d.ts +2 -0
- package/dist/components/Editor/utils/editorShortcutRegistry.d.ts +15 -0
- package/dist/components/Editor/utils/editorSizeOptions.d.ts +27 -0
- package/dist/components/Editor/utils/fabricMainCanvasSnapshot.d.ts +48 -0
- package/dist/components/Editor/utils/fabricRulerMath.d.ts +35 -0
- package/dist/components/Editor/utils/fabricScreenshotToBlob.d.ts +7 -0
- package/dist/components/Editor/utils/imageLoader.d.ts +10 -0
- package/dist/components/Editor/utils/objectUtils.d.ts +11 -0
- package/dist/components/Editor/utils/pattern.d.ts +56 -0
- package/dist/components/Editor/utils/scaleSplitClassicGridVisual.d.ts +9 -0
- package/dist/components/Editor/utils/screenshot.d.ts +8 -0
- package/dist/components/Editor/utils/selectionVisual.d.ts +7 -0
- package/dist/components/Editor/utils/tintMaskWithColor.d.ts +4 -0
- package/dist/components/Editor/utils/uploadLimit.d.ts +4 -0
- package/dist/components/Editor/workers/copyDiecuts.worker.d.ts +38 -0
- package/dist/components/Editor/workers/maskWorker.d.ts +13 -0
- package/dist/components/Editor/workers/renderWorker.d.ts +1 -0
- package/dist/components/Editor/workers/zoneScreenshotWorker.d.ts +49 -0
- package/dist/composables/useEditorI18n.d.ts +18 -0
- package/dist/copyDiecuts.worker.js +67 -0
- package/dist/deform.worker.js +760 -0
- package/dist/editor-sdk.es.js +73923 -0
- package/dist/index.d.ts +446 -0
- package/dist/locales/builtin-messages.d.ts +2 -0
- package/dist/locales/editor-locales.d.ts +7 -0
- package/dist/locales/en.d.ts +5 -0
- package/dist/locales/ja-JP.d.ts +5 -0
- package/dist/locales/ko-KR.d.ts +5 -0
- package/dist/locales/vi-VN.d.ts +5 -0
- package/dist/locales/zh.d.ts +5 -0
- package/dist/maskWorker.js +51 -0
- package/dist/prefetch.worker.js +16 -0
- package/dist/render.worker.js +27266 -0
- package/dist/renderWorker.js +40368 -0
- package/dist/style.css +1 -0
- package/dist/types.d.ts +483 -0
- package/dist/utils/backgroundRenderer.d.ts +64 -0
- package/dist/utils/encryptJson.d.ts +31 -0
- package/dist/utils/environment.d.ts +29 -0
- package/dist/utils/errorHandler.d.ts +27 -0
- package/dist/utils/fileToken.d.ts +18 -0
- package/dist/utils/http.d.ts +31 -0
- package/dist/utils/jsonFileCache.d.ts +6 -0
- package/dist/utils/license/api.d.ts +74 -0
- package/dist/utils/license/deviceId.d.ts +25 -0
- package/dist/utils/license/index.d.ts +9 -0
- package/dist/utils/license/licenseManager.d.ts +63 -0
- package/dist/utils/license/licenseStore.d.ts +17 -0
- package/dist/utils/license/retry.d.ts +11 -0
- package/dist/utils/license/tokenRefresh.d.ts +34 -0
- package/dist/utils/mediaBlobCache.d.ts +6 -0
- package/dist/utils/protection/encryptedModules.generated.d.ts +27 -0
- package/dist/utils/protection/moduleLoader.d.ts +17 -0
- package/dist/utils/renderService/blend.d.ts +4 -0
- package/dist/utils/renderService/deform.d.ts +21 -0
- package/dist/utils/renderService/deform.worker.d.ts +7 -0
- package/dist/utils/renderService/image.d.ts +8 -0
- package/dist/utils/renderService/index.d.ts +12 -0
- package/dist/utils/renderService/mask.d.ts +13 -0
- package/dist/utils/renderService/prepareRenderData.d.ts +2 -0
- package/dist/utils/renderService/psdConverter.d.ts +6 -0
- package/dist/utils/renderService/render.d.ts +14 -0
- package/dist/utils/renderService/render.worker.d.ts +17 -0
- package/dist/utils/renderService/types.d.ts +236 -0
- package/dist/utils/renderService/workerManager.d.ts +33 -0
- package/dist/utils/renderedImagesDB.d.ts +61 -0
- package/dist/utils/storage.d.ts +27 -0
- package/dist/utils/threeRenderService/index.d.ts +6 -0
- package/dist/utils/url.d.ts +39 -0
- package/dist/utils/workerBase.d.ts +38 -0
- package/dist/utils/workerLoader.d.ts +24 -0
- package/dist/wasm/index.d.ts +5 -0
- package/dist/wasm/perspectiveLoader.d.ts +70 -0
- package/dist/wasm/perspectiveLoader.worker.d.ts +116 -0
- package/dist/zoneScreenshotWorker.js +82 -0
- package/package.json +54 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ISmartObject } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* 获取或创建指定 faceId 的 deform worker
|
|
4
|
+
*/
|
|
5
|
+
export declare function getDeformWorker(faceId: number): Worker;
|
|
6
|
+
/**
|
|
7
|
+
* 规范化 layerData,将 Vue Proxy 对象转换为普通对象
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizeLayerData(layerData: ISmartObject): ISmartObject;
|
|
10
|
+
/**
|
|
11
|
+
* 使用 worker 进行变形
|
|
12
|
+
* @param designBitmap - 设计图
|
|
13
|
+
* @param layerData - 智能对象数据
|
|
14
|
+
* @param faceId - 面 ID
|
|
15
|
+
* @param canvasSize - 画布尺寸(可选,默认使用 layerData.size)
|
|
16
|
+
*/
|
|
17
|
+
export declare function deformWithWorker(designBitmap: ImageBitmap, layerData: ISmartObject, faceId: number, canvasSize?: {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}): Promise<ImageBitmap>;
|
|
21
|
+
/**
|
|
22
|
+
* 通知所有已创建的 Worker 更新 License
|
|
23
|
+
*/
|
|
24
|
+
export declare function notifyWorkersLicense(config: {
|
|
25
|
+
licenseToken: string;
|
|
26
|
+
licenseApiUrl: string;
|
|
27
|
+
deviceId: string;
|
|
28
|
+
domain: string;
|
|
29
|
+
}): void;
|
|
30
|
+
/**
|
|
31
|
+
* 清理所有 deform worker
|
|
32
|
+
*/
|
|
33
|
+
export declare function disposeDeformWorkers(): void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type RenderTaskStatus = 'rendering' | 'uploading' | 'done' | 'failed';
|
|
2
|
+
export interface RenderedImage {
|
|
3
|
+
index: number;
|
|
4
|
+
blob: Blob;
|
|
5
|
+
fileName: string;
|
|
6
|
+
}
|
|
7
|
+
/** fabricScreenshotList 中单张截图的 Blob 存储 */
|
|
8
|
+
export interface FabricScreenshotBlob {
|
|
9
|
+
id: number;
|
|
10
|
+
name?: string;
|
|
11
|
+
blob: Blob;
|
|
12
|
+
}
|
|
13
|
+
/** 单个模板的渲染数据(fabricScreenshotList 已提升到 RenderBundle 顶层共享) */
|
|
14
|
+
export interface RenderBundleTemplate {
|
|
15
|
+
index: number;
|
|
16
|
+
psdJson: unknown;
|
|
17
|
+
materialList: Array<{
|
|
18
|
+
layerName: string;
|
|
19
|
+
url: string;
|
|
20
|
+
sourceName?: string;
|
|
21
|
+
}>;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
/** 当前渲染的目标颜色(如 "Beige"、"Black"),用于过滤 psdJson 中不属于此颜色的图层 */
|
|
26
|
+
selectedColor?: string;
|
|
27
|
+
/** 颜色名称,用于图片命名(如 "Black") */
|
|
28
|
+
color?: string;
|
|
29
|
+
}
|
|
30
|
+
/** 所有模板的渲染数据包 */
|
|
31
|
+
export interface RenderBundle {
|
|
32
|
+
taskId: string;
|
|
33
|
+
designName?: string;
|
|
34
|
+
/** 所有模板共享的设计截图 Blob(收集一次,避免 N 个模板重复存储) */
|
|
35
|
+
fabricScreenshotList: FabricScreenshotBlob[];
|
|
36
|
+
templates: RenderBundleTemplate[];
|
|
37
|
+
}
|
|
38
|
+
export interface RenderTaskRecord {
|
|
39
|
+
taskId: string;
|
|
40
|
+
status: RenderTaskStatus;
|
|
41
|
+
images: RenderedImage[];
|
|
42
|
+
createdAt: number;
|
|
43
|
+
uploadedAt?: number;
|
|
44
|
+
retryCount?: number;
|
|
45
|
+
error?: string;
|
|
46
|
+
/** 完整渲染数据包(保存时收集,后台渲染用) */
|
|
47
|
+
renderBundle?: RenderBundle;
|
|
48
|
+
}
|
|
49
|
+
export declare function putRenderTask(record: RenderTaskRecord): Promise<void>;
|
|
50
|
+
export declare function getRenderTask(taskId: string): Promise<RenderTaskRecord | undefined>;
|
|
51
|
+
export declare function deleteRenderTask(taskId: string): Promise<void>;
|
|
52
|
+
export declare function getAllRenderTasks(): Promise<RenderTaskRecord[]>;
|
|
53
|
+
export declare function getPendingTasks(): Promise<RenderTaskRecord[]>;
|
|
54
|
+
export declare function updateRenderTaskStatus(taskId: string, status: RenderTaskStatus, extra?: Partial<RenderTaskRecord>): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* 批量查询本地图片,返回 taskId → blob URL 的映射。
|
|
57
|
+
* 调用方负责在适当时机 revoke 这些 URL。
|
|
58
|
+
*/
|
|
59
|
+
export declare function getLocalImageUrls(taskIds: string[]): Promise<Map<string, string>>;
|
|
60
|
+
export declare function appendRenderedImage(taskId: string, image: RenderedImage): Promise<void>;
|
|
61
|
+
export declare function cleanupOldTasks(maxAgeMs?: number): Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一的 Storage 工具类
|
|
3
|
+
* 处理 localStorage 的安全访问和环境检查
|
|
4
|
+
*/
|
|
5
|
+
export declare class StorageUtil {
|
|
6
|
+
private static hasStorage;
|
|
7
|
+
/**
|
|
8
|
+
* 获取存储项
|
|
9
|
+
*/
|
|
10
|
+
static getItem(key: string): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* 设置存储项
|
|
13
|
+
*/
|
|
14
|
+
static setItem(key: string, value: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 移除存储项
|
|
17
|
+
*/
|
|
18
|
+
static removeItem(key: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 清空所有存储项
|
|
21
|
+
*/
|
|
22
|
+
static clear(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 检查是否支持 Storage
|
|
25
|
+
*/
|
|
26
|
+
static isAvailable(): boolean;
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IRenderByJson, IRenderByJsonResult } from '../renderService/types';
|
|
2
|
+
export declare function preloadThreeScenesByJson(data: IRenderByJson): Promise<{
|
|
3
|
+
sceneCount: number;
|
|
4
|
+
cacheSize: number;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function renderByJsonWithThree(data: IRenderByJson): Promise<IRenderByJsonResult>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL 工具类
|
|
3
|
+
*/
|
|
4
|
+
export declare class UrlUtil {
|
|
5
|
+
/**
|
|
6
|
+
* 安全地解析 URL
|
|
7
|
+
*/
|
|
8
|
+
static parse(url: string): URL | null;
|
|
9
|
+
/**
|
|
10
|
+
* 添加查询参数
|
|
11
|
+
*/
|
|
12
|
+
static addParam(url: string, key: string, value: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* 移除查询参数
|
|
15
|
+
*/
|
|
16
|
+
static removeParam(url: string, key: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* 检查是否有指定参数
|
|
19
|
+
*/
|
|
20
|
+
static hasParam(url: string, key: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 格式化 URL(保持原始格式)
|
|
23
|
+
*/
|
|
24
|
+
private static formatUrl;
|
|
25
|
+
/**
|
|
26
|
+
* 检查是否为数据 URL
|
|
27
|
+
*/
|
|
28
|
+
static isDataUrl(url: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* 检查是否为 Blob URL
|
|
31
|
+
*/
|
|
32
|
+
static isBlobUrl(url: string): boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 为图片 URL 追加或覆盖 OSS 缩放参数。
|
|
36
|
+
* - 未传 width(null/undefined)或 width 无效(NaN、≤0)时按原图处理:去掉 x-oss-process(若有)
|
|
37
|
+
* - 否则:若已有 image/resize 则去掉 ,h_数字、再替换 w_数字;否则追加 x-oss-process=image/resize,w_<width>
|
|
38
|
+
*/
|
|
39
|
+
export declare function appendOssResize(url: string | null | undefined, width?: number | null): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface WorkerMessage<T = any> {
|
|
2
|
+
id?: number;
|
|
3
|
+
type?: string;
|
|
4
|
+
data?: T;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface WorkerRequestHandler<TRequest = any, TResponse = any> {
|
|
8
|
+
resolve: (value: TResponse) => void;
|
|
9
|
+
reject: (reason?: any) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Worker 管理基类
|
|
13
|
+
*/
|
|
14
|
+
export declare class WorkerManager<TRequest = any, TResponse = any> {
|
|
15
|
+
protected workers: Map<string | number, Worker>;
|
|
16
|
+
protected requests: Map<number, WorkerRequestHandler<TRequest, TResponse>>;
|
|
17
|
+
protected requestId: number;
|
|
18
|
+
/**
|
|
19
|
+
* 创建 Worker
|
|
20
|
+
*/
|
|
21
|
+
protected createWorker(workerPath: string, isDev: boolean): Worker;
|
|
22
|
+
/**
|
|
23
|
+
* 设置 Worker 消息处理
|
|
24
|
+
*/
|
|
25
|
+
protected setupWorkerHandlers(worker: Worker, onMessage: (data: any) => void): void;
|
|
26
|
+
/**
|
|
27
|
+
* 发送消息到 Worker
|
|
28
|
+
*/
|
|
29
|
+
protected sendMessage(worker: Worker, message: WorkerMessage<TRequest>, transfer?: Transferable[]): Promise<TResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* 处理 Worker 响应
|
|
32
|
+
*/
|
|
33
|
+
protected handleResponse(id: number, data: TResponse, error?: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* 清理所有 Workers
|
|
36
|
+
*/
|
|
37
|
+
dispose(): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 运行时 Worker 加载工具
|
|
3
|
+
*
|
|
4
|
+
* 注意:此模块仅在生产环境(!import.meta.env.DEV)下被使用
|
|
5
|
+
* 在开发环境下,所有 Worker 都通过 new Worker(new URL(..., import.meta.url)) 创建
|
|
6
|
+
*
|
|
7
|
+
* 使用固定文件名 + 版本号参数实现缓存控制,避免复杂的映射管理
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* 获取 Worker 的最终 URL
|
|
11
|
+
* @param workerPath 源码中的 Worker 相对路径
|
|
12
|
+
*
|
|
13
|
+
* 使用固定文件名 + SDK 版本号参数实现缓存控制
|
|
14
|
+
* - 文件名:将 .ts 替换为 .js(如 renderWorker.ts -> renderWorker.js)
|
|
15
|
+
* - 版本号:添加 ?v=版本号 实现缓存破坏
|
|
16
|
+
* - 路径:统一使用 /sdk-workers/ 绝对路径
|
|
17
|
+
*/
|
|
18
|
+
export declare function getWorkerUrl(workerPath: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* 创建 Worker 实例
|
|
21
|
+
* @param workerPath 源码中的 Worker 相对路径
|
|
22
|
+
* @param options Worker 构造参数
|
|
23
|
+
*/
|
|
24
|
+
export declare function createWorker(workerPath: string, options?: WorkerOptions): Worker;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 透视变换 WASM 模块加载器
|
|
3
|
+
* 用于加载和调用 TinyGo 编译的 WASM 模块
|
|
4
|
+
*/
|
|
5
|
+
export interface PerspectivePoint {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
}
|
|
9
|
+
export interface PerspectiveMatrix {
|
|
10
|
+
a: number;
|
|
11
|
+
b: number;
|
|
12
|
+
c: number;
|
|
13
|
+
d: number;
|
|
14
|
+
e: number;
|
|
15
|
+
f: number;
|
|
16
|
+
g: number;
|
|
17
|
+
h: number;
|
|
18
|
+
i?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class PerspectiveWasm {
|
|
21
|
+
private static instance;
|
|
22
|
+
private wasmReady;
|
|
23
|
+
private go;
|
|
24
|
+
private wasmModule;
|
|
25
|
+
private constructor();
|
|
26
|
+
static getInstance(): PerspectiveWasm;
|
|
27
|
+
/**
|
|
28
|
+
* 加载 WASM 模块
|
|
29
|
+
* @param wasmUrl WASM 文件路径(默认: /assets/perspective.wasm)
|
|
30
|
+
* @param wasmExecUrl wasm_exec.js 路径(默认: /assets/wasm_exec.js)
|
|
31
|
+
*/
|
|
32
|
+
load(wasmUrl?: string, wasmExecUrl?: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* 验证授权
|
|
35
|
+
*/
|
|
36
|
+
verifyLicense(token: string): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* 计算透视变换矩阵
|
|
39
|
+
*/
|
|
40
|
+
calcPerspectiveMatrix(points: PerspectivePoint[]): PerspectiveMatrix;
|
|
41
|
+
/**
|
|
42
|
+
* 矩阵求逆
|
|
43
|
+
*/
|
|
44
|
+
invertMatrix(matrix: PerspectiveMatrix): PerspectiveMatrix;
|
|
45
|
+
/**
|
|
46
|
+
* 应用透视变换到单个点
|
|
47
|
+
*/
|
|
48
|
+
applyPerspective(u: number, v: number, matrix: PerspectiveMatrix): PerspectivePoint;
|
|
49
|
+
/**
|
|
50
|
+
* 应用逆透视变换到单个点
|
|
51
|
+
*/
|
|
52
|
+
applyInversePerspective(x: number, y: number, matrix: PerspectiveMatrix): PerspectivePoint;
|
|
53
|
+
/**
|
|
54
|
+
* 批量变换点(高性能)
|
|
55
|
+
*/
|
|
56
|
+
transformPoints(points: PerspectivePoint[], matrix: PerspectiveMatrix, inverse?: boolean): PerspectivePoint[];
|
|
57
|
+
/**
|
|
58
|
+
* 检查 WASM 是否已加载
|
|
59
|
+
*/
|
|
60
|
+
isReady(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* 调用 WASM 函数
|
|
63
|
+
*/
|
|
64
|
+
private call;
|
|
65
|
+
/**
|
|
66
|
+
* 加载外部脚本
|
|
67
|
+
*/
|
|
68
|
+
private loadScript;
|
|
69
|
+
}
|
|
70
|
+
export default PerspectiveWasm;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 透视变换 WASM 模块加载器 (Worker 版本)
|
|
3
|
+
* 用于在 Web Worker 环境中加载和调用 TinyGo 编译的 WASM 模块
|
|
4
|
+
*/
|
|
5
|
+
export interface PerspectivePoint {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
}
|
|
9
|
+
export interface PerspectiveMatrix {
|
|
10
|
+
a: number;
|
|
11
|
+
b: number;
|
|
12
|
+
c: number;
|
|
13
|
+
d: number;
|
|
14
|
+
e: number;
|
|
15
|
+
f: number;
|
|
16
|
+
g: number;
|
|
17
|
+
h: number;
|
|
18
|
+
i?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class PerspectiveWasmWorker {
|
|
21
|
+
private static instance;
|
|
22
|
+
private wasmReady;
|
|
23
|
+
private go;
|
|
24
|
+
private wasmModule;
|
|
25
|
+
private constructor();
|
|
26
|
+
private isDebugEnabled;
|
|
27
|
+
private debugLog;
|
|
28
|
+
private debugWarn;
|
|
29
|
+
static getInstance(): PerspectiveWasmWorker;
|
|
30
|
+
/**
|
|
31
|
+
* 在 Worker 环境中加载 WASM 模块
|
|
32
|
+
* @param wasmUrl WASM 文件路径
|
|
33
|
+
* @param wasmExecUrl wasm_exec.js 路径
|
|
34
|
+
*/
|
|
35
|
+
load(wasmUrl?: string, wasmExecUrl?: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* 在 Worker 中加载 wasm_exec.js
|
|
38
|
+
* Module Worker 不支持 importScripts(),仅 Classic Worker 可尝试 importScripts,否则用 fetch + eval
|
|
39
|
+
*/
|
|
40
|
+
private loadWasmExec;
|
|
41
|
+
/**
|
|
42
|
+
* 验证授权(通过 API)
|
|
43
|
+
*/
|
|
44
|
+
verifyLicense(token: string, apiUrl?: string): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* 获取设备 ID(从全局变量或生成)
|
|
47
|
+
*/
|
|
48
|
+
private getDeviceID;
|
|
49
|
+
/**
|
|
50
|
+
* 获取域名(从全局变量或使用默认值)
|
|
51
|
+
*/
|
|
52
|
+
private getDomain;
|
|
53
|
+
/**
|
|
54
|
+
* 计算透视变换矩阵
|
|
55
|
+
*/
|
|
56
|
+
calcPerspectiveMatrix(points: PerspectivePoint[]): PerspectiveMatrix;
|
|
57
|
+
/**
|
|
58
|
+
* 矩阵求逆
|
|
59
|
+
*/
|
|
60
|
+
invertMatrix(matrix: PerspectiveMatrix): PerspectiveMatrix;
|
|
61
|
+
/**
|
|
62
|
+
* 应用透视变换到单个点
|
|
63
|
+
*/
|
|
64
|
+
applyPerspective(u: number, v: number, matrix: PerspectiveMatrix): PerspectivePoint;
|
|
65
|
+
/**
|
|
66
|
+
* 应用逆透视变换到单个点
|
|
67
|
+
*/
|
|
68
|
+
applyInversePerspective(x: number, y: number, matrix: PerspectiveMatrix): PerspectivePoint;
|
|
69
|
+
/**
|
|
70
|
+
* 批量变换点(高性能)
|
|
71
|
+
*/
|
|
72
|
+
transformPoints(points: PerspectivePoint[], matrix: PerspectiveMatrix, inverse?: boolean): PerspectivePoint[];
|
|
73
|
+
/**
|
|
74
|
+
* 检查 WASM 是否已加载
|
|
75
|
+
*/
|
|
76
|
+
isReady(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* 双三次插值点计算
|
|
79
|
+
*/
|
|
80
|
+
getBicubicPoint(u: number, v: number, points: PerspectivePoint[]): PerspectivePoint;
|
|
81
|
+
/**
|
|
82
|
+
* 双线性插值点计算
|
|
83
|
+
*/
|
|
84
|
+
getBilinearPoint(u: number, v: number, points: PerspectivePoint[]): PerspectivePoint;
|
|
85
|
+
/**
|
|
86
|
+
* 任意网格点插值计算
|
|
87
|
+
*/
|
|
88
|
+
getArbitraryMeshPoint(u: number, v: number, points: PerspectivePoint[], dim: number): PerspectivePoint;
|
|
89
|
+
/**
|
|
90
|
+
* 批量双三次插值(高性能优化)
|
|
91
|
+
* 一次性处理多个坐标,避免频繁的 JS/WASM 边界调用
|
|
92
|
+
*/
|
|
93
|
+
batchBicubicInterpolation(coords: Array<{
|
|
94
|
+
u: number;
|
|
95
|
+
v: number;
|
|
96
|
+
}>, controlPoints: PerspectivePoint[]): PerspectivePoint[];
|
|
97
|
+
/**
|
|
98
|
+
* 批量双线性插值(高性能优化)
|
|
99
|
+
*/
|
|
100
|
+
batchBilinearInterpolation(coords: Array<{
|
|
101
|
+
u: number;
|
|
102
|
+
v: number;
|
|
103
|
+
}>, controlPoints: PerspectivePoint[]): PerspectivePoint[];
|
|
104
|
+
/**
|
|
105
|
+
* 批量任意网格插值(高性能优化)
|
|
106
|
+
*/
|
|
107
|
+
batchArbitraryMeshInterpolation(coords: Array<{
|
|
108
|
+
u: number;
|
|
109
|
+
v: number;
|
|
110
|
+
}>, meshPoints: PerspectivePoint[], dim: number): PerspectivePoint[];
|
|
111
|
+
/**
|
|
112
|
+
* 调用 WASM 函数
|
|
113
|
+
*/
|
|
114
|
+
private call;
|
|
115
|
+
}
|
|
116
|
+
export default PerspectiveWasmWorker;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
async function _(s) {
|
|
2
|
+
const { bitmap: t, quality: e } = s, i = new OffscreenCanvas(t.width, t.height), o = i.getContext("2d");
|
|
3
|
+
if (!o) throw new Error("Failed to create OffscreenCanvas 2d context");
|
|
4
|
+
o.drawImage(t, 0, 0);
|
|
5
|
+
try {
|
|
6
|
+
t.close?.();
|
|
7
|
+
} catch {
|
|
8
|
+
}
|
|
9
|
+
const r = await i.convertToBlob({ type: "image/webp", quality: e });
|
|
10
|
+
return { id: s.id, type: "ENCODE_WEBP_RESULT", blob: r };
|
|
11
|
+
}
|
|
12
|
+
async function A(s) {
|
|
13
|
+
const {
|
|
14
|
+
baseBitmap: t,
|
|
15
|
+
viewportTransform: e,
|
|
16
|
+
canvasWidth: i,
|
|
17
|
+
canvasHeight: o,
|
|
18
|
+
exportExt: r,
|
|
19
|
+
multiplier: c
|
|
20
|
+
} = s, a = e, E = a[0], x = a[4], y = a[5], R = Math.abs(E - 1) < 0.01 && Math.abs(x) < 0.5 && Math.abs(y) < 0.5;
|
|
21
|
+
let d;
|
|
22
|
+
if (R) {
|
|
23
|
+
const h = Math.max(1, Math.round(i * c)), f = Math.max(1, Math.round(o * c));
|
|
24
|
+
d = await createImageBitmap(t, {
|
|
25
|
+
resizeWidth: h,
|
|
26
|
+
resizeHeight: f,
|
|
27
|
+
resizeQuality: "medium"
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
const h = Math.max(1, r.width), f = Math.max(1, r.height), u = new OffscreenCanvas(h, f), p = u.getContext("2d");
|
|
31
|
+
if (!p) throw new Error("Failed to create OffscreenCanvas context");
|
|
32
|
+
const w = a[0], g = a[1], v = a[2], M = a[3], l = a[4], b = a[5], n = w * M - g * v;
|
|
33
|
+
if (Math.abs(n) < 1e-9) throw new Error("Singular viewport matrix");
|
|
34
|
+
const B = M / n, T = -g / n, O = -v / n, C = w / n, I = (v * b - M * l) / n, S = (g * l - w * b) / n, m = t.width / i || 1;
|
|
35
|
+
p.setTransform(
|
|
36
|
+
B / m,
|
|
37
|
+
T / m,
|
|
38
|
+
O / m,
|
|
39
|
+
C / m,
|
|
40
|
+
I - r.minL,
|
|
41
|
+
S - r.minT
|
|
42
|
+
), p.drawImage(t, 0, 0);
|
|
43
|
+
const W = Math.max(1, Math.round(h * c)), z = Math.max(1, Math.round(f * c));
|
|
44
|
+
d = await createImageBitmap(u, {
|
|
45
|
+
resizeWidth: W,
|
|
46
|
+
resizeHeight: z,
|
|
47
|
+
resizeQuality: "medium"
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return { id: s.id, type: "TRANSFORM_BITMAP_RESULT", bitmap: d };
|
|
51
|
+
}
|
|
52
|
+
self.onmessage = async (s) => {
|
|
53
|
+
const t = s.data;
|
|
54
|
+
if (t) {
|
|
55
|
+
if (t.type === "TRANSFORM_BITMAP") {
|
|
56
|
+
try {
|
|
57
|
+
const e = await A(t);
|
|
58
|
+
self.postMessage(e, [e.bitmap]);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
self.postMessage({
|
|
61
|
+
id: t.id,
|
|
62
|
+
type: "ERROR",
|
|
63
|
+
error: e instanceof Error ? e.message : String(e)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (t.type === "ENCODE_WEBP") {
|
|
69
|
+
try {
|
|
70
|
+
const e = await _(t);
|
|
71
|
+
self.postMessage(e);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
self.postMessage({
|
|
74
|
+
id: t.id,
|
|
75
|
+
type: "ERROR",
|
|
76
|
+
error: e instanceof Error ? e.message : String(e)
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jetprint/editor-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build:wasm": "node wasm-build/build.js",
|
|
8
|
+
"build:sdk": "vite build",
|
|
9
|
+
"build": "npm run build:wasm && npm run build:sdk",
|
|
10
|
+
"build:prod": "cross-env NODE_ENV=production npm run build",
|
|
11
|
+
"dev": "vite"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/editor-sdk.es.js",
|
|
14
|
+
"module": "./dist/editor-sdk.es.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/editor-sdk.es.js",
|
|
19
|
+
"require": "./dist/editor-sdk.es.js",
|
|
20
|
+
"types": "./dist/index.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./style.css": "./dist/style.css"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"element-plus": "^2.13.0",
|
|
30
|
+
"fabric": "^7.1.0",
|
|
31
|
+
"pinia": "^3.0.0",
|
|
32
|
+
"vue": "^3.5.0"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"ali-oss": "^6.23.0",
|
|
36
|
+
"axios": "^1.13.2",
|
|
37
|
+
"crypto-js": "^4.2.0",
|
|
38
|
+
"idb": "^8.0.3",
|
|
39
|
+
"jszip": "^3.10.1",
|
|
40
|
+
"mathjs": "^12.1.0",
|
|
41
|
+
"three": "^0.184.0",
|
|
42
|
+
"vue-draggable-plus": "^0.6.1"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/three": "^0.184.0",
|
|
46
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
47
|
+
"cross-env": "^7.0.3",
|
|
48
|
+
"javascript-obfuscator": "^5.3.0",
|
|
49
|
+
"rollup-plugin-obfuscator": "^1.1.0",
|
|
50
|
+
"typescript": "^5.7.3",
|
|
51
|
+
"vite": "^7.2.4",
|
|
52
|
+
"vue": "^3.5.24"
|
|
53
|
+
}
|
|
54
|
+
}
|