toastify-pro 1.0.0 → 1.0.1

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.
@@ -1 +1,132 @@
1
+ class ToastifyPro {
2
+ constructor(options = {}) {
3
+ this.defaultOptions = {
4
+ position: options.position || "bottom-center", // top-left, top-right, bottom-left, bottom-right, top-center, bottom-center
5
+ timeout: options.timeout || 3000,
6
+ allowClose: options.allowClose !== false, // default true
7
+ maxLength: options.maxLength || 100,
8
+ };
9
+
10
+ // create container only once
11
+ const existing = document.querySelector(
12
+ `.toastify-pro-container.${this.defaultOptions.position}`
13
+ );
14
+ if (existing) {
15
+ this.container = existing;
16
+ } else {
17
+ this.container = document.createElement("div");
18
+ this.container.className = `toastify-pro-container ${this.defaultOptions.position}`;
19
+ document.body.appendChild(this.container);
20
+ }
21
+
22
+ this.injectStyles();
23
+ }
24
+
25
+ injectStyles() {
26
+ if (document.getElementById("toastify-pro-styles")) return; // load once
27
+ const style = document.createElement("style");
28
+ style.id = "toastify-pro-styles";
29
+ style.textContent = `
30
+ .toastify-pro-container {
31
+ position: fixed;
32
+ z-index: 9999;
33
+ display: flex;
34
+ flex-direction: column;
35
+ gap: 10px;
36
+ pointer-events: none;
37
+ }
38
+ .toastify-pro-container.top-left { top: 20px; left: 20px; align-items: flex-start; }
39
+ .toastify-pro-container.top-right { top: 20px; right: 20px; align-items: flex-end; }
40
+ .toastify-pro-container.bottom-left { bottom: 20px; left: 20px; align-items: flex-start; }
41
+ .toastify-pro-container.bottom-right { bottom: 20px; right: 20px; align-items: flex-end; }
42
+ .toastify-pro-container.top-center { top: 20px; left: 50%; transform: translateX(-50%); }
43
+ .toastify-pro-container.bottom-center { bottom: 150px; left: 50%; transform: translateX(-50%); }
44
+
45
+ .toastify-pro {
46
+ min-width: 220px;
47
+ max-width: 320px;
48
+ padding: 12px 18px;
49
+ border-radius: 20px;
50
+ font-size: 14px;
51
+ font-family: sans-serif;
52
+ color: white;
53
+ opacity: 0;
54
+ transform: translateY(20px);
55
+ transition: all 0.3s ease;
56
+ pointer-events: auto;
57
+ position: relative;
58
+ }
59
+ .toastify-pro.show { opacity: 1; transform: translateY(0); }
60
+ .toastify-pro.success { background: rgba(76, 175, 80, 0.9); }
61
+ .toastify-pro.error { background: rgba(244, 67, 54, 0.9); }
62
+ .toastify-pro.info { background: rgba(33, 150, 243, 0.9); }
63
+ .toastify-pro.warning { background: rgba(255, 152, 0, 0.9); }
64
+ .toastify-pro.dark { background: rgba(0,0,0,0.85); }
65
+ .toastify-pro.light { background: rgba(255,255,255,0.9); color: #000; }
66
+
67
+ .toastify-pro .close-btn {
68
+ position: absolute;
69
+ right: 20px;
70
+ top: 8px;
71
+ cursor: pointer;
72
+ font-size: 20px;
73
+ color: inherit;
74
+ opacity: 0.8;
75
+ }
76
+ .toastify-pro .close-btn:hover { opacity: 1; }
77
+ `;
78
+ document.head.appendChild(style);
79
+ }
80
+
81
+ show(message, type = "dark", opts = {}) {
82
+ const options = { ...this.defaultOptions, ...opts };
83
+
84
+ const toast = document.createElement("div");
85
+ toast.className = `toastify-pro ${type}`;
86
+ toast.innerText = message.substring(0, options.maxLength);
87
+
88
+ if (options.allowClose) {
89
+ const closeBtn = document.createElement("span");
90
+ closeBtn.className = "close-btn";
91
+ closeBtn.innerHTML = "×";
92
+ closeBtn.onclick = () => this.removeToast(toast);
93
+ toast.appendChild(closeBtn);
94
+ }
95
+
96
+ this.container.appendChild(toast);
97
+
98
+ // show animation
99
+ setTimeout(() => toast.classList.add("show"), 50);
100
+
101
+ // auto remove
102
+ if (options.timeout > 0) {
103
+ setTimeout(() => this.removeToast(toast), options.timeout);
104
+ }
105
+ }
106
+
107
+ removeToast(toast) {
108
+ toast.classList.remove("show");
109
+ setTimeout(() => toast.remove(), 300);
110
+ }
111
+
112
+ success(msg, opts) {
113
+ this.show(msg, "success", opts);
114
+ }
115
+ error(msg, opts) {
116
+ this.show(msg, "error", opts);
117
+ }
118
+ info(msg, opts) {
119
+ this.show(msg, "info", opts);
120
+ }
121
+ warning(msg, opts) {
122
+ this.show(msg, "warning", opts);
123
+ }
124
+ dark(msg, opts) {
125
+ this.show(msg, "dark", opts);
126
+ }
127
+ light(msg, opts) {
128
+ this.show(msg, "light", opts);
129
+ }
130
+ }
1
131
 
