@reela/credits 3.1.1 → 3.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/index.cjs CHANGED
@@ -1,236 +1,246 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
1
+
2
+ //#region src/prices/asset/asset-pro.ts
3
+ const assetProPrices = {
4
+ 1: 10,
5
+ 2: 13,
6
+ 3: 13,
7
+ 4: 16,
8
+ 5: 16,
9
+ 6: 19,
10
+ 7: 19,
11
+ 8: 22
9
12
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
13
+
14
+ //#endregion
15
+ //#region src/prices/asset/asset-lite.ts
16
+ const assetLitePrices = {
17
+ 1: 2,
18
+ 2: 4,
19
+ 3: 6,
20
+ 4: 8,
21
+ 5: 10,
22
+ 6: 12,
23
+ 7: 14,
24
+ 8: 16
17
25
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- calculateAssetCredits: () => calculateAssetCredits,
24
- calculateAvatarCredits: () => calculateAvatarCredits,
25
- calculateTaskCredits: () => calculateTaskCredits,
26
- estimateTaskCredits: () => estimateTaskCredits
27
- });
28
- module.exports = __toCommonJS(index_exports);
29
-
30
- // src/constants/shot-type.ts
31
- var shotType = {
32
- video: "video",
33
- image: "image"
26
+
27
+ //#endregion
28
+ //#region src/prices/asset/asset-max.ts
29
+ const assetMaxPrices = {
30
+ 1: 20,
31
+ 2: 25,
32
+ 3: 32,
33
+ 4: 38,
34
+ 5: 44,
35
+ 6: 50,
36
+ 7: 57,
37
+ 8: 63
34
38
  };
35
39
 
36
- // src/constants/tier.ts
37
- var tier = {
38
- lite: "lite",
39
- pro: "pro",
40
- max: "max",
41
- photo: "photo",
42
- ultra: "ultra"
40
+ //#endregion
41
+ //#region src/prices/asset/asset-ultra.ts
42
+ const assetUltraPrices = {
43
+ 1: 20,
44
+ 2: 25,
45
+ 3: 32,
46
+ 4: 38,
47
+ 5: 44,
48
+ 6: 50,
49
+ 7: 57,
50
+ 8: 63
43
51
  };
44
52
 
45
- // src/get-key.ts
46
- function getKey(pipeline) {
47
- const { tier: tier2 = "default", type = "default", cameraPosition = 1, visual: visual2 = [] } = pipeline;
48
- const v = Array.from(new Set(visual2));
49
- v.sort();
50
- return `${v.join("-")}-${type}-${tier2}-${cameraPosition}`;
51
- }
53
+ //#endregion
54
+ //#region src/prices/asset/asset-promax.ts
55
+ const assetPromaxPrices = {
56
+ 1: 20,
57
+ 2: 25,
58
+ 3: 32,
59
+ 4: 38,
60
+ 5: 44,
61
+ 6: 50,
62
+ 7: 57,
63
+ 8: 63
64
+ };
52
65
 
53
- // src/asset-credits.ts
54
- var IMAGE_CREDITS = 3;
55
- var creditsMap = {
56
- [getKey({ type: shotType.video, tier: tier.lite })]: {
57
- 1: 2,
58
- 2: 4,
59
- 3: 6,
60
- 4: 8,
61
- 5: 10,
62
- 6: 12,
63
- 7: 14,
64
- 8: 16
65
- },
66
- [getKey({ type: shotType.video, tier: tier.pro })]: {
67
- 1: 10,
68
- 2: 13,
69
- 3: 13,
70
- 4: 16,
71
- 5: 16,
72
- 6: 19,
73
- 7: 19,
74
- 8: 22
75
- },
76
- [getKey({ type: shotType.video, tier: tier.max })]: {
77
- 1: 20,
78
- 2: 25,
79
- 3: 32,
80
- 4: 38,
81
- 5: 44,
82
- 6: 50,
83
- 7: 57,
84
- 8: 63
85
- },
86
- [getKey({ type: shotType.video, tier: tier.ultra })]: {
87
- 1: 20,
88
- 2: 25,
89
- 3: 32,
90
- 4: 38,
91
- 5: 44,
92
- 6: 50,
93
- 7: 57,
94
- 8: 63
95
- }
66
+ //#endregion
67
+ //#region src/prices/asset/index.ts
68
+ const assetPrices = {
69
+ nano: assetLitePrices,
70
+ lite: assetLitePrices,
71
+ plus: assetProPrices,
72
+ pro: assetProPrices,
73
+ max: assetMaxPrices,
74
+ ultra: assetUltraPrices,
75
+ promax: assetPromaxPrices,
76
+ ultramax: assetUltraPrices
96
77
  };
78
+
79
+ //#endregion
80
+ //#region src/asset-credits.ts
81
+ const IMAGE_CREDITS = 3;
82
+ /**
83
+ * 计算重跑镜头的积分
84
+ * @param params object
85
+ */
97
86
  function calculateAssetCredits(params) {
98
- if (typeof params !== "object" || params === null || Array.isArray(params)) {
99
- throw new Error("Pipeline must be an object");
100
- }
101
- const duraion = Math.min(Math.ceil(params.duraion || 0), 8);
102
- let credits;
103
- switch (params.type) {
104
- case shotType.image:
105
- credits = IMAGE_CREDITS;
106
- break;
107
- case shotType.video:
108
- const m = creditsMap[getKey({ type: params.type, tier: params.tier })];
109
- if (!m) {
110
- break;
111
- }
112
- credits = m[duraion];
113
- break;
114
- default:
115
- break;
116
- }
117
- if (typeof credits === "undefined") {
118
- throw new Error(`Invalid pipeline, get pipeline ${JSON.stringify(params)}`);
119
- }
120
- return credits;
87
+ if (typeof params !== "object" || params === null || Array.isArray(params)) throw new Error("Pipeline must be an object");
88
+ const duraion = Math.min(Math.ceil(params.duraion || 0), 8);
89
+ let credits;
90
+ switch (params.type) {
91
+ case "image":
92
+ credits = IMAGE_CREDITS;
93
+ break;
94
+ case "video":
95
+ credits = assetPrices[params.tier]?.[duraion];
96
+ break;
97
+ default:
98
+ params.type;
99
+ break;
100
+ }
101
+ if (typeof credits === "undefined") throw new Error(`Invalid pipeline, get pipeline ${JSON.stringify(params)}`);
102
+ return credits;
121
103
  }
122
104
 
123
- // src/constants/visual.ts
124
- var visual = {
125
- aiv: "AIV",
126
- oiv: "OIV",
127
- aivr: "AIV_REFERENCE",
128
- aia: "AIA",
129
- aiar: "AIA_REFERENCE",
130
- ovs: "OVS",
131
- ova: "OVA_VISUAL",
132
- webv: "WEBV"
105
+ //#endregion
106
+ //#region src/prices/task/task-lite.ts
107
+ const taskLitePrices = {
108
+ OVA_VISUAL: 3,
109
+ OVS: 3,
110
+ OIV: 15,
111
+ AIV: 15,
112
+ AIV_REFERENCE: 15,
113
+ AIA: 15,
114
+ AIA_REFERENCE: 15,
115
+ WEBV: 3
116
+ };
117
+
118
+ //#endregion
119
+ //#region src/prices/task/task-max.ts
120
+ const taskMaxPrices = {
121
+ OVA_VISUAL: 3,
122
+ OVS: 3,
123
+ OIV: 100,
124
+ AIV: 100,
125
+ AIV_REFERENCE: 40,
126
+ AIA: 40,
127
+ AIA_REFERENCE: 40,
128
+ WEBV: 3
129
+ };
130
+
131
+ //#endregion
132
+ //#region src/prices/task/task-photo.ts
133
+ const taskPhotoPrices = {
134
+ OVA_VISUAL: 0,
135
+ OVS: 0,
136
+ OIV: 5,
137
+ AIV: 5,
138
+ AIV_REFERENCE: 5,
139
+ AIA: 0,
140
+ AIA_REFERENCE: 0,
141
+ WEBV: 0
142
+ };
143
+
144
+ //#endregion
145
+ //#region src/prices/task/task-pro.ts
146
+ const taskProPrices = {
147
+ OVA_VISUAL: 3,
148
+ OVS: 3,
149
+ OIV: 20,
150
+ AIV: 20,
151
+ AIV_REFERENCE: 20,
152
+ AIA: 20,
153
+ AIA_REFERENCE: 20,
154
+ WEBV: 3
155
+ };
156
+
157
+ //#endregion
158
+ //#region src/prices/task/task-ultra.ts
159
+ const taskUltraPrices = {
160
+ OVA_VISUAL: 3,
161
+ OVS: 3,
162
+ OIV: 100,
163
+ AIV: 100,
164
+ AIV_REFERENCE: 40,
165
+ AIA: 40,
166
+ AIA_REFERENCE: 40,
167
+ WEBV: 3
133
168
  };
134
169
 
135
- // src/task-credits.ts
136
- var unitCredits = {
137
- // AIV/OIV
138
- [getKey({ visual: [visual.aiv], tier: tier.photo })]: 5,
139
- [getKey({ visual: [visual.aiv], tier: tier.lite })]: 15,
140
- [getKey({ visual: [visual.aiv], tier: tier.pro })]: 20,
141
- [getKey({ visual: [visual.aiv], tier: tier.max })]: 100,
142
- [getKey({ visual: [visual.aiv], tier: tier.ultra })]: 100,
143
- // AIV_REFERENCE
144
- [getKey({ visual: [visual.aivr], tier: tier.photo })]: 5,
145
- [getKey({ visual: [visual.aivr], tier: tier.lite })]: 15,
146
- [getKey({ visual: [visual.aivr], tier: tier.pro })]: 20,
147
- [getKey({ visual: [visual.aivr], tier: tier.max })]: 40,
148
- [getKey({ visual: [visual.aivr], tier: tier.ultra })]: 40,
149
- // AIA/AIA_REFERENCE
150
- [getKey({ visual: [visual.aia], tier: tier.lite })]: 15,
151
- [getKey({ visual: [visual.aia], tier: tier.pro })]: 20,
152
- [getKey({ visual: [visual.aia], tier: tier.max })]: 40,
153
- [getKey({ visual: [visual.aia], tier: tier.ultra })]: 40,
154
- // OVS/OVA
155
- [getKey({ visual: [visual.ovs], tier: tier.lite })]: 3,
156
- [getKey({ visual: [visual.ovs], tier: tier.pro })]: 3,
157
- [getKey({ visual: [visual.ovs], tier: tier.max })]: 3,
158
- [getKey({ visual: [visual.ovs], tier: tier.ultra })]: 3,
159
- // WEBV
160
- [getKey({ visual: [visual.webv], tier: tier.lite })]: 3,
161
- [getKey({ visual: [visual.webv], tier: tier.pro })]: 3,
162
- [getKey({ visual: [visual.webv], tier: tier.max })]: 3,
163
- [getKey({ visual: [visual.webv], tier: tier.ultra })]: 3
170
+ //#endregion
171
+ //#region src/prices/task/task-promax.ts
172
+ const taskPromaxPrices = {
173
+ OVA_VISUAL: 3,
174
+ OVS: 3,
175
+ OIV: 100,
176
+ AIV: 100,
177
+ AIV_REFERENCE: 60,
178
+ AIA: 40,
179
+ AIA_REFERENCE: 40,
180
+ WEBV: 3
164
181
  };
182
+
183
+ //#endregion
184
+ //#region src/prices/task/index.ts
185
+ const taskPrices = {
186
+ photo: taskPhotoPrices,
187
+ nano: taskLitePrices,
188
+ lite: taskLitePrices,
189
+ plus: taskProPrices,
190
+ pro: taskProPrices,
191
+ max: taskMaxPrices,
192
+ promax: taskPromaxPrices,
193
+ ultra: taskUltraPrices,
194
+ ultramax: taskUltraPrices
195
+ };
196
+
197
+ //#endregion
198
+ //#region src/task-credits.ts
199
+ /**
200
+ * 计算任务实际消耗积分
201
+ * @param 时长,单位为秒
202
+ */
165
203
  function calculateTaskCredits(params) {
166
- const { durationOfShots, cameraPosition = 1, tier: tier2 } = params;
167
- if (typeof tier2 !== "string" || !tier2) {
168
- throw new Error("Tier must be a non-empty string");
169
- }
170
- if (typeof cameraPosition !== "number") {
171
- throw new Error("Camera position must be a number");
172
- }
173
- if (!Array.isArray(durationOfShots) || durationOfShots.length === 0) {
174
- throw new Error("Duration of shots must be a non-empty array");
175
- }
176
- let u = 0;
177
- for (const shot of durationOfShots) {
178
- u += getShotCredits(shot.type, tier2, shot.used, cameraPosition);
179
- }
180
- if (u === 0) {
181
- throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
182
- }
183
- return u;
204
+ const { durationOfShots, tier } = params;
205
+ if (typeof tier !== "string" || !tier) throw new Error("Tier must be a non-empty string");
206
+ if (!Array.isArray(durationOfShots) || durationOfShots.length === 0) throw new Error("Duration of shots must be a non-empty array");
207
+ let u = 0;
208
+ for (const shot of durationOfShots) u += getShotCredits(shot.type, tier, shot.used);
209
+ if (u === 0) throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
210
+ return u;
184
211
  }
212
+ /**
213
+ * 估算任务的积分
214
+ * @param 时长,单位为秒
215
+ */
185
216
  function estimateTaskCredits(params) {
186
- const { duration, visual: visual2, tier: tier2, cameraPosition = 1 } = params;
187
- if (typeof duration !== "number") {
188
- throw new Error("Duration must be a number");
189
- }
190
- if (!Array.isArray(visual2) || visual2.length === 0) {
191
- throw new Error("Visuals must be a non-empty array");
192
- }
193
- if (typeof tier2 !== "string" || !tier2) {
194
- throw new Error("Tier must be a non-empty string");
195
- }
196
- if (typeof cameraPosition !== "number") {
197
- throw new Error("Camera position must be a number");
198
- }
199
- const set = new Set(visual2);
200
- let u = 0;
201
- for (const v of set) {
202
- u += getShotCredits(v, tier2, duration, cameraPosition);
203
- }
204
- if (u === 0) {
205
- throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
206
- }
207
- return Math.floor(u / set.size);
217
+ const { duration, visual, tier } = params;
218
+ if (typeof duration !== "number") throw new Error("Duration must be a number");
219
+ if (!Array.isArray(visual) || visual.length === 0) throw new Error("Visuals must be a non-empty array");
220
+ if (typeof tier !== "string" || !tier) throw new Error("Tier must be a non-empty string");
221
+ const set = new Set(visual);
222
+ let u = 0;
223
+ for (const v of set) u += getShotCredits(v, tier, duration);
224
+ if (u === 0) throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
225
+ return Math.floor(u / set.size);
208
226
  }
209
- function getShotCredits(visualType, tier2, duration, cameraPosition = 1) {
210
- if (visualType === visual.ova) {
211
- visualType = visual.ovs;
212
- }
213
- if (visualType === visual.oiv) {
214
- visualType = visual.aiv;
215
- }
216
- if (visualType === visual.aiar) {
217
- visualType = visual.aia;
218
- }
219
- if (visualType === visual.aia) {
220
- return duration * (unitCredits[getKey({ visual: [visualType], tier: tier2 })] || 0) * (Number(cameraPosition) || 1);
221
- } else {
222
- return duration * (unitCredits[getKey({ visual: [visualType], tier: tier2 })] || 0);
223
- }
227
+ function getShotCredits(visual, tier, duration) {
228
+ const unitCredits = taskPrices[tier]?.[visual];
229
+ if (!unitCredits) throw new Error(`Invalid tier or visual, get tier ${tier} and visual ${visual}`);
230
+ return duration * unitCredits;
224
231
  }
225
232
 
226
- // src/avatar-credits.ts
233
+ //#endregion
234
+ //#region src/avatar-credits.ts
235
+ /**
236
+ * 计算制作Avatar的积分,固定为400积分。
237
+ */
227
238
  function calculateAvatarCredits() {
228
- return 200;
239
+ return 200;
229
240
  }
230
- // Annotate the CommonJS export names for ESM import in node:
231
- 0 && (module.exports = {
232
- calculateAssetCredits,
233
- calculateAvatarCredits,
234
- calculateTaskCredits,
235
- estimateTaskCredits
236
- });
241
+
242
+ //#endregion
243
+ exports.calculateAssetCredits = calculateAssetCredits;
244
+ exports.calculateAvatarCredits = calculateAvatarCredits;
245
+ exports.calculateTaskCredits = calculateTaskCredits;
246
+ exports.estimateTaskCredits = estimateTaskCredits;
package/index.d.cts CHANGED
@@ -1,26 +1,38 @@
1
+ //#region src/types/shot-type.d.ts
2
+ type ShotType = 'video' | 'image';
3
+ //#endregion
4
+ //#region ../constants/src/pipeline-tier.d.ts
5
+ declare const PIPELINE_TIER: readonly ["photo", "nano", "lite", "plus", "pro", "max", "promax", "ultra", "ultramax", "cinematic", "master", "studio"];
6
+ type PipelineTier = (typeof PIPELINE_TIER)[number];
7
+ //#endregion
8
+ //#region src/asset-credits.d.ts
1
9
  declare function calculateAssetCredits(params: {
2
- type: string;
3
- tier: string;
4
- duraion?: number;
10
+ type: ShotType;
11
+ tier: PipelineTier;
12
+ duraion?: number;
5
13
  }): number;
6
-
14
+ //#endregion
15
+ //#region ../constants/src/pipeline-visual.d.ts
16
+ declare const PIPELINE_VISUAL: readonly ["OVA_VISUAL", "OVS", "OIV", "AIV", "AIV_REFERENCE", "AIA", "AIA_REFERENCE", "WEBV"];
17
+ type PipelineVisual = (typeof PIPELINE_VISUAL)[number];
18
+ //#endregion
19
+ //#region src/task-credits.d.ts
7
20
  interface CalculateTaskCreditsParams {
8
- durationOfShots: Array<{
9
- type: string;
10
- used: number;
11
- }>;
12
- cameraPosition?: number;
13
- tier: string;
21
+ durationOfShots: Array<{
22
+ type: PipelineVisual;
23
+ used: number;
24
+ }>;
25
+ tier: PipelineTier;
14
26
  }
15
27
  declare function calculateTaskCredits(params: CalculateTaskCreditsParams): number;
16
28
  interface EstimateTaskCreditsParams {
17
- duration: number;
18
- visual: string[];
19
- tier: string;
20
- cameraPosition?: number;
29
+ duration: number;
30
+ visual: PipelineVisual[];
31
+ tier: PipelineTier;
21
32
  }
22
33
  declare function estimateTaskCredits(params: EstimateTaskCreditsParams): number;
23
-
34
+ //#endregion
35
+ //#region src/avatar-credits.d.ts
24
36
  declare function calculateAvatarCredits(): number;
25
-
26
- export { type CalculateTaskCreditsParams, type EstimateTaskCreditsParams, calculateAssetCredits, calculateAvatarCredits, calculateTaskCredits, estimateTaskCredits };
37
+ //#endregion
38
+ export { CalculateTaskCreditsParams, EstimateTaskCreditsParams, calculateAssetCredits, calculateAvatarCredits, calculateTaskCredits, estimateTaskCredits };
package/index.d.mts ADDED
@@ -0,0 +1,38 @@
1
+ //#region src/types/shot-type.d.ts
2
+ type ShotType = 'video' | 'image';
3
+ //#endregion
4
+ //#region ../constants/src/pipeline-tier.d.ts
5
+ declare const PIPELINE_TIER: readonly ["photo", "nano", "lite", "plus", "pro", "max", "promax", "ultra", "ultramax", "cinematic", "master", "studio"];
6
+ type PipelineTier = (typeof PIPELINE_TIER)[number];
7
+ //#endregion
8
+ //#region src/asset-credits.d.ts
9
+ declare function calculateAssetCredits(params: {
10
+ type: ShotType;
11
+ tier: PipelineTier;
12
+ duraion?: number;
13
+ }): number;
14
+ //#endregion
15
+ //#region ../constants/src/pipeline-visual.d.ts
16
+ declare const PIPELINE_VISUAL: readonly ["OVA_VISUAL", "OVS", "OIV", "AIV", "AIV_REFERENCE", "AIA", "AIA_REFERENCE", "WEBV"];
17
+ type PipelineVisual = (typeof PIPELINE_VISUAL)[number];
18
+ //#endregion
19
+ //#region src/task-credits.d.ts
20
+ interface CalculateTaskCreditsParams {
21
+ durationOfShots: Array<{
22
+ type: PipelineVisual;
23
+ used: number;
24
+ }>;
25
+ tier: PipelineTier;
26
+ }
27
+ declare function calculateTaskCredits(params: CalculateTaskCreditsParams): number;
28
+ interface EstimateTaskCreditsParams {
29
+ duration: number;
30
+ visual: PipelineVisual[];
31
+ tier: PipelineTier;
32
+ }
33
+ declare function estimateTaskCredits(params: EstimateTaskCreditsParams): number;
34
+ //#endregion
35
+ //#region src/avatar-credits.d.ts
36
+ declare function calculateAvatarCredits(): number;
37
+ //#endregion
38
+ export { CalculateTaskCreditsParams, EstimateTaskCreditsParams, calculateAssetCredits, calculateAvatarCredits, calculateTaskCredits, estimateTaskCredits };
package/index.mjs ADDED
@@ -0,0 +1,242 @@
1
+ //#region src/prices/asset/asset-pro.ts
2
+ const assetProPrices = {
3
+ 1: 10,
4
+ 2: 13,
5
+ 3: 13,
6
+ 4: 16,
7
+ 5: 16,
8
+ 6: 19,
9
+ 7: 19,
10
+ 8: 22
11
+ };
12
+
13
+ //#endregion
14
+ //#region src/prices/asset/asset-lite.ts
15
+ const assetLitePrices = {
16
+ 1: 2,
17
+ 2: 4,
18
+ 3: 6,
19
+ 4: 8,
20
+ 5: 10,
21
+ 6: 12,
22
+ 7: 14,
23
+ 8: 16
24
+ };
25
+
26
+ //#endregion
27
+ //#region src/prices/asset/asset-max.ts
28
+ const assetMaxPrices = {
29
+ 1: 20,
30
+ 2: 25,
31
+ 3: 32,
32
+ 4: 38,
33
+ 5: 44,
34
+ 6: 50,
35
+ 7: 57,
36
+ 8: 63
37
+ };
38
+
39
+ //#endregion
40
+ //#region src/prices/asset/asset-ultra.ts
41
+ const assetUltraPrices = {
42
+ 1: 20,
43
+ 2: 25,
44
+ 3: 32,
45
+ 4: 38,
46
+ 5: 44,
47
+ 6: 50,
48
+ 7: 57,
49
+ 8: 63
50
+ };
51
+
52
+ //#endregion
53
+ //#region src/prices/asset/asset-promax.ts
54
+ const assetPromaxPrices = {
55
+ 1: 20,
56
+ 2: 25,
57
+ 3: 32,
58
+ 4: 38,
59
+ 5: 44,
60
+ 6: 50,
61
+ 7: 57,
62
+ 8: 63
63
+ };
64
+
65
+ //#endregion
66
+ //#region src/prices/asset/index.ts
67
+ const assetPrices = {
68
+ nano: assetLitePrices,
69
+ lite: assetLitePrices,
70
+ plus: assetProPrices,
71
+ pro: assetProPrices,
72
+ max: assetMaxPrices,
73
+ ultra: assetUltraPrices,
74
+ promax: assetPromaxPrices,
75
+ ultramax: assetUltraPrices
76
+ };
77
+
78
+ //#endregion
79
+ //#region src/asset-credits.ts
80
+ const IMAGE_CREDITS = 3;
81
+ /**
82
+ * 计算重跑镜头的积分
83
+ * @param params object
84
+ */
85
+ function calculateAssetCredits(params) {
86
+ if (typeof params !== "object" || params === null || Array.isArray(params)) throw new Error("Pipeline must be an object");
87
+ const duraion = Math.min(Math.ceil(params.duraion || 0), 8);
88
+ let credits;
89
+ switch (params.type) {
90
+ case "image":
91
+ credits = IMAGE_CREDITS;
92
+ break;
93
+ case "video":
94
+ credits = assetPrices[params.tier]?.[duraion];
95
+ break;
96
+ default:
97
+ params.type;
98
+ break;
99
+ }
100
+ if (typeof credits === "undefined") throw new Error(`Invalid pipeline, get pipeline ${JSON.stringify(params)}`);
101
+ return credits;
102
+ }
103
+
104
+ //#endregion
105
+ //#region src/prices/task/task-lite.ts
106
+ const taskLitePrices = {
107
+ OVA_VISUAL: 3,
108
+ OVS: 3,
109
+ OIV: 15,
110
+ AIV: 15,
111
+ AIV_REFERENCE: 15,
112
+ AIA: 15,
113
+ AIA_REFERENCE: 15,
114
+ WEBV: 3
115
+ };
116
+
117
+ //#endregion
118
+ //#region src/prices/task/task-max.ts
119
+ const taskMaxPrices = {
120
+ OVA_VISUAL: 3,
121
+ OVS: 3,
122
+ OIV: 100,
123
+ AIV: 100,
124
+ AIV_REFERENCE: 40,
125
+ AIA: 40,
126
+ AIA_REFERENCE: 40,
127
+ WEBV: 3
128
+ };
129
+
130
+ //#endregion
131
+ //#region src/prices/task/task-photo.ts
132
+ const taskPhotoPrices = {
133
+ OVA_VISUAL: 0,
134
+ OVS: 0,
135
+ OIV: 5,
136
+ AIV: 5,
137
+ AIV_REFERENCE: 5,
138
+ AIA: 0,
139
+ AIA_REFERENCE: 0,
140
+ WEBV: 0
141
+ };
142
+
143
+ //#endregion
144
+ //#region src/prices/task/task-pro.ts
145
+ const taskProPrices = {
146
+ OVA_VISUAL: 3,
147
+ OVS: 3,
148
+ OIV: 20,
149
+ AIV: 20,
150
+ AIV_REFERENCE: 20,
151
+ AIA: 20,
152
+ AIA_REFERENCE: 20,
153
+ WEBV: 3
154
+ };
155
+
156
+ //#endregion
157
+ //#region src/prices/task/task-ultra.ts
158
+ const taskUltraPrices = {
159
+ OVA_VISUAL: 3,
160
+ OVS: 3,
161
+ OIV: 100,
162
+ AIV: 100,
163
+ AIV_REFERENCE: 40,
164
+ AIA: 40,
165
+ AIA_REFERENCE: 40,
166
+ WEBV: 3
167
+ };
168
+
169
+ //#endregion
170
+ //#region src/prices/task/task-promax.ts
171
+ const taskPromaxPrices = {
172
+ OVA_VISUAL: 3,
173
+ OVS: 3,
174
+ OIV: 100,
175
+ AIV: 100,
176
+ AIV_REFERENCE: 60,
177
+ AIA: 40,
178
+ AIA_REFERENCE: 40,
179
+ WEBV: 3
180
+ };
181
+
182
+ //#endregion
183
+ //#region src/prices/task/index.ts
184
+ const taskPrices = {
185
+ photo: taskPhotoPrices,
186
+ nano: taskLitePrices,
187
+ lite: taskLitePrices,
188
+ plus: taskProPrices,
189
+ pro: taskProPrices,
190
+ max: taskMaxPrices,
191
+ promax: taskPromaxPrices,
192
+ ultra: taskUltraPrices,
193
+ ultramax: taskUltraPrices
194
+ };
195
+
196
+ //#endregion
197
+ //#region src/task-credits.ts
198
+ /**
199
+ * 计算任务实际消耗积分
200
+ * @param 时长,单位为秒
201
+ */
202
+ function calculateTaskCredits(params) {
203
+ const { durationOfShots, tier } = params;
204
+ if (typeof tier !== "string" || !tier) throw new Error("Tier must be a non-empty string");
205
+ if (!Array.isArray(durationOfShots) || durationOfShots.length === 0) throw new Error("Duration of shots must be a non-empty array");
206
+ let u = 0;
207
+ for (const shot of durationOfShots) u += getShotCredits(shot.type, tier, shot.used);
208
+ if (u === 0) throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
209
+ return u;
210
+ }
211
+ /**
212
+ * 估算任务的积分
213
+ * @param 时长,单位为秒
214
+ */
215
+ function estimateTaskCredits(params) {
216
+ const { duration, visual, tier } = params;
217
+ if (typeof duration !== "number") throw new Error("Duration must be a number");
218
+ if (!Array.isArray(visual) || visual.length === 0) throw new Error("Visuals must be a non-empty array");
219
+ if (typeof tier !== "string" || !tier) throw new Error("Tier must be a non-empty string");
220
+ const set = new Set(visual);
221
+ let u = 0;
222
+ for (const v of set) u += getShotCredits(v, tier, duration);
223
+ if (u === 0) throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
224
+ return Math.floor(u / set.size);
225
+ }
226
+ function getShotCredits(visual, tier, duration) {
227
+ const unitCredits = taskPrices[tier]?.[visual];
228
+ if (!unitCredits) throw new Error(`Invalid tier or visual, get tier ${tier} and visual ${visual}`);
229
+ return duration * unitCredits;
230
+ }
231
+
232
+ //#endregion
233
+ //#region src/avatar-credits.ts
234
+ /**
235
+ * 计算制作Avatar的积分,固定为400积分。
236
+ */
237
+ function calculateAvatarCredits() {
238
+ return 200;
239
+ }
240
+
241
+ //#endregion
242
+ export { calculateAssetCredits, calculateAvatarCredits, calculateTaskCredits, estimateTaskCredits };
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@reela/credits",
3
- "version": "3.1.1",
4
- "main": "index.js",
5
- "types": "./index.d.ts",
3
+ "version": "3.2.0",
4
+ "main": "index.cjs",
5
+ "module": "index.mjs",
6
+ "types": "index.d.mts",
6
7
  "exports": {
7
8
  ".": {
8
- "import": "./index.js",
9
+ "import": "./index.mjs",
9
10
  "require": "./index.cjs",
10
- "types": "./index.d.ts"
11
+ "types": "./index.d.mts"
11
12
  }
12
13
  },
13
14
  "dependencies": {}
package/index.d.ts DELETED
@@ -1,26 +0,0 @@
1
- declare function calculateAssetCredits(params: {
2
- type: string;
3
- tier: string;
4
- duraion?: number;
5
- }): number;
6
-
7
- interface CalculateTaskCreditsParams {
8
- durationOfShots: Array<{
9
- type: string;
10
- used: number;
11
- }>;
12
- cameraPosition?: number;
13
- tier: string;
14
- }
15
- declare function calculateTaskCredits(params: CalculateTaskCreditsParams): number;
16
- interface EstimateTaskCreditsParams {
17
- duration: number;
18
- visual: string[];
19
- tier: string;
20
- cameraPosition?: number;
21
- }
22
- declare function estimateTaskCredits(params: EstimateTaskCreditsParams): number;
23
-
24
- declare function calculateAvatarCredits(): number;
25
-
26
- export { type CalculateTaskCreditsParams, type EstimateTaskCreditsParams, calculateAssetCredits, calculateAvatarCredits, calculateTaskCredits, estimateTaskCredits };
package/index.js DELETED
@@ -1,206 +0,0 @@
1
- // src/constants/shot-type.ts
2
- var shotType = {
3
- video: "video",
4
- image: "image"
5
- };
6
-
7
- // src/constants/tier.ts
8
- var tier = {
9
- lite: "lite",
10
- pro: "pro",
11
- max: "max",
12
- photo: "photo",
13
- ultra: "ultra"
14
- };
15
-
16
- // src/get-key.ts
17
- function getKey(pipeline) {
18
- const { tier: tier2 = "default", type = "default", cameraPosition = 1, visual: visual2 = [] } = pipeline;
19
- const v = Array.from(new Set(visual2));
20
- v.sort();
21
- return `${v.join("-")}-${type}-${tier2}-${cameraPosition}`;
22
- }
23
-
24
- // src/asset-credits.ts
25
- var IMAGE_CREDITS = 3;
26
- var creditsMap = {
27
- [getKey({ type: shotType.video, tier: tier.lite })]: {
28
- 1: 2,
29
- 2: 4,
30
- 3: 6,
31
- 4: 8,
32
- 5: 10,
33
- 6: 12,
34
- 7: 14,
35
- 8: 16
36
- },
37
- [getKey({ type: shotType.video, tier: tier.pro })]: {
38
- 1: 10,
39
- 2: 13,
40
- 3: 13,
41
- 4: 16,
42
- 5: 16,
43
- 6: 19,
44
- 7: 19,
45
- 8: 22
46
- },
47
- [getKey({ type: shotType.video, tier: tier.max })]: {
48
- 1: 20,
49
- 2: 25,
50
- 3: 32,
51
- 4: 38,
52
- 5: 44,
53
- 6: 50,
54
- 7: 57,
55
- 8: 63
56
- },
57
- [getKey({ type: shotType.video, tier: tier.ultra })]: {
58
- 1: 20,
59
- 2: 25,
60
- 3: 32,
61
- 4: 38,
62
- 5: 44,
63
- 6: 50,
64
- 7: 57,
65
- 8: 63
66
- }
67
- };
68
- function calculateAssetCredits(params) {
69
- if (typeof params !== "object" || params === null || Array.isArray(params)) {
70
- throw new Error("Pipeline must be an object");
71
- }
72
- const duraion = Math.min(Math.ceil(params.duraion || 0), 8);
73
- let credits;
74
- switch (params.type) {
75
- case shotType.image:
76
- credits = IMAGE_CREDITS;
77
- break;
78
- case shotType.video:
79
- const m = creditsMap[getKey({ type: params.type, tier: params.tier })];
80
- if (!m) {
81
- break;
82
- }
83
- credits = m[duraion];
84
- break;
85
- default:
86
- break;
87
- }
88
- if (typeof credits === "undefined") {
89
- throw new Error(`Invalid pipeline, get pipeline ${JSON.stringify(params)}`);
90
- }
91
- return credits;
92
- }
93
-
94
- // src/constants/visual.ts
95
- var visual = {
96
- aiv: "AIV",
97
- oiv: "OIV",
98
- aivr: "AIV_REFERENCE",
99
- aia: "AIA",
100
- aiar: "AIA_REFERENCE",
101
- ovs: "OVS",
102
- ova: "OVA_VISUAL",
103
- webv: "WEBV"
104
- };
105
-
106
- // src/task-credits.ts
107
- var unitCredits = {
108
- // AIV/OIV
109
- [getKey({ visual: [visual.aiv], tier: tier.photo })]: 5,
110
- [getKey({ visual: [visual.aiv], tier: tier.lite })]: 15,
111
- [getKey({ visual: [visual.aiv], tier: tier.pro })]: 20,
112
- [getKey({ visual: [visual.aiv], tier: tier.max })]: 100,
113
- [getKey({ visual: [visual.aiv], tier: tier.ultra })]: 100,
114
- // AIV_REFERENCE
115
- [getKey({ visual: [visual.aivr], tier: tier.photo })]: 5,
116
- [getKey({ visual: [visual.aivr], tier: tier.lite })]: 15,
117
- [getKey({ visual: [visual.aivr], tier: tier.pro })]: 20,
118
- [getKey({ visual: [visual.aivr], tier: tier.max })]: 40,
119
- [getKey({ visual: [visual.aivr], tier: tier.ultra })]: 40,
120
- // AIA/AIA_REFERENCE
121
- [getKey({ visual: [visual.aia], tier: tier.lite })]: 15,
122
- [getKey({ visual: [visual.aia], tier: tier.pro })]: 20,
123
- [getKey({ visual: [visual.aia], tier: tier.max })]: 40,
124
- [getKey({ visual: [visual.aia], tier: tier.ultra })]: 40,
125
- // OVS/OVA
126
- [getKey({ visual: [visual.ovs], tier: tier.lite })]: 3,
127
- [getKey({ visual: [visual.ovs], tier: tier.pro })]: 3,
128
- [getKey({ visual: [visual.ovs], tier: tier.max })]: 3,
129
- [getKey({ visual: [visual.ovs], tier: tier.ultra })]: 3,
130
- // WEBV
131
- [getKey({ visual: [visual.webv], tier: tier.lite })]: 3,
132
- [getKey({ visual: [visual.webv], tier: tier.pro })]: 3,
133
- [getKey({ visual: [visual.webv], tier: tier.max })]: 3,
134
- [getKey({ visual: [visual.webv], tier: tier.ultra })]: 3
135
- };
136
- function calculateTaskCredits(params) {
137
- const { durationOfShots, cameraPosition = 1, tier: tier2 } = params;
138
- if (typeof tier2 !== "string" || !tier2) {
139
- throw new Error("Tier must be a non-empty string");
140
- }
141
- if (typeof cameraPosition !== "number") {
142
- throw new Error("Camera position must be a number");
143
- }
144
- if (!Array.isArray(durationOfShots) || durationOfShots.length === 0) {
145
- throw new Error("Duration of shots must be a non-empty array");
146
- }
147
- let u = 0;
148
- for (const shot of durationOfShots) {
149
- u += getShotCredits(shot.type, tier2, shot.used, cameraPosition);
150
- }
151
- if (u === 0) {
152
- throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
153
- }
154
- return u;
155
- }
156
- function estimateTaskCredits(params) {
157
- const { duration, visual: visual2, tier: tier2, cameraPosition = 1 } = params;
158
- if (typeof duration !== "number") {
159
- throw new Error("Duration must be a number");
160
- }
161
- if (!Array.isArray(visual2) || visual2.length === 0) {
162
- throw new Error("Visuals must be a non-empty array");
163
- }
164
- if (typeof tier2 !== "string" || !tier2) {
165
- throw new Error("Tier must be a non-empty string");
166
- }
167
- if (typeof cameraPosition !== "number") {
168
- throw new Error("Camera position must be a number");
169
- }
170
- const set = new Set(visual2);
171
- let u = 0;
172
- for (const v of set) {
173
- u += getShotCredits(v, tier2, duration, cameraPosition);
174
- }
175
- if (u === 0) {
176
- throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
177
- }
178
- return Math.floor(u / set.size);
179
- }
180
- function getShotCredits(visualType, tier2, duration, cameraPosition = 1) {
181
- if (visualType === visual.ova) {
182
- visualType = visual.ovs;
183
- }
184
- if (visualType === visual.oiv) {
185
- visualType = visual.aiv;
186
- }
187
- if (visualType === visual.aiar) {
188
- visualType = visual.aia;
189
- }
190
- if (visualType === visual.aia) {
191
- return duration * (unitCredits[getKey({ visual: [visualType], tier: tier2 })] || 0) * (Number(cameraPosition) || 1);
192
- } else {
193
- return duration * (unitCredits[getKey({ visual: [visualType], tier: tier2 })] || 0);
194
- }
195
- }
196
-
197
- // src/avatar-credits.ts
198
- function calculateAvatarCredits() {
199
- return 200;
200
- }
201
- export {
202
- calculateAssetCredits,
203
- calculateAvatarCredits,
204
- calculateTaskCredits,
205
- estimateTaskCredits
206
- };