xiaoao-chat 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Your Name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # xiaoao-chat
2
+
3
+ A Vue 3 chat component library with popup chat functionality.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install xiaoao-chat
9
+ # or
10
+ yarn add xiaoao-chat
11
+ # or
12
+ pnpm add xiaoao-chat
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Basic Usage
18
+
19
+ ```javascript
20
+ import { createApp } from 'vue'
21
+ import App from './App.vue'
22
+
23
+ // Import the component library
24
+ import { ChatPopup, FloatBall } from 'xiaoao-chat'
25
+ import 'xiaoao-chat/style.css'
26
+
27
+ const app = createApp(App)
28
+
29
+ // Register components globally
30
+ app.component('ChatPopup', ChatPopup)
31
+ app.component('FloatBall', FloatBall)
32
+
33
+ app.mount('#app')
34
+ ```
35
+
36
+ ### Component List
37
+
38
+ - `ChatInput` - Chat input component
39
+ - `ChatIntroduce` - Chat introduction page
40
+ - `ChatMessage` - Chat message display component
41
+ - `ChatPopup` - Main chat popup container
42
+ - `FloatBall` - Floating chat button
43
+
44
+ ### Using with Composition API
45
+
46
+ ```vue
47
+ <template>
48
+ <div>
49
+ <FloatBall @click="showChat = true" />
50
+ <ChatPopup v-if="showChat" @close="showChat = false" />
51
+ </div>
52
+ </template>
53
+
54
+ <script setup>
55
+ import { ref } from 'vue'
56
+ import { ChatPopup, FloatBall } from 'xiaoao-chat'
57
+
58
+ const showChat = ref(false)
59
+ </script>
60
+ ```
61
+
62
+ ## Dependencies
63
+
64
+ This library depends on:
65
+ - Vue 3 (^3.5.29)
66
+ - Element Plus (^2.13.3)
67
+ - Other dependencies are included in the package
68
+
69
+ ## Development
70
+
71
+ ### Recommended IDE Setup
72
+
73
+ [VS Code](https://code.visualstudio.com/) + [Vue (Official)](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
74
+
75
+ ### Project Setup
76
+
77
+ ```sh
78
+ pnpm install
79
+ ```
80
+
81
+ ### Compile and Hot-Reload for Development
82
+
83
+ ```sh
84
+ pnpm dev
85
+ ```
86
+
87
+ ### Build for Production (as library)
88
+
89
+ ```sh
90
+ pnpm build
91
+ ```
92
+
93
+ This will generate the following files in the `dist` directory:
94
+ - `xiaoao-chat.js` - ES module bundle
95
+ - `xiaoao-chat.umd.cjs` - UMD bundle
96
+ - `style.css` - Compiled styles
97
+
98
+ ## License
99
+
100
+ MIT
Binary file
@@ -0,0 +1,96 @@
1
+ /*
2
+ pcm编码器+编码引擎
3
+ https://github.com/xiangyuecn/Recorder
4
+
5
+ 编码原理:本编码器输出的pcm格式数据其实就是Recorder中的buffers原始数据(经过了重新采样),16位时为LE小端模式(Little Endian),并未经过任何编码处理
6
+
7
+ 编码的代码和wav.js区别不大,pcm加上一个44字节wav头即成wav文件;所以要播放pcm就很简单了,直接转成wav文件来播放,已提供转换函数 Recorder.pcm2wav
8
+ */
9
+ (function(){
10
+ "use strict";
11
+
12
+ Recorder.prototype.enc_pcm={
13
+ stable:true
14
+ ,testmsg:"pcm为未封装的原始音频数据,pcm数据文件无法直接播放;支持位数8位、16位(填在比特率里面),采样率取值无限制"
15
+ };
16
+ Recorder.prototype.pcm=function(res,True,False){
17
+ var This=this,set=This.set
18
+ ,size=res.length
19
+ ,bitRate=set.bitRate==8?8:16;
20
+
21
+ var buffer=new ArrayBuffer(size*(bitRate/8));
22
+ var data=new DataView(buffer);
23
+ var offset=0;
24
+
25
+ // 写入采样数据
26
+ if(bitRate==8) {
27
+ for(var i=0;i<size;i++,offset++) {
28
+ //16转8据说是雷霄骅的 https://blog.csdn.net/sevennight1989/article/details/85376149 细节比blqw的按比例的算法清晰点,虽然都有明显杂音
29
+ var val=(res[i]>>8)+128;
30
+ data.setInt8(offset,val,true);
31
+ };
32
+ }else{
33
+ for (var i=0;i<size;i++,offset+=2){
34
+ data.setInt16(offset,res[i],true);
35
+ };
36
+ };
37
+
38
+
39
+ True(new Blob([data.buffer],{type:"audio/pcm"}));
40
+ };
41
+
42
+
43
+
44
+
45
+
46
+ /**pcm直接转码成wav,可以直接用来播放;需同时引入wav.js
47
+ data: {
48
+ sampleRate:16000 pcm的采样率
49
+ bitRate:16 pcm的位数 取值:8 或 16
50
+ blob:blob对象
51
+ }
52
+ data如果直接提供的blob将默认使用16位16khz的配置,仅用于测试
53
+ True(wavBlob,duration)
54
+ False(msg)
55
+ **/
56
+ Recorder.pcm2wav=function(data,True,False){
57
+ if(data.slice && data.type!=null){//Blob 测试用
58
+ data={blob:data};
59
+ };
60
+ var sampleRate=data.sampleRate||16000,bitRate=data.bitRate||16;
61
+ if(!data.sampleRate || !data.bitRate){
62
+ console.warn("pcm2wav必须提供sampleRate和bitRate");
63
+ };
64
+ if(!Recorder.prototype.wav){
65
+ False("pcm2wav必须先加载wav编码器wav.js");
66
+ return;
67
+ };
68
+
69
+ var reader=new FileReader();
70
+ reader.onloadend=function(){
71
+ var pcm;
72
+ if(bitRate==8){
73
+ //8位转成16位
74
+ var u8arr=new Uint8Array(reader.result);
75
+ pcm=new Int16Array(u8arr.length);
76
+ for(var j=0;j<u8arr.length;j++){
77
+ pcm[j]=(u8arr[j]-128)<<8;
78
+ };
79
+ }else{
80
+ pcm=new Int16Array(reader.result);
81
+ };
82
+
83
+ Recorder({
84
+ type:"wav"
85
+ ,sampleRate:sampleRate
86
+ ,bitRate:bitRate
87
+ }).mock(pcm,sampleRate).stop(function(wavBlob,duration){
88
+ True(wavBlob,duration);
89
+ },False);
90
+ };
91
+ reader.readAsArrayBuffer(data.blob);
92
+ };
93
+
94
+
95
+
96
+ })();