132
+ export { ToastifyPro as default };
@@ -1,8 +1,140 @@
1
- (function (factory) {
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
2
3
  typeof define === 'function' && define.amd ? define(factory) :
3
- factory();
4
- })((function () { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ToastifyPro = factory());
5
+ })(this, (function () { 'use strict';
5
6
 
7
+ class ToastifyPro {
8
+ constructor(options = {}) {
9
+ this.defaultOptions = {
10
+ position: options.position || "bottom-center", // top-left, top-right, bottom-left, bottom-right, top-center, bottom-center
11
+ timeout: options.timeout || 3000,
12
+ allowClose: options.allowClose !== false, // default true
13
+ maxLength: options.maxLength || 100,
14
+ };
15
+
16
+ // create container only once
17
+ const existing = document.querySelector(
18
+ `.toastify-pro-container.${this.defaultOptions.position}`
19
+ );
20
+ if (existing) {
21
+ this.container = existing;
22
+ } else {
23
+ this.container = document.createElement("div");
24
+ this.container.className = `toastify-pro-container ${this.defaultOptions.position}`;
25
+ document.body.appendChild(this.container);
26
+ }
27
+
28
+ this.injectStyles();
29
+ }
30
+
31
+ injectStyles() {
32
+ if (document.getElementById("toastify-pro-styles")) return; // load once
33
+ const style = document.createElement("style");
34
+ style.id = "toastify-pro-styles";
35
+ style.textContent = `
36
+ .toastify-pro-container {
37
+ position: fixed;
38
+ z-index: 9999;
39
+ display: flex;
40
+ flex-direction: column;
41
+ gap: 10px;
42
+ pointer-events: none;
43
+ }
44
+ .toastify-pro-container.top-left { top: 20px; left: 20px; align-items: flex-start; }
45
+ .toastify-pro-container.top-right { top: 20px; right: 20px; align-items: flex-end; }
46
+ .toastify-pro-container.bottom-left { bottom: 20px; left: 20px; align-items: flex-start; }
47
+ .toastify-pro-container.bottom-right { bottom: 20px; right: 20px; align-items: flex-end; }
48
+ .toastify-pro-container.top-center { top: 20px; left: 50%; transform: translateX(-50%); }
49
+ .toastify-pro-container.bottom-center { bottom: 150px; left: 50%; transform: translateX(-50%); }
50
+
51
+ .toastify-pro {
52
+ min-width: 220px;
53
+ max-width: 320px;
54
+ padding: 12px 18px;
55
+ border-radius: 20px;
56
+ font-size: 14px;
57
+ font-family: sans-serif;
58
+ color: white;
59
+ opacity: 0;
60
+ transform: translateY(20px);
61
+ transition: all 0.3s ease;
62
+ pointer-events: auto;
63
+ position: relative;
64
+ }
65
+ .toastify-pro.show { opacity: 1; transform: translateY(0); }
66
+ .toastify-pro.success { background: rgba(76, 175, 80, 0.9); }
67
+ .toastify-pro.error { background: rgba(244, 67, 54, 0.9); }
68
+ .toastify-pro.info { background: rgba(33, 150, 243, 0.9); }
69
+ .toastify-pro.warning { background: rgba(255, 152, 0, 0.9); }
70
+ .toastify-pro.dark { background: rgba(0,0,0,0.85); }
71
+ .toastify-pro.light { background: rgba(255,255,255,0.9); color: #000; }
72
+
73
+ .toastify-pro .close-btn {
74
+ position: absolute;
75
+ right: 20px;
76
+ top: 8px;
77
+ cursor: pointer;
78
+ font-size: 20px;
79
+ color: inherit;
80
+ opacity: 0.8;
81
+ }
82
+ .toastify-pro .close-btn:hover { opacity: 1; }
83
+ `;
84
+ document.head.appendChild(style);
85
+ }
86
+
87
+ show(message, type = "dark", opts = {}) {
88
+ const options = { ...this.defaultOptions, ...opts };
89
+
90
+ const toast = document.createElement("div");
91
+ toast.className = `toastify-pro ${type}`;
92
+ toast.innerText = message.substring(0, options.maxLength);
93
+
94
+ if (options.allowClose) {
95
+ const closeBtn = document.createElement("span");
96
+ closeBtn.className = "close-btn";
97
+ closeBtn.innerHTML = "×";
98
+ closeBtn.onclick = () => this.removeToast(toast);
99
+ toast.appendChild(closeBtn);
100
+ }
101
+
102
+ this.container.appendChild(toast);
103
+
104
+ // show animation
105
+ setTimeout(() => toast.classList.add("show"), 50);
106
+
107
+ // auto remove
108
+ if (options.timeout > 0) {
109
+ setTimeout(() => this.removeToast(toast), options.timeout);
110
+ }
111
+ }
112
+
113
+ removeToast(toast) {
114
+ toast.classList.remove("show");
115
+ setTimeout(() => toast.remove(), 300);
116
+ }
117
+
118
+ success(msg, opts) {
119
+ this.show(msg, "success", opts);
120
+ }
121
+ error(msg, opts) {
122
+ this.show(msg, "error", opts);
123
+ }
124
+ info(msg, opts) {
125
+ this.show(msg, "info", opts);
126
+ }
127
+ warning(msg, opts) {
128
+ this.show(msg, "warning", opts);
129
+ }
130
+ dark(msg, opts) {
131
+ this.show(msg, "dark", opts);
132
+ }
133
+ light(msg, opts) {
134
+ this.show(msg, "light", opts);
135
+ }
136
+ }
6
137
 
138
+ return ToastifyPro;
7
139
 
8
140
  }));
