@boomitra/carbon-calculator 0.2.1 → 0.2.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/package.json +15 -13
- package/QUICK_START.md +0 -195
- package/WIDGET_INTEGRATION_GUIDE.md +0 -367
- package/dist/index.html +0 -35
- package/dist/vite.svg +0 -1
package/package.json
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@boomitra/carbon-calculator",
|
|
3
|
-
"version": "0.2.1",
|
|
4
|
-
"publishConfig": {
|
|
5
|
-
"access": "public"
|
|
6
|
-
},
|
|
7
|
-
"main": "dist/assets/index-DxrxmbE-.js",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist",
|
|
10
|
-
"README.md",
|
|
11
|
-
"LICENSE",
|
|
12
|
-
"QUICK_START.md",
|
|
13
|
-
"WIDGET_INTEGRATION_GUIDE.md"
|
|
14
|
-
],
|
|
15
2
|
"browserslist": {
|
|
16
3
|
"development": [
|
|
17
4
|
"last 1 chrome version",
|
|
@@ -39,6 +26,17 @@
|
|
|
39
26
|
"react-router-dom": "^7.5.0",
|
|
40
27
|
"web-vitals": "^4.2.4"
|
|
41
28
|
},
|
|
29
|
+
"main": "dist/package/index.cjs.js",
|
|
30
|
+
"module": "dist/package/index.es.js",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"import": "./dist/package/index.es.js",
|
|
34
|
+
"require": "./dist/package/index.cjs.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
42
40
|
"peerDependencies": {
|
|
43
41
|
"react": ">=17 <20",
|
|
44
42
|
"react-dom": ">=17 <20"
|
|
@@ -59,6 +57,10 @@
|
|
|
59
57
|
"eslintConfig": {
|
|
60
58
|
"root": true
|
|
61
59
|
},
|
|
60
|
+
"name": "@boomitra/carbon-calculator",
|
|
61
|
+
"private": false,
|
|
62
|
+
"type": "module",
|
|
63
|
+
"version": "0.2.2",
|
|
62
64
|
"scripts": {
|
|
63
65
|
"start": "vite",
|
|
64
66
|
"build": "vite build",
|
package/QUICK_START.md
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
# 🚀 Quick Start - Inject Calculator into Another Project
|
|
2
|
-
|
|
3
|
-
## ✅ What's Already Done
|
|
4
|
-
|
|
5
|
-
Your widget has been successfully built! Here's what you have:
|
|
6
|
-
|
|
7
|
-
- **Built Widget File**: `dist/carbon-calculator-widget.iife.js` (500.83 KB, gzipped: 188.34 KB)
|
|
8
|
-
- **Test Page**: `test-widget.html` (working at http://localhost:8000/test-widget.html)
|
|
9
|
-
- **Full Documentation**: `WIDGET_INTEGRATION_GUIDE.md`
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## 📋 3 Simple Steps to Inject into Any Project
|
|
14
|
-
|
|
15
|
-
### Step 1: Get the Widget File
|
|
16
|
-
```bash
|
|
17
|
-
# The widget is already built in:
|
|
18
|
-
dist/carbon-calculator-widget.iife.js
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Step 2: Upload to Your Server
|
|
22
|
-
Upload `dist/carbon-calculator-widget.iife.js` to:
|
|
23
|
-
- Your website's `/assets/` or `/js/` folder
|
|
24
|
-
- A CDN (AWS S3, Cloudflare, etc.)
|
|
25
|
-
- Any publicly accessible URL
|
|
26
|
-
|
|
27
|
-
### Step 3: Add 2 Lines of Code
|
|
28
|
-
Add these to any HTML page where you want the calculator:
|
|
29
|
-
|
|
30
|
-
```html
|
|
31
|
-
<!-- Load the widget -->
|
|
32
|
-
<script src="https://your-domain.com/path/to/carbon-calculator-widget.iife.js"></script>
|
|
33
|
-
|
|
34
|
-
<!-- Display the widget -->
|
|
35
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
**That's it!** 🎉
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## 💡 Real-World Examples
|
|
43
|
-
|
|
44
|
-
### Example 1: Plain HTML Website
|
|
45
|
-
```html
|
|
46
|
-
<!DOCTYPE html>
|
|
47
|
-
<html>
|
|
48
|
-
<head>
|
|
49
|
-
<title>My Website</title>
|
|
50
|
-
</head>
|
|
51
|
-
<body>
|
|
52
|
-
<h1>Calculate Your Carbon Footprint</h1>
|
|
53
|
-
|
|
54
|
-
<!-- Widget goes here -->
|
|
55
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
56
|
-
|
|
57
|
-
<!-- Load widget script -->
|
|
58
|
-
<script src="/assets/carbon-calculator-widget.iife.js"></script>
|
|
59
|
-
</body>
|
|
60
|
-
</html>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Example 2: WordPress
|
|
64
|
-
1. Upload `carbon-calculator-widget.iife.js` to your theme's folder or media library
|
|
65
|
-
2. Edit your page in HTML mode and add:
|
|
66
|
-
```html
|
|
67
|
-
<script src="/wp-content/themes/your-theme/carbon-calculator-widget.iife.js"></script>
|
|
68
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Example 3: React App
|
|
72
|
-
```jsx
|
|
73
|
-
import { useEffect } from 'react';
|
|
74
|
-
|
|
75
|
-
function CalculatorPage() {
|
|
76
|
-
useEffect(() => {
|
|
77
|
-
const script = document.createElement('script');
|
|
78
|
-
script.src = '/carbon-calculator-widget.iife.js';
|
|
79
|
-
document.body.appendChild(script);
|
|
80
|
-
}, []);
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<div>
|
|
84
|
-
<h1>Carbon Calculator</h1>
|
|
85
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Example 4: Shopify
|
|
92
|
-
1. Upload the file to Shopify Files
|
|
93
|
-
2. In your theme editor, add a Custom HTML section:
|
|
94
|
-
```html
|
|
95
|
-
<script src="{{ 'carbon-calculator-widget.iife.js' | asset_url }}"></script>
|
|
96
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
---
|
|
100
|
-
|
|
101
|
-
## 🧪 Testing Locally (Already Set Up!)
|
|
102
|
-
|
|
103
|
-
You can test the widget right now:
|
|
104
|
-
|
|
105
|
-
1. **Test Page**: http://localhost:8000/test-widget.html
|
|
106
|
-
2. **Preview Build**: http://localhost:4173/
|
|
107
|
-
|
|
108
|
-
Both are currently running! Open either URL in your browser to see the widget in action.
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## 🎨 Customizing the Container
|
|
113
|
-
|
|
114
|
-
You can style the widget container (but not the widget internals due to Shadow DOM):
|
|
115
|
-
|
|
116
|
-
```html
|
|
117
|
-
<div style="max-width: 900px; margin: 50px auto;">
|
|
118
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
119
|
-
</div>
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Or with CSS:
|
|
123
|
-
```css
|
|
124
|
-
carbon-calculator-widget {
|
|
125
|
-
display: block;
|
|
126
|
-
max-width: 1000px;
|
|
127
|
-
margin: 0 auto;
|
|
128
|
-
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
|
|
134
|
-
## 📦 Files You Need
|
|
135
|
-
|
|
136
|
-
Only **ONE** file is needed to inject the widget anywhere:
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
dist/carbon-calculator-widget.iife.js
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
This file contains:
|
|
143
|
-
- ✅ All JavaScript code
|
|
144
|
-
- ✅ All CSS styles (inlined)
|
|
145
|
-
- ✅ React and dependencies
|
|
146
|
-
- ✅ Material-UI components
|
|
147
|
-
- ✅ Everything needed to run
|
|
148
|
-
|
|
149
|
-
---
|
|
150
|
-
|
|
151
|
-
## 🔄 Rebuilding After Changes
|
|
152
|
-
|
|
153
|
-
If you make changes to the calculator and want to update the widget:
|
|
154
|
-
|
|
155
|
-
```bash
|
|
156
|
-
# 1. Make your changes to the source code
|
|
157
|
-
# 2. Rebuild the widget
|
|
158
|
-
npm run build
|
|
159
|
-
|
|
160
|
-
# 3. Test it
|
|
161
|
-
npm run preview
|
|
162
|
-
# or
|
|
163
|
-
python3 -m http.server 8000
|
|
164
|
-
|
|
165
|
-
# 4. Upload the new dist/carbon-calculator-widget.iife.js to your server
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
---
|
|
169
|
-
|
|
170
|
-
## ✨ Key Features
|
|
171
|
-
|
|
172
|
-
- **🔒 Isolated**: Uses Shadow DOM - won't conflict with your site's styles
|
|
173
|
-
- **📱 Responsive**: Works on all screen sizes
|
|
174
|
-
- **🚀 Fast**: Single file, optimized and gzipped
|
|
175
|
-
- **🌐 Universal**: Works with any framework or plain HTML
|
|
176
|
-
- **💪 Self-contained**: No external dependencies needed
|
|
177
|
-
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
## 🆘 Need Help?
|
|
181
|
-
|
|
182
|
-
- **Full Guide**: See `WIDGET_INTEGRATION_GUIDE.md`
|
|
183
|
-
- **Test Page**: Open `test-widget.html` to see a working example
|
|
184
|
-
- **Source Code**: Check `src/widget.jsx` to see how it works
|
|
185
|
-
|
|
186
|
-
---
|
|
187
|
-
|
|
188
|
-
## 📊 Current Status
|
|
189
|
-
|
|
190
|
-
✅ Widget built successfully
|
|
191
|
-
✅ Test page created and working
|
|
192
|
-
✅ Local servers running for testing
|
|
193
|
-
✅ Ready to deploy!
|
|
194
|
-
|
|
195
|
-
**Next Step**: Upload `dist/carbon-calculator-widget.iife.js` to your target website and add the 2 lines of code! 🚀
|
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
# Carbon Calculator Widget - Integration Guide
|
|
2
|
-
|
|
3
|
-
This guide explains how to build and integrate the Carbon Calculator widget into any website or application.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 📦 Step 1: Build the Widget
|
|
8
|
-
|
|
9
|
-
First, you need to build the widget into a single JavaScript file that can be embedded anywhere.
|
|
10
|
-
|
|
11
|
-
### Build Command
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm run build
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
This will create a production-ready widget file in the `dist/` folder:
|
|
18
|
-
- **File**: `dist/carbon-calculator-widget.iife.js`
|
|
19
|
-
- **Format**: IIFE (Immediately Invoked Function Expression) - works in any browser
|
|
20
|
-
- **Size**: Single file with all CSS and JS bundled together
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## 🚀 Step 2: Deploy the Widget File
|
|
25
|
-
|
|
26
|
-
You have several options for hosting the widget:
|
|
27
|
-
|
|
28
|
-
### Option A: CDN (Recommended for Production)
|
|
29
|
-
Upload `carbon-calculator-widget.iife.js` to a CDN like:
|
|
30
|
-
- AWS S3 + CloudFront
|
|
31
|
-
- Vercel
|
|
32
|
-
- Netlify
|
|
33
|
-
- Any static file hosting service
|
|
34
|
-
|
|
35
|
-
### Option B: Local Server
|
|
36
|
-
Place the file on your web server in a publicly accessible directory.
|
|
37
|
-
|
|
38
|
-
### Option C: Same Domain
|
|
39
|
-
If integrating into your own website, copy the file to your public assets folder.
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
## 🔧 Step 3: Integrate into Another Project
|
|
44
|
-
|
|
45
|
-
Once the widget is built and hosted, you can embed it in **any HTML page** with just 2 lines of code:
|
|
46
|
-
|
|
47
|
-
### Basic Integration
|
|
48
|
-
|
|
49
|
-
```html
|
|
50
|
-
<!DOCTYPE html>
|
|
51
|
-
<html lang="en">
|
|
52
|
-
<head>
|
|
53
|
-
<meta charset="UTF-8">
|
|
54
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
55
|
-
<title>My Website with Carbon Calculator</title>
|
|
56
|
-
</head>
|
|
57
|
-
<body>
|
|
58
|
-
<h1>Welcome to My Website</h1>
|
|
59
|
-
|
|
60
|
-
<!-- 1️⃣ Load the widget script -->
|
|
61
|
-
<script src="https://your-cdn.com/carbon-calculator-widget.iife.js"></script>
|
|
62
|
-
|
|
63
|
-
<!-- 2️⃣ Add the widget anywhere on your page -->
|
|
64
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
65
|
-
|
|
66
|
-
</body>
|
|
67
|
-
</html>
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Alternative: Legacy Container Method
|
|
71
|
-
|
|
72
|
-
If you prefer using a div with an ID:
|
|
73
|
-
|
|
74
|
-
```html
|
|
75
|
-
<!DOCTYPE html>
|
|
76
|
-
<html lang="en">
|
|
77
|
-
<head>
|
|
78
|
-
<meta charset="UTF-8">
|
|
79
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
80
|
-
<title>My Website with Carbon Calculator</title>
|
|
81
|
-
</head>
|
|
82
|
-
<body>
|
|
83
|
-
<h1>Welcome to My Website</h1>
|
|
84
|
-
|
|
85
|
-
<!-- The widget will automatically inject itself into this div -->
|
|
86
|
-
<div id="boomitra-carbon-calculator"></div>
|
|
87
|
-
|
|
88
|
-
<!-- Load the widget script -->
|
|
89
|
-
<script src="https://your-cdn.com/carbon-calculator-widget.iife.js"></script>
|
|
90
|
-
|
|
91
|
-
</body>
|
|
92
|
-
</html>
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
## 🎨 Step 4: Styling & Customization
|
|
98
|
-
|
|
99
|
-
### Shadow DOM Isolation
|
|
100
|
-
The widget uses **Shadow DOM**, which means:
|
|
101
|
-
- ✅ Your website's CSS won't break the widget
|
|
102
|
-
- ✅ The widget's CSS won't affect your website
|
|
103
|
-
- ✅ Complete style isolation and encapsulation
|
|
104
|
-
|
|
105
|
-
### Custom Positioning
|
|
106
|
-
|
|
107
|
-
You can wrap the widget in a container and style it:
|
|
108
|
-
|
|
109
|
-
```html
|
|
110
|
-
<div style="max-width: 800px; margin: 50px auto; padding: 20px;">
|
|
111
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
112
|
-
</div>
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Or use CSS:
|
|
116
|
-
|
|
117
|
-
```css
|
|
118
|
-
carbon-calculator-widget {
|
|
119
|
-
display: block;
|
|
120
|
-
max-width: 900px;
|
|
121
|
-
margin: 0 auto;
|
|
122
|
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
123
|
-
border-radius: 8px;
|
|
124
|
-
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
|
-
## 📋 Complete Integration Examples
|
|
130
|
-
|
|
131
|
-
### Example 1: WordPress Site
|
|
132
|
-
|
|
133
|
-
```html
|
|
134
|
-
<!-- Add to your WordPress page/post in HTML mode -->
|
|
135
|
-
<script src="https://your-cdn.com/carbon-calculator-widget.iife.js"></script>
|
|
136
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### Example 2: React Application
|
|
140
|
-
|
|
141
|
-
```jsx
|
|
142
|
-
import { useEffect } from 'react';
|
|
143
|
-
|
|
144
|
-
function MyComponent() {
|
|
145
|
-
useEffect(() => {
|
|
146
|
-
// Load the widget script dynamically
|
|
147
|
-
const script = document.createElement('script');
|
|
148
|
-
script.src = 'https://your-cdn.com/carbon-calculator-widget.iife.js';
|
|
149
|
-
script.async = true;
|
|
150
|
-
document.body.appendChild(script);
|
|
151
|
-
|
|
152
|
-
return () => {
|
|
153
|
-
document.body.removeChild(script);
|
|
154
|
-
};
|
|
155
|
-
}, []);
|
|
156
|
-
|
|
157
|
-
return (
|
|
158
|
-
<div>
|
|
159
|
-
<h1>My React App</h1>
|
|
160
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
161
|
-
</div>
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
### Example 3: Next.js Application
|
|
167
|
-
|
|
168
|
-
```jsx
|
|
169
|
-
// pages/calculator.js
|
|
170
|
-
import Head from 'next/head';
|
|
171
|
-
import { useEffect } from 'react';
|
|
172
|
-
|
|
173
|
-
export default function CalculatorPage() {
|
|
174
|
-
useEffect(() => {
|
|
175
|
-
const script = document.createElement('script');
|
|
176
|
-
script.src = 'https://your-cdn.com/carbon-calculator-widget.iife.js';
|
|
177
|
-
script.async = true;
|
|
178
|
-
document.body.appendChild(script);
|
|
179
|
-
|
|
180
|
-
return () => {
|
|
181
|
-
document.body.removeChild(script);
|
|
182
|
-
};
|
|
183
|
-
}, []);
|
|
184
|
-
|
|
185
|
-
return (
|
|
186
|
-
<>
|
|
187
|
-
<Head>
|
|
188
|
-
<title>Carbon Calculator</title>
|
|
189
|
-
</Head>
|
|
190
|
-
<main>
|
|
191
|
-
<h1>Calculate Your Carbon Footprint</h1>
|
|
192
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
193
|
-
</main>
|
|
194
|
-
</>
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Example 4: Vue.js Application
|
|
200
|
-
|
|
201
|
-
```vue
|
|
202
|
-
<template>
|
|
203
|
-
<div>
|
|
204
|
-
<h1>My Vue App</h1>
|
|
205
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
206
|
-
</div>
|
|
207
|
-
</template>
|
|
208
|
-
|
|
209
|
-
<script>
|
|
210
|
-
export default {
|
|
211
|
-
name: 'CalculatorPage',
|
|
212
|
-
mounted() {
|
|
213
|
-
const script = document.createElement('script');
|
|
214
|
-
script.src = 'https://your-cdn.com/carbon-calculator-widget.iife.js';
|
|
215
|
-
script.async = true;
|
|
216
|
-
document.body.appendChild(script);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
</script>
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
### Example 5: Plain HTML with Local File
|
|
223
|
-
|
|
224
|
-
```html
|
|
225
|
-
<!DOCTYPE html>
|
|
226
|
-
<html lang="en">
|
|
227
|
-
<head>
|
|
228
|
-
<meta charset="UTF-8">
|
|
229
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
230
|
-
<title>Carbon Calculator Demo</title>
|
|
231
|
-
</head>
|
|
232
|
-
<body>
|
|
233
|
-
<div style="max-width: 1000px; margin: 50px auto; padding: 20px;">
|
|
234
|
-
<h1>Carbon Footprint Calculator</h1>
|
|
235
|
-
<p>Calculate your environmental impact below:</p>
|
|
236
|
-
|
|
237
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
238
|
-
</div>
|
|
239
|
-
|
|
240
|
-
<!-- Load from local file -->
|
|
241
|
-
<script src="/path/to/carbon-calculator-widget.iife.js"></script>
|
|
242
|
-
</body>
|
|
243
|
-
</html>
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
---
|
|
247
|
-
|
|
248
|
-
## 🧪 Step 5: Testing Locally
|
|
249
|
-
|
|
250
|
-
Before deploying, you can test the widget locally:
|
|
251
|
-
|
|
252
|
-
### 1. Build the widget
|
|
253
|
-
```bash
|
|
254
|
-
npm run build
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
### 2. Preview the build
|
|
258
|
-
```bash
|
|
259
|
-
npm run preview
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
This will start a local server (usually at `http://localhost:4173`) where you can test the built widget.
|
|
263
|
-
|
|
264
|
-
### 3. Create a test HTML file
|
|
265
|
-
|
|
266
|
-
Create `test-widget.html` in your project root:
|
|
267
|
-
|
|
268
|
-
```html
|
|
269
|
-
<!DOCTYPE html>
|
|
270
|
-
<html lang="en">
|
|
271
|
-
<head>
|
|
272
|
-
<meta charset="UTF-8">
|
|
273
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
274
|
-
<title>Widget Test</title>
|
|
275
|
-
</head>
|
|
276
|
-
<body>
|
|
277
|
-
<h1>Testing Carbon Calculator Widget</h1>
|
|
278
|
-
|
|
279
|
-
<carbon-calculator-widget></carbon-calculator-widget>
|
|
280
|
-
|
|
281
|
-
<script src="./dist/carbon-calculator-widget.iife.js"></script>
|
|
282
|
-
</body>
|
|
283
|
-
</html>
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
### 4. Serve the test file
|
|
287
|
-
|
|
288
|
-
Use a simple HTTP server:
|
|
289
|
-
|
|
290
|
-
```bash
|
|
291
|
-
# Using Python
|
|
292
|
-
python3 -m http.server 8000
|
|
293
|
-
|
|
294
|
-
# Using Node.js (if you have http-server installed)
|
|
295
|
-
npx http-server -p 8000
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
Then open `http://localhost:8000/test-widget.html` in your browser.
|
|
299
|
-
|
|
300
|
-
---
|
|
301
|
-
|
|
302
|
-
## ✅ Verification Checklist
|
|
303
|
-
|
|
304
|
-
After integration, verify:
|
|
305
|
-
|
|
306
|
-
- [ ] Widget loads without console errors
|
|
307
|
-
- [ ] All styles are applied correctly
|
|
308
|
-
- [ ] Calculator functionality works (input fields, calculations)
|
|
309
|
-
- [ ] Widget is responsive on mobile devices
|
|
310
|
-
- [ ] Widget doesn't conflict with your site's existing styles
|
|
311
|
-
- [ ] No JavaScript errors in browser console
|
|
312
|
-
|
|
313
|
-
---
|
|
314
|
-
|
|
315
|
-
## 🔍 Troubleshooting
|
|
316
|
-
|
|
317
|
-
### Widget doesn't appear
|
|
318
|
-
- Check browser console for errors
|
|
319
|
-
- Verify the script URL is correct and accessible
|
|
320
|
-
- Ensure the script is loaded before the widget element
|
|
321
|
-
|
|
322
|
-
### Styles are missing
|
|
323
|
-
- The widget uses Shadow DOM, so styles are bundled
|
|
324
|
-
- Check if the build process completed successfully
|
|
325
|
-
- Verify the CSS was inlined during build
|
|
326
|
-
|
|
327
|
-
### Widget conflicts with site styles
|
|
328
|
-
- This shouldn't happen due to Shadow DOM isolation
|
|
329
|
-
- If it does, check if you're using any global CSS that targets custom elements
|
|
330
|
-
|
|
331
|
-
---
|
|
332
|
-
|
|
333
|
-
## 📊 Browser Support
|
|
334
|
-
|
|
335
|
-
The widget supports all modern browsers:
|
|
336
|
-
- ✅ Chrome/Edge (latest)
|
|
337
|
-
- ✅ Firefox (latest)
|
|
338
|
-
- ✅ Safari (latest)
|
|
339
|
-
- ✅ Mobile browsers (iOS Safari, Chrome Mobile)
|
|
340
|
-
|
|
341
|
-
**Note**: Internet Explorer is not supported (requires Shadow DOM support).
|
|
342
|
-
|
|
343
|
-
---
|
|
344
|
-
|
|
345
|
-
## 🚢 Production Deployment Checklist
|
|
346
|
-
|
|
347
|
-
Before deploying to production:
|
|
348
|
-
|
|
349
|
-
1. [ ] Run `npm run build` to create production bundle
|
|
350
|
-
2. [ ] Test the built widget locally
|
|
351
|
-
3. [ ] Upload `dist/carbon-calculator-widget.iife.js` to your CDN/server
|
|
352
|
-
4. [ ] Update the script URL in your integration code
|
|
353
|
-
5. [ ] Test on staging environment
|
|
354
|
-
6. [ ] Verify on multiple browsers and devices
|
|
355
|
-
7. [ ] Check performance and load times
|
|
356
|
-
8. [ ] Deploy to production
|
|
357
|
-
|
|
358
|
-
---
|
|
359
|
-
|
|
360
|
-
## 📝 Summary
|
|
361
|
-
|
|
362
|
-
**Quick Start:**
|
|
363
|
-
1. Build: `npm run build`
|
|
364
|
-
2. Upload: `dist/carbon-calculator-widget.iife.js` to your server
|
|
365
|
-
3. Embed: Add script tag and `<carbon-calculator-widget>` element
|
|
366
|
-
|
|
367
|
-
That's it! Your carbon calculator is now a portable widget that can be embedded anywhere! 🎉
|
package/dist/index.html
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>Carbon Calculator Widget Test</title>
|
|
7
|
-
<style>
|
|
8
|
-
body {
|
|
9
|
-
font-family: sans-serif;
|
|
10
|
-
padding: 40px;
|
|
11
|
-
background: #f0f0f0;
|
|
12
|
-
}
|
|
13
|
-
.host-container {
|
|
14
|
-
max-width: 1200px;
|
|
15
|
-
margin: 0 auto;
|
|
16
|
-
background: white;
|
|
17
|
-
padding: 20px;
|
|
18
|
-
border-radius: 8px;
|
|
19
|
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
20
|
-
}
|
|
21
|
-
</style>
|
|
22
|
-
</head>
|
|
23
|
-
<body>
|
|
24
|
-
<h1>External Website Hosting the Widget</h1>
|
|
25
|
-
<p>Below is the calculator, isolated in Shadow DOM:</p>
|
|
26
|
-
|
|
27
|
-
<div class="host-container">
|
|
28
|
-
<!-- The target div as requested -->
|
|
29
|
-
<div id="boomitra-carbon-calculator"></div>
|
|
30
|
-
</div>
|
|
31
|
-
|
|
32
|
-
<!-- Load the built script -->
|
|
33
|
-
<script src="../dist/carbon-calculator-widget.iife.js"></script>
|
|
34
|
-
</body>
|
|
35
|
-
</html>
|
package/dist/vite.svg
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|