ramonai-widget 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 RamonAI
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,98 @@
1
+ ```markdown
2
+ # RamonAI Widget
3
+
4
+ A responsive shopping assistant widget built with React and Vite. It renders a floating launcher and a chat panel that you can drop into any storefront.
5
+
6
+ ## Local development
7
+
8
+ Install dependencies and run the demo page:
9
+
10
+ ```bash
11
+ npm install
12
+ npm run dev
13
+ ```
14
+
15
+ ## Build (production)
16
+
17
+ ```bash
18
+ npm run build
19
+ ```
20
+
21
+ The build outputs a single browser-safe bundle at `dist/ramonai-widget.js` (IIFE, styles inlined). It does not require Node.js polyfills in the browser.
22
+
23
+ ## Usage / embedding
24
+
25
+ ### 1) Single tag (CDN or self-hosted)
26
+
27
+ Add one script tag anywhere in your page. Works in all projects (vanilla HTML, React, Vue, Next.js, etc.). `type="module"` is fine, but not required.
28
+
29
+ ```html
30
+ <script
31
+ type="module"
32
+ id="ramonai-widget"
33
+ src="https://cdn.jsdelivr.net/npm/ramonai-widget@latest/dist/ramonai-widget.js"
34
+ data-shop-name="Your Shop"
35
+ data-accent="#242424"
36
+ <!-- data-target="#ramonai-host" -->
37
+ ></script>
38
+ ```
39
+
40
+ Supported attributes map to the public API:
41
+
42
+ - `data-shop-name`: display name shown in the UI.
43
+ - `data-accent` (alias `data-accent-color`): hex/color string for the accent.
44
+ - `data-target`: optional CSS selector for a host element to mount into. If omitted, the widget creates a fixed host element and mounts into `<body>`.
45
+
46
+ Note: `data-autoinit` is not required. The widget auto-initializes when it detects the `id="ramonai-widget"` script or any meaningful config attributes.
47
+
48
+ ### 2) Programmatic init (optional)
49
+
50
+ Load the bundle and call the global API:
51
+
52
+ ```html
53
+ <script src="/ramonai-widget.js"></script>
54
+ <script>
55
+ window.RamonAIWidget?.init({
56
+ shopName: "Example Shop",
57
+ accent: "#242424",
58
+ // target: document.querySelector('#ramonai-host'), // optional
59
+ });
60
+ // Later
61
+ // window.RamonAIWidget?.destroyAll();
62
+ // or keep the handle:
63
+ // const inst = window.RamonAIWidget?.init(...);
64
+ // inst?.destroy();
65
+ </script>
66
+ ```
67
+
68
+ ### Options
69
+
70
+ | name | type | default | description |
71
+ | --- | --- | --- | --- |
72
+ | `shopName` | `string` | `"فروشگاه شما"` | Display name shown in the widget greeting/labels. |
73
+ | `accent` | `string` | `#242424` | Accent color used by the UI. |
74
+ | `target` | `HTMLElement` | `undefined` | Optional host element to mount the widget into. If omitted, a default fixed host is appended to `<body>`. |
75
+
76
+ Notes:
77
+
78
+ - The script auto-initializes from the tag and reads the attributes listed above. `data-accent-color` is accepted as an alias for `data-accent`.
79
+ - The library build inlines `process.env` at build time, so no client polyfills are necessary.
80
+
81
+ ## Project structure
82
+
83
+ - `src/embed.tsx`: public embed API, auto-init, and mounting helpers.
84
+ - `src/widget/WidgetApp.tsx`: main widget UI and chat logic.
85
+ - `src/styles.css`: widget styles (inlined into the bundle).
86
+ - `src/main.tsx`: demo page used during local development.
87
+
88
+ ## Backend configuration (.env)
89
+
90
+ The chat API base URL is configured at build time via Vite env:
91
+
92
+ ```
93
+ VITE_API_BASE_URL=https://your-api.example.com/v1
94
+ ```
95
+
96
+ Create a `.env` (or `.env.production`) file with the variable above before running `npm run build`. The bundle will embed this value. At runtime, the widget cannot read server-side env; you must set it at build time.
97
+
98
+ `WidgetApp` posts messages to this `VITE_API_BASE_URL` and renders product suggestions from responses.