@@ -1 +1 @@
1
- !function(n){"function"==typeof define&&define.amd?define(n):n()}(function(){});
1
+ !function(t,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(t="undefined"!=typeof globalThis?globalThis:t||self).ToastifyPro=o()}(this,function(){"use strict";return class{constructor(t={}){this.defaultOptions={position:t.position||"bottom-center",timeout:t.timeout||3e3,allowClose:!1!==t.allowClose,maxLength:t.maxLength||100};const o=document.querySelector(`.toastify-pro-container.${this.defaultOptions.position}`);o?this.container=o:(this.container=document.createElement("div"),this.container.className=`toastify-pro-container ${this.defaultOptions.position}`,document.body.appendChild(this.container)),this.injectStyles()}injectStyles(){if(document.getElementById("toastify-pro-styles"))return;const t=document.createElement("style");t.id="toastify-pro-styles",t.textContent="\n .toastify-pro-container {\n position: fixed;\n z-index: 9999;\n display: flex;\n flex-direction: column;\n gap: 10px;\n pointer-events: none;\n }\n .toastify-pro-container.top-left { top: 20px; left: 20px; align-items: flex-start; }\n .toastify-pro-container.top-right { top: 20px; right: 20px; align-items: flex-end; }\n .toastify-pro-container.bottom-left { bottom: 20px; left: 20px; align-items: flex-start; }\n .toastify-pro-container.bottom-right { bottom: 20px; right: 20px; align-items: flex-end; }\n .toastify-pro-container.top-center { top: 20px; left: 50%; transform: translateX(-50%); }\n .toastify-pro-container.bottom-center { bottom: 150px; left: 50%; transform: translateX(-50%); }\n\n .toastify-pro {\n min-width: 220px;\n max-width: 320px;\n padding: 12px 18px;\n border-radius: 20px;\n font-size: 14px;\n font-family: sans-serif;\n color: white;\n opacity: 0;\n transform: translateY(20px);\n transition: all 0.3s ease;\n pointer-events: auto;\n position: relative;\n }\n .toastify-pro.show { opacity: 1; transform: translateY(0); }\n .toastify-pro.success { background: rgba(76, 175, 80, 0.9); }\n .toastify-pro.error { background: rgba(244, 67, 54, 0.9); }\n .toastify-pro.info { background: rgba(33, 150, 243, 0.9); }\n .toastify-pro.warning { background: rgba(255, 152, 0, 0.9); }\n .toastify-pro.dark { background: rgba(0,0,0,0.85); }\n .toastify-pro.light { background: rgba(255,255,255,0.9); color: #000; }\n\n .toastify-pro .close-btn {\n position: absolute;\n right: 20px;\n top: 8px;\n cursor: pointer;\n font-size: 20px;\n color: inherit;\n opacity: 0.8;\n }\n .toastify-pro .close-btn:hover { opacity: 1; }\n ",document.head.appendChild(t)}show(t,o="dark",n={}){const e={...this.defaultOptions,...n},i=document.createElement("div");if(i.className=`toastify-pro ${o}`,i.innerText=t.substring(0,e.maxLength),e.allowClose){const t=document.createElement("span");t.className="close-btn",t.innerHTML="×",t.onclick=()=>this.removeToast(i),i.appendChild(t)}this.container.appendChild(i),setTimeout(()=>i.classList.add("show"),50),e.timeout>0&&setTimeout(()=>this.removeToast(i),e.timeout)}removeToast(t){t.classList.remove("show"),setTimeout(()=>t.remove(),300)}success(t,o){this.show(t,"success",o)}error(t,o){this.show(t,"error",o)}info(t,o){this.show(t,"info",o)}warning(t,o){this.show(t,"warning",o)}dark(t,o){this.show(t,"dark",o)}light(t,o){this.show(t,"light",o)}}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toastify-pro",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A lightweight customizable toast notification library",
5
5
  "main": "dist/toastify-pro.umd.js",
6
6
  "module": "dist/toastify-pro.esm.js",
@@ -127,4 +127,6 @@
127
127
  light(msg, opts) {
128
128
  this.show(msg, "light", opts);
129
129
  }
130
- }
130
+ }
131
+
132
+ export default ToastifyPro;