@reela/credits 3.1.1 → 3.2.1

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,252 @@
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,
77
+ cinematic: assetUltraPrices,
78
+ master: assetUltraPrices,
79
+ studio: assetUltraPrices
96
80
  };
81
+
82
+ //#endregion
83
+ //#region src/asset-credits.ts
84
+ const IMAGE_CREDITS = 3;
85
+ /**
86
+ * 计算重跑镜头的积分
87
+ * @param params object
88
+ */
97
89
  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;
90
+ if (typeof params !== "object" || params === null || Array.isArray(params)) throw new Error("Pipeline must be an object");
91
+ const duraion = Math.min(Math.ceil(params.duraion || 0), 8);
92
+ let credits;
93
+ switch (params.type) {
94
+ case "image":
95
+ credits = IMAGE_CREDITS;
96
+ break;
97
+ case "video":
98
+ credits = assetPrices[params.tier]?.[duraion];
99
+ break;
100
+ default:
101
+ params.type;
102
+ break;
103
+ }
104
+ if (typeof credits === "undefined") throw new Error(`Invalid pipeline, get pipeline ${JSON.stringify(params)}`);
105
+ return credits;
121
106
  }
122
107
 
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"
108
+ //#endregion
109
+ //#region src/prices/task/task-lite.ts
110
+ const taskLitePrices = {
111
+ OVA_VISUAL: 3,
112
+ OVS: 3,
113
+ OIV: 15,
114
+ AIV: 15,
115
+ AIV_REFERENCE: 15,
116
+ AIA: 15,
117
+ AIA_REFERENCE: 15,
118
+ WEBV: 3
119
+ };
120
+
121
+ //#endregion
122
+ //#region src/prices/task/task-max.ts
123
+ const taskMaxPrices = {
124
+ OVA_VISUAL: 3,
125
+ OVS: 3,
126
+ OIV: 100,
127
+ AIV: 100,
128
+ AIV_REFERENCE: 40,
129
+ AIA: 40,
130
+ AIA_REFERENCE: 40,
131
+ WEBV: 3
132
+ };
133
+
134
+ //#endregion
135
+ //#region src/prices/task/task-photo.ts
136
+ const taskPhotoPrices = {
137
+ OVA_VISUAL: 0,
138
+ OVS: 0,
139
+ OIV: 5,
140
+ AIV: 5,
141
+ AIV_REFERENCE: 5,
142
+ AIA: 0,
143
+ AIA_REFERENCE: 0,
144
+ WEBV: 0
145
+ };
146
+
147
+ //#endregion
148
+ //#region src/prices/task/task-pro.ts
149
+ const taskProPrices = {
150
+ OVA_VISUAL: 3,
151
+ OVS: 3,
152
+ OIV: 20,
153
+ AIV: 20,
154
+ AIV_REFERENCE: 20,
155
+ AIA: 20,
156
+ AIA_REFERENCE: 20,
157
+ WEBV: 3
158
+ };
159
+
160
+ //#endregion
161
+ //#region src/prices/task/task-ultra.ts
162
+ const taskUltraPrices = {
163
+ OVA_VISUAL: 3,
164
+ OVS: 3,
165
+ OIV: 100,
166
+ AIV: 100,
167
+ AIV_REFERENCE: 40,
168
+ AIA: 40,
169
+ AIA_REFERENCE: 40,
170
+ WEBV: 3
133
171
  };
134
172
 
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
173
+ //#endregion
174
+ //#region src/prices/task/task-promax.ts
175
+ const taskPromaxPrices = {
176
+ OVA_VISUAL: 3,
177
+ OVS: 3,
178
+ OIV: 100,
179
+ AIV: 100,
180
+ AIV_REFERENCE: 60,
181
+ AIA: 40,
182
+ AIA_REFERENCE: 40,
183
+ WEBV: 3
164
184
  };
185
+
186
+ //#endregion
187
+ //#region src/prices/task/index.ts
188
+ const taskPrices = {
189
+ photo: taskPhotoPrices,
190
+ nano: taskLitePrices,
191
+ lite: taskLitePrices,
192
+ plus: taskProPrices,
193
+ pro: taskProPrices,
194
+ max: taskMaxPrices,
195
+ promax: taskPromaxPrices,
196
+ ultra: taskUltraPrices,
197
+ ultramax: taskUltraPrices,
198
+ cinematic: taskUltraPrices,
199
+ master: taskUltraPrices,
200
+ studio: taskUltraPrices
201
+ };
202
+
203
+ //#endregion
204
+ //#region src/task-credits.ts
205
+ /**
206
+ * 计算任务实际消耗积分
207
+ * @param 时长,单位为秒
208
+ */
165
209
  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;
