light-chain-open-ui 1.0.6 → 1.0.8
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/README.md +233 -224
- package/dist/{button-KoRq6mAW.js → button-CqwbqOYj.js} +5 -5
- package/dist/{button-hUFCfzUP.cjs → button-D6klXjl6.cjs} +2 -2
- package/dist/{client-jorIw6pH.js → client-BnxuHpr9.js} +207 -115
- package/dist/client-LNELhD1v.cjs +1 -0
- package/dist/{constants-CdudjmSn.js → constants-C7ZLmqrC.js} +33 -8
- package/dist/constants-DFJCA4_2.cjs +1 -0
- package/dist/contants.cjs +1 -1
- package/dist/contants.mjs +4 -4
- package/dist/core-B6yT9mOC.cjs +1 -0
- package/dist/core-BlgVibCC.js +1 -0
- package/dist/lightchain-ui.cjs +1 -1
- package/dist/lightchain-ui.mjs +6 -6
- package/dist/options.cjs +1 -1
- package/dist/options.mjs +2 -2
- package/dist/react.cjs +1 -1
- package/dist/react.mjs +10 -9
- package/dist/types/core/client.d.ts +10 -10
- package/dist/types/core/constants.d.ts +23 -1
- package/dist/types/core/task-types/index.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/options.d.ts +2 -2
- package/dist/types/react/index.d.ts +11 -10
- package/dist/types/types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/client-CJ8X0sFi.cjs +0 -1
- package/dist/constants-Bdlwi9VJ.cjs +0 -1
- package/dist/core-D0DpSeAr.cjs +0 -1
- package/dist/core-rH2gpxTB.js +0 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as e, C as t, D as n, E as r, F as i, O as a, S as o, T as s, _ as c, a as l, b as u, f as d, g as f, h as p, k as m, l as h, m as g, p as _, u as v, v as y, w as b, x, y as S } from "./constants-C7ZLmqrC.js";
|
|
2
2
|
//#region src/core/types.ts
|
|
3
|
-
var
|
|
3
|
+
var C = {
|
|
4
4
|
RUNNING: "running",
|
|
5
5
|
DONE: "done"
|
|
6
|
-
},
|
|
6
|
+
}, w = {
|
|
7
7
|
DONE: "done",
|
|
8
8
|
EXCEPTION: "exception"
|
|
9
|
-
},
|
|
9
|
+
}, T = {
|
|
10
10
|
MAX_SIZE_MB: 10,
|
|
11
11
|
MAX_WIDTH: 2048,
|
|
12
12
|
MAX_HEIGHT: 2048,
|
|
13
13
|
ASPECT_RATIO_MIN: 1 / 3,
|
|
14
14
|
ASPECT_RATIO_MAX: 3
|
|
15
|
-
},
|
|
15
|
+
}, E = [
|
|
16
16
|
"1:1",
|
|
17
17
|
"2:3",
|
|
18
18
|
"3:4",
|
|
@@ -23,32 +23,32 @@ var S = {
|
|
|
23
23
|
];
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region src/core/image-validator.ts
|
|
26
|
-
function
|
|
26
|
+
function D(e) {
|
|
27
27
|
let t = [];
|
|
28
|
-
e.size >
|
|
28
|
+
e.size > T.MAX_SIZE_MB * 1024 * 1024 && t.push("图片大小不能超过10MB"), (e.width > T.MAX_WIDTH || e.height > T.MAX_HEIGHT) && t.push("图片分辨率不能超过2048x2048");
|
|
29
29
|
let n = e.width / e.height;
|
|
30
|
-
return (n <
|
|
30
|
+
return (n < T.ASPECT_RATIO_MIN || n > T.ASPECT_RATIO_MAX) && t.push("宽高比必须在1:3到3:1之间"), {
|
|
31
31
|
valid: t.length === 0,
|
|
32
32
|
errors: t
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function O(e, t) {
|
|
36
36
|
let n = [];
|
|
37
37
|
return (e.width !== t.width || e.height !== t.height) && n.push("蒙版尺寸必须与原图尺寸相同"), {
|
|
38
38
|
valid: n.length === 0,
|
|
39
39
|
errors: n
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
async function
|
|
43
|
-
let t = e.size <=
|
|
42
|
+
async function k(e) {
|
|
43
|
+
let t = e.size <= T.MAX_SIZE_MB * 1024 * 1024;
|
|
44
44
|
return new Promise((n) => {
|
|
45
45
|
let r = new Image(), i = URL.createObjectURL(e);
|
|
46
46
|
r.onload = () => {
|
|
47
47
|
URL.revokeObjectURL(i);
|
|
48
48
|
let e = [];
|
|
49
|
-
(r.width >
|
|
49
|
+
(r.width > T.MAX_WIDTH || r.height > T.MAX_HEIGHT) && e.push("图片分辨率不能超过2048x2048");
|
|
50
50
|
let a = r.width / r.height;
|
|
51
|
-
(a <
|
|
51
|
+
(a < T.ASPECT_RATIO_MIN || a > T.ASPECT_RATIO_MAX) && e.push("宽高比必须在1:3到3:1之间"), t || e.push("图片大小不能超过10MB"), n({
|
|
52
52
|
valid: e.length === 0,
|
|
53
53
|
errors: e
|
|
54
54
|
});
|
|
@@ -62,7 +62,7 @@ async function O(e) {
|
|
|
62
62
|
}
|
|
63
63
|
//#endregion
|
|
64
64
|
//#region src/core/task-types/types-part-a.ts
|
|
65
|
-
var
|
|
65
|
+
var A = {
|
|
66
66
|
GeneratePrinting: {
|
|
67
67
|
key: "GeneratePrinting",
|
|
68
68
|
title: "图案设计",
|
|
@@ -160,7 +160,7 @@ var k = {
|
|
|
160
160
|
label: "视角",
|
|
161
161
|
type: "enum",
|
|
162
162
|
required: !0,
|
|
163
|
-
options:
|
|
163
|
+
options: u
|
|
164
164
|
}]
|
|
165
165
|
},
|
|
166
166
|
PrintingTiling: {
|
|
@@ -286,7 +286,7 @@ var k = {
|
|
|
286
286
|
label: "放大倍数",
|
|
287
287
|
type: "enum",
|
|
288
288
|
required: !0,
|
|
289
|
-
options:
|
|
289
|
+
options: r
|
|
290
290
|
}]
|
|
291
291
|
},
|
|
292
292
|
VectorConvert: {
|
|
@@ -303,7 +303,7 @@ var k = {
|
|
|
303
303
|
label: "图案类型",
|
|
304
304
|
type: "enum",
|
|
305
305
|
required: !0,
|
|
306
|
-
options:
|
|
306
|
+
options: S
|
|
307
307
|
}]
|
|
308
308
|
},
|
|
309
309
|
ChangeModel: {
|
|
@@ -321,19 +321,19 @@ var k = {
|
|
|
321
321
|
name: "gender",
|
|
322
322
|
label: "性别",
|
|
323
323
|
type: "enum",
|
|
324
|
-
options:
|
|
324
|
+
options: f
|
|
325
325
|
},
|
|
326
326
|
{
|
|
327
327
|
name: "age",
|
|
328
328
|
label: "年龄",
|
|
329
329
|
type: "enum",
|
|
330
|
-
options:
|
|
330
|
+
options: v
|
|
331
331
|
},
|
|
332
332
|
{
|
|
333
333
|
name: "race",
|
|
334
334
|
label: "人种",
|
|
335
335
|
type: "enum",
|
|
336
|
-
options:
|
|
336
|
+
options: t
|
|
337
337
|
}
|
|
338
338
|
]
|
|
339
339
|
},
|
|
@@ -361,7 +361,7 @@ var k = {
|
|
|
361
361
|
name: "position",
|
|
362
362
|
label: "服装位置",
|
|
363
363
|
type: "enum",
|
|
364
|
-
options:
|
|
364
|
+
options: x
|
|
365
365
|
}]
|
|
366
366
|
},
|
|
367
367
|
Eliminate: {
|
|
@@ -440,7 +440,7 @@ var k = {
|
|
|
440
440
|
label: "改版部位",
|
|
441
441
|
type: "multiEnum",
|
|
442
442
|
required: !0,
|
|
443
|
-
options:
|
|
443
|
+
options: g
|
|
444
444
|
}]
|
|
445
445
|
},
|
|
446
446
|
GenerateModel: {
|
|
@@ -460,13 +460,13 @@ var k = {
|
|
|
460
460
|
label: "性别",
|
|
461
461
|
type: "enum",
|
|
462
462
|
required: !0,
|
|
463
|
-
options:
|
|
463
|
+
options: f
|
|
464
464
|
},
|
|
465
465
|
{
|
|
466
466
|
name: "race",
|
|
467
467
|
label: "人种",
|
|
468
468
|
type: "enum",
|
|
469
|
-
options:
|
|
469
|
+
options: t
|
|
470
470
|
}
|
|
471
471
|
]
|
|
472
472
|
},
|
|
@@ -513,7 +513,7 @@ var k = {
|
|
|
513
513
|
label: "识别类型",
|
|
514
514
|
type: "enum",
|
|
515
515
|
required: !0,
|
|
516
|
-
options:
|
|
516
|
+
options: b
|
|
517
517
|
}]
|
|
518
518
|
},
|
|
519
519
|
LineArtToReal: {
|
|
@@ -532,7 +532,7 @@ var k = {
|
|
|
532
532
|
label: "图片类型",
|
|
533
533
|
type: "enum",
|
|
534
534
|
required: !0,
|
|
535
|
-
options:
|
|
535
|
+
options: c
|
|
536
536
|
},
|
|
537
537
|
{
|
|
538
538
|
name: "prompt",
|
|
@@ -606,7 +606,7 @@ var k = {
|
|
|
606
606
|
required: !0
|
|
607
607
|
}]
|
|
608
608
|
}
|
|
609
|
-
},
|
|
609
|
+
}, j = {
|
|
610
610
|
ChangeAccessoriesByImg: {
|
|
611
611
|
key: "ChangeAccessoriesByImg",
|
|
612
612
|
title: "配饰穿搭调整",
|
|
@@ -629,7 +629,7 @@ var k = {
|
|
|
629
629
|
label: "配件类型",
|
|
630
630
|
type: "enum",
|
|
631
631
|
required: !0,
|
|
632
|
-
options:
|
|
632
|
+
options: h
|
|
633
633
|
}
|
|
634
634
|
]
|
|
635
635
|
},
|
|
@@ -663,7 +663,7 @@ var k = {
|
|
|
663
663
|
label: "试衣模板",
|
|
664
664
|
type: "enum",
|
|
665
665
|
required: !0,
|
|
666
|
-
options:
|
|
666
|
+
options: e
|
|
667
667
|
}]
|
|
668
668
|
},
|
|
669
669
|
FixDeformities: {
|
|
@@ -698,7 +698,7 @@ var k = {
|
|
|
698
698
|
label: "裁剪模式",
|
|
699
699
|
type: "enum",
|
|
700
700
|
required: !0,
|
|
701
|
-
options:
|
|
701
|
+
options: _
|
|
702
702
|
},
|
|
703
703
|
{
|
|
704
704
|
name: "x",
|
|
@@ -741,7 +741,7 @@ var k = {
|
|
|
741
741
|
label: "服装位置",
|
|
742
742
|
type: "enum",
|
|
743
743
|
required: !0,
|
|
744
|
-
options:
|
|
744
|
+
options: x
|
|
745
745
|
}]
|
|
746
746
|
},
|
|
747
747
|
GenerateShortVideo: {
|
|
@@ -771,7 +771,7 @@ var k = {
|
|
|
771
771
|
label: "时长",
|
|
772
772
|
type: "enum",
|
|
773
773
|
required: !0,
|
|
774
|
-
options:
|
|
774
|
+
options: p
|
|
775
775
|
}
|
|
776
776
|
]
|
|
777
777
|
},
|
|
@@ -804,32 +804,75 @@ var k = {
|
|
|
804
804
|
}
|
|
805
805
|
]
|
|
806
806
|
},
|
|
807
|
-
|
|
808
|
-
key: "
|
|
809
|
-
title: "
|
|
810
|
-
description: "
|
|
807
|
+
OrientationRedesign: {
|
|
808
|
+
key: "OrientationRedesign",
|
|
809
|
+
title: "智能改款",
|
|
810
|
+
description: "上传服装主图与参考图,按指令智能改款",
|
|
811
811
|
fields: [
|
|
812
812
|
{
|
|
813
813
|
name: "imgUrl",
|
|
814
|
-
label: "
|
|
814
|
+
label: "主图",
|
|
815
815
|
type: "image",
|
|
816
816
|
required: !0
|
|
817
817
|
},
|
|
818
|
-
{
|
|
819
|
-
name: "maskUrl",
|
|
820
|
-
label: "蒙版1",
|
|
821
|
-
type: "mask"
|
|
822
|
-
},
|
|
823
818
|
{
|
|
824
819
|
name: "refImgUrl",
|
|
825
|
-
label: "参考图
|
|
820
|
+
label: "参考图",
|
|
826
821
|
type: "image"
|
|
827
822
|
},
|
|
828
823
|
{
|
|
829
824
|
name: "prompt",
|
|
830
|
-
label: "
|
|
825
|
+
label: "改款指令",
|
|
831
826
|
type: "text",
|
|
832
|
-
placeholder: "
|
|
827
|
+
placeholder: "描述改款需求"
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
name: "optimizeFlag",
|
|
831
|
+
label: "是否强化指令",
|
|
832
|
+
type: "boolean"
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
name: "qualityMode",
|
|
836
|
+
label: "质量模式",
|
|
837
|
+
type: "enum",
|
|
838
|
+
required: !0,
|
|
839
|
+
options: o
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
name: "aspectRatio",
|
|
843
|
+
label: "生图尺寸",
|
|
844
|
+
type: "aspectRatio"
|
|
845
|
+
}
|
|
846
|
+
]
|
|
847
|
+
},
|
|
848
|
+
OrientationDesignReplaceElement: {
|
|
849
|
+
key: "OrientationDesignReplaceElement",
|
|
850
|
+
title: "元素替换",
|
|
851
|
+
description: "基于遮罩与参考图替换设计点元素",
|
|
852
|
+
fields: [
|
|
853
|
+
{
|
|
854
|
+
name: "imgUrl",
|
|
855
|
+
label: "服装图片",
|
|
856
|
+
type: "image",
|
|
857
|
+
required: !0
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
name: "maskImgUrl",
|
|
861
|
+
label: "设计点遮罩",
|
|
862
|
+
type: "mask",
|
|
863
|
+
required: !0
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
name: "referenceImgUrl",
|
|
867
|
+
label: "设计点参考图",
|
|
868
|
+
type: "image",
|
|
869
|
+
required: !0
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
name: "referenceMaskImgUrl",
|
|
873
|
+
label: "参考图遮罩",
|
|
874
|
+
type: "mask",
|
|
875
|
+
required: !0
|
|
833
876
|
}
|
|
834
877
|
]
|
|
835
878
|
},
|
|
@@ -926,7 +969,7 @@ var k = {
|
|
|
926
969
|
VirtualFittingReferenceV2: {
|
|
927
970
|
key: "VirtualFittingReferenceV2",
|
|
928
971
|
title: "AI试衣参考图2.0",
|
|
929
|
-
description: "
|
|
972
|
+
description: "支持姿势、背景、质量与比例的试衣参考图2.0",
|
|
930
973
|
fields: [
|
|
931
974
|
{
|
|
932
975
|
name: "imgUrl",
|
|
@@ -956,6 +999,12 @@ var k = {
|
|
|
956
999
|
type: "text",
|
|
957
1000
|
placeholder: "描述试衣需求"
|
|
958
1001
|
},
|
|
1002
|
+
{
|
|
1003
|
+
name: "qualityMode",
|
|
1004
|
+
label: "生图质量",
|
|
1005
|
+
type: "enum",
|
|
1006
|
+
options: o
|
|
1007
|
+
},
|
|
959
1008
|
{
|
|
960
1009
|
name: "aspectRatio",
|
|
961
1010
|
label: "宽高比",
|
|
@@ -963,6 +1012,38 @@ var k = {
|
|
|
963
1012
|
}
|
|
964
1013
|
]
|
|
965
1014
|
},
|
|
1015
|
+
VirtualFittingV2: {
|
|
1016
|
+
key: "VirtualFittingV2",
|
|
1017
|
+
endpoint: "/task/submit/v2/VirtualFitting",
|
|
1018
|
+
title: "AI试衣2.0",
|
|
1019
|
+
description: "上传服装图,按文字指令生成商用模特效果图",
|
|
1020
|
+
fields: [
|
|
1021
|
+
{
|
|
1022
|
+
name: "imgUrl",
|
|
1023
|
+
label: "服装图片",
|
|
1024
|
+
type: "image",
|
|
1025
|
+
required: !0
|
|
1026
|
+
},
|
|
1027
|
+
{
|
|
1028
|
+
name: "userPrompt",
|
|
1029
|
+
label: "文字指令",
|
|
1030
|
+
type: "text",
|
|
1031
|
+
required: !0,
|
|
1032
|
+
placeholder: "描述试衣需求"
|
|
1033
|
+
},
|
|
1034
|
+
{
|
|
1035
|
+
name: "qualityMode",
|
|
1036
|
+
label: "生图质量",
|
|
1037
|
+
type: "enum",
|
|
1038
|
+
options: o
|
|
1039
|
+
},
|
|
1040
|
+
{
|
|
1041
|
+
name: "aspectRatio",
|
|
1042
|
+
label: "生成比例",
|
|
1043
|
+
type: "aspectRatio"
|
|
1044
|
+
}
|
|
1045
|
+
]
|
|
1046
|
+
},
|
|
966
1047
|
FlowerShapedDesign: {
|
|
967
1048
|
key: "FlowerShapedDesign",
|
|
968
1049
|
title: "花型创款",
|
|
@@ -1015,7 +1096,7 @@ var k = {
|
|
|
1015
1096
|
name: "removePattern",
|
|
1016
1097
|
label: "是否去除参考图印花",
|
|
1017
1098
|
type: "enum",
|
|
1018
|
-
options:
|
|
1099
|
+
options: s
|
|
1019
1100
|
}
|
|
1020
1101
|
]
|
|
1021
1102
|
},
|
|
@@ -1063,31 +1144,31 @@ var k = {
|
|
|
1063
1144
|
label: "性别",
|
|
1064
1145
|
type: "enum",
|
|
1065
1146
|
required: !0,
|
|
1066
|
-
options:
|
|
1147
|
+
options: f
|
|
1067
1148
|
},
|
|
1068
1149
|
{
|
|
1069
1150
|
name: "age",
|
|
1070
1151
|
label: "年龄",
|
|
1071
1152
|
type: "enum",
|
|
1072
|
-
options:
|
|
1153
|
+
options: v
|
|
1073
1154
|
},
|
|
1074
1155
|
{
|
|
1075
1156
|
name: "nationality",
|
|
1076
1157
|
label: "国籍",
|
|
1077
1158
|
type: "enum",
|
|
1078
|
-
options:
|
|
1159
|
+
options: y
|
|
1079
1160
|
},
|
|
1080
1161
|
{
|
|
1081
1162
|
name: "skinColor",
|
|
1082
1163
|
label: "肤色",
|
|
1083
1164
|
type: "enum",
|
|
1084
|
-
options:
|
|
1165
|
+
options: m
|
|
1085
1166
|
},
|
|
1086
1167
|
{
|
|
1087
1168
|
name: "bodyShape",
|
|
1088
1169
|
label: "身材",
|
|
1089
1170
|
type: "enum",
|
|
1090
|
-
options:
|
|
1171
|
+
options: d
|
|
1091
1172
|
}
|
|
1092
1173
|
]
|
|
1093
1174
|
},
|
|
@@ -1101,7 +1182,7 @@ var k = {
|
|
|
1101
1182
|
label: "性别",
|
|
1102
1183
|
type: "enum",
|
|
1103
1184
|
required: !0,
|
|
1104
|
-
options:
|
|
1185
|
+
options: f
|
|
1105
1186
|
},
|
|
1106
1187
|
{
|
|
1107
1188
|
name: "faceRefImgUrl",
|
|
@@ -1173,7 +1254,7 @@ var k = {
|
|
|
1173
1254
|
name: "gender",
|
|
1174
1255
|
label: "性别",
|
|
1175
1256
|
type: "enum",
|
|
1176
|
-
options:
|
|
1257
|
+
options: f
|
|
1177
1258
|
},
|
|
1178
1259
|
{
|
|
1179
1260
|
name: "similarity",
|
|
@@ -1227,7 +1308,7 @@ var k = {
|
|
|
1227
1308
|
label: "尺码",
|
|
1228
1309
|
type: "enum",
|
|
1229
1310
|
required: !0,
|
|
1230
|
-
options:
|
|
1311
|
+
options: a
|
|
1231
1312
|
},
|
|
1232
1313
|
{
|
|
1233
1314
|
name: "aspectRatio",
|
|
@@ -1305,7 +1386,7 @@ var k = {
|
|
|
1305
1386
|
label: "视角",
|
|
1306
1387
|
type: "enum",
|
|
1307
1388
|
required: !0,
|
|
1308
|
-
options:
|
|
1389
|
+
options: u
|
|
1309
1390
|
},
|
|
1310
1391
|
{
|
|
1311
1392
|
name: "aspectRatio",
|
|
@@ -1339,22 +1420,22 @@ var k = {
|
|
|
1339
1420
|
}
|
|
1340
1421
|
]
|
|
1341
1422
|
}
|
|
1342
|
-
},
|
|
1343
|
-
...
|
|
1344
|
-
...
|
|
1423
|
+
}, M = {
|
|
1424
|
+
...A,
|
|
1425
|
+
...j
|
|
1345
1426
|
};
|
|
1346
|
-
function
|
|
1347
|
-
return
|
|
1427
|
+
function N(e) {
|
|
1428
|
+
return M[e];
|
|
1348
1429
|
}
|
|
1349
|
-
function
|
|
1350
|
-
return Object.values(
|
|
1430
|
+
function P() {
|
|
1431
|
+
return Object.values(M);
|
|
1351
1432
|
}
|
|
1352
1433
|
//#endregion
|
|
1353
1434
|
//#region src/core/validate.ts
|
|
1354
|
-
function
|
|
1435
|
+
function F(e, t) {
|
|
1355
1436
|
let n = [];
|
|
1356
1437
|
for (let r of t) {
|
|
1357
|
-
let t = e[r.name], i =
|
|
1438
|
+
let t = e[r.name], i = I(r, t);
|
|
1358
1439
|
i && n.push(i);
|
|
1359
1440
|
}
|
|
1360
1441
|
return {
|
|
@@ -1362,12 +1443,12 @@ function P(e, t) {
|
|
|
1362
1443
|
errors: n
|
|
1363
1444
|
};
|
|
1364
1445
|
}
|
|
1365
|
-
function
|
|
1446
|
+
function I(e, t) {
|
|
1366
1447
|
let n = t == null || t === "";
|
|
1367
1448
|
if (e.required && n) return {
|
|
1368
1449
|
field: e.name,
|
|
1369
1450
|
label: e.label,
|
|
1370
|
-
message:
|
|
1451
|
+
message: l.FIELD_REQUIRED(e.label)
|
|
1371
1452
|
};
|
|
1372
1453
|
if (t == null) return null;
|
|
1373
1454
|
let r = (t) => ({
|
|
@@ -1378,42 +1459,45 @@ function F(e, t) {
|
|
|
1378
1459
|
switch (e.type) {
|
|
1379
1460
|
case "image":
|
|
1380
1461
|
case "mask":
|
|
1381
|
-
if (typeof t != "string" && !
|
|
1462
|
+
if (typeof t != "string" && !L(t)) return r(l.FIELD_STRING);
|
|
1382
1463
|
break;
|
|
1383
1464
|
case "images":
|
|
1384
|
-
if (!Array.isArray(t) || t.length === 0) return r(
|
|
1385
|
-
if (t.some((e) => (typeof e != "string" || e === "") && !
|
|
1465
|
+
if (!Array.isArray(t) || t.length === 0) return r(l.FIELD_ARRAY);
|
|
1466
|
+
if (t.some((e) => (typeof e != "string" || e === "") && !L(e))) return r(l.FIELD_ARRAY_ELEMENTS);
|
|
1386
1467
|
break;
|
|
1387
1468
|
case "text":
|
|
1388
|
-
if (typeof t != "string") return r(
|
|
1389
|
-
if (e.maxLength && t.length > e.maxLength) return r((t) =>
|
|
1469
|
+
if (typeof t != "string") return r(l.FIELD_STRING);
|
|
1470
|
+
if (e.maxLength && t.length > e.maxLength) return r((t) => l.FIELD_MAX_LENGTH(t, e.maxLength));
|
|
1390
1471
|
break;
|
|
1391
1472
|
case "enum":
|
|
1392
|
-
if (typeof t != "string") return r(
|
|
1393
|
-
if (e.options && !e.options.some((e) => e.value === t)) return r(
|
|
1473
|
+
if (typeof t != "string") return r(l.FIELD_STRING);
|
|
1474
|
+
if (e.options && !e.options.some((e) => e.value === t)) return r(l.FIELD_ENUM_INVALID);
|
|
1394
1475
|
break;
|
|
1395
1476
|
case "multiEnum":
|
|
1396
|
-
if (!Array.isArray(t) || t.length === 0) return r(
|
|
1397
|
-
if (t.some((e) => typeof e != "string" || e === "")) return r(
|
|
1398
|
-
if (e.options && t.some((t) => !e.options?.some((e) => e.value === t))) return r(
|
|
1477
|
+
if (!Array.isArray(t) || t.length === 0) return r(l.FIELD_ARRAY);
|
|
1478
|
+
if (t.some((e) => typeof e != "string" || e === "")) return r(l.FIELD_ARRAY_ELEMENTS);
|
|
1479
|
+
if (e.options && t.some((t) => !e.options?.some((e) => e.value === t))) return r(l.FIELD_ENUM_INVALID);
|
|
1399
1480
|
break;
|
|
1400
1481
|
case "color":
|
|
1401
|
-
if (typeof t != "string" || !/^#[0-9A-Fa-f]{6}$/.test(t)) return r(
|
|
1482
|
+
if (typeof t != "string" || !/^#[0-9A-Fa-f]{6}$/.test(t)) return r(l.FIELD_COLOR_FORMAT);
|
|
1402
1483
|
break;
|
|
1403
1484
|
case "number":
|
|
1404
|
-
if (typeof t != "number" || Number.isNaN(t)) return r(
|
|
1485
|
+
if (typeof t != "number" || Number.isNaN(t)) return r(l.FIELD_NUMBER);
|
|
1486
|
+
break;
|
|
1487
|
+
case "boolean":
|
|
1488
|
+
if (typeof t != "boolean") return r(l.FIELD_BOOLEAN);
|
|
1405
1489
|
break;
|
|
1406
1490
|
case "aspectRatio":
|
|
1407
1491
|
case "strength": break;
|
|
1408
1492
|
}
|
|
1409
1493
|
return null;
|
|
1410
1494
|
}
|
|
1411
|
-
function
|
|
1495
|
+
function L(e) {
|
|
1412
1496
|
return typeof File < "u" && e instanceof File;
|
|
1413
1497
|
}
|
|
1414
1498
|
//#endregion
|
|
1415
1499
|
//#region src/core/client.ts
|
|
1416
|
-
var
|
|
1500
|
+
var R = class {
|
|
1417
1501
|
constructor(e = {}) {
|
|
1418
1502
|
this.type = "", this.submitEndpoint = "/task/submit", this.submitEndpointMode = "prefix", this.pollEndpoint = "/task/progress", this.pollInterval = 1e3, this.maxPollAttempts = 120, this.phase = i.IDLE, this.taskId = "", this.progress = 0, this.result = null, this.error = "", this.activeTasks = /* @__PURE__ */ new Map(), this.pollTimer = null, this.isPollingBatch = !1, this.configure(e);
|
|
1419
1503
|
}
|
|
@@ -1422,7 +1506,7 @@ var L = class {
|
|
|
1422
1506
|
}
|
|
1423
1507
|
get typeDef() {
|
|
1424
1508
|
let e = this.resolvedTaskTypeKey;
|
|
1425
|
-
return e ?
|
|
1509
|
+
return e ? N(e) : void 0;
|
|
1426
1510
|
}
|
|
1427
1511
|
get taskFields() {
|
|
1428
1512
|
return this.typeDef?.fields ?? [];
|
|
@@ -1430,12 +1514,12 @@ var L = class {
|
|
|
1430
1514
|
async submit(e, t) {
|
|
1431
1515
|
let n = this.createRequestUri(e);
|
|
1432
1516
|
if (!n) {
|
|
1433
|
-
this.fail(
|
|
1517
|
+
this.fail(l.MISSING_ENDPOINT, i.IDLE);
|
|
1434
1518
|
return;
|
|
1435
1519
|
}
|
|
1436
1520
|
let r = this.getTaskFields(e);
|
|
1437
1521
|
if (r.length > 0) {
|
|
1438
|
-
let e =
|
|
1522
|
+
let e = F(t, r);
|
|
1439
1523
|
if (!e.valid) {
|
|
1440
1524
|
this.fail(e.errors.map((e) => e.message).join("; "), i.IDLE);
|
|
1441
1525
|
return;
|
|
@@ -1443,11 +1527,7 @@ var L = class {
|
|
|
1443
1527
|
}
|
|
1444
1528
|
this.phase = i.SUBMITTING, this.error = "", this.progress = 0, this.result = null;
|
|
1445
1529
|
try {
|
|
1446
|
-
let e = await this.resolveUploads(t, r), i = (await this.request(n,
|
|
1447
|
-
method: "POST",
|
|
1448
|
-
body: JSON.stringify(e),
|
|
1449
|
-
headers: { "Content-Type": "application/json" }
|
|
1450
|
-
})).data.taskId;
|
|
1530
|
+
let e = await this.resolveUploads(t, r), i = (await this.request(n, e)).data.taskId;
|
|
1451
1531
|
this.taskId = i;
|
|
1452
1532
|
let a = {
|
|
1453
1533
|
taskId: i,
|
|
@@ -1456,21 +1536,23 @@ var L = class {
|
|
|
1456
1536
|
};
|
|
1457
1537
|
this.onSubmit?.(a), await this.trackTask(i);
|
|
1458
1538
|
} catch (e) {
|
|
1459
|
-
this.fail(e instanceof Error ? e.message :
|
|
1539
|
+
this.fail(e instanceof Error ? e.message : l.SUBMIT_FAILED, this.phase);
|
|
1460
1540
|
}
|
|
1461
1541
|
}
|
|
1462
1542
|
reset() {
|
|
1463
1543
|
this.phase = i.IDLE, this.taskId = "", this.progress = 0, this.result = null, this.error = "", this.activeTasks.clear(), this.pollTimer &&= (clearTimeout(this.pollTimer), null);
|
|
1464
1544
|
}
|
|
1465
1545
|
createRequestUri(e = this.type) {
|
|
1466
|
-
|
|
1546
|
+
if (this.submitEndpointMode === "full") return this.submitEndpoint;
|
|
1547
|
+
let t = U(e), n = t ? N(t) : void 0;
|
|
1548
|
+
return n?.endpoint ? n.endpoint : e ? `${this.submitEndpoint}/${e}` : this.submitEndpoint;
|
|
1467
1549
|
}
|
|
1468
1550
|
get resolvedTaskTypeKey() {
|
|
1469
|
-
return
|
|
1551
|
+
return U(this.type);
|
|
1470
1552
|
}
|
|
1471
1553
|
getTaskFields(e) {
|
|
1472
|
-
let t =
|
|
1473
|
-
return t ?
|
|
1554
|
+
let t = U(e);
|
|
1555
|
+
return t ? N(t)?.fields ?? [] : [];
|
|
1474
1556
|
}
|
|
1475
1557
|
async resolveUploads(e, t) {
|
|
1476
1558
|
let n = t.length > 0 ? t.filter((e) => e.type === "image" || e.type === "mask" || e.type === "images") : Object.keys(e).map((e) => ({
|
|
@@ -1486,15 +1568,9 @@ var L = class {
|
|
|
1486
1568
|
return r;
|
|
1487
1569
|
}
|
|
1488
1570
|
async resolveUploadValue(e, t) {
|
|
1489
|
-
if (!
|
|
1571
|
+
if (!W(e)) return e;
|
|
1490
1572
|
if (!this.customUploadRequest) throw Error(`customUploadRequest is required to upload ${t.name}`);
|
|
1491
|
-
|
|
1492
|
-
return n.append(t.name || "file", e), B(await this.customUploadRequest({
|
|
1493
|
-
file: e,
|
|
1494
|
-
name: t.name,
|
|
1495
|
-
formData: n,
|
|
1496
|
-
field: t
|
|
1497
|
-
}));
|
|
1573
|
+
return G(await this.customUploadRequest(e));
|
|
1498
1574
|
}
|
|
1499
1575
|
trackTask(e) {
|
|
1500
1576
|
this.phase = i.POLLING;
|
|
@@ -1517,14 +1593,14 @@ var L = class {
|
|
|
1517
1593
|
this.isPollingBatch = !0;
|
|
1518
1594
|
let e = [...this.activeTasks.keys()];
|
|
1519
1595
|
try {
|
|
1520
|
-
let t = `${this.pollEndpoint}?taskIds=${e.map(encodeURIComponent).join(",")}`, n = await this.request(t
|
|
1596
|
+
let t = `${this.pollEndpoint}?taskIds=${e.map(encodeURIComponent).join(",")}`, n = await this.request(t), r = new Map(n.data.map((e) => [e.aiTaskId, e]));
|
|
1521
1597
|
e.forEach((e) => {
|
|
1522
1598
|
let t = this.activeTasks.get(e);
|
|
1523
1599
|
if (!t) return;
|
|
1524
1600
|
t.attempts += 1;
|
|
1525
1601
|
let n = r.get(e);
|
|
1526
1602
|
if (!n) {
|
|
1527
|
-
this.failTask(t,
|
|
1603
|
+
this.failTask(t, l.TASK_NOT_FOUND(e));
|
|
1528
1604
|
return;
|
|
1529
1605
|
}
|
|
1530
1606
|
this.taskId = e, this.progress = n.taskProgress;
|
|
@@ -1547,10 +1623,10 @@ var L = class {
|
|
|
1547
1623
|
this.onSuccess?.(r), this.completeTask(t);
|
|
1548
1624
|
return;
|
|
1549
1625
|
}
|
|
1550
|
-
t.attempts >= this.maxPollAttempts && this.failTask(t,
|
|
1626
|
+
t.attempts >= this.maxPollAttempts && this.failTask(t, l.POLL_TIMEOUT(e));
|
|
1551
1627
|
});
|
|
1552
1628
|
} catch (e) {
|
|
1553
|
-
let t = e instanceof Error ? e.message :
|
|
1629
|
+
let t = e instanceof Error ? e.message : l.POLL_FAILED;
|
|
1554
1630
|
[...this.activeTasks.values()].forEach((e) => this.failTask(e, t));
|
|
1555
1631
|
} finally {
|
|
1556
1632
|
this.isPollingBatch = !1, this.activeTasks.size ? (this.phase = i.POLLING, this.ensurePolling(this.pollInterval)) : this.phase === i.POLLING && (this.phase = this.error ? i.ERROR : i.SUCCESS);
|
|
@@ -1563,8 +1639,12 @@ var L = class {
|
|
|
1563
1639
|
this.activeTasks.delete(e.taskId), this.fail(t, i.POLLING, e.taskId), e.resolve();
|
|
1564
1640
|
}
|
|
1565
1641
|
async request(e, t) {
|
|
1566
|
-
let n = await
|
|
1567
|
-
|
|
1642
|
+
let n = this.customRequest ? await this.customRequest(e, t) : await fetch(e, t === void 0 ? { method: "GET" } : {
|
|
1643
|
+
method: "POST",
|
|
1644
|
+
body: JSON.stringify(t),
|
|
1645
|
+
headers: { "Content-Type": "application/json" }
|
|
1646
|
+
});
|
|
1647
|
+
return n && typeof n.json == "function" ? n.json() : z(n);
|
|
1568
1648
|
}
|
|
1569
1649
|
fail(e, t, n) {
|
|
1570
1650
|
this.phase = i.ERROR, this.error = e;
|
|
@@ -1576,17 +1656,29 @@ var L = class {
|
|
|
1576
1656
|
this.onError?.(r);
|
|
1577
1657
|
}
|
|
1578
1658
|
};
|
|
1579
|
-
function
|
|
1659
|
+
function z(e) {
|
|
1660
|
+
return H(e) && V(e.data) ? e.data : (B(e), e);
|
|
1661
|
+
}
|
|
1662
|
+
function B(e) {
|
|
1663
|
+
return H(e) && "data" in e;
|
|
1664
|
+
}
|
|
1665
|
+
function V(e) {
|
|
1666
|
+
return H(e) && "data" in e && ("code" in e || "success" in e || "msg" in e);
|
|
1667
|
+
}
|
|
1668
|
+
function H(e) {
|
|
1669
|
+
return typeof e == "object" && !!e;
|
|
1670
|
+
}
|
|
1671
|
+
function U(e) {
|
|
1580
1672
|
if (!e) return "";
|
|
1581
|
-
if (
|
|
1673
|
+
if (M[e]) return e;
|
|
1582
1674
|
let t = e.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[-\s]+/g, "_").toUpperCase();
|
|
1583
|
-
return
|
|
1675
|
+
return M[t] ? t : "";
|
|
1584
1676
|
}
|
|
1585
|
-
function
|
|
1677
|
+
function W(e) {
|
|
1586
1678
|
return typeof File < "u" && e instanceof File;
|
|
1587
1679
|
}
|
|
1588
|
-
async function
|
|
1589
|
-
return e ? typeof e == "string" ? e : e instanceof Response ?
|
|
1680
|
+
async function G(e) {
|
|
1681
|
+
return e ? typeof e == "string" ? e : e instanceof Response ? G(await e.json()) : typeof e.data == "string" ? e.data : e.data ? e.data.value || e.data.url || "" : e.value || e.url || "" : "";
|
|
1590
1682
|
}
|
|
1591
1683
|
//#endregion
|
|
1592
|
-
export {
|
|
1684
|
+
export { N as a, D as c, E as d, w as f, P as i, k as l, C as m, F as n, j as o, T as p, M as r, A as s, R as t, O as u };
|