@yh-ui/hooks 0.1.17 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +289 -0
- package/dist/index.cjs +147 -1460
- package/dist/index.d.ts +18 -698
- package/dist/index.mjs +15 -1427
- package/dist/storage/index.cjs +128 -0
- package/dist/storage/index.d.ts +26 -0
- package/dist/storage/index.mjs +112 -0
- package/dist/use-ai/index.cjs +11 -0
- package/dist/use-ai/index.d.ts +1 -0
- package/dist/use-ai/index.mjs +1 -0
- package/dist/use-ai/use-ai-conversations.cjs +73 -6
- package/dist/use-ai/use-ai-conversations.d.ts +34 -4
- package/dist/use-ai/use-ai-conversations.mjs +71 -4
- package/dist/use-ai/use-ai-persistence.cjs +160 -0
- package/dist/use-ai/use-ai-persistence.d.ts +62 -0
- package/dist/use-ai/use-ai-persistence.mjs +154 -0
- package/dist/use-countdown/index.cjs +51 -0
- package/dist/use-countdown/index.d.ts +17 -0
- package/dist/use-countdown/index.mjs +40 -0
- package/dist/use-sku/index.cjs +62 -0
- package/dist/use-sku/index.d.ts +30 -0
- package/dist/use-sku/index.mjs +58 -0
- package/dist/use-virtual-scroll/index.cjs +17 -26
- package/dist/use-virtual-scroll/index.d.ts +5 -9
- package/dist/use-virtual-scroll/index.mjs +18 -23
- package/package.json +6 -4
- package/dist/index.d.cts +0 -699
- package/dist/index.d.mts +0 -699
package/dist/index.cjs
CHANGED
|
@@ -1,1483 +1,170 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
require(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
n.default = e;
|
|
17
|
-
return n;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const _dayjs__namespace = /*#__PURE__*/_interopNamespaceCompat(_dayjs);
|
|
21
|
-
|
|
22
|
-
const defaultNamespace = "yh";
|
|
23
|
-
const statePrefix = "is-";
|
|
24
|
-
const namespaceContextKey = Symbol("namespaceContextKey");
|
|
25
|
-
const useGlobalNamespace = () => {
|
|
26
|
-
return vue.inject(namespaceContextKey, vue.ref(defaultNamespace));
|
|
27
|
-
};
|
|
28
|
-
const useNamespace = (block) => {
|
|
29
|
-
const namespace = useGlobalNamespace();
|
|
30
|
-
const b = (blockSuffix = "") => {
|
|
31
|
-
const ns = vue.unref(namespace);
|
|
32
|
-
return blockSuffix ? `${ns}-${block}-${blockSuffix}` : `${ns}-${block}`;
|
|
33
|
-
};
|
|
34
|
-
const e = (element) => {
|
|
35
|
-
return element ? `${b()}__${element}` : "";
|
|
36
|
-
};
|
|
37
|
-
const m = (modifier) => {
|
|
38
|
-
return modifier ? `${b()}--${modifier}` : "";
|
|
39
|
-
};
|
|
40
|
-
const bem = (blockSuffix, element, modifier) => {
|
|
41
|
-
let cls = b(blockSuffix);
|
|
42
|
-
if (element) cls += `__${element}`;
|
|
43
|
-
if (modifier) cls += `--${modifier}`;
|
|
44
|
-
return cls;
|
|
45
|
-
};
|
|
46
|
-
const em = (element, modifier) => {
|
|
47
|
-
return element && modifier ? `${b()}__${element}--${modifier}` : "";
|
|
48
|
-
};
|
|
49
|
-
function is(state, value) {
|
|
50
|
-
if (arguments.length === 1) {
|
|
51
|
-
return `${statePrefix}${state}`;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _useNamespace = require("./use-namespace/index.cjs");
|
|
7
|
+
Object.keys(_useNamespace).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _useNamespace[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _useNamespace[key];
|
|
52
14
|
}
|
|
53
|
-
return value ? `${statePrefix}${state}` : "";
|
|
54
|
-
}
|
|
55
|
-
const cssVar = (name) => {
|
|
56
|
-
return `--${vue.unref(namespace)}-${block}-${name}`;
|
|
57
|
-
};
|
|
58
|
-
const cssVarObj = (vars) => {
|
|
59
|
-
const obj = {};
|
|
60
|
-
Object.entries(vars).forEach(([key, value]) => {
|
|
61
|
-
obj[cssVar(key)] = value;
|
|
62
|
-
});
|
|
63
|
-
return obj;
|
|
64
|
-
};
|
|
65
|
-
const cssVarBlock = (name) => {
|
|
66
|
-
return `--${vue.unref(namespace)}-${name}`;
|
|
67
|
-
};
|
|
68
|
-
const cssVarBlockObj = (vars) => {
|
|
69
|
-
const obj = {};
|
|
70
|
-
Object.entries(vars).forEach(([key, value]) => {
|
|
71
|
-
obj[cssVarBlock(key)] = value;
|
|
72
|
-
});
|
|
73
|
-
return obj;
|
|
74
|
-
};
|
|
75
|
-
return {
|
|
76
|
-
namespace,
|
|
77
|
-
b,
|
|
78
|
-
e,
|
|
79
|
-
m,
|
|
80
|
-
bem,
|
|
81
|
-
em,
|
|
82
|
-
is,
|
|
83
|
-
cssVar,
|
|
84
|
-
cssVarObj,
|
|
85
|
-
cssVarBlock,
|
|
86
|
-
cssVarBlockObj
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const defaultInitialZIndex = 2e3;
|
|
91
|
-
const zIndexContextKey = Symbol("zIndexContextKey");
|
|
92
|
-
const zIndexCounterKey = Symbol("zIndexCounterKey");
|
|
93
|
-
const getNextZIndex = () => {
|
|
94
|
-
if (typeof window !== "undefined") {
|
|
95
|
-
const windowContext = window;
|
|
96
|
-
if (windowContext.__YH_Z_INDEX__ === void 0) {
|
|
97
|
-
windowContext.__YH_Z_INDEX__ = defaultInitialZIndex;
|
|
98
|
-
}
|
|
99
|
-
return ++windowContext.__YH_Z_INDEX__;
|
|
100
|
-
}
|
|
101
|
-
return defaultInitialZIndex;
|
|
102
|
-
};
|
|
103
|
-
const resetZIndex = (value = defaultInitialZIndex) => {
|
|
104
|
-
if (typeof window !== "undefined") {
|
|
105
|
-
window.__YH_Z_INDEX__ = value;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const createZIndexCounter = (initialValue = defaultInitialZIndex) => {
|
|
109
|
-
return { current: initialValue };
|
|
110
|
-
};
|
|
111
|
-
const useZIndex = (zIndexOverrides) => {
|
|
112
|
-
const injectedZIndex = vue.inject(zIndexContextKey, void 0);
|
|
113
|
-
const appCounter = vue.inject(zIndexCounterKey, null);
|
|
114
|
-
const initialZIndex = vue.computed(() => {
|
|
115
|
-
const override = vue.unref(zIndexOverrides);
|
|
116
|
-
return override ?? vue.unref(injectedZIndex) ?? defaultInitialZIndex;
|
|
117
15
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
16
|
+
});
|
|
17
|
+
var _useZIndex = require("./use-z-index/index.cjs");
|
|
18
|
+
Object.keys(_useZIndex).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _useZIndex[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _useZIndex[key];
|
|
124
25
|
}
|
|
125
|
-
return getNextZIndex();
|
|
126
|
-
};
|
|
127
|
-
return {
|
|
128
|
-
initialZIndex,
|
|
129
|
-
currentZIndex,
|
|
130
|
-
nextZIndex
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const configProviderContextKey = Symbol(
|
|
135
|
-
"configProviderContextKey"
|
|
136
|
-
);
|
|
137
|
-
const useConfig = () => {
|
|
138
|
-
const configRef = vue.inject(configProviderContextKey, null);
|
|
139
|
-
const globalSize = vue.computed(() => {
|
|
140
|
-
const config = vue.unref(configRef);
|
|
141
|
-
return config?.size || "default";
|
|
142
|
-
});
|
|
143
|
-
const globalZIndex = vue.computed(() => {
|
|
144
|
-
const config = vue.unref(configRef);
|
|
145
|
-
return config?.zIndex || 2e3;
|
|
146
|
-
});
|
|
147
|
-
const globalLocale = vue.computed(() => {
|
|
148
|
-
const config = vue.unref(configRef);
|
|
149
|
-
return config?.locale;
|
|
150
26
|
});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const dayjsLocales = undefined(
|
|
161
|
-
["../../../../node_modules/dayjs/locale/*.js", "!../../../../node_modules/dayjs/locale/en.js"],
|
|
162
|
-
{ eager: false }
|
|
163
|
-
);
|
|
164
|
-
const loadedLocales = /* @__PURE__ */ new Set(["en"]);
|
|
165
|
-
const localeMapping = {
|
|
166
|
-
"zh-cn": "zh-cn",
|
|
167
|
-
"zh-tw": "zh-tw",
|
|
168
|
-
"zh-hk": "zh-hk",
|
|
169
|
-
"zh-mo": "zh-tw",
|
|
170
|
-
en: "en",
|
|
171
|
-
ja: "ja",
|
|
172
|
-
ko: "ko",
|
|
173
|
-
de: "de",
|
|
174
|
-
fr: "fr",
|
|
175
|
-
es: "es",
|
|
176
|
-
pt: "pt",
|
|
177
|
-
"pt-br": "pt-br",
|
|
178
|
-
ru: "ru",
|
|
179
|
-
ar: "ar",
|
|
180
|
-
"ar-eg": "ar",
|
|
181
|
-
tr: "tr",
|
|
182
|
-
it: "it",
|
|
183
|
-
nl: "nl",
|
|
184
|
-
pl: "pl",
|
|
185
|
-
th: "th",
|
|
186
|
-
vi: "vi",
|
|
187
|
-
id: "id",
|
|
188
|
-
ms: "ms",
|
|
189
|
-
da: "da",
|
|
190
|
-
sv: "sv",
|
|
191
|
-
fi: "fi",
|
|
192
|
-
no: "nb",
|
|
193
|
-
"nb-NO": "nb",
|
|
194
|
-
cs: "cs",
|
|
195
|
-
sk: "sk",
|
|
196
|
-
uk: "uk",
|
|
197
|
-
hu: "hu",
|
|
198
|
-
ro: "ro",
|
|
199
|
-
bg: "bg",
|
|
200
|
-
az: "az",
|
|
201
|
-
fa: "fa",
|
|
202
|
-
hi: "hi",
|
|
203
|
-
pa: "pa-in",
|
|
204
|
-
el: "el",
|
|
205
|
-
ca: "ca",
|
|
206
|
-
tk: "tk",
|
|
207
|
-
ta: "ta",
|
|
208
|
-
lv: "lv",
|
|
209
|
-
af: "af",
|
|
210
|
-
et: "et",
|
|
211
|
-
sl: "sl",
|
|
212
|
-
he: "he",
|
|
213
|
-
lo: "lo",
|
|
214
|
-
lt: "lt",
|
|
215
|
-
mn: "mn",
|
|
216
|
-
kk: "kk",
|
|
217
|
-
ku: "ku",
|
|
218
|
-
ckb: "ku",
|
|
219
|
-
"ug-cn": "ug-cn",
|
|
220
|
-
km: "km",
|
|
221
|
-
sr: "sr",
|
|
222
|
-
eu: "eu",
|
|
223
|
-
ky: "ky",
|
|
224
|
-
"hy-am": "hy-am",
|
|
225
|
-
hr: "hr",
|
|
226
|
-
eo: "eo",
|
|
227
|
-
bn: "bn",
|
|
228
|
-
mg: "mg",
|
|
229
|
-
sw: "sw",
|
|
230
|
-
"uz-uz": "uz",
|
|
231
|
-
my: "my",
|
|
232
|
-
te: "te"
|
|
233
|
-
};
|
|
234
|
-
const getDayjsLocale = (localeCode) => {
|
|
235
|
-
return localeMapping[localeCode] || "en";
|
|
236
|
-
};
|
|
237
|
-
const setDayjsLocale = async (localeCode) => {
|
|
238
|
-
const dayjsLocale = getDayjsLocale(localeCode);
|
|
239
|
-
if (loadedLocales.has(dayjsLocale)) {
|
|
240
|
-
dayjs.locale(dayjsLocale);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
if (dayjsLocale === "en") {
|
|
244
|
-
dayjs.locale("en");
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const path = `../../../../node_modules/dayjs/locale/${dayjsLocale}.js`;
|
|
248
|
-
const loader = dayjsLocales[path];
|
|
249
|
-
if (loader) {
|
|
250
|
-
try {
|
|
251
|
-
await loader();
|
|
252
|
-
loadedLocales.add(dayjsLocale);
|
|
253
|
-
dayjs.locale(dayjsLocale);
|
|
254
|
-
} catch {
|
|
255
|
-
dayjs.locale("en");
|
|
256
|
-
}
|
|
257
|
-
} else {
|
|
258
|
-
dayjs.locale("en");
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
const setDayjsLocaleSync = (localeCode) => {
|
|
262
|
-
const dayjsLocale = getDayjsLocale(localeCode);
|
|
263
|
-
if (loadedLocales.has(dayjsLocale)) {
|
|
264
|
-
dayjs.locale(dayjsLocale);
|
|
265
|
-
} else {
|
|
266
|
-
dayjs.locale("en");
|
|
267
|
-
setDayjsLocale(localeCode);
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
const updateDayjsMonths = (localeCode, months) => {
|
|
271
|
-
const dayjsLocale = getDayjsLocale(localeCode);
|
|
272
|
-
const monthsArray = [
|
|
273
|
-
months.jan,
|
|
274
|
-
months.feb,
|
|
275
|
-
months.mar,
|
|
276
|
-
months.apr,
|
|
277
|
-
months.may,
|
|
278
|
-
months.jun,
|
|
279
|
-
months.jul,
|
|
280
|
-
months.aug,
|
|
281
|
-
months.sep,
|
|
282
|
-
months.oct,
|
|
283
|
-
months.nov,
|
|
284
|
-
months.dec
|
|
285
|
-
];
|
|
286
|
-
try {
|
|
287
|
-
if (dayjs.updateLocale) {
|
|
288
|
-
dayjs.updateLocale(dayjsLocale, {
|
|
289
|
-
months: monthsArray,
|
|
290
|
-
monthsShort: monthsArray
|
|
291
|
-
});
|
|
27
|
+
});
|
|
28
|
+
var _useSku = require("./use-sku/index.cjs");
|
|
29
|
+
Object.keys(_useSku).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _useSku[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _useSku[key];
|
|
292
36
|
}
|
|
293
|
-
} catch {
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
const useLocale = (localeOverrides) => {
|
|
298
|
-
const { globalLocale } = useConfig();
|
|
299
|
-
const locale$1 = vue.computed(() => {
|
|
300
|
-
return vue.unref(localeOverrides) ?? vue.unref(globalLocale) ?? locale.zhCn;
|
|
301
37
|
});
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const keys = path.split(".");
|
|
312
|
-
let result = locale$1.value.yh;
|
|
313
|
-
for (const key of keys) {
|
|
314
|
-
if (result && typeof result === "object") {
|
|
315
|
-
result = result[key];
|
|
316
|
-
} else {
|
|
317
|
-
result = void 0;
|
|
318
|
-
}
|
|
319
|
-
if (result === void 0) return path;
|
|
320
|
-
}
|
|
321
|
-
if (typeof result !== "string") return path;
|
|
322
|
-
if (options) {
|
|
323
|
-
return result.replace(/\{(\w+)\}/g, (_match, key) => {
|
|
324
|
-
const val = options[key];
|
|
325
|
-
return val !== void 0 ? String(val) : `{${key}}`;
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
return result;
|
|
329
|
-
};
|
|
330
|
-
const tRaw = (path) => {
|
|
331
|
-
const keys = path.split(".");
|
|
332
|
-
let result = locale$1.value.yh;
|
|
333
|
-
for (const key of keys) {
|
|
334
|
-
if (result && typeof result === "object") {
|
|
335
|
-
result = result[key];
|
|
336
|
-
} else {
|
|
337
|
-
result = void 0;
|
|
338
|
-
}
|
|
339
|
-
if (result === void 0) return path;
|
|
38
|
+
});
|
|
39
|
+
var _useCountdown = require("./use-countdown/index.cjs");
|
|
40
|
+
Object.keys(_useCountdown).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _useCountdown[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _useCountdown[key];
|
|
340
47
|
}
|
|
341
|
-
return result;
|
|
342
|
-
};
|
|
343
|
-
return {
|
|
344
|
-
locale: locale$1,
|
|
345
|
-
lang,
|
|
346
|
-
t,
|
|
347
|
-
tRaw
|
|
348
|
-
};
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
const idInjectionKey = Symbol("idInjectionKey");
|
|
352
|
-
const useId = (idOverrides) => {
|
|
353
|
-
const injectedId = vue.inject(idInjectionKey, void 0);
|
|
354
|
-
const nativeId = vue.useId();
|
|
355
|
-
const id = vue.computed(() => {
|
|
356
|
-
const override = vue.unref(idOverrides);
|
|
357
|
-
if (override) return override;
|
|
358
|
-
const injected = vue.unref(injectedId);
|
|
359
|
-
if (injected) return injected;
|
|
360
|
-
return nativeId;
|
|
361
48
|
});
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
return
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
const FormContextKey = Symbol("FormContextKey");
|
|
373
|
-
const FormItemContextKey = Symbol("FormItemContextKey");
|
|
374
|
-
const useFormItem = () => {
|
|
375
|
-
const form = vue.inject(FormContextKey, void 0);
|
|
376
|
-
const formItem = vue.inject(FormItemContextKey, void 0);
|
|
377
|
-
return {
|
|
378
|
-
form,
|
|
379
|
-
formItem,
|
|
380
|
-
// 触发校验
|
|
381
|
-
validate: (trigger) => {
|
|
382
|
-
if (formItem) {
|
|
383
|
-
return formItem.validate(trigger).catch(() => {
|
|
384
|
-
return false;
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
return Promise.resolve(true);
|
|
49
|
+
});
|
|
50
|
+
var _useLocale = require("./use-locale/index.cjs");
|
|
51
|
+
Object.keys(_useLocale).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _useLocale[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _useLocale[key];
|
|
388
58
|
}
|
|
389
|
-
};
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
function useVirtualScroll(options) {
|
|
393
|
-
const { itemHeight, containerHeight, overscan = 3 } = options;
|
|
394
|
-
const containerRef = vue.ref(null);
|
|
395
|
-
const scrollTop = vue.ref(0);
|
|
396
|
-
const itemsRef = vue.computed(() => {
|
|
397
|
-
const items = options.items;
|
|
398
|
-
return Array.isArray(items) ? items : items.value;
|
|
399
|
-
});
|
|
400
|
-
const totalHeight = vue.computed(() => itemsRef.value.length * itemHeight);
|
|
401
|
-
const visibleCount = vue.computed(() => Math.ceil(containerHeight / itemHeight));
|
|
402
|
-
const startIndex = vue.computed(() => {
|
|
403
|
-
const items = itemsRef.value;
|
|
404
|
-
if (items.length === 0) return 0;
|
|
405
|
-
const start = Math.floor(scrollTop.value / itemHeight);
|
|
406
|
-
return Math.max(0, start - overscan);
|
|
407
|
-
});
|
|
408
|
-
const endIndex = vue.computed(() => {
|
|
409
|
-
const items = itemsRef.value;
|
|
410
|
-
if (items.length === 0) return 0;
|
|
411
|
-
const start = Math.floor(scrollTop.value / itemHeight);
|
|
412
|
-
const end = start + visibleCount.value;
|
|
413
|
-
return Math.min(items.length, end + overscan);
|
|
414
59
|
});
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
};
|
|
425
|
-
const scrollToIndex = (index) => {
|
|
426
|
-
if (containerRef.value) {
|
|
427
|
-
const targetScrollTop = index * itemHeight;
|
|
428
|
-
containerRef.value.scrollTop = targetScrollTop;
|
|
429
|
-
scrollTop.value = targetScrollTop;
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
return {
|
|
433
|
-
visibleItems,
|
|
434
|
-
totalHeight,
|
|
435
|
-
offsetY,
|
|
436
|
-
startIndex: vue.computed(() => startIndex.value),
|
|
437
|
-
endIndex: vue.computed(() => endIndex.value),
|
|
438
|
-
onScroll,
|
|
439
|
-
scrollToIndex,
|
|
440
|
-
containerRef
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
function useCache(key, fetcher) {
|
|
445
|
-
const data = vue.shallowRef(null);
|
|
446
|
-
const execute = async () => {
|
|
447
|
-
try {
|
|
448
|
-
data.value = await fetcher();
|
|
449
|
-
} catch (err) {
|
|
450
|
-
console.error(`[YH-UI] Cache fetcher error for key ${key}:`, err);
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
return {
|
|
454
|
-
data,
|
|
455
|
-
execute
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
function useEventListener(target, event, handler, options) {
|
|
460
|
-
if (typeof window === "undefined") return;
|
|
461
|
-
const getTarget = () => {
|
|
462
|
-
if (typeof target === "function") {
|
|
463
|
-
return target();
|
|
464
|
-
}
|
|
465
|
-
return vue.unref(target);
|
|
466
|
-
};
|
|
467
|
-
const add = () => {
|
|
468
|
-
const el = getTarget();
|
|
469
|
-
if (el) {
|
|
470
|
-
el.addEventListener(event, handler, options);
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
const remove = () => {
|
|
474
|
-
const el = getTarget();
|
|
475
|
-
if (el) {
|
|
476
|
-
el.removeEventListener(event, handler, options);
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
vue.onMounted(add);
|
|
480
|
-
vue.onBeforeUnmount(remove);
|
|
481
|
-
if (vue.isRef(target)) {
|
|
482
|
-
vue.watch(target, (newVal, oldVal) => {
|
|
483
|
-
if (oldVal) {
|
|
484
|
-
oldVal.removeEventListener(event, handler, options);
|
|
485
|
-
}
|
|
486
|
-
if (newVal) {
|
|
487
|
-
newVal.addEventListener(event, handler, options);
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
const useScrollLock = (trigger) => {
|
|
494
|
-
const isLocked = vue.ref(false);
|
|
495
|
-
let initialHtmlStyle = { overflow: "", paddingRight: "" };
|
|
496
|
-
let initialBodyStyle = { overflow: "", paddingRight: "" };
|
|
497
|
-
const getScrollbarWidth = () => {
|
|
498
|
-
return window.innerWidth - document.documentElement.clientWidth;
|
|
499
|
-
};
|
|
500
|
-
const lock = () => {
|
|
501
|
-
if (isLocked.value) return;
|
|
502
|
-
const width = getScrollbarWidth();
|
|
503
|
-
const html = document.documentElement;
|
|
504
|
-
const body = document.body;
|
|
505
|
-
initialHtmlStyle = {
|
|
506
|
-
overflow: html.style.overflow,
|
|
507
|
-
paddingRight: html.style.paddingRight
|
|
508
|
-
};
|
|
509
|
-
initialBodyStyle = {
|
|
510
|
-
overflow: body.style.overflow,
|
|
511
|
-
paddingRight: body.style.paddingRight
|
|
512
|
-
};
|
|
513
|
-
if (width > 0) {
|
|
514
|
-
const scrollbarWidth = `${width}px`;
|
|
515
|
-
html.style.setProperty("--yh-scrollbar-width", scrollbarWidth);
|
|
516
|
-
const computedBodyPadding = window.getComputedStyle(body).paddingRight;
|
|
517
|
-
body.style.paddingRight = `calc(${computedBodyPadding} + ${scrollbarWidth})`;
|
|
518
|
-
}
|
|
519
|
-
html.style.overflow = "hidden";
|
|
520
|
-
body.style.overflow = "hidden";
|
|
521
|
-
html.classList.add("yh-popup-parent--hidden");
|
|
522
|
-
isLocked.value = true;
|
|
523
|
-
};
|
|
524
|
-
const unlock = () => {
|
|
525
|
-
if (!isLocked.value) return;
|
|
526
|
-
const html = document.documentElement;
|
|
527
|
-
const body = document.body;
|
|
528
|
-
html.style.overflow = initialHtmlStyle.overflow;
|
|
529
|
-
html.style.paddingRight = initialHtmlStyle.paddingRight;
|
|
530
|
-
body.style.overflow = initialBodyStyle.overflow;
|
|
531
|
-
body.style.paddingRight = initialBodyStyle.paddingRight;
|
|
532
|
-
html.classList.remove("yh-popup-parent--hidden");
|
|
533
|
-
setTimeout(() => {
|
|
534
|
-
if (!html.classList.contains("yh-popup-parent--hidden")) {
|
|
535
|
-
html.style.removeProperty("--yh-scrollbar-width");
|
|
536
|
-
}
|
|
537
|
-
}, 400);
|
|
538
|
-
isLocked.value = false;
|
|
539
|
-
};
|
|
540
|
-
vue.watch(trigger, (val) => {
|
|
541
|
-
if (val) {
|
|
542
|
-
lock();
|
|
543
|
-
} else {
|
|
544
|
-
unlock();
|
|
60
|
+
});
|
|
61
|
+
var _useId = require("./use-id/index.cjs");
|
|
62
|
+
Object.keys(_useId).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _useId[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _useId[key];
|
|
545
69
|
}
|
|
546
70
|
});
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
const el = vue.unref(target);
|
|
557
|
-
if (!el) return;
|
|
558
|
-
const path = event.composedPath();
|
|
559
|
-
if (path.includes(el)) return;
|
|
560
|
-
handler(event);
|
|
561
|
-
};
|
|
562
|
-
useEventListener(window, "mousedown", listener, true);
|
|
563
|
-
useEventListener(window, "touchstart", listener, true);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
const openaiParser = (raw) => {
|
|
567
|
-
const lines = raw.split("\n");
|
|
568
|
-
let text = "";
|
|
569
|
-
for (const line of lines) {
|
|
570
|
-
if (!line.startsWith("data: ")) continue;
|
|
571
|
-
const data = line.slice(6).trim();
|
|
572
|
-
if (data === "[DONE]") break;
|
|
573
|
-
try {
|
|
574
|
-
const json = JSON.parse(data);
|
|
575
|
-
const delta = json?.choices?.[0]?.delta?.content;
|
|
576
|
-
if (delta) text += delta;
|
|
577
|
-
} catch {
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return text || null;
|
|
581
|
-
};
|
|
582
|
-
const ernieParser = (raw) => {
|
|
583
|
-
const lines = raw.split("\n");
|
|
584
|
-
let text = "";
|
|
585
|
-
for (const line of lines) {
|
|
586
|
-
if (!line.startsWith("data: ")) continue;
|
|
587
|
-
const data = line.slice(6).trim();
|
|
588
|
-
try {
|
|
589
|
-
const json = JSON.parse(data);
|
|
590
|
-
if (json?.result) text += json.result;
|
|
591
|
-
} catch {
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
return text || null;
|
|
595
|
-
};
|
|
596
|
-
const qwenParser = (raw) => {
|
|
597
|
-
const lines = raw.split("\n");
|
|
598
|
-
let text = "";
|
|
599
|
-
for (const line of lines) {
|
|
600
|
-
if (!line.startsWith("data: ")) continue;
|
|
601
|
-
const data = line.slice(6).trim();
|
|
602
|
-
try {
|
|
603
|
-
const json = JSON.parse(data);
|
|
604
|
-
const t = json?.output?.text;
|
|
605
|
-
if (t) text += t;
|
|
606
|
-
} catch {
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
return text || null;
|
|
610
|
-
};
|
|
611
|
-
const claudeParser = (raw) => {
|
|
612
|
-
const lines = raw.split("\n");
|
|
613
|
-
let text = "";
|
|
614
|
-
for (const line of lines) {
|
|
615
|
-
if (!line.startsWith("data: ")) continue;
|
|
616
|
-
const data = line.slice(6).trim();
|
|
617
|
-
try {
|
|
618
|
-
const json = JSON.parse(data);
|
|
619
|
-
if (json?.type === "content_block_delta" && json?.delta?.text) {
|
|
620
|
-
text += json.delta.text;
|
|
621
|
-
}
|
|
622
|
-
} catch {
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
return text || null;
|
|
626
|
-
};
|
|
627
|
-
const geminiParser = (raw) => {
|
|
628
|
-
const lines = raw.split("\n");
|
|
629
|
-
let text = "";
|
|
630
|
-
for (const line of lines) {
|
|
631
|
-
const content = line.startsWith("data: ") ? line.slice(6).trim() : line.trim();
|
|
632
|
-
if (!content) continue;
|
|
633
|
-
try {
|
|
634
|
-
const json = JSON.parse(content);
|
|
635
|
-
const part = json?.candidates?.[0]?.content?.parts?.[0]?.text;
|
|
636
|
-
if (part) text += part;
|
|
637
|
-
} catch {
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
return text || null;
|
|
641
|
-
};
|
|
642
|
-
const plainTextParser = (raw) => raw || null;
|
|
643
|
-
class TypewriterThrottle {
|
|
644
|
-
queue = [];
|
|
645
|
-
rafId = null;
|
|
646
|
-
onUpdate;
|
|
647
|
-
charsPerFrame;
|
|
648
|
-
constructor(onUpdate, charsPerFrame = 3) {
|
|
649
|
-
this.onUpdate = onUpdate;
|
|
650
|
-
this.charsPerFrame = charsPerFrame;
|
|
651
|
-
}
|
|
652
|
-
push(text) {
|
|
653
|
-
this.queue.push(...text.split(""));
|
|
654
|
-
if (this.rafId === null) {
|
|
655
|
-
this.schedule();
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
schedule() {
|
|
659
|
-
this.rafId = requestAnimationFrame(() => {
|
|
660
|
-
this.rafId = null;
|
|
661
|
-
if (this.queue.length === 0) return;
|
|
662
|
-
const batch = this.queue.splice(0, this.charsPerFrame).join("");
|
|
663
|
-
this.onUpdate(batch);
|
|
664
|
-
if (this.queue.length > 0) {
|
|
665
|
-
this.schedule();
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
flush() {
|
|
670
|
-
if (this.rafId !== null) {
|
|
671
|
-
cancelAnimationFrame(this.rafId);
|
|
672
|
-
this.rafId = null;
|
|
673
|
-
}
|
|
674
|
-
if (this.queue.length > 0) {
|
|
675
|
-
const remaining = this.queue.splice(0).join("");
|
|
676
|
-
this.onUpdate(remaining);
|
|
71
|
+
});
|
|
72
|
+
var _useFormItem = require("./use-form-item/index.cjs");
|
|
73
|
+
Object.keys(_useFormItem).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _useFormItem[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _useFormItem[key];
|
|
677
80
|
}
|
|
678
|
-
}
|
|
679
|
-
cancel() {
|
|
680
|
-
if (this.rafId !== null) {
|
|
681
|
-
cancelAnimationFrame(this.rafId);
|
|
682
|
-
this.rafId = null;
|
|
683
|
-
}
|
|
684
|
-
this.queue = [];
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
function useAiStream(options) {
|
|
688
|
-
const isStreaming = vue.ref(false);
|
|
689
|
-
const currentContent = vue.ref("");
|
|
690
|
-
let abortController = new AbortController();
|
|
691
|
-
let typewriter = null;
|
|
692
|
-
const parser = options.parser ?? plainTextParser;
|
|
693
|
-
const enableTypewriter = options.typewriter !== false;
|
|
694
|
-
const charsPerFrame = options.charsPerFrame ?? 3;
|
|
695
|
-
const stop = () => {
|
|
696
|
-
if (isStreaming.value) {
|
|
697
|
-
abortController.abort();
|
|
698
|
-
isStreaming.value = false;
|
|
699
|
-
typewriter?.flush();
|
|
700
|
-
}
|
|
701
|
-
};
|
|
702
|
-
const fetchStream = async (query, ...args) => {
|
|
703
|
-
isStreaming.value = true;
|
|
704
|
-
currentContent.value = "";
|
|
705
|
-
abortController = new AbortController();
|
|
706
|
-
if (enableTypewriter) {
|
|
707
|
-
typewriter = new TypewriterThrottle((chunk) => {
|
|
708
|
-
currentContent.value += chunk;
|
|
709
|
-
options.onUpdate?.(chunk, currentContent.value);
|
|
710
|
-
}, charsPerFrame);
|
|
711
|
-
}
|
|
712
|
-
const pushText = (text) => {
|
|
713
|
-
if (!text) return;
|
|
714
|
-
if (enableTypewriter && typewriter) {
|
|
715
|
-
typewriter.push(text);
|
|
716
|
-
} else {
|
|
717
|
-
currentContent.value += text;
|
|
718
|
-
options.onUpdate?.(text, currentContent.value);
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
try {
|
|
722
|
-
const response = await options.request(query, ...args);
|
|
723
|
-
if (typeof response === "object" && response !== null && Symbol.asyncIterator in response) {
|
|
724
|
-
for await (const chunk of response) {
|
|
725
|
-
if (abortController.signal.aborted) break;
|
|
726
|
-
const parsed = parser(chunk);
|
|
727
|
-
if (parsed) pushText(parsed);
|
|
728
|
-
}
|
|
729
|
-
} else if (response instanceof Response && response.body) {
|
|
730
|
-
const reader = response.body.getReader();
|
|
731
|
-
const decoder = new TextDecoder("utf-8");
|
|
732
|
-
while (true) {
|
|
733
|
-
if (abortController.signal.aborted) {
|
|
734
|
-
reader.cancel();
|
|
735
|
-
break;
|
|
736
|
-
}
|
|
737
|
-
const { done, value } = await reader.read();
|
|
738
|
-
if (done) break;
|
|
739
|
-
const chunkStr = decoder.decode(value, { stream: true });
|
|
740
|
-
const parsed = parser(chunkStr);
|
|
741
|
-
if (parsed) pushText(parsed);
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
if (!abortController.signal.aborted) {
|
|
745
|
-
if (enableTypewriter && typewriter) {
|
|
746
|
-
typewriter.flush();
|
|
747
|
-
}
|
|
748
|
-
isStreaming.value = false;
|
|
749
|
-
options.onFinish?.(currentContent.value);
|
|
750
|
-
}
|
|
751
|
-
} catch (e) {
|
|
752
|
-
if (e.name !== "AbortError") {
|
|
753
|
-
options.onError?.(e);
|
|
754
|
-
}
|
|
755
|
-
typewriter?.cancel();
|
|
756
|
-
isStreaming.value = false;
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
return {
|
|
760
|
-
isStreaming,
|
|
761
|
-
currentContent,
|
|
762
|
-
fetchStream,
|
|
763
|
-
stop,
|
|
764
|
-
// 暴露解析器供测试/自定义使用
|
|
765
|
-
parsers: {
|
|
766
|
-
openaiParser,
|
|
767
|
-
ernieParser,
|
|
768
|
-
qwenParser,
|
|
769
|
-
claudeParser,
|
|
770
|
-
geminiParser,
|
|
771
|
-
plainTextParser
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
function createTypewriter(onChar, charsPerFrame) {
|
|
777
|
-
const queue = [];
|
|
778
|
-
let rafId = null;
|
|
779
|
-
const schedule = () => {
|
|
780
|
-
rafId = requestAnimationFrame(() => {
|
|
781
|
-
rafId = null;
|
|
782
|
-
if (queue.length === 0) return;
|
|
783
|
-
const batch = queue.splice(0, charsPerFrame).join("");
|
|
784
|
-
onChar(batch);
|
|
785
|
-
if (queue.length > 0) schedule();
|
|
786
|
-
});
|
|
787
|
-
};
|
|
788
|
-
return {
|
|
789
|
-
push(text) {
|
|
790
|
-
queue.push(...text.split(""));
|
|
791
|
-
if (rafId === null) schedule();
|
|
792
|
-
},
|
|
793
|
-
flush() {
|
|
794
|
-
if (rafId !== null) {
|
|
795
|
-
cancelAnimationFrame(rafId);
|
|
796
|
-
rafId = null;
|
|
797
|
-
}
|
|
798
|
-
if (queue.length > 0) {
|
|
799
|
-
onChar(queue.splice(0).join(""));
|
|
800
|
-
}
|
|
801
|
-
},
|
|
802
|
-
cancel() {
|
|
803
|
-
if (rafId !== null) {
|
|
804
|
-
cancelAnimationFrame(rafId);
|
|
805
|
-
rafId = null;
|
|
806
|
-
}
|
|
807
|
-
queue.length = 0;
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
function useAiChat(options = {}) {
|
|
812
|
-
const {
|
|
813
|
-
idGenerator = () => Math.random().toString(36).substring(2, 9),
|
|
814
|
-
parser = plainTextParser,
|
|
815
|
-
typewriter: enableTypewriter = true,
|
|
816
|
-
charsPerFrame = 3,
|
|
817
|
-
systemPrompt
|
|
818
|
-
} = options;
|
|
819
|
-
const messages = vue.ref(options.initialMessages ?? []);
|
|
820
|
-
const isGenerating = vue.ref(false);
|
|
821
|
-
const isSending = vue.computed(() => isGenerating.value);
|
|
822
|
-
let abortController = null;
|
|
823
|
-
const stop = () => {
|
|
824
|
-
if (abortController && isGenerating.value) {
|
|
825
|
-
abortController.abort();
|
|
826
|
-
isGenerating.value = false;
|
|
827
|
-
const lastMsg = messages.value[messages.value.length - 1];
|
|
828
|
-
if (lastMsg?.role === "assistant" && lastMsg.status === "generating") {
|
|
829
|
-
lastMsg.status = "stopped";
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
|
-
const clear = () => {
|
|
834
|
-
stop();
|
|
835
|
-
messages.value = [];
|
|
836
|
-
};
|
|
837
|
-
const removeMessage = (id) => {
|
|
838
|
-
const idx = messages.value.findIndex((m) => m.id === id);
|
|
839
|
-
if (idx !== -1) messages.value.splice(idx, 1);
|
|
840
|
-
};
|
|
841
|
-
const updateMessage = (id, patch) => {
|
|
842
|
-
const msg = messages.value.find((m) => m.id === id);
|
|
843
|
-
if (msg) Object.assign(msg, patch);
|
|
844
|
-
};
|
|
845
|
-
const sendMessage = async (content) => {
|
|
846
|
-
if (!content.trim() || isGenerating.value) return;
|
|
847
|
-
messages.value.push({
|
|
848
|
-
id: idGenerator(),
|
|
849
|
-
role: "user",
|
|
850
|
-
content,
|
|
851
|
-
createAt: Date.now(),
|
|
852
|
-
status: "success"
|
|
853
|
-
});
|
|
854
|
-
if (!options.request) return;
|
|
855
|
-
const assId = idGenerator();
|
|
856
|
-
const assistantMsg = {
|
|
857
|
-
id: assId,
|
|
858
|
-
role: "assistant",
|
|
859
|
-
content: "",
|
|
860
|
-
createAt: Date.now(),
|
|
861
|
-
status: "loading"
|
|
862
|
-
};
|
|
863
|
-
messages.value.push(assistantMsg);
|
|
864
|
-
isGenerating.value = true;
|
|
865
|
-
abortController = new AbortController();
|
|
866
|
-
const history = [];
|
|
867
|
-
if (systemPrompt) {
|
|
868
|
-
history.push({
|
|
869
|
-
id: "system",
|
|
870
|
-
role: "system",
|
|
871
|
-
content: systemPrompt,
|
|
872
|
-
createAt: 0,
|
|
873
|
-
status: "success"
|
|
874
|
-
});
|
|
875
|
-
}
|
|
876
|
-
history.push(...messages.value.slice(0, -2));
|
|
877
|
-
try {
|
|
878
|
-
const response = await options.request(content, history, abortController.signal);
|
|
879
|
-
const targetMsg = messages.value.find((m) => m.id === assId);
|
|
880
|
-
targetMsg.status = "generating";
|
|
881
|
-
let typewriterInstance = null;
|
|
882
|
-
if (enableTypewriter && typeof requestAnimationFrame !== "undefined") {
|
|
883
|
-
typewriterInstance = createTypewriter((chars) => {
|
|
884
|
-
targetMsg.content += chars;
|
|
885
|
-
}, charsPerFrame);
|
|
886
|
-
}
|
|
887
|
-
const pushChunk = (text) => {
|
|
888
|
-
if (!text) return;
|
|
889
|
-
if (typewriterInstance) {
|
|
890
|
-
typewriterInstance.push(text);
|
|
891
|
-
} else {
|
|
892
|
-
targetMsg.content += text;
|
|
893
|
-
}
|
|
894
|
-
};
|
|
895
|
-
if (typeof response === "object" && response !== null && Symbol.asyncIterator in response) {
|
|
896
|
-
for await (const chunk of response) {
|
|
897
|
-
if (abortController.signal.aborted) break;
|
|
898
|
-
const parsed = parser(chunk);
|
|
899
|
-
if (parsed) pushChunk(parsed);
|
|
900
|
-
}
|
|
901
|
-
} else if (response instanceof Response && response.body) {
|
|
902
|
-
const reader = response.body.getReader();
|
|
903
|
-
const decoder = new TextDecoder("utf-8");
|
|
904
|
-
while (true) {
|
|
905
|
-
if (abortController.signal.aborted) {
|
|
906
|
-
reader.cancel();
|
|
907
|
-
break;
|
|
908
|
-
}
|
|
909
|
-
const { done, value } = await reader.read();
|
|
910
|
-
if (done) break;
|
|
911
|
-
const chunkStr = decoder.decode(value, { stream: true });
|
|
912
|
-
const parsed = parser(chunkStr);
|
|
913
|
-
if (parsed) pushChunk(parsed);
|
|
914
|
-
}
|
|
915
|
-
} else if (typeof response === "string") {
|
|
916
|
-
pushChunk(response);
|
|
917
|
-
}
|
|
918
|
-
if (typewriterInstance) {
|
|
919
|
-
typewriterInstance.flush();
|
|
920
|
-
}
|
|
921
|
-
if (!abortController.signal.aborted) {
|
|
922
|
-
targetMsg.status = "success";
|
|
923
|
-
options.onFinish?.(targetMsg);
|
|
924
|
-
}
|
|
925
|
-
} catch (e) {
|
|
926
|
-
if (e.name !== "AbortError") {
|
|
927
|
-
const targetMsg = messages.value.find((m) => m.id === assId);
|
|
928
|
-
if (targetMsg) targetMsg.status = "error";
|
|
929
|
-
options.onError?.(e);
|
|
930
|
-
}
|
|
931
|
-
} finally {
|
|
932
|
-
if (isGenerating.value) {
|
|
933
|
-
isGenerating.value = false;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
return {
|
|
938
|
-
/** 会话历史 */
|
|
939
|
-
messages,
|
|
940
|
-
/** 是否正在生成(等同 isSending,别名友好) */
|
|
941
|
-
isGenerating,
|
|
942
|
-
/** 同 isGenerating,语义别名 */
|
|
943
|
-
isSending,
|
|
944
|
-
/** 触发发送(自动处理流、打字机) */
|
|
945
|
-
sendMessage,
|
|
946
|
-
/** 停止/中断当前生成 */
|
|
947
|
-
stop,
|
|
948
|
-
/** 移除单条消息 */
|
|
949
|
-
removeMessage,
|
|
950
|
-
/** 修改单条消息内容 */
|
|
951
|
-
updateMessage,
|
|
952
|
-
/** 重置清空所有会话 */
|
|
953
|
-
clear
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
const localStorageAdapter = {
|
|
958
|
-
getItem: (key) => {
|
|
959
|
-
try {
|
|
960
|
-
return localStorage.getItem(key);
|
|
961
|
-
} catch {
|
|
962
|
-
return null;
|
|
963
|
-
}
|
|
964
|
-
},
|
|
965
|
-
setItem: (key, value) => {
|
|
966
|
-
try {
|
|
967
|
-
localStorage.setItem(key, value);
|
|
968
|
-
} catch {
|
|
969
|
-
}
|
|
970
|
-
},
|
|
971
|
-
removeItem: (key) => {
|
|
972
|
-
try {
|
|
973
|
-
localStorage.removeItem(key);
|
|
974
|
-
} catch {
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
};
|
|
978
|
-
class IndexedDBAdapter {
|
|
979
|
-
db = null;
|
|
980
|
-
dbName;
|
|
981
|
-
storeName = "ai_conversations";
|
|
982
|
-
ready;
|
|
983
|
-
constructor(dbName = "yh-ui-ai") {
|
|
984
|
-
this.dbName = dbName;
|
|
985
|
-
this.ready = this.init();
|
|
986
|
-
}
|
|
987
|
-
init() {
|
|
988
|
-
return new Promise((resolve, reject) => {
|
|
989
|
-
if (typeof indexedDB === "undefined") {
|
|
990
|
-
resolve();
|
|
991
|
-
return;
|
|
992
|
-
}
|
|
993
|
-
const req = indexedDB.open(this.dbName, 1);
|
|
994
|
-
req.onupgradeneeded = () => {
|
|
995
|
-
req.result.createObjectStore(this.storeName);
|
|
996
|
-
};
|
|
997
|
-
req.onsuccess = () => {
|
|
998
|
-
this.db = req.result;
|
|
999
|
-
resolve();
|
|
1000
|
-
};
|
|
1001
|
-
req.onerror = () => reject(req.error);
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
async getItem(key) {
|
|
1005
|
-
await this.ready;
|
|
1006
|
-
if (!this.db) return null;
|
|
1007
|
-
return new Promise((resolve) => {
|
|
1008
|
-
const tx = this.db.transaction(this.storeName, "readonly");
|
|
1009
|
-
const req = tx.objectStore(this.storeName).get(key);
|
|
1010
|
-
req.onsuccess = () => resolve(req.result ?? null);
|
|
1011
|
-
req.onerror = () => resolve(null);
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
async setItem(key, value) {
|
|
1015
|
-
await this.ready;
|
|
1016
|
-
if (!this.db) return;
|
|
1017
|
-
return new Promise((resolve) => {
|
|
1018
|
-
const tx = this.db.transaction(this.storeName, "readwrite");
|
|
1019
|
-
tx.objectStore(this.storeName).put(value, key);
|
|
1020
|
-
tx.oncomplete = () => resolve();
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
async removeItem(key) {
|
|
1024
|
-
await this.ready;
|
|
1025
|
-
if (!this.db) return;
|
|
1026
|
-
return new Promise((resolve) => {
|
|
1027
|
-
const tx = this.db.transaction(this.storeName, "readwrite");
|
|
1028
|
-
tx.objectStore(this.storeName).delete(key);
|
|
1029
|
-
tx.oncomplete = () => resolve();
|
|
1030
|
-
});
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
function getGroupLabel(updatedAt) {
|
|
1034
|
-
const now = Date.now();
|
|
1035
|
-
const diff = now - updatedAt;
|
|
1036
|
-
const oneDay = 864e5;
|
|
1037
|
-
if (diff < oneDay) return "today";
|
|
1038
|
-
if (diff < 7 * oneDay) return "last7Days";
|
|
1039
|
-
if (diff < 30 * oneDay) return "last30Days";
|
|
1040
|
-
return "earlier";
|
|
1041
|
-
}
|
|
1042
|
-
const GROUP_ORDER = ["today", "last7Days", "last30Days", "earlier"];
|
|
1043
|
-
function useAiConversations(options = {}) {
|
|
1044
|
-
const {
|
|
1045
|
-
idGenerator = () => Math.random().toString(36).substring(2, 9),
|
|
1046
|
-
storage = "localStorage",
|
|
1047
|
-
storageKey = "yh-ui-ai-conversations",
|
|
1048
|
-
pageSize = 20
|
|
1049
|
-
} = options;
|
|
1050
|
-
let adapter = null;
|
|
1051
|
-
if (storage === "localStorage") {
|
|
1052
|
-
adapter = localStorageAdapter;
|
|
1053
|
-
} else if (storage === "indexedDB") {
|
|
1054
|
-
adapter = new IndexedDBAdapter();
|
|
1055
|
-
} else if (storage && typeof storage === "object") {
|
|
1056
|
-
adapter = storage;
|
|
1057
|
-
}
|
|
1058
|
-
const conversations = vue.ref([]);
|
|
1059
|
-
const page = vue.ref(1);
|
|
1060
|
-
const isLoadingMore = vue.ref(false);
|
|
1061
|
-
const initPromise = (async () => {
|
|
1062
|
-
let stored = [];
|
|
1063
|
-
if (adapter) {
|
|
1064
|
-
try {
|
|
1065
|
-
const raw = await adapter.getItem(storageKey);
|
|
1066
|
-
if (raw) stored = JSON.parse(raw);
|
|
1067
|
-
} catch {
|
|
1068
|
-
stored = [];
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
const init = options.initialConversations ?? [];
|
|
1072
|
-
const merged = [...init];
|
|
1073
|
-
for (const s of stored) {
|
|
1074
|
-
if (!merged.find((c) => c.id === s.id)) {
|
|
1075
|
-
merged.push(s);
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
conversations.value = merged.sort((a, b) => {
|
|
1079
|
-
if (a.pinned !== b.pinned) return a.pinned ? -1 : 1;
|
|
1080
|
-
return b.updatedAt - a.updatedAt;
|
|
1081
|
-
});
|
|
1082
|
-
})();
|
|
1083
|
-
const persist = async () => {
|
|
1084
|
-
if (!adapter) return;
|
|
1085
|
-
try {
|
|
1086
|
-
await adapter.setItem(storageKey, JSON.stringify(conversations.value));
|
|
1087
|
-
} catch {
|
|
1088
|
-
}
|
|
1089
|
-
};
|
|
1090
|
-
const groupedConversations = vue.computed(() => {
|
|
1091
|
-
const groups = {
|
|
1092
|
-
today: [],
|
|
1093
|
-
last7Days: [],
|
|
1094
|
-
last30Days: [],
|
|
1095
|
-
earlier: []
|
|
1096
|
-
};
|
|
1097
|
-
for (const c of conversations.value) {
|
|
1098
|
-
if (c.pinned) continue;
|
|
1099
|
-
const key = getGroupLabel(c.updatedAt);
|
|
1100
|
-
groups[key].push(c);
|
|
1101
|
-
}
|
|
1102
|
-
const result = [];
|
|
1103
|
-
const pinned = conversations.value.filter((c) => c.pinned);
|
|
1104
|
-
if (pinned.length > 0) {
|
|
1105
|
-
result.push({ label: "pinned", items: pinned });
|
|
1106
|
-
}
|
|
1107
|
-
for (const key of GROUP_ORDER) {
|
|
1108
|
-
if (groups[key].length > 0) {
|
|
1109
|
-
result.push({ label: key, items: groups[key] });
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
return result;
|
|
1113
|
-
});
|
|
1114
|
-
const pagedConversations = vue.computed(() => {
|
|
1115
|
-
return conversations.value.slice(0, page.value * pageSize);
|
|
1116
|
-
});
|
|
1117
|
-
const hasMore = vue.computed(() => {
|
|
1118
|
-
return pagedConversations.value.length < conversations.value.length;
|
|
1119
81
|
});
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
id: idGenerator(),
|
|
1130
|
-
title,
|
|
1131
|
-
updatedAt: Date.now(),
|
|
1132
|
-
meta
|
|
1133
|
-
};
|
|
1134
|
-
conversations.value.unshift(newConv);
|
|
1135
|
-
await persist();
|
|
1136
|
-
return newConv;
|
|
1137
|
-
};
|
|
1138
|
-
const removeConversation = async (id) => {
|
|
1139
|
-
const idx = conversations.value.findIndex((c) => c.id === id);
|
|
1140
|
-
if (idx !== -1) {
|
|
1141
|
-
conversations.value.splice(idx, 1);
|
|
1142
|
-
await persist();
|
|
1143
|
-
}
|
|
1144
|
-
};
|
|
1145
|
-
const updateConversation = async (id, updates) => {
|
|
1146
|
-
const idx = conversations.value.findIndex((c) => c.id === id);
|
|
1147
|
-
if (idx !== -1) {
|
|
1148
|
-
conversations.value[idx] = {
|
|
1149
|
-
...conversations.value[idx],
|
|
1150
|
-
...updates,
|
|
1151
|
-
updatedAt: Date.now()
|
|
1152
|
-
};
|
|
1153
|
-
await persist();
|
|
1154
|
-
}
|
|
1155
|
-
};
|
|
1156
|
-
const pinConversation = async (id, pinned = true) => {
|
|
1157
|
-
await updateConversation(id, { pinned });
|
|
1158
|
-
conversations.value.sort((a, b) => {
|
|
1159
|
-
if (a.pinned !== b.pinned) return a.pinned ? -1 : 1;
|
|
1160
|
-
return b.updatedAt - a.updatedAt;
|
|
1161
|
-
});
|
|
1162
|
-
await persist();
|
|
1163
|
-
};
|
|
1164
|
-
const clear = async () => {
|
|
1165
|
-
conversations.value = [];
|
|
1166
|
-
if (adapter) {
|
|
1167
|
-
await adapter.removeItem(storageKey);
|
|
1168
|
-
}
|
|
1169
|
-
};
|
|
1170
|
-
return {
|
|
1171
|
-
/** 完整会话列表 */
|
|
1172
|
-
conversations,
|
|
1173
|
-
/** 按时间分组后的列表(置顶 / 今天 / 最近 7 天 / 更早) */
|
|
1174
|
-
groupedConversations,
|
|
1175
|
-
/** 分页后的列表 */
|
|
1176
|
-
pagedConversations,
|
|
1177
|
-
/** 是否还有更多数据 */
|
|
1178
|
-
hasMore,
|
|
1179
|
-
/** 加载更多 */
|
|
1180
|
-
loadMore,
|
|
1181
|
-
/** 加载更多状态 */
|
|
1182
|
-
isLoadingMore,
|
|
1183
|
-
/** 等待初始化完成(SSR 场景使用) */
|
|
1184
|
-
ready: initPromise,
|
|
1185
|
-
/** 新建会话 */
|
|
1186
|
-
createConversation,
|
|
1187
|
-
/** 删除会话 */
|
|
1188
|
-
removeConversation,
|
|
1189
|
-
/** 更新会话属性 */
|
|
1190
|
-
updateConversation,
|
|
1191
|
-
/** 置顶/取消置顶 */
|
|
1192
|
-
pinConversation,
|
|
1193
|
-
/** 清空全部 */
|
|
1194
|
-
clear
|
|
1195
|
-
};
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
|
-
function useAiRequest(options) {
|
|
1199
|
-
const loading = vue.ref(false);
|
|
1200
|
-
const data = vue.ref("");
|
|
1201
|
-
const error = vue.ref(null);
|
|
1202
|
-
const send = async (query, ...args) => {
|
|
1203
|
-
loading.value = true;
|
|
1204
|
-
error.value = null;
|
|
1205
|
-
try {
|
|
1206
|
-
const result = await options.request(query, ...args);
|
|
1207
|
-
data.value = result;
|
|
1208
|
-
options.onSuccess?.(result);
|
|
1209
|
-
return result;
|
|
1210
|
-
} catch (e) {
|
|
1211
|
-
const err = e instanceof Error ? e : new Error(String(e));
|
|
1212
|
-
error.value = err;
|
|
1213
|
-
options.onError?.(err);
|
|
1214
|
-
throw err;
|
|
1215
|
-
} finally {
|
|
1216
|
-
loading.value = false;
|
|
1217
|
-
}
|
|
1218
|
-
};
|
|
1219
|
-
return {
|
|
1220
|
-
loading,
|
|
1221
|
-
data,
|
|
1222
|
-
error,
|
|
1223
|
-
send
|
|
1224
|
-
};
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
function useAiVoice(options = {}) {
|
|
1228
|
-
const {
|
|
1229
|
-
language = "zh-CN",
|
|
1230
|
-
interimResults = true,
|
|
1231
|
-
continuous = false,
|
|
1232
|
-
vad = true,
|
|
1233
|
-
vadThreshold = 2e3,
|
|
1234
|
-
volumeThreshold = 0.05,
|
|
1235
|
-
waveCount = 20,
|
|
1236
|
-
useSTT = true
|
|
1237
|
-
} = options;
|
|
1238
|
-
const isRecording = vue.ref(false);
|
|
1239
|
-
const transcript = vue.ref("");
|
|
1240
|
-
const interimTranscript = vue.ref("");
|
|
1241
|
-
const volume = vue.ref(0);
|
|
1242
|
-
const amplitudes = vue.ref(new Array(waveCount).fill(5));
|
|
1243
|
-
const audioBlob = vue.ref(null);
|
|
1244
|
-
const recognition = vue.shallowRef(null);
|
|
1245
|
-
const audioContext = vue.shallowRef(null);
|
|
1246
|
-
const analyser = vue.shallowRef(null);
|
|
1247
|
-
const stream = vue.shallowRef(null);
|
|
1248
|
-
const mediaRecorder = vue.shallowRef(null);
|
|
1249
|
-
let chunks = [];
|
|
1250
|
-
let animationId = null;
|
|
1251
|
-
let silenceStart = null;
|
|
1252
|
-
const _window = typeof window !== "undefined" ? window : null;
|
|
1253
|
-
const SpeechRecognition = _window?.SpeechRecognition || _window?.webkitSpeechRecognition;
|
|
1254
|
-
const sttSupported = !!SpeechRecognition;
|
|
1255
|
-
const initMediaRecorder = (mediaStream) => {
|
|
1256
|
-
chunks = [];
|
|
1257
|
-
const recorder = new MediaRecorder(mediaStream);
|
|
1258
|
-
recorder.ondataavailable = (e) => {
|
|
1259
|
-
if (e.data.size > 0) chunks.push(e.data);
|
|
1260
|
-
};
|
|
1261
|
-
recorder.onstop = () => {
|
|
1262
|
-
const blob = chunks.length > 0 ? new Blob(chunks, { type: "audio/webm" }) : null;
|
|
1263
|
-
audioBlob.value = blob;
|
|
1264
|
-
if (!isRecording.value) {
|
|
1265
|
-
options.onStop?.(transcript.value, blob);
|
|
1266
|
-
}
|
|
1267
|
-
};
|
|
1268
|
-
mediaRecorder.value = recorder;
|
|
1269
|
-
};
|
|
1270
|
-
const initRecognition = () => {
|
|
1271
|
-
if (!sttSupported || !useSTT) return;
|
|
1272
|
-
const recognitionInstance = new SpeechRecognition();
|
|
1273
|
-
recognitionInstance.lang = language;
|
|
1274
|
-
recognitionInstance.interimResults = interimResults;
|
|
1275
|
-
recognitionInstance.continuous = continuous;
|
|
1276
|
-
recognitionInstance.onresult = (event) => {
|
|
1277
|
-
let currentInterim = "";
|
|
1278
|
-
for (let i = event.resultIndex; i < event.results.length; ++i) {
|
|
1279
|
-
if (event.results[i].isFinal) {
|
|
1280
|
-
transcript.value += event.results[i][0].transcript;
|
|
1281
|
-
options.onResult?.(transcript.value);
|
|
1282
|
-
} else {
|
|
1283
|
-
currentInterim += event.results[i][0].transcript;
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
interimTranscript.value = currentInterim;
|
|
1287
|
-
options.onPartialResult?.(currentInterim);
|
|
1288
|
-
};
|
|
1289
|
-
recognitionInstance.onerror = (event) => {
|
|
1290
|
-
if (event.error !== "no-speech" && event.error !== "aborted") {
|
|
1291
|
-
options.onError?.(event);
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1294
|
-
recognition.value = recognitionInstance;
|
|
1295
|
-
};
|
|
1296
|
-
const initAudioAnalyzer = async (mediaStream) => {
|
|
1297
|
-
try {
|
|
1298
|
-
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
1299
|
-
audioContext.value = new AudioCtx();
|
|
1300
|
-
if (audioContext.value.state === "suspended") {
|
|
1301
|
-
await audioContext.value.resume();
|
|
1302
|
-
}
|
|
1303
|
-
analyser.value = audioContext.value.createAnalyser();
|
|
1304
|
-
analyser.value.fftSize = 256;
|
|
1305
|
-
const source = audioContext.value.createMediaStreamSource(mediaStream);
|
|
1306
|
-
source.connect(analyser.value);
|
|
1307
|
-
const bufferLength = analyser.value.frequencyBinCount;
|
|
1308
|
-
const dataArray = new Uint8Array(bufferLength);
|
|
1309
|
-
const process = () => {
|
|
1310
|
-
if (!isRecording.value) {
|
|
1311
|
-
amplitudes.value = new Array(waveCount).fill(5);
|
|
1312
|
-
volume.value = 0;
|
|
1313
|
-
return;
|
|
1314
|
-
}
|
|
1315
|
-
animationId = requestAnimationFrame(process);
|
|
1316
|
-
analyser.value.getByteFrequencyData(dataArray);
|
|
1317
|
-
let total = 0;
|
|
1318
|
-
for (let i = 0; i < bufferLength; i++) total += dataArray[i];
|
|
1319
|
-
const avg = total / bufferLength;
|
|
1320
|
-
volume.value = Math.min(100, avg / 128 * 100);
|
|
1321
|
-
const step = Math.floor(bufferLength / waveCount);
|
|
1322
|
-
const newAmps = [];
|
|
1323
|
-
for (let i = 0; i < waveCount; i++) {
|
|
1324
|
-
const val = dataArray[i * step];
|
|
1325
|
-
newAmps.push(6 + val / 255 * 34);
|
|
1326
|
-
}
|
|
1327
|
-
amplitudes.value = newAmps;
|
|
1328
|
-
if (vad) {
|
|
1329
|
-
const normalizedVol = avg / 255;
|
|
1330
|
-
if (normalizedVol < volumeThreshold) {
|
|
1331
|
-
if (silenceStart === null) silenceStart = Date.now();
|
|
1332
|
-
else if (Date.now() - silenceStart > vadThreshold) {
|
|
1333
|
-
stop();
|
|
1334
|
-
}
|
|
1335
|
-
} else {
|
|
1336
|
-
silenceStart = null;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
};
|
|
1340
|
-
process();
|
|
1341
|
-
} catch (err) {
|
|
1342
|
-
options.onError?.(err);
|
|
1343
|
-
}
|
|
1344
|
-
};
|
|
1345
|
-
const start = async () => {
|
|
1346
|
-
if (stream.value) return;
|
|
1347
|
-
try {
|
|
1348
|
-
transcript.value = "";
|
|
1349
|
-
interimTranscript.value = "";
|
|
1350
|
-
audioBlob.value = null;
|
|
1351
|
-
silenceStart = null;
|
|
1352
|
-
stream.value = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1353
|
-
isRecording.value = true;
|
|
1354
|
-
initMediaRecorder(stream.value);
|
|
1355
|
-
initRecognition();
|
|
1356
|
-
await initAudioAnalyzer(stream.value);
|
|
1357
|
-
mediaRecorder.value?.start(1e3);
|
|
1358
|
-
recognition.value?.start();
|
|
1359
|
-
options.onStart?.();
|
|
1360
|
-
} catch (err) {
|
|
1361
|
-
isRecording.value = false;
|
|
1362
|
-
if (stream.value) {
|
|
1363
|
-
stream.value.getTracks().forEach((t) => t.stop());
|
|
1364
|
-
stream.value = null;
|
|
1365
|
-
}
|
|
1366
|
-
console.error("[yh-ui/hooks] useAiVoice start failed:", err);
|
|
1367
|
-
options.onError?.(err);
|
|
82
|
+
});
|
|
83
|
+
var _useVirtualScroll = require("./use-virtual-scroll/index.cjs");
|
|
84
|
+
Object.keys(_useVirtualScroll).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _useVirtualScroll[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _useVirtualScroll[key];
|
|
1368
91
|
}
|
|
1369
|
-
};
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
if (recognition.value) {
|
|
1380
|
-
try {
|
|
1381
|
-
recognition.value.stop();
|
|
1382
|
-
} catch {
|
|
1383
|
-
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
var _useCache = require("./use-cache/index.cjs");
|
|
95
|
+
Object.keys(_useCache).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _useCache[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return _useCache[key];
|
|
1384
102
|
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
var _useEventListener = require("./use-event-listener/index.cjs");
|
|
106
|
+
Object.keys(_useEventListener).forEach(function (key) {
|
|
107
|
+
if (key === "default" || key === "__esModule") return;
|
|
108
|
+
if (key in exports && exports[key] === _useEventListener[key]) return;
|
|
109
|
+
Object.defineProperty(exports, key, {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return _useEventListener[key];
|
|
1388
113
|
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
var _useScrollLock = require("./use-scroll-lock/index.cjs");
|
|
117
|
+
Object.keys(_useScrollLock).forEach(function (key) {
|
|
118
|
+
if (key === "default" || key === "__esModule") return;
|
|
119
|
+
if (key in exports && exports[key] === _useScrollLock[key]) return;
|
|
120
|
+
Object.defineProperty(exports, key, {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () {
|
|
123
|
+
return _useScrollLock[key];
|
|
1399
124
|
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
var _useClickOutside = require("./use-click-outside/index.cjs");
|
|
128
|
+
Object.keys(_useClickOutside).forEach(function (key) {
|
|
129
|
+
if (key === "default" || key === "__esModule") return;
|
|
130
|
+
if (key in exports && exports[key] === _useClickOutside[key]) return;
|
|
131
|
+
Object.defineProperty(exports, key, {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function () {
|
|
134
|
+
return _useClickOutside[key];
|
|
1405
135
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
var _useConfig = require("./use-config/index.cjs");
|
|
139
|
+
Object.keys(_useConfig).forEach(function (key) {
|
|
140
|
+
if (key === "default" || key === "__esModule") return;
|
|
141
|
+
if (key in exports && exports[key] === _useConfig[key]) return;
|
|
142
|
+
Object.defineProperty(exports, key, {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function () {
|
|
145
|
+
return _useConfig[key];
|
|
1409
146
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
var _useAi = require("./use-ai/index.cjs");
|
|
150
|
+
Object.keys(_useAi).forEach(function (key) {
|
|
151
|
+
if (key === "default" || key === "__esModule") return;
|
|
152
|
+
if (key in exports && exports[key] === _useAi[key]) return;
|
|
153
|
+
Object.defineProperty(exports, key, {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function () {
|
|
156
|
+
return _useAi[key];
|
|
1416
157
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
var _storage = require("./storage/index.cjs");
|
|
161
|
+
Object.keys(_storage).forEach(function (key) {
|
|
162
|
+
if (key === "default" || key === "__esModule") return;
|
|
163
|
+
if (key in exports && exports[key] === _storage[key]) return;
|
|
164
|
+
Object.defineProperty(exports, key, {
|
|
165
|
+
enumerable: true,
|
|
166
|
+
get: function () {
|
|
167
|
+
return _storage[key];
|
|
1421
168
|
}
|
|
1422
|
-
amplitudes.value = new Array(waveCount).fill(5);
|
|
1423
|
-
volume.value = 0;
|
|
1424
|
-
};
|
|
1425
|
-
vue.onUnmounted(() => {
|
|
1426
|
-
if (isRecording.value) stop();
|
|
1427
|
-
else cleanup();
|
|
1428
169
|
});
|
|
1429
|
-
|
|
1430
|
-
isRecording,
|
|
1431
|
-
transcript,
|
|
1432
|
-
interimTranscript,
|
|
1433
|
-
amplitudes,
|
|
1434
|
-
volume,
|
|
1435
|
-
audioBlob,
|
|
1436
|
-
start,
|
|
1437
|
-
stop,
|
|
1438
|
-
cancel,
|
|
1439
|
-
sttSupported
|
|
1440
|
-
};
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
exports.FormContextKey = FormContextKey;
|
|
1444
|
-
exports.FormItemContextKey = FormItemContextKey;
|
|
1445
|
-
exports.IndexedDBAdapter = IndexedDBAdapter;
|
|
1446
|
-
exports.claudeParser = claudeParser;
|
|
1447
|
-
exports.configProviderContextKey = configProviderContextKey;
|
|
1448
|
-
exports.createZIndexCounter = createZIndexCounter;
|
|
1449
|
-
exports.defaultNamespace = defaultNamespace;
|
|
1450
|
-
exports.ernieParser = ernieParser;
|
|
1451
|
-
exports.geminiParser = geminiParser;
|
|
1452
|
-
exports.getDayjsLocale = getDayjsLocale;
|
|
1453
|
-
exports.getNextZIndex = getNextZIndex;
|
|
1454
|
-
exports.idInjectionKey = idInjectionKey;
|
|
1455
|
-
exports.localStorageAdapter = localStorageAdapter;
|
|
1456
|
-
exports.namespaceContextKey = namespaceContextKey;
|
|
1457
|
-
exports.openaiParser = openaiParser;
|
|
1458
|
-
exports.plainTextParser = plainTextParser;
|
|
1459
|
-
exports.qwenParser = qwenParser;
|
|
1460
|
-
exports.resetZIndex = resetZIndex;
|
|
1461
|
-
exports.setDayjsLocale = setDayjsLocale;
|
|
1462
|
-
exports.setDayjsLocaleSync = setDayjsLocaleSync;
|
|
1463
|
-
exports.updateDayjsMonths = updateDayjsMonths;
|
|
1464
|
-
exports.useAiChat = useAiChat;
|
|
1465
|
-
exports.useAiConversations = useAiConversations;
|
|
1466
|
-
exports.useAiRequest = useAiRequest;
|
|
1467
|
-
exports.useAiStream = useAiStream;
|
|
1468
|
-
exports.useAiVoice = useAiVoice;
|
|
1469
|
-
exports.useCache = useCache;
|
|
1470
|
-
exports.useClickOutside = useClickOutside;
|
|
1471
|
-
exports.useConfig = useConfig;
|
|
1472
|
-
exports.useEventListener = useEventListener;
|
|
1473
|
-
exports.useFormItem = useFormItem;
|
|
1474
|
-
exports.useGlobalNamespace = useGlobalNamespace;
|
|
1475
|
-
exports.useId = useId;
|
|
1476
|
-
exports.useIdInjection = useIdInjection;
|
|
1477
|
-
exports.useLocale = useLocale;
|
|
1478
|
-
exports.useNamespace = useNamespace;
|
|
1479
|
-
exports.useScrollLock = useScrollLock;
|
|
1480
|
-
exports.useVirtualScroll = useVirtualScroll;
|
|
1481
|
-
exports.useZIndex = useZIndex;
|
|
1482
|
-
exports.zIndexContextKey = zIndexContextKey;
|
|
1483
|
-
exports.zIndexCounterKey = zIndexCounterKey;
|
|
170
|
+
});
|