@atomm-developer/generator-sdk 1.0.4 → 1.0.5
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { t as toUtf8, f as fromUtf8 } from "./index-
|
|
4
|
+
import { t as toUtf8, f as fromUtf8 } from "./index-BtfWZLb7.js";
|
|
5
5
|
class EventStreamSerde {
|
|
6
6
|
constructor({ marshaller, serializer, deserializer, serdeContext, defaultContentType }) {
|
|
7
7
|
__publicField(this, "marshaller");
|
|
@@ -12265,7 +12265,7 @@ class HttpProtocol extends SerdeContext {
|
|
|
12265
12265
|
});
|
|
12266
12266
|
}
|
|
12267
12267
|
async loadEventStreamCapability() {
|
|
12268
|
-
const { EventStreamSerde } = await import("./index-
|
|
12268
|
+
const { EventStreamSerde } = await import("./index-Ba3cYeMp.js");
|
|
12269
12269
|
return new EventStreamSerde({
|
|
12270
12270
|
marshaller: this.getEventStreamMarshaller(),
|
|
12271
12271
|
serializer: this.serializer,
|
|
@@ -80710,20 +80710,20 @@ class ExportModule {
|
|
|
80710
80710
|
}
|
|
80711
80711
|
/**
|
|
80712
80712
|
* 下载图片到本地
|
|
80713
|
-
*
|
|
80713
|
+
* 支持 png / jpeg / webp / svg 格式
|
|
80714
|
+
*
|
|
80715
|
+
* 内部流程:
|
|
80716
|
+
* 1. 优先调用 getExportData(purpose, format) 获取导出数据
|
|
80717
|
+
* 2. 若未实现则回退到 getExportCanvas(purpose) → canvas.toBlob
|
|
80718
|
+
* 3. 生成 Blob → 触发浏览器下载
|
|
80714
80719
|
*/
|
|
80715
80720
|
async download(options) {
|
|
80716
80721
|
var _a2, _b;
|
|
80717
|
-
const canvas = await this._getCanvas("download");
|
|
80718
80722
|
const format2 = (options == null ? void 0 : options.format) ?? "png";
|
|
80719
|
-
const
|
|
80720
|
-
const
|
|
80721
|
-
const
|
|
80722
|
-
|
|
80723
|
-
);
|
|
80724
|
-
if (!blob) {
|
|
80725
|
-
throw new SdkError(-1, "Failed to create blob from canvas");
|
|
80726
|
-
}
|
|
80723
|
+
const quality = options == null ? void 0 : options.quality;
|
|
80724
|
+
const blob = await this._getBlob("download", format2, quality);
|
|
80725
|
+
const extension = format2 === "jpeg" ? "jpg" : format2;
|
|
80726
|
+
const fileName = (options == null ? void 0 : options.fileName) ?? ((_b = (_a2 = this.provider) == null ? void 0 : _a2.getFileName) == null ? void 0 : _b.call(_a2, "download")) ?? `export-${Date.now()}.${extension}`;
|
|
80727
80727
|
const url2 = URL.createObjectURL(blob);
|
|
80728
80728
|
const link = document.createElement("a");
|
|
80729
80729
|
link.download = fileName;
|
|
@@ -80739,48 +80739,153 @@ class ExportModule {
|
|
|
80739
80739
|
}
|
|
80740
80740
|
/**
|
|
80741
80741
|
* 打开到 xTool Studio
|
|
80742
|
-
*
|
|
80743
|
-
*
|
|
80744
|
-
* -
|
|
80745
|
-
* -
|
|
80742
|
+
*
|
|
80743
|
+
* 支持两种调用方式(向后兼容):
|
|
80744
|
+
* - openInStudio(source) — 直接传图片源(URL / data URL / Blob / File)
|
|
80745
|
+
* - openInStudio({ source, format }) — 传 options 对象,可指定导入格式
|
|
80746
|
+
* - openInStudio() — 无参数,通过 provider 获取数据
|
|
80747
|
+
*
|
|
80748
|
+
* 当未传 source 时,根据 format 参数通过 provider 获取对应格式的数据上传到 OSS
|
|
80746
80749
|
*/
|
|
80747
|
-
async openInStudio(
|
|
80748
|
-
|
|
80750
|
+
async openInStudio(sourceOrOptions) {
|
|
80751
|
+
var _a2;
|
|
80752
|
+
const { source, format: format2 } = this._normalizeStudioArgs(sourceOrOptions);
|
|
80753
|
+
const studioAsset = await this._resolveStudioAsset(source, format2);
|
|
80749
80754
|
const ossUrl = studioAsset.type === "url" ? studioAsset.url : await this._uploadFile(studioAsset.file);
|
|
80750
|
-
|
|
80755
|
+
const isSvg = format2 === "svg" || ((_a2 = studioAsset.file) == null ? void 0 : _a2.type) === "image/svg+xml";
|
|
80756
|
+
this._openStudioProtocol(ossUrl, isSvg ? "SVG" : "2D");
|
|
80751
80757
|
return { success: true };
|
|
80752
80758
|
}
|
|
80759
|
+
/**
|
|
80760
|
+
* 兼容解析 openInStudio 参数:
|
|
80761
|
+
* - 无参数 → { source: undefined, format: 'png' }
|
|
80762
|
+
* - string / Blob / File → { source, format: 'png' }
|
|
80763
|
+
* - { source?, format? } → 直接使用
|
|
80764
|
+
*/
|
|
80765
|
+
_normalizeStudioArgs(input) {
|
|
80766
|
+
if (input == null) {
|
|
80767
|
+
return { source: void 0, format: "png" };
|
|
80768
|
+
}
|
|
80769
|
+
if (typeof input === "string" || input instanceof Blob || input instanceof File) {
|
|
80770
|
+
return { source: input, format: "png" };
|
|
80771
|
+
}
|
|
80772
|
+
return {
|
|
80773
|
+
source: input.source,
|
|
80774
|
+
format: input.format ?? "png"
|
|
80775
|
+
};
|
|
80776
|
+
}
|
|
80753
80777
|
// ─────────────────────────────────────────────
|
|
80754
|
-
// 内部方法
|
|
80778
|
+
// 内部方法 - 数据获取
|
|
80755
80779
|
// ─────────────────────────────────────────────
|
|
80756
80780
|
/**
|
|
80757
|
-
* 获取导出
|
|
80781
|
+
* 获取导出 Blob,统一处理 getExportData / getExportCanvas 两种路径
|
|
80758
80782
|
*/
|
|
80759
|
-
async
|
|
80783
|
+
async _getBlob(purpose, format2, quality) {
|
|
80784
|
+
this._ensureProvider();
|
|
80785
|
+
const exportData = await this._tryGetExportData(purpose, format2);
|
|
80786
|
+
if (exportData) {
|
|
80787
|
+
return this._exportDataToBlob(exportData, format2, quality);
|
|
80788
|
+
}
|
|
80789
|
+
const canvas = await this._tryGetCanvas(purpose);
|
|
80790
|
+
if (canvas) {
|
|
80791
|
+
return this._canvasToBlob(canvas, format2, quality);
|
|
80792
|
+
}
|
|
80793
|
+
throw new SdkError(
|
|
80794
|
+
-1,
|
|
80795
|
+
`No export data available for purpose: ${purpose}. Implement getExportData or getExportCanvas in your ExportProvider.`
|
|
80796
|
+
);
|
|
80797
|
+
}
|
|
80798
|
+
/** 尝试通过 getExportData 获取导出数据 */
|
|
80799
|
+
async _tryGetExportData(purpose, format2) {
|
|
80800
|
+
var _a2;
|
|
80801
|
+
if (!((_a2 = this.provider) == null ? void 0 : _a2.getExportData)) return null;
|
|
80802
|
+
return await Promise.resolve(this.provider.getExportData(purpose, format2));
|
|
80803
|
+
}
|
|
80804
|
+
/** 尝试通过 getExportCanvas 获取画布 */
|
|
80805
|
+
async _tryGetCanvas(purpose) {
|
|
80806
|
+
var _a2;
|
|
80807
|
+
if (!((_a2 = this.provider) == null ? void 0 : _a2.getExportCanvas)) return null;
|
|
80808
|
+
return await Promise.resolve(this.provider.getExportCanvas(purpose));
|
|
80809
|
+
}
|
|
80810
|
+
/** 确保 provider 已注册 */
|
|
80811
|
+
_ensureProvider() {
|
|
80760
80812
|
if (!this.provider) {
|
|
80761
80813
|
throw new SdkError(
|
|
80762
80814
|
-1,
|
|
80763
80815
|
"Export provider not registered. Call sdk.export.register() first."
|
|
80764
80816
|
);
|
|
80765
80817
|
}
|
|
80766
|
-
|
|
80767
|
-
|
|
80768
|
-
|
|
80818
|
+
if (!this.provider.getExportData && !this.provider.getExportCanvas) {
|
|
80819
|
+
throw new SdkError(
|
|
80820
|
+
-1,
|
|
80821
|
+
"ExportProvider must implement at least one of getExportData or getExportCanvas."
|
|
80822
|
+
);
|
|
80823
|
+
}
|
|
80824
|
+
}
|
|
80825
|
+
// ─────────────────────────────────────────────
|
|
80826
|
+
// 内部方法 - ExportData → Blob 转换
|
|
80827
|
+
// ─────────────────────────────────────────────
|
|
80828
|
+
/** 将 ExportData 转换为 Blob */
|
|
80829
|
+
async _exportDataToBlob(data, format2, quality) {
|
|
80830
|
+
switch (data.type) {
|
|
80831
|
+
case "canvas":
|
|
80832
|
+
return this._canvasToBlob(data.canvas, format2, quality);
|
|
80833
|
+
case "blob":
|
|
80834
|
+
return data.blob;
|
|
80835
|
+
case "dataUrl":
|
|
80836
|
+
return this._dataUrlToBlob(data.dataUrl);
|
|
80837
|
+
case "url": {
|
|
80838
|
+
const response = await fetch(data.url);
|
|
80839
|
+
if (!response.ok) {
|
|
80840
|
+
throw new SdkError(-1, `Failed to fetch export URL: ${response.status}`);
|
|
80841
|
+
}
|
|
80842
|
+
return await response.blob();
|
|
80843
|
+
}
|
|
80844
|
+
case "svg":
|
|
80845
|
+
return new Blob([data.svgString], { type: "image/svg+xml" });
|
|
80846
|
+
default:
|
|
80847
|
+
throw new SdkError(-1, `Unknown ExportData type: ${data.type}`);
|
|
80848
|
+
}
|
|
80849
|
+
}
|
|
80850
|
+
/** Canvas → Blob,正确处理各格式 */
|
|
80851
|
+
_canvasToBlob(canvas, format2, quality) {
|
|
80852
|
+
if (format2 === "svg") {
|
|
80853
|
+
throw new SdkError(
|
|
80854
|
+
-1,
|
|
80855
|
+
'Cannot export SVG from HTMLCanvasElement. Implement getExportData in your ExportProvider to return { type: "svg", svgString }.'
|
|
80856
|
+
);
|
|
80769
80857
|
}
|
|
80770
|
-
|
|
80858
|
+
const mimeType = this._formatToMimeType(format2);
|
|
80859
|
+
return new Promise((resolve, reject) => {
|
|
80860
|
+
canvas.toBlob(
|
|
80861
|
+
(blob) => {
|
|
80862
|
+
if (!blob) {
|
|
80863
|
+
reject(new SdkError(-1, "Failed to create blob from canvas"));
|
|
80864
|
+
return;
|
|
80865
|
+
}
|
|
80866
|
+
resolve(blob);
|
|
80867
|
+
},
|
|
80868
|
+
mimeType,
|
|
80869
|
+
quality
|
|
80870
|
+
);
|
|
80871
|
+
});
|
|
80771
80872
|
}
|
|
80873
|
+
// ─────────────────────────────────────────────
|
|
80874
|
+
// 内部方法 - openInStudio 相关
|
|
80875
|
+
// ─────────────────────────────────────────────
|
|
80772
80876
|
/**
|
|
80773
80877
|
* 解析 openInStudio 的输入来源:
|
|
80774
80878
|
* - URL 直传给 Studio
|
|
80775
80879
|
* - data URL / Blob / File 先上传 OSS
|
|
80776
|
-
* -
|
|
80880
|
+
* - 未传时通过 provider 按 format 获取数据
|
|
80777
80881
|
*/
|
|
80778
|
-
async _resolveStudioAsset(source) {
|
|
80882
|
+
async _resolveStudioAsset(source, format2 = "png") {
|
|
80779
80883
|
if (typeof source === "string") {
|
|
80780
80884
|
if (this._isDataUrl(source)) {
|
|
80885
|
+
const ext2 = this._detectDataUrlExtension(source);
|
|
80781
80886
|
return {
|
|
80782
80887
|
type: "file",
|
|
80783
|
-
file: this._dataUrlToFile(source, `${v4$2()}
|
|
80888
|
+
file: this._dataUrlToFile(source, `${v4$2()}.${ext2}`)
|
|
80784
80889
|
};
|
|
80785
80890
|
}
|
|
80786
80891
|
if (this._isHttpUrl(source)) {
|
|
@@ -80795,21 +80900,14 @@ class ExportModule {
|
|
|
80795
80900
|
return { type: "file", file: source };
|
|
80796
80901
|
}
|
|
80797
80902
|
if (source instanceof Blob) {
|
|
80798
|
-
return {
|
|
80799
|
-
type: "file",
|
|
80800
|
-
file: this._blobToFile(source)
|
|
80801
|
-
};
|
|
80802
|
-
}
|
|
80803
|
-
const canvas = await this._getCanvas("studio");
|
|
80804
|
-
let dataUrl;
|
|
80805
|
-
try {
|
|
80806
|
-
dataUrl = canvas.toDataURL("image/png");
|
|
80807
|
-
} catch {
|
|
80808
|
-
throw new SdkError(-1, "Failed to export canvas (cross-origin taint?)");
|
|
80903
|
+
return { type: "file", file: this._blobToFile(source) };
|
|
80809
80904
|
}
|
|
80905
|
+
const blob = await this._getBlob("studio", format2);
|
|
80906
|
+
const ext = format2 === "jpeg" ? "jpg" : format2;
|
|
80907
|
+
const mimeType = this._formatToMimeType(format2);
|
|
80810
80908
|
return {
|
|
80811
80909
|
type: "file",
|
|
80812
|
-
file:
|
|
80910
|
+
file: new File([blob], `${v4$2()}.${ext}`, { type: mimeType })
|
|
80813
80911
|
};
|
|
80814
80912
|
}
|
|
80815
80913
|
/** 获取或懒初始化 Uploader 实例 */
|
|
@@ -80835,7 +80933,7 @@ class ExportModule {
|
|
|
80835
80933
|
});
|
|
80836
80934
|
}
|
|
80837
80935
|
/** 通过 xtool:// 协议打开 Studio */
|
|
80838
|
-
_openStudioProtocol(ossUrl) {
|
|
80936
|
+
_openStudioProtocol(ossUrl, assetType = "2D") {
|
|
80839
80937
|
const payload = {
|
|
80840
80938
|
event: {
|
|
80841
80939
|
name: "OpenOSSImage",
|
|
@@ -80862,7 +80960,7 @@ class ExportModule {
|
|
|
80862
80960
|
payload: {
|
|
80863
80961
|
urls: [
|
|
80864
80962
|
{
|
|
80865
|
-
type:
|
|
80963
|
+
type: assetType,
|
|
80866
80964
|
url: ossUrl,
|
|
80867
80965
|
aimakeInfo: { generator: this.appKey }
|
|
80868
80966
|
}
|
|
@@ -80878,6 +80976,31 @@ class ExportModule {
|
|
|
80878
80976
|
window.open(ossUrl, "_blank");
|
|
80879
80977
|
}
|
|
80880
80978
|
}
|
|
80979
|
+
// ─────────────────────────────────────────────
|
|
80980
|
+
// 工具方法
|
|
80981
|
+
// ─────────────────────────────────────────────
|
|
80982
|
+
/** 导出格式 → MIME 类型(仅位图格式) */
|
|
80983
|
+
_formatToMimeType(format2) {
|
|
80984
|
+
const map = {
|
|
80985
|
+
png: "image/png",
|
|
80986
|
+
jpeg: "image/jpeg",
|
|
80987
|
+
webp: "image/webp",
|
|
80988
|
+
svg: "image/svg+xml"
|
|
80989
|
+
};
|
|
80990
|
+
return map[format2] ?? "image/png";
|
|
80991
|
+
}
|
|
80992
|
+
/** data URL → Blob */
|
|
80993
|
+
_dataUrlToBlob(dataUrl) {
|
|
80994
|
+
var _a2;
|
|
80995
|
+
const [header, base64] = dataUrl.split(",");
|
|
80996
|
+
const mimeType = ((_a2 = header.match(/:(.*?);/)) == null ? void 0 : _a2[1]) ?? "image/png";
|
|
80997
|
+
const binary = atob(base64);
|
|
80998
|
+
const bytes = new Uint8Array(binary.length);
|
|
80999
|
+
for (let i = 0; i < binary.length; i++) {
|
|
81000
|
+
bytes[i] = binary.charCodeAt(i);
|
|
81001
|
+
}
|
|
81002
|
+
return new Blob([bytes], { type: mimeType });
|
|
81003
|
+
}
|
|
80881
81004
|
/** data URL → File 对象 */
|
|
80882
81005
|
_dataUrlToFile(dataUrl, filename) {
|
|
80883
81006
|
var _a2;
|
|
@@ -80896,6 +81019,13 @@ class ExportModule {
|
|
|
80896
81019
|
const extension = this._mimeTypeToExtension(mimeType);
|
|
80897
81020
|
return new File([blob], `${v4$2()}.${extension}`, { type: mimeType });
|
|
80898
81021
|
}
|
|
81022
|
+
/** 从 data URL 推断文件扩展名 */
|
|
81023
|
+
_detectDataUrlExtension(dataUrl) {
|
|
81024
|
+
var _a2;
|
|
81025
|
+
const mimeType = (_a2 = dataUrl.match(/^data:(image\/[a-zA-Z0-9.+-]+);/)) == null ? void 0 : _a2[1];
|
|
81026
|
+
if (!mimeType) return "png";
|
|
81027
|
+
return this._mimeTypeToExtension(mimeType);
|
|
81028
|
+
}
|
|
80899
81029
|
/** 判断是否为 data URL */
|
|
80900
81030
|
_isDataUrl(value) {
|
|
80901
81031
|
return /^data:image\/[a-zA-Z0-9.+-]+;base64,/.test(value);
|
|
@@ -80912,9 +81042,8 @@ class ExportModule {
|
|
|
80912
81042
|
/** MIME 类型 → 文件扩展名 */
|
|
80913
81043
|
_mimeTypeToExtension(mimeType) {
|
|
80914
81044
|
var _a2;
|
|
80915
|
-
if (mimeType === "image/svg+xml")
|
|
80916
|
-
|
|
80917
|
-
}
|
|
81045
|
+
if (mimeType === "image/svg+xml") return "svg";
|
|
81046
|
+
if (mimeType === "image/jpeg") return "jpg";
|
|
80918
81047
|
return ((_a2 = mimeType.split("/")[1]) == null ? void 0 : _a2.split("+")[0]) ?? "png";
|
|
80919
81048
|
}
|
|
80920
81049
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -298,12 +298,35 @@ declare class CreditsModule {
|
|
|
298
298
|
getCachedBalance(): number;
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
+
/**
|
|
302
|
+
* 通用导出数据
|
|
303
|
+
* 当画布不是 HTMLCanvasElement 时,开发者通过 getExportData 返回此类型
|
|
304
|
+
*/
|
|
305
|
+
export declare type ExportData = {
|
|
306
|
+
type: 'canvas';
|
|
307
|
+
canvas: HTMLCanvasElement;
|
|
308
|
+
} | {
|
|
309
|
+
type: 'blob';
|
|
310
|
+
blob: Blob;
|
|
311
|
+
} | {
|
|
312
|
+
type: 'dataUrl';
|
|
313
|
+
dataUrl: string;
|
|
314
|
+
} | {
|
|
315
|
+
type: 'url';
|
|
316
|
+
url: string;
|
|
317
|
+
} | {
|
|
318
|
+
type: 'svg';
|
|
319
|
+
svgString: string;
|
|
320
|
+
};
|
|
321
|
+
|
|
301
322
|
/** export.download() 参数 */
|
|
302
323
|
export declare interface ExportDownloadOptions {
|
|
303
|
-
/** 文件名(可选,默认 'export-{timestamp}.
|
|
324
|
+
/** 文件名(可选,默认 'export-{timestamp}.{format}') */
|
|
304
325
|
fileName?: string;
|
|
305
326
|
/** 导出格式(可选,默认 'png') */
|
|
306
|
-
format?:
|
|
327
|
+
format?: ExportFormat;
|
|
328
|
+
/** JPEG/WebP 质量 0-1(可选,默认 0.92) */
|
|
329
|
+
quality?: number;
|
|
307
330
|
}
|
|
308
331
|
|
|
309
332
|
/** export.download() 返回值 */
|
|
@@ -312,6 +335,9 @@ export declare interface ExportDownloadResult {
|
|
|
312
335
|
fileName: string;
|
|
313
336
|
}
|
|
314
337
|
|
|
338
|
+
/** 支持的导出格式 */
|
|
339
|
+
export declare type ExportFormat = 'png' | 'jpeg' | 'webp' | 'svg';
|
|
340
|
+
|
|
315
341
|
/**
|
|
316
342
|
* Export 模块
|
|
317
343
|
* 对外暴露:register / download / openInStudio
|
|
@@ -330,26 +356,51 @@ declare class ExportModule {
|
|
|
330
356
|
register(provider: ExportProvider): void;
|
|
331
357
|
/**
|
|
332
358
|
* 下载图片到本地
|
|
333
|
-
*
|
|
359
|
+
* 支持 png / jpeg / webp / svg 格式
|
|
360
|
+
*
|
|
361
|
+
* 内部流程:
|
|
362
|
+
* 1. 优先调用 getExportData(purpose, format) 获取导出数据
|
|
363
|
+
* 2. 若未实现则回退到 getExportCanvas(purpose) → canvas.toBlob
|
|
364
|
+
* 3. 生成 Blob → 触发浏览器下载
|
|
334
365
|
*/
|
|
335
366
|
download(options?: ExportDownloadOptions): Promise<ExportDownloadResult>;
|
|
336
367
|
/**
|
|
337
368
|
* 打开到 xTool Studio
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
* -
|
|
341
|
-
* -
|
|
369
|
+
*
|
|
370
|
+
* 支持两种调用方式(向后兼容):
|
|
371
|
+
* - openInStudio(source) — 直接传图片源(URL / data URL / Blob / File)
|
|
372
|
+
* - openInStudio({ source, format }) — 传 options 对象,可指定导入格式
|
|
373
|
+
* - openInStudio() — 无参数,通过 provider 获取数据
|
|
374
|
+
*
|
|
375
|
+
* 当未传 source 时,根据 format 参数通过 provider 获取对应格式的数据上传到 OSS
|
|
342
376
|
*/
|
|
343
|
-
openInStudio(
|
|
377
|
+
openInStudio(sourceOrOptions?: ExportOpenInStudioSource | ExportOpenInStudioOptions): Promise<ExportOpenInStudioResult>;
|
|
344
378
|
/**
|
|
345
|
-
*
|
|
379
|
+
* 兼容解析 openInStudio 参数:
|
|
380
|
+
* - 无参数 → { source: undefined, format: 'png' }
|
|
381
|
+
* - string / Blob / File → { source, format: 'png' }
|
|
382
|
+
* - { source?, format? } → 直接使用
|
|
346
383
|
*/
|
|
347
|
-
private
|
|
384
|
+
private _normalizeStudioArgs;
|
|
385
|
+
/**
|
|
386
|
+
* 获取导出 Blob,统一处理 getExportData / getExportCanvas 两种路径
|
|
387
|
+
*/
|
|
388
|
+
private _getBlob;
|
|
389
|
+
/** 尝试通过 getExportData 获取导出数据 */
|
|
390
|
+
private _tryGetExportData;
|
|
391
|
+
/** 尝试通过 getExportCanvas 获取画布 */
|
|
392
|
+
private _tryGetCanvas;
|
|
393
|
+
/** 确保 provider 已注册 */
|
|
394
|
+
private _ensureProvider;
|
|
395
|
+
/** 将 ExportData 转换为 Blob */
|
|
396
|
+
private _exportDataToBlob;
|
|
397
|
+
/** Canvas → Blob,正确处理各格式 */
|
|
398
|
+
private _canvasToBlob;
|
|
348
399
|
/**
|
|
349
400
|
* 解析 openInStudio 的输入来源:
|
|
350
401
|
* - URL 直传给 Studio
|
|
351
402
|
* - data URL / Blob / File 先上传 OSS
|
|
352
|
-
* -
|
|
403
|
+
* - 未传时通过 provider 按 format 获取数据
|
|
353
404
|
*/
|
|
354
405
|
private _resolveStudioAsset;
|
|
355
406
|
/** 获取或懒初始化 Uploader 实例 */
|
|
@@ -358,10 +409,16 @@ declare class ExportModule {
|
|
|
358
409
|
private _uploadFile;
|
|
359
410
|
/** 通过 xtool:// 协议打开 Studio */
|
|
360
411
|
private _openStudioProtocol;
|
|
412
|
+
/** 导出格式 → MIME 类型(仅位图格式) */
|
|
413
|
+
private _formatToMimeType;
|
|
414
|
+
/** data URL → Blob */
|
|
415
|
+
private _dataUrlToBlob;
|
|
361
416
|
/** data URL → File 对象 */
|
|
362
417
|
private _dataUrlToFile;
|
|
363
418
|
/** Blob → File 对象 */
|
|
364
419
|
private _blobToFile;
|
|
420
|
+
/** 从 data URL 推断文件扩展名 */
|
|
421
|
+
private _detectDataUrlExtension;
|
|
365
422
|
/** 判断是否为 data URL */
|
|
366
423
|
private _isDataUrl;
|
|
367
424
|
/** 判断是否为可直接交给 Studio 的远程 URL */
|
|
@@ -370,24 +427,48 @@ declare class ExportModule {
|
|
|
370
427
|
private _mimeTypeToExtension;
|
|
371
428
|
}
|
|
372
429
|
|
|
430
|
+
/**
|
|
431
|
+
* export.openInStudio() 参数
|
|
432
|
+
* 支持两种调用方式(向后兼容):
|
|
433
|
+
* - openInStudio(source) — 直接传图片源
|
|
434
|
+
* - openInStudio({ source, format }) — 传 options 对象
|
|
435
|
+
*/
|
|
436
|
+
export declare interface ExportOpenInStudioOptions {
|
|
437
|
+
/** 图片来源:URL / data URL / Blob / File,不传时从 provider 获取 */
|
|
438
|
+
source?: ExportOpenInStudioSource;
|
|
439
|
+
/** 导入 Studio 的格式(不传 source 时生效),默认 'png' */
|
|
440
|
+
format?: ExportFormat;
|
|
441
|
+
}
|
|
442
|
+
|
|
373
443
|
/** export.openInStudio() 返回值 */
|
|
374
444
|
export declare interface ExportOpenInStudioResult {
|
|
375
445
|
success: boolean;
|
|
376
446
|
}
|
|
377
447
|
|
|
378
|
-
/** export.openInStudio()
|
|
448
|
+
/** export.openInStudio() 直接传入的图片源(向后兼容) */
|
|
379
449
|
export declare type ExportOpenInStudioSource = string | Blob | File;
|
|
380
450
|
|
|
381
451
|
/**
|
|
382
452
|
* 导出能力提供者
|
|
383
453
|
* 开发者实现此接口并通过 sdk.export.register() 注册
|
|
454
|
+
*
|
|
455
|
+
* 提供两种方式(优先级:getExportData > getExportCanvas):
|
|
456
|
+
* - getExportData:灵活方式,适合非 canvas 场景(SVG/DOM/纯数据)
|
|
457
|
+
* - getExportCanvas:传统方式,直接返回 HTMLCanvasElement
|
|
458
|
+
*
|
|
459
|
+
* 至少实现其中一个,否则调用 download/openInStudio 时会抛出错误
|
|
384
460
|
*/
|
|
385
461
|
export declare interface ExportProvider {
|
|
386
462
|
/**
|
|
387
|
-
*
|
|
388
|
-
*
|
|
463
|
+
* 获取导出数据(灵活方式,优先级高于 getExportCanvas)
|
|
464
|
+
* 适用于非 canvas 场景:SVG 编辑器、DOM 截图、纯数据生成等
|
|
465
|
+
*/
|
|
466
|
+
getExportData?: (purpose: ExportPurpose, format: ExportFormat) => ExportData | Promise<ExportData | null> | null;
|
|
467
|
+
/**
|
|
468
|
+
* 获取导出用的 Canvas(传统方式)
|
|
469
|
+
* 当 getExportData 未实现或返回 null 时回退到此方法
|
|
389
470
|
*/
|
|
390
|
-
getExportCanvas
|
|
471
|
+
getExportCanvas?: (purpose: ExportPurpose) => HTMLCanvasElement | Promise<HTMLCanvasElement | null> | null;
|
|
391
472
|
/** 自定义文件名生成器(可选) */
|
|
392
473
|
getFileName?: (purpose: ExportPurpose) => string;
|
|
393
474
|
}
|
package/dist/index.es.js
CHANGED