@mobil80-dev/chatbot-widget 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -10,7 +10,7 @@ let isOpen = false
10
10
  /* =========================================================
11
11
  STYLE INJECTION (ONCE)
12
12
  ========================================================= */
13
- function injectStylesOnce() {
13
+ function injectStylesOnce () {
14
14
  if (stylesInjected) return
15
15
  stylesInjected = true
16
16
 
@@ -51,7 +51,7 @@ function injectStylesOnce() {
51
51
  /* =========================================================
52
52
  HELPER TO RESOLVE CONTAINER
53
53
  ========================================================= */
54
- function getAttachContainer(selector) {
54
+ function getAttachContainer (selector) {
55
55
  if (!selector) return document.body
56
56
  if (typeof selector === 'string') {
57
57
  const el = document.querySelector(selector)
@@ -63,18 +63,23 @@ function getAttachContainer(selector) {
63
63
  /* =========================================================
64
64
  BUTTON
65
65
  ========================================================= */
66
- function getButton() {
66
+ function getButton () {
67
67
  if (vcButton) return vcButton
68
68
  vcButton = document.createElement('div')
69
69
  vcButton.className = 'vc-fab'
70
70
  return vcButton
71
71
  }
72
72
 
73
- function updateButton(config) {
73
+ function updateButton (config) {
74
74
  const button = getButton()
75
75
  button.innerHTML = ''
76
76
 
77
- const { buttonType = 'text', buttonContent = '🤖', buttonShape = 'circle', primaryColor = '#2563eb' } = config
77
+ const {
78
+ buttonType = 'text',
79
+ buttonContent = '🤖',
80
+ buttonShape = 'circle',
81
+ primaryColor = '#2563eb'
82
+ } = config
78
83
  const isText = buttonType === 'text'
79
84
 
80
85
  if (buttonType === 'image') {
@@ -88,7 +93,8 @@ function updateButton(config) {
88
93
  button.textContent = buttonContent
89
94
  }
90
95
 
91
- const borderRadius = buttonShape === 'pill' ? '999px' : buttonShape === 'square' ? '8px' : '50%'
96
+ const borderRadius =
97
+ buttonShape === 'pill' ? '999px' : buttonShape === 'square' ? '8px' : '50%'
92
98
 
93
99
  Object.assign(button.style, {
94
100
  position: 'fixed',
@@ -116,22 +122,48 @@ function updateButton(config) {
116
122
  /* =========================================================
117
123
  CARD
118
124
  ========================================================= */
119
- function getCard() {
125
+ function getCard () {
120
126
  if (vcCard) return vcCard
121
127
  vcCard = document.createElement('div')
122
128
  return vcCard
123
129
  }
124
130
 
125
- function updateCard(config) {
131
+ function updateCard (config) {
126
132
  const card = getCard()
127
133
 
128
- const theme = config.theme === 'dark' ? 'dark' : config.theme === 'light' ? 'light' :
129
- window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
134
+ const theme =
135
+ config.theme === 'dark'
136
+ ? 'dark'
137
+ : config.theme === 'light'
138
+ ? 'light'
139
+ : window.matchMedia('(prefers-color-scheme: dark)').matches
140
+ ? 'dark'
141
+ : 'light'
130
142
  const isDark = theme === 'dark'
131
143
 
132
144
  const colors = isDark
133
- ? { cardBg: '#0f172a', headerBorder: '#1e293b', text: '#e5e7eb', mutedText: '#94a3b8', inputBg: '#020617', inputBorder: '#334155', botBubble: '#1e293b', userText: '#ffffff', messagesBg: '#020617' }
134
- : { cardBg: '#ffffff', headerBorder: '#e5e7eb', text: '#0f172a', mutedText: '#64748b', inputBg: '#ffffff', inputBorder: '#cbd5f5', botBubble: '#e5e7eb', userText: '#ffffff', messagesBg: '#f8fafc' }
145
+ ? {
146
+ cardBg: '#0f172a',
147
+ headerBorder: '#1e293b',
148
+ text: '#e5e7eb',
149
+ mutedText: '#94a3b8',
150
+ inputBg: '#020617',
151
+ inputBorder: '#334155',
152
+ botBubble: '#1e293b',
153
+ userText: '#ffffff',
154
+ messagesBg: '#020617'
155
+ }
156
+ : {
157
+ cardBg: '#ffffff',
158
+ headerBorder: '#e5e7eb',
159
+ text: '#0f172a',
160
+ mutedText: '#64748b',
161
+ inputBg: '#ffffff',
162
+ inputBorder: '#cbd5f5',
163
+ botBubble: '#e5e7eb',
164
+ userText: '#ffffff',
165
+ messagesBg: '#f8fafc'
166
+ }
135
167
 
136
168
  const primaryColor = config.primaryColor || '#2563eb'
137
169
 
@@ -162,8 +194,10 @@ function updateCard(config) {
162
194
  position: 'fixed',
163
195
  bottom: '90px',
164
196
  right: '20px',
197
+ maxWidth: '90vw',
165
198
  width: '400px',
166
199
  height: '420px',
200
+ maxHeight: '80vh',
167
201
  background: colors.cardBg,
168
202
  borderRadius: '12px',
169
203
  boxShadow: '0 10px 30px rgba(0,0,0,.3)',
@@ -171,6 +205,10 @@ function updateCard(config) {
171
205
  display: isOpen ? 'flex' : 'none',
172
206
  flexDirection: 'column'
173
207
  })
208
+ if (window.innerWidth < 450) {
209
+ card.style.bottom = '10px'
210
+ card.style.right = '5px'
211
+ }
174
212
 
175
213
  card.style.setProperty('--vc-text-muted', colors.mutedText)
176
214
  card.style.setProperty('--vc-bot-bg', colors.botBubble)
@@ -180,7 +218,7 @@ function updateCard(config) {
180
218
  const sendBtn = card.querySelector('#vc-send')
181
219
 
182
220
  // send message
183
- async function sendMessage() {
221
+ async function sendMessage () {
184
222
  const text = input.value.trim()
185
223
  if (!text) return
186
224
 
@@ -213,14 +251,16 @@ function updateCard(config) {
213
251
  })
214
252
  const data = await res.json()
215
253
  hideLoader(sendBtn)
216
- addBotMessage(data?.data?.blocks?.map(b => b.text).join('\n') || 'No response')
254
+ addBotMessage(
255
+ data?.data?.blocks?.map(b => b.text).join('\n') || 'No response'
256
+ )
217
257
  } catch {
218
258
  hideLoader(sendBtn)
219
259
  addBotMessage('⚠️ Something went wrong')
220
260
  }
221
261
  }
222
262
 
223
- function addBotMessage(text) {
263
+ function addBotMessage (text) {
224
264
  const div = document.createElement('div')
225
265
  div.style.cssText = `
226
266
  background:${colors.botBubble};
@@ -236,7 +276,9 @@ function updateCard(config) {
236
276
 
237
277
  // events
238
278
  sendBtn.onclick = sendMessage
239
- input.addEventListener('keydown', e => { if (e.key === 'Enter') sendMessage() })
279
+ input.addEventListener('keydown', e => {
280
+ if (e.key === 'Enter') sendMessage()
281
+ })
240
282
 
241
283
  return { messages, input, sendBtn }
242
284
  }
@@ -244,7 +286,7 @@ function updateCard(config) {
244
286
  /* =========================================================
245
287
  LOADER
246
288
  ========================================================= */
247
- function showLoader(container, sendBtn) {
289
+ function showLoader (container, sendBtn) {
248
290
  loaderEl = document.createElement('div')
249
291
  loaderEl.className = 'vc-loader'
250
292
  loaderEl.innerHTML = '<span></span><span></span><span></span>'
@@ -257,7 +299,7 @@ function showLoader(container, sendBtn) {
257
299
  }
258
300
  }
259
301
 
260
- function hideLoader(sendBtn) {
302
+ function hideLoader (sendBtn) {
261
303
  loaderEl?.remove()
262
304
  loaderEl = null
263
305
 
@@ -272,7 +314,7 @@ function hideLoader(sendBtn) {
272
314
  PUBLIC API
273
315
  ========================================================= */
274
316
  const VaultChat = {
275
- init(config = {}) {
317
+ init (config = {}) {
276
318
  injectStylesOnce()
277
319
  updateButton(config)
278
320
 
@@ -288,7 +330,7 @@ const VaultChat = {
288
330
  }
289
331
  },
290
332
 
291
- destroy() {
333
+ destroy () {
292
334
  vcButton?.remove()
293
335
  vcCard?.remove()
294
336
  vcButton = null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mobil80-dev/chatbot-widget",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Drop-in JavaScript chat widget for websites (no iframe, no framework)",
5
5
  "author": "NanthaGopal",
6
6
  "license": "MIT",
package/rollup.config.js CHANGED
@@ -11,4 +11,4 @@ export default {
11
11
  name: 'VaultChat'
12
12
  }
13
13
  ]
14
- }
14
+ }