210
+ const { durationOfShots, tier } = params;
211
+ if (typeof tier !== "string" || !tier) throw new Error("Tier must be a non-empty string");
212
+ if (!Array.isArray(durationOfShots) || durationOfShots.length === 0) throw new Error("Duration of shots must be a non-empty array");
213
+ let u = 0;
214
+ for (const shot of durationOfShots) u += getShotCredits(shot.type, tier, shot.used);
215
+ if (u === 0) throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
216
+ return u;
184
217
  }
218
+ /**
219
+ * 估算任务的积分
220
+ * @param 时长,单位为秒
221
+ */
185
222
  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);
223
+ const { duration, visual, tier } = params;
224
+ if (typeof duration !== "number") throw new Error("Duration must be a number");
225
+ if (!Array.isArray(visual) || visual.length === 0) throw new Error("Visuals must be a non-empty array");
226
+ if (typeof tier !== "string" || !tier) throw new Error("Tier must be a non-empty string");
227
+ const set = new Set(visual);
228
+ let u = 0;
229
+ for (const v of set) u += getShotCredits(v, tier, duration);
230
+ if (u === 0) throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
231
+ return Math.floor(u / set.size);
208
232
  }
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
- }
233
+ function getShotCredits(visual, tier, duration) {
234
+ const unitCredits = taskPrices[tier]?.[visual];
235
+ if (!unitCredits) throw new Error(`Invalid tier or visual, get tier ${tier} and visual ${visual}`);
236
+ return duration * unitCredits;
224
237
  }
225
238
 
226
- // src/avatar-credits.ts
239
+ //#endregion
240
+ //#region src/avatar-credits.ts
241
+ /**
242
+ * 计算制作Avatar的积分,固定为400积分。
243
+ */
227
244
  function calculateAvatarCredits() {
228
- return 200;
245
+ return 200;
229
246
  }
