@arcai/chatbot 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ IT License
2
+
3
+ Copyright (c) 2024 ArcAi
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,128 @@
1
+ # @arcai/chatbot
2
+
3
+ A customizable chatbot widget for websites with beautiful animations and modern design.
4
+
5
+ ## Features
6
+
7
+ - 🎨 Fully customizable appearance
8
+ - 🌊 Smooth animations
9
+ - 💭 Thought bubbles
10
+ - 🎯 Multiple positioning options
11
+ - 🌓 Glassmorphism effects
12
+ - 📱 Responsive design
13
+ - 🔌 Easy integration
14
+
15
+ ## Installation
16
+
17
+ ### NPM
18
+
19
+ ```bash
20
+ npm install @arcai/chatbot
21
+ ```
22
+
23
+ ### CDN
24
+
25
+ Add the script directly to your HTML:
26
+
27
+ ```html
28
+ <!-- Using jsDelivr -->
29
+ <script src="https://cdn.jsdelivr.net/npm/@arcai/chatbot/dist/chatbot.min.js"></script>
30
+
31
+ <!-- OR using UNPKG -->
32
+ <script src="https://unpkg.com/@arcai/chatbot/dist/chatbot.min.js"></script>
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ### With NPM
38
+
39
+ ```javascript
40
+ import { Chatbot } from '@arcai/chatbot';
41
+
42
+ const chatbot = new Chatbot({
43
+ apiKey: 'your-api-key',
44
+ position: 'bottom-right',
45
+ primaryColor: '#2563eb',
46
+ floatAnimation: 'float-up-down',
47
+ showThoughts: true,
48
+ customThoughts: [
49
+ "Need help?",
50
+ "Have any questions?",
51
+ "I'm here to assist you!"
52
+ ],
53
+ onMessage: async (message) => {
54
+ // Handle incoming messages
55
+ return "Thanks for your message!";
56
+ }
57
+ });
58
+ ```
59
+
60
+ ### With CDN
61
+
62
+ ```html
63
+ <script src="https://cdn.jsdelivr.net/npm/@arcai/chatbot/dist/chatbot.min.js"></script>
64
+ <script>
65
+ const chatbot = new Arcai.Chatbot({
66
+ apiKey: 'your-api-key',
67
+ position: 'bottom-right',
68
+ primaryColor: '#2563eb',
69
+ floatAnimation: 'float-up-down',
70
+ showThoughts: true,
71
+ customThoughts: [
72
+ "Need help?",
73
+ "Have any questions?",
74
+ "I'm here to assist you!"
75
+ ],
76
+ onMessage: async (message) => {
77
+ return "Thanks for your message!";
78
+ }
79
+ });
80
+ </script>
81
+ ```
82
+ ## Configuration Options
83
+
84
+ | Option | Type | Default | Description |
85
+ |--------|------|---------|-------------|
86
+ | `apiKey` | string | - | Your API key (required) |
87
+ | `position` | string | 'bottom-right' | Widget position ('bottom-right', 'bottom-left', 'top-right', 'top-left') |
88
+ | `primaryColor` | string | '#2563eb' | Primary color for the widget |
89
+ | `textColor` | string | '#1e293b' | Text color |
90
+ | `bgImage` | string | - | Background image URL |
91
+ | `opacity` | number | 100 | Background opacity (0-100) |
92
+ | `glassmorphism` | boolean | false | Enable glassmorphism effect |
93
+ | `floatAnimation` | string | 'float-up-down' | Animation style for the launcher |
94
+ | `showAvatar` | boolean | true | Show bot avatar in messages |
95
+ | `showThoughts` | boolean | true | Show thought bubbles |
96
+ | `thoughtInterval` | number | 8 | Interval between thoughts (seconds) |
97
+ | `customThoughts` | string[] | [...] | Custom thought messages |
98
+ | `onMessage` | function | - | Message handler function |
99
+
100
+ ## Methods
101
+
102
+ - `open()`: Open the chat widget
103
+ - `close()`: Close the chat widget
104
+ - `toggle()`: Toggle the chat widget
105
+ - `destroy()`: Remove the widget from the page
106
+
107
+ ## Events
108
+
109
+ The chatbot extends EventEmitter and emits the following events:
110
+
111
+ - `message`: When a message is sent or received
112
+ - `open`: When the widget is opened
113
+ - `close`: When the widget is closed
114
+
115
+ ## Styling
116
+
117
+ The widget uses CSS variables for easy customization:
118
+
119
+ ```css
120
+ :root {
121
+ --arcai-primary-color: #2563eb;
122
+ --arcai-primary-color-dark: #1d4ed8;
123
+ }
124
+ ```
125
+
126
+ ## License
127
+
128
+ MIT
@@ -0,0 +1,455 @@
1
+ "use strict";var arcai=(()=>{var N=Object.create;var x=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var H=(o,a)=>()=>(a||o((a={exports:{}}).exports,a),a.exports),O=(o,a)=>{for(var t in a)x(o,t,{get:a[t],enumerable:!0})},C=(o,a,t,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of Y(a))!j.call(o,i)&&i!==t&&x(o,i,{get:()=>a[i],enumerable:!(e=I(a,i))||e.enumerable});return o};var D=(o,a,t)=>(t=o!=null?N(A(o)):{},C(a||!o||!o.__esModule?x(t,"default",{value:o,enumerable:!0}):t,o)),z=o=>C(x({},"__esModule",{value:!0}),o);var M=H((q,y)=>{"use strict";var $=Object.prototype.hasOwnProperty,h="~";function f(){}Object.create&&(f.prototype=Object.create(null),new f().__proto__||(h=!1));function F(o,a,t){this.fn=o,this.context=a,this.once=t||!1}function k(o,a,t,e,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var n=new F(t,e||o,i),s=h?h+a:a;return o._events[s]?o._events[s].fn?o._events[s]=[o._events[s],n]:o._events[s].push(n):(o._events[s]=n,o._eventsCount++),o}function b(o,a){--o._eventsCount===0?o._events=new f:delete o._events[a]}function l(){this._events=new f,this._eventsCount=0}l.prototype.eventNames=function(){var a=[],t,e;if(this._eventsCount===0)return a;for(e in t=this._events)$.call(t,e)&&a.push(h?e.slice(1):e);return Object.getOwnPropertySymbols?a.concat(Object.getOwnPropertySymbols(t)):a};l.prototype.listeners=function(a){var t=h?h+a:a,e=this._events[t];if(!e)return[];if(e.fn)return[e.fn];for(var i=0,n=e.length,s=new Array(n);i<n;i++)s[i]=e[i].fn;return s};l.prototype.listenerCount=function(a){var t=h?h+a:a,e=this._events[t];return e?e.fn?1:e.length:0};l.prototype.emit=function(a,t,e,i,n,s){var p=h?h+a:a;if(!this._events[p])return!1;var r=this._events[p],d=arguments.length,u,c;if(r.fn){switch(r.once&&this.removeListener(a,r.fn,void 0,!0),d){case 1:return r.fn.call(r.context),!0;case 2:return r.fn.call(r.context,t),!0;case 3:return r.fn.call(r.context,t,e),!0;case 4:return r.fn.call(r.context,t,e,i),!0;case 5:return r.fn.call(r.context,t,e,i,n),!0;case 6:return r.fn.call(r.context,t,e,i,n,s),!0}for(c=1,u=new Array(d-1);c<d;c++)u[c-1]=arguments[c];r.fn.apply(r.context,u)}else{var m=r.length,g;for(c=0;c<m;c++)switch(r[c].once&&this.removeListener(a,r[c].fn,void 0,!0),d){case 1:r[c].fn.call(r[c].context);break;case 2:r[c].fn.call(r[c].context,t);break;case 3:r[c].fn.call(r[c].context,t,e);break;case 4:r[c].fn.call(r[c].context,t,e,i);break;default:if(!u)for(g=1,u=new Array(d-1);g<d;g++)u[g-1]=arguments[g];r[c].fn.apply(r[c].context,u)}}return!0};l.prototype.on=function(a,t,e){return k(this,a,t,e,!1)};l.prototype.once=function(a,t,e){return k(this,a,t,e,!0)};l.prototype.removeListener=function(a,t,e,i){var n=h?h+a:a;if(!this._events[n])return this;if(!t)return b(this,n),this;var s=this._events[n];if(s.fn)s.fn===t&&(!i||s.once)&&(!e||s.context===e)&&b(this,n);else{for(var p=0,r=[],d=s.length;p<d;p++)(s[p].fn!==t||i&&!s[p].once||e&&s[p].context!==e)&&r.push(s[p]);r.length?this._events[n]=r.length===1?r[0]:r:b(this,n)}return this};l.prototype.removeAllListeners=function(a){var t;return a?(t=h?h+a:a,this._events[t]&&b(this,t)):(this._events=new f,this._eventsCount=0),this};l.prototype.off=l.prototype.removeListener;l.prototype.addListener=l.prototype.on;l.prefixed=h;l.EventEmitter=l;typeof y<"u"&&(y.exports=l)});var P={};O(P,{Chatbot:()=>w});var T=D(M(),1);var E=T.default;var _=`
2
+ /* Dark mode support */
3
+ .arcai-widget[data-theme="dark"] {
4
+ --arcai-bg: #1a1a1a;
5
+ --arcai-text: #ffffff;
6
+ --arcai-border: #333333;
7
+ }
8
+
9
+ .arcai-widget[data-theme="light"] {
10
+ --arcai-bg: #ffffff;
11
+ --arcai-text: #1a1a1a;
12
+ --arcai-border: #e5e5e5;
13
+ }
14
+
15
+ .arcai-widget {
16
+ position: fixed;
17
+ z-index: 9999;
18
+ transform: none;
19
+ font-family: system-ui, -apple-system, sans-serif;
20
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
21
+ }
22
+
23
+ .arcai-widget.bottom-right {
24
+ bottom: 20px;
25
+ right: 20px;
26
+ transform-origin: bottom right;
27
+ }
28
+
29
+ .arcai-widget.bottom-left {
30
+ bottom: 20px;
31
+ left: 20px;
32
+ transform-origin: bottom left;
33
+ }
34
+
35
+ .arcai-widget.top-right {
36
+ top: 20px;
37
+ right: 20px;
38
+ transform-origin: top right;
39
+ }
40
+
41
+ .arcai-widget.top-left {
42
+ top: 20px;
43
+ left: 20px;
44
+ transform-origin: top left;
45
+ }
46
+
47
+ .arcai-widget.outside-left {
48
+ left: -28px; /* Half of launcher width */
49
+ top: 50%;
50
+ transform: translateY(-50%);
51
+ transform-origin: center left;
52
+ }
53
+
54
+ .arcai-widget.outside-left:hover {
55
+ left: 20px;
56
+ }
57
+
58
+ .arcai-widget.outside-left .arcai-chat {
59
+ left: 80px;
60
+ bottom: auto;
61
+ top: 50%;
62
+ transform: translateY(-50%);
63
+ }
64
+
65
+ .arcai-widget.outside-right {
66
+ right: -28px;
67
+ top: 50%;
68
+ transform: translateY(-50%);
69
+ transform-origin: center right;
70
+ }
71
+
72
+ .arcai-widget.outside-right:hover {
73
+ right: 20px;
74
+ }
75
+
76
+ .arcai-widget.outside-right .arcai-chat {
77
+ right: 80px;
78
+ bottom: auto;
79
+ top: 50%;
80
+ transform: translateY(-50%);
81
+ }
82
+
83
+ .arcai-launcher {
84
+ width: 56px;
85
+ height: 56px;
86
+ border-radius: 50%;
87
+ background: var(--arcai-primary-color, #2563eb);
88
+ color: white;
89
+ border: none;
90
+ cursor: pointer;
91
+ display: flex;
92
+ align-items: center;
93
+ justify-content: center;
94
+ transition: transform 0.2s, box-shadow 0.2s;
95
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
96
+ position: relative;
97
+ z-index: 2;
98
+ }
99
+
100
+ .arcai-launcher:hover {
101
+ transform: translateY(-2px);
102
+ box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
103
+ }
104
+
105
+ .arcai-launcher.float-up-down {
106
+ animation: arcaiFloatUpDown 3s ease-in-out infinite;
107
+ }
108
+
109
+ .arcai-launcher.float-left-right {
110
+ animation: arcaiFloatLeftRight 3s ease-in-out infinite;
111
+ }
112
+
113
+ .arcai-launcher.float-diagonal {
114
+ animation: arcaiFloatDiagonal 4s ease-in-out infinite;
115
+ }
116
+
117
+ .arcai-launcher.float-circle {
118
+ animation: arcaiFloatCircle 5s ease-in-out infinite;
119
+ }
120
+
121
+ /* Sound effect animations */
122
+ @keyframes arcaiSoundWave {
123
+ 0% { transform: scale(1); opacity: 0.8; }
124
+ 100% { transform: scale(2); opacity: 0; }
125
+ }
126
+
127
+ .arcai-sound-wave {
128
+ position: absolute;
129
+ border: 2px solid var(--arcai-primary-color);
130
+ width: 100%;
131
+ height: 100%;
132
+ border-radius: 50%;
133
+ animation: arcaiSoundWave 1s ease-out infinite;
134
+ }
135
+
136
+ /* Typing indicator */
137
+ .arcai-typing {
138
+ display: flex;
139
+ align-items: center;
140
+ gap: 4px;
141
+ padding: 8px;
142
+ background: var(--arcai-bg);
143
+ border-radius: 12px;
144
+ margin-bottom: 8px;
145
+ }
146
+
147
+ .arcai-typing-dot {
148
+ width: 6px;
149
+ height: 6px;
150
+ background: var(--arcai-primary-color);
151
+ border-radius: 50%;
152
+ animation: arcaiDotPulse 1.4s infinite;
153
+ }
154
+
155
+ .arcai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
156
+ .arcai-typing-dot:nth-child(3) { animation-delay: 0.4s; }
157
+
158
+ @keyframes arcaiDotPulse {
159
+ 0%, 60%, 100% { transform: scale(1); opacity: 1; }
160
+ 30% { transform: scale(1.2); opacity: 0.4; }
161
+ }
162
+
163
+ /* Suggested messages */
164
+ .arcai-suggestions {
165
+ display: flex;
166
+ flex-wrap: wrap;
167
+ gap: 8px;
168
+ margin-top: 12px;
169
+ }
170
+
171
+ .arcai-suggestion {
172
+ padding: 6px 12px;
173
+ background: var(--arcai-primary-color);
174
+ color: white;
175
+ border-radius: 16px;
176
+ font-size: 14px;
177
+ cursor: pointer;
178
+ transition: all 0.2s;
179
+ border: none;
180
+ }
181
+
182
+ .arcai-suggestion:hover {
183
+ transform: translateY(-1px);
184
+ filter: brightness(1.1);
185
+ }
186
+
187
+ /* Attachment handling */
188
+ .arcai-attachments {
189
+ display: flex;
190
+ flex-wrap: wrap;
191
+ gap: 8px;
192
+ margin-top: 8px;
193
+ }
194
+
195
+ .arcai-attachment {
196
+ display: flex;
197
+ align-items: center;
198
+ gap: 4px;
199
+ padding: 4px 8px;
200
+ background: var(--arcai-bg);
201
+ border-radius: 4px;
202
+ font-size: 12px;
203
+ }
204
+
205
+ .arcai-attachment-remove {
206
+ cursor: pointer;
207
+ opacity: 0.6;
208
+ transition: opacity 0.2s;
209
+ }
210
+
211
+ .arcai-attachment-remove:hover {
212
+ opacity: 1;
213
+ }
214
+
215
+ .arcai-chat {
216
+ position: fixed;
217
+ width: 380px;
218
+ height: 600px;
219
+ background: white;
220
+ border-radius: 12px;
221
+ box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
222
+ display: flex;
223
+ flex-direction: column;
224
+ overflow: hidden;
225
+ opacity: 0;
226
+ transform: translateY(20px);
227
+ transition: opacity 0.3s, transform 0.3s;
228
+ z-index: 1;
229
+ }
230
+
231
+ .arcai-chat.open {
232
+ opacity: 1;
233
+ transform: translateY(0);
234
+ }
235
+
236
+ .arcai-header {
237
+ padding: 16px;
238
+ background: var(--arcai-primary-color, #2563eb);
239
+ color: white;
240
+ display: flex;
241
+ align-items: center;
242
+ justify-content: space-between;
243
+ }
244
+
245
+ .arcai-header.glassmorphism {
246
+ backdrop-filter: blur(8px);
247
+ background: rgba(37, 99, 235, 0.8);
248
+ }
249
+
250
+ .arcai-title {
251
+ display: flex;
252
+ align-items: center;
253
+ gap: 8px;
254
+ font-weight: 500;
255
+ }
256
+
257
+ .arcai-close {
258
+ background: none;
259
+ border: none;
260
+ color: white;
261
+ cursor: pointer;
262
+ padding: 4px;
263
+ border-radius: 4px;
264
+ display: flex;
265
+ align-items: center;
266
+ justify-content: center;
267
+ }
268
+
269
+ .arcai-close:hover {
270
+ background: rgba(255, 255, 255, 0.1);
271
+ }
272
+
273
+ .arcai-messages {
274
+ flex: 1;
275
+ overflow-y: auto;
276
+ padding: 16px;
277
+ background: #f8fafc;
278
+ }
279
+
280
+ .arcai-message {
281
+ display: flex;
282
+ align-items: flex-start;
283
+ gap: 8px;
284
+ margin-bottom: 16px;
285
+ opacity: 0;
286
+ transform: translateY(10px);
287
+ animation: arcaiMessageSlideUp 0.3s forwards;
288
+ }
289
+
290
+ .arcai-message.user {
291
+ flex-direction: row-reverse;
292
+ }
293
+
294
+ .arcai-avatar {
295
+ width: 32px;
296
+ height: 32px;
297
+ border-radius: 50%;
298
+ background: #e2e8f0;
299
+ display: flex;
300
+ align-items: center;
301
+ justify-content: center;
302
+ flex-shrink: 0;
303
+ }
304
+
305
+ .arcai-bubble {
306
+ background: white;
307
+ padding: 12px 16px;
308
+ border-radius: 12px;
309
+ max-width: 70%;
310
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
311
+ }
312
+
313
+ .arcai-message.user .arcai-bubble {
314
+ background: var(--arcai-primary-color, #2563eb);
315
+ color: white;
316
+ }
317
+
318
+ .arcai-input {
319
+ padding: 16px;
320
+ background: white;
321
+ border-top: 1px solid #e2e8f0;
322
+ }
323
+
324
+ .arcai-input-form {
325
+ display: flex;
326
+ gap: 8px;
327
+ }
328
+
329
+ .arcai-input-field {
330
+ flex: 1;
331
+ padding: 8px 16px;
332
+ border: 1px solid #e2e8f0;
333
+ border-radius: 24px;
334
+ outline: none;
335
+ font-size: 14px;
336
+ }
337
+
338
+ .arcai-input-field:focus {
339
+ border-color: var(--arcai-primary-color, #2563eb);
340
+ box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
341
+ }
342
+
343
+ .arcai-send {
344
+ width: 36px;
345
+ height: 36px;
346
+ border-radius: 50%;
347
+ background: var(--arcai-primary-color, #2563eb);
348
+ color: white;
349
+ border: none;
350
+ cursor: pointer;
351
+ display: flex;
352
+ align-items: center;
353
+ justify-content: center;
354
+ transition: background-color 0.2s;
355
+ }
356
+
357
+ .arcai-send:hover {
358
+ background: var(--arcai-primary-color-dark, #1d4ed8);
359
+ }
360
+
361
+ .arcai-thought {
362
+ position: absolute;
363
+ bottom: 100%;
364
+ right: 0;
365
+ margin-bottom: 12px;
366
+ background: white;
367
+ padding: 12px 16px;
368
+ border-radius: 12px;
369
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
370
+ max-width: 240px;
371
+ opacity: 0;
372
+ transform: translateY(10px);
373
+ animation: arcaiThoughtBubble 4s ease-in-out forwards;
374
+ }
375
+
376
+ .arcai-thought::after {
377
+ content: '';
378
+ position: absolute;
379
+ bottom: -6px;
380
+ right: 24px;
381
+ width: 12px;
382
+ height: 12px;
383
+ background: white;
384
+ transform: rotate(45deg);
385
+ }
386
+
387
+ @keyframes arcaiFloatUpDown {
388
+ 0%, 100% { transform: translateY(0); }
389
+ 50% { transform: translateY(-10px); }
390
+ }
391
+
392
+ @keyframes arcaiFloatLeftRight {
393
+ 0%, 100% { transform: translateX(0); }
394
+ 50% { transform: translateX(10px); }
395
+ }
396
+
397
+ @keyframes arcaiFloatDiagonal {
398
+ 0%, 100% { transform: translate(0, 0); }
399
+ 50% { transform: translate(5px, -5px); }
400
+ }
401
+
402
+ @keyframes arcaiFloatCircle {
403
+ 0% { transform: translate(0, 0); }
404
+ 25% { transform: translate(5px, -5px); }
405
+ 50% { transform: translate(10px, 0); }
406
+ 75% { transform: translate(5px, 5px); }
407
+ 100% { transform: translate(0, 0); }
408
+ }
409
+
410
+ @keyframes arcaiMessageSlideUp {
411
+ to {
412
+ opacity: 1;
413
+ transform: translateY(0);
414
+ }
415
+ }
416
+
417
+ @keyframes arcaiThoughtBubble {
418
+ 0% {
419
+ opacity: 0;
420
+ transform: scale(0.8) translateY(10px);
421
+ }
422
+ 10% {
423
+ opacity: 1;
424
+ transform: scale(1) translateY(0);
425
+ }
426
+ 90% {
427
+ opacity: 1;
428
+ transform: scale(1) translateY(0);
429
+ }
430
+ 100% {
431
+ opacity: 0;
432
+ transform: scale(0.8) translateY(-10px);
433
+ }
434
+ }`;var v=`
435
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
436
+ <path d="M12 2a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2 2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z"/>
437
+ <path d="M12 8v8"/>
438
+ <path d="M5 3a2 2 0 0 0-2 2v2c0 1.1.9 2 2 2h2a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2H5z"/>
439
+ <path d="M17 3a2 2 0 0 0-2 2v2c0 1.1.9 2 2 2h2a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2h-2z"/>
440
+ <path d="M9 17v-1a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v1"/>
441
+ <path d="M3 13v6a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-6"/>
442
+ </svg>`,S=`
443
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
444
+ <path d="m22 2-7 20-4-9-9-4Z"/>
445
+ <path d="M22 2 11 13"/>
446
+ </svg>`,L=`
447
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
448
+ <path d="M18 6 6 18"/>
449
+ <path d="m6 6 12 12"/>
450
+ </svg>`;var w=class extends E{constructor(t){super();this.messages=[];this.isOpen=!1;this.config={...t,position:t.position||"bottom-right",primaryColor:t.primaryColor||"#2563eb",textColor:t.textColor||"#1e293b",bgImage:t.bgImage||"",opacity:t.opacity||100,glassmorphism:t.glassmorphism||!1,floatAnimation:t.floatAnimation||"float-up-down",showAvatar:t.showAvatar??!0,showThoughts:t.showThoughts??!0,thoughtInterval:t.thoughtInterval||8,customThoughts:t.customThoughts||["I'm here to help!","Have any questions?","Need assistance?"],onMessage:t.onMessage||this.defaultMessageHandler},this.injectStyles(),this.container=this.createContainer(),this.chat=this.createChat(),document.body.appendChild(this.container),this.config.showThoughts&&this.startThoughtCycle()}injectStyles(){let t=document.createElement("style");t.textContent=_,document.head.appendChild(t);let e=document.createElement("style");e.textContent=`
451
+ :root {
452
+ --arcai-primary-color: ${this.config.primaryColor};
453
+ --arcai-primary-color-dark: ${this.adjustColor(this.config.primaryColor,-20)};
454
+ }
455
+ `,document.head.appendChild(e)}createContainer(){let t=document.createElement("div");t.className=`arcai-widget ${this.config.position}`;let e=document.createElement("button");return e.className=`arcai-launcher ${this.config.floatAnimation}`,e.innerHTML=v,e.onclick=()=>this.toggle(),t.appendChild(e),t}createChat(){let t=document.createElement("div");t.className="arcai-chat";let e=document.createElement("div");e.className=`arcai-header ${this.config.glassmorphism?"glassmorphism":""}`,this.config.bgImage&&(e.style.backgroundImage=`url(${this.config.bgImage})`,e.style.backgroundSize="cover",e.style.backgroundPosition="center",e.style.backgroundColor=`rgba(37, 99, 235, ${this.config.opacity/100})`);let i=document.createElement("div");i.className="arcai-title",i.innerHTML=`${v} <span>Chat Assistant</span>`;let n=document.createElement("button");n.className="arcai-close",n.innerHTML=L,n.onclick=()=>this.close(),e.appendChild(i),e.appendChild(n);let s=document.createElement("div");s.className="arcai-messages";let p=document.createElement("div");p.className="arcai-input";let r=document.createElement("form");r.className="arcai-input-form",r.onsubmit=c=>{c.preventDefault();let m=r.querySelector("input");m?.value.trim()&&(this.sendMessage(m.value),m.value="")};let d=document.createElement("input");d.className="arcai-input-field",d.placeholder="Type your message...";let u=document.createElement("button");return u.className="arcai-send",u.type="submit",u.innerHTML=S,r.appendChild(d),r.appendChild(u),p.appendChild(r),t.appendChild(e),t.appendChild(s),t.appendChild(p),this.container.appendChild(t),t}async sendMessage(t){let e={id:Math.random().toString(36).substr(2,9),role:"user",content:t,timestamp:new Date};this.messages.push(e),this.renderMessage(e);try{let i=await this.config.onMessage(t),n={id:Math.random().toString(36).substr(2,9),role:"bot",content:i,timestamp:new Date};this.messages.push(n),this.renderMessage(n)}catch(i){console.error("Error sending message:",i)}}renderMessage(t){let e=this.chat.querySelector(".arcai-messages");if(!e)return;let i=document.createElement("div");if(i.className=`arcai-message ${t.role}`,this.config.showAvatar){let s=document.createElement("div");s.className="arcai-avatar",s.innerHTML=v,i.appendChild(s)}let n=document.createElement("div");n.className="arcai-bubble",n.textContent=t.content,i.appendChild(n),e.appendChild(i),e.scrollTop=e.scrollHeight}showThought(){let t=this.config.customThoughts[Math.floor(Math.random()*this.config.customThoughts.length)],e=document.createElement("div");e.className="arcai-thought",e.textContent=t;let i=this.container.querySelector(".arcai-launcher");i&&(i.appendChild(e),setTimeout(()=>{e.remove()},4e3))}startThoughtCycle(){this.thoughtTimeout&&clearTimeout(this.thoughtTimeout);let t=()=>{this.isOpen||this.showThought(),this.thoughtTimeout=setTimeout(t,this.config.thoughtInterval*1e3)};setTimeout(t,2e3)}adjustColor(t,e){let i=t.replace("#",""),n=parseInt(i,16),s=Math.min(255,Math.max(0,(n>>16)+e)),p=Math.min(255,Math.max(0,(n>>8&255)+e)),r=Math.min(255,Math.max(0,(n&255)+e));return`#${(s<<16|p<<8|r).toString(16).padStart(6,"0")}`}async defaultMessageHandler(t){return`I received your message: "${t}". This is a default response. Please configure a custom message handler for more meaningful interactions.`}open(){this.isOpen=!0,this.chat.classList.add("open")}close(){this.isOpen=!1,this.chat.classList.remove("open")}toggle(){this.isOpen?this.close():this.open()}destroy(){this.thoughtTimeout&&clearTimeout(this.thoughtTimeout),this.container.remove()}};return z(P);})();
@@ -0,0 +1,3 @@
1
+ export declare const botIcon = "\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M12 2a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2 2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z\"/>\n <path d=\"M12 8v8\"/>\n <path d=\"M5 3a2 2 0 0 0-2 2v2c0 1.1.9 2 2 2h2a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2H5z\"/>\n <path d=\"M17 3a2 2 0 0 0-2 2v2c0 1.1.9 2 2 2h2a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2h-2z\"/>\n <path d=\"M9 17v-1a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v1\"/>\n <path d=\"M3 13v6a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-6\"/>\n</svg>";
2
+ export declare const sendIcon = "\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"m22 2-7 20-4-9-9-4Z\"/>\n <path d=\"M22 2 11 13\"/>\n</svg>";
3
+ export declare const closeIcon = "\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M18 6 6 18\"/>\n <path d=\"m6 6 12 12\"/>\n</svg>";
package/dist/icons.js ADDED
@@ -0,0 +1,19 @@
1
+ export const botIcon = `
2
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
3
+ <path d="M12 2a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2 2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z"/>
4
+ <path d="M12 8v8"/>
5
+ <path d="M5 3a2 2 0 0 0-2 2v2c0 1.1.9 2 2 2h2a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2H5z"/>
6
+ <path d="M17 3a2 2 0 0 0-2 2v2c0 1.1.9 2 2 2h2a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2h-2z"/>
7
+ <path d="M9 17v-1a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v1"/>
8
+ <path d="M3 13v6a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-6"/>
9
+ </svg>`;
10
+ export const sendIcon = `
11
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
12
+ <path d="m22 2-7 20-4-9-9-4Z"/>
13
+ <path d="M22 2 11 13"/>
14
+ </svg>`;
15
+ export const closeIcon = `
16
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
17
+ <path d="M18 6 6 18"/>
18
+ <path d="m6 6 12 12"/>
19
+ </svg>`;
@@ -0,0 +1,25 @@
1
+ import EventEmitter from 'eventemitter3';
2
+ import type { ChatbotConfig, Message } from './types';
3
+ export declare class Chatbot extends EventEmitter {
4
+ private config;
5
+ private container;
6
+ private chat;
7
+ private messages;
8
+ private thoughtTimeout?;
9
+ private isOpen;
10
+ constructor(config: ChatbotConfig);
11
+ private injectStyles;
12
+ private createContainer;
13
+ private createChat;
14
+ private sendMessage;
15
+ private renderMessage;
16
+ private showThought;
17
+ private startThoughtCycle;
18
+ private adjustColor;
19
+ private defaultMessageHandler;
20
+ open(): void;
21
+ close(): void;
22
+ toggle(): void;
23
+ destroy(): void;
24
+ }
25
+ export type { ChatbotConfig, Message };