@bitpalm/ai-agents 0.3.5 → 0.5.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/README.md +49 -200
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +19 -0
- package/dist/react.d.ts +19 -0
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/widget.global.js +1 -1
- package/dist/widget.global.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,235 +4,84 @@ Drop-in AI chat agent widget for any website. Works with React, Next.js, Vue, va
|
|
|
4
4
|
|
|
5
5
|
> Don't have an agent yet? [Create one for free](https://agents.bitpalm.ai/register) — takes less than 10 minutes.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## 30-second install
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
### Script tag (any HTML page)
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<script
|
|
13
|
+
async
|
|
14
|
+
src="https://unpkg.com/@bitpalm/ai-agents"
|
|
15
|
+
data-slug="your-agent-slug"
|
|
16
|
+
data-token="your-embed-token"
|
|
17
|
+
></script>
|
|
11
18
|
```
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
### React / Next.js
|
|
14
21
|
|
|
15
22
|
```tsx
|
|
16
|
-
import { BitPalmAgent } from
|
|
23
|
+
import { BitPalmAgent } from "@bitpalm/ai-agents/react";
|
|
17
24
|
|
|
18
|
-
export default function
|
|
25
|
+
export default function RootLayout({ children }) {
|
|
19
26
|
return (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
<html>
|
|
28
|
+
<body>
|
|
29
|
+
{children}
|
|
30
|
+
<BitPalmAgent slug="your-agent-slug" token="your-embed-token" />
|
|
31
|
+
</body>
|
|
32
|
+
</html>
|
|
24
33
|
);
|
|
25
34
|
}
|
|
26
35
|
```
|
|
27
36
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## Vanilla JavaScript
|
|
37
|
+
### Vanilla JS
|
|
31
38
|
|
|
32
39
|
```js
|
|
33
|
-
import { createWidget } from
|
|
34
|
-
|
|
35
|
-
const widget = createWidget({ slug: 'your-agent-slug', token: 'your-embed-token' });
|
|
36
|
-
|
|
37
|
-
// Programmatic control
|
|
38
|
-
widget.open();
|
|
39
|
-
widget.close();
|
|
40
|
-
widget.toggle(); // open if closed, close if open
|
|
41
|
-
widget.isOpen(); // check if widget is open
|
|
42
|
-
widget.identify({
|
|
43
|
-
externalUserId: 'cust_123',
|
|
44
|
-
name: 'Max Mustermann',
|
|
45
|
-
email: 'max@example.com',
|
|
46
|
-
});
|
|
47
|
-
widget.context({
|
|
48
|
-
cart: { items: [{ name: 'Sneakers', price: 99.99 }], total: 99.99 },
|
|
49
|
-
});
|
|
50
|
-
widget.resetContext(); // clear all custom context
|
|
51
|
-
widget.send('Tell me about the Enterprise plan'); // send message as user
|
|
52
|
-
widget.on('lead_captured', (data) => console.log('Lead!', data)); // listen to events
|
|
53
|
-
widget.destroy();
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Script Tag
|
|
40
|
+
import { createWidget } from "@bitpalm/ai-agents";
|
|
57
41
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
```html
|
|
61
|
-
<script async src="https://unpkg.com/@bitpalm/ai-agents" data-slug="your-agent-slug" data-token="your-embed-token"></script>
|
|
42
|
+
const widget = createWidget({ slug: "your-agent-slug", token: "your-embed-token" });
|
|
62
43
|
```
|
|
63
44
|
|
|
64
|
-
##
|
|
65
|
-
|
|
66
|
-
| Option | Type | Default | Description |
|
|
67
|
-
|--------|------|---------|-------------|
|
|
68
|
-
| `slug` | `string` | — | **Required.** Your agent slug from the [BitPalm dashboard](https://agents.bitpalm.ai). |
|
|
69
|
-
| `token` | `string` | — | Required for restricted/private agents. Embed token from dashboard access settings. |
|
|
70
|
-
| `locale` | `string` | auto-detected | Widget language (`"en"`, `"de"`, `"ar"`, …). Falls back to `document.documentElement.lang`. |
|
|
71
|
-
| `baseUrl` | `string` | `"https://agents.bitpalm.ai"` | Agent platform URL. Only change this for self-hosted setups. |
|
|
72
|
-
| `zIndex` | `number` | `9999` | z-index for the widget iframe and chat button. |
|
|
73
|
-
| `autoIdentify` | `boolean` | `true` | Auto-detects form submissions and sends found identity fields (email/phone/name/company) for visitor stitching. |
|
|
74
|
-
|
|
75
|
-
## Features
|
|
45
|
+
## Light & dark theme
|
|
76
46
|
|
|
77
|
-
|
|
78
|
-
- **Returning visitor detection** — recognizes returning visitors, restores chat history, and enables session/page-count-based triggers
|
|
79
|
-
- **SPA support** — detects client-side navigation (`pushState` / `replaceState`) and keeps the widget alive across route changes
|
|
80
|
-
- **Trigger bubbles** — proactive chat bubbles configured from the dashboard, including visitor-data-driven triggers (session count, visited pages)
|
|
81
|
-
- **Scroll & exit tracking** — scroll depth and exit intent signals for smart triggers
|
|
82
|
-
- **Automatic form identity stitching** — captures common form fields on submit and links them to the current visitor profile
|
|
83
|
-
- **Custom context** — pass business data (cart, user tier, listings) to the AI for contextual, relevant answers
|
|
84
|
-
- **Privacy-friendly** — respects visitor opt-out (`_bp_optout` in localStorage); when opted out, no tracking beacons are sent and no visitor ID is stored
|
|
85
|
-
- **Light & fast** — no dependencies (React is optional), tiny bundle size
|
|
47
|
+
Set up dark colors for your agent in the dashboard playground. The widget then follows your website's theme on its own (`class="dark"`, `data-theme="dark"`, the page background or `color-scheme`) and switches live.
|
|
86
48
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
The widget already detects common field names automatically. For custom forms, you can add explicit markers:
|
|
90
|
-
|
|
91
|
-
- `data-bp-email`
|
|
92
|
-
- `data-bp-phone`
|
|
93
|
-
- `data-bp-name` (or `data-bp-first-name` / `data-bp-last-name`)
|
|
94
|
-
- `data-bp-company`
|
|
95
|
-
- `data-bp-field="email|phone|name|first-name|last-name|company"` (generic fallback)
|
|
96
|
-
|
|
97
|
-
Disable auto-identity for one specific form:
|
|
49
|
+
To set it yourself:
|
|
98
50
|
|
|
99
51
|
```html
|
|
100
|
-
<
|
|
52
|
+
<script async src="https://unpkg.com/@bitpalm/ai-agents" data-slug="your-agent-slug" data-theme="dark"></script>
|
|
101
53
|
```
|
|
102
54
|
|
|
103
|
-
## Manual Identify (Logged-in Users)
|
|
104
|
-
|
|
105
|
-
If your website has authenticated users, call `identify()` after login to attach trusted profile data to the current visitor:
|
|
106
|
-
|
|
107
|
-
```ts
|
|
108
|
-
widget.identify({
|
|
109
|
-
externalUserId: "user_42",
|
|
110
|
-
name: "Alex Example",
|
|
111
|
-
email: "alex@example.com",
|
|
112
|
-
phone: "+491701234567",
|
|
113
|
-
company: "Example GmbH",
|
|
114
|
-
});
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Optional signed identify fields (forwarded to your BitPalm backend):
|
|
118
|
-
|
|
119
|
-
- `signature`: backend-generated HMAC signature
|
|
120
|
-
- `signedAt`: unix timestamp (seconds)
|
|
121
|
-
- `signatureVersion`: currently `"v1"`
|
|
122
|
-
|
|
123
|
-
For script-tag integrations, trigger identify via a browser event:
|
|
124
|
-
|
|
125
55
|
```js
|
|
126
|
-
|
|
127
|
-
new CustomEvent("bitpalm-identify", {
|
|
128
|
-
detail: {
|
|
129
|
-
slug: "your-agent-slug",
|
|
130
|
-
externalUserId: "user_42",
|
|
131
|
-
name: "Alex Example",
|
|
132
|
-
email: "alex@example.com",
|
|
133
|
-
},
|
|
134
|
-
})
|
|
135
|
-
);
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
## Custom Context (Business Data for the AI)
|
|
139
|
-
|
|
140
|
-
Pass custom data from your website to the AI chatbot so it can give contextual, business-specific answers. Context is merged — calling `context()` multiple times adds to the existing data without replacing it.
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
// Shopify / E-Commerce: pass cart data
|
|
144
|
-
widget.context({
|
|
145
|
-
cart: {
|
|
146
|
-
items: [
|
|
147
|
-
{ name: "Nike Air Max 90", size: "42", price: 149.99 },
|
|
148
|
-
{ name: "Adidas Hoodie", qty: 2, price: 59.99 },
|
|
149
|
-
],
|
|
150
|
-
total: 269.97,
|
|
151
|
-
currency: "EUR",
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// SaaS: pass user status
|
|
156
|
-
widget.context({
|
|
157
|
-
plan: "trial",
|
|
158
|
-
trialDaysLeft: 3,
|
|
159
|
-
accountId: "acc_12345",
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
// Real Estate: pass current listing
|
|
163
|
-
widget.context({
|
|
164
|
-
property: { address: "Musterstr. 12, Berlin", price: 450000, rooms: 3 },
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// Merges with previous context (doesn't replace)
|
|
168
|
-
widget.context({ promoCode: "SUMMER20" });
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
The bot automatically uses this context in its responses — e.g. referencing specific cart items, tailoring advice to the user's plan, or answering questions about the current listing.
|
|
172
|
-
|
|
173
|
-
For script-tag integrations, use a browser event:
|
|
174
|
-
|
|
175
|
-
```js
|
|
176
|
-
window.dispatchEvent(
|
|
177
|
-
new CustomEvent("bitpalm-context", {
|
|
178
|
-
detail: {
|
|
179
|
-
slug: "your-agent-slug",
|
|
180
|
-
cart: { items: [...], total: 99.99 },
|
|
181
|
-
},
|
|
182
|
-
})
|
|
183
|
-
);
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
> **Note:** Context is session-only (not persisted to the database) and limited to 4 KB. Exceeding the limit logs a console warning.
|
|
187
|
-
|
|
188
|
-
## Programmatic Messages
|
|
189
|
-
|
|
190
|
-
Send a message as the user without them typing. Opens the widget automatically if closed.
|
|
191
|
-
|
|
192
|
-
```ts
|
|
193
|
-
// E.g. triggered by a "Ask about this product" button on your page
|
|
194
|
-
widget.send('Tell me more about the Enterprise plan');
|
|
195
|
-
|
|
196
|
-
// Or from a product page CTA
|
|
197
|
-
document.querySelector('#ask-bot').addEventListener('click', () => {
|
|
198
|
-
widget.send(`What can you tell me about ${productName}?`);
|
|
199
|
-
});
|
|
56
|
+
widget.setTheme("dark"); // "light", "dark" or "auto"
|
|
200
57
|
```
|
|
201
58
|
|
|
202
|
-
##
|
|
59
|
+
## Full documentation
|
|
203
60
|
|
|
204
|
-
|
|
61
|
+
📚 **[agents.bitpalm.ai/docs](https://agents.bitpalm.ai/docs)**
|
|
205
62
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
63
|
+
- [Quickstart for Script Tag](https://agents.bitpalm.ai/docs/quickstart/script-tag)
|
|
64
|
+
- [Quickstart for React / Next.js](https://agents.bitpalm.ai/docs/quickstart/react)
|
|
65
|
+
- [Quickstart for Vanilla JS](https://agents.bitpalm.ai/docs/quickstart/vanilla)
|
|
66
|
+
- [Configuration options](https://agents.bitpalm.ai/docs/configuration)
|
|
67
|
+
- [Light & dark theme](https://agents.bitpalm.ai/docs/theming)
|
|
68
|
+
- [Identify logged-in users](https://agents.bitpalm.ai/docs/identify)
|
|
69
|
+
- [Custom Context (cart, listings, account data)](https://agents.bitpalm.ai/docs/context)
|
|
70
|
+
- [Events (lead capture, conversation start)](https://agents.bitpalm.ai/docs/events)
|
|
71
|
+
- [API Reference](https://agents.bitpalm.ai/docs/api-reference)
|
|
72
|
+
- [Common Errors](https://agents.bitpalm.ai/docs/common-errors)
|
|
211
73
|
|
|
212
|
-
|
|
213
|
-
widget.on('conversation_started', () => {
|
|
214
|
-
analytics.track('Chat Started');
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
// React to widget open/close
|
|
218
|
-
widget.on('widget_opened', () => console.log('Chat opened'));
|
|
219
|
-
widget.on('widget_closed', () => console.log('Chat closed'));
|
|
220
|
-
|
|
221
|
-
// Unsubscribe
|
|
222
|
-
const unsub = widget.on('message_sent', (data) => { ... });
|
|
223
|
-
unsub(); // stop listening
|
|
224
|
-
```
|
|
74
|
+
## Features
|
|
225
75
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
| `lead_captured` | AI captures a lead via tool | `{ conversationId }` |
|
|
76
|
+
- Visitor Intelligence with intent scoring
|
|
77
|
+
- Returning visitor detection + chat history persistence
|
|
78
|
+
- SPA navigation tracking (`pushState` / `replaceState`)
|
|
79
|
+
- Trigger bubbles (session/page count, scroll depth, exit intent)
|
|
80
|
+
- Form auto-identify + signed identify for trusted data
|
|
81
|
+
- Custom context for business-aware AI responses
|
|
82
|
+
- Privacy-friendly with opt-out support
|
|
83
|
+
- Tiny bundle, no React dependency for vanilla build
|
|
235
84
|
|
|
236
85
|
## License
|
|
237
86
|
|
|
238
|
-
MIT —
|
|
87
|
+
MIT — built and operated by [BitPalm](https://agents.bitpalm.ai).
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var me=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var Ge=(t,o)=>{for(var m in o)me(t,m,{get:o[m],enumerable:!0})},Ve=(t,o,m,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let p of Ye(o))!Je.call(t,p)&&p!==m&&me(t,p,{get:()=>o[p],enumerable:!(a=qe(o,p))||a.enumerable});return t};var Ke=t=>Ve(me({},"__esModule",{value:!0}),t);var lt={};Ge(lt,{createWidget:()=>Q});module.exports=Ke(lt);var Xe="https://agents.bitpalm.ai",h="_bp_",Ze=new Set(["password","file","checkbox","radio","submit","button","reset","image"]),Qe=8e3,He=4096,Ne=`${h}identify_signature`,Re=`${h}identify_fingerprint`,Fe=`${h}identify_sent_at`;function et(t){return[t.external_user_id||"",t.email||"",t.phone||"",t.name||"",t.company||"",t.signature||"",t.signed_at!=null?String(t.signed_at):"",t.signature_version||"",t.identify_source||""].join("|").toLowerCase()}function d(t,o=180){return t?t.replace(/\s+/g," ").trim().slice(0,o):""}function tt(t){return t?` ${t.toLowerCase().replace(/[_-]+/g," ").replace(/[^a-z0-9\s@.]/g," ").replace(/\s+/g," ").trim()} `:""}function W(t,o){for(let m of o)if(t.includes(m))return!0;return!1}function A(t){return/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/i.test(t)}function _(t){let o=d(t,50);if(!o)return"";let m=o.startsWith("+"),a=o.replace(/\D/g,"");return a.length<6?"":`${m?"+":""}${a.slice(0,20)}`}function De(t){let o=d(t,140).toLowerCase();return!o||!A(o)?"":o}function U(t,o){for(let m of o){let a=t.querySelector(m),p=d(a?.value);if(p)return p}return""}function nt(t){return d(t.getAttribute("data-bp-field")||t.getAttribute("data-bitpalm-field"),64).toLowerCase().replace(/[_\s]+/g,"-")}function ot(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function it(t,o){let m=[],a=(i,x=140)=>{let l=d(i,x);l&&m.push(l)};a(o.name),a(o.id),a(o.getAttribute("autocomplete")),a(o.getAttribute("placeholder")),a(o.getAttribute("aria-label")),a(o.getAttribute("data-field")),a(o.getAttribute("data-name")),a(o.getAttribute("data-label")),a(o.getAttribute("data-bp-field")),a(o.getAttribute("data-bitpalm-field"));let p=new Set,w=i=>{let x=d(i,200);!x||p.has(x)||(p.add(x),m.push(x))};for(let i of Array.from(o.labels||[]))w(i.textContent);if(o.id){let i=t.querySelector(`label[for="${ot(o.id)}"]`);w(i?.textContent)}let y=o.closest("label");w(y?.textContent);let r=o.getAttribute("aria-labelledby");if(r)for(let i of r.split(/\s+/)){if(!i)continue;let x=t.ownerDocument.getElementById(i);w(x?.textContent)}return m}function st(t){let o=d(U(t,["[data-bp-email]","[data-bitpalm-email]"]),140).toLowerCase(),m=_(U(t,["[data-bp-phone]","[data-bitpalm-phone]"])),a=d(U(t,["[data-bp-name]","[data-bitpalm-name]","[data-bp-full-name]","[data-bitpalm-full-name]"])),p=d(U(t,["[data-bp-first-name]","[data-bitpalm-first-name]"])),w=d(U(t,["[data-bp-last-name]","[data-bitpalm-last-name]"])),y=d(U(t,["[data-bp-company]","[data-bitpalm-company]"]));for(let l of Array.from(t.elements)){if(!(l instanceof HTMLInputElement||l instanceof HTMLTextAreaElement||l instanceof HTMLSelectElement)||l.disabled||l instanceof HTMLInputElement&&Ze.has(l.type.toLowerCase()))continue;let g=nt(l),u=l.hasAttribute("data-bp-email")||l.hasAttribute("data-bitpalm-email")||l.hasAttribute("data-bp-phone")||l.hasAttribute("data-bitpalm-phone")||l.hasAttribute("data-bp-name")||l.hasAttribute("data-bitpalm-name")||l.hasAttribute("data-bp-full-name")||l.hasAttribute("data-bitpalm-full-name")||l.hasAttribute("data-bp-first-name")||l.hasAttribute("data-bitpalm-first-name")||l.hasAttribute("data-bp-last-name")||l.hasAttribute("data-bitpalm-last-name")||l.hasAttribute("data-bp-company")||l.hasAttribute("data-bitpalm-company")||!!g;if(l instanceof HTMLInputElement&&l.type.toLowerCase()==="hidden"&&!u)continue;let c=d(l.value);if(!c)continue;let $=l instanceof HTMLInputElement?l.type.toLowerCase():"",S=tt(it(t,l).join(" "));if(!o&&g==="email"&&A(c)){o=c.toLowerCase();continue}if(!m&&(g==="phone"||g==="tel"||g==="mobile"||g==="whatsapp")){let I=_(c);if(I){m=I;continue}}if(!y&&g==="company"){y=d(c,160);continue}if(!p&&(g==="first-name"||g==="firstname")){p=d(c,100);continue}if(!w&&(g==="last-name"||g==="lastname"||g==="surname")){w=d(c,100);continue}if(!a&&(g==="name"||g==="full-name"||g==="fullname")){!A(c)&&!_(c)&&(a=d(c,140));continue}let j=$==="email"||W(S,[" email "," e mail "," mail "," email adresse "," mailadresse "," correo "]),O=$==="tel"||W(S,[" phone "," phone number "," mobile "," tel "," telefon "," telefonnummer "," whatsapp "," handy "," kontakt "," nummer "]),H=W(S,[" company "," company name "," firma "," firmenname "," organization "," organisation "," business "," unternehmen "," agency "," brokerage "]),N=W(S,[" first name "," firstname "," given name "," givenname "," vorname "," fname "]),R=W(S,[" last name "," lastname "," family name "," familyname "," surname "," nachname "," lname "]),z=W(S,[" full name "," fullname "," contact name "," name "])&&!j&&!O;if(!o&&j&&A(c)){o=c.toLowerCase();continue}if(!m&&O){let I=_(c);if(I){m=I;continue}}if(!y&&H){y=d(c,160);continue}if(!p&&N){p=d(c,100);continue}if(!w&&R){w=d(c,100);continue}if(!a&&z&&!A(c)&&!_(c)){a=d(c,140);continue}!o&&A(c)&&(o=c.toLowerCase())}if(a&&(A(a)||_(a))&&(a=""),y&&(A(y)||_(y))&&(y=""),a||(a=d([p,w].filter(Boolean).join(" "),140)),a&&o&&a.toLowerCase()===o.toLowerCase()&&(a=""),!!!(o||m)&&!!!(a&&y))return null;let x={...a?{name:a}:{},...o?{email:o}:{},...m?{phone:m}:{},...y?{company:y}:{}};return Object.keys(x).length>0?x:null}function at(){if(typeof document<"u"){let t=document.documentElement.lang;if(t)return t.slice(0,2).toLowerCase()}return"en"}function ue(t,o=1200){if(typeof window<"u"&&"requestIdleCallback"in window){window.requestIdleCallback(t,{timeout:o});return}setTimeout(t,Math.min(o,300))}function fe(){if(typeof window>"u")return!1;let t=typeof navigator<"u"?navigator.userAgent:"";if(/Android|iPhone|iPad|iPod|IEMobile|Windows Phone|Mobile/i.test(t))return!0;let m=window.matchMedia("(pointer: coarse)").matches,a=window.matchMedia("(hover: none)").matches,p=Math.min(window.screen?.width||window.innerWidth,window.screen?.height||window.innerHeight);return m&&a&&p<=900}function Q(t){let{slug:o,locale:m=at(),baseUrl:a=Xe,token:p,zIndex:w=9999,autoIdentify:y=!0}=t,r=document,i=r.createElement("iframe"),x=`${a}/t/${o}/widget`,l=new URLSearchParams({locale:m});p&&l.set("token",p),i.src=`${x}?${l.toString()}`,i.allow="clipboard-write",i.setAttribute("allowtransparency","true"),i.loading="lazy",i.style.cssText=`position:fixed;bottom:0;right:0;width:1px;height:1px;border:none;z-index:${w};background:transparent;color-scheme:normal;opacity:0;pointer-events:none;`;let g=new URL(i.src).origin,u=r.createElement("div");if(u.setAttribute("role","button"),u.setAttribute("aria-label","Chat"),u.style.cssText=`position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;display:none;align-items:center;justify-content:center;cursor:pointer;z-index:${w-1};background:#00ff41;box-shadow:0 0 15px rgba(0,255,65,0.31);transition:transform .2s,opacity .3s;opacity:0;`,u.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/></svg>',u.onmouseenter=()=>{u.style.transform="scale(1.1)"},u.onmouseleave=()=>{u.style.transform="scale(1)"},u.onclick=()=>X(),r.body.appendChild(u),!r.getElementById("_bp_fade")){let e=r.createElement("style");e.id="_bp_fade",e.textContent="@keyframes _bp_fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",r.head.appendChild(e)}let c=null,$=!1,S=!1,j=!1,O=!1,H=!1,N=()=>{j||(j=!0,r.body.appendChild(i))},R=!1,z=0,I={overflow:"",overscrollBehavior:""},v={overflow:"",overscrollBehavior:"",position:"",top:"",left:"",right:"",width:""},pe=()=>{if(R||!fe())return;let s=r.documentElement,n=r.body;z=window.scrollY||window.pageYOffset||0,I.overflow=s.style.overflow,I.overscrollBehavior=s.style.overscrollBehavior,v.overflow=n.style.overflow,v.overscrollBehavior=n.style.overscrollBehavior,v.position=n.style.position,v.top=n.style.top,v.left=n.style.left,v.right=n.style.right,v.width=n.style.width,s.style.overflow="hidden",s.style.overscrollBehavior="none",n.style.overflow="hidden",n.style.overscrollBehavior="none",n.style.position="fixed",n.style.top=`-${z}px`,n.style.left="0",n.style.right="0",n.style.width="100%",R=!0},F=()=>{if(!R)return;let e=r.documentElement,s=r.body;e.style.overflow=I.overflow,e.style.overscrollBehavior=I.overscrollBehavior,s.style.overflow=v.overflow,s.style.overscrollBehavior=v.overscrollBehavior,s.style.position=v.position,s.style.top=v.top,s.style.left=v.left,s.style.right=v.right,s.style.width=v.width,window.scrollTo(0,z),R=!1},ge=()=>{let e=fe();i.style.display==="none"&&(i.style.display=""),e?(i.style.width="100vw",i.style.height="100dvh",i.style.left="0",i.style.top="0",i.style.bottom="0",i.style.right="0",pe()):(i.style.width="420px",i.style.height="620px",i.style.bottom="24px",i.style.right="24px",i.style.left="",i.style.top="",F()),i.style.opacity="1",i.style.pointerEvents="auto"},C=()=>{c&&(c.remove(),c=null)},J=()=>{},ee=()=>{},D=!1,P=new Map;function te(e,s){let n=P.get(e);if(n)for(let f of n)try{f(s)}catch{}}let ye=e=>{if(e.origin===g){if(e.data?.type==="bitpalm-widget-config"){S=!1,$=!0,i.style.display==="none"&&(i.style.display=""),e.data.primaryColor&&(u.style.background=e.data.primaryColor,u.style.boxShadow=e.data.chatShadow==="none"?"none":`0 0 15px ${e.data.primaryColor}50`);let s=e.data.chatButtonIconColor||"black";if(e.data.chatButtonIconSvg){u.innerHTML="";let n=r.createElement("span");n.style.cssText=`display:flex;align-items:center;justify-content:center;width:24px;height:24px;color:${s}`;let b=new DOMParser().parseFromString(e.data.chatButtonIconSvg,"image/svg+xml").querySelector("svg");b?(b.querySelectorAll("script,foreignObject").forEach(B=>B.remove()),b.querySelectorAll("*").forEach(B=>{for(let k of[...B.attributes])(k.name.startsWith("on")||k.value&&k.value.includes("javascript:"))&&B.removeAttribute(k.name)}),b.setAttribute("width","24"),b.setAttribute("height","24"),b.style.display="block",n.appendChild(b)):n.innerHTML='<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"><path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/></svg>',u.appendChild(n)}else{let n=u.querySelector("svg");n&&(n.style.stroke=s)}u.style.display="flex",requestAnimationFrame(()=>{u.style.opacity="1"})}if(e.data?.type==="bitpalm-widget-resize"){let s=e.data.width>0,n=D;D=s,s&&!n&&te("widget_opened"),!s&&n&&te("widget_closed");let f=fe();s?(i.style.width=f?"100vw":`${e.data.width}px`,i.style.height=f?"100dvh":`${e.data.height}px`,f?(i.style.left="0",i.style.top="0",i.style.bottom="0",i.style.right="0",pe()):F(),i.style.opacity="1",i.style.pointerEvents="auto"):(F(),i.style.width="1px",i.style.height="1px",i.style.left="",i.style.top="",i.style.opacity="0",i.style.pointerEvents="none"),u.style.display=s?"none":"flex"}if(e.data?.type==="bitpalm-trigger-show"){if(S||!$)return;C(),c=r.createElement("div"),c.style.cssText=`position:fixed;bottom:90px;right:24px;max-width:240px;background:#fff;border-radius:16px;padding:12px 32px 12px 12px;box-shadow:0 2px 20px rgba(0,0,0,0.08);cursor:pointer;z-index:${w-1};font-family:system-ui,sans-serif;animation:_bp_fade .3s;`;let s=(e.data.message||"").replace(/</g,"<");c.innerHTML=`<p style="font-size:14px;color:#1f2937;margin:0;">${s}</p><div style="position:absolute;bottom:-8px;right:20px;width:0;height:0;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #fff;"></div>`;let n=r.createElement("button");n.style.cssText="position:absolute;top:-8px;right:-8px;width:28px;height:28px;border-radius:50%;background:#fff;border:none;box-shadow:0 1px 4px rgba(0,0,0,0.1);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:#9ca3af;",n.innerHTML="✕",n.onclick=f=>{f.stopPropagation(),C(),i.contentWindow?.postMessage({type:"bitpalm-trigger-dismiss"},"*")},c.onclick=()=>{if(C(),u.style.display="none",ge(),N(),!O){H=!0;return}i.contentWindow?.postMessage({type:"bitpalm-trigger-engaged",message:s},"*")},c.appendChild(n),r.body.appendChild(c)}e.data?.type==="bitpalm-trigger-hide"&&C(),e.data?.type==="bitpalm-request-context"&&J(),e.data?.type==="bitpalm-chat-event"&&e.data.event&&te(e.data.event,e.data.data),e.data?.type==="bitpalm-widget-blocked"&&(S=!0,$=!1,u.style.display="none",C(),F(),i.style.display="none")}};window.addEventListener("message",ye);let L=!1;try{L=localStorage.getItem(`${h}optout`)==="1"}catch{}let G=`${h}vid`,E="";if(!L){try{E=localStorage.getItem(G)||""}catch{}if(!E){let e=r.cookie.match(new RegExp(`(?:^|; )${G}=([^;]+)`));E=e?decodeURIComponent(e[1]):""}E||(E=crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,11)}`);try{localStorage.setItem(G,E)}catch{}try{r.cookie=`${G}=${encodeURIComponent(E)};path=/;max-age=31536000;SameSite=Lax`}catch{}}L||ue(()=>{try{let e=new URLSearchParams(location.search),s={};for(let T of["utm_source","utm_medium","utm_campaign","utm_term","utm_content"]){let b=e.get(T);b&&(s[T]=b)}let n=JSON.stringify({tenant_slug:o,visitor_id:E,url:location.href,referrer:r.referrer||void 0,...Object.keys(s).length>0?{utm:s}:{}}),f=`${a}/api/widget/impression`;typeof navigator.sendBeacon=="function"?navigator.sendBeacon(f,new Blob([n],{type:"application/json"})):fetch(f,{method:"POST",body:n,headers:{"Content-Type":"application/json"},keepalive:!0}).catch(()=>{})}catch{}},2e3);let ne="",oe="",ie=0;try{ne=sessionStorage.getItem(Ne)||"",oe=sessionStorage.getItem(Re)||"";let e=parseInt(sessionStorage.getItem(Fe)||"0",10);Number.isFinite(e)&&e>0&&(ie=e)}catch{}let he=(e,s="")=>{if(L||!E)return;let n={},f=d(e.name,140),T=De(e.email),b=_(e.phone),B=d(e.company,160),k=d(e.external_user_id,140),ke=d(e.signature,260),le=Number(e.signed_at);if(f&&(n.name=f),T&&(n.email=T),b&&(n.phone=b),B&&(n.company=B),k&&(n.external_user_id=k),ke&&(n.signature=ke),Number.isFinite(le)&&le>0&&(n.signed_at=Math.floor(le)),(e.signature_version==="v1"||n.signature)&&(n.signature_version="v1"),(e.identify_source==="manual"||e.identify_source==="form")&&(n.identify_source=e.identify_source),!n.name&&!n.email&&!n.phone&&!n.company&&!n.external_user_id)return;let Z=et(n),ce=[s.toLowerCase(),Z].filter(Boolean).join("|"),de=Date.now();if(!(de-ie<Qe&&(ce===ne||Z===oe))){ne=ce,oe=Z,ie=de;try{sessionStorage.setItem(Ne,ce),sessionStorage.setItem(Re,Z),sessionStorage.setItem(Fe,String(de))}catch{}try{let $e=JSON.stringify({tenant_slug:o,visitor_id:E,url:location.href,referrer:r.referrer||void 0,...n}),Oe=`${a}/api/widget/identify`;typeof navigator.sendBeacon=="function"?navigator.sendBeacon(Oe,new Blob([$e],{type:"application/json"})):fetch(Oe,{method:"POST",body:$e,headers:{"Content-Type":"application/json"},keepalive:!0}).catch(()=>{})}catch{}}},be=e=>{if(L||!y||!E)return;let s=e.target instanceof HTMLFormElement?e.target:e.target instanceof Element?e.target.closest("form"):null;if(!(s instanceof HTMLFormElement))return;let n=(s.getAttribute("data-bp-identify")||s.getAttribute("data-bitpalm-identify")||"").toLowerCase();if(n==="off"||n==="false"||n==="0")return;let f=st(s);if(!f)return;let T=[s.getAttribute("id")||"",s.getAttribute("name")||"",s.getAttribute("action")||""].join("|");he({...f,identify_source:"form"},T)};!L&&y&&r.addEventListener("submit",be,!0);let q=parseInt(sessionStorage.getItem(`${h}pages`)||"0")+1;sessionStorage.setItem(`${h}pages`,String(q));let M=JSON.parse(sessionStorage.getItem(`${h}hist`)||"[]");M.push(location.href),M.length>20&&(M=M.slice(-20)),sessionStorage.setItem(`${h}hist`,JSON.stringify(M));let we=Date.now(),V=parseInt(sessionStorage.getItem(`${h}site_start`)||"0");V||(V=we,sessionStorage.setItem(`${h}site_start`,String(V)));let ve=[];J=()=>{let e=!1;try{e=!!localStorage.getItem(`${h}visited`)}catch{e=!1}if(i.contentWindow?.postMessage({type:"bitpalm-parent-context",url:location.href,title:r.title,returning:e,pageCount:q,pageHistory:M,loadedAt:we,siteStart:V,locale:m,visitorId:L?"":E},"*"),!e&&!L)try{localStorage.setItem(`${h}visited`,"1")}catch{}},i.addEventListener("load",()=>{O=!0,J(),[120,450,1100].forEach(e=>{let s=setTimeout(()=>J(),e);ve.push(s)}),H&&(H=!1,ee())}),r.readyState==="loading"?r.addEventListener("DOMContentLoaded",()=>ue(N,1600),{once:!0}):ue(N,1600);let xe=history.pushState.bind(history),Ee=history.replaceState.bind(history),K=()=>{q++,sessionStorage.setItem(`${h}pages`,String(q));let e=JSON.parse(sessionStorage.getItem(`${h}hist`)||"[]");if(e.push(location.href),e.length>20&&e.splice(0,e.length-20),M=e,sessionStorage.setItem(`${h}hist`,JSON.stringify(e)),i.contentWindow?.postMessage({type:"bitpalm-page-change",url:location.href,title:r.title,pageCount:q,pageHistory:e,loadedAt:Date.now()},"*"),!L)try{let s=JSON.stringify({tenant_slug:o,visitor_id:E,url:location.href}),n=`${a}/api/widget/impression`;typeof navigator.sendBeacon=="function"?navigator.sendBeacon(n,new Blob([s],{type:"application/json"})):fetch(n,{method:"POST",body:s,headers:{"Content-Type":"application/json"},keepalive:!0}).catch(()=>{})}catch{}};history.pushState=function(...e){xe(...e),K()},history.replaceState=function(...e){Ee(...e),K()},window.addEventListener("popstate",K);let Se=-1,se,Ie=()=>{clearTimeout(se),se=setTimeout(()=>{let e=Math.max(r.documentElement.scrollHeight,r.body.scrollHeight)-window.innerHeight,s=e>0?Math.round(window.scrollY/e*100):100;s!==Se&&(Se=s,i.contentWindow?.postMessage({type:"bitpalm-scroll-depth",percent:s},"*"))},500)};window.addEventListener("scroll",Ie,{passive:!0});let Le=e=>{e.clientY<=0&&i.contentWindow?.postMessage({type:"bitpalm-exit-intent"},"*")};r.addEventListener("mouseout",Le);let ae,Te=!1,re=()=>{clearTimeout(ae),!Te&&(ae=setTimeout(()=>{Te=!0,i.contentWindow?.postMessage({type:"bitpalm-inactivity"},"*")},15e3))},_e=["mousemove","keydown","scroll","touchstart"];_e.forEach(e=>r.addEventListener(e,re,{passive:!0})),re(),ee=()=>{i.contentWindow?.postMessage({type:"bitpalm-open"},"*");let e=i.src.split("#")[0];i.src=`${e}#bp-open-${Date.now()}`};let X=()=>{if(u.style.display="none",C(),ge(),N(),!O){H=!0;return}ee()},Ae=()=>{F(),i.contentWindow?.postMessage({type:"bitpalm-close"},"*")},Ce=e=>{!e||typeof e!="object"||he({external_user_id:d(e.externalUserId,140)||void 0,name:d(e.name,140)||void 0,email:De(e.email)||void 0,phone:_(e.phone)||void 0,company:d(e.company,160)||void 0,signature:d(e.signature,260)||void 0,signed_at:Number.isFinite(Number(e.signedAt))?Math.floor(Number(e.signedAt)):void 0,signature_version:e.signatureVersion==="v1"?"v1":void 0,identify_source:"manual"},"manual")},We=()=>{D?Ae():X()},Ue=()=>D,je=e=>{if(!e||typeof e!="string")return;let s=e.trim().slice(0,1e4);s&&(D||X(),setTimeout(()=>{i.contentWindow?.postMessage({type:"bitpalm-send-message",message:s},"*")},D?50:500))},Y={},Pe=e=>{if(!e||typeof e!="object"||Array.isArray(e))return;Y={...Y,...e};let s=JSON.stringify(Y);s.length>He&&console.warn(`[BitPalm] Custom context exceeds ${He} bytes (${s.length}). It may be truncated.`),i.contentWindow?.postMessage({type:"bitpalm-custom-context",data:Y},"*")},ze=()=>{Y={},i.contentWindow?.postMessage({type:"bitpalm-custom-context",data:{}},"*")},Me=e=>{let n=e.detail;if(!n||typeof n!="object")return;let f=d(n.slug,120);if(f&&f!==o)return;let{slug:T,...b}=n;Pe(b)};window.addEventListener("bitpalm-context",Me);let Be=e=>{let n=e.detail;if(!n||typeof n!="object")return;let f=d(n.slug,120);f&&f!==o||Ce(n)};return window.addEventListener("bitpalm-identify",Be),{open:X,close:Ae,toggle:We,isOpen:Ue,identify:Ce,context:Pe,resetContext:ze,send:je,on:(e,s)=>(P.has(e)||P.set(e,new Set),P.get(e).add(s),()=>P.get(e)?.delete(s)),off:(e,s)=>{P.get(e)?.delete(s)},destroy:()=>{window.removeEventListener("message",ye),window.removeEventListener("scroll",Ie),window.removeEventListener("popstate",K),r.removeEventListener("mouseout",Le),r.removeEventListener("submit",be,!0),_e.forEach(e=>r.removeEventListener(e,re)),clearTimeout(se),clearTimeout(ae),ve.forEach(e=>clearTimeout(e)),history.pushState=xe,history.replaceState=Ee,window.removeEventListener("bitpalm-identify",Be),window.removeEventListener("bitpalm-context",Me),P.clear(),F(),C(),u.remove(),i.remove()}}}function rt(t){if(t==null)return;let o=t.trim().toLowerCase();if(["1","true","yes","on"].includes(o))return!0;if(["0","false","no","off"].includes(o))return!1}if(typeof document<"u"){let t=document.currentScript;if(t?.dataset.slug){let o=()=>{Q({slug:t.dataset.slug,locale:t.dataset.locale,baseUrl:t.dataset.baseUrl,token:t.dataset.token,zIndex:t.dataset.zIndex?Number(t.dataset.zIndex):void 0,autoIdentify:rt(t.dataset.autoIdentify)})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",o):o()}}0&&(module.exports={createWidget});
|
|
1
|
+
"use strict";var ve=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var ft=Object.prototype.hasOwnProperty;var pt=(t,n)=>{for(var r in n)ve(t,r,{get:n[r],enumerable:!0})},gt=(t,n,r,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let m of ut(n))!ft.call(t,m)&&m!==r&&ve(t,m,{get:()=>n[m],enumerable:!(a=mt(n,m))||a.enumerable});return t};var ht=t=>gt(ve({},"__esModule",{value:!0}),t);var Pt={};pt(Pt,{createWidget:()=>oe,detectHostTheme:()=>H});module.exports=ht(Pt);var yt=["dark","dark-mode","dark-theme","theme-dark"],bt=["light","light-mode","light-theme","theme-light"],et=["data-theme","data-color-scheme","data-color-mode","data-mode","data-bs-theme"],tt="(prefers-color-scheme: dark)";function R(t){return t==="light"||t==="dark"?t:"auto"}function Ze(t){if(!t)return null;if(yt.some(n=>t.classList.contains(n)))return"dark";if(bt.some(n=>t.classList.contains(n)))return"light";for(let n of et){let r=(t.getAttribute(n)||"").toLowerCase();if(r.includes("dark"))return"dark";if(r.includes("light"))return"light"}return null}function we(t){let n=t/255;return n<=.03928?n/12.92:((n+.055)/1.055)**2.4}function Qe(t,n){if(!t)return null;let r=n.getComputedStyle(t).backgroundColor.match(/rgba?\(([^)]+)\)/);if(!r)return null;let[a,m,y,p=1]=r[1].split(/[\s,/]+/).filter(Boolean).map(Number);return[a,m,y,p].some(g=>Number.isNaN(g))||p<.5?null:.2126*we(a)+.7152*we(m)+.0722*we(y)<.2?"dark":"light"}function vt(t,n){let r=n.getComputedStyle(t.documentElement).colorScheme||"",a=t.querySelector('meta[name="color-scheme"]')?.getAttribute("content")||"",m=`${r} ${a}`.toLowerCase();return m.includes("dark")?m.includes("light")?n.matchMedia?.(tt).matches?"dark":"light":"dark":null}function H(t=document,n=window){return Ze(t.documentElement)??Ze(t.body)??Qe(t.body,n)??Qe(t.documentElement,n)??vt(t,n)??"light"}function Ee(t,n=document,r=window){let a=H(n,r),m=!1,y=()=>{m=!1;let c=H(n,r);c!==a&&(a=c,t(c))},p=()=>{m||(m=!0,typeof r.requestAnimationFrame=="function"?r.requestAnimationFrame(y):setTimeout(y,16))},l=typeof MutationObserver<"u"?new MutationObserver(p):null,g={attributes:!0,attributeFilter:["class","style",...et]};l?.observe(n.documentElement,g),n.body&&l?.observe(n.body,g);let b=typeof r.matchMedia=="function"?r.matchMedia(tt):null;return b?.addEventListener?.("change",p),()=>{l?.disconnect(),b?.removeEventListener?.("change",p)}}var wt="https://agents.bitpalm.ai",v="_bp_",Et=new Set(["password","file","checkbox","radio","submit","button","reset","image"]),xt=8e3,nt=4096,ot=`${v}identify_signature`,it=`${v}identify_fingerprint`,st=`${v}identify_sent_at`,at="0 4px 14px rgba(0,0,0,0.18)";function Tt(t){return[t.external_user_id||"",t.email||"",t.phone||"",t.name||"",t.company||"",t.signature||"",t.signed_at!=null?String(t.signed_at):"",t.signature_version||"",t.identify_source||""].join("|").toLowerCase()}function d(t,n=180){return t?t.replace(/\s+/g," ").trim().slice(0,n):""}function St(t){return t?` ${t.toLowerCase().replace(/[_-]+/g," ").replace(/[^a-z0-9\s@.]/g," ").replace(/\s+/g," ").trim()} `:""}function D(t,n){for(let r of n)if(t.includes(r))return!0;return!1}function A(t){return/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/i.test(t)}function _(t){let n=d(t,50);if(!n)return"";let r=n.startsWith("+"),a=n.replace(/\D/g,"");return a.length<6?"":`${r?"+":""}${a.slice(0,20)}`}function rt(t){let n=d(t,140).toLowerCase();return!n||!A(n)?"":n}function F(t,n){for(let r of n){let a=t.querySelector(r),m=d(a?.value);if(m)return m}return""}function Lt(t){return d(t.getAttribute("data-bp-field")||t.getAttribute("data-bitpalm-field"),64).toLowerCase().replace(/[_\s]+/g,"-")}function It(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function _t(t,n){let r=[],a=(g,b=140)=>{let c=d(g,b);c&&r.push(c)};a(n.name),a(n.id),a(n.getAttribute("autocomplete")),a(n.getAttribute("placeholder")),a(n.getAttribute("aria-label")),a(n.getAttribute("data-field")),a(n.getAttribute("data-name")),a(n.getAttribute("data-label")),a(n.getAttribute("data-bp-field")),a(n.getAttribute("data-bitpalm-field"));let m=new Set,y=g=>{let b=d(g,200);!b||m.has(b)||(m.add(b),r.push(b))};for(let g of Array.from(n.labels||[]))y(g.textContent);if(n.id){let g=t.querySelector(`label[for="${It(n.id)}"]`);y(g?.textContent)}let p=n.closest("label");y(p?.textContent);let l=n.getAttribute("aria-labelledby");if(l)for(let g of l.split(/\s+/)){if(!g)continue;let b=t.ownerDocument.getElementById(g);y(b?.textContent)}return r}function At(t){let n=d(F(t,["[data-bp-email]","[data-bitpalm-email]"]),140).toLowerCase(),r=_(F(t,["[data-bp-phone]","[data-bitpalm-phone]"])),a=d(F(t,["[data-bp-name]","[data-bitpalm-name]","[data-bp-full-name]","[data-bitpalm-full-name]"])),m=d(F(t,["[data-bp-first-name]","[data-bitpalm-first-name]"])),y=d(F(t,["[data-bp-last-name]","[data-bitpalm-last-name]"])),p=d(F(t,["[data-bp-company]","[data-bitpalm-company]"]));for(let c of Array.from(t.elements)){if(!(c instanceof HTMLInputElement||c instanceof HTMLTextAreaElement||c instanceof HTMLSelectElement)||c.disabled||c instanceof HTMLInputElement&&Et.has(c.type.toLowerCase()))continue;let i=Lt(c),ie=c.hasAttribute("data-bp-email")||c.hasAttribute("data-bitpalm-email")||c.hasAttribute("data-bp-phone")||c.hasAttribute("data-bitpalm-phone")||c.hasAttribute("data-bp-name")||c.hasAttribute("data-bitpalm-name")||c.hasAttribute("data-bp-full-name")||c.hasAttribute("data-bitpalm-full-name")||c.hasAttribute("data-bp-first-name")||c.hasAttribute("data-bitpalm-first-name")||c.hasAttribute("data-bp-last-name")||c.hasAttribute("data-bitpalm-last-name")||c.hasAttribute("data-bp-company")||c.hasAttribute("data-bitpalm-company")||!!i;if(c instanceof HTMLInputElement&&c.type.toLowerCase()==="hidden"&&!ie)continue;let f=d(c.value);if(!f)continue;let J=c instanceof HTMLInputElement?c.type.toLowerCase():"",u=St(_t(t,c).join(" "));if(!n&&i==="email"&&A(f)){n=f.toLowerCase();continue}if(!r&&(i==="phone"||i==="tel"||i==="mobile"||i==="whatsapp")){let S=_(f);if(S){r=S;continue}}if(!p&&i==="company"){p=d(f,160);continue}if(!m&&(i==="first-name"||i==="firstname")){m=d(f,100);continue}if(!y&&(i==="last-name"||i==="lastname"||i==="surname")){y=d(f,100);continue}if(!a&&(i==="name"||i==="full-name"||i==="fullname")){!A(f)&&!_(f)&&(a=d(f,140));continue}let T=J==="email"||D(u,[" email "," e mail "," mail "," email adresse "," mailadresse "," correo "]),$=J==="tel"||D(u,[" phone "," phone number "," mobile "," tel "," telefon "," telefonnummer "," whatsapp "," handy "," kontakt "," nummer "]),U=D(u,[" company "," company name "," firma "," firmenname "," organization "," organisation "," business "," unternehmen "," agency "," brokerage "]),G=D(u,[" first name "," firstname "," given name "," givenname "," vorname "," fname "]),j=D(u,[" last name "," lastname "," family name "," familyname "," surname "," nachname "," lname "]),O=D(u,[" full name "," fullname "," contact name "," name "])&&!T&&!$;if(!n&&T&&A(f)){n=f.toLowerCase();continue}if(!r&&$){let S=_(f);if(S){r=S;continue}}if(!p&&U){p=d(f,160);continue}if(!m&&G){m=d(f,100);continue}if(!y&&j){y=d(f,100);continue}if(!a&&O&&!A(f)&&!_(f)){a=d(f,140);continue}!n&&A(f)&&(n=f.toLowerCase())}if(a&&(A(a)||_(a))&&(a=""),p&&(A(p)||_(p))&&(p=""),a||(a=d([m,y].filter(Boolean).join(" "),140)),a&&n&&a.toLowerCase()===n.toLowerCase()&&(a=""),!!!(n||r)&&!!!(a&&p))return null;let b={...a?{name:a}:{},...n?{email:n}:{},...r?{phone:r}:{},...p?{company:p}:{}};return Object.keys(b).length>0?b:null}function Ct(){if(typeof document<"u"){let t=document.documentElement.lang;if(t)return t.slice(0,2).toLowerCase()}return"en"}function xe(t,n=1200){if(typeof window<"u"&&"requestIdleCallback"in window){window.requestIdleCallback(t,{timeout:n});return}setTimeout(t,Math.min(n,300))}function Te(){if(typeof window>"u")return!1;let t=typeof navigator<"u"?navigator.userAgent:"";if(/Android|iPhone|iPad|iPod|IEMobile|Windows Phone|Mobile/i.test(t))return!0;let r=window.matchMedia("(pointer: coarse)").matches,a=window.matchMedia("(hover: none)").matches,m=Math.min(window.screen?.width||window.innerWidth,window.screen?.height||window.innerHeight);return r&&a&&m<=900}function oe(t){let{slug:n,locale:r=Ct(),baseUrl:a=wt,token:m,zIndex:y=9999,autoIdentify:p=!0}=t,l=document,g=R(t.theme),b=g==="auto"?H():g,c=null,i=l.createElement("iframe"),ie=`${a}/t/${n}/widget`,f=new URLSearchParams({locale:r,theme:b});m&&f.set("token",m),i.src=`${ie}?${f.toString()}`,i.allow="clipboard-write; microphone",i.setAttribute("allowtransparency","true"),i.loading="lazy",i.style.cssText=`position:fixed;bottom:0;right:0;width:1px;height:1px;border:none;z-index:${y};background:transparent;color-scheme:normal;opacity:0;pointer-events:none;`;let J=new URL(i.src).origin,u=l.createElement("div");if(u.setAttribute("role","button"),u.setAttribute("aria-label","Chat"),u.style.cssText=`position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;display:none;align-items:center;justify-content:center;cursor:pointer;z-index:${y-1};background:#171717;box-shadow:${at};transition:transform .2s,opacity .3s;opacity:0;`,u.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/></svg>',u.onmouseenter=()=>{u.style.transform="scale(1.05)"},u.onmouseleave=()=>{u.style.transform="scale(1)"},u.onclick=()=>q(),l.body.appendChild(u),!l.getElementById("_bp_fade")){let e=l.createElement("style");e.id="_bp_fade",e.textContent="@keyframes _bp_fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",l.head.appendChild(e)}let T=null,$=!1,U=!1,G=!1,j=!1,O=!1,S=()=>{G||(G=!0,l.body.appendChild(i))},K=!1,se=0,V={overflow:"",overscrollBehavior:""},E={overflow:"",overscrollBehavior:"",position:"",top:"",left:"",right:"",width:""},Se=()=>{if(K||!Te())return;let s=l.documentElement,o=l.body;se=window.scrollY||window.pageYOffset||0,V.overflow=s.style.overflow,V.overscrollBehavior=s.style.overscrollBehavior,E.overflow=o.style.overflow,E.overscrollBehavior=o.style.overscrollBehavior,E.position=o.style.position,E.top=o.style.top,E.left=o.style.left,E.right=o.style.right,E.width=o.style.width,s.style.overflow="hidden",s.style.overscrollBehavior="none",o.style.overflow="hidden",o.style.overscrollBehavior="none",o.style.position="fixed",o.style.top=`-${se}px`,o.style.left="0",o.style.right="0",o.style.width="100%",K=!0},N=()=>{if(!K)return;let e=l.documentElement,s=l.body;e.style.overflow=V.overflow,e.style.overscrollBehavior=V.overscrollBehavior,s.style.overflow=E.overflow,s.style.overscrollBehavior=E.overscrollBehavior,s.style.position=E.position,s.style.top=E.top,s.style.left=E.left,s.style.right=E.right,s.style.width=E.width,window.scrollTo(0,se),K=!1},Le=()=>{let e=Te();i.style.display==="none"&&(i.style.display=""),e?(i.style.width="100vw",i.style.height="100dvh",i.style.left="0",i.style.top="0",i.style.bottom="0",i.style.right="0",Se()):(i.style.width="420px",i.style.height="620px",i.style.bottom="24px",i.style.right="24px",i.style.left="",i.style.top="",N()),i.style.opacity="1",i.style.pointerEvents="auto"},C=()=>{T&&(T.remove(),T=null)},X=()=>{},ae=()=>{},W=!1,k=new Map;function re(e,s){let o=k.get(e);if(o)for(let h of o)try{h(s)}catch{}}let Ie=e=>{if(e.origin===J){if(e.data?.type==="bitpalm-widget-config"){U=!1,$=!0,i.style.display==="none"&&(i.style.display=""),e.data.primaryColor&&(u.style.background=e.data.primaryColor,u.style.boxShadow=e.data.chatShadow==="none"?"none":at);let s=e.data.chatButtonIconColor||"black";if(e.data.chatButtonIconSvg){u.innerHTML="";let o=l.createElement("span");o.style.cssText=`display:flex;align-items:center;justify-content:center;width:24px;height:24px;color:${s}`;let w=new DOMParser().parseFromString(e.data.chatButtonIconSvg,"image/svg+xml").querySelector("svg");w?(w.querySelectorAll("script,foreignObject").forEach(B=>B.remove()),w.querySelectorAll("*").forEach(B=>{for(let M of[...B.attributes])(M.name.startsWith("on")||M.value&&M.value.includes("javascript:"))&&B.removeAttribute(M.name)}),w.setAttribute("width","24"),w.setAttribute("height","24"),w.style.display="block",o.appendChild(w)):o.innerHTML='<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"><path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/></svg>',u.appendChild(o)}else{let o=u.querySelector("svg");o&&(o.style.stroke=s)}u.style.display="flex",requestAnimationFrame(()=>{u.style.opacity="1"})}if(e.data?.type==="bitpalm-widget-resize"){let s=e.data.width>0,o=W;W=s,s&&!o&&re("widget_opened"),!s&&o&&re("widget_closed");let h=Te();s?(i.style.width=h?"100vw":`${e.data.width}px`,i.style.height=h?"100dvh":`${e.data.height}px`,h?(i.style.left="0",i.style.top="0",i.style.bottom="0",i.style.right="0",Se()):N(),i.style.opacity="1",i.style.pointerEvents="auto"):(N(),i.style.width="1px",i.style.height="1px",i.style.left="",i.style.top="",i.style.opacity="0",i.style.pointerEvents="none"),u.style.display=s?"none":"flex"}if(e.data?.type==="bitpalm-trigger-show"){if(U||!$)return;C(),T=l.createElement("div"),T.style.cssText=`position:fixed;bottom:90px;right:24px;max-width:240px;background:#fff;border-radius:16px;padding:12px 32px 12px 12px;box-shadow:0 2px 20px rgba(0,0,0,0.08);cursor:pointer;z-index:${y-1};font-family:system-ui,sans-serif;animation:_bp_fade .3s;`;let s=(e.data.message||"").replace(/</g,"<");T.innerHTML=`<p style="font-size:14px;color:#1f2937;margin:0;">${s}</p><div style="position:absolute;bottom:-8px;right:20px;width:0;height:0;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #fff;"></div>`;let o=l.createElement("button");o.style.cssText="position:absolute;top:-8px;right:-8px;width:28px;height:28px;border-radius:50%;background:#fff;border:none;box-shadow:0 1px 4px rgba(0,0,0,0.1);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:#9ca3af;",o.innerHTML="✕",o.onclick=h=>{h.stopPropagation(),C(),i.contentWindow?.postMessage({type:"bitpalm-trigger-dismiss"},"*")},T.onclick=()=>{if(C(),u.style.display="none",Le(),S(),!j){O=!0;return}i.contentWindow?.postMessage({type:"bitpalm-trigger-engaged",message:s},"*")},T.appendChild(o),l.body.appendChild(T)}e.data?.type==="bitpalm-trigger-hide"&&C(),e.data?.type==="bitpalm-request-context"&&X(),e.data?.type==="bitpalm-chat-event"&&e.data.event&&re(e.data.event,e.data.data),e.data?.type==="bitpalm-widget-blocked"&&(U=!0,$=!1,u.style.display="none",C(),N(),i.style.display="none")}};window.addEventListener("message",Ie);let L=!1;try{L=localStorage.getItem(`${v}optout`)==="1"}catch{}let Z=`${v}vid`,x="";if(!L){try{x=localStorage.getItem(Z)||""}catch{}if(!x){let e=l.cookie.match(new RegExp(`(?:^|; )${Z}=([^;]+)`));x=e?decodeURIComponent(e[1]):""}x||(x=crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,11)}`);try{localStorage.setItem(Z,x)}catch{}try{l.cookie=`${Z}=${encodeURIComponent(x)};path=/;max-age=31536000;SameSite=Lax`}catch{}}L||xe(()=>{try{let e=new URLSearchParams(location.search),s={};for(let I of["utm_source","utm_medium","utm_campaign","utm_term","utm_content"]){let w=e.get(I);w&&(s[I]=w)}let o=JSON.stringify({tenant_slug:n,visitor_id:x,url:location.href,referrer:l.referrer||void 0,...Object.keys(s).length>0?{utm:s}:{}}),h=`${a}/api/widget/impression`;typeof navigator.sendBeacon=="function"?navigator.sendBeacon(h,new Blob([o],{type:"application/json"})):fetch(h,{method:"POST",body:o,headers:{"Content-Type":"application/json"},keepalive:!0}).catch(()=>{})}catch{}},2e3);let le="",ce="",de=0;try{le=sessionStorage.getItem(ot)||"",ce=sessionStorage.getItem(it)||"";let e=parseInt(sessionStorage.getItem(st)||"0",10);Number.isFinite(e)&&e>0&&(de=e)}catch{}let _e=(e,s="")=>{if(L||!x)return;let o={},h=d(e.name,140),I=rt(e.email),w=_(e.phone),B=d(e.company,160),M=d(e.external_user_id,140),Ke=d(e.signature,260),he=Number(e.signed_at);if(h&&(o.name=h),I&&(o.email=I),w&&(o.phone=w),B&&(o.company=B),M&&(o.external_user_id=M),Ke&&(o.signature=Ke),Number.isFinite(he)&&he>0&&(o.signed_at=Math.floor(he)),(e.signature_version==="v1"||o.signature)&&(o.signature_version="v1"),(e.identify_source==="manual"||e.identify_source==="form")&&(o.identify_source=e.identify_source),!o.name&&!o.email&&!o.phone&&!o.company&&!o.external_user_id)return;let ne=Tt(o),ye=[s.toLowerCase(),ne].filter(Boolean).join("|"),be=Date.now();if(!(be-de<xt&&(ye===le||ne===ce))){le=ye,ce=ne,de=be;try{sessionStorage.setItem(ot,ye),sessionStorage.setItem(it,ne),sessionStorage.setItem(st,String(be))}catch{}try{let Ve=JSON.stringify({tenant_slug:n,visitor_id:x,url:location.href,referrer:l.referrer||void 0,...o}),Xe=`${a}/api/widget/identify`;typeof navigator.sendBeacon=="function"?navigator.sendBeacon(Xe,new Blob([Ve],{type:"application/json"})):fetch(Xe,{method:"POST",body:Ve,headers:{"Content-Type":"application/json"},keepalive:!0}).catch(()=>{})}catch{}}},Ae=e=>{if(L||!p||!x)return;let s=e.target instanceof HTMLFormElement?e.target:e.target instanceof Element?e.target.closest("form"):null;if(!(s instanceof HTMLFormElement))return;let o=(s.getAttribute("data-bp-identify")||s.getAttribute("data-bitpalm-identify")||"").toLowerCase();if(o==="off"||o==="false"||o==="0")return;let h=At(s);if(!h)return;let I=[s.getAttribute("id")||"",s.getAttribute("name")||"",s.getAttribute("action")||""].join("|");_e({...h,identify_source:"form"},I)};!L&&p&&l.addEventListener("submit",Ae,!0);let z=parseInt(sessionStorage.getItem(`${v}pages`)||"0")+1;sessionStorage.setItem(`${v}pages`,String(z));let P=JSON.parse(sessionStorage.getItem(`${v}hist`)||"[]");P.push(location.href),P.length>20&&(P=P.slice(-20)),sessionStorage.setItem(`${v}hist`,JSON.stringify(P));let Ce=Date.now(),Q=parseInt(sessionStorage.getItem(`${v}site_start`)||"0");Q||(Q=Ce,sessionStorage.setItem(`${v}site_start`,String(Q)));let ke=[];X=()=>{let e=!1;try{e=!!localStorage.getItem(`${v}visited`)}catch{e=!1}if(i.contentWindow?.postMessage({type:"bitpalm-parent-context",url:location.href,title:l.title,returning:e,pageCount:z,pageHistory:P,loadedAt:Ce,siteStart:Q,locale:r,visitorId:L?"":x},"*"),De(),!e&&!L)try{localStorage.setItem(`${v}visited`,"1")}catch{}},i.addEventListener("load",()=>{j=!0,X(),[120,450,1100].forEach(e=>{let s=setTimeout(()=>X(),e);ke.push(s)}),O&&(O=!1,ae())}),l.readyState==="loading"?l.addEventListener("DOMContentLoaded",()=>xe(S,1600),{once:!0}):xe(S,1600);let Pe=history.pushState.bind(history),Be=history.replaceState.bind(history),ee=()=>{z++,sessionStorage.setItem(`${v}pages`,String(z));let e=JSON.parse(sessionStorage.getItem(`${v}hist`)||"[]");if(e.push(location.href),e.length>20&&e.splice(0,e.length-20),P=e,sessionStorage.setItem(`${v}hist`,JSON.stringify(e)),i.contentWindow?.postMessage({type:"bitpalm-page-change",url:location.href,title:l.title,pageCount:z,pageHistory:e,loadedAt:Date.now()},"*"),!L)try{let s=JSON.stringify({tenant_slug:n,visitor_id:x,url:location.href}),o=`${a}/api/widget/impression`;typeof navigator.sendBeacon=="function"?navigator.sendBeacon(o,new Blob([s],{type:"application/json"})):fetch(o,{method:"POST",body:s,headers:{"Content-Type":"application/json"},keepalive:!0}).catch(()=>{})}catch{}};history.pushState=function(...e){Pe(...e),ee()},history.replaceState=function(...e){Be(...e),ee()},window.addEventListener("popstate",ee);let Me=-1,me,He=()=>{clearTimeout(me),me=setTimeout(()=>{let e=Math.max(l.documentElement.scrollHeight,l.body.scrollHeight)-window.innerHeight,s=e>0?Math.round(window.scrollY/e*100):100;s!==Me&&(Me=s,i.contentWindow?.postMessage({type:"bitpalm-scroll-depth",percent:s},"*"))},500)};window.addEventListener("scroll",He,{passive:!0});let $e=e=>{e.clientY<=0&&i.contentWindow?.postMessage({type:"bitpalm-exit-intent"},"*")};l.addEventListener("mouseout",$e);let ue,Oe=!1,fe=()=>{clearTimeout(ue),!Oe&&(ue=setTimeout(()=>{Oe=!0,i.contentWindow?.postMessage({type:"bitpalm-inactivity"},"*")},15e3))},Ne=["mousemove","keydown","scroll","touchstart"];Ne.forEach(e=>l.addEventListener(e,fe,{passive:!0})),fe(),ae=()=>{i.contentWindow?.postMessage({type:"bitpalm-open"},"*");let e=i.src.split("#")[0];i.src=`${e}#bp-open-${Date.now()}`};let q=()=>{if(u.style.display="none",C(),Le(),S(),!j){O=!0;return}ae()},pe=()=>{N(),i.contentWindow?.postMessage({type:"bitpalm-close"},"*")},We=e=>{!e||typeof e!="object"||_e({external_user_id:d(e.externalUserId,140)||void 0,name:d(e.name,140)||void 0,email:rt(e.email)||void 0,phone:_(e.phone)||void 0,company:d(e.company,160)||void 0,signature:d(e.signature,260)||void 0,signed_at:Number.isFinite(Number(e.signedAt))?Math.floor(Number(e.signedAt)):void 0,signature_version:e.signatureVersion==="v1"?"v1":void 0,identify_source:"manual"},"manual")},lt=()=>{W?pe():q()},ct=()=>W,Re=e=>{if(!e||typeof e!="string")return;let s=e.trim().slice(0,1e4);s&&(W||q(),setTimeout(()=>{i.contentWindow?.postMessage({type:"bitpalm-send-message",message:s},"*")},W?50:500))};function De(){i.contentWindow?.postMessage({type:"bitpalm-theme",theme:b},"*")}let te=e=>{e!==b&&(b=e,De())},Fe=e=>{g=R(e),c?.(),c=null,g==="auto"?(c=Ee(te),te(H())):te(g)};g==="auto"&&(c=Ee(te));let Ue=e=>{let s=e.detail;if(!s||typeof s!="object")return;let o=d(s.slug,120);o&&o!==n||Fe(R(s.theme))};window.addEventListener("bitpalm-theme",Ue);let Y={},je=e=>{if(!e||typeof e!="object"||Array.isArray(e))return;Y={...Y,...e};let s=JSON.stringify(Y);s.length>nt&&console.warn(`[BitPalm] Custom context exceeds ${nt} bytes (${s.length}). It may be truncated.`),i.contentWindow?.postMessage({type:"bitpalm-custom-context",data:Y},"*")},dt=()=>{Y={},i.contentWindow?.postMessage({type:"bitpalm-custom-context",data:{}},"*")},ze=e=>{let o=e.detail;if(!o||typeof o!="object")return;let h=d(o.slug,120);if(h&&h!==n)return;let{slug:I,...w}=o;je(w)};window.addEventListener("bitpalm-context",ze);let qe=e=>{let o=e.detail;if(!o||typeof o!="object")return;let h=d(o.slug,120);h&&h!==n||We(o)};window.addEventListener("bitpalm-identify",qe);let ge=e=>{let s=e.detail,o=d(s?.slug,120);return!o||o===n},Ye=e=>{ge(e)&&q()},Je=e=>{ge(e)&&pe()},Ge=e=>{if(!ge(e))return;let s=e.detail?.message;typeof s=="string"&&Re(s)};return window.addEventListener("bitpalm-open",Ye),window.addEventListener("bitpalm-close",Je),window.addEventListener("bitpalm-send",Ge),{open:q,close:pe,toggle:lt,isOpen:ct,identify:We,context:je,resetContext:dt,send:Re,on:(e,s)=>(k.has(e)||k.set(e,new Set),k.get(e).add(s),()=>k.get(e)?.delete(s)),off:(e,s)=>{k.get(e)?.delete(s)},setTheme:Fe,destroy:()=>{window.removeEventListener("message",Ie),window.removeEventListener("scroll",He),window.removeEventListener("popstate",ee),l.removeEventListener("mouseout",$e),l.removeEventListener("submit",Ae,!0),Ne.forEach(e=>l.removeEventListener(e,fe)),clearTimeout(me),clearTimeout(ue),ke.forEach(e=>clearTimeout(e)),history.pushState=Pe,history.replaceState=Be,window.removeEventListener("bitpalm-identify",qe),window.removeEventListener("bitpalm-context",ze),window.removeEventListener("bitpalm-theme",Ue),window.removeEventListener("bitpalm-open",Ye),window.removeEventListener("bitpalm-close",Je),window.removeEventListener("bitpalm-send",Ge),c?.(),k.clear(),N(),C(),u.remove(),i.remove()}}}function kt(t){if(t==null)return;let n=t.trim().toLowerCase();if(["1","true","yes","on"].includes(n))return!0;if(["0","false","no","off"].includes(n))return!1}if(typeof document<"u"){let t=document.currentScript;if(t?.dataset.slug){let n=()=>{oe({slug:t.dataset.slug,locale:t.dataset.locale,baseUrl:t.dataset.baseUrl,token:t.dataset.token,zIndex:t.dataset.zIndex?Number(t.dataset.zIndex):void 0,autoIdentify:kt(t.dataset.autoIdentify),theme:R(t.dataset.theme)})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",n):n()}}0&&(module.exports={createWidget,detectHostTheme});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|