230
- // Annotate the CommonJS export names for ESM import in node:
231
- 0 && (module.exports = {
232
- calculateAssetCredits,
233
- calculateAvatarCredits,
234
- calculateTaskCredits,
235
- estimateTaskCredits
236
- });
247
+
248
+ //#endregion
249
+ exports.calculateAssetCredits = calculateAssetCredits;
250
+ exports.calculateAvatarCredits = calculateAvatarCredits;
251
+ exports.calculateTaskCredits = calculateTaskCredits;
252
+ 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,248 @@
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
+ cinematic: assetUltraPrices,
77
+ master: assetUltraPrices,
78
+ studio: assetUltraPrices
79
+ };
80
+
81
+ //#endregion
82
+ //#region src/asset-credits.ts
83
+ const IMAGE_CREDITS = 3;
84
+ /**
85
+ * 计算重跑镜头的积分
86
+ * @param params object
87
+ */
88
+ function calculateAssetCredits(params) {
89
+ if (typeof params !== "object" || params === null || Array.isArray(params)) throw new Error("Pipeline must be an object");
90
+ const duraion = Math.min(Math.ceil(params.duraion || 0), 8);
91
+ let credits;
92
+ switch (params.type) {
93
+ case "image":
94
+ credits = IMAGE_CREDITS;
95
+ break;
96
+ case "video":
97
+ credits = assetPrices[params.tier]?.[duraion];
98
+ break;
99
+ default:
100
+ params.type;
101
+ break;
102
+ }
103
+ if (typeof credits === "undefined") throw new Error(`Invalid pipeline, get pipeline ${JSON.stringify(params)}`);
104
+ return credits;
105
+ }
106
+
107
+ //#endregion
108
+ //#region src/prices/task/task-lite.ts
109
+ const taskLitePrices = {
110
+ OVA_VISUAL: 3,
111
+ OVS: 3,
112
+ OIV: 15,
113
+ AIV: 15,
114
+ AIV_REFERENCE: 15,
115
+ AIA: 15,
116
+ AIA_REFERENCE: 15,
117
+ WEBV: 3
118
+ };
119
+
120
+ //#endregion
121
+ //#region src/prices/task/task-max.ts
122
+ const taskMaxPrices = {
123
+ OVA_VISUAL: 3,
124
+ OVS: 3,
125
+ OIV: 100,
126
+ AIV: 100,
127
+ AIV_REFERENCE: 40,
128
+ AIA: 40,
129
+ AIA_REFERENCE: 40,
130
+ WEBV: 3
131
+ };
132
+
133
+ //#endregion
134
+ //#region src/prices/task/task-photo.ts
135
+ const taskPhotoPrices = {
136
+ OVA_VISUAL: 0,
137
+ OVS: 0,
138
+ OIV: 5,
139
+ AIV: 5,
140
+ AIV_REFERENCE: 5,
141
+ AIA: 0,
142
+ AIA_REFERENCE: 0,
143
+ WEBV: 0
144
+ };
145
+
146
+ //#endregion
147
+ //#region src/prices/task/task-pro.ts
148
+ const taskProPrices = {
149
+ OVA_VISUAL: 3,
150
+ OVS: 3,
151
+ OIV: 20,
152
+ AIV: 20,
153
+ AIV_REFERENCE: 20,
154
+ AIA: 20,
155
+ AIA_REFERENCE: 20,
156
+ WEBV: 3
157
+ };
158
+
159
+ //#endregion
160
+ //#region src/prices/task/task-ultra.ts
161
+ const taskUltraPrices = {
162
+ OVA_VISUAL: 3,
163
+ OVS: 3,
164
+ OIV: 100,
165
+ AIV: 100,
166
+ AIV_REFERENCE: 40,
167
+ AIA: 40,
168
+ AIA_REFERENCE: 40,
169
+ WEBV: 3
170
+ };
171
+
172
+ //#endregion
173
+ //#region src/prices/task/task-promax.ts
174
+ const taskPromaxPrices = {
175
+ OVA_VISUAL: 3,
176
+ OVS: 3,
177
+ OIV: 100,
178
+ AIV: 100,
179
+ AIV_REFERENCE: 60,
180
+ AIA: 40,
181
+ AIA_REFERENCE: 40,
182
+ WEBV: 3
183
+ };
184
+
185
+ //#endregion
186
+ //#region src/prices/task/index.ts
187
+ const taskPrices = {
188
+ photo: taskPhotoPrices,
189
+ nano: taskLitePrices,
190
+ lite: taskLitePrices,
191
+ plus: taskProPrices,
192
+ pro: taskProPrices,
193
+ max: taskMaxPrices,
194
+ promax: taskPromaxPrices,
195
+ ultra: taskUltraPrices,
196
+ ultramax: taskUltraPrices,
197
+ cinematic: taskUltraPrices,
198
+ master: taskUltraPrices,
199
+ studio: taskUltraPrices
200
+ };
201
+
202
+ //#endregion
203
+ //#region src/task-credits.ts
204
+ /**
205
+ * 计算任务实际消耗积分
206
+ * @param 时长,单位为秒
207
+ */
208
+ function calculateTaskCredits(params) {
209
+ const { durationOfShots, tier } = params;
210
+ if (typeof tier !== "string" || !tier) throw new Error("Tier must be a non-empty string");
211
+ if (!Array.isArray(durationOfShots) || durationOfShots.length === 0) throw new Error("Duration of shots must be a non-empty array");
212
+ let u = 0;
213
+ for (const shot of durationOfShots) u += getShotCredits(shot.type, tier, shot.used);
214
+ if (u === 0) throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
215
+ return u;
216
+ }
217
+ /**
218
+ * 估算任务的积分
219
+ * @param 时长,单位为秒
220
+ */
221
+ function estimateTaskCredits(params) {
222
+ const { duration, visual, tier } = params;
223
+ if (typeof duration !== "number") throw new Error("Duration must be a number");
224
+ if (!Array.isArray(visual) || visual.length === 0) throw new Error("Visuals must be a non-empty array");
225
+ if (typeof tier !== "string" || !tier) throw new Error("Tier must be a non-empty string");
226
+ const set = new Set(visual);
227
+ let u = 0;
228
+ for (const v of set) u += getShotCredits(v, tier, duration);
229
+ if (u === 0) throw new Error(`Invalid params, get ${JSON.stringify(params)}`);
230
+ return Math.floor(u / set.size);
231
+ }
232
+ function getShotCredits(visual, tier, duration) {
233
+ const unitCredits = taskPrices[tier]?.[visual];
234
+ if (!unitCredits) throw new Error(`Invalid tier or visual, get tier ${tier} and visual ${visual}`);
235
+ return duration * unitCredits;
236
+ }
237
+
238
+ //#endregion
239
+ //#region src/avatar-credits.ts
240
+ /**
241
+ * 计算制作Avatar的积分,固定为400积分。
242
+ */
243
+ function calculateAvatarCredits() {
244
+ return 200;
245
+ }
246
+
247
+ //#endregion
248
+ 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.1",
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
- };