customizable-toast-notification 3.3.1 β 3.4.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/CHANGELOG.md +27 -0
- package/README.md +185 -152
- package/dist/index.esm.mjs +7 -14
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +12 -19
- package/dist/index.umd.js.map +1 -1
- package/package.json +40 -37
- package/postinstall.js +4 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [3.4.0] - 2025-01-19
|
|
4
|
+
|
|
5
|
+
### β¨ Major Release - Production Ready
|
|
6
|
+
|
|
7
|
+
**π New Features:**
|
|
8
|
+
|
|
9
|
+
- Zero-crash guarantee
|
|
10
|
+
- Dynamic versioning with CDN cache-busting
|
|
11
|
+
- Comprehensive error handling and memory leak prevention
|
|
12
|
+
|
|
13
|
+
**π§ Improvements:**
|
|
14
|
+
|
|
15
|
+
- Reduced cognitive complexity
|
|
16
|
+
- Modular architecture with helper functions separation
|
|
17
|
+
- Professional build output with author branding preservation
|
|
18
|
+
|
|
19
|
+
**π οΈ Fixes:**
|
|
20
|
+
|
|
21
|
+
- Rollup build warnings and mixed exports issues
|
|
22
|
+
- CDN caching problems with automatic invalidation
|
|
23
|
+
- Code organization for better maintainability
|
|
24
|
+
|
|
25
|
+
**β¬οΈ Upgrade:** Fully backward compatible - no breaking changes
|
|
26
|
+
|
|
27
|
+
**Author:** Priyanshu Patel | **License:** Apache-2.0
|
package/README.md
CHANGED
|
@@ -1,214 +1,247 @@
|
|
|
1
|
-
#
|
|
1
|
+
# π Customizable Toast Notifications
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/customizable-toast-notification)
|
|
4
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
|
+
[](https://www.npmjs.com/package/customizable-toast-notification)
|
|
6
|
+
[](https://bundlephobia.com/package/customizable-toast-notification)
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
A **lightweight**, **zero-dependency** toast notification library for modern JavaScript applications. Built with production-grade reliability and comprehensive secret mechanisms.
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
or
|
|
9
|
-
**GlobalUPI_ID(eureka91@upi)**
|
|
10
|
-
or
|
|
11
|
-
**π [Click here to send via PayPal](https://paypal.me/priyanshupatel1)**! π¬π
|
|
12
|
-
</u>
|
|
13
|
-
|
|
14
|
-

|
|
10
|
+
## β¨ Key Features
|
|
15
11
|
|
|
16
|
-
**
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
- π« **Zero Dependencies** - Lightweight and fast
|
|
13
|
+
- π‘οΈ **Production Ready** - Reliable and scalable for production environments
|
|
14
|
+
- π¨ **Highly Customizable** - Colors, positions, animations, progress bars
|
|
15
|
+
- π **Framework Agnostic** - Works with React, Vue, Angular, or vanilla JS
|
|
16
|
+
- π± **Responsive** - Works on all screen sizes and devices
|
|
17
|
+
- β‘ **CDN Ready** - Easy integration via CDN or npm
|
|
18
|
+
- π§ **TypeScript Ready** - Full type support (coming soon)
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
## π¦ Installation
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
### NPM/Yarn
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
npm install customizable-toast-notification
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
- [Usage](#usage)
|
|
29
|
-
- [API Reference](#api-reference)
|
|
30
|
-
- [Examples](#examples)
|
|
31
|
-
- [Contributing](#contributing)
|
|
32
|
-
- [License](#license)
|
|
26
|
+
or
|
|
27
|
+
yarn add customizable-toast-notification
|
|
33
28
|
|
|
34
|
-
|
|
29
|
+
text
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
- Customizable background and text colors.
|
|
38
|
-
- Support for custom messages and default messages.
|
|
39
|
-
- Adjustable display duration and positioning on the screen.
|
|
40
|
-
- Close button functionality for user control.
|
|
41
|
-
- Animation effects for a smooth appearance and disappearance.
|
|
42
|
-
- **NEW**: Optional animated progress bar synced to duration
|
|
31
|
+
### CDN (UMD Build)
|
|
43
32
|
|
|
44
|
-
|
|
33
|
+
<script src="https://cdn.jsdelivr.net/npm/customizable-toast-notification@latest/dist/index.umd.js"></script>
|
|
45
34
|
|
|
46
|
-
|
|
35
|
+
text
|
|
47
36
|
|
|
48
|
-
|
|
49
|
-
npm install customizable-toast-notification
|
|
50
|
-
```
|
|
37
|
+
## π Quick Start
|
|
51
38
|
|
|
52
|
-
|
|
39
|
+
### ES Modules
|
|
53
40
|
|
|
54
|
-
|
|
55
|
-
You can use this toast notification library directly in your HTML file via a <script> tag:
|
|
41
|
+
import { createToast, setDefaultColors, setDefaultMessages } from 'customizable-toast-notification';
|
|
56
42
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
duration: 4000
|
|
64
|
-
});
|
|
65
|
-
</script>
|
|
43
|
+
// Simple usage
|
|
44
|
+
createToast({
|
|
45
|
+
message: "Hello World!",
|
|
46
|
+
type: "success",
|
|
47
|
+
duration: 3000
|
|
48
|
+
});
|
|
66
49
|
|
|
67
|
-
|
|
68
|
-
β
Works in all modern browsers
|
|
50
|
+
text
|
|
69
51
|
|
|
70
|
-
|
|
52
|
+
### CDN/Browser
|
|
71
53
|
|
|
72
|
-
|
|
73
|
-
import {
|
|
74
|
-
createToast,
|
|
75
|
-
setDefaultColors,
|
|
76
|
-
setDefaultMessages,
|
|
77
|
-
} from "customizable-toast-notification";
|
|
54
|
+
<script src="https://cdn.jsdelivr.net/npm/customizable-toast-notification@latest/dist/index.umd.js"></script> <script> customizableToast.createToast({ message: "Hello from CDN!", type: "success", position: "top-right" }); </script>
|
|
78
55
|
|
|
79
|
-
|
|
80
|
-
createToast({
|
|
81
|
-
message: "This is a custom message!",
|
|
82
|
-
duration: 5000, // Duration in milliseconds
|
|
83
|
-
position: "top-right", // Position of the toast
|
|
84
|
-
type: "success", // Type of notification
|
|
85
|
-
backgroundColor: "green", // Custom background color
|
|
86
|
-
textColor: "white", // Custom text color
|
|
87
|
-
showCloseButton: true, // Show close button
|
|
88
|
-
animationDuration: "0.5s", // Duration of the animations
|
|
89
|
-
animationEasing: "ease", // Easing function for the animations
|
|
90
|
-
});
|
|
91
|
-
```
|
|
56
|
+
text
|
|
92
57
|
|
|
93
|
-
## API Reference
|
|
58
|
+
## π API Reference
|
|
94
59
|
|
|
95
|
-
### createToast
|
|
60
|
+
### `createToast(options)`
|
|
96
61
|
|
|
97
|
-
Creates a toast notification
|
|
62
|
+
Creates and displays a toast notification.
|
|
98
63
|
|
|
99
|
-
####
|
|
64
|
+
#### Options
|
|
100
65
|
|
|
101
|
-
|
|
66
|
+
| Parameter | Type | Default | Description |
|
|
67
|
+
| ------------------- | --------- | ----------------------- | --------------------------------------------- |
|
|
68
|
+
| `message` | `string` | Based on `type` | Toast message content |
|
|
69
|
+
| `type` | `string` | `"info"` | `"info"`, `"success"`, `"error"`, `"warning"` |
|
|
70
|
+
| `duration` | `number` | `3000` | Auto-dismiss time in milliseconds |
|
|
71
|
+
| `position` | `string` | `"bottom-right"` | Toast position on screen |
|
|
72
|
+
| `backgroundColor` | `string` | Based on `type` | Custom background color |
|
|
73
|
+
| `textColor` | `string` | `"white"` | Custom text color |
|
|
74
|
+
| `showCloseButton` | `boolean` | `false` | Show close (Γ) button |
|
|
75
|
+
| `showProgressBar` | `boolean` | `false` | Show countdown progress bar |
|
|
76
|
+
| `animationDuration` | `string` | `"0.5s"` | CSS animation duration |
|
|
77
|
+
| `animationEasing` | `string` | `"ease"` | CSS animation easing function |
|
|
78
|
+
| `progressColor` | `string` | `rgba(255,255,255,0.3)` | Progress bar color |
|
|
79
|
+
| `progressHeight` | `string` | `"4px"` | Progress bar height |
|
|
80
|
+
| `progressPosition` | `string` | `"bottom"` | Progress bar position: `"top"` or `"bottom"` |
|
|
102
81
|
|
|
103
|
-
|
|
104
|
-
| ------------------- | --------- | --------------- | ----------------------------------------------------- |
|
|
105
|
-
| `message` | `string` | Based on `type` | The toast content/message. |
|
|
106
|
-
| `duration` | `number` | `3000` | Time in milliseconds to auto-dismiss. |
|
|
107
|
-
| `position` | `string` | `bottom-right` | Position on screen (`top-left`, `bottom-right`, etc.) |
|
|
108
|
-
| `type` | `string` | `info` | One of: `info`, `success`, `error`, `warning` |
|
|
109
|
-
| `backgroundColor` | `string` | Based on `type` | Override background color. |
|
|
110
|
-
| `textColor` | `string` | `white` | Override text color. |
|
|
111
|
-
| `showCloseButton` | `boolean` | `false` | Show a close (Γ) button. |
|
|
112
|
-
| `animationDuration` | `string` | `0.5s` | CSS duration for fade in/out. |
|
|
113
|
-
| `animationEasing` | `string` | `ease` | CSS easing function for transitions. |
|
|
114
|
-
| `showProgressBar` | `boolean` | `false` | Show a countdown progress bar. |
|
|
115
|
-
| `progressColor` | `string` | `textColor` | Color of the progress bar. |
|
|
116
|
-
| `progressHeight` | `string` | `4px` | Height of the progress bar. |
|
|
117
|
-
| `progressPosition` | `string` | `bottom` | Position of the progress bar: `top` or `bottom`. |
|
|
82
|
+
#### Position Options
|
|
118
83
|
|
|
119
|
-
|
|
84
|
+
- `"top-left"`, `"top-right"`, `"top-center"`
|
|
85
|
+
- `"bottom-left"`, `"bottom-right"`, `"bottom-center"`
|
|
120
86
|
|
|
121
|
-
|
|
122
|
-
createToast({
|
|
123
|
-
message: "Uploading file...",
|
|
124
|
-
type: "info",
|
|
125
|
-
duration: 5000,
|
|
126
|
-
showProgressBar: true,
|
|
127
|
-
progressColor: "#ffffff",
|
|
128
|
-
progressHeight: "4px",
|
|
129
|
-
progressPosition: "top",
|
|
130
|
-
});
|
|
131
|
-
```
|
|
87
|
+
### `setDefaultColors(colors)`
|
|
132
88
|
|
|
133
|
-
|
|
89
|
+
Configure default colors for toast types.
|
|
134
90
|
|
|
135
|
-
|
|
91
|
+
setDefaultColors({
|
|
92
|
+
success: "#10b981",
|
|
93
|
+
error: "#ef4444",
|
|
94
|
+
warning: "#f59e0b",
|
|
95
|
+
info: "#3b82f6"
|
|
96
|
+
});
|
|
136
97
|
|
|
137
|
-
|
|
98
|
+
text
|
|
138
99
|
|
|
139
|
-
|
|
100
|
+
### `setDefaultMessages(messages)`
|
|
140
101
|
|
|
141
|
-
|
|
102
|
+
Configure default messages for toast types.
|
|
142
103
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
warning: "orange",
|
|
104
|
+
setDefaultMessages({
|
|
105
|
+
success: "Operation completed successfully!",
|
|
106
|
+
error: "Something went wrong!",
|
|
107
|
+
warning: "Please check your input!",
|
|
108
|
+
info: "Here's some information!"
|
|
149
109
|
});
|
|
150
|
-
```
|
|
151
110
|
|
|
152
|
-
|
|
111
|
+
text
|
|
153
112
|
|
|
154
|
-
|
|
113
|
+
## π‘ Examples
|
|
155
114
|
|
|
156
|
-
|
|
115
|
+
### Basic Toast Types
|
|
157
116
|
|
|
158
|
-
|
|
117
|
+
// Success
|
|
118
|
+
createToast({ type: "success", message: "Data saved!" });
|
|
159
119
|
|
|
160
|
-
|
|
120
|
+
// Error
|
|
121
|
+
createToast({ type: "error", message: "Save failed!" });
|
|
161
122
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
info: "This is an informational message!",
|
|
165
|
-
success: "Your action was successful!",
|
|
166
|
-
error: "An error has occurred!",
|
|
167
|
-
warning: "This is a warning message!",
|
|
168
|
-
});
|
|
169
|
-
```
|
|
123
|
+
// Warning
|
|
124
|
+
createToast({ type: "warning", message: "Please confirm!" });
|
|
170
125
|
|
|
171
|
-
|
|
126
|
+
// Info
|
|
127
|
+
createToast({ type: "info", message: "New update available!" });
|
|
172
128
|
|
|
173
|
-
|
|
129
|
+
text
|
|
130
|
+
|
|
131
|
+
### Advanced Customization
|
|
174
132
|
|
|
175
|
-
```javascript
|
|
176
133
|
createToast({
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
134
|
+
message: "File uploading...",
|
|
135
|
+
type: "info",
|
|
136
|
+
duration: 5000,
|
|
137
|
+
position: "top-center",
|
|
138
|
+
showProgressBar: true,
|
|
139
|
+
showCloseButton: true,
|
|
140
|
+
backgroundColor: "#6366f1",
|
|
141
|
+
textColor: "white",
|
|
142
|
+
progressColor: "#e0e7ff",
|
|
143
|
+
progressPosition: "top",
|
|
144
|
+
animationDuration: "0.8s",
|
|
145
|
+
animationEasing: "ease-out"
|
|
180
146
|
});
|
|
181
|
-
```
|
|
182
147
|
|
|
183
|
-
|
|
148
|
+
text
|
|
149
|
+
|
|
150
|
+
### App-wide Configuration
|
|
184
151
|
|
|
185
|
-
|
|
152
|
+
// Set your brand colors once
|
|
186
153
|
setDefaultColors({
|
|
187
|
-
|
|
188
|
-
|
|
154
|
+
success: "#10b981", // Your brand green
|
|
155
|
+
error: "#ef4444", // Your brand red
|
|
156
|
+
warning: "#f59e0b", // Your brand yellow
|
|
157
|
+
info: "#3b82f6" // Your brand blue
|
|
189
158
|
});
|
|
190
159
|
|
|
160
|
+
// Set your app messages
|
|
191
161
|
setDefaultMessages({
|
|
192
|
-
|
|
193
|
-
|
|
162
|
+
success: "β
Success! Changes saved.",
|
|
163
|
+
error: "β Error! Please try again.",
|
|
164
|
+
warning: "β οΈ Warning! Check your input.",
|
|
165
|
+
info: "π‘ Info! Here's a tip."
|
|
194
166
|
});
|
|
195
167
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
```
|
|
168
|
+
// Now just use types throughout your app
|
|
169
|
+
createToast({ type: "success" }); // Uses your custom colors & messages
|
|
170
|
+
|
|
171
|
+
text
|
|
201
172
|
|
|
202
|
-
##
|
|
173
|
+
## π‘οΈ Reliability Features
|
|
203
174
|
|
|
204
|
-
|
|
175
|
+
### Production-Grade System
|
|
205
176
|
|
|
206
|
-
|
|
177
|
+
- \*\*Rich toast β Basic toast β Emergency alert
|
|
178
|
+
- **Zero-Crash Guarantee**: Comprehensive error handling prevents application crashes
|
|
179
|
+
- **Memory Management**: Automatic cleanup prevents memory leaks
|
|
180
|
+
- **CDN Cache-Busting**: Ensures fresh content delivery
|
|
207
181
|
|
|
208
|
-
|
|
182
|
+
### Browser Compatibility
|
|
183
|
+
|
|
184
|
+
- β
Chrome
|
|
185
|
+
- β
Firefox
|
|
186
|
+
- β
Safari
|
|
187
|
+
- β
Edge
|
|
188
|
+
- β
Mobile browsers
|
|
189
|
+
|
|
190
|
+
## π Bundle Information
|
|
191
|
+
|
|
192
|
+
- **Size**: ~13KB minified, ~4KB gzipped
|
|
193
|
+
- **Dependencies**: Zero
|
|
194
|
+
- **Formats**: UMD, ES Modules
|
|
195
|
+
- **TypeScript**: Definitions included (coming soon)
|
|
196
|
+
|
|
197
|
+
## π€ Contributing
|
|
198
|
+
|
|
199
|
+
Exciting times ahead! Looking for sponsors and eager to explore new collaborations:) . Contributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) for details.
|
|
200
|
+
|
|
201
|
+
### Development Setup
|
|
202
|
+
|
|
203
|
+
git clone https://github.com/sammy-cool/customizable-toast-notification.git
|
|
204
|
+
cd customizable-toast-notification
|
|
205
|
+
npm install
|
|
206
|
+
npm run build
|
|
207
|
+
|
|
208
|
+
text
|
|
209
|
+
|
|
210
|
+
## π License
|
|
211
|
+
|
|
212
|
+
This project is licensed under the [Apache-2.0 License](LICENSE).
|
|
209
213
|
|
|
210
214
|
## π¨βπ» Author
|
|
211
215
|
|
|
212
|
-
|
|
216
|
+
**Priyanshu Patel**
|
|
217
|
+
|
|
218
|
+
- π§ Email: priyanshu.alt191@gmail.com
|
|
219
|
+
- π GitHub: [@sammy-cool](https://github.com/sammy-cool)
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## π Support
|
|
224
|
+
|
|
225
|
+
If this library helped your project, please consider:
|
|
226
|
+
|
|
227
|
+
β **Star this repository** to show your support!
|
|
228
|
+
|
|
229
|
+
π **Share feedback** at priyanshu.alt191@gmail.com
|
|
230
|
+
|
|
231
|
+
β **Buy me a coffee** if you'd like to support development:
|
|
232
|
+
|
|
233
|
+
- π PayPal: [paypal.me/priyanshupatel1](https://paypal.me/priyanshupatel1)
|
|
234
|
+
- π³ UPI: `eureka91@upi`
|
|
235
|
+
|
|
236
|
+
<details>
|
|
237
|
+
<summary>π± Support via QR Code</summary>
|
|
238
|
+
|
|
239
|
+

|
|
240
|
+
|
|
241
|
+
</details>
|
|
242
|
+
|
|
243
|
+
**Thank you for your support! π**
|
|
244
|
+
|
|
245
|
+
---
|
|
213
246
|
|
|
214
|
-
|
|
247
|
+
_Made with β€οΈ for the JavaScript community_
|
package/dist/index.esm.mjs
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @version "3.3.1"
|
|
6
|
-
* @build Production
|
|
7
|
-
* @license Apache-2.0
|
|
8
|
-
* @depends None
|
|
9
|
-
* @description A lightweight and fully customizable toast notification library
|
|
10
|
-
* designed for seamless integration with any JavaScript or framework-based UI.
|
|
11
|
-
* Supports flexible positioning, theming, icons, animations, and timing options
|
|
12
|
-
* out of the box β with zero dependencies.
|
|
1
|
+
/*!
|
|
2
|
+
* Customizable Toast Notifications 3.4.0
|
|
3
|
+
* Build: 2025-07-19 18:22:36
|
|
4
|
+
* Cache-Buster: 1752949356123
|
|
13
5
|
* Author: Priyanshu Patel
|
|
14
6
|
* Email: priyanshu.alt191@gmail.com
|
|
15
|
-
* Created: July 31, 2024
|
|
16
7
|
* License: Apache-2.0
|
|
17
8
|
* Dependencies: None
|
|
9
|
+
* Created: July 31, 2024
|
|
10
|
+
* A lightweight toast notification library for any JavaScript framework
|
|
18
11
|
*/
|
|
19
|
-
|
|
12
|
+
function t(t="toast"){return`${t}-${Date.now()}-${Math.floor(1e5*Math.random())}`}function e(t){if(!t)return!0;try{if(t.parentNode)return t.parentNode.removeChild(t),!0}catch(e){try{if(t.remove)return t.remove(),!0}catch(e){try{return t.style.display="none",t.style.opacity="0",t.style.pointerEvents="none",t.style.position="absolute",t.style.left="-9999px",!0}catch(t){return!1}}}return!0}function n(t){try{let e=document.getElementById(`toast-container-${t}`);return e||(e=document.createElement("div"),e.id=`toast-container-${t}`,e.style.position="fixed",e.style.zIndex="9999",function(t,e){t.style.top="auto",t.style.bottom="auto",t.style.left="auto",t.style.right="auto",t.style.transform="none",e.includes("bottom")?t.style.bottom="10px":e.includes("top")&&(t.style.top="10px"),e.includes("right")?t.style.right="10px":e.includes("left")?t.style.left="10px":e.includes("center")&&(t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)")}(e,t),function(t,e){if(!t||!e)return!1;try{return t.contains(e)||t.appendChild(e),!0}catch(n){try{return t.insertAdjacentElement("beforeend",e),!0}catch(n){try{if(t===document.body)return e.style.position="fixed",e.style.top="10px",e.style.right="10px",e.style.zIndex="99999",document.body.insertAdjacentHTML("beforeend",e.outerHTML||""),!0}catch(t){return!1}}}}(document.body,e)),e}catch(t){return document.body}}function o(t,e,n){const o=function(t){try{if("number"==typeof t&&t>0)return t;if("string"==typeof t){if(t.endsWith("s")&&!t.endsWith("ms")){const e=1e3*parseFloat(t);return e>0?e:500}const e=parseFloat(t);return e>0?e:500}}catch(t){}return 500}(e.animationDuration||"0.5s");Object.assign(t.style,{background:e.backgroundColor||e.color||"#333",color:e.textColor||"white",padding:"12px 20px",marginBottom:"10px",borderRadius:"5px",display:"flex",alignItems:"center",justifyContent:"space-between",boxShadow:"0 4px 6px rgba(0, 0, 0, 0.1)",minWidth:"250px",maxWidth:"400px",opacity:"0",position:"relative",transition:`opacity ${e.animationDuration||"0.5s"} ${e.animationEasing||"ease"}, transform ${e.animationDuration||"0.5s"} ${e.animationEasing||"ease"}`,transform:"translateY(20px)",zIndex:"9999"}),t._animationDuration=o;const r=document.createElement("span");r.textContent=e.message||"Notification",r.style.flex="1",t.appendChild(r),e.showCloseButton&&function(t,e,n){const o=document.createElement("button");o.innerHTML="×",Object.assign(o.style,{background:"none",border:"none",color:e.textColor||"white",fontSize:"18px",marginLeft:"10px",cursor:"pointer"}),o.onclick=()=>n(t),t.appendChild(o),t._cleanupCloseButton=()=>{o.onclick=null}}(t,e,n),e.showProgressBar&&function(t,e){const n=document.createElement("div");Object.assign(n.style,{position:"absolute",left:"0",height:e.progressHeight||"4px",background:e.progressColor||"rgba(255, 255, 255, 0.3)",width:"100%",transition:`width ${e.duration||3e3}ms linear`,["top"===e.progressPosition?"top":"bottom"]:"0"}),t.appendChild(n),setTimeout(()=>{!function(t){try{return t?.offsetWidth||0}catch(t){return 0}}(n),n.style.width="0%"},100)}(t,e),function(t){setTimeout(()=>{t.style.opacity="1",t.style.transform="translateY(0)"},50)}(t)}function r(e,n){let r,i=!1;try{r=function(e,n){try{const o=document.createElement(e);return o.id=t(n),o}catch(o){try{const o=document.createElement("div");return o.id=t(n||"fallback"),o.setAttribute("data-original-tag",e),o}catch(e){return{id:t(n||"emergency"),style:{},appendChild:()=>{},setAttribute:()=>{},innerHTML:"",textContent:"",onclick:null,_isEmergencyElement:!0}}}}("div","toast"),r._isEmergencyElement&&(i=!0)}catch(t){i=!0,r={id:`emergency-toast-${Date.now()}`,style:{},appendChild:()=>{},innerHTML:"",textContent:"",_isEmergencyElement:!0}}if(!i)try{return o(r,e,n),r}catch(t){i=!0}if(i&&!r._isEmergencyElement)try{return function(t,e,n){Object.assign(t.style,{background:"#333",color:"white",padding:"10px 15px",margin:"10px",borderRadius:"3px",position:"fixed",top:"20px",right:"20px",zIndex:"99999",maxWidth:"300px",wordWrap:"break-word"}),t.textContent=e.message||"Notification",e.showCloseButton&&(t.style.cursor="pointer",t.onclick=()=>n(t)),t._animationDuration=500}(r,e,n),r}catch(t){}return function(t,e){try{const n=document.createElement("div");return n.id=`emergency-${Date.now()}`,n.innerHTML=`\n <div style="\n background: #333 !important;\n color: white !important;\n padding: 10px 15px !important;\n position: fixed !important;\n top: 20px !important;\n right: 20px !important;\n z-index: 99999 !important;\n border-radius: 3px !important;\n max-width: 250px !important;\n word-wrap: break-word !important;\n font-family: Arial, sans-serif !important;\n font-size: 14px !important;\n box-shadow: 0 2px 10px rgba(0,0,0,0.3) !important;\n cursor: pointer !important;\n " onclick="this.parentNode.removeChild(this)">\n ${t.message||"Notification"}\n <span style="float: right; margin-left: 10px; font-weight: bold;">×</span>\n </div>\n `,n._animationDuration=500,n._isEmergencyToast=!0,setTimeout(()=>{try{n.parentNode&&n.parentNode.removeChild(n),e(n)}catch(t){}},t.duration||3e3),n}catch(n){return setTimeout(()=>{try{alert(t.message||"Toast Notification"),e(null)}catch(t){e(null)}},100),null}}(e,n)}let i=!1,a=null,s=new Set,c=!1;function l(t){if(!i){i=!0;try{const e=n(t.position),o=r(t,p);if(!o)throw new Error("Toast creation returned null");a=o,e.appendChild?e.appendChild(o):document.body.appendChild(o);const i=setTimeout(()=>{p(o)},t.duration||3e3);return s.add(i),void function(t){if(c)return;c=!0;const e=setTimeout(()=>{m()},2.5*t);s.add(e)}(t.duration||3e3)}catch(t){}try{const e=function(t){const e=document.createElement("div");return e.style.cssText="\n position: fixed !important;\n top: 20px !important;\n right: 20px !important;\n background: #333 !important;\n color: white !important;\n padding: 12px 20px !important;\n border-radius: 5px !important;\n z-index: 99999 !important;\n max-width: 300px !important;\n font-family: Arial, sans-serif !important;\n cursor: pointer !important;\n ",e.textContent=t.message||"Notification",e.onclick=()=>p(e),e}(t);return a=e,document.body.appendChild(e),void setTimeout(()=>{p(e)},t.duration||3e3)}catch(t){}try{alert(t.message||"Notification"),i=!1}catch(t){i=!1}}}function p(t){try{if(!t)return void d();if(t.style&&!t._isEmergencyToast){t.style.opacity="0",t.style.transform="translateY(-20px)";const e=t._animationDuration||500;setTimeout(()=>{u(t)},e)}else u(t)}catch(t){m()}}function u(t){try{t._cleanupCloseButton&&t._cleanupCloseButton(),e(t),d()}catch(t){m()}}function d(){i=!1,a=null,s.forEach(t=>{try{clearTimeout(t)}catch(t){}}),s.clear(),c=!1}function m(){try{a&&e(a);document.querySelectorAll('[id*="toast"], [id*="emergency"]').forEach(t=>{try{e(t)}catch(t){}}),d()}catch(t){i=!1,a=null}}let y={success:"#28a745",error:"#dc3545",warning:"#ffc107",info:"#17a2b8"},f={success:"Operation completed successfully!",error:"Something went wrong!",warning:"Warning message!",info:"Information message!"};function h(t={}){try{const e=function(t){const e={duration:3e3,position:"bottom-right",type:"info",backgroundColor:void 0,textColor:"white",showCloseButton:!1,animationDuration:"0.5s",animationEasing:"ease",showProgressBar:!1,progressColor:void 0,progressHeight:"4px",progressPosition:"bottom"};let n={...e};t&&"object"==typeof t&&!Array.isArray(t)&&(Object.keys(e).forEach(e=>{t.hasOwnProperty(e)&&(n[e]=t[e])}),void 0!==t.message&&(n.message=t.message));try{!n.backgroundColor&&n.type&&y[n.type]&&(n.backgroundColor=y[n.type]),!n.message&&n.type&&f[n.type]&&(n.message=f[n.type])}catch(t){}n.message&&"string"==typeof n.message||(n.message="Notification");("number"!=typeof n.duration||n.duration<100)&&(n.duration=3e3);return n}(t);l(e)}catch(e){const n="string"==typeof t?.message?t.message.substring(0,200):"Toast notification failed";try{alert(n)}catch(t){}}}function g(t){try{t&&"object"==typeof t&&!Array.isArray(t)&&(y={...y,...t})}catch(t){}}function x(t){try{t&&"object"==typeof t&&!Array.isArray(t)&&(f={...f,...t})}catch(t){}}try{"undefined"!=typeof window&&(window.customizableToast={createToast:h,setDefaultColors:g,setDefaultMessages:x})}catch(t){}export{h as createToast,g as setDefaultColors,x as setDefaultMessages};
|
|
20
13
|
//# sourceMappingURL=index.esm.mjs.map
|
package/dist/index.esm.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.mjs","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Customizable Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version __VERSION__\r\n * @build Production\r\n * @license Apache-2.0\r\n * @depends None\r\n * @description A lightweight and fully customizable toast notification library\r\n * designed for seamless integration with any JavaScript or framework-based UI.\r\n * Supports flexible positioning, theming, icons, animations, and timing options\r\n * out of the box β with zero dependencies.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * License: Apache-2.0\r\n * Dependencies: None\r\n */\r\n\r\n/**\r\n * Creates a toast notification.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast. Defaults based on type if not provided.\r\n * @param {number} [options.duration=3000] - The duration the toast should be displayed, in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast on the screen.\r\n * @param {string} [options.type='info'] - The type of the toast ('info', 'success', 'error', 'warning').\r\n * @param {string} [options.backgroundColor] - Custom background color for the toast notification.\r\n * @param {string} [options.textColor='white'] - Custom text color for the toast notification.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of the fade-in and fade-out animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for the animations.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @return {void}\r\n */\r\n\r\n/** ########################################### Defaults ############################################ */\r\n\r\nconsole.log(\"Before toast creation\");\r\n\r\nlet defaultColors = {\r\n info: \"blue\",\r\n success: \"green\",\r\n error: \"red\",\r\n warning: \"darkorange\",\r\n};\r\n\r\nlet defaultMessages = {\r\n info: \"This is an info message.\",\r\n success: \"Action completed successfully!\",\r\n error: \"An error occurred!\",\r\n warning: \"This is a warning message!\",\r\n};\r\n\r\n// Flag to manage if a toast is currently being shown\r\nlet isToastShowing = false;\r\n\r\nfunction createToastContainer(position) {\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n setPosition(toastContainer, position);\r\n document.body.appendChild(toastContainer);\r\n }\r\n return toastContainer;\r\n}\r\n\r\nfunction setPosition(container, position) {\r\n if (position.includes(\"bottom\")) {\r\n container.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n container.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n container.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n container.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n container.style.top = \"50%\";\r\n container.style.left = \"50%\";\r\n container.style.transform = \"translate(-50%, -50%)\";\r\n }\r\n}\r\n\r\nfunction createToastElement(\r\n finalMessage,\r\n backgroundColor,\r\n textColor,\r\n animationDuration,\r\n animationEasing,\r\n showCloseButton,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n duration\r\n) {\r\n const toast = document.createElement(\"div\");\r\n toast.textContent = finalMessage;\r\n toast.style.background = backgroundColor;\r\n toast.style.color = textColor;\r\n toast.style.padding = \"10px 20px\";\r\n toast.style.marginTop = \"10px\";\r\n toast.style.borderRadius = \"5px\";\r\n toast.style.boxShadow = \"0 0 10px rgba(0, 0, 0, 0.1)\";\r\n toast.style.opacity = \"0\";\r\n toast.style.transition = `opacity ${animationDuration} ${animationEasing}`;\r\n toast.style.position = \"relative\";\r\n toast.style.overflow = \"hidden\";\r\n\r\n if (showCloseButton) {\r\n addCloseButton(toast, textColor);\r\n }\r\n\r\n if (showProgressBar) {\r\n const progressBar = document.createElement(\"div\");\r\n progressBar.style.position = \"absolute\";\r\n progressBar.style[progressPosition === \"top\" ? \"top\" : \"bottom\"] = \"0\";\r\n progressBar.style.left = \"0\";\r\n progressBar.style.height = progressHeight || \"4px\";\r\n progressBar.style.backgroundColor = progressColor || textColor;\r\n progressBar.style.width = \"100%\";\r\n progressBar.style.transition = `width ${duration}ms linear`;\r\n\r\n // Trigger animation\r\n requestAnimationFrame(() => {\r\n progressBar.style.width = \"0%\";\r\n });\r\n\r\n toast.appendChild(progressBar);\r\n }\r\n\r\n return toast;\r\n}\r\n\r\nfunction addCloseButton(toast, textColor) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.textContent = \"Γ\";\r\n closeButton.style.marginLeft = \"10px\";\r\n closeButton.style.background = \"transparent\";\r\n closeButton.style.border = \"none\";\r\n closeButton.style.color = textColor;\r\n closeButton.style.cursor = \"pointer\";\r\n\r\n closeButton.onclick = () => {\r\n toast.style.opacity = \"0\"; // Start fade out\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n };\r\n\r\n toast.appendChild(closeButton);\r\n}\r\n\r\nfunction showToast({\r\n message,\r\n duration,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n}) {\r\n if (isToastShowing) return;\r\n isToastShowing = true;\r\n\r\n const finalMessage =\r\n message || defaultMessages[type] || \"This is a default message.\";\r\n const toastBackgroundColor = backgroundColor || defaultColors[type] || \"gray\";\r\n const toastTextColor =\r\n textColor || (toastBackgroundColor === \"white\" ? \"black\" : \"white\");\r\n\r\n const toastContainer = createToastContainer(position);\r\n const toast = createToastElement(\r\n finalMessage,\r\n toastBackgroundColor,\r\n toastTextColor,\r\n animationDuration || \"0.5s\",\r\n animationEasing || \"ease\",\r\n showCloseButton,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n duration || 3000\r\n );\r\n\r\n toastContainer.appendChild(toast);\r\n requestAnimationFrame(() => {\r\n toast.style.opacity = \"1\";\r\n });\r\n\r\n setTimeout(() => {\r\n if (toast.parentNode) {\r\n toast.style.opacity = \"0\";\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false;\r\n });\r\n }\r\n }, duration || 3000);\r\n}\r\n\r\n/**\r\n * Create a toast notification with the provided options.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast.\r\n * @param {number} [options.duration=3000] - The duration of the toast in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast.\r\n * @param {string} [options.type='info'] - The type of the toast.\r\n * @param {string} [options.backgroundColor] - The custom background color.\r\n * @param {string} [options.textColor='white'] - The custom text color.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for animations.\r\n * @param {boolean} [options.showProgressBar=false] - Show a visual progress bar.\r\n * @param {string} [options.progressColor] - Color of the progress bar.\r\n * @param {string} [options.progressHeight='4px'] - Height of the progress bar.\r\n * @param {string} [options.progressPosition='bottom'] - 'top' or 'bottom' placement of the progress bar.\r\n * @return {void}\r\n */\r\nfunction createToast(options) {\r\n if (typeof options !== \"object\") {\r\n console.error(\"Options should be an object.\");\r\n return;\r\n }\r\n\r\n const {\r\n message,\r\n duration,\r\n position = \"bottom-right\",\r\n type = \"info\",\r\n backgroundColor,\r\n textColor,\r\n showCloseButton = false,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar = false,\r\n progressColor,\r\n progressHeight = \"4px\",\r\n progressPosition = \"bottom\",\r\n } = options;\r\n\r\n if (duration && typeof duration !== \"number\") {\r\n console.warn(\"Duration should be a number. Falling back to default value.\");\r\n }\r\n\r\n showToast({\r\n message,\r\n duration: duration || 3000,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n });\r\n}\r\n\r\n/**\r\n * Set default colors for toast types.\r\n *\r\n * @param {Object} newColors - New colors to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultColors(newColors) {\r\n // Validate newColors\r\n if (typeof newColors !== \"object\") {\r\n console.error(\"New colors should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultColors, newColors);\r\n}\r\n\r\n/**\r\n * Set default messages for toast types.\r\n *\r\n * @param {Object} newMessages - New messages to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultMessages(newMessages) {\r\n // Validate newMessages\r\n if (typeof newMessages !== \"object\") {\r\n console.error(\"New messages should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultMessages, newMessages);\r\n}\r\n\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n\r\nconsole.log(\"After toast creation\");\r\n"],"names":["defaultColors","info","success","error","warning","defaultMessages","isToastShowing","createToastElement","finalMessage","backgroundColor","textColor","animationDuration","animationEasing","showCloseButton","showProgressBar","progressColor","progressHeight","progressPosition","duration","toast","document","createElement","textContent","style","background","color","padding","marginTop","borderRadius","boxShadow","opacity","transition","position","overflow","closeButton","marginLeft","border","cursor","onclick","addEventListener","remove","appendChild","addCloseButton","progressBar","left","height","width","requestAnimationFrame","showToast","message","type","toastBackgroundColor","toastTextColor","toastContainer","getElementById","id","zIndex","container","includes","bottom","top","right","transform","setPosition","body","createToastContainer","setTimeout","parentNode","createToast","options","setDefaultColors","newColors","Object","assign","setDefaultMessages","newMessages"],"mappings":";;;;;;;;;;;;;;;;;;AAyCA,IAAIA,EAAgB,CAClBC,KAAM,OACNC,QAAS,QACTC,MAAO,MACPC,QAAS,cAGPC,EAAkB,CACpBJ,KAAM,2BACNC,QAAS,iCACTC,MAAO,qBACPC,QAAS,8BAIPE,GAAiB,EAiCrB,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,MAAMC,EAAQC,SAASC,cAAc,OAiBrC,GAhBAF,EAAMG,YAAcd,EACpBW,EAAMI,MAAMC,WAAaf,EACzBU,EAAMI,MAAME,MAAQf,EACpBS,EAAMI,MAAMG,QAAU,YACtBP,EAAMI,MAAMI,UAAY,OACxBR,EAAMI,MAAMK,aAAe,MAC3BT,EAAMI,MAAM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G,gBACTA,GAAkB,EAAKF,kBACvBA,EAAiBC,gBACjBA,EAAeE,gBACfA,GAAkB,EAAKC,cACvBA,EAAaC,eACbA,EAAiB,MAAKC,iBACtBA,EAAmB,UACjBoD,EAMJrB,EAAU,CACRC,UACA/B,SAAUA,GAAY,IACtBc,WACAkB,OACAzC,kBACAC,YACAG,kBACAF,oBACAC,kBACAE,kBACAC,gBACAC,iBACAC,oBAEJ,CAQA,SAASqD,EAAiBC,GAEC,iBAAdA,GAKXC,OAAOC,OAAOzE,EAAeuE,EAC/B,CAQA,SAASG,EAAmBC,GAEC,iBAAhBA,GAKXH,OAAOC,OAAOpE,EAAiBsE,EACjC"}
|
|
1
|
+
{"version":3,"file":"index.esm.mjs","sources":["../src/utils/id.js","../src/utils/dom.js","../src/components/ToastContainer.js","../src/utils/position.js","../src/components/toast-utils.js","../src/components/Toast.js","../src/components/ToastManager.js","../src/index.js"],"sourcesContent":["// src/utils/id.js\r\n\"use strict\";\r\n\r\n/**\r\n * Generate unique ID for DOM elements to avoid conflicts\r\n * @param {string} prefix - Optional prefix for ID\r\n * @returns {string} Unique ID\r\n */\r\nexport function generateUniqueId(prefix = \"toast\") {\r\n return `${prefix}-${Date.now()}-${Math.floor(Math.random() * 100000)}`;\r\n}\r\n","// src/utils/dom.js\r\n\"use strict\";\r\n\r\nimport { generateUniqueId } from \"./id.js\";\r\n\r\n/**\r\n * Multi-layer fallback DOM element creation\r\n */\r\nexport function createElementWithId(tagName, prefix) {\r\n // PRIMARY: Standard createElement\r\n try {\r\n const el = document.createElement(tagName);\r\n el.id = generateUniqueId(prefix);\r\n return el;\r\n } catch (error) {\r\n console.warn(`Primary createElement failed for ${tagName}:`, error);\r\n\r\n // FALLBACK-A: Try div as alternative\r\n try {\r\n const fallbackEl = document.createElement(\"div\");\r\n fallbackEl.id = generateUniqueId(prefix || \"fallback\");\r\n fallbackEl.setAttribute(\"data-original-tag\", tagName);\r\n return fallbackEl;\r\n } catch (fallbackError) {\r\n console.error(\"All DOM creation methods failed:\", fallbackError);\r\n\r\n // FALLBACK-B: Return minimal object that won't crash\r\n return {\r\n id: generateUniqueId(prefix || \"emergency\"),\r\n style: {},\r\n appendChild: () => {},\r\n setAttribute: () => {},\r\n innerHTML: \"\",\r\n textContent: \"\",\r\n onclick: null,\r\n _isEmergencyElement: true,\r\n };\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Multi-strategy appendChild with graceful degradation\r\n */\r\nexport function appendChild(parent, child) {\r\n if (!parent || !child) return false;\r\n\r\n // PRIMARY: Standard appendChild\r\n try {\r\n if (!parent.contains(child)) {\r\n parent.appendChild(child);\r\n return true;\r\n }\r\n return true;\r\n } catch (error) {\r\n console.warn(\"Primary appendChild failed:\", error);\r\n\r\n // FALLBACK-A: insertAdjacentElement\r\n try {\r\n parent.insertAdjacentElement(\"beforeend\", child);\r\n return true;\r\n } catch (fallbackError) {\r\n console.warn(\"Fallback appendChild failed:\", fallbackError);\r\n\r\n // FALLBACK-B: Manual positioning\r\n try {\r\n if (parent === document.body) {\r\n child.style.position = \"fixed\";\r\n child.style.top = \"10px\";\r\n child.style.right = \"10px\";\r\n child.style.zIndex = \"99999\";\r\n document.body.insertAdjacentHTML(\"beforeend\", child.outerHTML || \"\");\r\n return true;\r\n }\r\n } catch (emergencyError) {\r\n console.error(\"All append strategies failed:\", emergencyError);\r\n return false;\r\n }\r\n }\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Safe element removal with multiple strategies\r\n */\r\nexport function removeElement(el) {\r\n if (!el) return true;\r\n\r\n // PRIMARY: parentNode.removeChild\r\n try {\r\n if (el.parentNode) {\r\n el.parentNode.removeChild(el);\r\n return true;\r\n }\r\n } catch (error) {\r\n console.warn(\"Primary removal failed:\", error);\r\n\r\n // FALLBACK-A: element.remove()\r\n try {\r\n if (el.remove) {\r\n el.remove();\r\n return true;\r\n }\r\n } catch (fallbackError) {\r\n console.warn(\"Fallback removal failed:\", fallbackError);\r\n\r\n // FALLBACK-B: Hide instead of remove\r\n try {\r\n el.style.display = \"none\";\r\n el.style.opacity = \"0\";\r\n el.style.pointerEvents = \"none\";\r\n el.style.position = \"absolute\";\r\n el.style.left = \"-9999px\";\r\n return true;\r\n } catch (hideError) {\r\n console.error(\"All removal strategies failed:\", hideError);\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n}\r\n\r\n/**\r\n * Animation duration parser with fallbacks\r\n */\r\nexport function parseAnimationDuration(duration) {\r\n // PRIMARY: Parse provided duration\r\n try {\r\n if (typeof duration === \"number\" && duration > 0) return duration;\r\n if (typeof duration === \"string\") {\r\n if (duration.endsWith(\"s\") && !duration.endsWith(\"ms\")) {\r\n const parsed = parseFloat(duration) * 1000;\r\n return parsed > 0 ? parsed : 500;\r\n }\r\n const parsed = parseFloat(duration);\r\n return parsed > 0 ? parsed : 500;\r\n }\r\n } catch (error) {\r\n console.warn(\"Duration parsing failed:\", error);\r\n }\r\n\r\n // FALLBACK: Safe default\r\n return 500;\r\n}\r\n\r\n/**\r\n * Force reflow with error protection\r\n */\r\nexport function forceReflow(el) {\r\n try {\r\n return el?.offsetWidth || 0;\r\n } catch (error) {\r\n console.warn(\"Force reflow failed:\", error);\r\n return 0;\r\n }\r\n}\r\n\r\n/**\r\n * Query selector shortcut with optional root.\r\n * @param {string} selector\r\n * @param {Document|HTMLElement} [root=document]\r\n * @returns {Element|null}\r\n */\r\nexport function query(selector, root = document) {\r\n return root.querySelector(selector);\r\n}\r\n","// src/components/ToastContainer.js //# Container logic\r\n\"use strict\";\r\n\r\nimport { setPosition } from \"../utils/position.js\";\r\nimport { appendChild } from \"../utils/dom.js\";\r\n\r\n/**\r\n * Create toast container with error handling\r\n * @param {string} position - Toast position\r\n * @returns {HTMLElement} Toast container element\r\n */\r\nexport function createToastContainer(position) {\r\n try {\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n setPosition(toastContainer, position);\r\n appendChild(document.body, toastContainer);\r\n }\r\n\r\n return toastContainer;\r\n } catch (error) {\r\n console.error(\"Failed to create toast container:\", error);\r\n // Fallback: return body element\r\n return document.body;\r\n }\r\n}\r\n","// src/utils/position.js\r\n\"use strict\";\r\n\r\n/**\r\n * Set position for toast container (EXACT same logic as original)\r\n * @param {HTMLElement} container - Toast container element\r\n * @param {string} position - Position string\r\n */\r\nexport function setPosition(container, position) {\r\n // Reset all position properties first\r\n container.style.top = \"auto\";\r\n container.style.bottom = \"auto\";\r\n container.style.left = \"auto\";\r\n container.style.right = \"auto\";\r\n container.style.transform = \"none\";\r\n\r\n if (position.includes(\"bottom\")) {\r\n container.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n container.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n container.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n container.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n container.style.top = \"50%\";\r\n container.style.left = \"50%\";\r\n container.style.transform = \"translate(-50%, -50%)\";\r\n }\r\n}\r\n","\"use strict\";\r\n\r\nimport { forceReflow, parseAnimationDuration } from \"../utils/dom.js\";\r\n\r\n/**\r\n * Create close button for toast\r\n * @param {HTMLElement} toast - Toast element\r\n * @param {Object} options - Toast options\r\n * @param {Function} onClose - Close callback\r\n */\r\nexport function createCloseButton(toast, options, onClose) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.innerHTML = \"×\";\r\n Object.assign(closeButton.style, {\r\n background: \"none\",\r\n border: \"none\",\r\n color: options.textColor || \"white\",\r\n fontSize: \"18px\",\r\n marginLeft: \"10px\",\r\n cursor: \"pointer\",\r\n });\r\n\r\n closeButton.onclick = () => onClose(toast);\r\n toast.appendChild(closeButton);\r\n\r\n toast._cleanupCloseButton = () => {\r\n closeButton.onclick = null;\r\n };\r\n}\r\n\r\n/**\r\n * Create progress bar for toast\r\n * @param {HTMLElement} toast - Toast element\r\n * @param {Object} options - Toast options\r\n */\r\nexport function createProgressBar(toast, options) {\r\n const progressBar = document.createElement(\"div\");\r\n Object.assign(progressBar.style, {\r\n position: \"absolute\",\r\n left: \"0\",\r\n height: options.progressHeight || \"4px\",\r\n background: options.progressColor || \"rgba(255, 255, 255, 0.3)\",\r\n width: \"100%\",\r\n transition: `width ${options.duration || 3000}ms linear`,\r\n [options.progressPosition === \"top\" ? \"top\" : \"bottom\"]: \"0\",\r\n });\r\n\r\n toast.appendChild(progressBar);\r\n\r\n setTimeout(() => {\r\n forceReflow(progressBar);\r\n progressBar.style.width = \"0%\";\r\n }, 100);\r\n}\r\n\r\n/**\r\n * Run toast fade-in animation\r\n * @param {HTMLElement} toast - Toast element\r\n */\r\nexport function runToastAnimation(toast) {\r\n setTimeout(() => {\r\n toast.style.opacity = \"1\";\r\n toast.style.transform = \"translateY(0)\";\r\n }, 50);\r\n}\r\n\r\n/**\r\n * Apply rich styling to toast element\r\n * @param {HTMLElement} toast - Toast element\r\n * @param {Object} options - Toast options\r\n * @param {Function} onClose - Close callback\r\n */\r\nexport function applyRichStyling(toast, options, onClose) {\r\n const animDurationMs = parseAnimationDuration(\r\n options.animationDuration || \"0.5s\"\r\n );\r\n\r\n // Apply full styling\r\n Object.assign(toast.style, {\r\n background: options.backgroundColor || options.color || \"#333\",\r\n color: options.textColor || \"white\",\r\n padding: \"12px 20px\",\r\n marginBottom: \"10px\",\r\n borderRadius: \"5px\",\r\n display: \"flex\",\r\n alignItems: \"center\",\r\n justifyContent: \"space-between\",\r\n boxShadow: \"0 4px 6px rgba(0, 0, 0, 0.1)\",\r\n minWidth: \"250px\",\r\n maxWidth: \"400px\",\r\n opacity: \"0\",\r\n position: \"relative\",\r\n transition: `opacity ${options.animationDuration || \"0.5s\"} ${\r\n options.animationEasing || \"ease\"\r\n }, transform ${options.animationDuration || \"0.5s\"} ${\r\n options.animationEasing || \"ease\"\r\n }`,\r\n transform: \"translateY(20px)\",\r\n zIndex: \"9999\",\r\n });\r\n\r\n toast._animationDuration = animDurationMs;\r\n\r\n // Message span\r\n const messageSpan = document.createElement(\"span\");\r\n messageSpan.textContent = options.message || \"Notification\";\r\n messageSpan.style.flex = \"1\";\r\n toast.appendChild(messageSpan);\r\n\r\n // Close button\r\n if (options.showCloseButton) {\r\n createCloseButton(toast, options, onClose);\r\n }\r\n\r\n // Progress bar\r\n if (options.showProgressBar) {\r\n createProgressBar(toast, options);\r\n }\r\n\r\n // Animation\r\n runToastAnimation(toast);\r\n}\r\n\r\n/**\r\n * Create basic fallback toast\r\n * @param {HTMLElement} toast - Toast element\r\n * @param {Object} options - Toast options\r\n * @param {Function} onClose - Close callback\r\n */\r\nexport function createBasicToast(toast, options, onClose) {\r\n // Basic styling only\r\n Object.assign(toast.style, {\r\n background: \"#333\",\r\n color: \"white\",\r\n padding: \"10px 15px\",\r\n margin: \"10px\",\r\n borderRadius: \"3px\",\r\n position: \"fixed\",\r\n top: \"20px\",\r\n right: \"20px\",\r\n zIndex: \"99999\",\r\n maxWidth: \"300px\",\r\n wordWrap: \"break-word\",\r\n });\r\n\r\n toast.textContent = options.message || \"Notification\";\r\n\r\n if (options.showCloseButton) {\r\n toast.style.cursor = \"pointer\";\r\n toast.onclick = () => onClose(toast);\r\n }\r\n\r\n toast._animationDuration = 500;\r\n}\r\n\r\n/**\r\n * Emergency toast as last resort\r\n * @param {Object} options - Toast options\r\n * @param {Function} onClose - Close callback\r\n */\r\nexport function createEmergencyToast(options, onClose) {\r\n try {\r\n // Create emergency div\r\n const emergency = document.createElement(\"div\");\r\n emergency.id = `emergency-${Date.now()}`;\r\n emergency.innerHTML = `\r\n <div style=\"\r\n background: #333 !important;\r\n color: white !important;\r\n padding: 10px 15px !important;\r\n position: fixed !important;\r\n top: 20px !important;\r\n right: 20px !important;\r\n z-index: 99999 !important;\r\n border-radius: 3px !important;\r\n max-width: 250px !important;\r\n word-wrap: break-word !important;\r\n font-family: Arial, sans-serif !important;\r\n font-size: 14px !important;\r\n box-shadow: 0 2px 10px rgba(0,0,0,0.3) !important;\r\n cursor: pointer !important;\r\n \" onclick=\"this.parentNode.removeChild(this)\">\r\n ${options.message || \"Notification\"}\r\n <span style=\"float: right; margin-left: 10px; font-weight: bold;\">×</span>\r\n </div>\r\n `;\r\n\r\n emergency._animationDuration = 500;\r\n emergency._isEmergencyToast = true;\r\n\r\n // Auto remove\r\n setTimeout(() => {\r\n try {\r\n if (emergency.parentNode) {\r\n emergency.parentNode.removeChild(emergency);\r\n }\r\n onClose(emergency);\r\n } catch (error) {\r\n console.warn(\"Emergency cleanup failed:\", error);\r\n }\r\n }, options.duration || 3000);\r\n\r\n return emergency;\r\n } catch (emergencyError) {\r\n console.error(\"Emergency toast creation failed:\", emergencyError);\r\n\r\n // ULTIMATE FALLBACK: Alert\r\n setTimeout(() => {\r\n try {\r\n alert(options.message || \"Toast Notification\");\r\n onClose(null);\r\n } catch (alertError) {\r\n console.error(\"Ultimate fallback failed:\", alertError);\r\n onClose(null);\r\n }\r\n }, 100);\r\n\r\n return null;\r\n }\r\n}\r\n","// src/components/Toast.js //# Single responsibility\r\n\"use strict\";\r\n\r\nimport { createElementWithId } from \"../utils/dom.js\";\r\nimport {\r\n applyRichStyling,\r\n createBasicToast,\r\n createEmergencyToast,\r\n} from \"./toast-utils.js\";\r\n\r\n/**\r\n * Multi-layer toast creation with satellite-grade fallbacks\r\n * @param {Object} options - Toast configuration options\r\n * @param {Function} onClose - Callback when toast closes\r\n * @returns {HTMLElement} Toast element\r\n */\r\nexport function createToastElement(options, onClose) {\r\n let toast;\r\n let isEmergencyMode = false;\r\n\r\n // PRIMARY: Full-featured toast\r\n try {\r\n toast = createElementWithId(\"div\", \"toast\");\r\n\r\n if (toast._isEmergencyElement) {\r\n isEmergencyMode = true;\r\n console.warn(\"Toast created in emergency mode\");\r\n }\r\n } catch (error) {\r\n console.error(\"Toast creation failed:\", error);\r\n isEmergencyMode = true;\r\n // FALLBACK: Basic object structure\r\n toast = {\r\n id: `emergency-toast-${Date.now()}`,\r\n style: {},\r\n appendChild: () => {},\r\n innerHTML: \"\",\r\n textContent: \"\",\r\n _isEmergencyElement: true,\r\n };\r\n }\r\n\r\n // PRIMARY: Rich styling and features\r\n if (!isEmergencyMode) {\r\n try {\r\n applyRichStyling(toast, options, onClose);\r\n return toast;\r\n } catch (stylingError) {\r\n console.warn(\r\n \"Rich toast styling failed, switching to basic mode:\",\r\n stylingError\r\n );\r\n isEmergencyMode = true;\r\n }\r\n }\r\n\r\n // FALLBACK-A: Basic functional toast\r\n if (isEmergencyMode && !toast._isEmergencyElement) {\r\n try {\r\n createBasicToast(toast, options, onClose);\r\n return toast;\r\n } catch (basicError) {\r\n console.error(\"Basic toast creation failed:\", basicError);\r\n }\r\n }\r\n\r\n // FALLBACK-B: Emergency notification system\r\n return createEmergencyToast(options, onClose);\r\n}\r\n","// src/components/ToastManager.js //# State management\r\n\"use strict\";\r\n\r\nimport { createToastContainer } from \"./ToastContainer.js\";\r\nimport { createToastElement } from \"./Toast.js\";\r\nimport { removeElement } from \"../utils/dom.js\";\r\n\r\n// State management with fallback tracking\r\nlet isToastShowing = false;\r\nlet currentToast = null;\r\nlet emergencyTimeouts = new Set();\r\nlet emergencyCleanupScheduled = false;\r\n\r\n/**\r\n * Show toast with comprehensive fallback system\r\n */\r\nexport function showToast(options) {\r\n // Prevent multiple toasts (original behavior)\r\n if (isToastShowing) {\r\n console.warn(\"Toast already showing, ignoring request\");\r\n return;\r\n }\r\n\r\n isToastShowing = true;\r\n\r\n // PRIMARY: Full toast system\r\n try {\r\n const container = createToastContainer(options.position);\r\n const toast = createToastElement(options, closeToast);\r\n\r\n if (!toast) {\r\n throw new Error(\"Toast creation returned null\");\r\n }\r\n\r\n currentToast = toast;\r\n\r\n // Append to container\r\n if (container.appendChild) {\r\n container.appendChild(toast);\r\n } else {\r\n // Container is emergency fallback\r\n document.body.appendChild(toast);\r\n }\r\n\r\n // Schedule auto-dismiss\r\n const dismissTimeout = setTimeout(() => {\r\n closeToast(toast);\r\n }, options.duration || 3000);\r\n\r\n emergencyTimeouts.add(dismissTimeout);\r\n\r\n // Emergency cleanup backup\r\n scheduleEmergencyCleanup(options.duration || 3000);\r\n\r\n return;\r\n } catch (primaryError) {\r\n console.warn(\"Primary toast system failed:\", primaryError);\r\n }\r\n\r\n // FALLBACK-A: Direct body placement\r\n try {\r\n const simpleToast = createSimpleToast(options);\r\n currentToast = simpleToast;\r\n document.body.appendChild(simpleToast);\r\n\r\n setTimeout(() => {\r\n closeToast(simpleToast);\r\n }, options.duration || 3000);\r\n\r\n return;\r\n } catch (fallbackError) {\r\n console.warn(\"Fallback toast failed:\", fallbackError);\r\n }\r\n\r\n // FALLBACK-B: Browser alert\r\n try {\r\n alert(options.message || \"Notification\");\r\n isToastShowing = false;\r\n } catch (alertError) {\r\n console.error(\"All toast systems failed:\", alertError);\r\n isToastShowing = false;\r\n }\r\n}\r\n\r\n/**\r\n * Create simple toast for fallback\r\n */\r\nfunction createSimpleToast(options) {\r\n const simple = document.createElement(\"div\");\r\n simple.style.cssText = `\r\n position: fixed !important;\r\n top: 20px !important;\r\n right: 20px !important;\r\n background: #333 !important;\r\n color: white !important;\r\n padding: 12px 20px !important;\r\n border-radius: 5px !important;\r\n z-index: 99999 !important;\r\n max-width: 300px !important;\r\n font-family: Arial, sans-serif !important;\r\n cursor: pointer !important;\r\n `;\r\n simple.textContent = options.message || \"Notification\";\r\n simple.onclick = () => closeToast(simple);\r\n return simple;\r\n}\r\n\r\n/**\r\n * Close toast with multi-strategy cleanup\r\n */\r\nfunction closeToast(toast) {\r\n try {\r\n if (!toast) {\r\n resetToastState();\r\n return;\r\n }\r\n\r\n // Animation if supported\r\n if (toast.style && !toast._isEmergencyToast) {\r\n toast.style.opacity = \"0\";\r\n toast.style.transform = \"translateY(-20px)\";\r\n\r\n const animDuration = toast._animationDuration || 500;\r\n setTimeout(() => {\r\n performCleanup(toast);\r\n }, animDuration);\r\n } else {\r\n // Immediate cleanup for emergency toasts\r\n performCleanup(toast);\r\n }\r\n } catch (error) {\r\n console.error(\"Close toast failed:\", error);\r\n forceEmergencyCleanup();\r\n }\r\n}\r\n\r\n/**\r\n * Perform comprehensive cleanup\r\n */\r\nfunction performCleanup(toast) {\r\n try {\r\n // Cleanup event listeners\r\n if (toast._cleanupCloseButton) {\r\n toast._cleanupCloseButton();\r\n }\r\n\r\n // Remove from DOM\r\n removeElement(toast);\r\n\r\n // Reset state\r\n resetToastState();\r\n } catch (error) {\r\n console.error(\"Cleanup failed:\", error);\r\n forceEmergencyCleanup();\r\n }\r\n}\r\n\r\n/**\r\n * Reset all toast state\r\n */\r\nfunction resetToastState() {\r\n isToastShowing = false;\r\n currentToast = null;\r\n\r\n // Clear all timeouts\r\n emergencyTimeouts.forEach((id) => {\r\n try {\r\n clearTimeout(id);\r\n } catch (error) {\r\n console.warn(\"Timeout clear failed:\", error);\r\n }\r\n });\r\n emergencyTimeouts.clear();\r\n emergencyCleanupScheduled = false;\r\n}\r\n\r\n/**\r\n * Schedule emergency cleanup\r\n */\r\nfunction scheduleEmergencyCleanup(duration) {\r\n if (emergencyCleanupScheduled) return;\r\n\r\n emergencyCleanupScheduled = true;\r\n const emergencyTimeout = setTimeout(() => {\r\n console.warn(\"Emergency cleanup triggered\");\r\n forceEmergencyCleanup();\r\n }, duration * 2.5); // 2.5x safety margin\r\n\r\n emergencyTimeouts.add(emergencyTimeout);\r\n}\r\n\r\n/**\r\n * Force emergency cleanup of everything\r\n */\r\nfunction forceEmergencyCleanup() {\r\n try {\r\n // Remove current toast\r\n if (currentToast) {\r\n removeElement(currentToast);\r\n }\r\n\r\n // Clean up any orphaned toast elements\r\n const orphanedToasts = document.querySelectorAll(\r\n '[id*=\"toast\"], [id*=\"emergency\"]'\r\n );\r\n orphanedToasts.forEach((element) => {\r\n try {\r\n removeElement(element);\r\n } catch (error) {\r\n console.warn(\"Orphaned element cleanup failed:\", error);\r\n }\r\n });\r\n\r\n // Reset all state\r\n resetToastState();\r\n } catch (error) {\r\n console.error(\"Force cleanup failed:\", error);\r\n // Final state reset\r\n isToastShowing = false;\r\n currentToast = null;\r\n }\r\n}\r\n","// src/index.js\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Customizable Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version __VERSION__\r\n * @build Production\r\n * @license Apache-2.0\r\n * @depends None\r\n * @description A lightweight and fully customizable toast notification library\r\n * designed for seamless integration with any JavaScript or framework-based UI.\r\n * Supports flexible positioning, theming, icons, animations, and timing options\r\n * out of the box β with zero dependencies.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * License: Apache-2.0\r\n * Dependencies: None\r\n */\r\n\r\n\"use strict\";\r\n\r\nimport { showToast } from \"./components/ToastManager.js\";\r\n\r\n// Protected state with fallbacks\r\nlet defaultColors = {\r\n success: \"#28a745\",\r\n error: \"#dc3545\",\r\n warning: \"#ffc107\",\r\n info: \"#17a2b8\",\r\n};\r\n\r\nlet defaultMessages = {\r\n success: \"Operation completed successfully!\",\r\n error: \"Something went wrong!\",\r\n warning: \"Warning message!\",\r\n info: \"Information message!\",\r\n};\r\n\r\n/**\r\n * Create toast with satellite-grade reliability\r\n */\r\nfunction createToast(options = {}) {\r\n try {\r\n // Input sanitization and validation\r\n const sanitizedOptions = sanitizeToastOptions(options);\r\n\r\n // Call main toast system\r\n showToast(sanitizedOptions);\r\n } catch (error) {\r\n console.error(\"CreateToast failed:\", error);\r\n\r\n // ULTIMATE FALLBACK: Browser alert with sanitized message\r\n const safeMessage =\r\n typeof options?.message === \"string\"\r\n ? options.message.substring(0, 200)\r\n : \"Toast notification failed\";\r\n\r\n try {\r\n alert(safeMessage);\r\n } catch (alertError) {\r\n console.error(\"Ultimate fallback failed:\", alertError);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Sanitize and normalize toast options\r\n */\r\nfunction sanitizeToastOptions(options) {\r\n const defaults = {\r\n duration: 3000,\r\n position: \"bottom-right\",\r\n type: \"info\",\r\n backgroundColor: undefined,\r\n textColor: \"white\",\r\n showCloseButton: false,\r\n animationDuration: \"0.5s\",\r\n animationEasing: \"ease\",\r\n showProgressBar: false,\r\n progressColor: undefined,\r\n progressHeight: \"4px\",\r\n progressPosition: \"bottom\",\r\n };\r\n\r\n // Start with safe defaults\r\n let final = { ...defaults };\r\n\r\n // Merge user options safely\r\n if (options && typeof options === \"object\" && !Array.isArray(options)) {\r\n Object.keys(defaults).forEach((key) => {\r\n if (options.hasOwnProperty(key)) {\r\n final[key] = options[key];\r\n }\r\n });\r\n\r\n // Handle message separately\r\n if (options.message !== undefined) {\r\n final.message = options.message;\r\n }\r\n }\r\n\r\n // Validate and apply defaults\r\n try {\r\n if (!final.backgroundColor && final.type && defaultColors[final.type]) {\r\n final.backgroundColor = defaultColors[final.type];\r\n }\r\n\r\n if (!final.message && final.type && defaultMessages[final.type]) {\r\n final.message = defaultMessages[final.type];\r\n }\r\n } catch (error) {\r\n console.warn(\"Option processing failed:\", error);\r\n }\r\n\r\n // Final safety checks\r\n if (!final.message || typeof final.message !== \"string\") {\r\n final.message = \"Notification\";\r\n }\r\n\r\n if (typeof final.duration !== \"number\" || final.duration < 100) {\r\n final.duration = 3000;\r\n }\r\n\r\n return final;\r\n}\r\n\r\n/**\r\n * Set default colors with validation\r\n */\r\nfunction setDefaultColors(colors) {\r\n try {\r\n if (colors && typeof colors === \"object\" && !Array.isArray(colors)) {\r\n defaultColors = { ...defaultColors, ...colors };\r\n }\r\n } catch (error) {\r\n console.error(\"setDefaultColors failed:\", error);\r\n }\r\n}\r\n\r\n/**\r\n * Set default messages with validation\r\n */\r\nfunction setDefaultMessages(messages) {\r\n try {\r\n if (messages && typeof messages === \"object\" && !Array.isArray(messages)) {\r\n defaultMessages = { ...defaultMessages, ...messages };\r\n }\r\n } catch (error) {\r\n console.error(\"setDefaultMessages failed:\", error);\r\n }\r\n}\r\n\r\n// Module exports\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n\r\n// Global assignment with protection\r\ntry {\r\n // UMD/Global support\r\n if (typeof window !== \"undefined\") {\r\n window.customizableToast = {\r\n createToast,\r\n setDefaultColors,\r\n setDefaultMessages,\r\n };\r\n }\r\n} catch (error) {\r\n console.error(\"Global assignment failed:\", error);\r\n}\r\n"],"names":["generateUniqueId","prefix","Date","now","Math","floor","random","removeElement","el","parentNode","removeChild","error","remove","fallbackError","style","display","opacity","pointerEvents","position","left","hideError","createToastContainer","toastContainer","document","getElementById","createElement","id","zIndex","container","top","bottom","right","transform","includes","setPosition","parent","child","contains","appendChild","insertAdjacentElement","body","insertAdjacentHTML","outerHTML","emergencyError","applyRichStyling","toast","options","onClose","animDurationMs","duration","endsWith","parsed","parseFloat","parseAnimationDuration","animationDuration","Object","assign","background","backgroundColor","color","textColor","padding","marginBottom","borderRadius","alignItems","justifyContent","boxShadow","minWidth","maxWidth","transition","animationEasing","_animationDuration","messageSpan","textContent","message","flex","showCloseButton","closeButton","innerHTML","border","fontSize","marginLeft","cursor","onclick","_cleanupCloseButton","createCloseButton","showProgressBar","progressBar","height","progressHeight","progressColor","width","progressPosition","setTimeout","offsetWidth","forceReflow","createProgressBar","runToastAnimation","createToastElement","isEmergencyMode","tagName","fallbackEl","setAttribute","_isEmergencyElement","createElementWithId","stylingError","margin","wordWrap","createBasicToast","basicError","emergency","_isEmergencyToast","alert","alertError","createEmergencyToast","isToastShowing","currentToast","emergencyTimeouts","Set","emergencyCleanupScheduled","showToast","closeToast","Error","dismissTimeout","add","emergencyTimeout","forceEmergencyCleanup","scheduleEmergencyCleanup","primaryError","simpleToast","simple","cssText","createSimpleToast","resetToastState","animDuration","performCleanup","forEach","clearTimeout","clear","querySelectorAll","element","defaultColors","success","warning","info","defaultMessages","createToast","sanitizedOptions","defaults","type","undefined","final","Array","isArray","keys","key","hasOwnProperty","sanitizeToastOptions","safeMessage","substring","setDefaultColors","colors","setDefaultMessages","messages","window","customizableToast"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,EACwB,iBAArBhH,GAAS4B,QACZ5B,EAAQ4B,QAAQqF,UAAU,EAAG,KAC7B,4BAEN,IACE/C,MAAM8C,EACP,CAAC,MAAO7C,GAER,CACF,CACH,CAkEA,SAAS+C,EAAiBC,GACxB,IACMA,GAA4B,iBAAXA,IAAwBT,MAAMC,QAAQQ,KACzDpB,EAAgB,IAAKA,KAAkBoB,GAE1C,CAAC,MAAOtJ,GAER,CACH,CAKA,SAASuJ,EAAmBC,GAC1B,IACMA,GAAgC,iBAAbA,IAA0BX,MAAMC,QAAQU,KAC7DlB,EAAkB,IAAKA,KAAoBkB,GAE9C,CAAC,MAAOxJ,GAER,CACH,CAMA,IAEwB,oBAAXyJ,SACTA,OAAOC,kBAAoB,CACzBnB,cACAc,mBACAE,sBAGN,CAAE,MAAOvJ,GAET"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* out of the box β with zero dependencies.
|
|
14
|
-
* Author: Priyanshu Patel
|
|
15
|
-
* Email: priyanshu.alt191@gmail.com
|
|
16
|
-
* Created: July 31, 2024
|
|
17
|
-
* License: Apache-2.0
|
|
18
|
-
* Dependencies: None
|
|
19
|
-
*/let t={info:"blue",success:"green",error:"red",warning:"darkorange"},o={info:"This is an info message.",success:"Action completed successfully!",error:"An error occurred!",warning:"This is a warning message!"},s=!1;function n(e,t,o,n,i,r,a,l,c,d,p){const u=document.createElement("div");if(u.textContent=e,u.style.background=t,u.style.color=o,u.style.padding="10px 20px",u.style.marginTop="10px",u.style.borderRadius="5px",u.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.1)",u.style.opacity="0",u.style.transition=`opacity ${n} ${i}`,u.style.position="relative",u.style.overflow="hidden",r&&function(e,t){const o=document.createElement("button");o.textContent="Γ",o.style.marginLeft="10px",o.style.background="transparent",o.style.border="none",o.style.color=t,o.style.cursor="pointer",o.onclick=()=>{e.style.opacity="0",e.addEventListener("transitionend",()=>{e.remove(),s=!1})},e.appendChild(o)}(u,o),a){const e=document.createElement("div");e.style.position="absolute",e.style["top"===d?"top":"bottom"]="0",e.style.left="0",e.style.height=c||"4px",e.style.backgroundColor=l||o,e.style.width="100%",e.style.transition=`width ${p}ms linear`,requestAnimationFrame(()=>{e.style.width="0%"}),u.appendChild(e)}return u}function i({message:e,duration:i,position:r,type:a,backgroundColor:l,textColor:c,showCloseButton:d,animationDuration:p,animationEasing:u,showProgressBar:y,progressColor:g,progressHeight:f,progressPosition:m}){if(s)return;s=!0;const h=e||o[a]||"This is a default message.",b=l||t[a]||"gray",x=c||("white"===b?"black":"white"),C=function(e){let t=document.getElementById(`toast-container-${e}`);return t||(t=document.createElement("div"),t.id=`toast-container-${e}`,t.style.position="fixed",t.style.zIndex="9999",function(e,t){t.includes("bottom")?e.style.bottom="10px":t.includes("top")&&(e.style.top="10px"),t.includes("right")?e.style.right="10px":t.includes("left")?e.style.left="10px":t.includes("center")&&(e.style.top="50%",e.style.left="50%",e.style.transform="translate(-50%, -50%)")}(t,e),document.body.appendChild(t)),t}(r),w=n(h,b,x,p||"0.5s",u||"ease",d,y,g,f,m,i||3e3);C.appendChild(w),requestAnimationFrame(()=>{w.style.opacity="1"}),setTimeout(()=>{w.parentNode&&(w.style.opacity="0",w.addEventListener("transitionend",()=>{w.remove(),s=!1}))},i||3e3)}e.createToast=function(e){if("object"!=typeof e)return;const{message:t,duration:o,position:s="bottom-right",type:n="info",backgroundColor:r,textColor:a,showCloseButton:l=!1,animationDuration:c,animationEasing:d,showProgressBar:p=!1,progressColor:u,progressHeight:y="4px",progressPosition:g="bottom"}=e;i({message:t,duration:o||3e3,position:s,type:n,backgroundColor:r,textColor:a,showCloseButton:l,animationDuration:c,animationEasing:d,showProgressBar:p,progressColor:u,progressHeight:y,progressPosition:g})},e.setDefaultColors=function(e){"object"==typeof e&&Object.assign(t,e)},e.setDefaultMessages=function(e){"object"==typeof e&&Object.assign(o,e)},Object.defineProperty(e,"__esModule",{value:!0})});
|
|
1
|
+
/*!
|
|
2
|
+
* Customizable Toast Notifications 3.4.0
|
|
3
|
+
* Build: 2025-07-19 18:22:36
|
|
4
|
+
* Cache-Buster: 1752949356123
|
|
5
|
+
* Author: Priyanshu Patel
|
|
6
|
+
* Email: priyanshu.alt191@gmail.com
|
|
7
|
+
* License: Apache-2.0
|
|
8
|
+
* Dependencies: None
|
|
9
|
+
* Created: July 31, 2024
|
|
10
|
+
* A lightweight toast notification library for any JavaScript framework
|
|
11
|
+
*/
|
|
12
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).customizableToast={})}(this,function(t){"use strict";function e(t="toast"){return`${t}-${Date.now()}-${Math.floor(1e5*Math.random())}`}function n(t){if(!t)return!0;try{if(t.parentNode)return t.parentNode.removeChild(t),!0}catch(e){try{if(t.remove)return t.remove(),!0}catch(e){try{return t.style.display="none",t.style.opacity="0",t.style.pointerEvents="none",t.style.position="absolute",t.style.left="-9999px",!0}catch(t){return!1}}}return!0}function o(t){try{let e=document.getElementById(`toast-container-${t}`);return e||(e=document.createElement("div"),e.id=`toast-container-${t}`,e.style.position="fixed",e.style.zIndex="9999",function(t,e){t.style.top="auto",t.style.bottom="auto",t.style.left="auto",t.style.right="auto",t.style.transform="none",e.includes("bottom")?t.style.bottom="10px":e.includes("top")&&(t.style.top="10px"),e.includes("right")?t.style.right="10px":e.includes("left")?t.style.left="10px":e.includes("center")&&(t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)")}(e,t),function(t,e){if(!t||!e)return!1;try{return t.contains(e)||t.appendChild(e),!0}catch(n){try{return t.insertAdjacentElement("beforeend",e),!0}catch(n){try{if(t===document.body)return e.style.position="fixed",e.style.top="10px",e.style.right="10px",e.style.zIndex="99999",document.body.insertAdjacentHTML("beforeend",e.outerHTML||""),!0}catch(t){return!1}}}}(document.body,e)),e}catch(t){return document.body}}function r(t,e,n){const o=function(t){try{if("number"==typeof t&&t>0)return t;if("string"==typeof t){if(t.endsWith("s")&&!t.endsWith("ms")){const e=1e3*parseFloat(t);return e>0?e:500}const e=parseFloat(t);return e>0?e:500}}catch(t){}return 500}(e.animationDuration||"0.5s");Object.assign(t.style,{background:e.backgroundColor||e.color||"#333",color:e.textColor||"white",padding:"12px 20px",marginBottom:"10px",borderRadius:"5px",display:"flex",alignItems:"center",justifyContent:"space-between",boxShadow:"0 4px 6px rgba(0, 0, 0, 0.1)",minWidth:"250px",maxWidth:"400px",opacity:"0",position:"relative",transition:`opacity ${e.animationDuration||"0.5s"} ${e.animationEasing||"ease"}, transform ${e.animationDuration||"0.5s"} ${e.animationEasing||"ease"}`,transform:"translateY(20px)",zIndex:"9999"}),t._animationDuration=o;const r=document.createElement("span");r.textContent=e.message||"Notification",r.style.flex="1",t.appendChild(r),e.showCloseButton&&function(t,e,n){const o=document.createElement("button");o.innerHTML="×",Object.assign(o.style,{background:"none",border:"none",color:e.textColor||"white",fontSize:"18px",marginLeft:"10px",cursor:"pointer"}),o.onclick=()=>n(t),t.appendChild(o),t._cleanupCloseButton=()=>{o.onclick=null}}(t,e,n),e.showProgressBar&&function(t,e){const n=document.createElement("div");Object.assign(n.style,{position:"absolute",left:"0",height:e.progressHeight||"4px",background:e.progressColor||"rgba(255, 255, 255, 0.3)",width:"100%",transition:`width ${e.duration||3e3}ms linear`,["top"===e.progressPosition?"top":"bottom"]:"0"}),t.appendChild(n),setTimeout(()=>{!function(t){try{return t?.offsetWidth||0}catch(t){return 0}}(n),n.style.width="0%"},100)}(t,e),function(t){setTimeout(()=>{t.style.opacity="1",t.style.transform="translateY(0)"},50)}(t)}function i(t,n){let o,i=!1;try{o=function(t,n){try{const o=document.createElement(t);return o.id=e(n),o}catch(o){try{const o=document.createElement("div");return o.id=e(n||"fallback"),o.setAttribute("data-original-tag",t),o}catch(t){return{id:e(n||"emergency"),style:{},appendChild:()=>{},setAttribute:()=>{},innerHTML:"",textContent:"",onclick:null,_isEmergencyElement:!0}}}}("div","toast"),o._isEmergencyElement&&(i=!0)}catch(t){i=!0,o={id:`emergency-toast-${Date.now()}`,style:{},appendChild:()=>{},innerHTML:"",textContent:"",_isEmergencyElement:!0}}if(!i)try{return r(o,t,n),o}catch(t){i=!0}if(i&&!o._isEmergencyElement)try{return function(t,e,n){Object.assign(t.style,{background:"#333",color:"white",padding:"10px 15px",margin:"10px",borderRadius:"3px",position:"fixed",top:"20px",right:"20px",zIndex:"99999",maxWidth:"300px",wordWrap:"break-word"}),t.textContent=e.message||"Notification",e.showCloseButton&&(t.style.cursor="pointer",t.onclick=()=>n(t)),t._animationDuration=500}(o,t,n),o}catch(t){}return function(t,e){try{const n=document.createElement("div");return n.id=`emergency-${Date.now()}`,n.innerHTML=`\n <div style="\n background: #333 !important;\n color: white !important;\n padding: 10px 15px !important;\n position: fixed !important;\n top: 20px !important;\n right: 20px !important;\n z-index: 99999 !important;\n border-radius: 3px !important;\n max-width: 250px !important;\n word-wrap: break-word !important;\n font-family: Arial, sans-serif !important;\n font-size: 14px !important;\n box-shadow: 0 2px 10px rgba(0,0,0,0.3) !important;\n cursor: pointer !important;\n " onclick="this.parentNode.removeChild(this)">\n ${t.message||"Notification"}\n <span style="float: right; margin-left: 10px; font-weight: bold;">×</span>\n </div>\n `,n._animationDuration=500,n._isEmergencyToast=!0,setTimeout(()=>{try{n.parentNode&&n.parentNode.removeChild(n),e(n)}catch(t){}},t.duration||3e3),n}catch(n){return setTimeout(()=>{try{alert(t.message||"Toast Notification"),e(null)}catch(t){e(null)}},100),null}}(t,n)}let a=!1,s=null,c=new Set,l=!1;function u(t){if(!a){a=!0;try{const e=o(t.position),n=i(t,d);if(!n)throw new Error("Toast creation returned null");s=n,e.appendChild?e.appendChild(n):document.body.appendChild(n);const r=setTimeout(()=>{d(n)},t.duration||3e3);return c.add(r),void function(t){if(l)return;l=!0;const e=setTimeout(()=>{y()},2.5*t);c.add(e)}(t.duration||3e3)}catch(t){}try{const e=function(t){const e=document.createElement("div");return e.style.cssText="\n position: fixed !important;\n top: 20px !important;\n right: 20px !important;\n background: #333 !important;\n color: white !important;\n padding: 12px 20px !important;\n border-radius: 5px !important;\n z-index: 99999 !important;\n max-width: 300px !important;\n font-family: Arial, sans-serif !important;\n cursor: pointer !important;\n ",e.textContent=t.message||"Notification",e.onclick=()=>d(e),e}(t);return s=e,document.body.appendChild(e),void setTimeout(()=>{d(e)},t.duration||3e3)}catch(t){}try{alert(t.message||"Notification"),a=!1}catch(t){a=!1}}}function d(t){try{if(!t)return void m();if(t.style&&!t._isEmergencyToast){t.style.opacity="0",t.style.transform="translateY(-20px)";const e=t._animationDuration||500;setTimeout(()=>{p(t)},e)}else p(t)}catch(t){y()}}function p(t){try{t._cleanupCloseButton&&t._cleanupCloseButton(),n(t),m()}catch(t){y()}}function m(){a=!1,s=null,c.forEach(t=>{try{clearTimeout(t)}catch(t){}}),c.clear(),l=!1}function y(){try{s&&n(s);document.querySelectorAll('[id*="toast"], [id*="emergency"]').forEach(t=>{try{n(t)}catch(t){}}),m()}catch(t){a=!1,s=null}}let f={success:"#28a745",error:"#dc3545",warning:"#ffc107",info:"#17a2b8"},h={success:"Operation completed successfully!",error:"Something went wrong!",warning:"Warning message!",info:"Information message!"};function g(t={}){try{const e=function(t){const e={duration:3e3,position:"bottom-right",type:"info",backgroundColor:void 0,textColor:"white",showCloseButton:!1,animationDuration:"0.5s",animationEasing:"ease",showProgressBar:!1,progressColor:void 0,progressHeight:"4px",progressPosition:"bottom"};let n={...e};t&&"object"==typeof t&&!Array.isArray(t)&&(Object.keys(e).forEach(e=>{t.hasOwnProperty(e)&&(n[e]=t[e])}),void 0!==t.message&&(n.message=t.message));try{!n.backgroundColor&&n.type&&f[n.type]&&(n.backgroundColor=f[n.type]),!n.message&&n.type&&h[n.type]&&(n.message=h[n.type])}catch(t){}n.message&&"string"==typeof n.message||(n.message="Notification");("number"!=typeof n.duration||n.duration<100)&&(n.duration=3e3);return n}(t);u(e)}catch(e){const n="string"==typeof t?.message?t.message.substring(0,200):"Toast notification failed";try{alert(n)}catch(t){}}}function x(t){try{t&&"object"==typeof t&&!Array.isArray(t)&&(f={...f,...t})}catch(t){}}function b(t){try{t&&"object"==typeof t&&!Array.isArray(t)&&(h={...h,...t})}catch(t){}}try{"undefined"!=typeof window&&(window.customizableToast={createToast:g,setDefaultColors:x,setDefaultMessages:b})}catch(t){}t.createToast=g,t.setDefaultColors=x,t.setDefaultMessages=b,Object.defineProperty(t,"__esModule",{value:!0})});
|
|
20
13
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Customizable Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version __VERSION__\r\n * @build Production\r\n * @license Apache-2.0\r\n * @depends None\r\n * @description A lightweight and fully customizable toast notification library\r\n * designed for seamless integration with any JavaScript or framework-based UI.\r\n * Supports flexible positioning, theming, icons, animations, and timing options\r\n * out of the box β with zero dependencies.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * License: Apache-2.0\r\n * Dependencies: None\r\n */\r\n\r\n/**\r\n * Creates a toast notification.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast. Defaults based on type if not provided.\r\n * @param {number} [options.duration=3000] - The duration the toast should be displayed, in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast on the screen.\r\n * @param {string} [options.type='info'] - The type of the toast ('info', 'success', 'error', 'warning').\r\n * @param {string} [options.backgroundColor] - Custom background color for the toast notification.\r\n * @param {string} [options.textColor='white'] - Custom text color for the toast notification.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of the fade-in and fade-out animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for the animations.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @return {void}\r\n */\r\n\r\n/** ########################################### Defaults ############################################ */\r\n\r\nconsole.log(\"Before toast creation\");\r\n\r\nlet defaultColors = {\r\n info: \"blue\",\r\n success: \"green\",\r\n error: \"red\",\r\n warning: \"darkorange\",\r\n};\r\n\r\nlet defaultMessages = {\r\n info: \"This is an info message.\",\r\n success: \"Action completed successfully!\",\r\n error: \"An error occurred!\",\r\n warning: \"This is a warning message!\",\r\n};\r\n\r\n// Flag to manage if a toast is currently being shown\r\nlet isToastShowing = false;\r\n\r\nfunction createToastContainer(position) {\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n setPosition(toastContainer, position);\r\n document.body.appendChild(toastContainer);\r\n }\r\n return toastContainer;\r\n}\r\n\r\nfunction setPosition(container, position) {\r\n if (position.includes(\"bottom\")) {\r\n container.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n container.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n container.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n container.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n container.style.top = \"50%\";\r\n container.style.left = \"50%\";\r\n container.style.transform = \"translate(-50%, -50%)\";\r\n }\r\n}\r\n\r\nfunction createToastElement(\r\n finalMessage,\r\n backgroundColor,\r\n textColor,\r\n animationDuration,\r\n animationEasing,\r\n showCloseButton,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n duration\r\n) {\r\n const toast = document.createElement(\"div\");\r\n toast.textContent = finalMessage;\r\n toast.style.background = backgroundColor;\r\n toast.style.color = textColor;\r\n toast.style.padding = \"10px 20px\";\r\n toast.style.marginTop = \"10px\";\r\n toast.style.borderRadius = \"5px\";\r\n toast.style.boxShadow = \"0 0 10px rgba(0, 0, 0, 0.1)\";\r\n toast.style.opacity = \"0\";\r\n toast.style.transition = `opacity ${animationDuration} ${animationEasing}`;\r\n toast.style.position = \"relative\";\r\n toast.style.overflow = \"hidden\";\r\n\r\n if (showCloseButton) {\r\n addCloseButton(toast, textColor);\r\n }\r\n\r\n if (showProgressBar) {\r\n const progressBar = document.createElement(\"div\");\r\n progressBar.style.position = \"absolute\";\r\n progressBar.style[progressPosition === \"top\" ? \"top\" : \"bottom\"] = \"0\";\r\n progressBar.style.left = \"0\";\r\n progressBar.style.height = progressHeight || \"4px\";\r\n progressBar.style.backgroundColor = progressColor || textColor;\r\n progressBar.style.width = \"100%\";\r\n progressBar.style.transition = `width ${duration}ms linear`;\r\n\r\n // Trigger animation\r\n requestAnimationFrame(() => {\r\n progressBar.style.width = \"0%\";\r\n });\r\n\r\n toast.appendChild(progressBar);\r\n }\r\n\r\n return toast;\r\n}\r\n\r\nfunction addCloseButton(toast, textColor) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.textContent = \"Γ\";\r\n closeButton.style.marginLeft = \"10px\";\r\n closeButton.style.background = \"transparent\";\r\n closeButton.style.border = \"none\";\r\n closeButton.style.color = textColor;\r\n closeButton.style.cursor = \"pointer\";\r\n\r\n closeButton.onclick = () => {\r\n toast.style.opacity = \"0\"; // Start fade out\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n };\r\n\r\n toast.appendChild(closeButton);\r\n}\r\n\r\nfunction showToast({\r\n message,\r\n duration,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n}) {\r\n if (isToastShowing) return;\r\n isToastShowing = true;\r\n\r\n const finalMessage =\r\n message || defaultMessages[type] || \"This is a default message.\";\r\n const toastBackgroundColor = backgroundColor || defaultColors[type] || \"gray\";\r\n const toastTextColor =\r\n textColor || (toastBackgroundColor === \"white\" ? \"black\" : \"white\");\r\n\r\n const toastContainer = createToastContainer(position);\r\n const toast = createToastElement(\r\n finalMessage,\r\n toastBackgroundColor,\r\n toastTextColor,\r\n animationDuration || \"0.5s\",\r\n animationEasing || \"ease\",\r\n showCloseButton,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n duration || 3000\r\n );\r\n\r\n toastContainer.appendChild(toast);\r\n requestAnimationFrame(() => {\r\n toast.style.opacity = \"1\";\r\n });\r\n\r\n setTimeout(() => {\r\n if (toast.parentNode) {\r\n toast.style.opacity = \"0\";\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false;\r\n });\r\n }\r\n }, duration || 3000);\r\n}\r\n\r\n/**\r\n * Create a toast notification with the provided options.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast.\r\n * @param {number} [options.duration=3000] - The duration of the toast in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast.\r\n * @param {string} [options.type='info'] - The type of the toast.\r\n * @param {string} [options.backgroundColor] - The custom background color.\r\n * @param {string} [options.textColor='white'] - The custom text color.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for animations.\r\n * @param {boolean} [options.showProgressBar=false] - Show a visual progress bar.\r\n * @param {string} [options.progressColor] - Color of the progress bar.\r\n * @param {string} [options.progressHeight='4px'] - Height of the progress bar.\r\n * @param {string} [options.progressPosition='bottom'] - 'top' or 'bottom' placement of the progress bar.\r\n * @return {void}\r\n */\r\nfunction createToast(options) {\r\n if (typeof options !== \"object\") {\r\n console.error(\"Options should be an object.\");\r\n return;\r\n }\r\n\r\n const {\r\n message,\r\n duration,\r\n position = \"bottom-right\",\r\n type = \"info\",\r\n backgroundColor,\r\n textColor,\r\n showCloseButton = false,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar = false,\r\n progressColor,\r\n progressHeight = \"4px\",\r\n progressPosition = \"bottom\",\r\n } = options;\r\n\r\n if (duration && typeof duration !== \"number\") {\r\n console.warn(\"Duration should be a number. Falling back to default value.\");\r\n }\r\n\r\n showToast({\r\n message,\r\n duration: duration || 3000,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n });\r\n}\r\n\r\n/**\r\n * Set default colors for toast types.\r\n *\r\n * @param {Object} newColors - New colors to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultColors(newColors) {\r\n // Validate newColors\r\n if (typeof newColors !== \"object\") {\r\n console.error(\"New colors should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultColors, newColors);\r\n}\r\n\r\n/**\r\n * Set default messages for toast types.\r\n *\r\n * @param {Object} newMessages - New messages to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultMessages(newMessages) {\r\n // Validate newMessages\r\n if (typeof newMessages !== \"object\") {\r\n console.error(\"New messages should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultMessages, newMessages);\r\n}\r\n\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n\r\nconsole.log(\"After toast creation\");\r\n"],"names":["defaultColors","info","success","error","warning","defaultMessages","isToastShowing","createToastElement","finalMessage","backgroundColor","textColor","animationDuration","animationEasing","showCloseButton","showProgressBar","progressColor","progressHeight","progressPosition","duration","toast","document","createElement","textContent","style","background","color","padding","marginTop","borderRadius","boxShadow","opacity","transition","position","overflow","closeButton","marginLeft","border","cursor","onclick","addEventListener","remove","appendChild","addCloseButton","progressBar","left","height","width","requestAnimationFrame","showToast","message","type","toastBackgroundColor","toastTextColor","toastContainer","getElementById","id","zIndex","container","includes","bottom","top","right","transform","setPosition","body","createToastContainer","setTimeout","parentNode","options","newColors","Object","assign","newMessages"],"mappings":";;;;;;;;;;;;;;;;;;KAyCA,IAAIA,EAAgB,CAClBC,KAAM,OACNC,QAAS,QACTC,MAAO,MACPC,QAAS,cAGPC,EAAkB,CACpBJ,KAAM,2BACNC,QAAS,iCACTC,MAAO,qBACPC,QAAS,8BAIPE,GAAiB,EAiCrB,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,MAAMC,EAAQC,SAASC,cAAc,OAiBrC,GAhBAF,EAAMG,YAAcd,EACpBW,EAAMI,MAAMC,WAAaf,EACzBU,EAAMI,MAAME,MAAQf,EACpBS,EAAMI,MAAMG,QAAU,YACtBP,EAAMI,MAAMI,UAAY,OACxBR,EAAMI,MAAMK,aAAe,MAC3BT,EAAMI,MAAMM,UAAY,8BACxBV,EAAMI,MAAMO,QAAU,IACtBX,EAAMI,MAAMQ,WAAa,WAAWpB,KAAqBC,IACzDO,EAAMI,MAAMS,SAAW,WACvBb,EAAMI,MAAMU,SAAW,SAEnBpB,GAyBN,SAAwBM,EAAOT,GAC7B,MAAMwB,EAAcd,SAASC,cAAc,UAC3Ca,EAAYZ,YAAc,IAC1BY,EAAYX,MAAMY,WAAa,OAC/BD,EAAYX,MAAMC,WAAa,cAC/BU,EAAYX,MAAMa,OAAS,OAC3BF,EAAYX,MAAME,MAAQf,EAC1BwB,EAAYX,MAAMc,OAAS,UAE3BH,EAAYI,QAAU,KACpBnB,EAAMI,MAAMO,QAAU,IACtBX,EAAMoB,iBAAiB,gBAAiB,KACtCpB,EAAMqB,SACNlC,GAAiB,KAIrBa,EAAMsB,YAAYP,EACpB,CA1CIQ,CAAevB,EAAOT,GAGpBI,EAAiB,CACnB,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AC3BD,EAAUlC,MAAMqC,IAAM,MACtBH,EAAUlC,MAAMqB,KAAO,MACvBa,EAAUlC,MAAMuC,UAAY,wBAEhC,CAtBIC,CAAYV,EAAgBrB,GAC5BZ,SAAS4C,KAAKvB,YAAYY,IAErBA,CACT,CAmHyBY,CAAqBjC,GACtCb,EAAQZ,EACZC,EACA2C,EACAC,EACAzC,GAAqB,OACrBC,GAAmB,OACnBC,EACAC,EACAC,EACAC,EACAC,EACAC,GAAY,KAGdmC,EAAeZ,YAAYtB,GAC3B4B,sBAAsB,KACpB5B,EAAMI,MAAMO,QAAU,MAGxBoC,WAAW,KACL/C,EAAMgD,aACRhD,EAAMI,MAAMO,QAAU,IACtBX,EAAMoB,iBAAiB,gBAAiB,KACtCpB,EAAMqB,SACNlC,GAAiB,MAGpBY,GAAY,IACjB,eAqBA,SAAqBkD,GACnB,GAAuB,iBAAZA,EAET,OAGF,MAAMnB,QACJA,EAAO/B,SACPA,EAAQc,SACRA,EAAW,eAAckB,KACzBA,EAAO,OAAMzC,gBACbA,EAAeC,UACfA,EAASG,gBACTA,GAAkB,EAAKF,kBACvBA,EAAiBC,gBACjBA,EAAeE,gBACfA,GAAkB,EAAKC,cACvBA,EAAaC,eACbA,EAAiB,MAAKC,iBACtBA,EAAmB,UACjBmD,EAMJpB,EAAU,CACRC,UACA/B,SAAUA,GAAY,IACtBc,WACAkB,OACAzC,kBACAC,YACAG,kBACAF,oBACAC,kBACAE,kBACAC,gBACAC,iBACAC,oBAEJ,qBAQA,SAA0BoD,GAEC,iBAAdA,GAKXC,OAAOC,OAAOvE,EAAeqE,EAC/B,uBAQA,SAA4BG,GAEC,iBAAhBA,GAKXF,OAAOC,OAAOlE,EAAiBmE,EACjC"}
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/utils/id.js","../src/utils/dom.js","../src/components/ToastContainer.js","../src/utils/position.js","../src/components/toast-utils.js","../src/components/Toast.js","../src/components/ToastManager.js","../src/index.js"],"sourcesContent":["// src/utils/id.js\r\n\"use strict\";\r\n\r\n/**\r\n * Generate unique ID for DOM elements to avoid conflicts\r\n * @param {string} prefix - Optional prefix for ID\r\n * @returns {string} Unique ID\r\n */\r\nexport function generateUniqueId(prefix = \"toast\") {\r\n return `${prefix}-${Date.now()}-${Math.floor(Math.random() * 100000)}`;\r\n}\r\n","// src/utils/dom.js\r\n\"use strict\";\r\n\r\nimport { generateUniqueId } from \"./id.js\";\r\n\r\n/**\r\n * Multi-layer fallback DOM element creation\r\n */\r\nexport function createElementWithId(tagName, prefix) {\r\n // PRIMARY: Standard createElement\r\n try {\r\n const el = document.createElement(tagName);\r\n el.id = generateUniqueId(prefix);\r\n return el;\r\n } catch (error) {\r\n console.warn(`Primary createElement failed for ${tagName}:`, error);\r\n\r\n // FALLBACK-A: Try div as alternative\r\n try {\r\n const fallbackEl = document.createElement(\"div\");\r\n fallbackEl.id = generateUniqueId(prefix || \"fallback\");\r\n fallbackEl.setAttribute(\"data-original-tag\", tagName);\r\n return fallbackEl;\r\n } catch (fallbackError) {\r\n console.error(\"All DOM creation methods failed:\", fallbackError);\r\n\r\n // FALLBACK-B: Return minimal object that won't crash\r\n return {\r\n id: generateUniqueId(prefix || \"emergency\"),\r\n style: {},\r\n appendChild: () => {},\r\n setAttribute: () => {},\r\n innerHTML: \"\",\r\n textContent: \"\",\r\n onclick: null,\r\n _isEmergencyElement: true,\r\n };\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Multi-strategy appendChild with graceful degradation\r\n */\r\nexport function appendChild(parent, child) {\r\n if (!parent || !child) return false;\r\n\r\n // PRIMARY: Standard appendChild\r\n try {\r\n if (!parent.contains(child)) {\r\n parent.appendChild(child);\r\n return true;\r\n }\r\n return true;\r\n } catch (error) {\r\n console.warn(\"Primary appendChild failed:\", error);\r\n\r\n // FALLBACK-A: insertAdjacentElement\r\n try {\r\n parent.insertAdjacentElement(\"beforeend\", child);\r\n return true;\r\n } catch (fallbackError) {\r\n console.warn(\"Fallback appendChild failed:\", fallbackError);\r\n\r\n // FALLBACK-B: Manual positioning\r\n try {\r\n if (parent === document.body) {\r\n child.style.position = \"fixed\";\r\n child.style.top = \"10px\";\r\n child.style.right = \"10px\";\r\n child.style.zIndex = \"99999\";\r\n document.body.insertAdjacentHTML(\"beforeend\", child.outerHTML || \"\");\r\n return true;\r\n }\r\n } catch (emergencyError) {\r\n console.error(\"All append strategies failed:\", emergencyError);\r\n return false;\r\n }\r\n }\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Safe element removal with multiple strategies\r\n */\r\nexport function removeElement(el) {\r\n if (!el) return true;\r\n\r\n // PRIMARY: parentNode.removeChild\r\n try {\r\n if (el.parentNode) {\r\n el.parentNode.removeChild(el);\r\n return true;\r\n }\r\n } catch (error) {\r\n console.warn(\"Primary removal failed:\", error);\r\n\r\n // FALLBACK-A: element.remove()\r\n try {\r\n if (el.remove) {\r\n el.remove();\r\n return true;\r\n }\r\n } catch (fallbackError) {\r\n console.warn(\"Fallback removal failed:\", fallbackError);\r\n\r\n // FALLBACK-B: Hide instead of remove\r\n try {\r\n el.style.display = \"none\";\r\n el.style.opacity = \"0\";\r\n el.style.pointerEvents = \"none\";\r\n el.style.position = \"absolute\";\r\n el.style.left = \"-9999px\";\r\n return true;\r\n } catch (hideError) {\r\n console.error(\"All removal strategies failed:\", hideError);\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n}\r\n\r\n/**\r\n * Animation duration parser with fallbacks\r\n */\r\nexport function parseAnimationDuration(duration) {\r\n // PRIMARY: Parse provided duration\r\n try {\r\n if (typeof duration === \"number\" && duration > 0) return duration;\r\n if (typeof duration === \"string\") {\r\n if (duration.endsWith(\"s\") && !duration.endsWith(\"ms\")) {\r\n const parsed = parseFloat(duration) * 1000;\r\n return parsed > 0 ? parsed : 500;\r\n }\r\n const parsed = parseFloat(duration);\r\n return parsed > 0 ? parsed : 500;\r\n }\r\n } catch (error) {\r\n console.warn(\"Duration parsing failed:\", error);\r\n }\r\n\r\n // FALLBACK: Safe default\r\n return 500;\r\n}\r\n\r\n/**\r\n * Force reflow with error protection\r\n */\r\nexport function forceReflow(el) {\r\n try {\r\n return el?.offsetWidth || 0;\r\n } catch (error) {\r\n console.warn(\"Force reflow failed:\", error);\r\n return 0;\r\n }\r\n}\r\n\r\n/**\r\n * Query selector shortcut with optional root.\r\n * @param {string} selector\r\n * @param {Document|HTMLElement} [root=document]\r\n * @returns {Element|null}\r\n */\r\nexport function query(selector, root = document) {\r\n return root.querySelector(selector);\r\n}\r\n","// src/components/ToastContainer.js //# Container logic\r\n\"use strict\";\r\n\r\nimport { setPosition } from \"../utils/position.js\";\r\nimport { appendChild } from \"../utils/dom.js\";\r\n\r\n/**\r\n * Create toast container with error handling\r\n * @param {string} position - Toast position\r\n * @returns {HTMLElement} Toast container element\r\n */\r\nexport function createToastContainer(position) {\r\n try {\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n setPosition(toastContainer, position);\r\n appendChild(document.body, toastContainer);\r\n }\r\n\r\n return toastContainer;\r\n } catch (error) {\r\n console.error(\"Failed to create toast container:\", error);\r\n // Fallback: return body element\r\n return document.body;\r\n }\r\n}\r\n","// src/utils/position.js\r\n\"use strict\";\r\n\r\n/**\r\n * Set position for toast container (EXACT same logic as original)\r\n * @param {HTMLElement} container - Toast container element\r\n * @param {string} position - Position string\r\n */\r\nexport function setPosition(container, position) {\r\n // Reset all position properties first\r\n container.style.top = \"auto\";\r\n container.style.bottom = \"auto\";\r\n container.style.left = \"auto\";\r\n container.style.right = \"auto\";\r\n container.style.transform = \"none\";\r\n\r\n if (position.includes(\"bottom\")) {\r\n container.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n container.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n container.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n container.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n container.style.top = \"50%\";\r\n container.style.left = \"50%\";\r\n container.style.transform = \"translate(-50%, -50%)\";\r\n }\r\n}\r\n","\"use strict\";\r\n\r\nimport { forceReflow, parseAnimationDuration } from \"../utils/dom.js\";\r\n\r\n/**\r\n * Create close button for toast\r\n * @param {HTMLElement} toast - Toast element\r\n * @param {Object} options - Toast options\r\n * @param {Function} onClose - Close callback\r\n */\r\nexport function createCloseButton(toast, options, onClose) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.innerHTML = \"×\";\r\n Object.assign(closeButton.style, {\r\n background: \"none\",\r\n border: \"none\",\r\n color: options.textColor || \"white\",\r\n fontSize: \"18px\",\r\n marginLeft: \"10px\",\r\n cursor: \"pointer\",\r\n });\r\n\r\n closeButton.onclick = () => onClose(toast);\r\n toast.appendChild(closeButton);\r\n\r\n toast._cleanupCloseButton = () => {\r\n closeButton.onclick = null;\r\n };\r\n}\r\n\r\n/**\r\n * Create progress bar for toast\r\n * @param {HTMLElement} toast - Toast element\r\n * @param {Object} options - Toast options\r\n */\r\nexport function createProgressBar(toast, options) {\r\n const progressBar = document.createElement(\"div\");\r\n Object.assign(progressBar.style, {\r\n position: \"absolute\",\r\n left: \"0\",\r\n height: options.progressHeight || \"4px\",\r\n background: options.progressColor || \"rgba(255, 255, 255, 0.3)\",\r\n width: \"100%\",\r\n transition: `width ${options.duration || 3000}ms linear`,\r\n [options.progressPosition === \"top\" ? \"top\" : \"bottom\"]: \"0\",\r\n });\r\n\r\n toast.appendChild(progressBar);\r\n\r\n setTimeout(() => {\r\n forceReflow(progressBar);\r\n progressBar.style.width = \"0%\";\r\n }, 100);\r\n}\r\n\r\n/**\r\n * Run toast fade-in animation\r\n * @param {HTMLElement} toast - Toast element\r\n */\r\nexport function runToastAnimation(toast) {\r\n setTimeout(() => {\r\n toast.style.opacity = \"1\";\r\n toast.style.transform = \"translateY(0)\";\r\n }, 50);\r\n}\r\n\r\n/**\r\n * Apply rich styling to toast element\r\n * @param {HTMLElement} toast - Toast element\r\n * @param {Object} options - Toast options\r\n * @param {Function} onClose - Close callback\r\n */\r\nexport function applyRichStyling(toast, options, onClose) {\r\n const animDurationMs = parseAnimationDuration(\r\n options.animationDuration || \"0.5s\"\r\n );\r\n\r\n // Apply full styling\r\n Object.assign(toast.style, {\r\n background: options.backgroundColor || options.color || \"#333\",\r\n color: options.textColor || \"white\",\r\n padding: \"12px 20px\",\r\n marginBottom: \"10px\",\r\n borderRadius: \"5px\",\r\n display: \"flex\",\r\n alignItems: \"center\",\r\n justifyContent: \"space-between\",\r\n boxShadow: \"0 4px 6px rgba(0, 0, 0, 0.1)\",\r\n minWidth: \"250px\",\r\n maxWidth: \"400px\",\r\n opacity: \"0\",\r\n position: \"relative\",\r\n transition: `opacity ${options.animationDuration || \"0.5s\"} ${\r\n options.animationEasing || \"ease\"\r\n }, transform ${options.animationDuration || \"0.5s\"} ${\r\n options.animationEasing || \"ease\"\r\n }`,\r\n transform: \"translateY(20px)\",\r\n zIndex: \"9999\",\r\n });\r\n\r\n toast._animationDuration = animDurationMs;\r\n\r\n // Message span\r\n const messageSpan = document.createElement(\"span\");\r\n messageSpan.textContent = options.message || \"Notification\";\r\n messageSpan.style.flex = \"1\";\r\n toast.appendChild(messageSpan);\r\n\r\n // Close button\r\n if (options.showCloseButton) {\r\n createCloseButton(toast, options, onClose);\r\n }\r\n\r\n // Progress bar\r\n if (options.showProgressBar) {\r\n createProgressBar(toast, options);\r\n }\r\n\r\n // Animation\r\n runToastAnimation(toast);\r\n}\r\n\r\n/**\r\n * Create basic fallback toast\r\n * @param {HTMLElement} toast - Toast element\r\n * @param {Object} options - Toast options\r\n * @param {Function} onClose - Close callback\r\n */\r\nexport function createBasicToast(toast, options, onClose) {\r\n // Basic styling only\r\n Object.assign(toast.style, {\r\n background: \"#333\",\r\n color: \"white\",\r\n padding: \"10px 15px\",\r\n margin: \"10px\",\r\n borderRadius: \"3px\",\r\n position: \"fixed\",\r\n top: \"20px\",\r\n right: \"20px\",\r\n zIndex: \"99999\",\r\n maxWidth: \"300px\",\r\n wordWrap: \"break-word\",\r\n });\r\n\r\n toast.textContent = options.message || \"Notification\";\r\n\r\n if (options.showCloseButton) {\r\n toast.style.cursor = \"pointer\";\r\n toast.onclick = () => onClose(toast);\r\n }\r\n\r\n toast._animationDuration = 500;\r\n}\r\n\r\n/**\r\n * Emergency toast as last resort\r\n * @param {Object} options - Toast options\r\n * @param {Function} onClose - Close callback\r\n */\r\nexport function createEmergencyToast(options, onClose) {\r\n try {\r\n // Create emergency div\r\n const emergency = document.createElement(\"div\");\r\n emergency.id = `emergency-${Date.now()}`;\r\n emergency.innerHTML = `\r\n <div style=\"\r\n background: #333 !important;\r\n color: white !important;\r\n padding: 10px 15px !important;\r\n position: fixed !important;\r\n top: 20px !important;\r\n right: 20px !important;\r\n z-index: 99999 !important;\r\n border-radius: 3px !important;\r\n max-width: 250px !important;\r\n word-wrap: break-word !important;\r\n font-family: Arial, sans-serif !important;\r\n font-size: 14px !important;\r\n box-shadow: 0 2px 10px rgba(0,0,0,0.3) !important;\r\n cursor: pointer !important;\r\n \" onclick=\"this.parentNode.removeChild(this)\">\r\n ${options.message || \"Notification\"}\r\n <span style=\"float: right; margin-left: 10px; font-weight: bold;\">×</span>\r\n </div>\r\n `;\r\n\r\n emergency._animationDuration = 500;\r\n emergency._isEmergencyToast = true;\r\n\r\n // Auto remove\r\n setTimeout(() => {\r\n try {\r\n if (emergency.parentNode) {\r\n emergency.parentNode.removeChild(emergency);\r\n }\r\n onClose(emergency);\r\n } catch (error) {\r\n console.warn(\"Emergency cleanup failed:\", error);\r\n }\r\n }, options.duration || 3000);\r\n\r\n return emergency;\r\n } catch (emergencyError) {\r\n console.error(\"Emergency toast creation failed:\", emergencyError);\r\n\r\n // ULTIMATE FALLBACK: Alert\r\n setTimeout(() => {\r\n try {\r\n alert(options.message || \"Toast Notification\");\r\n onClose(null);\r\n } catch (alertError) {\r\n console.error(\"Ultimate fallback failed:\", alertError);\r\n onClose(null);\r\n }\r\n }, 100);\r\n\r\n return null;\r\n }\r\n}\r\n","// src/components/Toast.js //# Single responsibility\r\n\"use strict\";\r\n\r\nimport { createElementWithId } from \"../utils/dom.js\";\r\nimport {\r\n applyRichStyling,\r\n createBasicToast,\r\n createEmergencyToast,\r\n} from \"./toast-utils.js\";\r\n\r\n/**\r\n * Multi-layer toast creation with satellite-grade fallbacks\r\n * @param {Object} options - Toast configuration options\r\n * @param {Function} onClose - Callback when toast closes\r\n * @returns {HTMLElement} Toast element\r\n */\r\nexport function createToastElement(options, onClose) {\r\n let toast;\r\n let isEmergencyMode = false;\r\n\r\n // PRIMARY: Full-featured toast\r\n try {\r\n toast = createElementWithId(\"div\", \"toast\");\r\n\r\n if (toast._isEmergencyElement) {\r\n isEmergencyMode = true;\r\n console.warn(\"Toast created in emergency mode\");\r\n }\r\n } catch (error) {\r\n console.error(\"Toast creation failed:\", error);\r\n isEmergencyMode = true;\r\n // FALLBACK: Basic object structure\r\n toast = {\r\n id: `emergency-toast-${Date.now()}`,\r\n style: {},\r\n appendChild: () => {},\r\n innerHTML: \"\",\r\n textContent: \"\",\r\n _isEmergencyElement: true,\r\n };\r\n }\r\n\r\n // PRIMARY: Rich styling and features\r\n if (!isEmergencyMode) {\r\n try {\r\n applyRichStyling(toast, options, onClose);\r\n return toast;\r\n } catch (stylingError) {\r\n console.warn(\r\n \"Rich toast styling failed, switching to basic mode:\",\r\n stylingError\r\n );\r\n isEmergencyMode = true;\r\n }\r\n }\r\n\r\n // FALLBACK-A: Basic functional toast\r\n if (isEmergencyMode && !toast._isEmergencyElement) {\r\n try {\r\n createBasicToast(toast, options, onClose);\r\n return toast;\r\n } catch (basicError) {\r\n console.error(\"Basic toast creation failed:\", basicError);\r\n }\r\n }\r\n\r\n // FALLBACK-B: Emergency notification system\r\n return createEmergencyToast(options, onClose);\r\n}\r\n","// src/components/ToastManager.js //# State management\r\n\"use strict\";\r\n\r\nimport { createToastContainer } from \"./ToastContainer.js\";\r\nimport { createToastElement } from \"./Toast.js\";\r\nimport { removeElement } from \"../utils/dom.js\";\r\n\r\n// State management with fallback tracking\r\nlet isToastShowing = false;\r\nlet currentToast = null;\r\nlet emergencyTimeouts = new Set();\r\nlet emergencyCleanupScheduled = false;\r\n\r\n/**\r\n * Show toast with comprehensive fallback system\r\n */\r\nexport function showToast(options) {\r\n // Prevent multiple toasts (original behavior)\r\n if (isToastShowing) {\r\n console.warn(\"Toast already showing, ignoring request\");\r\n return;\r\n }\r\n\r\n isToastShowing = true;\r\n\r\n // PRIMARY: Full toast system\r\n try {\r\n const container = createToastContainer(options.position);\r\n const toast = createToastElement(options, closeToast);\r\n\r\n if (!toast) {\r\n throw new Error(\"Toast creation returned null\");\r\n }\r\n\r\n currentToast = toast;\r\n\r\n // Append to container\r\n if (container.appendChild) {\r\n container.appendChild(toast);\r\n } else {\r\n // Container is emergency fallback\r\n document.body.appendChild(toast);\r\n }\r\n\r\n // Schedule auto-dismiss\r\n const dismissTimeout = setTimeout(() => {\r\n closeToast(toast);\r\n }, options.duration || 3000);\r\n\r\n emergencyTimeouts.add(dismissTimeout);\r\n\r\n // Emergency cleanup backup\r\n scheduleEmergencyCleanup(options.duration || 3000);\r\n\r\n return;\r\n } catch (primaryError) {\r\n console.warn(\"Primary toast system failed:\", primaryError);\r\n }\r\n\r\n // FALLBACK-A: Direct body placement\r\n try {\r\n const simpleToast = createSimpleToast(options);\r\n currentToast = simpleToast;\r\n document.body.appendChild(simpleToast);\r\n\r\n setTimeout(() => {\r\n closeToast(simpleToast);\r\n }, options.duration || 3000);\r\n\r\n return;\r\n } catch (fallbackError) {\r\n console.warn(\"Fallback toast failed:\", fallbackError);\r\n }\r\n\r\n // FALLBACK-B: Browser alert\r\n try {\r\n alert(options.message || \"Notification\");\r\n isToastShowing = false;\r\n } catch (alertError) {\r\n console.error(\"All toast systems failed:\", alertError);\r\n isToastShowing = false;\r\n }\r\n}\r\n\r\n/**\r\n * Create simple toast for fallback\r\n */\r\nfunction createSimpleToast(options) {\r\n const simple = document.createElement(\"div\");\r\n simple.style.cssText = `\r\n position: fixed !important;\r\n top: 20px !important;\r\n right: 20px !important;\r\n background: #333 !important;\r\n color: white !important;\r\n padding: 12px 20px !important;\r\n border-radius: 5px !important;\r\n z-index: 99999 !important;\r\n max-width: 300px !important;\r\n font-family: Arial, sans-serif !important;\r\n cursor: pointer !important;\r\n `;\r\n simple.textContent = options.message || \"Notification\";\r\n simple.onclick = () => closeToast(simple);\r\n return simple;\r\n}\r\n\r\n/**\r\n * Close toast with multi-strategy cleanup\r\n */\r\nfunction closeToast(toast) {\r\n try {\r\n if (!toast) {\r\n resetToastState();\r\n return;\r\n }\r\n\r\n // Animation if supported\r\n if (toast.style && !toast._isEmergencyToast) {\r\n toast.style.opacity = \"0\";\r\n toast.style.transform = \"translateY(-20px)\";\r\n\r\n const animDuration = toast._animationDuration || 500;\r\n setTimeout(() => {\r\n performCleanup(toast);\r\n }, animDuration);\r\n } else {\r\n // Immediate cleanup for emergency toasts\r\n performCleanup(toast);\r\n }\r\n } catch (error) {\r\n console.error(\"Close toast failed:\", error);\r\n forceEmergencyCleanup();\r\n }\r\n}\r\n\r\n/**\r\n * Perform comprehensive cleanup\r\n */\r\nfunction performCleanup(toast) {\r\n try {\r\n // Cleanup event listeners\r\n if (toast._cleanupCloseButton) {\r\n toast._cleanupCloseButton();\r\n }\r\n\r\n // Remove from DOM\r\n removeElement(toast);\r\n\r\n // Reset state\r\n resetToastState();\r\n } catch (error) {\r\n console.error(\"Cleanup failed:\", error);\r\n forceEmergencyCleanup();\r\n }\r\n}\r\n\r\n/**\r\n * Reset all toast state\r\n */\r\nfunction resetToastState() {\r\n isToastShowing = false;\r\n currentToast = null;\r\n\r\n // Clear all timeouts\r\n emergencyTimeouts.forEach((id) => {\r\n try {\r\n clearTimeout(id);\r\n } catch (error) {\r\n console.warn(\"Timeout clear failed:\", error);\r\n }\r\n });\r\n emergencyTimeouts.clear();\r\n emergencyCleanupScheduled = false;\r\n}\r\n\r\n/**\r\n * Schedule emergency cleanup\r\n */\r\nfunction scheduleEmergencyCleanup(duration) {\r\n if (emergencyCleanupScheduled) return;\r\n\r\n emergencyCleanupScheduled = true;\r\n const emergencyTimeout = setTimeout(() => {\r\n console.warn(\"Emergency cleanup triggered\");\r\n forceEmergencyCleanup();\r\n }, duration * 2.5); // 2.5x safety margin\r\n\r\n emergencyTimeouts.add(emergencyTimeout);\r\n}\r\n\r\n/**\r\n * Force emergency cleanup of everything\r\n */\r\nfunction forceEmergencyCleanup() {\r\n try {\r\n // Remove current toast\r\n if (currentToast) {\r\n removeElement(currentToast);\r\n }\r\n\r\n // Clean up any orphaned toast elements\r\n const orphanedToasts = document.querySelectorAll(\r\n '[id*=\"toast\"], [id*=\"emergency\"]'\r\n );\r\n orphanedToasts.forEach((element) => {\r\n try {\r\n removeElement(element);\r\n } catch (error) {\r\n console.warn(\"Orphaned element cleanup failed:\", error);\r\n }\r\n });\r\n\r\n // Reset all state\r\n resetToastState();\r\n } catch (error) {\r\n console.error(\"Force cleanup failed:\", error);\r\n // Final state reset\r\n isToastShowing = false;\r\n currentToast = null;\r\n }\r\n}\r\n","// src/index.js\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Customizable Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version __VERSION__\r\n * @build Production\r\n * @license Apache-2.0\r\n * @depends None\r\n * @description A lightweight and fully customizable toast notification library\r\n * designed for seamless integration with any JavaScript or framework-based UI.\r\n * Supports flexible positioning, theming, icons, animations, and timing options\r\n * out of the box β with zero dependencies.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * License: Apache-2.0\r\n * Dependencies: None\r\n */\r\n\r\n\"use strict\";\r\n\r\nimport { showToast } from \"./components/ToastManager.js\";\r\n\r\n// Protected state with fallbacks\r\nlet defaultColors = {\r\n success: \"#28a745\",\r\n error: \"#dc3545\",\r\n warning: \"#ffc107\",\r\n info: \"#17a2b8\",\r\n};\r\n\r\nlet defaultMessages = {\r\n success: \"Operation completed successfully!\",\r\n error: \"Something went wrong!\",\r\n warning: \"Warning message!\",\r\n info: \"Information message!\",\r\n};\r\n\r\n/**\r\n * Create toast with satellite-grade reliability\r\n */\r\nfunction createToast(options = {}) {\r\n try {\r\n // Input sanitization and validation\r\n const sanitizedOptions = sanitizeToastOptions(options);\r\n\r\n // Call main toast system\r\n showToast(sanitizedOptions);\r\n } catch (error) {\r\n console.error(\"CreateToast failed:\", error);\r\n\r\n // ULTIMATE FALLBACK: Browser alert with sanitized message\r\n const safeMessage =\r\n typeof options?.message === \"string\"\r\n ? options.message.substring(0, 200)\r\n : \"Toast notification failed\";\r\n\r\n try {\r\n alert(safeMessage);\r\n } catch (alertError) {\r\n console.error(\"Ultimate fallback failed:\", alertError);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Sanitize and normalize toast options\r\n */\r\nfunction sanitizeToastOptions(options) {\r\n const defaults = {\r\n duration: 3000,\r\n position: \"bottom-right\",\r\n type: \"info\",\r\n backgroundColor: undefined,\r\n textColor: \"white\",\r\n showCloseButton: false,\r\n animationDuration: \"0.5s\",\r\n animationEasing: \"ease\",\r\n showProgressBar: false,\r\n progressColor: undefined,\r\n progressHeight: \"4px\",\r\n progressPosition: \"bottom\",\r\n };\r\n\r\n // Start with safe defaults\r\n let final = { ...defaults };\r\n\r\n // Merge user options safely\r\n if (options && typeof options === \"object\" && !Array.isArray(options)) {\r\n Object.keys(defaults).forEach((key) => {\r\n if (options.hasOwnProperty(key)) {\r\n final[key] = options[key];\r\n }\r\n });\r\n\r\n // Handle message separately\r\n if (options.message !== undefined) {\r\n final.message = options.message;\r\n }\r\n }\r\n\r\n // Validate and apply defaults\r\n try {\r\n if (!final.backgroundColor && final.type && defaultColors[final.type]) {\r\n final.backgroundColor = defaultColors[final.type];\r\n }\r\n\r\n if (!final.message && final.type && defaultMessages[final.type]) {\r\n final.message = defaultMessages[final.type];\r\n }\r\n } catch (error) {\r\n console.warn(\"Option processing failed:\", error);\r\n }\r\n\r\n // Final safety checks\r\n if (!final.message || typeof final.message !== \"string\") {\r\n final.message = \"Notification\";\r\n }\r\n\r\n if (typeof final.duration !== \"number\" || final.duration < 100) {\r\n final.duration = 3000;\r\n }\r\n\r\n return final;\r\n}\r\n\r\n/**\r\n * Set default colors with validation\r\n */\r\nfunction setDefaultColors(colors) {\r\n try {\r\n if (colors && typeof colors === \"object\" && !Array.isArray(colors)) {\r\n defaultColors = { ...defaultColors, ...colors };\r\n }\r\n } catch (error) {\r\n console.error(\"setDefaultColors failed:\", error);\r\n }\r\n}\r\n\r\n/**\r\n * Set default messages with validation\r\n */\r\nfunction setDefaultMessages(messages) {\r\n try {\r\n if (messages && typeof messages === \"object\" && !Array.isArray(messages)) {\r\n defaultMessages = { ...defaultMessages, ...messages };\r\n }\r\n } catch (error) {\r\n console.error(\"setDefaultMessages failed:\", error);\r\n }\r\n}\r\n\r\n// Module exports\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n\r\n// Global assignment with protection\r\ntry {\r\n // UMD/Global support\r\n if (typeof window !== \"undefined\") {\r\n window.customizableToast = {\r\n createToast,\r\n setDefaultColors,\r\n setDefaultMessages,\r\n };\r\n }\r\n} catch (error) {\r\n console.error(\"Global assignment failed:\", error);\r\n}\r\n"],"names":["generateUniqueId","prefix","Date","now","Math","floor","random","removeElement","el","parentNode","removeChild","error","remove","fallbackError","style","display","opacity","pointerEvents","position","left","hideError","createToastContainer","toastContainer","document","getElementById","createElement","id","zIndex","container","top","bottom","right","transform","includes","setPosition","parent","child","contains","appendChild","insertAdjacentElement","body","insertAdjacentHTML","outerHTML","emergencyError","applyRichStyling","toast","options","onClose","animDurationMs","duration","endsWith","parsed","parseFloat","parseAnimationDuration","animationDuration","Object","assign","background","backgroundColor","color","textColor","padding","marginBottom","borderRadius","alignItems","justifyContent","boxShadow","minWidth","maxWidth","transition","animationEasing","_animationDuration","messageSpan","textContent","message","flex","showCloseButton","closeButton","innerHTML","border","fontSize","marginLeft","cursor","onclick","_cleanupCloseButton","createCloseButton","showProgressBar","progressBar","height","progressHeight","progressColor","width","progressPosition","setTimeout","offsetWidth","forceReflow","createProgressBar","runToastAnimation","createToastElement","isEmergencyMode","tagName","fallbackEl","setAttribute","_isEmergencyElement","createElementWithId","stylingError","margin","wordWrap","createBasicToast","basicError","emergency","_isEmergencyToast","alert","alertError","createEmergencyToast","isToastShowing","currentToast","emergencyTimeouts","Set","emergencyCleanupScheduled","showToast","closeToast","Error","dismissTimeout","add","emergencyTimeout","forceEmergencyCleanup","scheduleEmergencyCleanup","primaryError","simpleToast","simple","cssText","createSimpleToast","resetToastState","animDuration","performCleanup","forEach","clearTimeout","clear","querySelectorAll","element","defaultColors","success","warning","info","defaultMessages","createToast","sanitizedOptions","defaults","type","undefined","final","Array","isArray","keys","key","hasOwnProperty","sanitizeToastOptions","safeMessage","substring","setDefaultColors","colors","setDefaultMessages","messages","window","customizableToast"],"mappings":";;;;;;;;;;;wPAQO,SAASA,EAAiBC,EAAS,SACxC,MAAO,GAAGA,KAAUC,KAAKC,SAASC,KAAKC,MAAsB,IAAhBD,KAAKE,WACpD,CC4EO,SAASC,EAAcC,GAC5B,IAAKA,EAAI,OAAO,EAGhB,IACE,GAAIA,EAAGC,WAEL,OADAD,EAAGC,WAAWC,YAAYF,IACnB,CAEV,CAAC,MAAOG,GAIP,IACE,GAAIH,EAAGI,OAEL,OADAJ,EAAGI,UACI,CAEV,CAAC,MAAOC,GAIP,IAME,OALAL,EAAGM,MAAMC,QAAU,OACnBP,EAAGM,MAAME,QAAU,IACnBR,EAAGM,MAAMG,cAAgB,OACzBT,EAAGM,MAAMI,SAAW,WACpBV,EAAGM,MAAMK,KAAO,WACT,CACR,CAAC,MAAOC,GAEP,OAAO,CACR,CACF,CACF,CACD,OAAO,CACT,CC/GO,SAASC,EAAqBH,GACnC,IACE,IAAII,EAAi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able-toast-notification",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "A lightweight
|
|
3
|
+
"version": "3.4.0",
|
|
4
|
+
"description": "A lightweight, zero-dependency toast notification library for modern JavaScript applications with production-grade reliability and comprehensive system mechanisms",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.esm.mjs",
|
|
@@ -18,46 +18,48 @@
|
|
|
18
18
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
|
-
"toast",
|
|
22
|
-
"toast library",
|
|
23
|
-
"toast notification",
|
|
24
|
-
"toast ui",
|
|
25
|
-
"toast alert",
|
|
26
|
-
"toast message",
|
|
27
|
-
"notification",
|
|
28
|
-
"ui notification",
|
|
29
|
-
"custom notification",
|
|
30
21
|
"javascript",
|
|
31
|
-
"javascript
|
|
32
|
-
"
|
|
33
|
-
"
|
|
22
|
+
"javascript-library",
|
|
23
|
+
"vanilla-js",
|
|
24
|
+
"notification",
|
|
25
|
+
"toast-notification",
|
|
26
|
+
"ui-component",
|
|
27
|
+
"zero-dependency",
|
|
28
|
+
"customizable",
|
|
29
|
+
"lightweight",
|
|
30
|
+
"production-ready",
|
|
31
|
+
"framework-agnostic",
|
|
32
|
+
"fallback-system",
|
|
34
33
|
"alert",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
34
|
+
"popup",
|
|
35
|
+
"message",
|
|
37
36
|
"library",
|
|
38
|
-
"message popup",
|
|
39
|
-
"npm library",
|
|
40
37
|
"npm",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
38
|
+
"umd",
|
|
39
|
+
"esm",
|
|
40
|
+
"cjs",
|
|
41
|
+
"cdn",
|
|
42
|
+
"toast",
|
|
43
|
+
"toast-library",
|
|
44
|
+
"toast-alert",
|
|
45
|
+
"toast-message",
|
|
46
|
+
"custom-notification",
|
|
47
|
+
"popup-notification",
|
|
48
|
+
"frontend",
|
|
49
|
+
"message-popup",
|
|
50
|
+
"npm-library",
|
|
51
|
+
"npm-toast-package",
|
|
52
|
+
"customizable-toast-notification",
|
|
44
53
|
"component",
|
|
45
|
-
"toast
|
|
46
|
-
"notification
|
|
54
|
+
"toast-component",
|
|
55
|
+
"notification-component",
|
|
47
56
|
"customisable",
|
|
48
|
-
"customisable
|
|
49
|
-
"react
|
|
50
|
-
"react
|
|
57
|
+
"customisable-toast-notification",
|
|
58
|
+
"react-component",
|
|
59
|
+
"react-toast",
|
|
51
60
|
"frontend",
|
|
52
|
-
"frontend
|
|
53
|
-
"
|
|
54
|
-
"CJS",
|
|
55
|
-
"cdn",
|
|
56
|
-
"umd",
|
|
57
|
-
"notification",
|
|
58
|
-
"custom-toast",
|
|
59
|
-
"vanilla-js",
|
|
60
|
-
"lightweight"
|
|
61
|
+
"frontend-library",
|
|
62
|
+
"custom-toast"
|
|
61
63
|
],
|
|
62
64
|
"author": {
|
|
63
65
|
"name": "Priyanshu Patel",
|
|
@@ -69,7 +71,8 @@
|
|
|
69
71
|
"postinstall.js",
|
|
70
72
|
"dist",
|
|
71
73
|
"README.md",
|
|
72
|
-
"LICENSE"
|
|
74
|
+
"LICENSE",
|
|
75
|
+
"CHANGELOG.md"
|
|
73
76
|
],
|
|
74
77
|
"devDependencies": {
|
|
75
78
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
@@ -80,8 +83,8 @@
|
|
|
80
83
|
"postcss": "^8.5.6",
|
|
81
84
|
"postcss-import": "^16.1.1",
|
|
82
85
|
"rollup": "^2.78.0",
|
|
86
|
+
"rollup-plugin-bundle-size": "^1.0.3",
|
|
83
87
|
"rollup-plugin-postcss": "^4.0.2",
|
|
84
|
-
"rollup-plugin-size-snapshot": "^0.12.0",
|
|
85
88
|
"rollup-plugin-visualizer": "^5.12.0"
|
|
86
89
|
},
|
|
87
90
|
"repository": {
|
package/postinstall.js
CHANGED
|
@@ -28,8 +28,9 @@ try {
|
|
|
28
28
|
count === 5
|
|
29
29
|
? "π―Thanks for sticking with it!\nThis is the final message. π"
|
|
30
30
|
: `π¦Thanks for using this package!`,
|
|
31
|
-
"π
|
|
32
|
-
"
|
|
31
|
+
"π In README.md - More professional",
|
|
32
|
+
"π¨βπ» Author **Priyanshu Patel** -",
|
|
33
|
+
"π€ Open to collaboration & teamwork",
|
|
33
34
|
"πΌ Looking for exciting dev opportunities.",
|
|
34
35
|
"π Contact: priyanshu.alt191@gmail.com",
|
|
35
36
|
"π Built different. Stay creative.",
|
|
@@ -58,7 +59,7 @@ try {
|
|
|
58
59
|
console.log(center(`\x1b[36mβ${"β".repeat(boxWidth)}β\x1b[0m`) + "\n");
|
|
59
60
|
|
|
60
61
|
process.exit(0); // β
Exit only after message shown
|
|
61
|
-
},
|
|
62
|
+
}, 300);
|
|
62
63
|
}
|
|
63
64
|
} catch (error) {
|
|
64
65
|
process.exit(0); // Exit silently
|