@class-kit/core 0.1.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/CHANGELOG.md +6 -0
- package/LICENSE +3 -0
- package/README.md +26 -0
- package/dist/business/ComicReaderController.d.ts +37 -0
- package/dist/business/ComicReaderController.d.ts.map +1 -0
- package/dist/business/DanmakuController.d.ts +45 -0
- package/dist/business/DanmakuController.d.ts.map +1 -0
- package/dist/business/LiveRoomController.d.ts +37 -0
- package/dist/business/LiveRoomController.d.ts.map +1 -0
- package/dist/business/NovelReaderController.d.ts +63 -0
- package/dist/business/NovelReaderController.d.ts.map +1 -0
- package/dist/config.d.ts +89 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/data/TableController.d.ts +54 -0
- package/dist/data/TableController.d.ts.map +1 -0
- package/dist/data/UploadController.d.ts +27 -0
- package/dist/data/UploadController.d.ts.map +1 -0
- package/dist/display/BadgeController.d.ts +20 -0
- package/dist/display/BadgeController.d.ts.map +1 -0
- package/dist/display/CalendarController.d.ts +22 -0
- package/dist/display/CalendarController.d.ts.map +1 -0
- package/dist/display/CanvasEditorController.d.ts +87 -0
- package/dist/display/CanvasEditorController.d.ts.map +1 -0
- package/dist/display/CanvasImageController.d.ts +67 -0
- package/dist/display/CanvasImageController.d.ts.map +1 -0
- package/dist/display/CountdownController.d.ts +39 -0
- package/dist/display/CountdownController.d.ts.map +1 -0
- package/dist/display/DesignEffectController.d.ts +9 -0
- package/dist/display/DesignEffectController.d.ts.map +1 -0
- package/dist/display/FilePreviewController.d.ts +30 -0
- package/dist/display/FilePreviewController.d.ts.map +1 -0
- package/dist/display/GradientTextController.d.ts +8 -0
- package/dist/display/GradientTextController.d.ts.map +1 -0
- package/dist/display/HoneycombController.d.ts +18 -0
- package/dist/display/HoneycombController.d.ts.map +1 -0
- package/dist/display/ImagePreviewController.d.ts +17 -0
- package/dist/display/ImagePreviewController.d.ts.map +1 -0
- package/dist/display/LazyImageController.d.ts +11 -0
- package/dist/display/LazyImageController.d.ts.map +1 -0
- package/dist/display/MarqueeController.d.ts +17 -0
- package/dist/display/MarqueeController.d.ts.map +1 -0
- package/dist/display/ProgressController.d.ts +33 -0
- package/dist/display/ProgressController.d.ts.map +1 -0
- package/dist/display/RollingNumberController.d.ts +11 -0
- package/dist/display/RollingNumberController.d.ts.map +1 -0
- package/dist/display/SignatureController.d.ts +49 -0
- package/dist/display/SignatureController.d.ts.map +1 -0
- package/dist/display/SkeletonController.d.ts +16 -0
- package/dist/display/SkeletonController.d.ts.map +1 -0
- package/dist/display/SwiperController.d.ts +25 -0
- package/dist/display/SwiperController.d.ts.map +1 -0
- package/dist/display/TagController.d.ts +18 -0
- package/dist/display/TagController.d.ts.map +1 -0
- package/dist/display/TiltCardController.d.ts +10 -0
- package/dist/display/TiltCardController.d.ts.map +1 -0
- package/dist/display/TimelineController.d.ts +13 -0
- package/dist/display/TimelineController.d.ts.map +1 -0
- package/dist/display/TypewriterTextController.d.ts +17 -0
- package/dist/display/TypewriterTextController.d.ts.map +1 -0
- package/dist/display/VideoDetailTransitionController.d.ts +45 -0
- package/dist/display/VideoDetailTransitionController.d.ts.map +1 -0
- package/dist/display/VideoPlayerController.d.ts +18 -0
- package/dist/display/VideoPlayerController.d.ts.map +1 -0
- package/dist/display/types.d.ts +217 -0
- package/dist/display/types.d.ts.map +1 -0
- package/dist/feedback/AffixController.d.ts +11 -0
- package/dist/feedback/AffixController.d.ts.map +1 -0
- package/dist/feedback/BacktopController.d.ts +12 -0
- package/dist/feedback/BacktopController.d.ts.map +1 -0
- package/dist/feedback/FloatingBallController.d.ts +41 -0
- package/dist/feedback/FloatingBallController.d.ts.map +1 -0
- package/dist/feedback/ModalController.d.ts +13 -0
- package/dist/feedback/ModalController.d.ts.map +1 -0
- package/dist/feedback/PopupController.d.ts +24 -0
- package/dist/feedback/PopupController.d.ts.map +1 -0
- package/dist/feedback/ToastManager.d.ts +15 -0
- package/dist/feedback/ToastManager.d.ts.map +1 -0
- package/dist/feedback/TooltipController.d.ts +19 -0
- package/dist/feedback/TooltipController.d.ts.map +1 -0
- package/dist/feedback/placement.d.ts +5 -0
- package/dist/feedback/placement.d.ts.map +1 -0
- package/dist/feedback/types.d.ts +24 -0
- package/dist/feedback/types.d.ts.map +1 -0
- package/dist/form/ColorPickerController.d.ts +25 -0
- package/dist/form/ColorPickerController.d.ts.map +1 -0
- package/dist/form/DatePickerController.d.ts +39 -0
- package/dist/form/DatePickerController.d.ts.map +1 -0
- package/dist/form/DateRangePickerController.d.ts +56 -0
- package/dist/form/DateRangePickerController.d.ts.map +1 -0
- package/dist/form/FieldController.d.ts +16 -0
- package/dist/form/FieldController.d.ts.map +1 -0
- package/dist/form/FormController.d.ts +27 -0
- package/dist/form/FormController.d.ts.map +1 -0
- package/dist/form/MultiColumnPickerController.d.ts +37 -0
- package/dist/form/MultiColumnPickerController.d.ts.map +1 -0
- package/dist/form/PasswordInputController.d.ts +15 -0
- package/dist/form/PasswordInputController.d.ts.map +1 -0
- package/dist/form/SlideCaptchaController.d.ts +60 -0
- package/dist/form/SlideCaptchaController.d.ts.map +1 -0
- package/dist/form/VerificationCodeController.d.ts +29 -0
- package/dist/form/VerificationCodeController.d.ts.map +1 -0
- package/dist/form/VirtualSelectController.d.ts +34 -0
- package/dist/form/VirtualSelectController.d.ts.map +1 -0
- package/dist/form/emitter.d.ts +8 -0
- package/dist/form/emitter.d.ts.map +1 -0
- package/dist/form/index.d.ts +6 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/path.d.ts +6 -0
- package/dist/form/path.d.ts.map +1 -0
- package/dist/form/types.d.ts +60 -0
- package/dist/form/types.d.ts.map +1 -0
- package/dist/form/validation.d.ts +3 -0
- package/dist/form/validation.d.ts.map +1 -0
- package/dist/index.cjs +4688 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4624 -0
- package/dist/index.js.map +1 -0
- package/dist/interaction/DragController.d.ts +47 -0
- package/dist/interaction/DragController.d.ts.map +1 -0
- package/dist/interaction/DropController.d.ts +22 -0
- package/dist/interaction/DropController.d.ts.map +1 -0
- package/dist/interaction/GestureController.d.ts +34 -0
- package/dist/interaction/GestureController.d.ts.map +1 -0
- package/dist/navigation/BreadcrumbController.d.ts +17 -0
- package/dist/navigation/BreadcrumbController.d.ts.map +1 -0
- package/dist/navigation/PaginationController.d.ts +27 -0
- package/dist/navigation/PaginationController.d.ts.map +1 -0
- package/dist/navigation/TabsController.d.ts +13 -0
- package/dist/navigation/TabsController.d.ts.map +1 -0
- package/dist/virtualization/ChatVirtualListController.d.ts +17 -0
- package/dist/virtualization/ChatVirtualListController.d.ts.map +1 -0
- package/dist/virtualization/MasonryVirtualListController.d.ts +32 -0
- package/dist/virtualization/MasonryVirtualListController.d.ts.map +1 -0
- package/dist/virtualization/VirtualListController.d.ts +29 -0
- package/dist/virtualization/VirtualListController.d.ts.map +1 -0
- package/dist/virtualization/types.d.ts +67 -0
- package/dist/virtualization/types.d.ts.map +1 -0
- package/package.json +41 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,4624 @@
|
|
|
1
|
+
function isEmpty(value) {
|
|
2
|
+
return (value == null ||
|
|
3
|
+
value === "" ||
|
|
4
|
+
(Array.isArray(value) && value.length === 0));
|
|
5
|
+
}
|
|
6
|
+
async function runCustomValidator(validate, context) {
|
|
7
|
+
return validate(context);
|
|
8
|
+
}
|
|
9
|
+
async function validateValue(context, rules) {
|
|
10
|
+
const errors = [];
|
|
11
|
+
for (const rule of rules) {
|
|
12
|
+
if (rule.required && isEmpty(context.value)) {
|
|
13
|
+
errors.push(rule.message ?? "This field is required.");
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (rule.pattern && !isEmpty(context.value) && !rule.pattern.test(String(context.value))) {
|
|
17
|
+
errors.push(rule.message ?? "The value does not match the required format.");
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (rule.minLength != null &&
|
|
21
|
+
!isEmpty(context.value) &&
|
|
22
|
+
String(context.value).length < rule.minLength) {
|
|
23
|
+
errors.push(rule.message ?? `Please enter at least ${rule.minLength} characters.`);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (rule.maxLength != null &&
|
|
27
|
+
!isEmpty(context.value) &&
|
|
28
|
+
String(context.value).length > rule.maxLength) {
|
|
29
|
+
errors.push(rule.message ?? `Please enter no more than ${rule.maxLength} characters.`);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (rule.validate) {
|
|
33
|
+
const customError = await runCustomValidator(rule.validate, context);
|
|
34
|
+
if (customError)
|
|
35
|
+
errors.push(customError);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return errors;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class FieldController {
|
|
42
|
+
constructor(name, options = {}) {
|
|
43
|
+
this.name = name;
|
|
44
|
+
this.rules = options.rules ?? [];
|
|
45
|
+
this.validateOn = options.validateOn ?? ["change", "blur", "submit"];
|
|
46
|
+
this.state = {
|
|
47
|
+
name,
|
|
48
|
+
value: options.initialValue,
|
|
49
|
+
initialValue: options.initialValue,
|
|
50
|
+
errors: [],
|
|
51
|
+
meta: {
|
|
52
|
+
dirty: false,
|
|
53
|
+
touched: false,
|
|
54
|
+
validating: false,
|
|
55
|
+
submitted: false
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
getState() {
|
|
60
|
+
return {
|
|
61
|
+
...this.state,
|
|
62
|
+
errors: [...this.state.errors],
|
|
63
|
+
meta: { ...this.state.meta }
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
setValue(value) {
|
|
67
|
+
this.state = {
|
|
68
|
+
...this.state,
|
|
69
|
+
value,
|
|
70
|
+
meta: {
|
|
71
|
+
...this.state.meta,
|
|
72
|
+
dirty: !Object.is(value, this.state.initialValue)
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
markTouched() {
|
|
77
|
+
this.state = {
|
|
78
|
+
...this.state,
|
|
79
|
+
meta: { ...this.state.meta, touched: true }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
markSubmitted() {
|
|
83
|
+
this.state = {
|
|
84
|
+
...this.state,
|
|
85
|
+
meta: { ...this.state.meta, submitted: true }
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
reset(value = this.state.initialValue) {
|
|
89
|
+
this.state = {
|
|
90
|
+
name: this.name,
|
|
91
|
+
value,
|
|
92
|
+
initialValue: value,
|
|
93
|
+
errors: [],
|
|
94
|
+
meta: {
|
|
95
|
+
dirty: false,
|
|
96
|
+
touched: false,
|
|
97
|
+
validating: false,
|
|
98
|
+
submitted: false
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
shouldValidate(trigger) {
|
|
103
|
+
return this.validateOn.includes(trigger);
|
|
104
|
+
}
|
|
105
|
+
async validate(values) {
|
|
106
|
+
this.state = {
|
|
107
|
+
...this.state,
|
|
108
|
+
meta: { ...this.state.meta, validating: true }
|
|
109
|
+
};
|
|
110
|
+
const errors = await validateValue({ field: this.name, value: this.state.value, values }, this.rules);
|
|
111
|
+
this.state = {
|
|
112
|
+
...this.state,
|
|
113
|
+
errors,
|
|
114
|
+
meta: { ...this.state.meta, validating: false }
|
|
115
|
+
};
|
|
116
|
+
return errors;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
class StateEmitter {
|
|
121
|
+
constructor() {
|
|
122
|
+
this.listeners = new Set();
|
|
123
|
+
}
|
|
124
|
+
subscribe(listener) {
|
|
125
|
+
this.listeners.add(listener);
|
|
126
|
+
return () => {
|
|
127
|
+
this.listeners.delete(listener);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
emit(state) {
|
|
131
|
+
this.listeners.forEach((listener) => listener(state));
|
|
132
|
+
}
|
|
133
|
+
clear() {
|
|
134
|
+
this.listeners.clear();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const pathPattern = /[^.[\]]+/g;
|
|
139
|
+
function toPath(path) {
|
|
140
|
+
return path.match(pathPattern) ?? [];
|
|
141
|
+
}
|
|
142
|
+
function getByPath(source, path) {
|
|
143
|
+
return toPath(path).reduce((current, key) => {
|
|
144
|
+
if (current == null || typeof current !== "object")
|
|
145
|
+
return undefined;
|
|
146
|
+
return current[key];
|
|
147
|
+
}, source);
|
|
148
|
+
}
|
|
149
|
+
function setByPath(source, path, value) {
|
|
150
|
+
const keys = toPath(path);
|
|
151
|
+
if (keys.length === 0)
|
|
152
|
+
return source;
|
|
153
|
+
const next = { ...source };
|
|
154
|
+
let cursor = next;
|
|
155
|
+
keys.forEach((key, index) => {
|
|
156
|
+
if (index === keys.length - 1) {
|
|
157
|
+
cursor[key] = value;
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const existing = cursor[key];
|
|
161
|
+
const child = existing != null && typeof existing === "object"
|
|
162
|
+
? { ...existing }
|
|
163
|
+
: {};
|
|
164
|
+
cursor[key] = child;
|
|
165
|
+
cursor = child;
|
|
166
|
+
});
|
|
167
|
+
return next;
|
|
168
|
+
}
|
|
169
|
+
function cloneValues(values) {
|
|
170
|
+
if (typeof structuredClone === "function") {
|
|
171
|
+
try {
|
|
172
|
+
return structuredClone(values);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return cloneFallback(values);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return cloneFallback(values);
|
|
179
|
+
}
|
|
180
|
+
function cloneFallback(value, seen = new WeakMap()) {
|
|
181
|
+
if (value == null || typeof value !== "object")
|
|
182
|
+
return value;
|
|
183
|
+
if (value instanceof Date)
|
|
184
|
+
return new Date(value.getTime());
|
|
185
|
+
if (value instanceof RegExp)
|
|
186
|
+
return new RegExp(value.source, value.flags);
|
|
187
|
+
if (typeof File !== "undefined" && value instanceof File)
|
|
188
|
+
return value;
|
|
189
|
+
if (typeof Blob !== "undefined" && value instanceof Blob)
|
|
190
|
+
return value;
|
|
191
|
+
const objectValue = value;
|
|
192
|
+
if (seen.has(objectValue))
|
|
193
|
+
return seen.get(objectValue);
|
|
194
|
+
if (Array.isArray(value)) {
|
|
195
|
+
const next = [];
|
|
196
|
+
seen.set(objectValue, next);
|
|
197
|
+
value.forEach((item) => next.push(cloneFallback(item, seen)));
|
|
198
|
+
return next;
|
|
199
|
+
}
|
|
200
|
+
if (value instanceof Map) {
|
|
201
|
+
const next = new Map();
|
|
202
|
+
seen.set(objectValue, next);
|
|
203
|
+
value.forEach((mapValue, mapKey) => next.set(cloneFallback(mapKey, seen), cloneFallback(mapValue, seen)));
|
|
204
|
+
return next;
|
|
205
|
+
}
|
|
206
|
+
if (value instanceof Set) {
|
|
207
|
+
const next = new Set();
|
|
208
|
+
seen.set(objectValue, next);
|
|
209
|
+
value.forEach((item) => next.add(cloneFallback(item, seen)));
|
|
210
|
+
return next;
|
|
211
|
+
}
|
|
212
|
+
const next = {};
|
|
213
|
+
seen.set(objectValue, next);
|
|
214
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
215
|
+
next[key] = cloneFallback(item, seen);
|
|
216
|
+
});
|
|
217
|
+
return next;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
class FormController {
|
|
221
|
+
constructor(options = {}) {
|
|
222
|
+
this.emitter = new StateEmitter();
|
|
223
|
+
this.fields = new Map();
|
|
224
|
+
this.submitting = false;
|
|
225
|
+
this.submitted = false;
|
|
226
|
+
this.submitCount = 0;
|
|
227
|
+
this.initialValues = cloneValues(options.initialValues ?? {});
|
|
228
|
+
this.values = cloneValues(options.initialValues ?? {});
|
|
229
|
+
this.validateOn = options.validateOn ?? ["submit"];
|
|
230
|
+
this.onSubmit = options.onSubmit;
|
|
231
|
+
this.state = this.createState();
|
|
232
|
+
}
|
|
233
|
+
registerField(name, options = {}) {
|
|
234
|
+
const initialValue = options.initialValue !== undefined
|
|
235
|
+
? options.initialValue
|
|
236
|
+
: getByPath(this.values, name);
|
|
237
|
+
const field = new FieldController(name, {
|
|
238
|
+
...options,
|
|
239
|
+
initialValue,
|
|
240
|
+
validateOn: options.validateOn ?? this.validateOn,
|
|
241
|
+
});
|
|
242
|
+
this.fields.set(name, field);
|
|
243
|
+
if (initialValue !== undefined) {
|
|
244
|
+
this.values = setByPath(this.values, name, initialValue);
|
|
245
|
+
}
|
|
246
|
+
this.notify();
|
|
247
|
+
return () => {
|
|
248
|
+
this.fields.delete(name);
|
|
249
|
+
this.notify();
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
subscribe(listener) {
|
|
253
|
+
return this.emitter.subscribe(listener);
|
|
254
|
+
}
|
|
255
|
+
getState() {
|
|
256
|
+
return this.state;
|
|
257
|
+
}
|
|
258
|
+
getValue(name) {
|
|
259
|
+
return getByPath(this.values, name);
|
|
260
|
+
}
|
|
261
|
+
createState() {
|
|
262
|
+
const fieldStates = Object.fromEntries(Array.from(this.fields.entries()).map(([name, field]) => [
|
|
263
|
+
name,
|
|
264
|
+
field.getState(),
|
|
265
|
+
]));
|
|
266
|
+
const errors = {};
|
|
267
|
+
Object.entries(fieldStates).forEach(([name, field]) => {
|
|
268
|
+
if (field.errors.length > 0)
|
|
269
|
+
errors[name] = field.errors;
|
|
270
|
+
});
|
|
271
|
+
const states = Object.values(fieldStates);
|
|
272
|
+
return {
|
|
273
|
+
values: cloneValues(this.values),
|
|
274
|
+
errors,
|
|
275
|
+
fields: fieldStates,
|
|
276
|
+
dirty: states.some((field) => field.meta.dirty),
|
|
277
|
+
touched: states.some((field) => field.meta.touched),
|
|
278
|
+
validating: states.some((field) => field.meta.validating),
|
|
279
|
+
submitting: this.submitting,
|
|
280
|
+
submitted: this.submitted,
|
|
281
|
+
valid: Object.keys(errors).length === 0,
|
|
282
|
+
submitCount: this.submitCount,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
async setValue(name, value, trigger = "change") {
|
|
286
|
+
this.values = setByPath(this.values, name, value);
|
|
287
|
+
const field = this.fields.get(name);
|
|
288
|
+
field?.setValue(value);
|
|
289
|
+
if (field?.shouldValidate(trigger)) {
|
|
290
|
+
await field.validate(this.values);
|
|
291
|
+
}
|
|
292
|
+
this.notify();
|
|
293
|
+
}
|
|
294
|
+
async blur(name) {
|
|
295
|
+
const field = this.fields.get(name);
|
|
296
|
+
field?.markTouched();
|
|
297
|
+
if (field?.shouldValidate("blur")) {
|
|
298
|
+
await field.validate(this.values);
|
|
299
|
+
}
|
|
300
|
+
this.notify();
|
|
301
|
+
}
|
|
302
|
+
async validate() {
|
|
303
|
+
const tasks = Array.from(this.fields.values()).map((field) => field.validate(this.values));
|
|
304
|
+
this.notify();
|
|
305
|
+
await Promise.all(tasks);
|
|
306
|
+
this.notify();
|
|
307
|
+
return this.getState().valid;
|
|
308
|
+
}
|
|
309
|
+
async submit() {
|
|
310
|
+
this.submitting = true;
|
|
311
|
+
this.submitted = true;
|
|
312
|
+
this.submitCount += 1;
|
|
313
|
+
this.fields.forEach((field) => field.markSubmitted());
|
|
314
|
+
this.notify();
|
|
315
|
+
const valid = await this.validate();
|
|
316
|
+
const state = this.getState();
|
|
317
|
+
try {
|
|
318
|
+
if (valid && this.onSubmit) {
|
|
319
|
+
await this.onSubmit(state.values, state);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
finally {
|
|
323
|
+
this.submitting = false;
|
|
324
|
+
this.notify();
|
|
325
|
+
}
|
|
326
|
+
return this.getState();
|
|
327
|
+
}
|
|
328
|
+
reset(values = this.initialValues) {
|
|
329
|
+
this.values = cloneValues(values);
|
|
330
|
+
this.submitting = false;
|
|
331
|
+
this.submitted = false;
|
|
332
|
+
this.submitCount = 0;
|
|
333
|
+
this.fields.forEach((field, name) => {
|
|
334
|
+
const nextValue = getByPath(this.values, name);
|
|
335
|
+
field.reset(nextValue);
|
|
336
|
+
});
|
|
337
|
+
this.notify();
|
|
338
|
+
}
|
|
339
|
+
destroy() {
|
|
340
|
+
this.fields.clear();
|
|
341
|
+
this.emitter.clear();
|
|
342
|
+
}
|
|
343
|
+
notify() {
|
|
344
|
+
this.state = this.createState();
|
|
345
|
+
this.emitter.emit(this.state);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const builtInThemeNames = [
|
|
350
|
+
"minimal",
|
|
351
|
+
"violet",
|
|
352
|
+
"emerald",
|
|
353
|
+
"sky",
|
|
354
|
+
"rose",
|
|
355
|
+
"amber",
|
|
356
|
+
"liquid-glass",
|
|
357
|
+
];
|
|
358
|
+
const defaultLocale = {
|
|
359
|
+
backtopLabel: "回到顶部",
|
|
360
|
+
calendarNextMonth: "下个月",
|
|
361
|
+
calendarPreviousMonth: "上个月",
|
|
362
|
+
emptyText: "暂无数据",
|
|
363
|
+
loadingText: "加载中...",
|
|
364
|
+
countdownDayUnit: "天",
|
|
365
|
+
countdownHourUnit: "时",
|
|
366
|
+
countdownMinuteUnit: "分",
|
|
367
|
+
countdownSecondUnit: "秒",
|
|
368
|
+
colorPickerAlphaLabel: "透明度",
|
|
369
|
+
comicReaderLoadMoreText: "继续下滑加载",
|
|
370
|
+
comicReaderLoadingText: "加载中...",
|
|
371
|
+
comicReaderNoMoreText: "已到底部",
|
|
372
|
+
comicReaderNextLabel: "下一页",
|
|
373
|
+
comicReaderPreviousLabel: "上一页",
|
|
374
|
+
datePickerNextMonth: "下个月",
|
|
375
|
+
datePickerPlaceholder: "请选择日期",
|
|
376
|
+
datePickerPreviousMonth: "上个月",
|
|
377
|
+
datePickerWeekLabels: ["日", "一", "二", "三", "四", "五", "六"],
|
|
378
|
+
dateDayUnit: "日",
|
|
379
|
+
dateMonthUnit: "月",
|
|
380
|
+
dateYearUnit: "年",
|
|
381
|
+
dateRangeClear: "清空",
|
|
382
|
+
dateRangeEndPlaceholder: "结束日期",
|
|
383
|
+
dateRangePlaceholder: "请选择日期范围",
|
|
384
|
+
dateRangeSeparator: "至",
|
|
385
|
+
dateRangeStartPlaceholder: "开始日期",
|
|
386
|
+
inputClearLabel: "清空内容",
|
|
387
|
+
passwordClearLabel: "清空密码",
|
|
388
|
+
passwordHiddenAlt: "显示密码",
|
|
389
|
+
passwordHiddenIcon: "显示",
|
|
390
|
+
passwordToggleHiddenLabel: "显示密码",
|
|
391
|
+
passwordToggleVisibleLabel: "隐藏密码",
|
|
392
|
+
passwordVisibleAlt: "隐藏密码",
|
|
393
|
+
passwordVisibleIcon: "隐藏",
|
|
394
|
+
popconfirmCancelText: "取消",
|
|
395
|
+
popconfirmConfirmText: "确认",
|
|
396
|
+
popconfirmContent: "确认执行该操作?",
|
|
397
|
+
selectClearLabel: "清空选择",
|
|
398
|
+
selectEmptyText: "暂无匹配选项",
|
|
399
|
+
selectPlaceholder: "Select",
|
|
400
|
+
selectSearchPlaceholder: "搜索选项",
|
|
401
|
+
selectSelectedIcon: "",
|
|
402
|
+
signatureClearText: "一键清除",
|
|
403
|
+
signatureUndoText: "回退",
|
|
404
|
+
tableColumnSettingsLabel: "列设置",
|
|
405
|
+
tableEmptyText: "暂无表格数据",
|
|
406
|
+
tableLoadingText: "表格加载中...",
|
|
407
|
+
tableSelectAllLabel: "选择全部",
|
|
408
|
+
tableSelectRowLabel: "选择",
|
|
409
|
+
tabsEmptyText: "暂无内容",
|
|
410
|
+
tabsLoadingText: "内容加载中...",
|
|
411
|
+
uploadButtonText: "选择文件",
|
|
412
|
+
uploadDragText: "拖拽文件到这里",
|
|
413
|
+
verificationInputLabel: "验证码",
|
|
414
|
+
virtualListPullUpLoadingText: "正在加载更多...",
|
|
415
|
+
virtualListPullUpReadyText: "继续上拉加载",
|
|
416
|
+
novelReaderEmptyText: "暂无章节内容",
|
|
417
|
+
novelReaderNextLabel: "下一页",
|
|
418
|
+
novelReaderPreviousLabel: "上一页",
|
|
419
|
+
novelReaderTitle: "小说阅读",
|
|
420
|
+
liveRoomFavoriteLabel: "收藏",
|
|
421
|
+
liveRoomGiftLabel: "福袋",
|
|
422
|
+
liveRoomInputPlaceholder: "说点什么...",
|
|
423
|
+
liveRoomLikeLabel: "点赞",
|
|
424
|
+
liveRoomMoreLabel: "更多",
|
|
425
|
+
liveRoomSelfName: "我",
|
|
426
|
+
liveRoomSendLabel: "发送",
|
|
427
|
+
liveRoomShareLabel: "分享",
|
|
428
|
+
};
|
|
429
|
+
function cloneLocale(locale) {
|
|
430
|
+
return {
|
|
431
|
+
...locale,
|
|
432
|
+
datePickerWeekLabels: [...locale.datePickerWeekLabels],
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
let globalConfig = {
|
|
436
|
+
locale: cloneLocale(defaultLocale),
|
|
437
|
+
theme: { name: "minimal" },
|
|
438
|
+
};
|
|
439
|
+
function resolveTheme(theme) {
|
|
440
|
+
const name = typeof theme === "string" ? theme : theme?.name;
|
|
441
|
+
return {
|
|
442
|
+
name: builtInThemeNames.includes(name)
|
|
443
|
+
? name
|
|
444
|
+
: "minimal",
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
function configureClassComponents(config = {}) {
|
|
448
|
+
const nextLocale = {
|
|
449
|
+
...globalConfig.locale,
|
|
450
|
+
...config.locale,
|
|
451
|
+
};
|
|
452
|
+
globalConfig = {
|
|
453
|
+
locale: cloneLocale(nextLocale),
|
|
454
|
+
theme: config.theme
|
|
455
|
+
? resolveTheme(config.theme)
|
|
456
|
+
: { ...globalConfig.theme },
|
|
457
|
+
};
|
|
458
|
+
return getClassComponentsConfig();
|
|
459
|
+
}
|
|
460
|
+
function getClassComponentsConfig() {
|
|
461
|
+
return {
|
|
462
|
+
locale: cloneLocale(globalConfig.locale),
|
|
463
|
+
theme: { ...globalConfig.theme },
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
function getClassComponentsLocale() {
|
|
467
|
+
return getClassComponentsConfig().locale;
|
|
468
|
+
}
|
|
469
|
+
function resetClassComponentsConfig() {
|
|
470
|
+
globalConfig = {
|
|
471
|
+
locale: cloneLocale(defaultLocale),
|
|
472
|
+
theme: { name: "minimal" },
|
|
473
|
+
};
|
|
474
|
+
return getClassComponentsConfig();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
class MultiColumnPickerController {
|
|
478
|
+
constructor(options) {
|
|
479
|
+
this.dateSource = options.source;
|
|
480
|
+
this.sourceColumns = options.columns ?? this.createDateColumns(options.source, options.values);
|
|
481
|
+
this.cascade = options.cascade ?? false;
|
|
482
|
+
this.values = options.values ?? [];
|
|
483
|
+
}
|
|
484
|
+
updateOptions(options) {
|
|
485
|
+
if (options.columns) {
|
|
486
|
+
this.dateSource = undefined;
|
|
487
|
+
this.sourceColumns = options.columns;
|
|
488
|
+
}
|
|
489
|
+
if (options.source) {
|
|
490
|
+
this.dateSource = options.source;
|
|
491
|
+
this.sourceColumns = this.createDateColumns(options.source, options.values ?? this.values);
|
|
492
|
+
}
|
|
493
|
+
if (options.cascade !== undefined)
|
|
494
|
+
this.cascade = options.cascade;
|
|
495
|
+
if (options.values)
|
|
496
|
+
this.values = options.values;
|
|
497
|
+
return this.getState();
|
|
498
|
+
}
|
|
499
|
+
select(columnIndex, value) {
|
|
500
|
+
this.values = [...this.values.slice(0, columnIndex), value];
|
|
501
|
+
return this.getState();
|
|
502
|
+
}
|
|
503
|
+
selectByDelta(columnIndex, delta) {
|
|
504
|
+
const state = this.getState();
|
|
505
|
+
const column = state.columns[columnIndex] ?? [];
|
|
506
|
+
if (column.length === 0)
|
|
507
|
+
return state;
|
|
508
|
+
const currentIndex = Math.max(0, column.findIndex((item) => item.value === state.values[columnIndex]));
|
|
509
|
+
const nextStep = Math.trunc(delta);
|
|
510
|
+
const direction = nextStep >= 0 ? 1 : -1;
|
|
511
|
+
let nextIndex = Math.min(column.length - 1, Math.max(0, currentIndex + nextStep));
|
|
512
|
+
while (column[nextIndex]?.disabled && nextIndex > 0 && nextIndex < column.length - 1) {
|
|
513
|
+
nextIndex += direction;
|
|
514
|
+
}
|
|
515
|
+
const next = column[nextIndex];
|
|
516
|
+
return next && !next.disabled ? this.select(columnIndex, next.value) : state;
|
|
517
|
+
}
|
|
518
|
+
getState() {
|
|
519
|
+
if (this.dateSource)
|
|
520
|
+
this.sourceColumns = this.createDateColumns(this.dateSource, this.values);
|
|
521
|
+
const columns = [];
|
|
522
|
+
const selectedOptions = [];
|
|
523
|
+
if (!this.cascade) {
|
|
524
|
+
this.sourceColumns.forEach((column, index) => {
|
|
525
|
+
columns[index] = column;
|
|
526
|
+
const selected = column.find((item) => item.value === this.values[index]) ?? column.find((item) => !item.disabled) ?? column[0];
|
|
527
|
+
if (selected) {
|
|
528
|
+
selectedOptions[index] = selected;
|
|
529
|
+
this.values[index] = selected.value;
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
return { columns, selectedOptions, values: selectedOptions.map((item) => item.value) };
|
|
533
|
+
}
|
|
534
|
+
let currentColumn = this.sourceColumns[0] ?? [];
|
|
535
|
+
let index = 0;
|
|
536
|
+
while (currentColumn.length > 0) {
|
|
537
|
+
columns[index] = currentColumn;
|
|
538
|
+
const selected = currentColumn.find((item) => item.value === this.values[index]) ?? currentColumn.find((item) => !item.disabled) ?? currentColumn[0];
|
|
539
|
+
if (!selected)
|
|
540
|
+
break;
|
|
541
|
+
selectedOptions[index] = selected;
|
|
542
|
+
this.values[index] = selected.value;
|
|
543
|
+
currentColumn = selected.children ?? [];
|
|
544
|
+
index += 1;
|
|
545
|
+
}
|
|
546
|
+
return { columns, selectedOptions, values: selectedOptions.map((item) => item.value) };
|
|
547
|
+
}
|
|
548
|
+
createDateColumns(source, values = []) {
|
|
549
|
+
if (!source)
|
|
550
|
+
return [];
|
|
551
|
+
const currentYear = new Date().getFullYear();
|
|
552
|
+
const startYear = source.startYear ?? (source.endYear ? source.endYear - (source.yearCount ?? 100) + 1 : currentYear - 50);
|
|
553
|
+
const endYear = source.endYear ?? startYear + (source.yearCount ?? 100) - 1;
|
|
554
|
+
const selectedYear = Number(values[0] ?? startYear);
|
|
555
|
+
const selectedMonth = Number(values[1] ?? 1);
|
|
556
|
+
const days = new Date(selectedYear, selectedMonth, 0).getDate();
|
|
557
|
+
const locale = getClassComponentsLocale();
|
|
558
|
+
const years = this.range(startYear, endYear).map((year) => ({ label: `${year}${locale.dateYearUnit}`, value: year }));
|
|
559
|
+
const months = this.range(1, 12).map((month) => ({ label: `${month}${locale.dateMonthUnit}`, value: month }));
|
|
560
|
+
const dayItems = this.range(1, days).map((day) => ({ label: `${day}${locale.dateDayUnit}`, value: day }));
|
|
561
|
+
return [years, months, dayItems];
|
|
562
|
+
}
|
|
563
|
+
range(start, end) {
|
|
564
|
+
const result = [];
|
|
565
|
+
for (let value = start; value <= end; value += 1)
|
|
566
|
+
result.push(value);
|
|
567
|
+
return result;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
class VirtualSelectController {
|
|
572
|
+
constructor(options) {
|
|
573
|
+
this.multiple = Boolean(options.multiple);
|
|
574
|
+
this.options = options.options;
|
|
575
|
+
this.query = normalizeQuery(options.query);
|
|
576
|
+
this.selectedValues = normalizeSelectedValues(options.value, this.multiple);
|
|
577
|
+
}
|
|
578
|
+
update(options) {
|
|
579
|
+
if (options.multiple !== undefined)
|
|
580
|
+
this.multiple = Boolean(options.multiple);
|
|
581
|
+
if (options.options !== undefined)
|
|
582
|
+
this.options = options.options;
|
|
583
|
+
if (options.query !== undefined)
|
|
584
|
+
this.query = normalizeQuery(options.query);
|
|
585
|
+
if (Object.prototype.hasOwnProperty.call(options, "value")) {
|
|
586
|
+
this.selectedValues = normalizeSelectedValues(options.value, this.multiple);
|
|
587
|
+
}
|
|
588
|
+
return this.getState();
|
|
589
|
+
}
|
|
590
|
+
clear() {
|
|
591
|
+
this.selectedValues = [];
|
|
592
|
+
return this.getValue();
|
|
593
|
+
}
|
|
594
|
+
getState() {
|
|
595
|
+
const availableValues = new Set(this.options.map((option) => option.value));
|
|
596
|
+
const selectedValues = this.selectedValues.filter((value) => availableValues.has(value));
|
|
597
|
+
if (selectedValues.length !== this.selectedValues.length)
|
|
598
|
+
this.selectedValues = selectedValues;
|
|
599
|
+
return {
|
|
600
|
+
filteredOptions: this.getFilteredOptions(),
|
|
601
|
+
multiple: this.multiple,
|
|
602
|
+
query: this.query,
|
|
603
|
+
selectedOptions: this.options.filter((option) => selectedValues.includes(option.value)),
|
|
604
|
+
selectedValues
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
getValue() {
|
|
608
|
+
if (this.multiple)
|
|
609
|
+
return [...this.selectedValues];
|
|
610
|
+
return this.selectedValues[0] ?? "";
|
|
611
|
+
}
|
|
612
|
+
isSelected(value) {
|
|
613
|
+
return this.selectedValues.includes(value);
|
|
614
|
+
}
|
|
615
|
+
toggle(option) {
|
|
616
|
+
if (option.disabled)
|
|
617
|
+
return this.getValue();
|
|
618
|
+
if (!this.multiple) {
|
|
619
|
+
this.selectedValues = [option.value];
|
|
620
|
+
return option.value;
|
|
621
|
+
}
|
|
622
|
+
this.selectedValues = this.isSelected(option.value)
|
|
623
|
+
? this.selectedValues.filter((value) => value !== option.value)
|
|
624
|
+
: [...this.selectedValues, option.value];
|
|
625
|
+
return this.getValue();
|
|
626
|
+
}
|
|
627
|
+
getFilteredOptions() {
|
|
628
|
+
if (!this.query)
|
|
629
|
+
return this.options;
|
|
630
|
+
return this.options.filter((option) => option.label.toLocaleLowerCase().includes(this.query));
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function normalizeQuery(query) {
|
|
634
|
+
return String(query ?? "").trim().toLocaleLowerCase();
|
|
635
|
+
}
|
|
636
|
+
function normalizeSelectedValues(value, multiple) {
|
|
637
|
+
if (Array.isArray(value))
|
|
638
|
+
return multiple ? [...value] : value.slice(0, 1);
|
|
639
|
+
if (value === "" || value === undefined)
|
|
640
|
+
return [];
|
|
641
|
+
return [value];
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function clampChannel(value) {
|
|
645
|
+
return Math.max(0, Math.min(255, Math.round(Number.isFinite(value) ? value : 0)));
|
|
646
|
+
}
|
|
647
|
+
function clampAlpha(value) {
|
|
648
|
+
return Math.max(0, Math.min(1, Number.isFinite(value) ? value : 1));
|
|
649
|
+
}
|
|
650
|
+
function toHex(value) {
|
|
651
|
+
return clampChannel(value).toString(16).padStart(2, "0");
|
|
652
|
+
}
|
|
653
|
+
function parseHex(value) {
|
|
654
|
+
const raw = value.trim();
|
|
655
|
+
const short = raw.match(/^#([0-9a-f]{3})([0-9a-f])?$/i);
|
|
656
|
+
if (short) {
|
|
657
|
+
const rgb = short[1] ?? "000";
|
|
658
|
+
const alpha = short[2] ?? "f";
|
|
659
|
+
const red = parseInt(rgb.charAt(0) + rgb.charAt(0), 16);
|
|
660
|
+
const green = parseInt(rgb.charAt(1) + rgb.charAt(1), 16);
|
|
661
|
+
const blue = parseInt(rgb.charAt(2) + rgb.charAt(2), 16);
|
|
662
|
+
return { alpha: parseInt(alpha + alpha, 16) / 255, blue, green, hex: `#${toHex(red)}${toHex(green)}${toHex(blue)}`, red };
|
|
663
|
+
}
|
|
664
|
+
const full = raw.match(/^#([0-9a-f]{6})([0-9a-f]{2})?$/i);
|
|
665
|
+
if (!full)
|
|
666
|
+
return undefined;
|
|
667
|
+
const rgb = full[1] ?? "000000";
|
|
668
|
+
return {
|
|
669
|
+
alpha: full[2] ? parseInt(full[2], 16) / 255 : 1,
|
|
670
|
+
blue: parseInt(rgb.slice(4, 6), 16),
|
|
671
|
+
green: parseInt(rgb.slice(2, 4), 16),
|
|
672
|
+
hex: `#${rgb.toLowerCase()}`,
|
|
673
|
+
red: parseInt(rgb.slice(0, 2), 16)
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
function parseRgb(value) {
|
|
677
|
+
const match = value.trim().match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*([\d.]+))?\s*\)$/i);
|
|
678
|
+
if (!match)
|
|
679
|
+
return undefined;
|
|
680
|
+
const red = clampChannel(Number(match[1]));
|
|
681
|
+
const green = clampChannel(Number(match[2]));
|
|
682
|
+
const blue = clampChannel(Number(match[3]));
|
|
683
|
+
return { alpha: clampAlpha(Number(match[4] ?? 1)), blue, green, hex: `#${toHex(red)}${toHex(green)}${toHex(blue)}`, red };
|
|
684
|
+
}
|
|
685
|
+
function formatRgba(red, green, blue, alpha) {
|
|
686
|
+
return `rgba(${clampChannel(red)}, ${clampChannel(green)}, ${clampChannel(blue)}, ${Number(clampAlpha(alpha).toFixed(2))})`;
|
|
687
|
+
}
|
|
688
|
+
function getContrastColor(red, green, blue, alpha) {
|
|
689
|
+
const opacity = clampAlpha(alpha);
|
|
690
|
+
const blendedRed = clampChannel(red) * opacity + 255 * (1 - opacity);
|
|
691
|
+
const blendedGreen = clampChannel(green) * opacity + 255 * (1 - opacity);
|
|
692
|
+
const blendedBlue = clampChannel(blue) * opacity + 255 * (1 - opacity);
|
|
693
|
+
const luminance = (0.299 * blendedRed + 0.587 * blendedGreen + 0.114 * blendedBlue) / 255;
|
|
694
|
+
return luminance > 0.58 ? "#000000" : "#ffffff";
|
|
695
|
+
}
|
|
696
|
+
function rgbToHsv(red, green, blue) {
|
|
697
|
+
const r = clampChannel(red) / 255;
|
|
698
|
+
const g = clampChannel(green) / 255;
|
|
699
|
+
const b = clampChannel(blue) / 255;
|
|
700
|
+
const max = Math.max(r, g, b);
|
|
701
|
+
const min = Math.min(r, g, b);
|
|
702
|
+
const delta = max - min;
|
|
703
|
+
let hue = 0;
|
|
704
|
+
if (delta !== 0) {
|
|
705
|
+
if (max === r)
|
|
706
|
+
hue = ((g - b) / delta) % 6;
|
|
707
|
+
else if (max === g)
|
|
708
|
+
hue = (b - r) / delta + 2;
|
|
709
|
+
else
|
|
710
|
+
hue = (r - g) / delta + 4;
|
|
711
|
+
hue *= 60;
|
|
712
|
+
if (hue < 0)
|
|
713
|
+
hue += 360;
|
|
714
|
+
}
|
|
715
|
+
return {
|
|
716
|
+
brightness: max,
|
|
717
|
+
hue,
|
|
718
|
+
saturation: max === 0 ? 0 : delta / max
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
function hsvToRgb(hue, saturation, brightness) {
|
|
722
|
+
const h = ((Number.isFinite(hue) ? hue : 0) % 360 + 360) % 360;
|
|
723
|
+
const s = Math.max(0, Math.min(1, Number.isFinite(saturation) ? saturation : 0));
|
|
724
|
+
const v = Math.max(0, Math.min(1, Number.isFinite(brightness) ? brightness : 0));
|
|
725
|
+
const c = v * s;
|
|
726
|
+
const x = c * (1 - Math.abs((h / 60) % 2 - 1));
|
|
727
|
+
const m = v - c;
|
|
728
|
+
let r = 0;
|
|
729
|
+
let g = 0;
|
|
730
|
+
let b = 0;
|
|
731
|
+
if (h < 60)
|
|
732
|
+
[r, g, b] = [c, x, 0];
|
|
733
|
+
else if (h < 120)
|
|
734
|
+
[r, g, b] = [x, c, 0];
|
|
735
|
+
else if (h < 180)
|
|
736
|
+
[r, g, b] = [0, c, x];
|
|
737
|
+
else if (h < 240)
|
|
738
|
+
[r, g, b] = [0, x, c];
|
|
739
|
+
else if (h < 300)
|
|
740
|
+
[r, g, b] = [x, 0, c];
|
|
741
|
+
else
|
|
742
|
+
[r, g, b] = [c, 0, x];
|
|
743
|
+
return {
|
|
744
|
+
blue: clampChannel((b + m) * 255),
|
|
745
|
+
green: clampChannel((g + m) * 255),
|
|
746
|
+
red: clampChannel((r + m) * 255)
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
class ColorPickerController {
|
|
750
|
+
constructor(value = "#7c3aed") {
|
|
751
|
+
this.state = this.parse(value);
|
|
752
|
+
}
|
|
753
|
+
parse(value) {
|
|
754
|
+
const parsed = parseRgb(value) ?? parseHex(value) ?? parseHex("#7c3aed");
|
|
755
|
+
const hsv = rgbToHsv(parsed.red, parsed.green, parsed.blue);
|
|
756
|
+
const rgba = formatRgba(parsed.red, parsed.green, parsed.blue, parsed.alpha);
|
|
757
|
+
return { ...parsed, ...hsv, contrastColor: getContrastColor(parsed.red, parsed.green, parsed.blue, parsed.alpha), rgba, value: rgba };
|
|
758
|
+
}
|
|
759
|
+
update(value) {
|
|
760
|
+
this.state = this.parse(value);
|
|
761
|
+
return this.getState();
|
|
762
|
+
}
|
|
763
|
+
setHex(hex) {
|
|
764
|
+
const parsed = parseHex(hex) ?? this.state;
|
|
765
|
+
this.state = this.parse(formatRgba(parsed.red, parsed.green, parsed.blue, this.state.alpha));
|
|
766
|
+
return this.getState();
|
|
767
|
+
}
|
|
768
|
+
setAlpha(alpha) {
|
|
769
|
+
this.state = this.parse(formatRgba(this.state.red, this.state.green, this.state.blue, alpha));
|
|
770
|
+
return this.getState();
|
|
771
|
+
}
|
|
772
|
+
setHue(hue) {
|
|
773
|
+
const rgb = hsvToRgb(hue, this.state.saturation, this.state.brightness);
|
|
774
|
+
this.state = this.parse(formatRgba(rgb.red, rgb.green, rgb.blue, this.state.alpha));
|
|
775
|
+
return this.getState();
|
|
776
|
+
}
|
|
777
|
+
setSaturationBrightness(saturation, brightness) {
|
|
778
|
+
const rgb = hsvToRgb(this.state.hue, saturation, brightness);
|
|
779
|
+
this.state = this.parse(formatRgba(rgb.red, rgb.green, rgb.blue, this.state.alpha));
|
|
780
|
+
return this.getState();
|
|
781
|
+
}
|
|
782
|
+
getState() {
|
|
783
|
+
return { ...this.state };
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function pad$2(value) {
|
|
788
|
+
return String(value).padStart(2, "0");
|
|
789
|
+
}
|
|
790
|
+
function toDateKey$1(date) {
|
|
791
|
+
return `${date.getFullYear()}-${pad$2(date.getMonth() + 1)}-${pad$2(date.getDate())}`;
|
|
792
|
+
}
|
|
793
|
+
function parseDate$1(value) {
|
|
794
|
+
if (!value || !/^\d{4}-\d{2}-\d{2}$/.test(value))
|
|
795
|
+
return undefined;
|
|
796
|
+
const [yearText, monthText, dayText] = value.split("-");
|
|
797
|
+
const year = Number(yearText);
|
|
798
|
+
const month = Number(monthText);
|
|
799
|
+
const day = Number(dayText);
|
|
800
|
+
if (!Number.isFinite(year) || !Number.isFinite(month) || !Number.isFinite(day))
|
|
801
|
+
return undefined;
|
|
802
|
+
const date = new Date(year, month - 1, day);
|
|
803
|
+
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day ? date : undefined;
|
|
804
|
+
}
|
|
805
|
+
function compareKey$1(a, b) {
|
|
806
|
+
return a.localeCompare(b);
|
|
807
|
+
}
|
|
808
|
+
const lunarFormatter = (() => {
|
|
809
|
+
try {
|
|
810
|
+
return new Intl.DateTimeFormat("zh-CN-u-ca-chinese", { day: "numeric", month: "long" });
|
|
811
|
+
}
|
|
812
|
+
catch {
|
|
813
|
+
return undefined;
|
|
814
|
+
}
|
|
815
|
+
})();
|
|
816
|
+
function formatLunar(date) {
|
|
817
|
+
if (!lunarFormatter)
|
|
818
|
+
return undefined;
|
|
819
|
+
try {
|
|
820
|
+
return lunarFormatter.format(date).replace(/\s/g, "");
|
|
821
|
+
}
|
|
822
|
+
catch {
|
|
823
|
+
return undefined;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
class DatePickerController {
|
|
827
|
+
constructor(options = {}) {
|
|
828
|
+
this.limitDate = parseDate$1(options.limitDate) ? options.limitDate : undefined;
|
|
829
|
+
this.limitDirection = options.limitDirection === "after" || options.limitDirection === "before" ? options.limitDirection : undefined;
|
|
830
|
+
this.min = parseDate$1(options.min) ? options.min : undefined;
|
|
831
|
+
this.max = parseDate$1(options.max) ? options.max : undefined;
|
|
832
|
+
const base = parseDate$1(options.value) ?? new Date();
|
|
833
|
+
this.state = this.createState(base.getFullYear(), base.getMonth() + 1, options.value ?? "");
|
|
834
|
+
}
|
|
835
|
+
updateOptions(options = {}) {
|
|
836
|
+
this.limitDate = parseDate$1(options.limitDate) ? options.limitDate : undefined;
|
|
837
|
+
this.limitDirection = options.limitDirection === "after" || options.limitDirection === "before" ? options.limitDirection : undefined;
|
|
838
|
+
this.min = parseDate$1(options.min) ? options.min : undefined;
|
|
839
|
+
this.max = parseDate$1(options.max) ? options.max : undefined;
|
|
840
|
+
const base = parseDate$1(options.value) ?? new Date(this.state.year, this.state.month - 1, 1);
|
|
841
|
+
this.state = this.createState(base.getFullYear(), base.getMonth() + 1, options.value ?? "");
|
|
842
|
+
return this.getState();
|
|
843
|
+
}
|
|
844
|
+
moveMonth(delta) {
|
|
845
|
+
const date = new Date(this.state.year, this.state.month - 1 + delta, 1);
|
|
846
|
+
this.state = this.createState(date.getFullYear(), date.getMonth() + 1, this.state.value);
|
|
847
|
+
return this.getState();
|
|
848
|
+
}
|
|
849
|
+
select(value) {
|
|
850
|
+
if (!parseDate$1(value) || this.isDisabled(value))
|
|
851
|
+
return this.getState();
|
|
852
|
+
const date = parseDate$1(value);
|
|
853
|
+
this.state = this.createState(date.getFullYear(), date.getMonth() + 1, value);
|
|
854
|
+
return this.getState();
|
|
855
|
+
}
|
|
856
|
+
createYearOptions(start, end) {
|
|
857
|
+
const current = new Date().getFullYear();
|
|
858
|
+
const minYear = start ?? current - 50;
|
|
859
|
+
const maxYear = end ?? current + 50;
|
|
860
|
+
return Array.from({ length: Math.max(1, maxYear - minYear + 1) }, (_, index) => minYear + index);
|
|
861
|
+
}
|
|
862
|
+
getDaysInMonth(year, month) {
|
|
863
|
+
return new Date(year, month, 0).getDate();
|
|
864
|
+
}
|
|
865
|
+
getState() {
|
|
866
|
+
return { ...this.state, days: this.state.days.map((day) => ({ ...day })) };
|
|
867
|
+
}
|
|
868
|
+
isDisabled(value) {
|
|
869
|
+
return Boolean((this.min && compareKey$1(value, this.min) < 0) ||
|
|
870
|
+
(this.max && compareKey$1(value, this.max) > 0) ||
|
|
871
|
+
(this.limitDate && this.limitDirection === "before" && compareKey$1(value, this.limitDate) < 0) ||
|
|
872
|
+
(this.limitDate && this.limitDirection === "after" && compareKey$1(value, this.limitDate) > 0));
|
|
873
|
+
}
|
|
874
|
+
createState(year, month, value) {
|
|
875
|
+
const first = new Date(year, month - 1, 1);
|
|
876
|
+
const start = new Date(year, month - 1, 1 - first.getDay());
|
|
877
|
+
const today = toDateKey$1(new Date());
|
|
878
|
+
const days = Array.from({ length: 42 }, (_, index) => {
|
|
879
|
+
const date = new Date(start.getFullYear(), start.getMonth(), start.getDate() + index);
|
|
880
|
+
const key = toDateKey$1(date);
|
|
881
|
+
return {
|
|
882
|
+
date: key,
|
|
883
|
+
day: date.getDate(),
|
|
884
|
+
disabled: this.isDisabled(key),
|
|
885
|
+
inMonth: date.getMonth() === month - 1,
|
|
886
|
+
lunar: formatLunar(date),
|
|
887
|
+
selected: key === value,
|
|
888
|
+
today: key === today
|
|
889
|
+
};
|
|
890
|
+
});
|
|
891
|
+
return { days, month, value, year };
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function pad$1(value) {
|
|
896
|
+
return String(value).padStart(2, "0");
|
|
897
|
+
}
|
|
898
|
+
function toDateKey(date) {
|
|
899
|
+
return `${date.getFullYear()}-${pad$1(date.getMonth() + 1)}-${pad$1(date.getDate())}`;
|
|
900
|
+
}
|
|
901
|
+
function parseDate(value) {
|
|
902
|
+
if (!value || !/^\d{4}-\d{2}-\d{2}$/.test(value))
|
|
903
|
+
return undefined;
|
|
904
|
+
const [yearText, monthText, dayText] = value.split("-");
|
|
905
|
+
const year = Number(yearText);
|
|
906
|
+
const month = Number(monthText);
|
|
907
|
+
const day = Number(dayText);
|
|
908
|
+
if (!Number.isFinite(year) || !Number.isFinite(month) || !Number.isFinite(day))
|
|
909
|
+
return undefined;
|
|
910
|
+
const date = new Date(year, month - 1, day);
|
|
911
|
+
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day ? date : undefined;
|
|
912
|
+
}
|
|
913
|
+
function compareKey(a, b) {
|
|
914
|
+
if (!a || !b)
|
|
915
|
+
return 0;
|
|
916
|
+
return a.localeCompare(b);
|
|
917
|
+
}
|
|
918
|
+
function normalizeRange(value, allowSameDay = true) {
|
|
919
|
+
const start = parseDate(value?.start) ? value?.start : undefined;
|
|
920
|
+
const end = parseDate(value?.end) ? value?.end : undefined;
|
|
921
|
+
if (!allowSameDay && start && end && compareKey(start, end) === 0)
|
|
922
|
+
return { start, end: undefined };
|
|
923
|
+
if (start && end && compareKey(start, end) > 0)
|
|
924
|
+
return { start: end, end: start };
|
|
925
|
+
return { start, end };
|
|
926
|
+
}
|
|
927
|
+
function addMonths(date, delta) {
|
|
928
|
+
return new Date(date.getFullYear(), date.getMonth() + delta, 1);
|
|
929
|
+
}
|
|
930
|
+
class DateRangePickerController {
|
|
931
|
+
constructor(options = {}) {
|
|
932
|
+
this.allowSameDay = options.allowSameDay ?? true;
|
|
933
|
+
this.limitDate = parseDate(options.limitDate) ? options.limitDate : undefined;
|
|
934
|
+
this.limitDirection = options.limitDirection === "after" || options.limitDirection === "before" ? options.limitDirection : undefined;
|
|
935
|
+
this.min = parseDate(options.min) ? options.min : undefined;
|
|
936
|
+
this.max = parseDate(options.max) ? options.max : undefined;
|
|
937
|
+
const value = normalizeRange(options.value, this.allowSameDay);
|
|
938
|
+
const base = parseDate(value.start) ?? parseDate(value.end) ?? new Date();
|
|
939
|
+
this.state = this.createState(base.getFullYear(), base.getMonth() + 1, value);
|
|
940
|
+
}
|
|
941
|
+
updateOptions(options = {}) {
|
|
942
|
+
this.allowSameDay = options.allowSameDay ?? this.allowSameDay;
|
|
943
|
+
this.limitDate = parseDate(options.limitDate) ? options.limitDate : undefined;
|
|
944
|
+
this.limitDirection = options.limitDirection === "after" || options.limitDirection === "before" ? options.limitDirection : undefined;
|
|
945
|
+
this.min = parseDate(options.min) ? options.min : undefined;
|
|
946
|
+
this.max = parseDate(options.max) ? options.max : undefined;
|
|
947
|
+
const value = normalizeRange(options.value, this.allowSameDay);
|
|
948
|
+
const base = parseDate(value.start) ?? parseDate(value.end) ?? new Date(this.state.leftYear, this.state.leftMonth - 1, 1);
|
|
949
|
+
this.state = this.createState(base.getFullYear(), base.getMonth() + 1, value);
|
|
950
|
+
return this.getState();
|
|
951
|
+
}
|
|
952
|
+
moveMonth(delta) {
|
|
953
|
+
const base = new Date(this.state.leftYear, this.state.leftMonth - 1 + delta, 1);
|
|
954
|
+
this.state = this.createState(base.getFullYear(), base.getMonth() + 1, { start: this.state.start, end: this.state.end });
|
|
955
|
+
return this.getState();
|
|
956
|
+
}
|
|
957
|
+
hoverDate(value) {
|
|
958
|
+
this.hover = value && parseDate(value) && !this.isDisabled(value) ? value : undefined;
|
|
959
|
+
this.state = this.createState(this.state.leftYear, this.state.leftMonth, { start: this.state.start, end: this.state.end });
|
|
960
|
+
return this.getState();
|
|
961
|
+
}
|
|
962
|
+
select(value) {
|
|
963
|
+
if (!parseDate(value) || this.isDisabled(value))
|
|
964
|
+
return this.getState();
|
|
965
|
+
const current = { start: this.state.start, end: this.state.end };
|
|
966
|
+
let next;
|
|
967
|
+
if (!current.start || current.end || compareKey(value, current.start) < 0) {
|
|
968
|
+
next = { start: value, end: undefined };
|
|
969
|
+
}
|
|
970
|
+
else if (!this.allowSameDay && compareKey(value, current.start) === 0) {
|
|
971
|
+
next = { start: current.start, end: undefined };
|
|
972
|
+
}
|
|
973
|
+
else {
|
|
974
|
+
next = normalizeRange({ start: current.start, end: value }, this.allowSameDay);
|
|
975
|
+
this.hover = undefined;
|
|
976
|
+
}
|
|
977
|
+
const base = parseDate(next.start) ?? new Date(this.state.leftYear, this.state.leftMonth - 1, 1);
|
|
978
|
+
this.state = this.createState(base.getFullYear(), base.getMonth() + 1, next);
|
|
979
|
+
return this.getState();
|
|
980
|
+
}
|
|
981
|
+
clear() {
|
|
982
|
+
this.hover = undefined;
|
|
983
|
+
this.state = this.createState(this.state.leftYear, this.state.leftMonth, {});
|
|
984
|
+
return this.getState();
|
|
985
|
+
}
|
|
986
|
+
getValue() {
|
|
987
|
+
return { start: this.state.start, end: this.state.end };
|
|
988
|
+
}
|
|
989
|
+
getState() {
|
|
990
|
+
return {
|
|
991
|
+
...this.state,
|
|
992
|
+
leftDays: this.state.leftDays.map((day) => ({ ...day })),
|
|
993
|
+
rightDays: this.state.rightDays.map((day) => ({ ...day }))
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
isDisabled(value) {
|
|
997
|
+
return Boolean((this.min && compareKey(value, this.min) < 0) ||
|
|
998
|
+
(this.max && compareKey(value, this.max) > 0) ||
|
|
999
|
+
(this.limitDate && this.limitDirection === "before" && compareKey(value, this.limitDate) < 0) ||
|
|
1000
|
+
(this.limitDate && this.limitDirection === "after" && compareKey(value, this.limitDate) > 0));
|
|
1001
|
+
}
|
|
1002
|
+
createState(year, month, value) {
|
|
1003
|
+
const leftBase = new Date(year, month - 1, 1);
|
|
1004
|
+
const rightBase = addMonths(leftBase, 1);
|
|
1005
|
+
const range = normalizeRange(value, this.allowSameDay);
|
|
1006
|
+
const selecting = range.start && !range.end ? "end" : "start";
|
|
1007
|
+
return {
|
|
1008
|
+
end: range.end,
|
|
1009
|
+
leftDays: this.createMonthDays(leftBase.getFullYear(), leftBase.getMonth() + 1, range),
|
|
1010
|
+
leftMonth: leftBase.getMonth() + 1,
|
|
1011
|
+
leftYear: leftBase.getFullYear(),
|
|
1012
|
+
rightDays: this.createMonthDays(rightBase.getFullYear(), rightBase.getMonth() + 1, range),
|
|
1013
|
+
rightMonth: rightBase.getMonth() + 1,
|
|
1014
|
+
rightYear: rightBase.getFullYear(),
|
|
1015
|
+
selecting,
|
|
1016
|
+
start: range.start
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
createMonthDays(year, month, value) {
|
|
1020
|
+
const first = new Date(year, month - 1, 1);
|
|
1021
|
+
const start = new Date(year, month - 1, 1 - first.getDay());
|
|
1022
|
+
const today = toDateKey(new Date());
|
|
1023
|
+
const previewEnd = value.start && !value.end && this.hover ? (compareKey(this.hover, value.start) >= 0 ? this.hover : value.start) : undefined;
|
|
1024
|
+
const previewStart = value.start && !value.end && this.hover ? (compareKey(this.hover, value.start) >= 0 ? value.start : this.hover) : undefined;
|
|
1025
|
+
return Array.from({ length: 42 }, (_, index) => {
|
|
1026
|
+
const date = new Date(start.getFullYear(), start.getMonth(), start.getDate() + index);
|
|
1027
|
+
const key = toDateKey(date);
|
|
1028
|
+
const selectingEndSameDay = !this.allowSameDay && Boolean(value.start && !value.end && key === value.start);
|
|
1029
|
+
const selected = key === value.start || key === value.end;
|
|
1030
|
+
const inRange = Boolean(value.start && value.end && compareKey(key, value.start) >= 0 && compareKey(key, value.end) <= 0);
|
|
1031
|
+
const preview = Boolean(previewStart && previewEnd && compareKey(key, previewStart) >= 0 && compareKey(key, previewEnd) <= 0);
|
|
1032
|
+
return {
|
|
1033
|
+
date: key,
|
|
1034
|
+
day: date.getDate(),
|
|
1035
|
+
disabled: this.isDisabled(key) || selectingEndSameDay,
|
|
1036
|
+
inMonth: date.getMonth() === month - 1,
|
|
1037
|
+
inRange,
|
|
1038
|
+
preview,
|
|
1039
|
+
rangeEnd: key === value.end,
|
|
1040
|
+
rangeStart: key === value.start,
|
|
1041
|
+
selected,
|
|
1042
|
+
today: key === today
|
|
1043
|
+
};
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
class PasswordInputController {
|
|
1049
|
+
constructor(options = {}) {
|
|
1050
|
+
this.visible = options.visible ?? false;
|
|
1051
|
+
}
|
|
1052
|
+
setVisible(visible) {
|
|
1053
|
+
this.visible = visible;
|
|
1054
|
+
return this.getState();
|
|
1055
|
+
}
|
|
1056
|
+
toggle() {
|
|
1057
|
+
this.visible = !this.visible;
|
|
1058
|
+
return this.getState();
|
|
1059
|
+
}
|
|
1060
|
+
getState() {
|
|
1061
|
+
return {
|
|
1062
|
+
inputType: this.visible ? "text" : "password",
|
|
1063
|
+
visible: this.visible
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
const DEFAULT_WIDTH = 320;
|
|
1069
|
+
const DEFAULT_HEIGHT = 260;
|
|
1070
|
+
const DEFAULT_PIECE_SIZE = 52;
|
|
1071
|
+
const DEFAULT_TOLERANCE = 6;
|
|
1072
|
+
function finiteNumber(value, fallback) {
|
|
1073
|
+
return Number.isFinite(value) ? Number(value) : fallback;
|
|
1074
|
+
}
|
|
1075
|
+
function clamp$c(value, min, max) {
|
|
1076
|
+
return Math.min(max, Math.max(min, value));
|
|
1077
|
+
}
|
|
1078
|
+
class SlideCaptchaController {
|
|
1079
|
+
constructor(options = {}) {
|
|
1080
|
+
this.offsetX = 0;
|
|
1081
|
+
this.offsetY = 0;
|
|
1082
|
+
this.status = "idle";
|
|
1083
|
+
this.width = Math.max(160, finiteNumber(options.width, DEFAULT_WIDTH));
|
|
1084
|
+
this.height = Math.max(160, finiteNumber(options.height, DEFAULT_HEIGHT));
|
|
1085
|
+
this.pieceWidth = Math.max(24, finiteNumber(options.pieceWidth, DEFAULT_PIECE_SIZE));
|
|
1086
|
+
this.pieceHeight = Math.max(24, finiteNumber(options.pieceHeight, DEFAULT_PIECE_SIZE));
|
|
1087
|
+
this.moveAxis = options.moveAxis === "xy" ? "xy" : "x";
|
|
1088
|
+
this.originY = this.normalizeOriginY(options.originY);
|
|
1089
|
+
this.tolerance = Math.max(0, finiteNumber(options.tolerance, DEFAULT_TOLERANCE));
|
|
1090
|
+
this.targetX = this.normalizeTargetX(options.targetX);
|
|
1091
|
+
this.targetY = this.normalizeTargetY(options.targetY);
|
|
1092
|
+
this.value = Boolean(options.value);
|
|
1093
|
+
if (this.value) {
|
|
1094
|
+
this.offsetX = this.targetX;
|
|
1095
|
+
this.offsetY = this.moveAxis === "xy" ? this.targetY - this.originY : 0;
|
|
1096
|
+
this.status = "success";
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
updateOptions(options = {}) {
|
|
1100
|
+
if (options.width !== undefined)
|
|
1101
|
+
this.width = Math.max(160, finiteNumber(options.width, DEFAULT_WIDTH));
|
|
1102
|
+
if (options.height !== undefined)
|
|
1103
|
+
this.height = Math.max(160, finiteNumber(options.height, DEFAULT_HEIGHT));
|
|
1104
|
+
if (options.pieceWidth !== undefined)
|
|
1105
|
+
this.pieceWidth = Math.max(24, finiteNumber(options.pieceWidth, DEFAULT_PIECE_SIZE));
|
|
1106
|
+
if (options.pieceHeight !== undefined)
|
|
1107
|
+
this.pieceHeight = Math.max(24, finiteNumber(options.pieceHeight, DEFAULT_PIECE_SIZE));
|
|
1108
|
+
if (options.moveAxis !== undefined)
|
|
1109
|
+
this.moveAxis = options.moveAxis === "xy" ? "xy" : "x";
|
|
1110
|
+
if (options.originY !== undefined || options.height !== undefined || options.pieceHeight !== undefined) {
|
|
1111
|
+
this.originY = this.normalizeOriginY(options.originY ?? this.originY);
|
|
1112
|
+
}
|
|
1113
|
+
if (options.tolerance !== undefined)
|
|
1114
|
+
this.tolerance = Math.max(0, finiteNumber(options.tolerance, DEFAULT_TOLERANCE));
|
|
1115
|
+
if (options.targetX !== undefined || options.width !== undefined || options.pieceWidth !== undefined) {
|
|
1116
|
+
this.targetX = this.normalizeTargetX(options.targetX ?? this.targetX);
|
|
1117
|
+
}
|
|
1118
|
+
if (options.targetY !== undefined || options.originY !== undefined || options.height !== undefined || options.pieceHeight !== undefined) {
|
|
1119
|
+
this.targetY = this.normalizeTargetY(options.targetY ?? this.targetY);
|
|
1120
|
+
}
|
|
1121
|
+
if (options.value !== undefined) {
|
|
1122
|
+
this.value = Boolean(options.value);
|
|
1123
|
+
this.status = this.value ? "success" : "idle";
|
|
1124
|
+
this.offsetX = this.value ? this.targetX : 0;
|
|
1125
|
+
this.offsetY = this.value && this.moveAxis === "xy" ? this.targetY - this.originY : 0;
|
|
1126
|
+
}
|
|
1127
|
+
else {
|
|
1128
|
+
this.offsetX = clamp$c(this.offsetX, 0, this.getMaxOffset());
|
|
1129
|
+
this.offsetY =
|
|
1130
|
+
this.moveAxis === "xy"
|
|
1131
|
+
? clamp$c(this.offsetY, this.getMinOffsetY(), this.getMaxOffsetY())
|
|
1132
|
+
: 0;
|
|
1133
|
+
}
|
|
1134
|
+
return this.getState();
|
|
1135
|
+
}
|
|
1136
|
+
start() {
|
|
1137
|
+
if (this.value)
|
|
1138
|
+
return this.getState();
|
|
1139
|
+
this.status = "dragging";
|
|
1140
|
+
return this.getState();
|
|
1141
|
+
}
|
|
1142
|
+
move(offsetX, offsetY = 0) {
|
|
1143
|
+
if (this.value)
|
|
1144
|
+
return this.getState();
|
|
1145
|
+
this.offsetX = clamp$c(finiteNumber(offsetX, 0), 0, this.getMaxOffset());
|
|
1146
|
+
this.offsetY =
|
|
1147
|
+
this.moveAxis === "xy"
|
|
1148
|
+
? clamp$c(finiteNumber(offsetY, 0), this.getMinOffsetY(), this.getMaxOffsetY())
|
|
1149
|
+
: 0;
|
|
1150
|
+
this.status = "dragging";
|
|
1151
|
+
return this.getState();
|
|
1152
|
+
}
|
|
1153
|
+
verify() {
|
|
1154
|
+
const success = Math.abs(this.offsetX - this.targetX) <= this.tolerance &&
|
|
1155
|
+
(this.moveAxis === "x" ||
|
|
1156
|
+
Math.abs(this.originY + this.offsetY - this.targetY) <= this.tolerance);
|
|
1157
|
+
this.value = success;
|
|
1158
|
+
this.status = success ? "success" : "failed";
|
|
1159
|
+
if (success) {
|
|
1160
|
+
this.offsetX = this.targetX;
|
|
1161
|
+
this.offsetY = this.moveAxis === "xy" ? this.targetY - this.originY : 0;
|
|
1162
|
+
}
|
|
1163
|
+
return this.getState();
|
|
1164
|
+
}
|
|
1165
|
+
reset() {
|
|
1166
|
+
this.offsetX = 0;
|
|
1167
|
+
this.offsetY = 0;
|
|
1168
|
+
this.status = "idle";
|
|
1169
|
+
this.value = false;
|
|
1170
|
+
return this.getState();
|
|
1171
|
+
}
|
|
1172
|
+
getState() {
|
|
1173
|
+
const maxOffset = this.getMaxOffset();
|
|
1174
|
+
const minOffsetY = this.getMinOffsetY();
|
|
1175
|
+
const maxOffsetY = this.getMaxOffsetY();
|
|
1176
|
+
return {
|
|
1177
|
+
height: this.height,
|
|
1178
|
+
maxOffset,
|
|
1179
|
+
maxOffsetY,
|
|
1180
|
+
minOffsetY,
|
|
1181
|
+
moveAxis: this.moveAxis,
|
|
1182
|
+
offsetX: this.offsetX,
|
|
1183
|
+
offsetY: this.offsetY,
|
|
1184
|
+
originY: this.originY,
|
|
1185
|
+
pieceHeight: this.pieceHeight,
|
|
1186
|
+
pieceWidth: this.pieceWidth,
|
|
1187
|
+
progress: maxOffset > 0 ? this.offsetX / maxOffset : 0,
|
|
1188
|
+
status: this.status,
|
|
1189
|
+
targetX: this.targetX,
|
|
1190
|
+
targetY: this.targetY,
|
|
1191
|
+
tolerance: this.tolerance,
|
|
1192
|
+
value: this.value,
|
|
1193
|
+
width: this.width
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
getMaxOffset() {
|
|
1197
|
+
return Math.max(0, this.width - this.pieceWidth);
|
|
1198
|
+
}
|
|
1199
|
+
getMinOffsetY() {
|
|
1200
|
+
return -this.originY;
|
|
1201
|
+
}
|
|
1202
|
+
getMaxOffsetY() {
|
|
1203
|
+
return Math.max(this.getMinOffsetY(), this.height - this.pieceHeight - this.originY);
|
|
1204
|
+
}
|
|
1205
|
+
normalizeOriginY(value) {
|
|
1206
|
+
return clamp$c(finiteNumber(value, 0), 0, Math.max(0, this.height - this.pieceHeight));
|
|
1207
|
+
}
|
|
1208
|
+
normalizeTargetX(value) {
|
|
1209
|
+
return clamp$c(finiteNumber(value, this.width * 0.62), 0, this.getMaxOffset());
|
|
1210
|
+
}
|
|
1211
|
+
normalizeTargetY(value) {
|
|
1212
|
+
return clamp$c(finiteNumber(value, this.originY), 0, Math.max(0, this.height - this.pieceHeight));
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
function normalizeLength(length) {
|
|
1217
|
+
return Math.min(12, Math.max(1, Math.floor(length ?? 6)));
|
|
1218
|
+
}
|
|
1219
|
+
function normalizeValue$1(value, length) {
|
|
1220
|
+
return value.replace(/\s+/g, "").slice(0, length);
|
|
1221
|
+
}
|
|
1222
|
+
class VerificationCodeController {
|
|
1223
|
+
constructor(options = {}) {
|
|
1224
|
+
this.length = normalizeLength(options.length);
|
|
1225
|
+
this.value = normalizeValue$1(options.value ?? "", this.length);
|
|
1226
|
+
}
|
|
1227
|
+
updateOptions(options = {}) {
|
|
1228
|
+
if (options.length !== undefined)
|
|
1229
|
+
this.length = normalizeLength(options.length);
|
|
1230
|
+
if (options.value !== undefined)
|
|
1231
|
+
this.value = normalizeValue$1(options.value, this.length);
|
|
1232
|
+
else
|
|
1233
|
+
this.value = normalizeValue$1(this.value, this.length);
|
|
1234
|
+
return this.getState();
|
|
1235
|
+
}
|
|
1236
|
+
getNextInputIndex(preferredIndex = 0) {
|
|
1237
|
+
const chars = this.getState().chars;
|
|
1238
|
+
const firstEmpty = chars.findIndex((item) => !item);
|
|
1239
|
+
if (firstEmpty >= 0)
|
|
1240
|
+
return firstEmpty;
|
|
1241
|
+
return Math.min(this.length - 1, Math.max(0, preferredIndex));
|
|
1242
|
+
}
|
|
1243
|
+
input(index, char) {
|
|
1244
|
+
return this.inputAtNextSlot(index, char).state;
|
|
1245
|
+
}
|
|
1246
|
+
inputAtNextSlot(index, char) {
|
|
1247
|
+
const chars = this.getState().chars;
|
|
1248
|
+
const writeIndex = this.getNextInputIndex(index);
|
|
1249
|
+
if (writeIndex < 0 || writeIndex >= this.length) {
|
|
1250
|
+
return { focusIndex: Math.min(this.length - 1, Math.max(0, index)), state: this.getState(), writeIndex };
|
|
1251
|
+
}
|
|
1252
|
+
chars[writeIndex] = char.slice(-1);
|
|
1253
|
+
this.value = normalizeValue$1(chars.join(""), this.length);
|
|
1254
|
+
return {
|
|
1255
|
+
focusIndex: Math.min(this.length - 1, writeIndex + 1),
|
|
1256
|
+
state: this.getState(),
|
|
1257
|
+
writeIndex
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
paste(value, startIndex = 0) {
|
|
1261
|
+
const chars = this.getState().chars;
|
|
1262
|
+
normalizeValue$1(value, this.length).split("").forEach((char, offset) => {
|
|
1263
|
+
const index = startIndex + offset;
|
|
1264
|
+
if (index >= 0 && index < this.length)
|
|
1265
|
+
chars[index] = char;
|
|
1266
|
+
});
|
|
1267
|
+
this.value = normalizeValue$1(chars.join(""), this.length);
|
|
1268
|
+
return this.getState();
|
|
1269
|
+
}
|
|
1270
|
+
remove(index) {
|
|
1271
|
+
if (index < 0 || index >= this.length)
|
|
1272
|
+
return this.getState();
|
|
1273
|
+
const chars = this.getState().chars;
|
|
1274
|
+
chars[index] = "";
|
|
1275
|
+
this.value = normalizeValue$1(chars.join(""), this.length);
|
|
1276
|
+
return this.getState();
|
|
1277
|
+
}
|
|
1278
|
+
clear() {
|
|
1279
|
+
this.value = "";
|
|
1280
|
+
return this.getState();
|
|
1281
|
+
}
|
|
1282
|
+
getState() {
|
|
1283
|
+
const chars = Array.from({ length: this.length }, (_, index) => this.value[index] ?? "");
|
|
1284
|
+
return { chars, complete: chars.every(Boolean), length: this.length, value: chars.join("") };
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
class ModalController {
|
|
1289
|
+
constructor(open = false) {
|
|
1290
|
+
this.emitter = new StateEmitter();
|
|
1291
|
+
this.openState = open;
|
|
1292
|
+
}
|
|
1293
|
+
isOpen() {
|
|
1294
|
+
return this.openState;
|
|
1295
|
+
}
|
|
1296
|
+
open() {
|
|
1297
|
+
this.setOpen(true);
|
|
1298
|
+
}
|
|
1299
|
+
close() {
|
|
1300
|
+
this.setOpen(false);
|
|
1301
|
+
}
|
|
1302
|
+
toggle() {
|
|
1303
|
+
this.setOpen(!this.openState);
|
|
1304
|
+
}
|
|
1305
|
+
setOpen(open) {
|
|
1306
|
+
if (this.openState === open)
|
|
1307
|
+
return;
|
|
1308
|
+
this.openState = open;
|
|
1309
|
+
this.emitter.emit(this.openState);
|
|
1310
|
+
}
|
|
1311
|
+
subscribe(listener) {
|
|
1312
|
+
listener(this.openState);
|
|
1313
|
+
return this.emitter.subscribe(listener);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
function clamp$b(value, min, max) {
|
|
1318
|
+
return Math.min(max, Math.max(min, value));
|
|
1319
|
+
}
|
|
1320
|
+
class FloatingBallController {
|
|
1321
|
+
constructor(options = {}) {
|
|
1322
|
+
this.adsorb = options.adsorb ?? true;
|
|
1323
|
+
this.adsorbAxis = options.adsorbAxis ?? "xy";
|
|
1324
|
+
this.boundary = options.boundary;
|
|
1325
|
+
this.gap = Math.max(0, options.gap ?? 16);
|
|
1326
|
+
this.moveAxis = options.moveAxis ?? "xy";
|
|
1327
|
+
this.position = options.initialPosition ?? { x: this.gap, y: this.gap };
|
|
1328
|
+
}
|
|
1329
|
+
updateOptions(options) {
|
|
1330
|
+
if (options.adsorb !== undefined)
|
|
1331
|
+
this.adsorb = options.adsorb;
|
|
1332
|
+
if (options.adsorbAxis !== undefined)
|
|
1333
|
+
this.adsorbAxis = options.adsorbAxis;
|
|
1334
|
+
if (options.boundary !== undefined)
|
|
1335
|
+
this.boundary = options.boundary;
|
|
1336
|
+
if (options.gap !== undefined)
|
|
1337
|
+
this.gap = Math.max(0, options.gap);
|
|
1338
|
+
if (options.moveAxis !== undefined)
|
|
1339
|
+
this.moveAxis = options.moveAxis;
|
|
1340
|
+
return this.getState();
|
|
1341
|
+
}
|
|
1342
|
+
move(position, viewport, size) {
|
|
1343
|
+
this.position = this.clampToViewport({
|
|
1344
|
+
x: this.moveAxis === "y" ? this.position.x : position.x,
|
|
1345
|
+
y: this.moveAxis === "x" ? this.position.y : position.y
|
|
1346
|
+
}, this.boundary ?? viewport, size);
|
|
1347
|
+
this.edge = undefined;
|
|
1348
|
+
return this.getState();
|
|
1349
|
+
}
|
|
1350
|
+
release(viewport, size) {
|
|
1351
|
+
const bounds = this.boundary ?? viewport;
|
|
1352
|
+
if (!this.adsorb) {
|
|
1353
|
+
this.position = this.clampToViewport(this.position, bounds, size);
|
|
1354
|
+
return this.getState();
|
|
1355
|
+
}
|
|
1356
|
+
const distances = {
|
|
1357
|
+
bottom: bounds.height - (this.position.y + size.height),
|
|
1358
|
+
left: this.position.x,
|
|
1359
|
+
right: bounds.width - (this.position.x + size.width),
|
|
1360
|
+
top: this.position.y
|
|
1361
|
+
};
|
|
1362
|
+
const adsorbEdges = this.adsorbAxis === "x"
|
|
1363
|
+
? ["left", "right"]
|
|
1364
|
+
: this.adsorbAxis === "y"
|
|
1365
|
+
? ["top", "bottom"]
|
|
1366
|
+
: ["left", "right", "top", "bottom"];
|
|
1367
|
+
this.edge = adsorbEdges.reduce((best, edge) => distances[edge] < distances[best] ? edge : best);
|
|
1368
|
+
const next = { ...this.position };
|
|
1369
|
+
if (this.edge === "left")
|
|
1370
|
+
next.x = this.gap;
|
|
1371
|
+
if (this.edge === "right")
|
|
1372
|
+
next.x = bounds.width - size.width - this.gap;
|
|
1373
|
+
if (this.edge === "top")
|
|
1374
|
+
next.y = this.gap;
|
|
1375
|
+
if (this.edge === "bottom")
|
|
1376
|
+
next.y = bounds.height - size.height - this.gap;
|
|
1377
|
+
this.position = this.clampToViewport(next, bounds, size);
|
|
1378
|
+
return this.getState();
|
|
1379
|
+
}
|
|
1380
|
+
getState() {
|
|
1381
|
+
return {
|
|
1382
|
+
adsorb: this.adsorb,
|
|
1383
|
+
adsorbAxis: this.adsorbAxis,
|
|
1384
|
+
edge: this.edge,
|
|
1385
|
+
gap: this.gap,
|
|
1386
|
+
moveAxis: this.moveAxis,
|
|
1387
|
+
position: { ...this.position }
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
clampToViewport(position, viewport, size) {
|
|
1391
|
+
return {
|
|
1392
|
+
x: clamp$b(position.x, this.gap, Math.max(this.gap, viewport.width - size.width - this.gap)),
|
|
1393
|
+
y: clamp$b(position.y, this.gap, Math.max(this.gap, viewport.height - size.height - this.gap))
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
class PopupController {
|
|
1399
|
+
constructor(open = false, placement = "bottom") {
|
|
1400
|
+
this.emitter = new StateEmitter();
|
|
1401
|
+
this.openState = open;
|
|
1402
|
+
this.placementState = placement;
|
|
1403
|
+
}
|
|
1404
|
+
isOpen() {
|
|
1405
|
+
return this.openState;
|
|
1406
|
+
}
|
|
1407
|
+
getPlacement() {
|
|
1408
|
+
return this.placementState;
|
|
1409
|
+
}
|
|
1410
|
+
getState() {
|
|
1411
|
+
return {
|
|
1412
|
+
open: this.openState,
|
|
1413
|
+
placement: this.placementState
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
open() {
|
|
1417
|
+
this.setOpen(true);
|
|
1418
|
+
}
|
|
1419
|
+
close() {
|
|
1420
|
+
this.setOpen(false);
|
|
1421
|
+
}
|
|
1422
|
+
toggle() {
|
|
1423
|
+
this.setOpen(!this.openState);
|
|
1424
|
+
}
|
|
1425
|
+
setOpen(open) {
|
|
1426
|
+
if (this.openState === open)
|
|
1427
|
+
return;
|
|
1428
|
+
this.openState = open;
|
|
1429
|
+
this.emit();
|
|
1430
|
+
}
|
|
1431
|
+
setPlacement(placement) {
|
|
1432
|
+
if (this.placementState === placement)
|
|
1433
|
+
return;
|
|
1434
|
+
this.placementState = placement;
|
|
1435
|
+
this.emit();
|
|
1436
|
+
}
|
|
1437
|
+
update(state) {
|
|
1438
|
+
const nextOpen = state.open ?? this.openState;
|
|
1439
|
+
const nextPlacement = state.placement ?? this.placementState;
|
|
1440
|
+
if (nextOpen === this.openState && nextPlacement === this.placementState)
|
|
1441
|
+
return;
|
|
1442
|
+
this.openState = nextOpen;
|
|
1443
|
+
this.placementState = nextPlacement;
|
|
1444
|
+
this.emit();
|
|
1445
|
+
}
|
|
1446
|
+
subscribe(listener) {
|
|
1447
|
+
listener(this.getState());
|
|
1448
|
+
return this.emitter.subscribe(listener);
|
|
1449
|
+
}
|
|
1450
|
+
emit() {
|
|
1451
|
+
this.emitter.emit(this.getState());
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
class TooltipController {
|
|
1456
|
+
constructor(open = false) {
|
|
1457
|
+
this.emitter = new StateEmitter();
|
|
1458
|
+
this.openState = open;
|
|
1459
|
+
}
|
|
1460
|
+
isOpen() {
|
|
1461
|
+
return this.openState;
|
|
1462
|
+
}
|
|
1463
|
+
getState() {
|
|
1464
|
+
return { open: this.openState };
|
|
1465
|
+
}
|
|
1466
|
+
subscribe(listener) {
|
|
1467
|
+
listener(this.getState());
|
|
1468
|
+
return this.emitter.subscribe(listener);
|
|
1469
|
+
}
|
|
1470
|
+
setOpen(open) {
|
|
1471
|
+
if (this.openState === open)
|
|
1472
|
+
return;
|
|
1473
|
+
this.openState = open;
|
|
1474
|
+
this.emit();
|
|
1475
|
+
}
|
|
1476
|
+
open() {
|
|
1477
|
+
this.setOpen(true);
|
|
1478
|
+
}
|
|
1479
|
+
close() {
|
|
1480
|
+
this.setOpen(false);
|
|
1481
|
+
}
|
|
1482
|
+
toggle() {
|
|
1483
|
+
this.setOpen(!this.openState);
|
|
1484
|
+
}
|
|
1485
|
+
destroy() {
|
|
1486
|
+
this.emitter.clear();
|
|
1487
|
+
}
|
|
1488
|
+
emit() {
|
|
1489
|
+
this.emitter.emit(this.getState());
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
class AffixController {
|
|
1494
|
+
constructor(offsetTop = 0) {
|
|
1495
|
+
this.offsetTop = Math.max(0, Number.isFinite(offsetTop) ? offsetTop : 0);
|
|
1496
|
+
}
|
|
1497
|
+
update(offsetTop = 0) {
|
|
1498
|
+
this.offsetTop = Math.max(0, Number.isFinite(offsetTop) ? offsetTop : 0);
|
|
1499
|
+
return this.resolve(0);
|
|
1500
|
+
}
|
|
1501
|
+
resolve(top) {
|
|
1502
|
+
return { fixed: top <= this.offsetTop, offsetTop: this.offsetTop };
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
class BacktopController {
|
|
1507
|
+
constructor(visibilityHeight = 240) {
|
|
1508
|
+
this.visibilityHeight = Math.max(0, Number.isFinite(visibilityHeight) ? visibilityHeight : 240);
|
|
1509
|
+
this.hysteresis = this.resolveHysteresis();
|
|
1510
|
+
}
|
|
1511
|
+
update(visibilityHeight = 240) {
|
|
1512
|
+
this.visibilityHeight = Math.max(0, Number.isFinite(visibilityHeight) ? visibilityHeight : 240);
|
|
1513
|
+
this.hysteresis = this.resolveHysteresis();
|
|
1514
|
+
return this.resolve(0);
|
|
1515
|
+
}
|
|
1516
|
+
resolve(scrollTop, previousVisible = false) {
|
|
1517
|
+
const safeScrollTop = Math.max(0, Number.isFinite(scrollTop) ? scrollTop : 0);
|
|
1518
|
+
const threshold = previousVisible ? Math.max(0, this.visibilityHeight - this.hysteresis) : this.visibilityHeight;
|
|
1519
|
+
return { visible: safeScrollTop >= threshold };
|
|
1520
|
+
}
|
|
1521
|
+
resolveHysteresis() {
|
|
1522
|
+
return Math.min(32, Math.max(8, Math.round(this.visibilityHeight * 0.08)));
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
function createId() {
|
|
1527
|
+
return `toast-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
1528
|
+
}
|
|
1529
|
+
class ToastManager {
|
|
1530
|
+
constructor() {
|
|
1531
|
+
this.emitter = new StateEmitter();
|
|
1532
|
+
this.timers = new Map();
|
|
1533
|
+
this.items = [];
|
|
1534
|
+
}
|
|
1535
|
+
getToasts() {
|
|
1536
|
+
return [...this.items];
|
|
1537
|
+
}
|
|
1538
|
+
show(options) {
|
|
1539
|
+
const toast = {
|
|
1540
|
+
id: options.id ?? createId(),
|
|
1541
|
+
title: options.title,
|
|
1542
|
+
message: options.message,
|
|
1543
|
+
tone: options.tone ?? "info",
|
|
1544
|
+
duration: options.duration ?? 3000,
|
|
1545
|
+
position: options.position ?? "top-right",
|
|
1546
|
+
};
|
|
1547
|
+
this.items = [toast, ...this.items.filter((item) => item.id !== toast.id)];
|
|
1548
|
+
this.scheduleDismiss(toast);
|
|
1549
|
+
this.notify();
|
|
1550
|
+
return toast.id;
|
|
1551
|
+
}
|
|
1552
|
+
dismiss(id) {
|
|
1553
|
+
const timer = this.timers.get(id);
|
|
1554
|
+
if (timer)
|
|
1555
|
+
clearTimeout(timer);
|
|
1556
|
+
this.timers.delete(id);
|
|
1557
|
+
this.items = this.items.filter((item) => item.id !== id);
|
|
1558
|
+
this.notify();
|
|
1559
|
+
}
|
|
1560
|
+
clear() {
|
|
1561
|
+
this.timers.forEach((timer) => clearTimeout(timer));
|
|
1562
|
+
this.timers.clear();
|
|
1563
|
+
this.items = [];
|
|
1564
|
+
this.notify();
|
|
1565
|
+
}
|
|
1566
|
+
subscribe(listener) {
|
|
1567
|
+
listener(this.getToasts());
|
|
1568
|
+
return this.emitter.subscribe(listener);
|
|
1569
|
+
}
|
|
1570
|
+
scheduleDismiss(toast) {
|
|
1571
|
+
const existing = this.timers.get(toast.id);
|
|
1572
|
+
if (existing)
|
|
1573
|
+
clearTimeout(existing);
|
|
1574
|
+
if (toast.duration <= 0)
|
|
1575
|
+
return;
|
|
1576
|
+
this.timers.set(toast.id, setTimeout(() => this.dismiss(toast.id), toast.duration));
|
|
1577
|
+
}
|
|
1578
|
+
notify() {
|
|
1579
|
+
this.emitter.emit(this.getToasts());
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
function getSafeTooltipPlacement(triggerRect, tooltipRect, preferred, viewportWidth = window.innerWidth, viewportHeight = window.innerHeight, margin = 8) {
|
|
1584
|
+
const fits = {
|
|
1585
|
+
top: triggerRect.top >= tooltipRect.height + margin,
|
|
1586
|
+
bottom: viewportHeight - triggerRect.bottom >= tooltipRect.height + margin,
|
|
1587
|
+
left: triggerRect.left >= tooltipRect.width + margin,
|
|
1588
|
+
right: viewportWidth - triggerRect.right >= tooltipRect.width + margin
|
|
1589
|
+
};
|
|
1590
|
+
if (preferred.startsWith("top") && fits.top)
|
|
1591
|
+
return preferred;
|
|
1592
|
+
if (preferred.startsWith("bottom") && fits.bottom)
|
|
1593
|
+
return preferred;
|
|
1594
|
+
if (preferred.startsWith("left") && fits.left)
|
|
1595
|
+
return preferred;
|
|
1596
|
+
if (preferred.startsWith("right") && fits.right)
|
|
1597
|
+
return preferred;
|
|
1598
|
+
if (fits.top)
|
|
1599
|
+
return "top";
|
|
1600
|
+
if (fits.bottom)
|
|
1601
|
+
return "bottom";
|
|
1602
|
+
if (fits.right)
|
|
1603
|
+
return "right";
|
|
1604
|
+
if (fits.left)
|
|
1605
|
+
return "left";
|
|
1606
|
+
return preferred;
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
class TabsController {
|
|
1610
|
+
constructor(tabs, activeId) {
|
|
1611
|
+
this.emitter = new StateEmitter();
|
|
1612
|
+
this.tabs = tabs;
|
|
1613
|
+
this.activeId = activeId ?? tabs.find((tab) => !tab.disabled)?.id ?? tabs[0]?.id ?? "";
|
|
1614
|
+
}
|
|
1615
|
+
getActiveId() {
|
|
1616
|
+
return this.activeId;
|
|
1617
|
+
}
|
|
1618
|
+
setTabs(tabs) {
|
|
1619
|
+
this.tabs = tabs;
|
|
1620
|
+
if (!this.tabs.some((tab) => tab.id === this.activeId && !tab.disabled)) {
|
|
1621
|
+
this.activeId = this.tabs.find((tab) => !tab.disabled)?.id ?? this.tabs[0]?.id ?? "";
|
|
1622
|
+
this.emitter.emit(this.activeId);
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
activate(id) {
|
|
1626
|
+
const tab = this.tabs.find((item) => item.id === id);
|
|
1627
|
+
if (!tab || tab.disabled || this.activeId === id)
|
|
1628
|
+
return;
|
|
1629
|
+
this.activeId = id;
|
|
1630
|
+
this.emitter.emit(this.activeId);
|
|
1631
|
+
}
|
|
1632
|
+
subscribe(listener) {
|
|
1633
|
+
listener(this.activeId);
|
|
1634
|
+
return this.emitter.subscribe(listener);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
class BreadcrumbController {
|
|
1639
|
+
constructor(items = []) {
|
|
1640
|
+
this.items = this.normalize(items);
|
|
1641
|
+
}
|
|
1642
|
+
update(items = []) {
|
|
1643
|
+
this.items = this.normalize(items);
|
|
1644
|
+
return this.getState();
|
|
1645
|
+
}
|
|
1646
|
+
getState() {
|
|
1647
|
+
return { items: this.items.map((item) => ({ ...item })) };
|
|
1648
|
+
}
|
|
1649
|
+
normalize(items) {
|
|
1650
|
+
return items.filter((item) => item && String(item.label ?? "").trim()).map((item, index) => ({ ...item, key: item.key ?? index }));
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
class PaginationController {
|
|
1655
|
+
constructor(options = {}) {
|
|
1656
|
+
this.state = this.normalize(options);
|
|
1657
|
+
}
|
|
1658
|
+
update(options = {}) {
|
|
1659
|
+
this.state = this.normalize(options);
|
|
1660
|
+
return this.getState();
|
|
1661
|
+
}
|
|
1662
|
+
setCurrent(page) {
|
|
1663
|
+
this.state = this.normalize({ ...this.state, current: page });
|
|
1664
|
+
return this.getState();
|
|
1665
|
+
}
|
|
1666
|
+
getState() {
|
|
1667
|
+
return { ...this.state, pages: [...this.state.pages] };
|
|
1668
|
+
}
|
|
1669
|
+
normalize(options) {
|
|
1670
|
+
const boundaryCount = Math.max(1, Math.floor(Number.isFinite(options.boundaryCount) ? Number(options.boundaryCount) : 1));
|
|
1671
|
+
const siblingCount = Math.max(0, Math.floor(Number.isFinite(options.siblingCount) ? Number(options.siblingCount) : 1));
|
|
1672
|
+
const total = Math.max(0, Math.floor(Number.isFinite(options.total) ? Number(options.total) : 0));
|
|
1673
|
+
const pageSize = Math.max(1, Math.floor(Number.isFinite(options.pageSize) ? Number(options.pageSize) : 10));
|
|
1674
|
+
const pageCount = Math.max(1, Math.ceil(total / pageSize));
|
|
1675
|
+
const current = Math.max(1, Math.min(pageCount, Math.floor(Number.isFinite(options.current) ? Number(options.current) : 1)));
|
|
1676
|
+
const pages = this.createPages(current, pageCount, boundaryCount, siblingCount);
|
|
1677
|
+
return { boundaryCount, current, pageCount, pageSize, pages, siblingCount, total };
|
|
1678
|
+
}
|
|
1679
|
+
createPages(current, pageCount, boundaryCount, siblingCount) {
|
|
1680
|
+
const allCount = boundaryCount * 2 + siblingCount * 2 + 3;
|
|
1681
|
+
if (pageCount <= allCount)
|
|
1682
|
+
return Array.from({ length: pageCount }, (_, index) => index + 1);
|
|
1683
|
+
const pages = [];
|
|
1684
|
+
const addPage = (page) => {
|
|
1685
|
+
if (!pages.includes(page))
|
|
1686
|
+
pages.push(page);
|
|
1687
|
+
};
|
|
1688
|
+
for (let page = 1; page <= Math.min(boundaryCount, pageCount); page += 1)
|
|
1689
|
+
addPage(page);
|
|
1690
|
+
const siblingStart = Math.max(boundaryCount + 1, Math.min(current - siblingCount, pageCount - boundaryCount - siblingCount * 2));
|
|
1691
|
+
const siblingEnd = Math.min(pageCount - boundaryCount, Math.max(current + siblingCount, boundaryCount + 1 + siblingCount * 2));
|
|
1692
|
+
if (siblingStart > boundaryCount + 1)
|
|
1693
|
+
pages.push("ellipsis");
|
|
1694
|
+
for (let page = siblingStart; page <= siblingEnd; page += 1)
|
|
1695
|
+
addPage(page);
|
|
1696
|
+
if (siblingEnd < pageCount - boundaryCount)
|
|
1697
|
+
pages.push("ellipsis");
|
|
1698
|
+
for (let page = Math.max(pageCount - boundaryCount + 1, 1); page <= pageCount; page += 1)
|
|
1699
|
+
addPage(page);
|
|
1700
|
+
return pages;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
class BadgeController {
|
|
1705
|
+
constructor(options = {}) {
|
|
1706
|
+
this.state = this.normalize(options);
|
|
1707
|
+
}
|
|
1708
|
+
update(options = {}) {
|
|
1709
|
+
this.state = this.normalize(options);
|
|
1710
|
+
return this.getState();
|
|
1711
|
+
}
|
|
1712
|
+
getState() {
|
|
1713
|
+
return { ...this.state };
|
|
1714
|
+
}
|
|
1715
|
+
normalize(options) {
|
|
1716
|
+
const max = Number.isFinite(options.max) ? Math.max(1, Number(options.max)) : 99;
|
|
1717
|
+
const value = typeof options.value === "number" && options.value > max ? `${max}+` : String(options.value ?? "");
|
|
1718
|
+
return {
|
|
1719
|
+
displayValue: options.dot ? "" : value,
|
|
1720
|
+
dot: Boolean(options.dot),
|
|
1721
|
+
tone: options.tone ?? "danger"
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
class CalendarController {
|
|
1727
|
+
constructor(options = {}) {
|
|
1728
|
+
this.controller = new DatePickerController(options);
|
|
1729
|
+
}
|
|
1730
|
+
updateOptions(options = {}) {
|
|
1731
|
+
this.controller.updateOptions(options);
|
|
1732
|
+
return this.getState();
|
|
1733
|
+
}
|
|
1734
|
+
moveMonth(delta) {
|
|
1735
|
+
this.controller.moveMonth(delta);
|
|
1736
|
+
return this.getState();
|
|
1737
|
+
}
|
|
1738
|
+
select(value) {
|
|
1739
|
+
this.controller.select(value);
|
|
1740
|
+
return this.getState();
|
|
1741
|
+
}
|
|
1742
|
+
getState() {
|
|
1743
|
+
const state = this.controller.getState();
|
|
1744
|
+
const locale = getClassComponentsLocale();
|
|
1745
|
+
return {
|
|
1746
|
+
days: state.days,
|
|
1747
|
+
month: state.month,
|
|
1748
|
+
title: `${state.year}${locale.dateYearUnit} ${state.month}${locale.dateMonthUnit}`,
|
|
1749
|
+
value: state.value,
|
|
1750
|
+
year: state.year
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
const MIN_NODE_WIDTH = 32;
|
|
1756
|
+
const MAX_NODE_WIDTH = 320;
|
|
1757
|
+
const DEFAULT_NODE_WIDTH = 160;
|
|
1758
|
+
const DEFAULT_NODE_HEIGHT = 64;
|
|
1759
|
+
const DEFAULT_GAP_X = 220;
|
|
1760
|
+
const MIN_NODE_GAP_Y = 4;
|
|
1761
|
+
function clamp$a(value, min, max) {
|
|
1762
|
+
return Math.min(max, Math.max(min, value));
|
|
1763
|
+
}
|
|
1764
|
+
function finiteOr$3(value, fallback) {
|
|
1765
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
1766
|
+
}
|
|
1767
|
+
function estimateNodeWidth(node) {
|
|
1768
|
+
if (node.width !== undefined)
|
|
1769
|
+
return clamp$a(finiteOr$3(node.width, DEFAULT_NODE_WIDTH), MIN_NODE_WIDTH, MAX_NODE_WIDTH);
|
|
1770
|
+
const title = String(node.title || " ");
|
|
1771
|
+
const contentLines = String(node.content ?? "").split(/\r?\n/);
|
|
1772
|
+
const longestContentLine = contentLines.reduce((max, line) => Math.max(max, line.length), 0);
|
|
1773
|
+
const longestLine = Math.max(title.length, longestContentLine);
|
|
1774
|
+
return clamp$a(Math.ceil(longestLine * 7.2 + 24), MIN_NODE_WIDTH, MAX_NODE_WIDTH);
|
|
1775
|
+
}
|
|
1776
|
+
function estimateNodeHeight(node) {
|
|
1777
|
+
const width = estimateNodeWidth(node);
|
|
1778
|
+
const charsPerLine = Math.max(1, Math.floor((width - 24) / 7.2));
|
|
1779
|
+
const titleLines = Math.max(1, Math.ceil(String(node.title || " ").length / charsPerLine));
|
|
1780
|
+
const content = String(node.content ?? "");
|
|
1781
|
+
const contentLines = content.trim() === ""
|
|
1782
|
+
? 0
|
|
1783
|
+
: content
|
|
1784
|
+
.split(/\r?\n/)
|
|
1785
|
+
.reduce((total, line) => total + Math.max(1, Math.ceil((line.length || 1) / charsPerLine)), 0);
|
|
1786
|
+
const estimated = 20 + titleLines * 18 + contentLines * 16 + (contentLines > 0 ? 6 : 0);
|
|
1787
|
+
return Math.max(DEFAULT_NODE_HEIGHT, Math.ceil(estimated));
|
|
1788
|
+
}
|
|
1789
|
+
function createDefaultNodes() {
|
|
1790
|
+
return [
|
|
1791
|
+
{ id: "root", title: "项目画布", content: "双模式编辑器初版", x: 0, y: 0, width: 200, height: 92, children: ["doc", "mind"] },
|
|
1792
|
+
{ id: "doc", parentId: "root", title: "文档模式", content: "像 Word/幕布一样输入结构化内容。", level: 2, children: ["doc-a"] },
|
|
1793
|
+
{ id: "doc-a", parentId: "doc", title: "基础段落", content: "支持标题、正文、层级和只读状态。", level: 3 },
|
|
1794
|
+
{ id: "mind", parentId: "root", title: "脑图模式", content: "卡片、拖拽、连线、缩放和平移。", level: 2, children: ["mind-a", "mind-b"] },
|
|
1795
|
+
{ id: "mind-a", parentId: "mind", title: "卡片 A", content: "可拖拽节点", level: 3 },
|
|
1796
|
+
{ id: "mind-b", parentId: "mind", title: "卡片 B", content: "自动生成连线", level: 3 }
|
|
1797
|
+
];
|
|
1798
|
+
}
|
|
1799
|
+
function normalizeViewport(viewport) {
|
|
1800
|
+
return {
|
|
1801
|
+
x: finiteOr$3(viewport?.x, 0),
|
|
1802
|
+
y: finiteOr$3(viewport?.y, 0),
|
|
1803
|
+
zoom: clamp$a(finiteOr$3(viewport?.zoom, 1), 0.35, 2.4)
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
function normalizeMode(mode) {
|
|
1807
|
+
return mode === "mind" ? "mind" : "document";
|
|
1808
|
+
}
|
|
1809
|
+
function cloneNode(node) {
|
|
1810
|
+
return {
|
|
1811
|
+
...node,
|
|
1812
|
+
children: node.children ? [...node.children] : undefined
|
|
1813
|
+
};
|
|
1814
|
+
}
|
|
1815
|
+
function normalizeNodes(nodes) {
|
|
1816
|
+
const source = nodes && nodes.length > 0 ? nodes : createDefaultNodes();
|
|
1817
|
+
const seen = new Set();
|
|
1818
|
+
const normalized = source
|
|
1819
|
+
.filter((node) => {
|
|
1820
|
+
if (!node.id || seen.has(node.id))
|
|
1821
|
+
return false;
|
|
1822
|
+
seen.add(node.id);
|
|
1823
|
+
return true;
|
|
1824
|
+
})
|
|
1825
|
+
.map(cloneNode);
|
|
1826
|
+
return reconcileHierarchy(normalized);
|
|
1827
|
+
}
|
|
1828
|
+
function reconcileHierarchy(nodes) {
|
|
1829
|
+
const nodeMap = new Map(nodes.map((node) => [node.id, node]));
|
|
1830
|
+
const childIds = new Set();
|
|
1831
|
+
nodes.forEach((node) => {
|
|
1832
|
+
const children = (node.children ?? []).filter((childId) => childId !== node.id && nodeMap.has(childId));
|
|
1833
|
+
if (children.length > 0) {
|
|
1834
|
+
node.children = Array.from(new Set(children));
|
|
1835
|
+
node.children.forEach((childId) => {
|
|
1836
|
+
childIds.add(childId);
|
|
1837
|
+
const child = nodeMap.get(childId);
|
|
1838
|
+
if (child && !child.parentId)
|
|
1839
|
+
child.parentId = node.id;
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1842
|
+
else {
|
|
1843
|
+
delete node.children;
|
|
1844
|
+
}
|
|
1845
|
+
});
|
|
1846
|
+
nodes.forEach((node) => {
|
|
1847
|
+
const parent = node.parentId ? nodeMap.get(node.parentId) : undefined;
|
|
1848
|
+
if (!parent || parent.id === node.id)
|
|
1849
|
+
return;
|
|
1850
|
+
const children = parent.children ?? [];
|
|
1851
|
+
if (!children.includes(node.id))
|
|
1852
|
+
parent.children = [...children, node.id];
|
|
1853
|
+
childIds.add(node.id);
|
|
1854
|
+
});
|
|
1855
|
+
nodes.forEach((node) => {
|
|
1856
|
+
if (!node.parentId && childIds.has(node.id)) {
|
|
1857
|
+
const parent = nodes.find((candidate) => candidate.children?.includes(node.id));
|
|
1858
|
+
if (parent)
|
|
1859
|
+
node.parentId = parent.id;
|
|
1860
|
+
}
|
|
1861
|
+
});
|
|
1862
|
+
return nodes;
|
|
1863
|
+
}
|
|
1864
|
+
function getRootId(nodes, rootId) {
|
|
1865
|
+
if (rootId && nodes.some((node) => node.id === rootId))
|
|
1866
|
+
return rootId;
|
|
1867
|
+
const explicitRoot = nodes.find((node) => !node.parentId);
|
|
1868
|
+
return explicitRoot?.id ?? nodes[0]?.id ?? "root";
|
|
1869
|
+
}
|
|
1870
|
+
class CanvasEditorController {
|
|
1871
|
+
constructor(options = {}) {
|
|
1872
|
+
this.idSeed = 0;
|
|
1873
|
+
this.mode = normalizeMode(options.mode);
|
|
1874
|
+
this.nodes = normalizeNodes(options.nodes);
|
|
1875
|
+
this.rootId = getRootId(this.nodes, options.rootId);
|
|
1876
|
+
this.viewport = normalizeViewport(options.viewport);
|
|
1877
|
+
this.disabled = options.disabled ?? false;
|
|
1878
|
+
this.readOnly = options.readOnly ?? false;
|
|
1879
|
+
}
|
|
1880
|
+
updateOptions(options = {}) {
|
|
1881
|
+
if (options.mode)
|
|
1882
|
+
this.mode = normalizeMode(options.mode);
|
|
1883
|
+
if (options.nodes) {
|
|
1884
|
+
this.nodes = normalizeNodes(options.nodes);
|
|
1885
|
+
this.rootId = getRootId(this.nodes, options.rootId ?? this.rootId);
|
|
1886
|
+
}
|
|
1887
|
+
else if (options.rootId) {
|
|
1888
|
+
this.rootId = getRootId(this.nodes, options.rootId);
|
|
1889
|
+
}
|
|
1890
|
+
if (options.viewport)
|
|
1891
|
+
this.viewport = normalizeViewport({ ...this.viewport, ...options.viewport });
|
|
1892
|
+
if (typeof options.disabled === "boolean")
|
|
1893
|
+
this.disabled = options.disabled;
|
|
1894
|
+
if (typeof options.readOnly === "boolean")
|
|
1895
|
+
this.readOnly = options.readOnly;
|
|
1896
|
+
return this.getState();
|
|
1897
|
+
}
|
|
1898
|
+
setMode(mode) {
|
|
1899
|
+
this.mode = normalizeMode(mode);
|
|
1900
|
+
return this.getState();
|
|
1901
|
+
}
|
|
1902
|
+
select(id) {
|
|
1903
|
+
this.selectedId = id && this.nodes.some((node) => node.id === id) ? id : undefined;
|
|
1904
|
+
return this.getState();
|
|
1905
|
+
}
|
|
1906
|
+
updateNode(id, patch) {
|
|
1907
|
+
if (this.disabled || this.readOnly)
|
|
1908
|
+
return this.getState();
|
|
1909
|
+
this.nodes = this.nodes.map((node) => {
|
|
1910
|
+
if (node.id !== id)
|
|
1911
|
+
return node;
|
|
1912
|
+
const nextNode = { ...node, ...patch };
|
|
1913
|
+
return { ...nextNode, height: estimateNodeHeight(nextNode) };
|
|
1914
|
+
});
|
|
1915
|
+
return this.getState();
|
|
1916
|
+
}
|
|
1917
|
+
addNode(input = {}) {
|
|
1918
|
+
if (this.disabled || this.readOnly)
|
|
1919
|
+
return this.getState();
|
|
1920
|
+
const nodeMap = new Map(this.nodes.map((node) => [node.id, node]));
|
|
1921
|
+
const fallbackParentId = this.selectedId && nodeMap.has(this.selectedId) ? this.selectedId : this.rootId;
|
|
1922
|
+
const parentId = input.parentId && nodeMap.has(input.parentId) ? input.parentId : fallbackParentId;
|
|
1923
|
+
const id = this.createNodeId(input.id);
|
|
1924
|
+
const nextNode = {
|
|
1925
|
+
content: input.content ?? "补充节点说明",
|
|
1926
|
+
id,
|
|
1927
|
+
parentId,
|
|
1928
|
+
title: input.title ?? "新节点",
|
|
1929
|
+
...(input.width !== undefined ? { width: input.width } : {}),
|
|
1930
|
+
...(input.x !== undefined ? { x: input.x } : {}),
|
|
1931
|
+
...(input.y !== undefined ? { y: input.y } : {})
|
|
1932
|
+
};
|
|
1933
|
+
nextNode.height = finiteOr$3(input.height, estimateNodeHeight(nextNode));
|
|
1934
|
+
this.nodes = this.nodes
|
|
1935
|
+
.map((node) => node.id === parentId ? { ...node, children: [...(node.children ?? []), id] } : node)
|
|
1936
|
+
.concat(nextNode);
|
|
1937
|
+
this.selectedId = id;
|
|
1938
|
+
return this.getState();
|
|
1939
|
+
}
|
|
1940
|
+
removeNode(id) {
|
|
1941
|
+
if (this.disabled || this.readOnly || id === this.rootId)
|
|
1942
|
+
return this.getState();
|
|
1943
|
+
const nodeMap = new Map(this.nodes.map((node) => [node.id, node]));
|
|
1944
|
+
if (!nodeMap.has(id))
|
|
1945
|
+
return this.getState();
|
|
1946
|
+
const removeIds = new Set();
|
|
1947
|
+
const collect = (nodeId) => {
|
|
1948
|
+
if (removeIds.has(nodeId))
|
|
1949
|
+
return;
|
|
1950
|
+
removeIds.add(nodeId);
|
|
1951
|
+
(nodeMap.get(nodeId)?.children ?? []).forEach(collect);
|
|
1952
|
+
};
|
|
1953
|
+
collect(id);
|
|
1954
|
+
this.nodes = this.nodes
|
|
1955
|
+
.filter((node) => !removeIds.has(node.id))
|
|
1956
|
+
.map((node) => ({
|
|
1957
|
+
...node,
|
|
1958
|
+
children: node.children?.filter((childId) => !removeIds.has(childId))
|
|
1959
|
+
}));
|
|
1960
|
+
if (this.selectedId && removeIds.has(this.selectedId))
|
|
1961
|
+
this.selectedId = undefined;
|
|
1962
|
+
return this.getState();
|
|
1963
|
+
}
|
|
1964
|
+
moveNode(input) {
|
|
1965
|
+
if (this.disabled || this.readOnly)
|
|
1966
|
+
return this.getState();
|
|
1967
|
+
const zoom = this.viewport.zoom || 1;
|
|
1968
|
+
this.nodes = this.nodes.map((node) => node.id === input.id
|
|
1969
|
+
? {
|
|
1970
|
+
...node,
|
|
1971
|
+
x: finiteOr$3(node.x, 0) + input.deltaX / zoom,
|
|
1972
|
+
y: finiteOr$3(node.y, 0) + input.deltaY / zoom
|
|
1973
|
+
}
|
|
1974
|
+
: node);
|
|
1975
|
+
return this.getState();
|
|
1976
|
+
}
|
|
1977
|
+
pan(input) {
|
|
1978
|
+
if (this.disabled)
|
|
1979
|
+
return this.getState();
|
|
1980
|
+
this.viewport = {
|
|
1981
|
+
...this.viewport,
|
|
1982
|
+
x: this.viewport.x + input.deltaX,
|
|
1983
|
+
y: this.viewport.y + input.deltaY
|
|
1984
|
+
};
|
|
1985
|
+
return this.getState();
|
|
1986
|
+
}
|
|
1987
|
+
zoom(delta) {
|
|
1988
|
+
if (this.disabled)
|
|
1989
|
+
return this.getState();
|
|
1990
|
+
this.viewport = {
|
|
1991
|
+
...this.viewport,
|
|
1992
|
+
zoom: clamp$a(this.viewport.zoom + delta, 0.35, 2.4)
|
|
1993
|
+
};
|
|
1994
|
+
return this.getState();
|
|
1995
|
+
}
|
|
1996
|
+
resetViewport() {
|
|
1997
|
+
this.viewport = normalizeViewport();
|
|
1998
|
+
return this.getState();
|
|
1999
|
+
}
|
|
2000
|
+
createNodeId(preferredId) {
|
|
2001
|
+
if (preferredId && !this.nodes.some((node) => node.id === preferredId))
|
|
2002
|
+
return preferredId;
|
|
2003
|
+
let id = "";
|
|
2004
|
+
do {
|
|
2005
|
+
this.idSeed += 1;
|
|
2006
|
+
id = `node-${Date.now().toString(36)}-${this.idSeed}`;
|
|
2007
|
+
} while (this.nodes.some((node) => node.id === id));
|
|
2008
|
+
return id;
|
|
2009
|
+
}
|
|
2010
|
+
getState() {
|
|
2011
|
+
const nodes = this.getLayoutNodes();
|
|
2012
|
+
return {
|
|
2013
|
+
disabled: this.disabled,
|
|
2014
|
+
links: this.createLinks(nodes),
|
|
2015
|
+
mode: this.mode,
|
|
2016
|
+
nodes,
|
|
2017
|
+
readOnly: this.readOnly,
|
|
2018
|
+
rootId: this.rootId,
|
|
2019
|
+
selectedId: this.selectedId,
|
|
2020
|
+
viewport: { ...this.viewport }
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
getLayoutNodes() {
|
|
2024
|
+
const rawNodes = this.nodes.map(cloneNode);
|
|
2025
|
+
const nodeMap = new Map(rawNodes.map((node) => [node.id, node]));
|
|
2026
|
+
const root = nodeMap.get(this.rootId) ?? rawNodes[0];
|
|
2027
|
+
if (!root)
|
|
2028
|
+
return [];
|
|
2029
|
+
const visited = new Set();
|
|
2030
|
+
const depthById = new Map();
|
|
2031
|
+
const result = [];
|
|
2032
|
+
const walk = (id, depth, siblingIndex, offsetY) => {
|
|
2033
|
+
const node = nodeMap.get(id);
|
|
2034
|
+
if (!node || visited.has(id))
|
|
2035
|
+
return offsetY;
|
|
2036
|
+
visited.add(id);
|
|
2037
|
+
depthById.set(id, depth);
|
|
2038
|
+
const children = (node.children ?? []).filter((childId) => nodeMap.has(childId));
|
|
2039
|
+
const width = estimateNodeWidth(node);
|
|
2040
|
+
const height = Math.max(finiteOr$3(node.height, DEFAULT_NODE_HEIGHT), estimateNodeHeight({ ...node, width }));
|
|
2041
|
+
const startY = offsetY;
|
|
2042
|
+
let nextY = offsetY;
|
|
2043
|
+
children.forEach((childId, index) => {
|
|
2044
|
+
nextY = walk(childId, depth + 1, index, nextY);
|
|
2045
|
+
});
|
|
2046
|
+
const endY = children.length > 0 ? nextY - MIN_NODE_GAP_Y : startY;
|
|
2047
|
+
const fallbackY = children.length > 0 ? (startY + endY) / 2 : startY;
|
|
2048
|
+
const y = finiteOr$3(node.y, children.length > 0 ? fallbackY - height / 2 : siblingIndex === 0 && depth === 0 ? 0 : offsetY);
|
|
2049
|
+
result.push({
|
|
2050
|
+
...node,
|
|
2051
|
+
height,
|
|
2052
|
+
width,
|
|
2053
|
+
x: depth * DEFAULT_GAP_X,
|
|
2054
|
+
y
|
|
2055
|
+
});
|
|
2056
|
+
return Math.max(children.length > 0 ? nextY : offsetY, y + height + MIN_NODE_GAP_Y);
|
|
2057
|
+
};
|
|
2058
|
+
walk(root.id, 0, 0, 0);
|
|
2059
|
+
rawNodes.forEach((node) => {
|
|
2060
|
+
if (!visited.has(node.id)) {
|
|
2061
|
+
depthById.set(node.id, 0);
|
|
2062
|
+
const width = estimateNodeWidth(node);
|
|
2063
|
+
const height = Math.max(finiteOr$3(node.height, DEFAULT_NODE_HEIGHT), estimateNodeHeight({ ...node, width }));
|
|
2064
|
+
result.push({
|
|
2065
|
+
...node,
|
|
2066
|
+
height,
|
|
2067
|
+
width,
|
|
2068
|
+
x: 0,
|
|
2069
|
+
y: finiteOr$3(node.y, result.length * (height + MIN_NODE_GAP_Y))
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
});
|
|
2073
|
+
return this.separateOverlappingNodes(result, depthById);
|
|
2074
|
+
}
|
|
2075
|
+
separateOverlappingNodes(nodes, depthById) {
|
|
2076
|
+
const nextNodes = nodes.map(cloneNode);
|
|
2077
|
+
const groups = new Map();
|
|
2078
|
+
nextNodes.forEach((node) => {
|
|
2079
|
+
const depth = depthById.get(node.id) ?? 0;
|
|
2080
|
+
const group = groups.get(depth) ?? [];
|
|
2081
|
+
group.push(node);
|
|
2082
|
+
groups.set(depth, group);
|
|
2083
|
+
});
|
|
2084
|
+
groups.forEach((group) => {
|
|
2085
|
+
group
|
|
2086
|
+
.sort((a, b) => finiteOr$3(a.y, 0) - finiteOr$3(b.y, 0))
|
|
2087
|
+
.reduce((nextY, node) => {
|
|
2088
|
+
const currentY = finiteOr$3(node.y, nextY);
|
|
2089
|
+
const y = Math.max(currentY, nextY);
|
|
2090
|
+
node.y = y;
|
|
2091
|
+
return y + finiteOr$3(node.height, DEFAULT_NODE_HEIGHT) + MIN_NODE_GAP_Y;
|
|
2092
|
+
}, Number.NEGATIVE_INFINITY);
|
|
2093
|
+
});
|
|
2094
|
+
return nextNodes;
|
|
2095
|
+
}
|
|
2096
|
+
createLinks(nodes) {
|
|
2097
|
+
const nodeMap = new Map(nodes.map((node) => [node.id, node]));
|
|
2098
|
+
const links = [];
|
|
2099
|
+
nodes.forEach((node) => {
|
|
2100
|
+
(node.children ?? []).forEach((childId) => {
|
|
2101
|
+
const child = nodeMap.get(childId);
|
|
2102
|
+
if (!child)
|
|
2103
|
+
return;
|
|
2104
|
+
const fromX = finiteOr$3(node.x, 0) + finiteOr$3(node.width, DEFAULT_NODE_WIDTH);
|
|
2105
|
+
const fromY = finiteOr$3(node.y, 0) + finiteOr$3(node.height, DEFAULT_NODE_HEIGHT) / 2;
|
|
2106
|
+
const toX = finiteOr$3(child.x, 0);
|
|
2107
|
+
const toY = finiteOr$3(child.y, 0) + finiteOr$3(child.height, DEFAULT_NODE_HEIGHT) / 2;
|
|
2108
|
+
const curve = Math.max(48, Math.abs(toX - fromX) * 0.45);
|
|
2109
|
+
links.push({
|
|
2110
|
+
d: `M ${fromX} ${fromY} C ${fromX + curve} ${fromY}, ${toX - curve} ${toY}, ${toX} ${toY}`,
|
|
2111
|
+
from: node.id,
|
|
2112
|
+
to: child.id
|
|
2113
|
+
});
|
|
2114
|
+
});
|
|
2115
|
+
});
|
|
2116
|
+
return links;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
function finiteOr$2(value, fallback) {
|
|
2121
|
+
return Number.isFinite(value) ? Number(value) : fallback;
|
|
2122
|
+
}
|
|
2123
|
+
function clamp$9(value, min, max) {
|
|
2124
|
+
return Math.min(max, Math.max(min, value));
|
|
2125
|
+
}
|
|
2126
|
+
function normalizeDpr(value) {
|
|
2127
|
+
return clamp$9(finiteOr$2(value, 1), 1, 4);
|
|
2128
|
+
}
|
|
2129
|
+
function roundedRect(ctx, x, y, width, height, radius = 0) {
|
|
2130
|
+
const r = clamp$9(radius, 0, Math.min(width, height) / 2);
|
|
2131
|
+
ctx.beginPath();
|
|
2132
|
+
ctx.moveTo(x + r, y);
|
|
2133
|
+
ctx.lineTo(x + width - r, y);
|
|
2134
|
+
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
|
|
2135
|
+
ctx.lineTo(x + width, y + height - r);
|
|
2136
|
+
ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
|
|
2137
|
+
ctx.lineTo(x + r, y + height);
|
|
2138
|
+
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
|
|
2139
|
+
ctx.lineTo(x, y + r);
|
|
2140
|
+
ctx.quadraticCurveTo(x, y, x + r, y);
|
|
2141
|
+
ctx.closePath();
|
|
2142
|
+
}
|
|
2143
|
+
function createFont(layer) {
|
|
2144
|
+
const style = layer.fontStyle ?? "normal";
|
|
2145
|
+
const weight = layer.fontWeight ?? 500;
|
|
2146
|
+
const size = finiteOr$2(layer.fontSize, 16);
|
|
2147
|
+
const family = layer.fontFamily ?? "Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif";
|
|
2148
|
+
return `${style} ${weight} ${size}px ${family}`;
|
|
2149
|
+
}
|
|
2150
|
+
function wrapText(ctx, text, maxWidth, maxLines = Number.MAX_SAFE_INTEGER) {
|
|
2151
|
+
const characters = Array.from(text);
|
|
2152
|
+
const lines = [];
|
|
2153
|
+
let line = "";
|
|
2154
|
+
for (const char of characters) {
|
|
2155
|
+
const next = `${line}${char}`;
|
|
2156
|
+
if (line && ctx.measureText(next).width > maxWidth) {
|
|
2157
|
+
lines.push(line);
|
|
2158
|
+
line = char;
|
|
2159
|
+
if (lines.length >= maxLines)
|
|
2160
|
+
break;
|
|
2161
|
+
}
|
|
2162
|
+
else {
|
|
2163
|
+
line = next;
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
if (line && lines.length < maxLines)
|
|
2167
|
+
lines.push(line);
|
|
2168
|
+
if (lines.length === maxLines && characters.join("").length > lines.join("").length) {
|
|
2169
|
+
const last = lines[lines.length - 1] ?? "";
|
|
2170
|
+
let trimmed = last;
|
|
2171
|
+
while (trimmed && ctx.measureText(`${trimmed}...`).width > maxWidth)
|
|
2172
|
+
trimmed = trimmed.slice(0, -1);
|
|
2173
|
+
lines[lines.length - 1] = `${trimmed}...`;
|
|
2174
|
+
}
|
|
2175
|
+
return lines;
|
|
2176
|
+
}
|
|
2177
|
+
function loadImage(src) {
|
|
2178
|
+
return new Promise((resolve, reject) => {
|
|
2179
|
+
const image = new Image();
|
|
2180
|
+
image.crossOrigin = "anonymous";
|
|
2181
|
+
image.onload = () => resolve(image);
|
|
2182
|
+
image.onerror = () => reject(new Error(`Failed to load image: ${src}`));
|
|
2183
|
+
image.src = src;
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
class CanvasImageController {
|
|
2187
|
+
constructor(options) {
|
|
2188
|
+
this.options = { ...options, layers: [...(options.layers ?? [])] };
|
|
2189
|
+
}
|
|
2190
|
+
updateOptions(options) {
|
|
2191
|
+
this.options = { ...this.options, ...options, layers: options.layers ? [...options.layers] : this.options.layers };
|
|
2192
|
+
return this.getState();
|
|
2193
|
+
}
|
|
2194
|
+
getState() {
|
|
2195
|
+
return {
|
|
2196
|
+
background: this.options.background ?? "transparent",
|
|
2197
|
+
dpr: normalizeDpr(this.options.dpr),
|
|
2198
|
+
height: Math.max(1, finiteOr$2(this.options.height, 1)),
|
|
2199
|
+
layerCount: this.options.layers?.length ?? 0,
|
|
2200
|
+
width: Math.max(1, finiteOr$2(this.options.width, 1))
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
async draw(canvas) {
|
|
2204
|
+
const state = this.getState();
|
|
2205
|
+
const ctx = canvas.getContext("2d");
|
|
2206
|
+
if (!ctx)
|
|
2207
|
+
return state;
|
|
2208
|
+
canvas.width = Math.round(state.width * state.dpr);
|
|
2209
|
+
canvas.height = Math.round(state.height * state.dpr);
|
|
2210
|
+
canvas.style.width = `${state.width}px`;
|
|
2211
|
+
canvas.style.height = `${state.height}px`;
|
|
2212
|
+
ctx.setTransform(state.dpr, 0, 0, state.dpr, 0, 0);
|
|
2213
|
+
ctx.clearRect(0, 0, state.width, state.height);
|
|
2214
|
+
if (state.background !== "transparent") {
|
|
2215
|
+
ctx.fillStyle = state.background;
|
|
2216
|
+
ctx.fillRect(0, 0, state.width, state.height);
|
|
2217
|
+
}
|
|
2218
|
+
for (const layer of this.options.layers ?? []) {
|
|
2219
|
+
await this.drawLayer(ctx, layer);
|
|
2220
|
+
}
|
|
2221
|
+
return state;
|
|
2222
|
+
}
|
|
2223
|
+
async drawLayer(ctx, layer) {
|
|
2224
|
+
ctx.save();
|
|
2225
|
+
ctx.globalAlpha = clamp$9(layer.opacity ?? 1, 0, 1);
|
|
2226
|
+
if (layer.rotate) {
|
|
2227
|
+
ctx.translate(layer.x, layer.y);
|
|
2228
|
+
ctx.rotate((layer.rotate * Math.PI) / 180);
|
|
2229
|
+
ctx.translate(-layer.x, -layer.y);
|
|
2230
|
+
}
|
|
2231
|
+
if (layer.type === "rect") {
|
|
2232
|
+
roundedRect(ctx, layer.x, layer.y, layer.width, layer.height, layer.radius);
|
|
2233
|
+
if (layer.fill) {
|
|
2234
|
+
ctx.fillStyle = layer.fill;
|
|
2235
|
+
ctx.fill();
|
|
2236
|
+
}
|
|
2237
|
+
if (layer.stroke && layer.strokeWidth) {
|
|
2238
|
+
ctx.strokeStyle = layer.stroke;
|
|
2239
|
+
ctx.lineWidth = layer.strokeWidth;
|
|
2240
|
+
ctx.stroke();
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
if (layer.type === "text") {
|
|
2244
|
+
ctx.font = createFont(layer);
|
|
2245
|
+
ctx.fillStyle = layer.color ?? "#111827";
|
|
2246
|
+
ctx.textAlign = layer.textAlign ?? "left";
|
|
2247
|
+
ctx.textBaseline = layer.textBaseline ?? "top";
|
|
2248
|
+
const lineHeight = finiteOr$2(layer.lineHeight, finiteOr$2(layer.fontSize, 16) * 1.4);
|
|
2249
|
+
const lines = layer.wrap && layer.maxWidth
|
|
2250
|
+
? wrapText(ctx, layer.text, layer.maxWidth, layer.maxLines)
|
|
2251
|
+
: layer.text.split("\n").slice(0, layer.maxLines ?? Number.MAX_SAFE_INTEGER);
|
|
2252
|
+
lines.forEach((line, index) => {
|
|
2253
|
+
if (!layer.letterSpacing) {
|
|
2254
|
+
ctx.fillText(line, layer.x, layer.y + index * lineHeight, layer.maxWidth);
|
|
2255
|
+
return;
|
|
2256
|
+
}
|
|
2257
|
+
let offset = 0;
|
|
2258
|
+
Array.from(line).forEach((char) => {
|
|
2259
|
+
ctx.fillText(char, layer.x + offset, layer.y + index * lineHeight);
|
|
2260
|
+
offset += ctx.measureText(char).width + (layer.letterSpacing ?? 0);
|
|
2261
|
+
});
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
if (layer.type === "image") {
|
|
2265
|
+
const image = await loadImage(layer.src);
|
|
2266
|
+
const sourceRatio = image.width / image.height;
|
|
2267
|
+
const targetRatio = layer.width / layer.height;
|
|
2268
|
+
let sx = 0;
|
|
2269
|
+
let sy = 0;
|
|
2270
|
+
let sw = image.width;
|
|
2271
|
+
let sh = image.height;
|
|
2272
|
+
let dx = layer.x;
|
|
2273
|
+
let dy = layer.y;
|
|
2274
|
+
let dw = layer.width;
|
|
2275
|
+
let dh = layer.height;
|
|
2276
|
+
if (layer.fit === "cover") {
|
|
2277
|
+
if (sourceRatio > targetRatio) {
|
|
2278
|
+
sw = image.height * targetRatio;
|
|
2279
|
+
sx = (image.width - sw) / 2;
|
|
2280
|
+
}
|
|
2281
|
+
else {
|
|
2282
|
+
sh = image.width / targetRatio;
|
|
2283
|
+
sy = (image.height - sh) / 2;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
else if (layer.fit === "contain") {
|
|
2287
|
+
if (sourceRatio > targetRatio) {
|
|
2288
|
+
dh = layer.width / sourceRatio;
|
|
2289
|
+
dy = layer.y + (layer.height - dh) / 2;
|
|
2290
|
+
}
|
|
2291
|
+
else {
|
|
2292
|
+
dw = layer.height * sourceRatio;
|
|
2293
|
+
dx = layer.x + (layer.width - dw) / 2;
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
if (layer.radius) {
|
|
2297
|
+
roundedRect(ctx, layer.x, layer.y, layer.width, layer.height, layer.radius);
|
|
2298
|
+
ctx.clip();
|
|
2299
|
+
}
|
|
2300
|
+
ctx.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh);
|
|
2301
|
+
}
|
|
2302
|
+
ctx.restore();
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
function toTimestamp(value) {
|
|
2307
|
+
if (value instanceof Date)
|
|
2308
|
+
return value.getTime();
|
|
2309
|
+
if (typeof value === "number")
|
|
2310
|
+
return Number.isFinite(value) ? value : Date.now();
|
|
2311
|
+
if (typeof value === "string") {
|
|
2312
|
+
const time = new Date(value).getTime();
|
|
2313
|
+
return Number.isFinite(time) ? time : Date.now();
|
|
2314
|
+
}
|
|
2315
|
+
return Date.now();
|
|
2316
|
+
}
|
|
2317
|
+
function toDuration(value, unit = 1) {
|
|
2318
|
+
if (value === undefined)
|
|
2319
|
+
return undefined;
|
|
2320
|
+
const normalized = Number(value);
|
|
2321
|
+
if (!Number.isFinite(normalized))
|
|
2322
|
+
return undefined;
|
|
2323
|
+
return Math.max(0, normalized * unit);
|
|
2324
|
+
}
|
|
2325
|
+
function resolveTarget(options = {}) {
|
|
2326
|
+
if (options.target !== undefined)
|
|
2327
|
+
return toTimestamp(options.target);
|
|
2328
|
+
const now = Number.isFinite(options.now ?? NaN) ? Number(options.now) : Date.now();
|
|
2329
|
+
const duration = toDuration(options.duration) ??
|
|
2330
|
+
toDuration(options.minutes, 60000) ??
|
|
2331
|
+
toDuration(options.seconds, 1000);
|
|
2332
|
+
return now + (duration ?? 0);
|
|
2333
|
+
}
|
|
2334
|
+
function pad(value) {
|
|
2335
|
+
return String(value).padStart(2, "0");
|
|
2336
|
+
}
|
|
2337
|
+
class CountdownController {
|
|
2338
|
+
constructor(options = {}) {
|
|
2339
|
+
this.autoStart = options.autoStart ?? true;
|
|
2340
|
+
this.format = options.format ?? "unit";
|
|
2341
|
+
this.running = this.autoStart;
|
|
2342
|
+
this.sourceMode = options.minutes !== undefined ? "minutes" : options.seconds !== undefined ? "seconds" : "default";
|
|
2343
|
+
this.target = resolveTarget(options);
|
|
2344
|
+
}
|
|
2345
|
+
updateOptions(options = {}) {
|
|
2346
|
+
if (options.autoStart !== undefined)
|
|
2347
|
+
this.autoStart = options.autoStart;
|
|
2348
|
+
if (options.format)
|
|
2349
|
+
this.format = options.format;
|
|
2350
|
+
if (options.target !== undefined ||
|
|
2351
|
+
options.duration !== undefined ||
|
|
2352
|
+
options.minutes !== undefined ||
|
|
2353
|
+
options.seconds !== undefined) {
|
|
2354
|
+
this.sourceMode = options.minutes !== undefined ? "minutes" : options.seconds !== undefined ? "seconds" : "default";
|
|
2355
|
+
this.target = resolveTarget(options);
|
|
2356
|
+
}
|
|
2357
|
+
if (options.autoStart !== undefined)
|
|
2358
|
+
this.running = options.autoStart;
|
|
2359
|
+
return this.getState(options.now);
|
|
2360
|
+
}
|
|
2361
|
+
start(now) {
|
|
2362
|
+
this.running = true;
|
|
2363
|
+
return this.getState(now);
|
|
2364
|
+
}
|
|
2365
|
+
pause(now) {
|
|
2366
|
+
this.running = false;
|
|
2367
|
+
return this.getState(now);
|
|
2368
|
+
}
|
|
2369
|
+
reset(target, now) {
|
|
2370
|
+
if (target !== undefined)
|
|
2371
|
+
this.target = toTimestamp(target);
|
|
2372
|
+
this.running = this.autoStart;
|
|
2373
|
+
return this.getState(now);
|
|
2374
|
+
}
|
|
2375
|
+
getState(now = Date.now()) {
|
|
2376
|
+
const parts = this.createParts(Math.max(0, this.target - now));
|
|
2377
|
+
const done = parts.total <= 0;
|
|
2378
|
+
if (done)
|
|
2379
|
+
this.running = false;
|
|
2380
|
+
return {
|
|
2381
|
+
...parts,
|
|
2382
|
+
display: this.formatParts(parts),
|
|
2383
|
+
done,
|
|
2384
|
+
running: this.running && !done
|
|
2385
|
+
};
|
|
2386
|
+
}
|
|
2387
|
+
createParts(total) {
|
|
2388
|
+
const secondsTotal = Math.floor(total / 1000);
|
|
2389
|
+
const days = Math.floor(secondsTotal / 86400);
|
|
2390
|
+
const hours = Math.floor((secondsTotal % 86400) / 3600);
|
|
2391
|
+
const minutes = Math.floor((secondsTotal % 3600) / 60);
|
|
2392
|
+
const seconds = secondsTotal % 60;
|
|
2393
|
+
return { days, hours, milliseconds: total % 1000, minutes, seconds, total };
|
|
2394
|
+
}
|
|
2395
|
+
formatParts(parts) {
|
|
2396
|
+
if (this.sourceMode === "minutes") {
|
|
2397
|
+
const totalMinutes = Math.floor(Math.floor(parts.total / 1000) / 60);
|
|
2398
|
+
return `${pad(totalMinutes)}:${pad(parts.seconds)}`;
|
|
2399
|
+
}
|
|
2400
|
+
if (this.sourceMode === "seconds")
|
|
2401
|
+
return pad(Math.floor(parts.total / 1000));
|
|
2402
|
+
if (this.format === "compact")
|
|
2403
|
+
return `${parts.days > 0 ? `${parts.days}d ` : ""}${pad(parts.hours)}:${pad(parts.minutes)}:${pad(parts.seconds)}`;
|
|
2404
|
+
if (this.format === "clock")
|
|
2405
|
+
return `${pad(parts.days * 24 + parts.hours)}:${pad(parts.minutes)}:${pad(parts.seconds)}`;
|
|
2406
|
+
const locale = getClassComponentsLocale();
|
|
2407
|
+
return `${parts.days}${locale.countdownDayUnit} ${pad(parts.hours)}${locale.countdownHourUnit} ${pad(parts.minutes)}${locale.countdownMinuteUnit} ${pad(parts.seconds)}${locale.countdownSecondUnit}`;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
class SkeletonController {
|
|
2412
|
+
constructor(options = {}) {
|
|
2413
|
+
this.state = this.normalize(options);
|
|
2414
|
+
}
|
|
2415
|
+
update(options = {}) {
|
|
2416
|
+
this.state = this.normalize(options);
|
|
2417
|
+
return this.getState();
|
|
2418
|
+
}
|
|
2419
|
+
getState() {
|
|
2420
|
+
return { ...this.state, rows: [...this.state.rows] };
|
|
2421
|
+
}
|
|
2422
|
+
normalize(options) {
|
|
2423
|
+
const count = Math.max(1, Math.min(20, Math.floor(Number.isFinite(options.count) ? Number(options.count) : 3)));
|
|
2424
|
+
return { animated: options.animated ?? true, rows: Array.from({ length: count }, (_, index) => index) };
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
class TagController {
|
|
2429
|
+
constructor(options = {}) {
|
|
2430
|
+
this.state = this.normalize(options);
|
|
2431
|
+
}
|
|
2432
|
+
update(options = {}) {
|
|
2433
|
+
this.state = this.normalize(options);
|
|
2434
|
+
return this.getState();
|
|
2435
|
+
}
|
|
2436
|
+
getState() {
|
|
2437
|
+
return { ...this.state };
|
|
2438
|
+
}
|
|
2439
|
+
normalize(options) {
|
|
2440
|
+
return {
|
|
2441
|
+
checkable: Boolean(options.checkable),
|
|
2442
|
+
checked: Boolean(options.checked),
|
|
2443
|
+
closable: Boolean(options.closable),
|
|
2444
|
+
disabled: Boolean(options.disabled),
|
|
2445
|
+
tone: options.tone ?? "neutral"
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
function normalizeValue(value) {
|
|
2451
|
+
if (!Number.isFinite(value))
|
|
2452
|
+
return 0;
|
|
2453
|
+
return Math.max(0, Math.floor(value));
|
|
2454
|
+
}
|
|
2455
|
+
function toDigits(value, minDigits) {
|
|
2456
|
+
const normalized = normalizeValue(value);
|
|
2457
|
+
const chars = String(normalized).padStart(minDigits, "0").split("");
|
|
2458
|
+
return chars.map((char) => Number(char));
|
|
2459
|
+
}
|
|
2460
|
+
class RollingNumberController {
|
|
2461
|
+
constructor(value = 0, options = {}) {
|
|
2462
|
+
this.minDigits = Math.max(1, options.minDigits ?? 1);
|
|
2463
|
+
this.previousValue = normalizeValue(value);
|
|
2464
|
+
this.previousDigits = toDigits(this.previousValue, this.minDigits);
|
|
2465
|
+
}
|
|
2466
|
+
getStableColumns(value = this.previousValue) {
|
|
2467
|
+
const digits = toDigits(value, this.minDigits);
|
|
2468
|
+
return digits.map((digit, index) => ({
|
|
2469
|
+
key: `${digits.length - index - 1}`,
|
|
2470
|
+
digit,
|
|
2471
|
+
offset: digit
|
|
2472
|
+
}));
|
|
2473
|
+
}
|
|
2474
|
+
update(value) {
|
|
2475
|
+
const nextValue = normalizeValue(value);
|
|
2476
|
+
const nextDigits = toDigits(nextValue, this.minDigits);
|
|
2477
|
+
const previousDigits = this.alignPreviousDigits(nextDigits.length);
|
|
2478
|
+
const increasing = nextValue >= this.previousValue;
|
|
2479
|
+
const columns = nextDigits.map((digit, index) => {
|
|
2480
|
+
const previousDigit = previousDigits[index] ?? 0;
|
|
2481
|
+
const offset = increasing && previousDigit === 9 && digit === 0 ? 10 : digit;
|
|
2482
|
+
return {
|
|
2483
|
+
key: `${nextDigits.length - index - 1}`,
|
|
2484
|
+
digit,
|
|
2485
|
+
offset
|
|
2486
|
+
};
|
|
2487
|
+
});
|
|
2488
|
+
this.previousValue = nextValue;
|
|
2489
|
+
this.previousDigits = nextDigits;
|
|
2490
|
+
return columns;
|
|
2491
|
+
}
|
|
2492
|
+
alignPreviousDigits(length) {
|
|
2493
|
+
const padding = Array.from({ length: Math.max(0, length - this.previousDigits.length) }, () => 0);
|
|
2494
|
+
return [...padding, ...this.previousDigits].slice(-length);
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
const DEFAULT_ROOT_MARGIN = "200px";
|
|
2499
|
+
function normalizeRootMargin(rootMargin) {
|
|
2500
|
+
return typeof rootMargin === "string" && rootMargin.trim() ? rootMargin : DEFAULT_ROOT_MARGIN;
|
|
2501
|
+
}
|
|
2502
|
+
function normalizeThreshold(threshold) {
|
|
2503
|
+
if (typeof threshold !== "number" || !Number.isFinite(threshold))
|
|
2504
|
+
return 0;
|
|
2505
|
+
return Math.min(1, Math.max(0, threshold));
|
|
2506
|
+
}
|
|
2507
|
+
function normalizeSrc(src) {
|
|
2508
|
+
return typeof src === "string" ? src.trim() : "";
|
|
2509
|
+
}
|
|
2510
|
+
class LazyImageController {
|
|
2511
|
+
constructor(options) {
|
|
2512
|
+
this.state = {
|
|
2513
|
+
currentSrc: options.eager ? normalizeSrc(options.src) : undefined,
|
|
2514
|
+
eager: Boolean(options.eager),
|
|
2515
|
+
fallbackSrc: normalizeSrc(options.fallbackSrc) || undefined,
|
|
2516
|
+
placeholderSrc: normalizeSrc(options.placeholderSrc) || undefined,
|
|
2517
|
+
rootMargin: normalizeRootMargin(options.rootMargin),
|
|
2518
|
+
src: normalizeSrc(options.src),
|
|
2519
|
+
status: options.eager ? "loading" : "idle",
|
|
2520
|
+
threshold: normalizeThreshold(options.threshold)
|
|
2521
|
+
};
|
|
2522
|
+
}
|
|
2523
|
+
updateOptions(options) {
|
|
2524
|
+
const nextSrc = options.src === undefined ? this.state.src : normalizeSrc(options.src);
|
|
2525
|
+
const srcChanged = nextSrc !== this.state.src;
|
|
2526
|
+
const eager = options.eager ?? this.state.eager;
|
|
2527
|
+
this.state = {
|
|
2528
|
+
...this.state,
|
|
2529
|
+
eager,
|
|
2530
|
+
fallbackSrc: options.fallbackSrc === undefined
|
|
2531
|
+
? this.state.fallbackSrc
|
|
2532
|
+
: normalizeSrc(options.fallbackSrc) || undefined,
|
|
2533
|
+
placeholderSrc: options.placeholderSrc === undefined
|
|
2534
|
+
? this.state.placeholderSrc
|
|
2535
|
+
: normalizeSrc(options.placeholderSrc) || undefined,
|
|
2536
|
+
rootMargin: normalizeRootMargin(options.rootMargin ?? this.state.rootMargin),
|
|
2537
|
+
src: nextSrc,
|
|
2538
|
+
threshold: normalizeThreshold(options.threshold ?? this.state.threshold)
|
|
2539
|
+
};
|
|
2540
|
+
if (srcChanged) {
|
|
2541
|
+
this.state.status = eager ? "loading" : "idle";
|
|
2542
|
+
this.state.currentSrc = eager ? nextSrc : undefined;
|
|
2543
|
+
}
|
|
2544
|
+
else if (eager && this.state.status === "idle") {
|
|
2545
|
+
this.startLoading();
|
|
2546
|
+
}
|
|
2547
|
+
return this.getState();
|
|
2548
|
+
}
|
|
2549
|
+
startLoading() {
|
|
2550
|
+
if (!this.state.src) {
|
|
2551
|
+
this.state = { ...this.state, currentSrc: undefined, status: "error" };
|
|
2552
|
+
return this.getState();
|
|
2553
|
+
}
|
|
2554
|
+
if (this.state.status === "loaded" && this.state.currentSrc === this.state.src) {
|
|
2555
|
+
return this.getState();
|
|
2556
|
+
}
|
|
2557
|
+
this.state = { ...this.state, currentSrc: this.state.src, status: "loading" };
|
|
2558
|
+
return this.getState();
|
|
2559
|
+
}
|
|
2560
|
+
markLoaded() {
|
|
2561
|
+
this.state = { ...this.state, status: "loaded" };
|
|
2562
|
+
return this.getState();
|
|
2563
|
+
}
|
|
2564
|
+
markError() {
|
|
2565
|
+
if (this.state.fallbackSrc && this.state.currentSrc !== this.state.fallbackSrc) {
|
|
2566
|
+
this.state = { ...this.state, currentSrc: this.state.fallbackSrc, status: "loading" };
|
|
2567
|
+
return this.getState();
|
|
2568
|
+
}
|
|
2569
|
+
this.state = { ...this.state, status: "error" };
|
|
2570
|
+
return this.getState();
|
|
2571
|
+
}
|
|
2572
|
+
getState() {
|
|
2573
|
+
return { ...this.state };
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
const DEFAULT_DURATION = 18000;
|
|
2578
|
+
const DEFAULT_GAP$1 = "32px";
|
|
2579
|
+
const DEFAULT_ITEM_HEIGHT = "28px";
|
|
2580
|
+
const DEFAULT_STEP_ANIMATION_DURATION = 420;
|
|
2581
|
+
function normalizeDirection$1(direction) {
|
|
2582
|
+
return direction === "vertical" ? "vertical" : "horizontal";
|
|
2583
|
+
}
|
|
2584
|
+
function normalizeDuration$1(duration) {
|
|
2585
|
+
if (typeof duration !== "number" || !Number.isFinite(duration))
|
|
2586
|
+
return DEFAULT_DURATION;
|
|
2587
|
+
return Math.max(1000, Math.floor(duration));
|
|
2588
|
+
}
|
|
2589
|
+
function normalizeGap(gap) {
|
|
2590
|
+
if (typeof gap === "number")
|
|
2591
|
+
return `${Math.max(0, gap)}px`;
|
|
2592
|
+
if (typeof gap === "string" && gap.trim())
|
|
2593
|
+
return gap;
|
|
2594
|
+
return DEFAULT_GAP$1;
|
|
2595
|
+
}
|
|
2596
|
+
function normalizeItemHeight(itemHeight) {
|
|
2597
|
+
if (typeof itemHeight === "number")
|
|
2598
|
+
return `${Math.max(1, itemHeight)}px`;
|
|
2599
|
+
if (typeof itemHeight === "string" && itemHeight.trim())
|
|
2600
|
+
return itemHeight;
|
|
2601
|
+
return DEFAULT_ITEM_HEIGHT;
|
|
2602
|
+
}
|
|
2603
|
+
function normalizeVerticalMode(verticalMode) {
|
|
2604
|
+
return verticalMode === "step" ? "step" : "continuous";
|
|
2605
|
+
}
|
|
2606
|
+
function normalizeStepAnimation(stepAnimation) {
|
|
2607
|
+
if (stepAnimation === null)
|
|
2608
|
+
return null;
|
|
2609
|
+
return stepAnimation === "fade" || stepAnimation === "flip" ? stepAnimation : "slide";
|
|
2610
|
+
}
|
|
2611
|
+
function normalizeStepAnimationDuration(duration) {
|
|
2612
|
+
if (typeof duration !== "number" || !Number.isFinite(duration))
|
|
2613
|
+
return DEFAULT_STEP_ANIMATION_DURATION;
|
|
2614
|
+
return Math.max(0, Math.floor(duration));
|
|
2615
|
+
}
|
|
2616
|
+
function normalizeItems(items) {
|
|
2617
|
+
return items
|
|
2618
|
+
.map((item, index) => {
|
|
2619
|
+
if (typeof item === "object" && item !== null) {
|
|
2620
|
+
const text = String(item.text).trim();
|
|
2621
|
+
return {
|
|
2622
|
+
key: item.key?.trim() || `${index}-${text}`,
|
|
2623
|
+
text,
|
|
2624
|
+
value: item.value
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
const text = String(item).trim();
|
|
2628
|
+
return {
|
|
2629
|
+
key: `${index}-${text}`,
|
|
2630
|
+
text
|
|
2631
|
+
};
|
|
2632
|
+
})
|
|
2633
|
+
.filter((item) => item.text.length > 0);
|
|
2634
|
+
}
|
|
2635
|
+
class MarqueeController {
|
|
2636
|
+
constructor(items = [], options = {}) {
|
|
2637
|
+
this.items = normalizeItems(items);
|
|
2638
|
+
this.direction = normalizeDirection$1(options.direction);
|
|
2639
|
+
this.duration = normalizeDuration$1(options.duration);
|
|
2640
|
+
this.gap = normalizeGap(options.gap);
|
|
2641
|
+
this.itemHeight = normalizeItemHeight(options.itemHeight);
|
|
2642
|
+
this.pauseOnHover = options.pauseOnHover ?? true;
|
|
2643
|
+
this.reverse = Boolean(options.reverse);
|
|
2644
|
+
this.stepAnimation = normalizeStepAnimation(options.stepAnimation);
|
|
2645
|
+
this.stepAnimationDuration = normalizeStepAnimationDuration(options.stepAnimationDuration);
|
|
2646
|
+
this.verticalMode = normalizeVerticalMode(options.verticalMode);
|
|
2647
|
+
}
|
|
2648
|
+
update(items, options = {}) {
|
|
2649
|
+
this.items = normalizeItems(items);
|
|
2650
|
+
this.direction = normalizeDirection$1(options.direction ?? this.direction);
|
|
2651
|
+
this.duration = normalizeDuration$1(options.duration ?? this.duration);
|
|
2652
|
+
this.gap = normalizeGap(options.gap ?? this.gap);
|
|
2653
|
+
this.itemHeight = normalizeItemHeight(options.itemHeight ?? this.itemHeight);
|
|
2654
|
+
this.pauseOnHover = options.pauseOnHover ?? this.pauseOnHover;
|
|
2655
|
+
this.reverse = options.reverse ?? this.reverse;
|
|
2656
|
+
this.stepAnimation = normalizeStepAnimation(Object.prototype.hasOwnProperty.call(options, "stepAnimation")
|
|
2657
|
+
? options.stepAnimation
|
|
2658
|
+
: this.stepAnimation);
|
|
2659
|
+
this.stepAnimationDuration = normalizeStepAnimationDuration(options.stepAnimationDuration ?? this.stepAnimationDuration);
|
|
2660
|
+
this.verticalMode = normalizeVerticalMode(options.verticalMode ?? this.verticalMode);
|
|
2661
|
+
return this.getState();
|
|
2662
|
+
}
|
|
2663
|
+
getState() {
|
|
2664
|
+
return {
|
|
2665
|
+
direction: this.direction,
|
|
2666
|
+
duration: this.duration,
|
|
2667
|
+
gap: this.gap,
|
|
2668
|
+
itemHeight: this.itemHeight,
|
|
2669
|
+
items: this.items,
|
|
2670
|
+
pauseOnHover: this.pauseOnHover,
|
|
2671
|
+
reverse: this.reverse,
|
|
2672
|
+
shouldAnimate: this.items.length > 1,
|
|
2673
|
+
stepAnimation: this.stepAnimation,
|
|
2674
|
+
stepAnimationDuration: this.stepAnimationDuration,
|
|
2675
|
+
verticalMode: this.verticalMode
|
|
2676
|
+
};
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
function clamp$8(value, min, max) {
|
|
2681
|
+
return Math.min(max, Math.max(min, value));
|
|
2682
|
+
}
|
|
2683
|
+
function finiteOr$1(value, fallback) {
|
|
2684
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
2685
|
+
}
|
|
2686
|
+
function normalizeOptions$2(options = {}) {
|
|
2687
|
+
return {
|
|
2688
|
+
disabled: options.disabled ?? false,
|
|
2689
|
+
enterTransitionDuration: clamp$8(finiteOr$1(options.enterTransitionDuration, 180), 0, 600),
|
|
2690
|
+
glare: options.glare ?? true,
|
|
2691
|
+
maxTilt: clamp$8(finiteOr$1(options.maxTilt, 12), 0, 45),
|
|
2692
|
+
moveTransitionDuration: clamp$8(finiteOr$1(options.moveTransitionDuration, 80), 0, 300),
|
|
2693
|
+
perspective: clamp$8(finiteOr$1(options.perspective, 900), 240, 2400),
|
|
2694
|
+
scale: clamp$8(finiteOr$1(options.scale, 1.02), 1, 1.18),
|
|
2695
|
+
transitionEasing: options.transitionEasing ?? "cubic-bezier(0.2, 0.8, 0.2, 1)",
|
|
2696
|
+
transitionDuration: clamp$8(finiteOr$1(options.transitionDuration, 180), 0, 1200)
|
|
2697
|
+
};
|
|
2698
|
+
}
|
|
2699
|
+
function createTransform(rotateX, rotateY, scale, perspective) {
|
|
2700
|
+
return `perspective(${perspective}px) rotateX(${rotateX.toFixed(3)}deg) rotateY(${rotateY.toFixed(3)}deg) scale(${scale.toFixed(3)})`;
|
|
2701
|
+
}
|
|
2702
|
+
class TiltCardController {
|
|
2703
|
+
constructor(options = {}) {
|
|
2704
|
+
this.options = normalizeOptions$2(options);
|
|
2705
|
+
}
|
|
2706
|
+
updateOptions(options = {}) {
|
|
2707
|
+
this.options = normalizeOptions$2({ ...this.options, ...options });
|
|
2708
|
+
return this.reset();
|
|
2709
|
+
}
|
|
2710
|
+
move(input) {
|
|
2711
|
+
const width = Math.max(1, finiteOr$1(input.width, 1));
|
|
2712
|
+
const height = Math.max(1, finiteOr$1(input.height, 1));
|
|
2713
|
+
if (this.options.disabled) {
|
|
2714
|
+
return this.reset();
|
|
2715
|
+
}
|
|
2716
|
+
const x = clamp$8(input.pointerX / width, 0, 1);
|
|
2717
|
+
const y = clamp$8(input.pointerY / height, 0, 1);
|
|
2718
|
+
const rotateY = (x - 0.5) * this.options.maxTilt * 2;
|
|
2719
|
+
const rotateX = (0.5 - y) * this.options.maxTilt * 2;
|
|
2720
|
+
return {
|
|
2721
|
+
glare: this.options.glare,
|
|
2722
|
+
glareOpacity: this.options.glare ? clamp$8(Math.abs(x - 0.5) + Math.abs(y - 0.5), 0.16, 0.58) : 0,
|
|
2723
|
+
glareX: x * 100,
|
|
2724
|
+
glareY: y * 100,
|
|
2725
|
+
isActive: true,
|
|
2726
|
+
rotateX,
|
|
2727
|
+
rotateY,
|
|
2728
|
+
scale: this.options.scale,
|
|
2729
|
+
transform: createTransform(rotateX, rotateY, this.options.scale, this.options.perspective),
|
|
2730
|
+
transitionDuration: input.phase === "enter" ? this.options.enterTransitionDuration : this.options.moveTransitionDuration,
|
|
2731
|
+
transitionEasing: this.options.transitionEasing
|
|
2732
|
+
};
|
|
2733
|
+
}
|
|
2734
|
+
reset() {
|
|
2735
|
+
return {
|
|
2736
|
+
glare: this.options.glare,
|
|
2737
|
+
glareOpacity: 0,
|
|
2738
|
+
glareX: 50,
|
|
2739
|
+
glareY: 50,
|
|
2740
|
+
isActive: false,
|
|
2741
|
+
rotateX: 0,
|
|
2742
|
+
rotateY: 0,
|
|
2743
|
+
scale: 1,
|
|
2744
|
+
transform: createTransform(0, 0, 1, this.options.perspective),
|
|
2745
|
+
transitionDuration: this.options.transitionDuration,
|
|
2746
|
+
transitionEasing: this.options.transitionEasing
|
|
2747
|
+
};
|
|
2748
|
+
}
|
|
2749
|
+
getOptions() {
|
|
2750
|
+
return { ...this.options };
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
function finiteOr(value, fallback) {
|
|
2755
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
2756
|
+
}
|
|
2757
|
+
function clamp$7(value, min, max) {
|
|
2758
|
+
return Math.min(max, Math.max(min, value));
|
|
2759
|
+
}
|
|
2760
|
+
function normalizeOptions$1(options = {}) {
|
|
2761
|
+
return {
|
|
2762
|
+
cursor: options.cursor ?? true,
|
|
2763
|
+
delay: clamp$7(finiteOr(options.delay, 0), 0, 60000),
|
|
2764
|
+
disabled: options.disabled ?? false,
|
|
2765
|
+
loading: options.loading ?? false,
|
|
2766
|
+
loop: options.loop ?? false,
|
|
2767
|
+
speed: clamp$7(finiteOr(options.speed, 36), 1, 5000),
|
|
2768
|
+
startOnMount: options.startOnMount ?? true,
|
|
2769
|
+
text: options.text ?? ""
|
|
2770
|
+
};
|
|
2771
|
+
}
|
|
2772
|
+
class TypewriterTextController {
|
|
2773
|
+
constructor(options = {}) {
|
|
2774
|
+
this.options = normalizeOptions$1(options);
|
|
2775
|
+
this.index = this.options.disabled ? this.options.text.length : 0;
|
|
2776
|
+
this.running = !this.options.disabled && this.options.startOnMount && this.options.text.length > 0;
|
|
2777
|
+
}
|
|
2778
|
+
updateOptions(options = {}) {
|
|
2779
|
+
const previousText = this.options.text;
|
|
2780
|
+
this.options = normalizeOptions$1({ ...this.options, ...options });
|
|
2781
|
+
if (this.options.disabled) {
|
|
2782
|
+
this.index = this.options.text.length;
|
|
2783
|
+
this.running = false;
|
|
2784
|
+
return this.getState();
|
|
2785
|
+
}
|
|
2786
|
+
if (previousText !== this.options.text) {
|
|
2787
|
+
this.index = 0;
|
|
2788
|
+
this.running = this.options.startOnMount && this.options.text.length > 0;
|
|
2789
|
+
}
|
|
2790
|
+
else {
|
|
2791
|
+
this.index = clamp$7(this.index, 0, this.options.text.length);
|
|
2792
|
+
if (this.index >= this.options.text.length)
|
|
2793
|
+
this.running = false;
|
|
2794
|
+
}
|
|
2795
|
+
return this.getState();
|
|
2796
|
+
}
|
|
2797
|
+
start() {
|
|
2798
|
+
if (!this.options.disabled && this.index < this.options.text.length)
|
|
2799
|
+
this.running = true;
|
|
2800
|
+
return this.getState();
|
|
2801
|
+
}
|
|
2802
|
+
pause() {
|
|
2803
|
+
this.running = false;
|
|
2804
|
+
return this.getState();
|
|
2805
|
+
}
|
|
2806
|
+
reset() {
|
|
2807
|
+
this.index = this.options.disabled ? this.options.text.length : 0;
|
|
2808
|
+
this.running = !this.options.disabled && this.options.startOnMount && this.options.text.length > 0;
|
|
2809
|
+
return this.getState();
|
|
2810
|
+
}
|
|
2811
|
+
finish() {
|
|
2812
|
+
this.index = this.options.text.length;
|
|
2813
|
+
this.running = false;
|
|
2814
|
+
return this.getState();
|
|
2815
|
+
}
|
|
2816
|
+
tick() {
|
|
2817
|
+
if (!this.running || this.options.disabled)
|
|
2818
|
+
return this.getState();
|
|
2819
|
+
if (this.index < this.options.text.length)
|
|
2820
|
+
this.index += 1;
|
|
2821
|
+
if (this.index >= this.options.text.length) {
|
|
2822
|
+
if (this.options.loop && this.options.text.length > 0) {
|
|
2823
|
+
this.index = 0;
|
|
2824
|
+
this.running = true;
|
|
2825
|
+
}
|
|
2826
|
+
else {
|
|
2827
|
+
this.running = false;
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
return this.getState();
|
|
2831
|
+
}
|
|
2832
|
+
getDelay() {
|
|
2833
|
+
return this.options.delay;
|
|
2834
|
+
}
|
|
2835
|
+
getSpeed() {
|
|
2836
|
+
return this.options.speed;
|
|
2837
|
+
}
|
|
2838
|
+
getState() {
|
|
2839
|
+
return {
|
|
2840
|
+
cursor: this.options.cursor,
|
|
2841
|
+
displayedText: this.options.text.slice(0, this.index),
|
|
2842
|
+
done: !this.running && this.index >= this.options.text.length,
|
|
2843
|
+
index: this.index,
|
|
2844
|
+
loading: this.options.loading && this.running,
|
|
2845
|
+
running: this.running,
|
|
2846
|
+
text: this.options.text
|
|
2847
|
+
};
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
const defaultColors = ["#7c3aed", "#ec4899", "#22d3ee"];
|
|
2852
|
+
const cssColorPattern$1 = /^(#|rgb\(|rgba\(|hsl\(|hsla\(|color\(|color-mix\(|var\(|[a-zA-Z])/;
|
|
2853
|
+
function normalizeColors$1(colors) {
|
|
2854
|
+
const next = (colors ?? [])
|
|
2855
|
+
.map((color) => String(color).trim())
|
|
2856
|
+
.filter((color) => color.length > 0 && cssColorPattern$1.test(color));
|
|
2857
|
+
return next.length >= 2 ? next : [...defaultColors];
|
|
2858
|
+
}
|
|
2859
|
+
function normalizeDirection(direction) {
|
|
2860
|
+
if (typeof direction === "number" && Number.isFinite(direction))
|
|
2861
|
+
return `${direction}deg`;
|
|
2862
|
+
const next = String(direction ?? "90deg").trim();
|
|
2863
|
+
return next.length > 0 ? next : "90deg";
|
|
2864
|
+
}
|
|
2865
|
+
function normalizeDuration(duration) {
|
|
2866
|
+
return Math.max(600, Number.isFinite(duration) ? Number(duration) : 3600);
|
|
2867
|
+
}
|
|
2868
|
+
function normalizeText(text) {
|
|
2869
|
+
return String(text ?? "");
|
|
2870
|
+
}
|
|
2871
|
+
function normalizeOptions(options = {}) {
|
|
2872
|
+
const colors = normalizeColors$1(options.colors);
|
|
2873
|
+
const direction = normalizeDirection(options.direction);
|
|
2874
|
+
return {
|
|
2875
|
+
animated: options.animated ?? false,
|
|
2876
|
+
backgroundImage: `linear-gradient(${direction}, ${colors.join(", ")})`,
|
|
2877
|
+
backgroundSize: String(options.backgroundSize ?? "200% 100%"),
|
|
2878
|
+
colors,
|
|
2879
|
+
direction,
|
|
2880
|
+
duration: normalizeDuration(options.duration),
|
|
2881
|
+
easing: String(options.easing ?? "cubic-bezier(0.22, 0.8, 0.28, 1)"),
|
|
2882
|
+
fontWeight: options.fontWeight ?? 700,
|
|
2883
|
+
text: normalizeText(options.text)
|
|
2884
|
+
};
|
|
2885
|
+
}
|
|
2886
|
+
class GradientTextController {
|
|
2887
|
+
constructor(options = {}) {
|
|
2888
|
+
this.state = normalizeOptions(options);
|
|
2889
|
+
}
|
|
2890
|
+
updateOptions(options = {}) {
|
|
2891
|
+
this.state = normalizeOptions(options);
|
|
2892
|
+
return this.getState();
|
|
2893
|
+
}
|
|
2894
|
+
getState() {
|
|
2895
|
+
return { ...this.state, colors: [...this.state.colors] };
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
|
|
2899
|
+
const presetSet = new Set([
|
|
2900
|
+
"aurora",
|
|
2901
|
+
"border-glow",
|
|
2902
|
+
"frosted",
|
|
2903
|
+
"glass",
|
|
2904
|
+
"gradient",
|
|
2905
|
+
"holographic",
|
|
2906
|
+
"mesh",
|
|
2907
|
+
"neon",
|
|
2908
|
+
"noise",
|
|
2909
|
+
"scanline",
|
|
2910
|
+
"soft-grid",
|
|
2911
|
+
"spotlight"
|
|
2912
|
+
]);
|
|
2913
|
+
const toneSet = new Set(["accent", "cool", "danger", "neutral", "success", "warm"]);
|
|
2914
|
+
const toneColors = {
|
|
2915
|
+
accent: ["#7c3aed", "#ec4899", "#22d3ee"],
|
|
2916
|
+
cool: ["#0ea5e9", "#22d3ee", "#14b8a6"],
|
|
2917
|
+
danger: ["#ef4444", "#f97316", "#facc15"],
|
|
2918
|
+
neutral: ["#334155", "#94a3b8", "#e2e8f0"],
|
|
2919
|
+
success: ["#16a34a", "#22c55e", "#84cc16"],
|
|
2920
|
+
warm: ["#f59e0b", "#f97316", "#fb7185"]
|
|
2921
|
+
};
|
|
2922
|
+
const cssColorPattern = /^(#|rgb\(|rgba\(|hsl\(|hsla\(|color\(|color-mix\(|var\(|[a-zA-Z])/;
|
|
2923
|
+
function clamp$6(value, min, max) {
|
|
2924
|
+
return Math.min(max, Math.max(min, value));
|
|
2925
|
+
}
|
|
2926
|
+
function normalizePreset(preset) {
|
|
2927
|
+
return presetSet.has(preset) ? preset : "glass";
|
|
2928
|
+
}
|
|
2929
|
+
function normalizeTone(tone) {
|
|
2930
|
+
return toneSet.has(tone) ? tone : "accent";
|
|
2931
|
+
}
|
|
2932
|
+
function normalizeRadius(radius) {
|
|
2933
|
+
if (typeof radius === "number" && Number.isFinite(radius))
|
|
2934
|
+
return `${Math.max(0, radius)}px`;
|
|
2935
|
+
const next = String(radius ?? "var(--cc-radius-lg)").trim();
|
|
2936
|
+
return next.length > 0 ? next : "var(--cc-radius-lg)";
|
|
2937
|
+
}
|
|
2938
|
+
function normalizeColors(colors, tone) {
|
|
2939
|
+
const next = (colors ?? [])
|
|
2940
|
+
.map((color) => String(color).trim())
|
|
2941
|
+
.filter((color) => color.length > 0 && cssColorPattern.test(color));
|
|
2942
|
+
return next.length >= 2 ? next : [...toneColors[tone]];
|
|
2943
|
+
}
|
|
2944
|
+
function normalizeIntensity(intensity) {
|
|
2945
|
+
return clamp$6(Number.isFinite(intensity) ? Number(intensity) : 0.72, 0, 1);
|
|
2946
|
+
}
|
|
2947
|
+
class DesignEffectController {
|
|
2948
|
+
constructor(options = {}) {
|
|
2949
|
+
this.state = this.normalize(options);
|
|
2950
|
+
}
|
|
2951
|
+
updateOptions(options = {}) {
|
|
2952
|
+
this.state = this.normalize(options);
|
|
2953
|
+
return this.getState();
|
|
2954
|
+
}
|
|
2955
|
+
getState() {
|
|
2956
|
+
return {
|
|
2957
|
+
...this.state,
|
|
2958
|
+
colors: [...this.state.colors],
|
|
2959
|
+
styleVars: { ...this.state.styleVars }
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
normalize(options) {
|
|
2963
|
+
const preset = normalizePreset(options.preset);
|
|
2964
|
+
const tone = normalizeTone(options.tone);
|
|
2965
|
+
const colors = normalizeColors(options.colors, tone);
|
|
2966
|
+
const intensity = normalizeIntensity(options.intensity);
|
|
2967
|
+
const radius = normalizeRadius(options.radius);
|
|
2968
|
+
const animated = options.animated ?? ["aurora", "gradient", "holographic", "scanline"].includes(preset);
|
|
2969
|
+
return {
|
|
2970
|
+
animated,
|
|
2971
|
+
className: `cc-design-effect cc-design-effect--${preset}`,
|
|
2972
|
+
colors,
|
|
2973
|
+
disabled: options.disabled ?? false,
|
|
2974
|
+
intensity,
|
|
2975
|
+
interactive: options.interactive ?? ["border-glow", "glass", "spotlight"].includes(preset),
|
|
2976
|
+
overlay: !["border-glow", "noise", "soft-grid"].includes(preset),
|
|
2977
|
+
preset,
|
|
2978
|
+
radius,
|
|
2979
|
+
styleVars: {
|
|
2980
|
+
"--cc-design-effect-alpha": intensity.toFixed(3),
|
|
2981
|
+
"--cc-design-effect-color-1": colors[0],
|
|
2982
|
+
"--cc-design-effect-color-2": colors[1],
|
|
2983
|
+
"--cc-design-effect-color-3": colors[2] ?? colors[0],
|
|
2984
|
+
"--cc-design-effect-radius": radius
|
|
2985
|
+
},
|
|
2986
|
+
tone
|
|
2987
|
+
};
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
function clamp$5(value, min, max) {
|
|
2992
|
+
return Math.min(max, Math.max(min, value));
|
|
2993
|
+
}
|
|
2994
|
+
class SwiperController {
|
|
2995
|
+
constructor(options) {
|
|
2996
|
+
this.count = Math.max(0, Math.floor(options.count));
|
|
2997
|
+
this.current = clamp$5(Math.floor(options.current ?? 0), 0, Math.max(0, this.count - 1));
|
|
2998
|
+
this.loop = options.loop ?? false;
|
|
2999
|
+
this.threshold = Math.max(1, options.threshold ?? 48);
|
|
3000
|
+
}
|
|
3001
|
+
updateOptions(options) {
|
|
3002
|
+
if (options.count !== undefined)
|
|
3003
|
+
this.count = Math.max(0, Math.floor(options.count));
|
|
3004
|
+
if (options.loop !== undefined)
|
|
3005
|
+
this.loop = options.loop;
|
|
3006
|
+
if (options.threshold !== undefined)
|
|
3007
|
+
this.threshold = Math.max(1, options.threshold);
|
|
3008
|
+
if (options.current !== undefined)
|
|
3009
|
+
this.current = clamp$5(Math.floor(options.current), 0, Math.max(0, this.count - 1));
|
|
3010
|
+
else
|
|
3011
|
+
this.current = clamp$5(this.current, 0, Math.max(0, this.count - 1));
|
|
3012
|
+
return this.getState();
|
|
3013
|
+
}
|
|
3014
|
+
next() {
|
|
3015
|
+
if (this.count <= 0)
|
|
3016
|
+
return this.getState();
|
|
3017
|
+
this.current = this.current >= this.count - 1 ? (this.loop ? 0 : this.count - 1) : this.current + 1;
|
|
3018
|
+
return this.getState();
|
|
3019
|
+
}
|
|
3020
|
+
previous() {
|
|
3021
|
+
if (this.count <= 0)
|
|
3022
|
+
return this.getState();
|
|
3023
|
+
this.current = this.current <= 0 ? (this.loop ? this.count - 1 : 0) : this.current - 1;
|
|
3024
|
+
return this.getState();
|
|
3025
|
+
}
|
|
3026
|
+
resolveSwipe(deltaX, velocityX = 0) {
|
|
3027
|
+
if (Math.abs(deltaX) < this.threshold && Math.abs(velocityX) < 360)
|
|
3028
|
+
return this.getState();
|
|
3029
|
+
return deltaX < 0 || velocityX < -360 ? this.next() : this.previous();
|
|
3030
|
+
}
|
|
3031
|
+
setCurrent(index) {
|
|
3032
|
+
this.current = clamp$5(index, 0, Math.max(0, this.count - 1));
|
|
3033
|
+
return this.getState();
|
|
3034
|
+
}
|
|
3035
|
+
getState() {
|
|
3036
|
+
return {
|
|
3037
|
+
count: this.count,
|
|
3038
|
+
current: this.current,
|
|
3039
|
+
loop: this.loop
|
|
3040
|
+
};
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
function clamp$4(value, min, max) {
|
|
3045
|
+
return Math.min(max, Math.max(min, value));
|
|
3046
|
+
}
|
|
3047
|
+
class ImagePreviewController {
|
|
3048
|
+
constructor(items = [], activeIndex = 0, open = false) {
|
|
3049
|
+
this.loading = false;
|
|
3050
|
+
this.items = items.filter((item) => item.src);
|
|
3051
|
+
this.activeIndex = clamp$4(activeIndex, 0, Math.max(0, this.items.length - 1));
|
|
3052
|
+
this.openState = open;
|
|
3053
|
+
}
|
|
3054
|
+
updateItems(items, activeIndex = this.activeIndex) {
|
|
3055
|
+
this.items = items.filter((item) => item.src);
|
|
3056
|
+
this.activeIndex = clamp$4(activeIndex, 0, Math.max(0, this.items.length - 1));
|
|
3057
|
+
this.loading = false;
|
|
3058
|
+
return this.getState();
|
|
3059
|
+
}
|
|
3060
|
+
open(index = this.activeIndex) {
|
|
3061
|
+
this.openState = true;
|
|
3062
|
+
this.activeIndex = clamp$4(index, 0, Math.max(0, this.items.length - 1));
|
|
3063
|
+
return this.getState();
|
|
3064
|
+
}
|
|
3065
|
+
close() {
|
|
3066
|
+
this.openState = false;
|
|
3067
|
+
return this.getState();
|
|
3068
|
+
}
|
|
3069
|
+
next() {
|
|
3070
|
+
if (this.items.length > 0)
|
|
3071
|
+
this.activeIndex = (this.activeIndex + 1) % this.items.length;
|
|
3072
|
+
this.loading = true;
|
|
3073
|
+
return this.getState();
|
|
3074
|
+
}
|
|
3075
|
+
previous() {
|
|
3076
|
+
if (this.items.length > 0)
|
|
3077
|
+
this.activeIndex = (this.activeIndex - 1 + this.items.length) % this.items.length;
|
|
3078
|
+
this.loading = true;
|
|
3079
|
+
return this.getState();
|
|
3080
|
+
}
|
|
3081
|
+
setActiveIndex(index) {
|
|
3082
|
+
this.activeIndex = clamp$4(index, 0, Math.max(0, this.items.length - 1));
|
|
3083
|
+
this.loading = true;
|
|
3084
|
+
return this.getState();
|
|
3085
|
+
}
|
|
3086
|
+
setLoading(loading) {
|
|
3087
|
+
this.loading = loading;
|
|
3088
|
+
return this.getState();
|
|
3089
|
+
}
|
|
3090
|
+
getState() {
|
|
3091
|
+
return {
|
|
3092
|
+
activeIndex: this.activeIndex,
|
|
3093
|
+
activeItem: this.items[this.activeIndex],
|
|
3094
|
+
count: this.items.length,
|
|
3095
|
+
items: this.items,
|
|
3096
|
+
loading: this.loading,
|
|
3097
|
+
open: this.openState
|
|
3098
|
+
};
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
|
|
3102
|
+
class TimelineController {
|
|
3103
|
+
constructor(options) {
|
|
3104
|
+
this.items = options.items;
|
|
3105
|
+
this.direction = options.direction ?? "vertical";
|
|
3106
|
+
}
|
|
3107
|
+
updateOptions(options) {
|
|
3108
|
+
if (options.items)
|
|
3109
|
+
this.items = options.items;
|
|
3110
|
+
if (options.direction)
|
|
3111
|
+
this.direction = options.direction;
|
|
3112
|
+
return this.getState();
|
|
3113
|
+
}
|
|
3114
|
+
getState() {
|
|
3115
|
+
return { direction: this.direction, items: this.items };
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
function normalizeSources(input) {
|
|
3120
|
+
const list = Array.isArray(input) ? input : [input];
|
|
3121
|
+
return list
|
|
3122
|
+
.map((source) => (typeof source === "string" ? { src: source } : source))
|
|
3123
|
+
.filter((source) => Boolean(source.src));
|
|
3124
|
+
}
|
|
3125
|
+
class VideoPlayerController {
|
|
3126
|
+
constructor(options) {
|
|
3127
|
+
this.state = this.normalize(options);
|
|
3128
|
+
}
|
|
3129
|
+
updateOptions(options) {
|
|
3130
|
+
this.state = this.normalize({ ...this.state, ...options, sources: options.sources ?? this.state.sources });
|
|
3131
|
+
return this.getState();
|
|
3132
|
+
}
|
|
3133
|
+
getState() {
|
|
3134
|
+
return { ...this.state, sources: [...this.state.sources] };
|
|
3135
|
+
}
|
|
3136
|
+
normalize(options) {
|
|
3137
|
+
return {
|
|
3138
|
+
autoplay: options.autoplay ?? false,
|
|
3139
|
+
controls: options.controls ?? true,
|
|
3140
|
+
loop: options.loop ?? false,
|
|
3141
|
+
muted: options.muted ?? false,
|
|
3142
|
+
poster: options.poster,
|
|
3143
|
+
preload: options.preload ?? "metadata",
|
|
3144
|
+
sources: normalizeSources(options.sources)
|
|
3145
|
+
};
|
|
3146
|
+
}
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
function cloneItem(item) {
|
|
3150
|
+
return {
|
|
3151
|
+
...item,
|
|
3152
|
+
sources: Array.isArray(item.sources) ? [...item.sources] : item.sources
|
|
3153
|
+
};
|
|
3154
|
+
}
|
|
3155
|
+
function normalizeRect(rect) {
|
|
3156
|
+
if (!rect)
|
|
3157
|
+
return undefined;
|
|
3158
|
+
return {
|
|
3159
|
+
height: Math.max(1, rect.height),
|
|
3160
|
+
left: Number.isFinite(rect.left) ? rect.left : 0,
|
|
3161
|
+
top: Number.isFinite(rect.top) ? rect.top : 0,
|
|
3162
|
+
width: Math.max(1, rect.width)
|
|
3163
|
+
};
|
|
3164
|
+
}
|
|
3165
|
+
class VideoDetailTransitionController {
|
|
3166
|
+
constructor(options) {
|
|
3167
|
+
this.state = this.normalize(options);
|
|
3168
|
+
}
|
|
3169
|
+
updateOptions(options) {
|
|
3170
|
+
this.state = this.normalize({ ...this.state, ...options, items: options.items ?? this.state.items });
|
|
3171
|
+
return this.getState();
|
|
3172
|
+
}
|
|
3173
|
+
open(id, sourceRect) {
|
|
3174
|
+
const activeItem = this.state.items.find((item) => item.id === id);
|
|
3175
|
+
this.state = {
|
|
3176
|
+
...this.state,
|
|
3177
|
+
activeId: activeItem?.id,
|
|
3178
|
+
activeItem,
|
|
3179
|
+
phase: activeItem ? "entering" : "closed",
|
|
3180
|
+
sourceRect: normalizeRect(sourceRect)
|
|
3181
|
+
};
|
|
3182
|
+
return this.getState();
|
|
3183
|
+
}
|
|
3184
|
+
entered() {
|
|
3185
|
+
if (!this.state.activeItem)
|
|
3186
|
+
return this.closeNow();
|
|
3187
|
+
this.state = { ...this.state, phase: "open" };
|
|
3188
|
+
return this.getState();
|
|
3189
|
+
}
|
|
3190
|
+
close() {
|
|
3191
|
+
if (!this.state.activeItem)
|
|
3192
|
+
return this.closeNow();
|
|
3193
|
+
this.state = { ...this.state, phase: "leaving" };
|
|
3194
|
+
return this.getState();
|
|
3195
|
+
}
|
|
3196
|
+
closeNow() {
|
|
3197
|
+
this.state = { ...this.state, activeId: undefined, activeItem: undefined, phase: "closed", sourceRect: undefined };
|
|
3198
|
+
return this.getState();
|
|
3199
|
+
}
|
|
3200
|
+
getState() {
|
|
3201
|
+
return {
|
|
3202
|
+
...this.state,
|
|
3203
|
+
activeItem: this.state.activeItem ? cloneItem(this.state.activeItem) : undefined,
|
|
3204
|
+
items: this.state.items.map(cloneItem),
|
|
3205
|
+
sourceRect: this.state.sourceRect ? { ...this.state.sourceRect } : undefined
|
|
3206
|
+
};
|
|
3207
|
+
}
|
|
3208
|
+
normalize(options) {
|
|
3209
|
+
const items = options.items.map(cloneItem);
|
|
3210
|
+
const activeItem = options.activeId ? items.find((item) => item.id === options.activeId) : undefined;
|
|
3211
|
+
return {
|
|
3212
|
+
activeId: activeItem?.id,
|
|
3213
|
+
activeItem,
|
|
3214
|
+
animationDuration: Math.max(120, Math.min(900, options.animationDuration ?? 420)),
|
|
3215
|
+
backdropColor: options.backdropColor ?? "rgba(0, 0, 0, 0.96)",
|
|
3216
|
+
items,
|
|
3217
|
+
phase: activeItem ? options.phase ?? "open" : "closed",
|
|
3218
|
+
sourceRect: normalizeRect(options.sourceRect)
|
|
3219
|
+
};
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3223
|
+
const WORD_EXTENSIONS = new Set(["doc", "docx", "rtf"]);
|
|
3224
|
+
const EXCEL_EXTENSIONS = new Set(["csv", "xls", "xlsx"]);
|
|
3225
|
+
const PPT_EXTENSIONS = new Set(["ppt", "pptx"]);
|
|
3226
|
+
const DEFAULT_OFFICE_VIEWER = "https://view.officeapps.live.com/op/embed.aspx?src=";
|
|
3227
|
+
function clamp$3(value, min, max) {
|
|
3228
|
+
return Math.min(max, Math.max(min, value));
|
|
3229
|
+
}
|
|
3230
|
+
function getExtension(value) {
|
|
3231
|
+
const clean = value.split("?")[0]?.split("#")[0] ?? value;
|
|
3232
|
+
const filename = clean.split("/").pop() ?? clean;
|
|
3233
|
+
const extension = filename.includes(".") ? filename.split(".").pop() ?? "" : "";
|
|
3234
|
+
return extension.toLowerCase();
|
|
3235
|
+
}
|
|
3236
|
+
function inferType(src, fileName) {
|
|
3237
|
+
const extension = getExtension(fileName || src);
|
|
3238
|
+
if (extension === "pdf")
|
|
3239
|
+
return "pdf";
|
|
3240
|
+
if (WORD_EXTENSIONS.has(extension))
|
|
3241
|
+
return "word";
|
|
3242
|
+
if (EXCEL_EXTENSIONS.has(extension))
|
|
3243
|
+
return "excel";
|
|
3244
|
+
if (PPT_EXTENSIONS.has(extension))
|
|
3245
|
+
return "ppt";
|
|
3246
|
+
return "unknown";
|
|
3247
|
+
}
|
|
3248
|
+
function inferFileName(src, fileName) {
|
|
3249
|
+
if (fileName)
|
|
3250
|
+
return fileName;
|
|
3251
|
+
try {
|
|
3252
|
+
const url = new URL(src, "https://class-kit.local");
|
|
3253
|
+
const last = url.pathname.split("/").filter(Boolean).pop();
|
|
3254
|
+
return last ? decodeURIComponent(last) : "Document";
|
|
3255
|
+
}
|
|
3256
|
+
catch {
|
|
3257
|
+
const last = src.split("?")[0]?.split("#")[0]?.split("/").filter(Boolean).pop();
|
|
3258
|
+
return last ? decodeURIComponent(last) : "Document";
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
function buildPdfUrl(src, page) {
|
|
3262
|
+
const clean = src.split("#")[0] ?? src;
|
|
3263
|
+
return `${clean}#page=${page}`;
|
|
3264
|
+
}
|
|
3265
|
+
function buildOfficeUrl(src, viewerBaseUrl) {
|
|
3266
|
+
const base = viewerBaseUrl || DEFAULT_OFFICE_VIEWER;
|
|
3267
|
+
return `${base}${encodeURIComponent(src)}`;
|
|
3268
|
+
}
|
|
3269
|
+
class FilePreviewController {
|
|
3270
|
+
constructor(options) {
|
|
3271
|
+
this.options = { ...options };
|
|
3272
|
+
}
|
|
3273
|
+
updateOptions(options) {
|
|
3274
|
+
this.options = { ...this.options, ...options };
|
|
3275
|
+
return this.getState();
|
|
3276
|
+
}
|
|
3277
|
+
goTo(page) {
|
|
3278
|
+
this.options.currentPage = page;
|
|
3279
|
+
return this.getState();
|
|
3280
|
+
}
|
|
3281
|
+
next() {
|
|
3282
|
+
return this.goTo(this.getState().currentPage + 1);
|
|
3283
|
+
}
|
|
3284
|
+
previous() {
|
|
3285
|
+
return this.goTo(this.getState().currentPage - 1);
|
|
3286
|
+
}
|
|
3287
|
+
getState() {
|
|
3288
|
+
const fileName = inferFileName(this.options.src, this.options.fileName);
|
|
3289
|
+
const type = this.options.type && this.options.type !== "unknown" ? this.options.type : inferType(this.options.src, fileName);
|
|
3290
|
+
const pageCount = this.options.pageCount && this.options.pageCount > 0 ? Math.floor(this.options.pageCount) : undefined;
|
|
3291
|
+
const currentPage = clamp$3(Math.floor(this.options.currentPage ?? 1), 1, pageCount ?? Number.MAX_SAFE_INTEGER);
|
|
3292
|
+
const mode = type === "pdf" ? "pdf" : type === "word" || type === "excel" || type === "ppt" ? "office" : "unsupported";
|
|
3293
|
+
const previewUrl = mode === "pdf"
|
|
3294
|
+
? buildPdfUrl(this.options.src, currentPage)
|
|
3295
|
+
: mode === "office"
|
|
3296
|
+
? buildOfficeUrl(this.options.src, this.options.viewerBaseUrl)
|
|
3297
|
+
: "";
|
|
3298
|
+
return {
|
|
3299
|
+
currentPage,
|
|
3300
|
+
fileName,
|
|
3301
|
+
mode,
|
|
3302
|
+
pageCount,
|
|
3303
|
+
previewUrl,
|
|
3304
|
+
src: this.options.src,
|
|
3305
|
+
title: fileName,
|
|
3306
|
+
type
|
|
3307
|
+
};
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
function clamp$2(value, min, max) {
|
|
3312
|
+
return Math.min(max, Math.max(min, value));
|
|
3313
|
+
}
|
|
3314
|
+
class ProgressController {
|
|
3315
|
+
constructor(options = {}) {
|
|
3316
|
+
this.min = options.min ?? 0;
|
|
3317
|
+
this.max = Math.max(this.min, options.max ?? 100);
|
|
3318
|
+
this.step = Math.max(0, options.step ?? 1);
|
|
3319
|
+
this.disabled = options.disabled ?? false;
|
|
3320
|
+
this.value = this.normalizeValue(options.value ?? this.min);
|
|
3321
|
+
}
|
|
3322
|
+
updateOptions(options) {
|
|
3323
|
+
if (options.min !== undefined)
|
|
3324
|
+
this.min = options.min;
|
|
3325
|
+
if (options.max !== undefined)
|
|
3326
|
+
this.max = Math.max(this.min, options.max);
|
|
3327
|
+
if (options.step !== undefined)
|
|
3328
|
+
this.step = Math.max(0, options.step);
|
|
3329
|
+
if (options.disabled !== undefined)
|
|
3330
|
+
this.disabled = options.disabled;
|
|
3331
|
+
if (options.value !== undefined)
|
|
3332
|
+
this.value = this.normalizeValue(options.value);
|
|
3333
|
+
return this.getState();
|
|
3334
|
+
}
|
|
3335
|
+
setValue(value) {
|
|
3336
|
+
if (!this.disabled)
|
|
3337
|
+
this.value = this.normalizeValue(value);
|
|
3338
|
+
return this.getState();
|
|
3339
|
+
}
|
|
3340
|
+
valueFromRatio(ratio) {
|
|
3341
|
+
return this.setValue(this.min + clamp$2(ratio, 0, 1) * (this.max - this.min));
|
|
3342
|
+
}
|
|
3343
|
+
valueFromClientX(clientX, rect, thumbWidth = 0) {
|
|
3344
|
+
if (rect.width <= 0)
|
|
3345
|
+
return this.getState();
|
|
3346
|
+
const travelWidth = Math.max(1, rect.width - Math.max(0, thumbWidth));
|
|
3347
|
+
const offset = clientX - rect.left - Math.max(0, thumbWidth) / 2;
|
|
3348
|
+
return this.valueFromRatio(offset / travelWidth);
|
|
3349
|
+
}
|
|
3350
|
+
getState() {
|
|
3351
|
+
const range = this.max - this.min;
|
|
3352
|
+
return {
|
|
3353
|
+
disabled: this.disabled,
|
|
3354
|
+
max: this.max,
|
|
3355
|
+
min: this.min,
|
|
3356
|
+
percent: range <= 0 ? 0 : ((this.value - this.min) / range) * 100,
|
|
3357
|
+
step: this.step,
|
|
3358
|
+
value: this.value
|
|
3359
|
+
};
|
|
3360
|
+
}
|
|
3361
|
+
normalizeValue(value) {
|
|
3362
|
+
const clamped = clamp$2(Number.isFinite(value) ? value : this.min, this.min, this.max);
|
|
3363
|
+
if (this.step <= 0)
|
|
3364
|
+
return clamped;
|
|
3365
|
+
const precision = Math.max(0, String(this.step).split(".")[1]?.length ?? 0);
|
|
3366
|
+
return Number((Math.round((clamped - this.min) / this.step) * this.step + this.min).toFixed(precision));
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
|
|
3370
|
+
function clamp$1(value, min, max) {
|
|
3371
|
+
return Math.min(max, Math.max(min, value));
|
|
3372
|
+
}
|
|
3373
|
+
function normalizeLineWidth(value) {
|
|
3374
|
+
return clamp$1(Number.isFinite(value ?? NaN) ? Number(value) : 3, 0.5, 24);
|
|
3375
|
+
}
|
|
3376
|
+
function normalizePoint(x, y, size, pressure = 0.5) {
|
|
3377
|
+
const width = Math.max(1, size.width);
|
|
3378
|
+
const height = Math.max(1, size.height);
|
|
3379
|
+
return {
|
|
3380
|
+
pressure: clamp$1(Number.isFinite(pressure) ? pressure : 0.5, 0, 1),
|
|
3381
|
+
time: Date.now(),
|
|
3382
|
+
x: clamp$1(x / width, 0, 1),
|
|
3383
|
+
y: clamp$1(y / height, 0, 1)
|
|
3384
|
+
};
|
|
3385
|
+
}
|
|
3386
|
+
class SignatureController {
|
|
3387
|
+
constructor(options = {}) {
|
|
3388
|
+
this.isDrawing = false;
|
|
3389
|
+
this.strokes = [];
|
|
3390
|
+
this.disabled = options.disabled ?? false;
|
|
3391
|
+
this.lineWidth = normalizeLineWidth(options.lineWidth);
|
|
3392
|
+
this.penColor = options.penColor ?? "#111827";
|
|
3393
|
+
this.readOnly = options.readOnly ?? false;
|
|
3394
|
+
}
|
|
3395
|
+
updateOptions(options = {}) {
|
|
3396
|
+
if (options.disabled !== undefined)
|
|
3397
|
+
this.disabled = options.disabled;
|
|
3398
|
+
if (options.lineWidth !== undefined)
|
|
3399
|
+
this.lineWidth = normalizeLineWidth(options.lineWidth);
|
|
3400
|
+
if (options.penColor !== undefined)
|
|
3401
|
+
this.penColor = options.penColor;
|
|
3402
|
+
if (options.readOnly !== undefined)
|
|
3403
|
+
this.readOnly = options.readOnly;
|
|
3404
|
+
return this.getState();
|
|
3405
|
+
}
|
|
3406
|
+
beginStroke(x, y, size, pressure = 0.5) {
|
|
3407
|
+
if (this.disabled || this.readOnly)
|
|
3408
|
+
return this.getState();
|
|
3409
|
+
this.isDrawing = true;
|
|
3410
|
+
this.strokes.push({
|
|
3411
|
+
color: this.penColor,
|
|
3412
|
+
lineWidth: this.lineWidth,
|
|
3413
|
+
points: [normalizePoint(x, y, size, pressure)]
|
|
3414
|
+
});
|
|
3415
|
+
return this.getState();
|
|
3416
|
+
}
|
|
3417
|
+
addPoint(x, y, size, pressure = 0.5) {
|
|
3418
|
+
if (!this.isDrawing || this.disabled || this.readOnly)
|
|
3419
|
+
return this.getState();
|
|
3420
|
+
const stroke = this.strokes[this.strokes.length - 1];
|
|
3421
|
+
if (!stroke)
|
|
3422
|
+
return this.getState();
|
|
3423
|
+
stroke.points.push(normalizePoint(x, y, size, pressure));
|
|
3424
|
+
return this.getState();
|
|
3425
|
+
}
|
|
3426
|
+
endStroke() {
|
|
3427
|
+
this.isDrawing = false;
|
|
3428
|
+
const stroke = this.strokes[this.strokes.length - 1];
|
|
3429
|
+
if (stroke && stroke.points.length === 0)
|
|
3430
|
+
this.strokes.pop();
|
|
3431
|
+
return this.getState();
|
|
3432
|
+
}
|
|
3433
|
+
clear() {
|
|
3434
|
+
this.isDrawing = false;
|
|
3435
|
+
this.strokes = [];
|
|
3436
|
+
return this.getState();
|
|
3437
|
+
}
|
|
3438
|
+
undo() {
|
|
3439
|
+
if (!this.disabled && !this.readOnly)
|
|
3440
|
+
this.strokes.pop();
|
|
3441
|
+
return this.getState();
|
|
3442
|
+
}
|
|
3443
|
+
replaceStrokes(strokes = []) {
|
|
3444
|
+
this.strokes = strokes.map((stroke) => ({
|
|
3445
|
+
color: stroke.color,
|
|
3446
|
+
lineWidth: normalizeLineWidth(stroke.lineWidth),
|
|
3447
|
+
points: stroke.points.map((point) => ({
|
|
3448
|
+
pressure: clamp$1(point.pressure, 0, 1),
|
|
3449
|
+
time: point.time,
|
|
3450
|
+
x: clamp$1(point.x, 0, 1),
|
|
3451
|
+
y: clamp$1(point.y, 0, 1)
|
|
3452
|
+
}))
|
|
3453
|
+
}));
|
|
3454
|
+
this.isDrawing = false;
|
|
3455
|
+
return this.getState();
|
|
3456
|
+
}
|
|
3457
|
+
getState() {
|
|
3458
|
+
return {
|
|
3459
|
+
disabled: this.disabled,
|
|
3460
|
+
isDrawing: this.isDrawing,
|
|
3461
|
+
isEmpty: this.strokes.length === 0,
|
|
3462
|
+
lineWidth: this.lineWidth,
|
|
3463
|
+
penColor: this.penColor,
|
|
3464
|
+
readOnly: this.readOnly,
|
|
3465
|
+
strokeCount: this.strokes.length,
|
|
3466
|
+
strokes: this.strokes.map((stroke) => ({
|
|
3467
|
+
color: stroke.color,
|
|
3468
|
+
lineWidth: stroke.lineWidth,
|
|
3469
|
+
points: stroke.points.map((point) => ({ ...point }))
|
|
3470
|
+
}))
|
|
3471
|
+
};
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
const DEFAULT_MIN_WIDTH = 32;
|
|
3476
|
+
const DEFAULT_MAX_WIDTH = 1000;
|
|
3477
|
+
function normalizeMinWidth(width) {
|
|
3478
|
+
return Math.max(DEFAULT_MIN_WIDTH, Math.floor(Number.isFinite(width) ? Number(width) : DEFAULT_MIN_WIDTH));
|
|
3479
|
+
}
|
|
3480
|
+
function normalizeMaxWidth(width, minWidth = DEFAULT_MIN_WIDTH) {
|
|
3481
|
+
return Math.max(minWidth, Math.min(DEFAULT_MAX_WIDTH, Math.floor(Number.isFinite(width) ? Number(width) : DEFAULT_MAX_WIDTH)));
|
|
3482
|
+
}
|
|
3483
|
+
function clampWidth(width, minWidth, maxWidth, fallback = minWidth) {
|
|
3484
|
+
const next = Number.isFinite(width) ? Number(width) : fallback;
|
|
3485
|
+
return Math.max(minWidth, Math.min(maxWidth, Math.round(next)));
|
|
3486
|
+
}
|
|
3487
|
+
class TableController {
|
|
3488
|
+
constructor(options = {}) {
|
|
3489
|
+
this.options = this.normalize(options);
|
|
3490
|
+
}
|
|
3491
|
+
update(options = {}) {
|
|
3492
|
+
this.options = this.normalize({ ...this.options, ...options });
|
|
3493
|
+
return this.getState();
|
|
3494
|
+
}
|
|
3495
|
+
resizeColumn(key, delta, containerWidth = this.options.containerWidth) {
|
|
3496
|
+
if (!Number.isFinite(delta) || delta === 0)
|
|
3497
|
+
return this.getState();
|
|
3498
|
+
const columns = this.getNormalizedColumns();
|
|
3499
|
+
const availableContainerWidth = this.getColumnContainerWidth(containerWidth);
|
|
3500
|
+
const visibleIndexes = columns.map((column, index) => column.hidden ? -1 : index).filter((index) => index >= 0);
|
|
3501
|
+
const targetIndex = columns.findIndex((column) => column.key === key && !column.hidden);
|
|
3502
|
+
if (targetIndex < 0)
|
|
3503
|
+
return this.getState();
|
|
3504
|
+
const target = columns[targetIndex];
|
|
3505
|
+
if (!target)
|
|
3506
|
+
return this.getState();
|
|
3507
|
+
const currentTotal = visibleIndexes.reduce((sum, index) => sum + (columns[index]?.width ?? 0), 0);
|
|
3508
|
+
let desired = delta;
|
|
3509
|
+
if (desired > 0) {
|
|
3510
|
+
const targetGrow = target.maxWidth - target.width;
|
|
3511
|
+
const fillGap = Math.max(0, availableContainerWidth - currentTotal);
|
|
3512
|
+
const growWithoutShrink = Math.min(desired, targetGrow, fillGap);
|
|
3513
|
+
target.width += growWithoutShrink;
|
|
3514
|
+
desired -= growWithoutShrink;
|
|
3515
|
+
if (desired > 0) {
|
|
3516
|
+
const shrinkableIndexes = visibleIndexes.filter((index) => index !== targetIndex && index > targetIndex);
|
|
3517
|
+
const fallbackIndexes = visibleIndexes.filter((index) => index !== targetIndex && index < targetIndex).reverse();
|
|
3518
|
+
const shrinkable = [...shrinkableIndexes, ...fallbackIndexes];
|
|
3519
|
+
let shrinkNeed = Math.min(desired, target.maxWidth - target.width);
|
|
3520
|
+
for (const index of shrinkable) {
|
|
3521
|
+
if (shrinkNeed <= 0)
|
|
3522
|
+
break;
|
|
3523
|
+
const column = columns[index];
|
|
3524
|
+
if (!column)
|
|
3525
|
+
continue;
|
|
3526
|
+
const amount = Math.min(shrinkNeed, column.width - column.minWidth);
|
|
3527
|
+
column.width -= amount;
|
|
3528
|
+
shrinkNeed -= amount;
|
|
3529
|
+
target.width += amount;
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
else {
|
|
3534
|
+
const shrink = Math.min(Math.abs(desired), target.width - target.minWidth);
|
|
3535
|
+
target.width -= shrink;
|
|
3536
|
+
}
|
|
3537
|
+
target.autoWidth = false;
|
|
3538
|
+
this.options.columns = columns;
|
|
3539
|
+
return this.getState();
|
|
3540
|
+
}
|
|
3541
|
+
toggleColumn(key, visible, containerWidth = this.options.containerWidth) {
|
|
3542
|
+
const columns = this.options.columns;
|
|
3543
|
+
const target = columns.find((column) => column.key === key);
|
|
3544
|
+
if (!target)
|
|
3545
|
+
return this.getState();
|
|
3546
|
+
const nextHidden = visible === undefined ? !target.hidden : !visible;
|
|
3547
|
+
const visibleCount = columns.filter((column) => !column.hidden).length;
|
|
3548
|
+
if (nextHidden && !target.hidden && visibleCount <= 1)
|
|
3549
|
+
return this.getState();
|
|
3550
|
+
this.options.containerWidth = this.getColumnContainerWidth(containerWidth);
|
|
3551
|
+
this.options.columns = columns.map((column) => column.key === key ? { ...column, hidden: nextHidden } : column);
|
|
3552
|
+
return this.getState();
|
|
3553
|
+
}
|
|
3554
|
+
toggleRow(key, checked) {
|
|
3555
|
+
const set = new Set(this.options.selectedKeys);
|
|
3556
|
+
const nextChecked = checked ?? !set.has(key);
|
|
3557
|
+
if (nextChecked)
|
|
3558
|
+
set.add(key);
|
|
3559
|
+
else
|
|
3560
|
+
set.delete(key);
|
|
3561
|
+
this.options.selectedKeys = Array.from(set);
|
|
3562
|
+
return this.getState();
|
|
3563
|
+
}
|
|
3564
|
+
toggleAllRows(checked) {
|
|
3565
|
+
const keys = this.options.rows.map((row, index) => this.getRowKey(row, index));
|
|
3566
|
+
const selected = new Set(this.options.selectedKeys);
|
|
3567
|
+
const nextChecked = checked ?? this.getSelectionStatus(keys) !== "all";
|
|
3568
|
+
keys.forEach((key) => {
|
|
3569
|
+
if (nextChecked)
|
|
3570
|
+
selected.add(key);
|
|
3571
|
+
else
|
|
3572
|
+
selected.delete(key);
|
|
3573
|
+
});
|
|
3574
|
+
this.options.selectedKeys = Array.from(selected);
|
|
3575
|
+
return this.getState();
|
|
3576
|
+
}
|
|
3577
|
+
getRowKey(row, index) {
|
|
3578
|
+
return this.options.getRowKey(row, index);
|
|
3579
|
+
}
|
|
3580
|
+
getState() {
|
|
3581
|
+
const allColumns = this.getNormalizedColumns();
|
|
3582
|
+
const columns = allColumns.filter((column) => !column.hidden);
|
|
3583
|
+
const rowKeys = this.options.rows.map((row, index) => this.getRowKey(row, index));
|
|
3584
|
+
return {
|
|
3585
|
+
allColumns: allColumns.map((column) => this.toPublicColumn(column)),
|
|
3586
|
+
columns: columns.map((column) => this.toPublicColumn(column)),
|
|
3587
|
+
rows: [...this.options.rows],
|
|
3588
|
+
selectionStatus: this.getSelectionStatus(rowKeys),
|
|
3589
|
+
selectedKeys: [...this.options.selectedKeys],
|
|
3590
|
+
tableWidth: columns.reduce((sum, column) => sum + column.width, 0)
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
normalize(options) {
|
|
3594
|
+
return {
|
|
3595
|
+
columns: (options.columns ?? []).map((column) => this.normalizeColumn(column)),
|
|
3596
|
+
containerWidth: Math.max(0, Number.isFinite(options.containerWidth) ? Number(options.containerWidth) : 0),
|
|
3597
|
+
getRowKey: options.getRowKey ?? ((_, index) => index),
|
|
3598
|
+
rows: [...(options.rows ?? [])],
|
|
3599
|
+
selectedKeys: [...(options.selectedKeys ?? [])]
|
|
3600
|
+
};
|
|
3601
|
+
}
|
|
3602
|
+
normalizeColumn(column) {
|
|
3603
|
+
const minWidth = normalizeMinWidth(column.minWidth);
|
|
3604
|
+
const maxWidth = normalizeMaxWidth(column.maxWidth, minWidth);
|
|
3605
|
+
const explicitWidth = Number.isFinite(column.width) || Number.isFinite(column.defaultWidth);
|
|
3606
|
+
return {
|
|
3607
|
+
...column,
|
|
3608
|
+
autoWidth: "autoWidth" in column ? Boolean(column.autoWidth) : !explicitWidth,
|
|
3609
|
+
fixed: column.fixed === "left" || column.fixed === "right" ? column.fixed : undefined,
|
|
3610
|
+
hidden: Boolean(column.hidden),
|
|
3611
|
+
maxWidth,
|
|
3612
|
+
minWidth,
|
|
3613
|
+
width: clampWidth(column.width ?? column.defaultWidth, minWidth, maxWidth)
|
|
3614
|
+
};
|
|
3615
|
+
}
|
|
3616
|
+
getNormalizedColumns() {
|
|
3617
|
+
const columns = this.options.columns.map((column) => this.normalizeColumn(column));
|
|
3618
|
+
const visibleCount = columns.filter((column) => !column.hidden).length;
|
|
3619
|
+
const safeColumns = visibleCount > 0 && columns.length > 0
|
|
3620
|
+
? columns
|
|
3621
|
+
: columns.map((column, index) => index === 0 ? { ...column, hidden: false } : column);
|
|
3622
|
+
return this.distributeDefaultWidths(safeColumns);
|
|
3623
|
+
}
|
|
3624
|
+
distributeDefaultWidths(columns) {
|
|
3625
|
+
const containerWidth = this.getColumnContainerWidth();
|
|
3626
|
+
if (containerWidth <= 0)
|
|
3627
|
+
return columns;
|
|
3628
|
+
const visible = columns.filter((column) => !column.hidden);
|
|
3629
|
+
const flexible = visible.filter((column) => column.autoWidth);
|
|
3630
|
+
if (flexible.length === 0)
|
|
3631
|
+
return this.ensureContainerFill(this.fillContainerGap(columns, containerWidth), containerWidth);
|
|
3632
|
+
const fixedTotal = visible
|
|
3633
|
+
.filter((column) => !flexible.includes(column))
|
|
3634
|
+
.reduce((sum, column) => sum + column.width, 0);
|
|
3635
|
+
const remaining = Math.max(0, containerWidth - fixedTotal);
|
|
3636
|
+
const base = remaining / flexible.length;
|
|
3637
|
+
let used = 0;
|
|
3638
|
+
const next = columns.map((column) => {
|
|
3639
|
+
if (column.hidden || !flexible.some((item) => item.key === column.key))
|
|
3640
|
+
return column;
|
|
3641
|
+
const width = clampWidth(base, column.minWidth, column.maxWidth, column.minWidth);
|
|
3642
|
+
used += width;
|
|
3643
|
+
return { ...column, width };
|
|
3644
|
+
});
|
|
3645
|
+
return this.ensureContainerFill(this.fillContainerGap(next, containerWidth, fixedTotal + used), containerWidth);
|
|
3646
|
+
}
|
|
3647
|
+
fillContainerGap(columns, containerWidth, knownTotal) {
|
|
3648
|
+
const next = columns.map((column) => ({ ...column }));
|
|
3649
|
+
const total = knownTotal ?? next.filter((column) => !column.hidden).reduce((sum, column) => sum + column.width, 0);
|
|
3650
|
+
let gap = containerWidth - total;
|
|
3651
|
+
if (gap === 0)
|
|
3652
|
+
return next;
|
|
3653
|
+
const visibleIndexes = next
|
|
3654
|
+
.map((column, index) => column.hidden ? -1 : index)
|
|
3655
|
+
.filter((index) => index >= 0)
|
|
3656
|
+
.reverse();
|
|
3657
|
+
if (gap > 0 && visibleIndexes.length > 0) {
|
|
3658
|
+
const base = Math.floor(gap / visibleIndexes.length);
|
|
3659
|
+
let remainder = gap - base * visibleIndexes.length;
|
|
3660
|
+
for (const index of visibleIndexes) {
|
|
3661
|
+
const column = next[index];
|
|
3662
|
+
if (!column)
|
|
3663
|
+
continue;
|
|
3664
|
+
const extra = base + (remainder > 0 ? 1 : 0);
|
|
3665
|
+
column.width += extra;
|
|
3666
|
+
remainder -= remainder > 0 ? 1 : 0;
|
|
3667
|
+
}
|
|
3668
|
+
return next;
|
|
3669
|
+
}
|
|
3670
|
+
for (const index of visibleIndexes) {
|
|
3671
|
+
if (gap === 0)
|
|
3672
|
+
break;
|
|
3673
|
+
const column = next[index];
|
|
3674
|
+
if (!column)
|
|
3675
|
+
continue;
|
|
3676
|
+
const delta = Math.min(Math.abs(gap), column.width - column.minWidth);
|
|
3677
|
+
column.width -= delta;
|
|
3678
|
+
gap += delta;
|
|
3679
|
+
}
|
|
3680
|
+
return next;
|
|
3681
|
+
}
|
|
3682
|
+
ensureContainerFill(columns, containerWidth) {
|
|
3683
|
+
if (containerWidth <= 0)
|
|
3684
|
+
return columns;
|
|
3685
|
+
const visibleIndexes = columns.map((column, index) => column.hidden ? -1 : index).filter((index) => index >= 0);
|
|
3686
|
+
if (visibleIndexes.length === 0)
|
|
3687
|
+
return columns;
|
|
3688
|
+
const total = visibleIndexes.reduce((sum, index) => sum + (columns[index]?.width ?? 0), 0);
|
|
3689
|
+
const gap = Math.ceil(containerWidth - total);
|
|
3690
|
+
if (gap <= 0)
|
|
3691
|
+
return columns;
|
|
3692
|
+
const next = columns.map((column) => ({ ...column }));
|
|
3693
|
+
const base = Math.floor(gap / visibleIndexes.length);
|
|
3694
|
+
let remainder = gap - base * visibleIndexes.length;
|
|
3695
|
+
for (const index of visibleIndexes) {
|
|
3696
|
+
const column = next[index];
|
|
3697
|
+
if (!column)
|
|
3698
|
+
continue;
|
|
3699
|
+
const extra = base + (remainder > 0 ? 1 : 0);
|
|
3700
|
+
column.width += extra;
|
|
3701
|
+
remainder -= remainder > 0 ? 1 : 0;
|
|
3702
|
+
}
|
|
3703
|
+
return next;
|
|
3704
|
+
}
|
|
3705
|
+
getColumnContainerWidth(containerWidth = this.options.containerWidth) {
|
|
3706
|
+
return Math.max(0, containerWidth);
|
|
3707
|
+
}
|
|
3708
|
+
toPublicColumn(column) {
|
|
3709
|
+
const publicColumn = { ...column };
|
|
3710
|
+
delete publicColumn.autoWidth;
|
|
3711
|
+
return publicColumn;
|
|
3712
|
+
}
|
|
3713
|
+
getSelectionStatus(keys) {
|
|
3714
|
+
if (keys.length === 0)
|
|
3715
|
+
return "none";
|
|
3716
|
+
const selected = new Set(this.options.selectedKeys);
|
|
3717
|
+
const selectedCount = keys.filter((key) => selected.has(key)).length;
|
|
3718
|
+
if (selectedCount === 0)
|
|
3719
|
+
return "none";
|
|
3720
|
+
if (selectedCount === keys.length)
|
|
3721
|
+
return "all";
|
|
3722
|
+
return "partial";
|
|
3723
|
+
}
|
|
3724
|
+
}
|
|
3725
|
+
|
|
3726
|
+
class UploadController {
|
|
3727
|
+
constructor(options = {}) {
|
|
3728
|
+
this.files = [];
|
|
3729
|
+
this.options = options;
|
|
3730
|
+
}
|
|
3731
|
+
updateOptions(options = {}) {
|
|
3732
|
+
this.options = options;
|
|
3733
|
+
return this.getState();
|
|
3734
|
+
}
|
|
3735
|
+
addFiles(files) {
|
|
3736
|
+
const next = files
|
|
3737
|
+
.filter((file) => !this.options.maxSize || file.size <= this.options.maxSize)
|
|
3738
|
+
.map((file) => ({ file, id: `${file.name}-${file.size}-${file.lastModified}-${Math.random().toString(36).slice(2)}`, name: file.name, size: file.size, status: "ready" }));
|
|
3739
|
+
this.files = this.options.multiple ? [...this.files, ...next] : next.slice(0, 1);
|
|
3740
|
+
return this.getState();
|
|
3741
|
+
}
|
|
3742
|
+
remove(id) {
|
|
3743
|
+
this.files = this.files.filter((file) => file.id !== id);
|
|
3744
|
+
return this.getState();
|
|
3745
|
+
}
|
|
3746
|
+
replaceFiles(files = []) {
|
|
3747
|
+
this.files = this.options.multiple ? files.map((file) => ({ ...file })) : files.slice(0, 1).map((file) => ({ ...file }));
|
|
3748
|
+
return this.getState();
|
|
3749
|
+
}
|
|
3750
|
+
clear() {
|
|
3751
|
+
this.files = [];
|
|
3752
|
+
return this.getState();
|
|
3753
|
+
}
|
|
3754
|
+
getState() {
|
|
3755
|
+
return { files: this.files.map((file) => ({ ...file })) };
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
|
|
3759
|
+
function now() {
|
|
3760
|
+
return Date.now();
|
|
3761
|
+
}
|
|
3762
|
+
function resolveDirection(deltaX, deltaY, threshold) {
|
|
3763
|
+
if (Math.abs(deltaX) < threshold && Math.abs(deltaY) < threshold)
|
|
3764
|
+
return "none";
|
|
3765
|
+
if (Math.abs(deltaX) > Math.abs(deltaY))
|
|
3766
|
+
return deltaX > 0 ? "right" : "left";
|
|
3767
|
+
return deltaY > 0 ? "down" : "up";
|
|
3768
|
+
}
|
|
3769
|
+
class GestureController {
|
|
3770
|
+
constructor(options = {}) {
|
|
3771
|
+
this.current = { x: 0, y: 0, time: 0 };
|
|
3772
|
+
this.previous = { x: 0, y: 0, time: 0 };
|
|
3773
|
+
this.startPoint = { x: 0, y: 0, time: 0 };
|
|
3774
|
+
this.active = false;
|
|
3775
|
+
this.threshold = Math.max(0, options.threshold ?? 4);
|
|
3776
|
+
}
|
|
3777
|
+
start(point) {
|
|
3778
|
+
const time = point.time ?? now();
|
|
3779
|
+
this.active = true;
|
|
3780
|
+
this.startPoint = { ...point, time };
|
|
3781
|
+
this.previous = this.startPoint;
|
|
3782
|
+
this.current = this.startPoint;
|
|
3783
|
+
return this.getState();
|
|
3784
|
+
}
|
|
3785
|
+
move(point) {
|
|
3786
|
+
if (!this.active)
|
|
3787
|
+
return this.getState();
|
|
3788
|
+
this.previous = this.current;
|
|
3789
|
+
this.current = { ...point, time: point.time ?? now() };
|
|
3790
|
+
return this.getState();
|
|
3791
|
+
}
|
|
3792
|
+
end(point) {
|
|
3793
|
+
if (point)
|
|
3794
|
+
this.move(point);
|
|
3795
|
+
const state = this.getState();
|
|
3796
|
+
this.active = false;
|
|
3797
|
+
return { ...state, active: false };
|
|
3798
|
+
}
|
|
3799
|
+
getState() {
|
|
3800
|
+
const deltaX = this.current.x - this.startPoint.x;
|
|
3801
|
+
const deltaY = this.current.y - this.startPoint.y;
|
|
3802
|
+
const frameTime = Math.max(1, (this.current.time ?? 0) - (this.previous.time ?? 0));
|
|
3803
|
+
return {
|
|
3804
|
+
active: this.active,
|
|
3805
|
+
direction: resolveDirection(deltaX, deltaY, this.threshold),
|
|
3806
|
+
distance: Math.hypot(deltaX, deltaY),
|
|
3807
|
+
duration: Math.max(0, (this.current.time ?? 0) - (this.startPoint.time ?? 0)),
|
|
3808
|
+
startX: this.startPoint.x,
|
|
3809
|
+
startY: this.startPoint.y,
|
|
3810
|
+
velocityX: ((this.current.x - this.previous.x) / frameTime) * 1000,
|
|
3811
|
+
velocityY: ((this.current.y - this.previous.y) / frameTime) * 1000,
|
|
3812
|
+
x: deltaX,
|
|
3813
|
+
y: deltaY
|
|
3814
|
+
};
|
|
3815
|
+
}
|
|
3816
|
+
}
|
|
3817
|
+
|
|
3818
|
+
function clamp(value, min, max) {
|
|
3819
|
+
return Math.min(max, Math.max(min, value));
|
|
3820
|
+
}
|
|
3821
|
+
class DragController {
|
|
3822
|
+
constructor(options = {}) {
|
|
3823
|
+
this.dragOffset = { x: 0, y: 0 };
|
|
3824
|
+
this.axis = options.axis ?? "xy";
|
|
3825
|
+
this.bounds = options.bounds;
|
|
3826
|
+
this.disabled = options.disabled ?? false;
|
|
3827
|
+
this.position = options.initialPosition ?? { x: 0, y: 0 };
|
|
3828
|
+
this.restrictToBounds = options.restrictToBounds ?? true;
|
|
3829
|
+
this.gesture = new GestureController({ threshold: options.threshold ?? 2 });
|
|
3830
|
+
}
|
|
3831
|
+
updateOptions(options) {
|
|
3832
|
+
if (options.axis !== undefined)
|
|
3833
|
+
this.axis = options.axis;
|
|
3834
|
+
if (options.bounds !== undefined)
|
|
3835
|
+
this.bounds = options.bounds;
|
|
3836
|
+
if (options.disabled !== undefined)
|
|
3837
|
+
this.disabled = options.disabled;
|
|
3838
|
+
if (options.initialPosition !== undefined && !this.getState().dragging)
|
|
3839
|
+
this.position = options.initialPosition;
|
|
3840
|
+
if (options.restrictToBounds !== undefined)
|
|
3841
|
+
this.restrictToBounds = options.restrictToBounds;
|
|
3842
|
+
return this.getState();
|
|
3843
|
+
}
|
|
3844
|
+
start(point, elementPosition = this.position) {
|
|
3845
|
+
if (this.disabled)
|
|
3846
|
+
return this.getState();
|
|
3847
|
+
this.position = this.clampPosition(elementPosition);
|
|
3848
|
+
this.dragOffset = { x: point.x - this.position.x, y: point.y - this.position.y };
|
|
3849
|
+
this.gesture.start(point);
|
|
3850
|
+
return this.getState();
|
|
3851
|
+
}
|
|
3852
|
+
move(point) {
|
|
3853
|
+
if (!this.gesture.getState().active || this.disabled)
|
|
3854
|
+
return this.getState();
|
|
3855
|
+
this.gesture.move(point);
|
|
3856
|
+
const nextPosition = {
|
|
3857
|
+
x: this.axis === "y" ? this.position.x : point.x - this.dragOffset.x,
|
|
3858
|
+
y: this.axis === "x" ? this.position.y : point.y - this.dragOffset.y
|
|
3859
|
+
};
|
|
3860
|
+
this.position = this.clampPosition(nextPosition);
|
|
3861
|
+
return this.getState();
|
|
3862
|
+
}
|
|
3863
|
+
end(point) {
|
|
3864
|
+
if (point)
|
|
3865
|
+
this.move(point);
|
|
3866
|
+
this.gesture.end();
|
|
3867
|
+
return this.getState();
|
|
3868
|
+
}
|
|
3869
|
+
setPosition(position) {
|
|
3870
|
+
this.position = this.clampPosition(position);
|
|
3871
|
+
return this.getState();
|
|
3872
|
+
}
|
|
3873
|
+
isOverTarget(source, target) {
|
|
3874
|
+
if (!target)
|
|
3875
|
+
return false;
|
|
3876
|
+
return source.x < target.x + target.width
|
|
3877
|
+
&& source.x + source.width > target.x
|
|
3878
|
+
&& source.y < target.y + target.height
|
|
3879
|
+
&& source.y + source.height > target.y;
|
|
3880
|
+
}
|
|
3881
|
+
getState() {
|
|
3882
|
+
return {
|
|
3883
|
+
dragging: this.gesture.getState().active,
|
|
3884
|
+
gesture: this.gesture.getState(),
|
|
3885
|
+
position: this.position
|
|
3886
|
+
};
|
|
3887
|
+
}
|
|
3888
|
+
clampPosition(position) {
|
|
3889
|
+
if (!this.bounds || !this.restrictToBounds)
|
|
3890
|
+
return position;
|
|
3891
|
+
return {
|
|
3892
|
+
x: clamp(position.x, 0, Math.max(0, this.bounds.width)),
|
|
3893
|
+
y: clamp(position.y, 0, Math.max(0, this.bounds.height))
|
|
3894
|
+
};
|
|
3895
|
+
}
|
|
3896
|
+
}
|
|
3897
|
+
|
|
3898
|
+
class DropController {
|
|
3899
|
+
constructor(items = []) {
|
|
3900
|
+
this.items = items;
|
|
3901
|
+
}
|
|
3902
|
+
updateItems(items) {
|
|
3903
|
+
this.items = items;
|
|
3904
|
+
return this.getState();
|
|
3905
|
+
}
|
|
3906
|
+
start(id) {
|
|
3907
|
+
const item = this.items.find((entry) => entry.id === id);
|
|
3908
|
+
if (!item || item.disabled)
|
|
3909
|
+
return this.getState();
|
|
3910
|
+
this.draggingId = id;
|
|
3911
|
+
this.overIndex = this.items.findIndex((entry) => entry.id === id);
|
|
3912
|
+
return this.getState();
|
|
3913
|
+
}
|
|
3914
|
+
moveToIndex(index) {
|
|
3915
|
+
if (!this.draggingId)
|
|
3916
|
+
return this.getState();
|
|
3917
|
+
this.overIndex = Math.max(0, Math.min(index, this.items.length - 1));
|
|
3918
|
+
return this.getState();
|
|
3919
|
+
}
|
|
3920
|
+
end() {
|
|
3921
|
+
if (!this.draggingId || this.overIndex === undefined) {
|
|
3922
|
+
this.draggingId = undefined;
|
|
3923
|
+
this.overIndex = undefined;
|
|
3924
|
+
return this.getState();
|
|
3925
|
+
}
|
|
3926
|
+
const fromIndex = this.items.findIndex((item) => item.id === this.draggingId);
|
|
3927
|
+
const toIndex = this.overIndex;
|
|
3928
|
+
if (fromIndex >= 0 && toIndex >= 0 && fromIndex !== toIndex) {
|
|
3929
|
+
const next = [...this.items];
|
|
3930
|
+
const [moving] = next.splice(fromIndex, 1);
|
|
3931
|
+
if (moving)
|
|
3932
|
+
next.splice(toIndex, 0, moving);
|
|
3933
|
+
this.items = next;
|
|
3934
|
+
}
|
|
3935
|
+
this.draggingId = undefined;
|
|
3936
|
+
this.overIndex = undefined;
|
|
3937
|
+
return this.getState();
|
|
3938
|
+
}
|
|
3939
|
+
cancel() {
|
|
3940
|
+
this.draggingId = undefined;
|
|
3941
|
+
this.overIndex = undefined;
|
|
3942
|
+
return this.getState();
|
|
3943
|
+
}
|
|
3944
|
+
getState() {
|
|
3945
|
+
return {
|
|
3946
|
+
draggingId: this.draggingId,
|
|
3947
|
+
items: this.items,
|
|
3948
|
+
overIndex: this.overIndex
|
|
3949
|
+
};
|
|
3950
|
+
}
|
|
3951
|
+
}
|
|
3952
|
+
|
|
3953
|
+
class ComicReaderController {
|
|
3954
|
+
constructor(options) {
|
|
3955
|
+
this.pages = [...options.pages];
|
|
3956
|
+
this.current = this.clamp(options.current ?? 0);
|
|
3957
|
+
this.hasMore = options.hasMore ?? false;
|
|
3958
|
+
this.loading = options.loading ?? false;
|
|
3959
|
+
}
|
|
3960
|
+
update(options) {
|
|
3961
|
+
if (options.pages)
|
|
3962
|
+
this.pages = [...options.pages];
|
|
3963
|
+
if (typeof options.current === "number")
|
|
3964
|
+
this.current = this.clamp(options.current);
|
|
3965
|
+
else
|
|
3966
|
+
this.current = this.clamp(this.current);
|
|
3967
|
+
if (typeof options.hasMore === "boolean")
|
|
3968
|
+
this.hasMore = options.hasMore;
|
|
3969
|
+
if (typeof options.loading === "boolean")
|
|
3970
|
+
this.loading = options.loading;
|
|
3971
|
+
return this.getState();
|
|
3972
|
+
}
|
|
3973
|
+
append(pages, hasMore = this.hasMore) {
|
|
3974
|
+
const existed = new Set(this.pages.map((item) => item.id));
|
|
3975
|
+
this.pages = [...this.pages, ...pages.filter((item) => !existed.has(item.id))];
|
|
3976
|
+
this.hasMore = hasMore;
|
|
3977
|
+
this.loading = false;
|
|
3978
|
+
return this.getState();
|
|
3979
|
+
}
|
|
3980
|
+
setLoading(loading) {
|
|
3981
|
+
this.loading = loading;
|
|
3982
|
+
return this.getState();
|
|
3983
|
+
}
|
|
3984
|
+
next() {
|
|
3985
|
+
this.current = this.clamp(this.current + 1);
|
|
3986
|
+
return this.getState();
|
|
3987
|
+
}
|
|
3988
|
+
previous() {
|
|
3989
|
+
this.current = this.clamp(this.current - 1);
|
|
3990
|
+
return this.getState();
|
|
3991
|
+
}
|
|
3992
|
+
goTo(index) {
|
|
3993
|
+
this.current = this.clamp(index);
|
|
3994
|
+
return this.getState();
|
|
3995
|
+
}
|
|
3996
|
+
getState() {
|
|
3997
|
+
const total = this.pages.length;
|
|
3998
|
+
return {
|
|
3999
|
+
canNext: this.current < total - 1,
|
|
4000
|
+
canPrevious: this.current > 0,
|
|
4001
|
+
current: this.current,
|
|
4002
|
+
hasMore: this.hasMore,
|
|
4003
|
+
loading: this.loading,
|
|
4004
|
+
page: this.pages[this.current] ?? null,
|
|
4005
|
+
pages: [...this.pages],
|
|
4006
|
+
total
|
|
4007
|
+
};
|
|
4008
|
+
}
|
|
4009
|
+
clamp(index) {
|
|
4010
|
+
if (this.pages.length === 0)
|
|
4011
|
+
return 0;
|
|
4012
|
+
return Math.min(Math.max(0, Math.trunc(index)), this.pages.length - 1);
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
|
|
4016
|
+
class DanmakuController {
|
|
4017
|
+
constructor(items = [], options = {}) {
|
|
4018
|
+
this.trackCursor = 0;
|
|
4019
|
+
this.maxTracks = Math.max(1, Math.trunc(options.maxTracks ?? 6));
|
|
4020
|
+
this.defaultDuration = Math.max(1000, options.defaultDuration ?? 7600);
|
|
4021
|
+
this.defaultSpeed = this.normalizeSpeed(options.speed);
|
|
4022
|
+
this.defaultColor = options.color ?? "#ffffff";
|
|
4023
|
+
this.enabled = options.enabled ?? true;
|
|
4024
|
+
this.items = items.map((item) => this.normalize(item));
|
|
4025
|
+
}
|
|
4026
|
+
update(items, options = {}) {
|
|
4027
|
+
this.maxTracks = Math.max(1, Math.trunc(options.maxTracks ?? this.maxTracks));
|
|
4028
|
+
this.defaultDuration = Math.max(1000, options.defaultDuration ?? this.defaultDuration);
|
|
4029
|
+
this.defaultSpeed = typeof options.speed === "number" ? this.normalizeSpeed(options.speed) : this.defaultSpeed;
|
|
4030
|
+
this.defaultColor = options.color ?? this.defaultColor;
|
|
4031
|
+
this.enabled = options.enabled ?? this.enabled;
|
|
4032
|
+
this.items = items.map((item) => this.normalize(item));
|
|
4033
|
+
return this.getState();
|
|
4034
|
+
}
|
|
4035
|
+
add(item) {
|
|
4036
|
+
this.items = [...this.items, this.normalize({ ...item, id: item.id ?? `danmaku-${Date.now()}-${this.items.length}` })];
|
|
4037
|
+
return this.getState();
|
|
4038
|
+
}
|
|
4039
|
+
remove(id) {
|
|
4040
|
+
this.items = this.items.filter((item) => item.id !== id);
|
|
4041
|
+
return this.getState();
|
|
4042
|
+
}
|
|
4043
|
+
getState() {
|
|
4044
|
+
return { enabled: this.enabled, items: this.enabled ? [...this.items] : [], maxTracks: this.maxTracks };
|
|
4045
|
+
}
|
|
4046
|
+
normalize(item) {
|
|
4047
|
+
const track = item.track ?? this.trackCursor;
|
|
4048
|
+
this.trackCursor = (track + 1) % this.maxTracks;
|
|
4049
|
+
return {
|
|
4050
|
+
...item,
|
|
4051
|
+
color: item.color ?? this.defaultColor,
|
|
4052
|
+
duration: this.resolveDuration(item),
|
|
4053
|
+
track: Math.min(Math.max(0, track), this.maxTracks - 1),
|
|
4054
|
+
type: item.type ?? (item.imageSrc ? "image" : item.icon ? "icon" : "text")
|
|
4055
|
+
};
|
|
4056
|
+
}
|
|
4057
|
+
normalizeSpeed(speed) {
|
|
4058
|
+
if (typeof speed !== "number" || !Number.isFinite(speed))
|
|
4059
|
+
return undefined;
|
|
4060
|
+
return Math.min(Math.max(speed, 24), 800);
|
|
4061
|
+
}
|
|
4062
|
+
resolveDuration(item) {
|
|
4063
|
+
if (typeof item.duration === "number" && Number.isFinite(item.duration))
|
|
4064
|
+
return Math.max(1000, item.duration);
|
|
4065
|
+
const speed = this.normalizeSpeed(item.speed) ?? this.defaultSpeed;
|
|
4066
|
+
if (!speed)
|
|
4067
|
+
return this.defaultDuration;
|
|
4068
|
+
return Math.round(Math.min(Math.max(900000 / speed, 1000), 30000));
|
|
4069
|
+
}
|
|
4070
|
+
}
|
|
4071
|
+
|
|
4072
|
+
class LiveRoomController {
|
|
4073
|
+
constructor(options) {
|
|
4074
|
+
this.state = {
|
|
4075
|
+
chats: [...(options.chats ?? [])],
|
|
4076
|
+
danmaku: [...(options.danmaku ?? [])],
|
|
4077
|
+
favorited: options.favorited ?? false,
|
|
4078
|
+
host: options.host,
|
|
4079
|
+
liked: options.liked ?? false,
|
|
4080
|
+
likeCount: Math.max(0, options.likeCount ?? 0)
|
|
4081
|
+
};
|
|
4082
|
+
}
|
|
4083
|
+
update(options) {
|
|
4084
|
+
this.state = {
|
|
4085
|
+
chats: options.chats ? [...options.chats] : this.state.chats,
|
|
4086
|
+
danmaku: options.danmaku ? [...options.danmaku] : this.state.danmaku,
|
|
4087
|
+
favorited: options.favorited ?? this.state.favorited,
|
|
4088
|
+
host: options.host ?? this.state.host,
|
|
4089
|
+
liked: options.liked ?? this.state.liked,
|
|
4090
|
+
likeCount: Math.max(0, options.likeCount ?? this.state.likeCount)
|
|
4091
|
+
};
|
|
4092
|
+
return this.getState();
|
|
4093
|
+
}
|
|
4094
|
+
addChat(message) {
|
|
4095
|
+
this.state = { ...this.state, chats: [...this.state.chats, message] };
|
|
4096
|
+
return this.getState();
|
|
4097
|
+
}
|
|
4098
|
+
addDanmaku(item) {
|
|
4099
|
+
this.state = { ...this.state, danmaku: [...this.state.danmaku, item] };
|
|
4100
|
+
return this.getState();
|
|
4101
|
+
}
|
|
4102
|
+
toggleFavorite() {
|
|
4103
|
+
this.state = { ...this.state, favorited: !this.state.favorited };
|
|
4104
|
+
return this.getState();
|
|
4105
|
+
}
|
|
4106
|
+
toggleLike() {
|
|
4107
|
+
const liked = !this.state.liked;
|
|
4108
|
+
this.state = { ...this.state, liked, likeCount: Math.max(0, this.state.likeCount + (liked ? 1 : -1)) };
|
|
4109
|
+
return this.getState();
|
|
4110
|
+
}
|
|
4111
|
+
getState() {
|
|
4112
|
+
return {
|
|
4113
|
+
...this.state,
|
|
4114
|
+
chats: [...this.state.chats],
|
|
4115
|
+
danmaku: [...this.state.danmaku],
|
|
4116
|
+
host: { ...this.state.host }
|
|
4117
|
+
};
|
|
4118
|
+
}
|
|
4119
|
+
}
|
|
4120
|
+
|
|
4121
|
+
class NovelReaderController {
|
|
4122
|
+
constructor(options) {
|
|
4123
|
+
this.pages = [...options.pages];
|
|
4124
|
+
this.loop = options.loop ?? false;
|
|
4125
|
+
this.current = this.clamp(options.current ?? 0);
|
|
4126
|
+
}
|
|
4127
|
+
update(options) {
|
|
4128
|
+
if (options.pages)
|
|
4129
|
+
this.pages = [...options.pages];
|
|
4130
|
+
if (typeof options.loop === "boolean")
|
|
4131
|
+
this.loop = options.loop;
|
|
4132
|
+
if (typeof options.current === "number")
|
|
4133
|
+
this.current = this.clamp(options.current);
|
|
4134
|
+
else
|
|
4135
|
+
this.current = this.clamp(this.current);
|
|
4136
|
+
return this.getState();
|
|
4137
|
+
}
|
|
4138
|
+
next() {
|
|
4139
|
+
this.current = this.loop && this.current >= this.pages.length - 1 ? 0 : this.clamp(this.current + 1);
|
|
4140
|
+
return this.getState();
|
|
4141
|
+
}
|
|
4142
|
+
previous() {
|
|
4143
|
+
this.current = this.loop && this.current <= 0 ? this.pages.length - 1 : this.clamp(this.current - 1);
|
|
4144
|
+
return this.getState();
|
|
4145
|
+
}
|
|
4146
|
+
goTo(index) {
|
|
4147
|
+
this.current = this.clamp(index);
|
|
4148
|
+
return this.getState();
|
|
4149
|
+
}
|
|
4150
|
+
getTurnMetrics(input) {
|
|
4151
|
+
const width = Math.max(1, input.width);
|
|
4152
|
+
const deltaX = Number.isFinite(input.deltaX)
|
|
4153
|
+
? input.deltaX
|
|
4154
|
+
: input.pointerX != null && input.startX != null
|
|
4155
|
+
? input.pointerX - input.startX
|
|
4156
|
+
: 0;
|
|
4157
|
+
const direction = deltaX < 0 ? "next" : "previous";
|
|
4158
|
+
const distance = Math.abs(deltaX);
|
|
4159
|
+
const raw = distance / (width * 0.74);
|
|
4160
|
+
const progress = input.canTurn
|
|
4161
|
+
? Math.min(0.995, this.easeOutCubic(raw))
|
|
4162
|
+
: Math.min(0.2, raw * 0.28);
|
|
4163
|
+
const signed = direction === "previous" ? 1 : -1;
|
|
4164
|
+
const curl = Math.sin(progress * Math.PI);
|
|
4165
|
+
const softness = Math.sin(Math.min(1, progress) * Math.PI * 0.72);
|
|
4166
|
+
const angle = signed * (2 + progress * 162 - curl * 10);
|
|
4167
|
+
const foldTranslate = 58 - progress * 92;
|
|
4168
|
+
const shadowTranslate = 22 - progress * 22;
|
|
4169
|
+
return {
|
|
4170
|
+
angle,
|
|
4171
|
+
canTurn: input.canTurn,
|
|
4172
|
+
clipEnd: 4 + progress * 13,
|
|
4173
|
+
clipStart: progress * 12,
|
|
4174
|
+
curl,
|
|
4175
|
+
direction,
|
|
4176
|
+
dragX: signed * Math.min(18, distance * 0.035),
|
|
4177
|
+
foldOpacity: Math.min(0.96, 0.16 + progress * 0.76 + curl * 0.12),
|
|
4178
|
+
foldScale: 0.36 + progress * 0.98 + softness * 0.08,
|
|
4179
|
+
foldSkew: signed * (8 + progress * 16 + curl * 5),
|
|
4180
|
+
foldTranslate,
|
|
4181
|
+
nextOpacity: Math.min(1, 0.42 + progress * 0.58),
|
|
4182
|
+
pageOpacity: Math.max(0.3, 1 - progress * 0.28),
|
|
4183
|
+
progress,
|
|
4184
|
+
release: input.canTurn && progress >= NovelReaderController.releaseThreshold,
|
|
4185
|
+
shadowOpacity: Math.min(0.62, 0.1 + progress * 0.38 + curl * 0.18),
|
|
4186
|
+
shadowScale: 0.76 + progress * 0.48,
|
|
4187
|
+
shadowTranslate,
|
|
4188
|
+
skew: signed * (progress * 3.2 + curl * 3.8),
|
|
4189
|
+
translate: signed * (progress * 8 + curl * 3)
|
|
4190
|
+
};
|
|
4191
|
+
}
|
|
4192
|
+
getState() {
|
|
4193
|
+
const total = this.pages.length;
|
|
4194
|
+
return {
|
|
4195
|
+
canNext: this.loop ? total > 1 : this.current < total - 1,
|
|
4196
|
+
canPrevious: this.loop ? total > 1 : this.current > 0,
|
|
4197
|
+
current: this.current,
|
|
4198
|
+
page: this.pages[this.current] ?? null,
|
|
4199
|
+
total
|
|
4200
|
+
};
|
|
4201
|
+
}
|
|
4202
|
+
clamp(index) {
|
|
4203
|
+
if (this.pages.length === 0)
|
|
4204
|
+
return 0;
|
|
4205
|
+
return Math.min(Math.max(0, Math.trunc(index)), this.pages.length - 1);
|
|
4206
|
+
}
|
|
4207
|
+
easeOutCubic(value) {
|
|
4208
|
+
const clamped = Math.min(Math.max(value, 0), 1);
|
|
4209
|
+
return 1 - Math.pow(1 - clamped, 3);
|
|
4210
|
+
}
|
|
4211
|
+
}
|
|
4212
|
+
NovelReaderController.releaseThreshold = 0.32;
|
|
4213
|
+
|
|
4214
|
+
const DEFAULT_OVERSCAN$1 = 4;
|
|
4215
|
+
class VirtualListController {
|
|
4216
|
+
constructor(options) {
|
|
4217
|
+
this.measuredSizes = new Map();
|
|
4218
|
+
this.offsets = [];
|
|
4219
|
+
this.totalSize = 0;
|
|
4220
|
+
this.count = Math.max(0, Math.floor(options.count));
|
|
4221
|
+
this.estimateSize = options.estimateSize;
|
|
4222
|
+
this.overscanBefore = Math.max(0, Math.floor(options.overscanBefore ?? options.overscan ?? DEFAULT_OVERSCAN$1));
|
|
4223
|
+
this.overscanAfter = Math.max(0, Math.floor(options.overscanAfter ?? options.overscan ?? DEFAULT_OVERSCAN$1));
|
|
4224
|
+
this.pullUpThreshold = Math.max(0, Math.floor(options.pullUpThreshold ?? 48));
|
|
4225
|
+
this.recalculate();
|
|
4226
|
+
}
|
|
4227
|
+
updateOptions(options) {
|
|
4228
|
+
if (options.count !== undefined) {
|
|
4229
|
+
const nextCount = Math.max(0, Math.floor(options.count));
|
|
4230
|
+
if (nextCount < this.count) {
|
|
4231
|
+
Array.from(this.measuredSizes.keys()).forEach((index) => {
|
|
4232
|
+
if (index >= nextCount)
|
|
4233
|
+
this.measuredSizes.delete(index);
|
|
4234
|
+
});
|
|
4235
|
+
}
|
|
4236
|
+
this.count = nextCount;
|
|
4237
|
+
}
|
|
4238
|
+
if (options.estimateSize !== undefined) {
|
|
4239
|
+
this.estimateSize = options.estimateSize;
|
|
4240
|
+
}
|
|
4241
|
+
if (options.overscan !== undefined || options.overscanBefore !== undefined) {
|
|
4242
|
+
this.overscanBefore = Math.max(0, Math.floor(options.overscanBefore ?? options.overscan ?? this.overscanBefore));
|
|
4243
|
+
}
|
|
4244
|
+
if (options.overscan !== undefined || options.overscanAfter !== undefined) {
|
|
4245
|
+
this.overscanAfter = Math.max(0, Math.floor(options.overscanAfter ?? options.overscan ?? this.overscanAfter));
|
|
4246
|
+
}
|
|
4247
|
+
if (options.pullUpThreshold !== undefined) {
|
|
4248
|
+
this.pullUpThreshold = Math.max(0, Math.floor(options.pullUpThreshold));
|
|
4249
|
+
}
|
|
4250
|
+
this.recalculate();
|
|
4251
|
+
}
|
|
4252
|
+
getState() {
|
|
4253
|
+
return {
|
|
4254
|
+
count: this.count,
|
|
4255
|
+
estimateSize: this.estimateSize,
|
|
4256
|
+
measuredCount: this.measuredSizes.size,
|
|
4257
|
+
overscan: Math.max(this.overscanBefore, this.overscanAfter),
|
|
4258
|
+
pullUpThreshold: this.pullUpThreshold
|
|
4259
|
+
};
|
|
4260
|
+
}
|
|
4261
|
+
getTotalSize() {
|
|
4262
|
+
return this.totalSize;
|
|
4263
|
+
}
|
|
4264
|
+
shouldTriggerPullUp(scrollOffset, viewportSize) {
|
|
4265
|
+
return scrollOffset + Math.max(0, viewportSize) >= this.totalSize - this.pullUpThreshold;
|
|
4266
|
+
}
|
|
4267
|
+
getItem(index) {
|
|
4268
|
+
const safeIndex = this.clampIndex(index);
|
|
4269
|
+
const start = this.offsets[safeIndex] ?? 0;
|
|
4270
|
+
const size = this.getSize(safeIndex);
|
|
4271
|
+
return {
|
|
4272
|
+
end: start + size,
|
|
4273
|
+
index: safeIndex,
|
|
4274
|
+
key: String(safeIndex),
|
|
4275
|
+
size,
|
|
4276
|
+
start
|
|
4277
|
+
};
|
|
4278
|
+
}
|
|
4279
|
+
getRange(scrollOffset, viewportSize) {
|
|
4280
|
+
if (this.count === 0) {
|
|
4281
|
+
return {
|
|
4282
|
+
endIndex: -1,
|
|
4283
|
+
items: [],
|
|
4284
|
+
offsetAfter: 0,
|
|
4285
|
+
offsetBefore: 0,
|
|
4286
|
+
startIndex: 0,
|
|
4287
|
+
totalSize: 0
|
|
4288
|
+
};
|
|
4289
|
+
}
|
|
4290
|
+
const safeViewportSize = Math.max(0, viewportSize);
|
|
4291
|
+
const maxScrollOffset = Math.max(0, this.totalSize - safeViewportSize);
|
|
4292
|
+
const safeScrollOffset = Math.min(Math.max(0, scrollOffset), maxScrollOffset);
|
|
4293
|
+
const visibleStart = this.findNearestIndex(safeScrollOffset);
|
|
4294
|
+
const visibleEnd = this.findNearestIndex(safeScrollOffset + safeViewportSize);
|
|
4295
|
+
const startIndex = Math.max(0, visibleStart - this.overscanBefore);
|
|
4296
|
+
const endIndex = Math.min(this.count - 1, visibleEnd + this.overscanAfter);
|
|
4297
|
+
const items = this.getItems(startIndex, endIndex);
|
|
4298
|
+
const offsetBefore = this.offsets[startIndex] ?? 0;
|
|
4299
|
+
const lastItem = items[items.length - 1];
|
|
4300
|
+
const offsetAfter = Math.max(0, this.totalSize - (lastItem?.end ?? 0));
|
|
4301
|
+
return {
|
|
4302
|
+
endIndex,
|
|
4303
|
+
items,
|
|
4304
|
+
offsetAfter,
|
|
4305
|
+
offsetBefore,
|
|
4306
|
+
startIndex,
|
|
4307
|
+
totalSize: this.totalSize
|
|
4308
|
+
};
|
|
4309
|
+
}
|
|
4310
|
+
measure(index, size) {
|
|
4311
|
+
if (index < 0 || index >= this.count || !Number.isFinite(size) || size <= 0)
|
|
4312
|
+
return false;
|
|
4313
|
+
const normalizedSize = Math.round(size);
|
|
4314
|
+
if (this.measuredSizes.get(index) === normalizedSize)
|
|
4315
|
+
return false;
|
|
4316
|
+
this.measuredSizes.set(index, normalizedSize);
|
|
4317
|
+
this.recalculate();
|
|
4318
|
+
return true;
|
|
4319
|
+
}
|
|
4320
|
+
resetMeasurements() {
|
|
4321
|
+
this.measuredSizes.clear();
|
|
4322
|
+
this.recalculate();
|
|
4323
|
+
}
|
|
4324
|
+
shiftMeasurements(offset) {
|
|
4325
|
+
if (offset === 0 || this.measuredSizes.size === 0)
|
|
4326
|
+
return;
|
|
4327
|
+
const nextMeasurements = new Map();
|
|
4328
|
+
this.measuredSizes.forEach((size, index) => {
|
|
4329
|
+
const nextIndex = index + offset;
|
|
4330
|
+
if (nextIndex >= 0 && nextIndex < this.count)
|
|
4331
|
+
nextMeasurements.set(nextIndex, size);
|
|
4332
|
+
});
|
|
4333
|
+
this.measuredSizes = nextMeasurements;
|
|
4334
|
+
this.recalculate();
|
|
4335
|
+
}
|
|
4336
|
+
scrollToIndex(index, align = "start", viewportSize = 0) {
|
|
4337
|
+
if (this.count === 0)
|
|
4338
|
+
return 0;
|
|
4339
|
+
const item = this.getItem(index);
|
|
4340
|
+
if (align === "center")
|
|
4341
|
+
return Math.max(0, item.start - viewportSize / 2 + item.size / 2);
|
|
4342
|
+
if (align === "end")
|
|
4343
|
+
return Math.max(0, item.end - viewportSize);
|
|
4344
|
+
return item.start;
|
|
4345
|
+
}
|
|
4346
|
+
getItems(startIndex, endIndex) {
|
|
4347
|
+
const items = [];
|
|
4348
|
+
for (let index = startIndex; index <= endIndex; index += 1) {
|
|
4349
|
+
items.push(this.getItem(index));
|
|
4350
|
+
}
|
|
4351
|
+
return items;
|
|
4352
|
+
}
|
|
4353
|
+
getSize(index) {
|
|
4354
|
+
return this.measuredSizes.get(index) ?? this.getEstimatedSize(index);
|
|
4355
|
+
}
|
|
4356
|
+
getEstimatedSize(index) {
|
|
4357
|
+
const size = typeof this.estimateSize === "function" ? this.estimateSize(index) : this.estimateSize;
|
|
4358
|
+
return Math.max(1, Number.isFinite(size) ? Math.round(size) : 1);
|
|
4359
|
+
}
|
|
4360
|
+
recalculate() {
|
|
4361
|
+
this.offsets = new Array(this.count);
|
|
4362
|
+
let offset = 0;
|
|
4363
|
+
for (let index = 0; index < this.count; index += 1) {
|
|
4364
|
+
this.offsets[index] = offset;
|
|
4365
|
+
offset += this.getSize(index);
|
|
4366
|
+
}
|
|
4367
|
+
this.totalSize = offset;
|
|
4368
|
+
}
|
|
4369
|
+
findNearestIndex(offset) {
|
|
4370
|
+
if (offset <= 0)
|
|
4371
|
+
return 0;
|
|
4372
|
+
if (offset >= this.totalSize)
|
|
4373
|
+
return Math.max(0, this.count - 1);
|
|
4374
|
+
let low = 0;
|
|
4375
|
+
let high = this.count - 1;
|
|
4376
|
+
let nearest = this.count - 1;
|
|
4377
|
+
while (low <= high) {
|
|
4378
|
+
const middle = Math.floor((low + high) / 2);
|
|
4379
|
+
const start = this.offsets[middle] ?? 0;
|
|
4380
|
+
const end = start + this.getSize(middle);
|
|
4381
|
+
if (offset >= end) {
|
|
4382
|
+
low = middle + 1;
|
|
4383
|
+
}
|
|
4384
|
+
else {
|
|
4385
|
+
nearest = middle;
|
|
4386
|
+
high = middle - 1;
|
|
4387
|
+
}
|
|
4388
|
+
}
|
|
4389
|
+
return this.clampIndex(nearest);
|
|
4390
|
+
}
|
|
4391
|
+
clampIndex(index) {
|
|
4392
|
+
return Math.min(Math.max(0, Math.floor(index)), Math.max(0, this.count - 1));
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
|
|
4396
|
+
class ChatVirtualListController {
|
|
4397
|
+
constructor(options = {}) {
|
|
4398
|
+
this.bottomThreshold = Math.max(0, options.bottomThreshold ?? 48);
|
|
4399
|
+
this.topThreshold = Math.max(0, options.topThreshold ?? 80);
|
|
4400
|
+
}
|
|
4401
|
+
updateOptions(options) {
|
|
4402
|
+
if (options.bottomThreshold !== undefined) {
|
|
4403
|
+
this.bottomThreshold = Math.max(0, options.bottomThreshold);
|
|
4404
|
+
}
|
|
4405
|
+
if (options.topThreshold !== undefined) {
|
|
4406
|
+
this.topThreshold = Math.max(0, options.topThreshold);
|
|
4407
|
+
}
|
|
4408
|
+
}
|
|
4409
|
+
isNearBottom(scrollTop, viewportHeight, totalSize, scrollHeight = totalSize) {
|
|
4410
|
+
return (Math.max(totalSize, scrollHeight) - scrollTop - viewportHeight <=
|
|
4411
|
+
this.bottomThreshold);
|
|
4412
|
+
}
|
|
4413
|
+
isNearTop(scrollTop) {
|
|
4414
|
+
return scrollTop <= this.topThreshold;
|
|
4415
|
+
}
|
|
4416
|
+
getBottomScrollTop(totalSize, viewportHeight, scrollHeight = totalSize) {
|
|
4417
|
+
return Math.max(0, totalSize - viewportHeight, scrollHeight - viewportHeight);
|
|
4418
|
+
}
|
|
4419
|
+
getPrependCompensatedScrollTop(previousScrollTop, previousTotalSize, nextTotalSize) {
|
|
4420
|
+
return Math.max(0, previousScrollTop + Math.max(0, nextTotalSize - previousTotalSize));
|
|
4421
|
+
}
|
|
4422
|
+
detectPrependCount(previousKeys, nextKeys) {
|
|
4423
|
+
if (previousKeys.length === 0 || nextKeys.length === 0)
|
|
4424
|
+
return 0;
|
|
4425
|
+
const firstPreviousKey = previousKeys[0];
|
|
4426
|
+
const index = nextKeys.findIndex((key) => Object.is(key, firstPreviousKey));
|
|
4427
|
+
return index > 0 ? index : 0;
|
|
4428
|
+
}
|
|
4429
|
+
detectAppendCount(previousKeys, nextKeys) {
|
|
4430
|
+
if (previousKeys.length === 0 || nextKeys.length <= previousKeys.length)
|
|
4431
|
+
return 0;
|
|
4432
|
+
const previousKeysStillPrefix = previousKeys.every((key, index) => Object.is(key, nextKeys[index]));
|
|
4433
|
+
return previousKeysStillPrefix ? nextKeys.length - previousKeys.length : 0;
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
|
|
4437
|
+
const DEFAULT_GAP = 16;
|
|
4438
|
+
const DEFAULT_MIN_COLUMN_WIDTH = 220;
|
|
4439
|
+
const DEFAULT_OVERSCAN = 320;
|
|
4440
|
+
class MasonryVirtualListController {
|
|
4441
|
+
constructor(options) {
|
|
4442
|
+
this.measuredSizes = new Map();
|
|
4443
|
+
this.items = [];
|
|
4444
|
+
this.totalSize = 0;
|
|
4445
|
+
this.resolvedColumns = 1;
|
|
4446
|
+
this.columnWidth = 0;
|
|
4447
|
+
this.columns = this.normalizeOptionalCount(options.columns);
|
|
4448
|
+
this.containerWidth = Math.max(0, options.containerWidth);
|
|
4449
|
+
this.count = Math.max(0, Math.floor(options.count));
|
|
4450
|
+
this.estimateSize = options.estimateSize;
|
|
4451
|
+
this.gap = Math.max(0, options.gap ?? DEFAULT_GAP);
|
|
4452
|
+
this.minColumnWidth = Math.max(1, options.minColumnWidth ?? DEFAULT_MIN_COLUMN_WIDTH);
|
|
4453
|
+
this.overscan = Math.max(0, options.overscan ?? DEFAULT_OVERSCAN);
|
|
4454
|
+
this.recalculate();
|
|
4455
|
+
}
|
|
4456
|
+
updateOptions(options) {
|
|
4457
|
+
if (options.columns !== undefined) {
|
|
4458
|
+
this.columns = this.normalizeOptionalCount(options.columns);
|
|
4459
|
+
}
|
|
4460
|
+
if (options.containerWidth !== undefined) {
|
|
4461
|
+
this.containerWidth = Math.max(0, options.containerWidth);
|
|
4462
|
+
}
|
|
4463
|
+
if (options.count !== undefined) {
|
|
4464
|
+
const nextCount = Math.max(0, Math.floor(options.count));
|
|
4465
|
+
if (nextCount < this.count) {
|
|
4466
|
+
Array.from(this.measuredSizes.keys()).forEach((index) => {
|
|
4467
|
+
if (index >= nextCount)
|
|
4468
|
+
this.measuredSizes.delete(index);
|
|
4469
|
+
});
|
|
4470
|
+
}
|
|
4471
|
+
this.count = nextCount;
|
|
4472
|
+
}
|
|
4473
|
+
if (options.estimateSize !== undefined) {
|
|
4474
|
+
this.estimateSize = options.estimateSize;
|
|
4475
|
+
}
|
|
4476
|
+
if (options.gap !== undefined) {
|
|
4477
|
+
this.gap = Math.max(0, options.gap);
|
|
4478
|
+
}
|
|
4479
|
+
if (options.minColumnWidth !== undefined) {
|
|
4480
|
+
this.minColumnWidth = Math.max(1, options.minColumnWidth);
|
|
4481
|
+
}
|
|
4482
|
+
if (options.overscan !== undefined) {
|
|
4483
|
+
this.overscan = Math.max(0, options.overscan);
|
|
4484
|
+
}
|
|
4485
|
+
this.recalculate();
|
|
4486
|
+
}
|
|
4487
|
+
getState() {
|
|
4488
|
+
return {
|
|
4489
|
+
columnWidth: this.columnWidth,
|
|
4490
|
+
columns: this.resolvedColumns,
|
|
4491
|
+
count: this.count,
|
|
4492
|
+
gap: this.gap,
|
|
4493
|
+
measuredCount: this.measuredSizes.size,
|
|
4494
|
+
overscan: this.overscan
|
|
4495
|
+
};
|
|
4496
|
+
}
|
|
4497
|
+
getTotalSize() {
|
|
4498
|
+
return this.totalSize;
|
|
4499
|
+
}
|
|
4500
|
+
getItem(index) {
|
|
4501
|
+
const safeIndex = this.clampIndex(index);
|
|
4502
|
+
return this.items[safeIndex] ?? this.createFallbackItem(safeIndex);
|
|
4503
|
+
}
|
|
4504
|
+
getRange(scrollOffset, viewportSize) {
|
|
4505
|
+
if (this.count === 0) {
|
|
4506
|
+
return {
|
|
4507
|
+
columnWidth: this.columnWidth,
|
|
4508
|
+
columns: this.resolvedColumns,
|
|
4509
|
+
endIndex: -1,
|
|
4510
|
+
items: [],
|
|
4511
|
+
startIndex: 0,
|
|
4512
|
+
totalSize: 0
|
|
4513
|
+
};
|
|
4514
|
+
}
|
|
4515
|
+
const safeViewportSize = Math.max(0, viewportSize);
|
|
4516
|
+
const maxScrollOffset = Math.max(0, this.totalSize - safeViewportSize);
|
|
4517
|
+
const safeScrollOffset = Math.min(Math.max(0, scrollOffset), maxScrollOffset);
|
|
4518
|
+
const rangeStart = Math.max(0, safeScrollOffset - this.overscan);
|
|
4519
|
+
const rangeEnd = safeScrollOffset + safeViewportSize + this.overscan;
|
|
4520
|
+
const items = this.items.filter((item) => item.end >= rangeStart && item.start <= rangeEnd);
|
|
4521
|
+
return {
|
|
4522
|
+
columnWidth: this.columnWidth,
|
|
4523
|
+
columns: this.resolvedColumns,
|
|
4524
|
+
endIndex: items[items.length - 1]?.index ?? -1,
|
|
4525
|
+
items,
|
|
4526
|
+
startIndex: items[0]?.index ?? 0,
|
|
4527
|
+
totalSize: this.totalSize
|
|
4528
|
+
};
|
|
4529
|
+
}
|
|
4530
|
+
measure(index, size) {
|
|
4531
|
+
if (index < 0 || index >= this.count || !Number.isFinite(size) || size <= 0)
|
|
4532
|
+
return false;
|
|
4533
|
+
const normalizedSize = Math.round(size);
|
|
4534
|
+
if (this.measuredSizes.get(index) === normalizedSize)
|
|
4535
|
+
return false;
|
|
4536
|
+
this.measuredSizes.set(index, normalizedSize);
|
|
4537
|
+
this.recalculate();
|
|
4538
|
+
return true;
|
|
4539
|
+
}
|
|
4540
|
+
resetMeasurements() {
|
|
4541
|
+
this.measuredSizes.clear();
|
|
4542
|
+
this.recalculate();
|
|
4543
|
+
}
|
|
4544
|
+
recalculate() {
|
|
4545
|
+
this.resolvedColumns = this.resolveColumns();
|
|
4546
|
+
this.columnWidth =
|
|
4547
|
+
this.resolvedColumns <= 1
|
|
4548
|
+
? Math.max(0, this.containerWidth)
|
|
4549
|
+
: Math.max(1, (this.containerWidth - this.gap * (this.resolvedColumns - 1)) / this.resolvedColumns);
|
|
4550
|
+
const columnHeights = new Array(this.resolvedColumns).fill(0);
|
|
4551
|
+
this.items = new Array(this.count);
|
|
4552
|
+
for (let index = 0; index < this.count; index += 1) {
|
|
4553
|
+
const column = this.findShortestColumn(columnHeights);
|
|
4554
|
+
const x = column * (this.columnWidth + this.gap);
|
|
4555
|
+
const y = columnHeights[column] ?? 0;
|
|
4556
|
+
const height = this.getSize(index);
|
|
4557
|
+
this.items[index] = {
|
|
4558
|
+
column,
|
|
4559
|
+
end: y + height,
|
|
4560
|
+
height,
|
|
4561
|
+
index,
|
|
4562
|
+
key: String(index),
|
|
4563
|
+
start: y,
|
|
4564
|
+
width: this.columnWidth,
|
|
4565
|
+
x,
|
|
4566
|
+
y
|
|
4567
|
+
};
|
|
4568
|
+
columnHeights[column] = y + height + this.gap;
|
|
4569
|
+
}
|
|
4570
|
+
this.totalSize = Math.max(0, ...columnHeights.map((height) => Math.max(0, height - this.gap)));
|
|
4571
|
+
}
|
|
4572
|
+
resolveColumns() {
|
|
4573
|
+
if (this.columns !== undefined)
|
|
4574
|
+
return Math.max(1, this.columns);
|
|
4575
|
+
if (this.containerWidth <= 0)
|
|
4576
|
+
return 1;
|
|
4577
|
+
return Math.max(1, Math.floor((this.containerWidth + this.gap) / (this.minColumnWidth + this.gap)));
|
|
4578
|
+
}
|
|
4579
|
+
getSize(index) {
|
|
4580
|
+
return this.measuredSizes.get(index) ?? this.getEstimatedSize(index);
|
|
4581
|
+
}
|
|
4582
|
+
getEstimatedSize(index) {
|
|
4583
|
+
const size = typeof this.estimateSize === "function"
|
|
4584
|
+
? this.estimateSize(index, this.columnWidth)
|
|
4585
|
+
: this.estimateSize;
|
|
4586
|
+
return Math.max(1, Number.isFinite(size) ? Math.round(size) : 1);
|
|
4587
|
+
}
|
|
4588
|
+
findShortestColumn(columnHeights) {
|
|
4589
|
+
let column = 0;
|
|
4590
|
+
let minHeight = columnHeights[0] ?? 0;
|
|
4591
|
+
for (let index = 1; index < columnHeights.length; index += 1) {
|
|
4592
|
+
const height = columnHeights[index] ?? 0;
|
|
4593
|
+
if (height < minHeight) {
|
|
4594
|
+
column = index;
|
|
4595
|
+
minHeight = height;
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
return column;
|
|
4599
|
+
}
|
|
4600
|
+
createFallbackItem(index) {
|
|
4601
|
+
return {
|
|
4602
|
+
column: 0,
|
|
4603
|
+
end: 0,
|
|
4604
|
+
height: 0,
|
|
4605
|
+
index,
|
|
4606
|
+
key: String(index),
|
|
4607
|
+
start: 0,
|
|
4608
|
+
width: this.columnWidth,
|
|
4609
|
+
x: 0,
|
|
4610
|
+
y: 0
|
|
4611
|
+
};
|
|
4612
|
+
}
|
|
4613
|
+
normalizeOptionalCount(value) {
|
|
4614
|
+
if (value === undefined)
|
|
4615
|
+
return undefined;
|
|
4616
|
+
return Math.max(1, Math.floor(value));
|
|
4617
|
+
}
|
|
4618
|
+
clampIndex(index) {
|
|
4619
|
+
return Math.min(Math.max(0, Math.floor(index)), Math.max(0, this.count - 1));
|
|
4620
|
+
}
|
|
4621
|
+
}
|
|
4622
|
+
|
|
4623
|
+
export { AffixController, BacktopController, BadgeController, BreadcrumbController, CalendarController, CanvasEditorController, CanvasImageController, ChatVirtualListController, ColorPickerController, ComicReaderController, CountdownController, DanmakuController, DatePickerController, DateRangePickerController, DesignEffectController, DragController, DropController, FieldController, FilePreviewController, FloatingBallController, FormController, GestureController, GradientTextController, ImagePreviewController, LazyImageController, LiveRoomController, MarqueeController, MasonryVirtualListController, ModalController, MultiColumnPickerController, NovelReaderController, PaginationController, PasswordInputController, PopupController, ProgressController, RollingNumberController, SignatureController, SkeletonController, SlideCaptchaController, StateEmitter, SwiperController, TableController, TabsController, TagController, TiltCardController, TimelineController, ToastManager, TooltipController, TypewriterTextController, UploadController, VerificationCodeController, VideoDetailTransitionController, VideoPlayerController, VirtualListController, VirtualSelectController, cloneValues, configureClassComponents, getByPath, getClassComponentsConfig, getClassComponentsLocale, getSafeTooltipPlacement, resetClassComponentsConfig, setByPath };
|
|
4624
|
+
//# sourceMappingURL=index.js.map
|