emessages 2.1.2 → 2.2.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.
- package/dist/cli.cjs +89 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +66 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.cjs +203 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -8
- package/dist/index.d.ts +12 -8
- package/dist/index.mjs +203 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/cli.ts
|
|
27
|
+
var fs = __toESM(require("fs"), 1);
|
|
28
|
+
var path = __toESM(require("path"), 1);
|
|
29
|
+
var fileName = "globalEMessage";
|
|
30
|
+
var jsContent = `import { Emessage } from "emessages";
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* Add your global error messages and available operation here.
|
|
34
|
+
*/
|
|
35
|
+
Emessage.global(
|
|
36
|
+
{
|
|
37
|
+
"GLOBAL_ERROR_NAME": "GLOBAL ERROR MESSAGE",
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
`;
|
|
41
|
+
var tsContent = `import { Emessage } from "emessages";
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Add your global error messages and available operation here.
|
|
45
|
+
*/
|
|
46
|
+
Emessage.global(
|
|
47
|
+
{
|
|
48
|
+
"GLOBAL_ERROR_NAME": "GLOBAL ERROR MESSAGE",
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
`;
|
|
52
|
+
function findProjectRoot(startDir) {
|
|
53
|
+
let currentDir = startDir;
|
|
54
|
+
while (currentDir !== path.parse(currentDir).root) {
|
|
55
|
+
if (fs.existsSync(path.join(currentDir, "package.json"))) {
|
|
56
|
+
return currentDir;
|
|
57
|
+
}
|
|
58
|
+
currentDir = path.dirname(currentDir);
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function generateGlobalEmessageFile() {
|
|
63
|
+
const cwd = process.cwd();
|
|
64
|
+
const projectRoot = findProjectRoot(cwd);
|
|
65
|
+
if (!projectRoot) {
|
|
66
|
+
console.error("Error: Could not find project root (package.json not found).");
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
70
|
+
const isTypeScriptProject = fs.existsSync(tsconfigPath);
|
|
71
|
+
const fileExtension = isTypeScriptProject ? "ts" : "js";
|
|
72
|
+
const content = isTypeScriptProject ? tsContent : jsContent;
|
|
73
|
+
const outputFileName = `${fileName}.${fileExtension}`;
|
|
74
|
+
const outputPath = path.join(projectRoot, outputFileName);
|
|
75
|
+
if (fs.existsSync(outputPath)) {
|
|
76
|
+
console.warn(`Warning: ${outputFileName} already exists. Skipping file creation.`);
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
fs.writeFileSync(outputPath, content, "utf8");
|
|
81
|
+
console.log(`Successfully created ${outputFileName} in your project root.`);
|
|
82
|
+
console.log("You can now configure global messages by editing this file.");
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error(`Error creating ${outputFileName}:`, error.message);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
generateGlobalEmessageFile();
|
|
89
|
+
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nconst fileName = 'globalEMessage';\nconst jsContent = `import { Emessage } from \"emessages\";\n\n/*\n * Add your global error messages and available operation here.\n */\nEmessage.global(\n {\n \"GLOBAL_ERROR_NAME\": \"GLOBAL ERROR MESSAGE\",\n }\n);\n`;\n\nconst tsContent = `import { Emessage } from \"emessages\";\n\n/*\n * Add your global error messages and available operation here.\n */\nEmessage.global(\n {\n \"GLOBAL_ERROR_NAME\": \"GLOBAL ERROR MESSAGE\",\n }\n);\n`;\n\nfunction findProjectRoot(startDir: string): string | null {\n let currentDir = startDir;\n while (currentDir !== path.parse(currentDir).root) {\n if (fs.existsSync(path.join(currentDir, 'package.json'))) {\n return currentDir;\n }\n currentDir = path.dirname(currentDir);\n }\n return null;\n}\n\nfunction generateGlobalEmessageFile() {\n const cwd = process.cwd();\n const projectRoot = findProjectRoot(cwd);\n\n if (!projectRoot) {\n console.error('Error: Could not find project root (package.json not found).');\n process.exit(1);\n }\n\n const tsconfigPath = path.join(projectRoot, 'tsconfig.json');\n const isTypeScriptProject = fs.existsSync(tsconfigPath);\n\n const fileExtension = isTypeScriptProject ? 'ts' : 'js';\n const content = isTypeScriptProject ? tsContent : jsContent;\n const outputFileName = `${fileName}.${fileExtension}`;\n const outputPath = path.join(projectRoot, outputFileName);\n\n if (fs.existsSync(outputPath)) {\n console.warn(`Warning: ${outputFileName} already exists. Skipping file creation.`);\n process.exit(0);\n }\n\n try {\n fs.writeFileSync(outputPath, content, 'utf8');\n console.log(`Successfully created ${outputFileName} in your project root.`);\n console.log('You can now configure global messages by editing this file.');\n } catch (error: any) {\n console.error(`Error creating ${outputFileName}:`, error.message);\n process.exit(1);\n }\n}\n\ngenerateGlobalEmessageFile();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAoB;AACpB,WAAsB;AAEtB,IAAM,WAAW;AACjB,IAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYlB,IAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYlB,SAAS,gBAAgB,UAAiC;AACtD,MAAI,aAAa;AACjB,SAAO,eAAoB,WAAM,UAAU,EAAE,MAAM;AAC/C,QAAO,cAAgB,UAAK,YAAY,cAAc,CAAC,GAAG;AACtD,aAAO;AAAA,IACX;AACA,iBAAkB,aAAQ,UAAU;AAAA,EACxC;AACA,SAAO;AACX;AAEA,SAAS,6BAA6B;AAClC,QAAM,MAAM,QAAQ,IAAI;AACxB,QAAM,cAAc,gBAAgB,GAAG;AAEvC,MAAI,CAAC,aAAa;AACd,YAAQ,MAAM,8DAA8D;AAC5E,YAAQ,KAAK,CAAC;AAAA,EAClB;AAEA,QAAM,eAAoB,UAAK,aAAa,eAAe;AAC3D,QAAM,sBAAyB,cAAW,YAAY;AAEtD,QAAM,gBAAgB,sBAAsB,OAAO;AACnD,QAAM,UAAU,sBAAsB,YAAY;AAClD,QAAM,iBAAiB,GAAG,QAAQ,IAAI,aAAa;AACnD,QAAM,aAAkB,UAAK,aAAa,cAAc;AAExD,MAAO,cAAW,UAAU,GAAG;AAC3B,YAAQ,KAAK,YAAY,cAAc,0CAA0C;AACjF,YAAQ,KAAK,CAAC;AAAA,EAClB;AAEA,MAAI;AACA,IAAG,iBAAc,YAAY,SAAS,MAAM;AAC5C,YAAQ,IAAI,wBAAwB,cAAc,wBAAwB;AAC1E,YAAQ,IAAI,6DAA6D;AAAA,EAC7E,SAAS,OAAY;AACjB,YAAQ,MAAM,kBAAkB,cAAc,KAAK,MAAM,OAAO;AAChE,YAAQ,KAAK,CAAC;AAAA,EAClB;AACJ;AAEA,2BAA2B;","names":[]}
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import * as fs from "fs";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
var fileName = "globalEMessage";
|
|
7
|
+
var jsContent = `import { Emessage } from "emessages";
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Add your global error messages and available operation here.
|
|
11
|
+
*/
|
|
12
|
+
Emessage.global(
|
|
13
|
+
{
|
|
14
|
+
"GLOBAL_ERROR_NAME": "GLOBAL ERROR MESSAGE",
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
`;
|
|
18
|
+
var tsContent = `import { Emessage } from "emessages";
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* Add your global error messages and available operation here.
|
|
22
|
+
*/
|
|
23
|
+
Emessage.global(
|
|
24
|
+
{
|
|
25
|
+
"GLOBAL_ERROR_NAME": "GLOBAL ERROR MESSAGE",
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
`;
|
|
29
|
+
function findProjectRoot(startDir) {
|
|
30
|
+
let currentDir = startDir;
|
|
31
|
+
while (currentDir !== path.parse(currentDir).root) {
|
|
32
|
+
if (fs.existsSync(path.join(currentDir, "package.json"))) {
|
|
33
|
+
return currentDir;
|
|
34
|
+
}
|
|
35
|
+
currentDir = path.dirname(currentDir);
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
function generateGlobalEmessageFile() {
|
|
40
|
+
const cwd = process.cwd();
|
|
41
|
+
const projectRoot = findProjectRoot(cwd);
|
|
42
|
+
if (!projectRoot) {
|
|
43
|
+
console.error("Error: Could not find project root (package.json not found).");
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
47
|
+
const isTypeScriptProject = fs.existsSync(tsconfigPath);
|
|
48
|
+
const fileExtension = isTypeScriptProject ? "ts" : "js";
|
|
49
|
+
const content = isTypeScriptProject ? tsContent : jsContent;
|
|
50
|
+
const outputFileName = `${fileName}.${fileExtension}`;
|
|
51
|
+
const outputPath = path.join(projectRoot, outputFileName);
|
|
52
|
+
if (fs.existsSync(outputPath)) {
|
|
53
|
+
console.warn(`Warning: ${outputFileName} already exists. Skipping file creation.`);
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
fs.writeFileSync(outputPath, content, "utf8");
|
|
58
|
+
console.log(`Successfully created ${outputFileName} in your project root.`);
|
|
59
|
+
console.log("You can now configure global messages by editing this file.");
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(`Error creating ${outputFileName}:`, error.message);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
generateGlobalEmessageFile();
|
|
66
|
+
//# sourceMappingURL=cli.mjs.map
|
package/dist/cli.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nconst fileName = 'globalEMessage';\nconst jsContent = `import { Emessage } from \"emessages\";\n\n/*\n * Add your global error messages and available operation here.\n */\nEmessage.global(\n {\n \"GLOBAL_ERROR_NAME\": \"GLOBAL ERROR MESSAGE\",\n }\n);\n`;\n\nconst tsContent = `import { Emessage } from \"emessages\";\n\n/*\n * Add your global error messages and available operation here.\n */\nEmessage.global(\n {\n \"GLOBAL_ERROR_NAME\": \"GLOBAL ERROR MESSAGE\",\n }\n);\n`;\n\nfunction findProjectRoot(startDir: string): string | null {\n let currentDir = startDir;\n while (currentDir !== path.parse(currentDir).root) {\n if (fs.existsSync(path.join(currentDir, 'package.json'))) {\n return currentDir;\n }\n currentDir = path.dirname(currentDir);\n }\n return null;\n}\n\nfunction generateGlobalEmessageFile() {\n const cwd = process.cwd();\n const projectRoot = findProjectRoot(cwd);\n\n if (!projectRoot) {\n console.error('Error: Could not find project root (package.json not found).');\n process.exit(1);\n }\n\n const tsconfigPath = path.join(projectRoot, 'tsconfig.json');\n const isTypeScriptProject = fs.existsSync(tsconfigPath);\n\n const fileExtension = isTypeScriptProject ? 'ts' : 'js';\n const content = isTypeScriptProject ? tsContent : jsContent;\n const outputFileName = `${fileName}.${fileExtension}`;\n const outputPath = path.join(projectRoot, outputFileName);\n\n if (fs.existsSync(outputPath)) {\n console.warn(`Warning: ${outputFileName} already exists. Skipping file creation.`);\n process.exit(0);\n }\n\n try {\n fs.writeFileSync(outputPath, content, 'utf8');\n console.log(`Successfully created ${outputFileName} in your project root.`);\n console.log('You can now configure global messages by editing this file.');\n } catch (error: any) {\n console.error(`Error creating ${outputFileName}:`, error.message);\n process.exit(1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AA2B;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -33,31 +33,215 @@ var globalMessageStore = /* @__PURE__ */ new Map();
|
|
|
33
33
|
function isBrowser() {
|
|
34
34
|
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function removeToastElement(toastElement) {
|
|
37
|
+
if (!toastElement || !toastElement.parentElement) return;
|
|
38
|
+
toastElement.classList.remove("visible");
|
|
39
|
+
toastElement.addEventListener("transitionend", () => {
|
|
40
|
+
const container = toastElement.parentElement;
|
|
41
|
+
if (container) {
|
|
42
|
+
container.removeChild(toastElement);
|
|
43
|
+
if (container.childElementCount === 0 && container.parentElement) {
|
|
44
|
+
container.parentElement.removeChild(container);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function initializeGlobalApi() {
|
|
50
|
+
if (!isBrowser()) return;
|
|
51
|
+
if (!window.emessages) {
|
|
52
|
+
window.emessages = {};
|
|
53
|
+
}
|
|
54
|
+
if (!window.emessages.closeToast) {
|
|
55
|
+
window.emessages.closeToast = function(eventOrId) {
|
|
56
|
+
let toastElement = null;
|
|
57
|
+
if (typeof eventOrId === "string") {
|
|
58
|
+
toastElement = document.getElementById(eventOrId);
|
|
59
|
+
} else if (eventOrId && eventOrId.target) {
|
|
60
|
+
toastElement = eventOrId.target.closest(".emessage-toast");
|
|
61
|
+
}
|
|
62
|
+
if (toastElement) {
|
|
63
|
+
removeToastElement(toastElement);
|
|
64
|
+
} else {
|
|
65
|
+
console.warn("emessages: closeToast() was called but could not find a toast element to close.");
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
initializeGlobalApi();
|
|
71
|
+
function injectToastStyles() {
|
|
72
|
+
if (!isBrowser()) return;
|
|
73
|
+
const styleId = "emessages-toast-styles";
|
|
74
|
+
if (document.getElementById(styleId)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const style = document.createElement("style");
|
|
78
|
+
style.id = styleId;
|
|
79
|
+
style.innerHTML = `
|
|
80
|
+
.emessages-toast-container {
|
|
81
|
+
position: fixed;
|
|
82
|
+
display: flex;
|
|
83
|
+
flex-direction: column;
|
|
84
|
+
padding: 10px;
|
|
85
|
+
pointer-events: none;
|
|
86
|
+
z-index: 9999;
|
|
87
|
+
box-sizing: border-box;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* Positioning for containers */
|
|
91
|
+
.emessages-toast-container.top-left { top: 0; left: 0; align-items: flex-start; }
|
|
92
|
+
.emessages-toast-container.top-center { top: 0; left: 50%; transform: translateX(-50%); align-items: center; }
|
|
93
|
+
.emessages-toast-container.top-right { top: 0; right: 0; align-items: flex-end; }
|
|
94
|
+
.emessages-toast-container.bottom-left { bottom: 0; left: 0; align-items: flex-start; }
|
|
95
|
+
.emessages-toast-container.bottom-center { bottom: 0; left: 50%; transform: translateX(-50%); align-items: center; }
|
|
96
|
+
.emessages-toast-container.bottom-right { bottom: 0; right: 0; align-items: flex-end; }
|
|
97
|
+
.emessages-toast-container.center { top: 50%; left: 50%; transform: translate(-50%, -50%); align-items: center; }
|
|
98
|
+
.emessages-toast-container.center-left { top: 50%; left: 0; transform: translateY(-50%); align-items: flex-start; }
|
|
99
|
+
.emessages-toast-container.center-right { top: 50%; right: 0; transform: translateY(-50%); align-items: flex-end; }
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
.emessage-toast {
|
|
103
|
+
padding: 12px 18px;
|
|
104
|
+
margin: 8px;
|
|
105
|
+
border-radius: 6px;
|
|
106
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
|
107
|
+
font-size: 14px;
|
|
108
|
+
opacity: 0;
|
|
109
|
+
transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
|
|
110
|
+
transform: translateY(20px);
|
|
111
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
112
|
+
pointer-events: all;
|
|
113
|
+
max-width: 350px;
|
|
114
|
+
word-break: break-word;
|
|
115
|
+
display: flex;
|
|
116
|
+
justify-content: space-between;
|
|
117
|
+
align-items: center;
|
|
118
|
+
gap: 10px;
|
|
119
|
+
box-sizing: border-box;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.emessage-toast.visible {
|
|
123
|
+
opacity: 1;
|
|
124
|
+
transform: translateY(0);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* Default styles based on message type */
|
|
128
|
+
.emessage-toast-err { background-color: #ef4444; color: white; } /* red-500 */
|
|
129
|
+
.emessage-toast-war { background-color: #f59e0b; color: white; } /* amber-500 */
|
|
130
|
+
.emessage-toast-log { background-color: #ffffff; color: #1f2937; border: 1px solid #e5e7eb; } /* white, gray-800 text, gray-200 border */
|
|
131
|
+
|
|
132
|
+
.emessage-toast-message {
|
|
133
|
+
flex-grow: 1;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.emessage-toast-close {
|
|
137
|
+
background: none;
|
|
138
|
+
border: none;
|
|
139
|
+
color: inherit;
|
|
140
|
+
font-size: 20px;
|
|
141
|
+
font-weight: bold;
|
|
142
|
+
cursor: pointer;
|
|
143
|
+
line-height: 1;
|
|
144
|
+
opacity: 0.7;
|
|
145
|
+
padding: 0;
|
|
146
|
+
margin-left: 15px;
|
|
147
|
+
}
|
|
148
|
+
.emessage-toast-close:hover {
|
|
149
|
+
opacity: 1;
|
|
150
|
+
}
|
|
151
|
+
.emessage-toast-close:focus,
|
|
152
|
+
.emessage-toast-close:focus-visible {
|
|
153
|
+
outline: none;
|
|
154
|
+
}
|
|
155
|
+
`;
|
|
156
|
+
document.head.insertBefore(style, document.head.firstChild);
|
|
157
|
+
}
|
|
158
|
+
function getOrCreateToastContainer(position) {
|
|
159
|
+
const positionMap = {
|
|
160
|
+
top: "top-center",
|
|
161
|
+
bottom: "bottom-center",
|
|
162
|
+
left: "center-left",
|
|
163
|
+
right: "center-right",
|
|
164
|
+
center: "center",
|
|
165
|
+
"top-right": "top-right",
|
|
166
|
+
"top-left": "top-left",
|
|
167
|
+
"top-center": "top-center",
|
|
168
|
+
"bottom-right": "bottom-right",
|
|
169
|
+
"bottom-left": "bottom-left",
|
|
170
|
+
"bottom-center": "bottom-center",
|
|
171
|
+
"center-left": "center-left",
|
|
172
|
+
"center-right": "center-right"
|
|
173
|
+
};
|
|
174
|
+
const normalizedPosition = positionMap[position.toLowerCase().replace(/\s/g, "-")] || "top-right";
|
|
175
|
+
const containerId = `emessages-toast-container-${normalizedPosition}`;
|
|
176
|
+
let container = document.getElementById(containerId);
|
|
177
|
+
if (!container) {
|
|
178
|
+
container = document.createElement("div");
|
|
179
|
+
container.id = containerId;
|
|
180
|
+
container.className = `emessages-toast-container ${normalizedPosition}`;
|
|
181
|
+
document.body.appendChild(container);
|
|
182
|
+
}
|
|
183
|
+
return container;
|
|
184
|
+
}
|
|
185
|
+
function showToast(message, toastOptions, messageType = "log") {
|
|
37
186
|
if (!isBrowser()) {
|
|
38
187
|
return;
|
|
39
188
|
}
|
|
189
|
+
injectToastStyles();
|
|
190
|
+
const config = typeof toastOptions === "object" ? toastOptions : {};
|
|
191
|
+
let {
|
|
192
|
+
message: customMessage,
|
|
193
|
+
style: customStyle,
|
|
194
|
+
class: customClass,
|
|
195
|
+
position = "top-right",
|
|
196
|
+
stay = false,
|
|
197
|
+
duration = 3e3,
|
|
198
|
+
delay = 0
|
|
199
|
+
} = config;
|
|
40
200
|
const toast = document.createElement("div");
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
201
|
+
toast.id = `emessage-toast-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
202
|
+
let toastClasses = ["emessage-toast"];
|
|
203
|
+
toastClasses.push(`emessage-toast-${messageType}`);
|
|
204
|
+
if (customClass) {
|
|
205
|
+
toastClasses.push(...customClass.split(" ").filter((c) => c));
|
|
206
|
+
}
|
|
207
|
+
toast.className = toastClasses.join(" ");
|
|
208
|
+
if (customStyle) {
|
|
209
|
+
toast.style.cssText += customStyle;
|
|
210
|
+
}
|
|
211
|
+
const messageElement = document.createElement("div");
|
|
212
|
+
messageElement.className = "emessage-toast-message";
|
|
213
|
+
if (typeof customMessage === "object" && customMessage !== null) {
|
|
214
|
+
console.warn("emessages: The `toast.message` property received an object (likely a React component), but it only accepts an HTML string. Please pass a string of HTML to render it correctly. Falling back to the default message.");
|
|
215
|
+
customMessage = void 0;
|
|
216
|
+
}
|
|
217
|
+
messageElement.innerHTML = customMessage || message;
|
|
218
|
+
toast.appendChild(messageElement);
|
|
219
|
+
const closeButton = document.createElement("button");
|
|
220
|
+
closeButton.className = "emessage-toast-close";
|
|
221
|
+
closeButton.innerHTML = "×";
|
|
222
|
+
closeButton.setAttribute("aria-label", "Close");
|
|
223
|
+
closeButton.onclick = () => removeToastElement(toast);
|
|
224
|
+
toast.appendChild(closeButton);
|
|
225
|
+
const container = getOrCreateToastContainer(position);
|
|
53
226
|
setTimeout(() => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
227
|
+
if (position.includes("bottom")) {
|
|
228
|
+
container.prepend(toast);
|
|
229
|
+
} else {
|
|
230
|
+
container.appendChild(toast);
|
|
231
|
+
}
|
|
232
|
+
requestAnimationFrame(() => {
|
|
233
|
+
toast.classList.add("visible");
|
|
234
|
+
});
|
|
235
|
+
}, delay);
|
|
236
|
+
if (!stay) {
|
|
237
|
+
const hideTimeout = setTimeout(() => removeToastElement(toast), delay + duration);
|
|
238
|
+
toast.addEventListener("mouseenter", () => clearTimeout(hideTimeout));
|
|
239
|
+
toast.addEventListener("mouseleave", () => {
|
|
240
|
+
if (!stay) {
|
|
241
|
+
setTimeout(() => removeToastElement(toast), 1e3);
|
|
58
242
|
}
|
|
59
243
|
});
|
|
60
|
-
}
|
|
244
|
+
}
|
|
61
245
|
}
|
|
62
246
|
|
|
63
247
|
// src/index.ts
|
|
@@ -129,7 +313,7 @@ function processEmessage(errorName, config) {
|
|
|
129
313
|
}
|
|
130
314
|
}
|
|
131
315
|
if (config.toast && isBrowser()) {
|
|
132
|
-
showToast(message, config.toast);
|
|
316
|
+
showToast(message, config.toast, consoleType);
|
|
133
317
|
}
|
|
134
318
|
if (config.callBack) {
|
|
135
319
|
try {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/store.ts","../src/utils.ts"],"sourcesContent":["import { individualMessageStore, globalMessageStore } from \"./store\";\r\nimport type {\r\n EmessageConfig,\r\n EmessageOptions,\r\n StoredEmessage,\r\n ToastConfig,\r\n MessageType,\r\n} from \"./types\";\r\nimport { isBrowser, showToast } from \"./utils\";\r\n\r\nfunction parseConfig(\r\n config: Record<string, any>\r\n): { name: string; options: StoredEmessage } | null {\r\n const options: EmessageOptions = {};\r\n let message: string | null = null;\r\n let name: string | null = null;\r\n const optionKeys = [\"type\", \"break\", \"toast\", \"returnEM\", \"callBack\"];\r\n\r\n for (const key in config) {\r\n if (Object.prototype.hasOwnProperty.call(config, key)) {\r\n if (optionKeys.includes(key)) {\r\n (options as any)[key] = config[key];\r\n } else {\r\n if (name !== null) {\r\n console.warn(\r\n `emessages: Found multiple potential error names in one config object. Using first one found: \"${name}\".`\r\n );\r\n continue;\r\n }\r\n name = key;\r\n message = String(config[key]);\r\n }\r\n }\r\n }\r\n\r\n if (name === null || message === null) {\r\n console.error(\r\n \"emessages: Invalid config object. Could not find error name and message.\",\r\n config\r\n );\r\n return null;\r\n }\r\n\r\n return { name, options: { ...options, message } };\r\n}\r\n\r\nfunction processEmessage(\r\n errorName: string,\r\n config: StoredEmessage\r\n): string | void {\r\n const message = config.message;\r\n\r\n let consoleType: MessageType | false;\r\n if (config.type === false) {\r\n consoleType = false;\r\n } else if (config.type === true || config.type === undefined) {\r\n consoleType = \"err\";\r\n } else {\r\n consoleType = config.type;\r\n }\r\n\r\n // 1. Console log\r\n if (consoleType) {\r\n if (isBrowser()) {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(message);\r\n break;\r\n case \"war\":\r\n console.warn(message);\r\n break;\r\n case \"err\":\r\n console.error(message);\r\n break;\r\n }\r\n } else {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(`\\x1b[30;47m ${message} \\x1b[0m`);\r\n break;\r\n case \"war\":\r\n console.warn(`\\x1b[37;43m ${message} \\x1b[0m`);\r\n break;\r\n case \"err\":\r\n console.error(`\\x1b[37;41m ${message} \\x1b[0m`);\r\n break;\r\n }\r\n }\r\n }\r\n\r\n // 2. Toast notification\r\n if (config.toast && isBrowser()) {\r\n showToast(message, config.toast);\r\n }\r\n\r\n // 3. Callback\r\n if (config.callBack) {\r\n try {\r\n config.callBack();\r\n } catch (e: any) {\r\n console.error(\r\n `emessages: Error in callBack for \"${errorName}\":`,\r\n e.message\r\n );\r\n }\r\n }\r\n\r\n // 4. Return error message\r\n if (config.returnEM) {\r\n return message;\r\n }\r\n\r\n // 5. Break execution\r\n if (config.break ?? true) {\r\n if (isBrowser()) {\r\n throw new Error(message);\r\n } else {\r\n process.exit(1);\r\n }\r\n }\r\n}\r\n\r\nexport function Emessage(...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n individualMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n}\r\n\r\nEmessage.global = function (...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n globalMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n};\r\n\r\nexport function showE(error: string | Record<string, any>): string | void {\r\n let config: StoredEmessage | null = null;\r\n let errorName: string | null = null;\r\n\r\n if (typeof error === \"string\") {\r\n errorName = error;\r\n config =\r\n individualMessageStore.get(error) ?? globalMessageStore.get(error) ?? null;\r\n if (!config) {\r\n console.error(`emessages: Error \"${error}\" not found.`);\r\n return;\r\n }\r\n } else if (typeof error === \"object\" && error !== null) {\r\n const parsed = parseConfig(error);\r\n if (parsed) {\r\n errorName = parsed.name;\r\n config = parsed.options;\r\n } else {\r\n console.error(\"emessages: Invalid object passed to showE.\");\r\n return;\r\n }\r\n } else {\r\n console.error(\"emessages: Invalid argument passed to showE.\");\r\n return;\r\n }\r\n\r\n if (config && errorName) {\r\n return processEmessage(errorName, config);\r\n }\r\n}\r\n","import type { StoredEmessage } from \"./types\";\r\n\r\nexport const individualMessageStore = new Map<string, StoredEmessage>();\r\nexport const globalMessageStore = new Map<string, StoredEmessage>();\r\n","import { ToastConfig } from \"./types\";\r\n\r\nexport function isBrowser(): boolean {\r\n return typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\r\n}\r\n\r\nexport function showToast(\r\n message: string,\r\n toastConfig: boolean | ToastConfig\r\n): void {\r\n if (!isBrowser()) {\r\n return;\r\n }\r\n\r\n const toast = document.createElement(\"div\");\r\n\r\n const config: ToastConfig = typeof toastConfig === \"object\" ? toastConfig : {};\r\n\r\n toast.textContent = config.message || message;\r\n\r\n // Base styles are applied via CSS, but some can be defaults.\r\n toast.className = \"emessage-toast\";\r\n if (config.style) {\r\n toast.classList.add(...config.style.split(\" \"));\r\n }\r\n\r\n // Positioning\r\n const position = config.position || \"top-right\";\r\n toast.setAttribute(\"data-position\", position);\r\n\r\n document.body.appendChild(toast);\r\n\r\n // Animate in\r\n setTimeout(() => {\r\n toast.classList.add(\"visible\");\r\n }, 10);\r\n\r\n // Animate out and remove\r\n setTimeout(() => {\r\n toast.classList.remove(\"visible\");\r\n toast.addEventListener(\"transitionend\", () => {\r\n if (toast.parentElement) {\r\n toast.parentElement.removeChild(toast);\r\n }\r\n });\r\n }, 3000);\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.ts","../src/utils.ts"],"sourcesContent":["import { individualMessageStore, globalMessageStore } from \"./store\";\r\nimport type {\r\n EmessageConfig,\r\n EmessageOptions,\r\n StoredEmessage,\r\n ToastConfig,\r\n MessageType,\r\n} from \"./types\";\r\nimport { isBrowser, showToast } from \"./utils\";\r\n\r\nfunction parseConfig(\r\n config: Record<string, any>\r\n): { name: string; options: StoredEmessage } | null {\r\n const options: EmessageOptions = {};\r\n let message: string | null = null;\r\n let name: string | null = null;\r\n const optionKeys = [\"type\", \"break\", \"toast\", \"returnEM\", \"callBack\"];\r\n\r\n for (const key in config) {\r\n if (Object.prototype.hasOwnProperty.call(config, key)) {\r\n if (optionKeys.includes(key)) {\r\n (options as any)[key] = config[key];\r\n } else {\r\n if (name !== null) {\r\n console.warn(\r\n `emessages: Found multiple potential error names in one config object. Using first one found: \"${name}\".`\r\n );\r\n continue;\r\n }\r\n name = key;\r\n message = String(config[key]);\r\n }\r\n }\r\n }\r\n\r\n if (name === null || message === null) {\r\n console.error(\r\n \"emessages: Invalid config object. Could not find error name and message.\",\r\n config\r\n );\r\n return null;\r\n }\r\n\r\n return { name, options: { ...options, message } };\r\n}\r\n\r\nfunction processEmessage(\r\n errorName: string,\r\n config: StoredEmessage\r\n): string | void {\r\n const message = config.message;\r\n\r\n let consoleType: MessageType | false;\r\n if (config.type === false) {\r\n consoleType = false;\r\n } else if (config.type === true || config.type === undefined) {\r\n consoleType = \"err\";\r\n } else {\r\n consoleType = config.type;\r\n }\r\n\r\n // 1. Console log\r\n if (consoleType) {\r\n if (isBrowser()) {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(message);\r\n break;\r\n case \"war\":\r\n console.warn(message);\r\n break;\r\n case \"err\":\r\n console.error(message);\r\n break;\r\n }\r\n } else {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(`\\x1b[30;47m ${message} \\x1b[0m`);\r\n break;\r\n case \"war\":\r\n console.warn(`\\x1b[37;43m ${message} \\x1b[0m`);\r\n break;\r\n case \"err\":\r\n console.error(`\\x1b[37;41m ${message} \\x1b[0m`);\r\n break;\r\n }\r\n }\r\n }\r\n\r\n // 2. Toast notification\r\n if (config.toast && isBrowser()) {\r\n showToast(message, config.toast, consoleType as MessageType);\r\n }\r\n\r\n // 3. Callback\r\n if (config.callBack) {\r\n try {\r\n config.callBack();\r\n } catch (e: any) {\r\n console.error(\r\n `emessages: Error in callBack for \"${errorName}\":`,\r\n e.message\r\n );\r\n }\r\n }\r\n\r\n // 4. Return error message\r\n if (config.returnEM) {\r\n return message;\r\n }\r\n\r\n // 5. Break execution\r\n if (config.break ?? true) {\r\n if (isBrowser()) {\r\n throw new Error(message);\r\n } else {\r\n process.exit(1);\r\n }\r\n }\r\n}\r\n\r\nexport function Emessage(...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n individualMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n}\r\n\r\nEmessage.global = function (...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n globalMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n};\r\n\r\nexport function showE(error: string | Record<string, any>): string | void {\r\n let config: StoredEmessage | null = null;\r\n let errorName: string | null = null;\r\n\r\n if (typeof error === \"string\") {\r\n errorName = error;\r\n config =\r\n individualMessageStore.get(error) ?? globalMessageStore.get(error) ?? null;\r\n if (!config) {\r\n console.error(`emessages: Error \"${error}\" not found.`);\r\n return;\r\n }\r\n } else if (typeof error === \"object\" && error !== null) {\r\n const parsed = parseConfig(error);\r\n if (parsed) {\r\n errorName = parsed.name;\r\n config = parsed.options;\r\n } else {\r\n console.error(\"emessages: Invalid object passed to showE.\");\r\n return;\r\n }\r\n } else {\r\n console.error(\"emessages: Invalid argument passed to showE.\");\r\n return;\r\n }\r\n\r\n if (config && errorName) {\r\n return processEmessage(errorName, config);\r\n }\r\n}\r\n","import type { StoredEmessage } from \"./types\";\r\n\r\nexport const individualMessageStore = new Map<string, StoredEmessage>();\r\nexport const globalMessageStore = new Map<string, StoredEmessage>();\r\n","import { ToastConfig, MessageType } from \"./types\";\r\n\r\nexport function isBrowser(): boolean {\r\n return typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\r\n}\r\n\r\n\r\n/**\r\n * Removes a toast element from the DOM with a fade-out transition.\r\n * @param toastElement The toast element to remove.\r\n */\r\nfunction removeToastElement(toastElement: HTMLElement | null) {\r\n if (!toastElement || !toastElement.parentElement) return;\r\n\r\n toastElement.classList.remove(\"visible\");\r\n // Remove the element after the transition ends to allow for animation\r\n toastElement.addEventListener(\"transitionend\", () => {\r\n const container = toastElement.parentElement;\r\n if (container) {\r\n container.removeChild(toastElement);\r\n // If the container is now empty, remove it from the DOM\r\n if (container.childElementCount === 0 && container.parentElement) {\r\n container.parentElement.removeChild(container);\r\n }\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Initializes the global API for emessages, like window.emessages.closeToast\r\n */\r\nfunction initializeGlobalApi() {\r\n if (!isBrowser()) return;\r\n\r\n // Ensure the global namespace exists\r\n if (!(window as any).emessages) {\r\n (window as any).emessages = {};\r\n }\r\n\r\n // Attach the closeToast function if it doesn't exist\r\n if (!(window as any).emessages.closeToast) {\r\n (window as any).emessages.closeToast = function (eventOrId: Event | string) {\r\n let toastElement: HTMLElement | null = null;\r\n\r\n if (typeof eventOrId === 'string') {\r\n // Find toast by ID\r\n toastElement = document.getElementById(eventOrId);\r\n } else if (eventOrId && eventOrId.target) {\r\n // Find toast by traversing from the event target\r\n toastElement = (eventOrId.target as HTMLElement).closest('.emessage-toast');\r\n }\r\n\r\n if (toastElement) {\r\n removeToastElement(toastElement);\r\n } else {\r\n console.warn('emessages: closeToast() was called but could not find a toast element to close.');\r\n }\r\n };\r\n }\r\n}\r\n\r\n// Initialize the global API when the module is loaded\r\ninitializeGlobalApi();\r\n\r\n\r\n// Function to inject CSS for toasts\r\nfunction injectToastStyles() {\r\n if (!isBrowser()) return;\r\n\r\n const styleId = \"emessages-toast-styles\";\r\n if (document.getElementById(styleId)) {\r\n return; // Styles already injected\r\n }\r\n\r\n const style = document.createElement(\"style\");\r\n style.id = styleId;\r\n style.innerHTML = `\r\n .emessages-toast-container {\r\n position: fixed;\r\n display: flex;\r\n flex-direction: column;\r\n padding: 10px;\r\n pointer-events: none;\r\n z-index: 9999;\r\n box-sizing: border-box;\r\n }\r\n\r\n /* Positioning for containers */\r\n .emessages-toast-container.top-left { top: 0; left: 0; align-items: flex-start; }\r\n .emessages-toast-container.top-center { top: 0; left: 50%; transform: translateX(-50%); align-items: center; }\r\n .emessages-toast-container.top-right { top: 0; right: 0; align-items: flex-end; }\r\n .emessages-toast-container.bottom-left { bottom: 0; left: 0; align-items: flex-start; }\r\n .emessages-toast-container.bottom-center { bottom: 0; left: 50%; transform: translateX(-50%); align-items: center; }\r\n .emessages-toast-container.bottom-right { bottom: 0; right: 0; align-items: flex-end; }\r\n .emessages-toast-container.center { top: 50%; left: 50%; transform: translate(-50%, -50%); align-items: center; }\r\n .emessages-toast-container.center-left { top: 50%; left: 0; transform: translateY(-50%); align-items: flex-start; }\r\n .emessages-toast-container.center-right { top: 50%; right: 0; transform: translateY(-50%); align-items: flex-end; }\r\n\r\n\r\n .emessage-toast {\r\n padding: 12px 18px;\r\n margin: 8px;\r\n border-radius: 6px;\r\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";\r\n font-size: 14px;\r\n opacity: 0;\r\n transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;\r\n transform: translateY(20px);\r\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\r\n pointer-events: all;\r\n max-width: 350px;\r\n word-break: break-word;\r\n display: flex;\r\n justify-content: space-between;\r\n align-items: center;\r\n gap: 10px;\r\n box-sizing: border-box;\r\n }\r\n\r\n .emessage-toast.visible {\r\n opacity: 1;\r\n transform: translateY(0);\r\n }\r\n\r\n /* Default styles based on message type */\r\n .emessage-toast-err { background-color: #ef4444; color: white; } /* red-500 */\r\n .emessage-toast-war { background-color: #f59e0b; color: white; } /* amber-500 */\r\n .emessage-toast-log { background-color: #ffffff; color: #1f2937; border: 1px solid #e5e7eb; } /* white, gray-800 text, gray-200 border */\r\n\r\n .emessage-toast-message {\r\n flex-grow: 1;\r\n }\r\n\r\n .emessage-toast-close {\r\n background: none;\r\n border: none;\r\n color: inherit;\r\n font-size: 20px;\r\n font-weight: bold;\r\n cursor: pointer;\r\n line-height: 1;\r\n opacity: 0.7;\r\n padding: 0;\r\n margin-left: 15px;\r\n }\r\n .emessage-toast-close:hover {\r\n opacity: 1;\r\n }\r\n .emessage-toast-close:focus,\r\n .emessage-toast-close:focus-visible {\r\n outline: none;\r\n }\r\n `;\r\n // Prepend styles to give user stylesheets higher priority\r\n document.head.insertBefore(style, document.head.firstChild);\r\n}\r\n\r\n// Function to get or create a specific toast container for a position\r\nfunction getOrCreateToastContainer(position: string): HTMLElement {\r\n // Normalize position string to handle variants like \"top\" -> \"top-center\"\r\n const positionMap: Record<string, string> = {\r\n top: \"top-center\",\r\n bottom: \"bottom-center\",\r\n left: \"center-left\",\r\n right: \"center-right\",\r\n center: \"center\",\r\n \"top-right\": \"top-right\",\r\n \"top-left\": \"top-left\",\r\n \"top-center\": \"top-center\",\r\n \"bottom-right\": \"bottom-right\",\r\n \"bottom-left\": \"bottom-left\",\r\n \"bottom-center\": \"bottom-center\",\r\n \"center-left\": \"center-left\",\r\n \"center-right\": \"center-right\",\r\n };\r\n\r\n const normalizedPosition = positionMap[position.toLowerCase().replace(/\\s/g, \"-\")] || \"top-right\";\r\n const containerId = `emessages-toast-container-${normalizedPosition}`;\r\n let container = document.getElementById(containerId);\r\n\r\n if (!container) {\r\n container = document.createElement(\"div\");\r\n container.id = containerId;\r\n container.className = `emessages-toast-container ${normalizedPosition}`;\r\n document.body.appendChild(container);\r\n }\r\n return container;\r\n}\r\n\r\n\r\nexport function showToast(\r\n message: string,\r\n toastOptions: boolean | ToastConfig,\r\n messageType: MessageType = \"log\"\r\n): void {\r\n if (!isBrowser()) {\r\n return;\r\n }\r\n\r\n injectToastStyles();\r\n\r\n const config: ToastConfig = typeof toastOptions === \"object\" ? toastOptions : {};\r\n\r\n let {\r\n message: customMessage,\r\n style: customStyle,\r\n class: customClass,\r\n position = \"top-right\",\r\n stay = false,\r\n duration = 3000,\r\n delay = 0,\r\n } = config;\r\n \r\n const toast = document.createElement(\"div\");\r\n // Assign a unique ID for programmatic closing\r\n toast.id = `emessage-toast-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\r\n \r\n // Base class is applied first\r\n let toastClasses = ['emessage-toast'];\r\n \r\n // Add default type class. We use a separate class to avoid specificity conflicts.\r\n toastClasses.push(`emessage-toast-${messageType}`);\r\n \r\n // Add custom classes. These can now override the default type styles if they have the same specificity.\r\n if (customClass) {\r\n toastClasses.push(...customClass.split(' ').filter(c => c));\r\n }\r\n \r\n toast.className = toastClasses.join(' ');\r\n \r\n // Apply custom inline style from config (highest priority)\r\n if (customStyle) {\r\n toast.style.cssText += customStyle;\r\n }\r\n \r\n // Create a dedicated element for the message to avoid conflicts with the close button\r\n const messageElement = document.createElement('div');\r\n messageElement.className = 'emessage-toast-message';\r\n \r\n // Check if customMessage is a React element or other object, which is invalid.\r\n if (typeof customMessage === 'object' && customMessage !== null) {\r\n console.warn('emessages: The `toast.message` property received an object (likely a React component), but it only accepts an HTML string. Please pass a string of HTML to render it correctly. Falling back to the default message.');\r\n customMessage = undefined; // Use the default message instead\r\n }\r\n \r\n messageElement.innerHTML = customMessage || message;\r\n toast.appendChild(messageElement);\r\n \r\n \r\n // Add close button (always add for accessibility, but control removal logic)\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.className = \"emessage-toast-close\";\r\n closeButton.innerHTML = \"×\";\r\n closeButton.setAttribute(\"aria-label\", \"Close\");\r\n closeButton.onclick = () => removeToastElement(toast);\r\n toast.appendChild(closeButton);\r\n \r\n const container = getOrCreateToastContainer(position);\r\n \r\n // Delay the appearance of the toast\r\n setTimeout(() => {\r\n // For bottom-positioned toasts, insert at the top of the container\r\n if (position.includes('bottom')) {\r\n container.prepend(toast);\r\n } else {\r\n container.appendChild(toast);\r\n }\r\n \r\n // Allow the element to be in the DOM before transitioning\r\n requestAnimationFrame(() => {\r\n toast.classList.add(\"visible\");\r\n });\r\n }, delay);\r\n \r\n // Set up auto-hide if not staying\r\n if (!stay) {\r\n const hideTimeout = setTimeout(() => removeToastElement(toast), delay + duration);\r\n // Optional: pause on hover\r\n toast.addEventListener('mouseenter', () => clearTimeout(hideTimeout));\r\n toast.addEventListener('mouseleave', () => {\r\n if (!stay) {\r\n setTimeout(() => removeToastElement(toast), 1000); // Give some time before hiding on mouse leave\r\n }\r\n });\r\n }}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,yBAAyB,oBAAI,IAA4B;AAC/D,IAAM,qBAAqB,oBAAI,IAA4B;;;ACD3D,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AACrE;AAOA,SAAS,mBAAmB,cAAkC;AAC5D,MAAI,CAAC,gBAAgB,CAAC,aAAa,cAAe;AAElD,eAAa,UAAU,OAAO,SAAS;AAEvC,eAAa,iBAAiB,iBAAiB,MAAM;AACnD,UAAM,YAAY,aAAa;AAC/B,QAAI,WAAW;AACb,gBAAU,YAAY,YAAY;AAElC,UAAI,UAAU,sBAAsB,KAAK,UAAU,eAAe;AAChE,kBAAU,cAAc,YAAY,SAAS;AAAA,MAC/C;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAKA,SAAS,sBAAsB;AAC7B,MAAI,CAAC,UAAU,EAAG;AAGlB,MAAI,CAAE,OAAe,WAAW;AAC9B,IAAC,OAAe,YAAY,CAAC;AAA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
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
type MessageType = "log" | "war" | "err";
|
|
1
|
+
type MessageType = "log" | "war" | "err" | boolean;
|
|
2
2
|
interface ToastConfig {
|
|
3
|
-
style?: string;
|
|
4
3
|
message?: string;
|
|
5
|
-
|
|
4
|
+
style?: string;
|
|
5
|
+
class?: string;
|
|
6
|
+
position?: "top" | "bottom" | "left" | "right" | "center" | "top-right" | "top-left" | "top-center" | "bottom-right" | "bottom-left" | "bottom-center" | "center-left" | "center-right";
|
|
7
|
+
stay?: boolean;
|
|
8
|
+
duration?: number;
|
|
9
|
+
delay?: number;
|
|
6
10
|
}
|
|
7
11
|
interface EmessageOptions {
|
|
8
|
-
type?: MessageType
|
|
12
|
+
type?: MessageType;
|
|
9
13
|
break?: boolean;
|
|
10
14
|
toast?: boolean | ToastConfig;
|
|
11
15
|
returnEM?: boolean;
|
|
12
|
-
callBack?: (
|
|
16
|
+
callBack?: () => void;
|
|
17
|
+
}
|
|
18
|
+
interface EmessageConfig extends EmessageOptions {
|
|
19
|
+
[key: string]: string | MessageType | boolean | (() => void) | ToastConfig | undefined;
|
|
13
20
|
}
|
|
14
|
-
type EmessageConfig = EmessageOptions & {
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
};
|
|
17
21
|
|
|
18
22
|
declare function Emessage(...configs: EmessageConfig[]): void;
|
|
19
23
|
declare namespace Emessage {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
type MessageType = "log" | "war" | "err";
|
|
1
|
+
type MessageType = "log" | "war" | "err" | boolean;
|
|
2
2
|
interface ToastConfig {
|
|
3
|
-
style?: string;
|
|
4
3
|
message?: string;
|
|
5
|
-
|
|
4
|
+
style?: string;
|
|
5
|
+
class?: string;
|
|
6
|
+
position?: "top" | "bottom" | "left" | "right" | "center" | "top-right" | "top-left" | "top-center" | "bottom-right" | "bottom-left" | "bottom-center" | "center-left" | "center-right";
|
|
7
|
+
stay?: boolean;
|
|
8
|
+
duration?: number;
|
|
9
|
+
delay?: number;
|
|
6
10
|
}
|
|
7
11
|
interface EmessageOptions {
|
|
8
|
-
type?: MessageType
|
|
12
|
+
type?: MessageType;
|
|
9
13
|
break?: boolean;
|
|
10
14
|
toast?: boolean | ToastConfig;
|
|
11
15
|
returnEM?: boolean;
|
|
12
|
-
callBack?: (
|
|
16
|
+
callBack?: () => void;
|
|
17
|
+
}
|
|
18
|
+
interface EmessageConfig extends EmessageOptions {
|
|
19
|
+
[key: string]: string | MessageType | boolean | (() => void) | ToastConfig | undefined;
|
|
13
20
|
}
|
|
14
|
-
type EmessageConfig = EmessageOptions & {
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
};
|
|
17
21
|
|
|
18
22
|
declare function Emessage(...configs: EmessageConfig[]): void;
|
|
19
23
|
declare namespace Emessage {
|
package/dist/index.mjs
CHANGED
|
@@ -6,31 +6,215 @@ var globalMessageStore = /* @__PURE__ */ new Map();
|
|
|
6
6
|
function isBrowser() {
|
|
7
7
|
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function removeToastElement(toastElement) {
|
|
10
|
+
if (!toastElement || !toastElement.parentElement) return;
|
|
11
|
+
toastElement.classList.remove("visible");
|
|
12
|
+
toastElement.addEventListener("transitionend", () => {
|
|
13
|
+
const container = toastElement.parentElement;
|
|
14
|
+
if (container) {
|
|
15
|
+
container.removeChild(toastElement);
|
|
16
|
+
if (container.childElementCount === 0 && container.parentElement) {
|
|
17
|
+
container.parentElement.removeChild(container);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function initializeGlobalApi() {
|
|
23
|
+
if (!isBrowser()) return;
|
|
24
|
+
if (!window.emessages) {
|
|
25
|
+
window.emessages = {};
|
|
26
|
+
}
|
|
27
|
+
if (!window.emessages.closeToast) {
|
|
28
|
+
window.emessages.closeToast = function(eventOrId) {
|
|
29
|
+
let toastElement = null;
|
|
30
|
+
if (typeof eventOrId === "string") {
|
|
31
|
+
toastElement = document.getElementById(eventOrId);
|
|
32
|
+
} else if (eventOrId && eventOrId.target) {
|
|
33
|
+
toastElement = eventOrId.target.closest(".emessage-toast");
|
|
34
|
+
}
|
|
35
|
+
if (toastElement) {
|
|
36
|
+
removeToastElement(toastElement);
|
|
37
|
+
} else {
|
|
38
|
+
console.warn("emessages: closeToast() was called but could not find a toast element to close.");
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
initializeGlobalApi();
|
|
44
|
+
function injectToastStyles() {
|
|
45
|
+
if (!isBrowser()) return;
|
|
46
|
+
const styleId = "emessages-toast-styles";
|
|
47
|
+
if (document.getElementById(styleId)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const style = document.createElement("style");
|
|
51
|
+
style.id = styleId;
|
|
52
|
+
style.innerHTML = `
|
|
53
|
+
.emessages-toast-container {
|
|
54
|
+
position: fixed;
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-direction: column;
|
|
57
|
+
padding: 10px;
|
|
58
|
+
pointer-events: none;
|
|
59
|
+
z-index: 9999;
|
|
60
|
+
box-sizing: border-box;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* Positioning for containers */
|
|
64
|
+
.emessages-toast-container.top-left { top: 0; left: 0; align-items: flex-start; }
|
|
65
|
+
.emessages-toast-container.top-center { top: 0; left: 50%; transform: translateX(-50%); align-items: center; }
|
|
66
|
+
.emessages-toast-container.top-right { top: 0; right: 0; align-items: flex-end; }
|
|
67
|
+
.emessages-toast-container.bottom-left { bottom: 0; left: 0; align-items: flex-start; }
|
|
68
|
+
.emessages-toast-container.bottom-center { bottom: 0; left: 50%; transform: translateX(-50%); align-items: center; }
|
|
69
|
+
.emessages-toast-container.bottom-right { bottom: 0; right: 0; align-items: flex-end; }
|
|
70
|
+
.emessages-toast-container.center { top: 50%; left: 50%; transform: translate(-50%, -50%); align-items: center; }
|
|
71
|
+
.emessages-toast-container.center-left { top: 50%; left: 0; transform: translateY(-50%); align-items: flex-start; }
|
|
72
|
+
.emessages-toast-container.center-right { top: 50%; right: 0; transform: translateY(-50%); align-items: flex-end; }
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
.emessage-toast {
|
|
76
|
+
padding: 12px 18px;
|
|
77
|
+
margin: 8px;
|
|
78
|
+
border-radius: 6px;
|
|
79
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
|
80
|
+
font-size: 14px;
|
|
81
|
+
opacity: 0;
|
|
82
|
+
transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
|
|
83
|
+
transform: translateY(20px);
|
|
84
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
85
|
+
pointer-events: all;
|
|
86
|
+
max-width: 350px;
|
|
87
|
+
word-break: break-word;
|
|
88
|
+
display: flex;
|
|
89
|
+
justify-content: space-between;
|
|
90
|
+
align-items: center;
|
|
91
|
+
gap: 10px;
|
|
92
|
+
box-sizing: border-box;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.emessage-toast.visible {
|
|
96
|
+
opacity: 1;
|
|
97
|
+
transform: translateY(0);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* Default styles based on message type */
|
|
101
|
+
.emessage-toast-err { background-color: #ef4444; color: white; } /* red-500 */
|
|
102
|
+
.emessage-toast-war { background-color: #f59e0b; color: white; } /* amber-500 */
|
|
103
|
+
.emessage-toast-log { background-color: #ffffff; color: #1f2937; border: 1px solid #e5e7eb; } /* white, gray-800 text, gray-200 border */
|
|
104
|
+
|
|
105
|
+
.emessage-toast-message {
|
|
106
|
+
flex-grow: 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.emessage-toast-close {
|
|
110
|
+
background: none;
|
|
111
|
+
border: none;
|
|
112
|
+
color: inherit;
|
|
113
|
+
font-size: 20px;
|
|
114
|
+
font-weight: bold;
|
|
115
|
+
cursor: pointer;
|
|
116
|
+
line-height: 1;
|
|
117
|
+
opacity: 0.7;
|
|
118
|
+
padding: 0;
|
|
119
|
+
margin-left: 15px;
|
|
120
|
+
}
|
|
121
|
+
.emessage-toast-close:hover {
|
|
122
|
+
opacity: 1;
|
|
123
|
+
}
|
|
124
|
+
.emessage-toast-close:focus,
|
|
125
|
+
.emessage-toast-close:focus-visible {
|
|
126
|
+
outline: none;
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
document.head.insertBefore(style, document.head.firstChild);
|
|
130
|
+
}
|
|
131
|
+
function getOrCreateToastContainer(position) {
|
|
132
|
+
const positionMap = {
|
|
133
|
+
top: "top-center",
|
|
134
|
+
bottom: "bottom-center",
|
|
135
|
+
left: "center-left",
|
|
136
|
+
right: "center-right",
|
|
137
|
+
center: "center",
|
|
138
|
+
"top-right": "top-right",
|
|
139
|
+
"top-left": "top-left",
|
|
140
|
+
"top-center": "top-center",
|
|
141
|
+
"bottom-right": "bottom-right",
|
|
142
|
+
"bottom-left": "bottom-left",
|
|
143
|
+
"bottom-center": "bottom-center",
|
|
144
|
+
"center-left": "center-left",
|
|
145
|
+
"center-right": "center-right"
|
|
146
|
+
};
|
|
147
|
+
const normalizedPosition = positionMap[position.toLowerCase().replace(/\s/g, "-")] || "top-right";
|
|
148
|
+
const containerId = `emessages-toast-container-${normalizedPosition}`;
|
|
149
|
+
let container = document.getElementById(containerId);
|
|
150
|
+
if (!container) {
|
|
151
|
+
container = document.createElement("div");
|
|
152
|
+
container.id = containerId;
|
|
153
|
+
container.className = `emessages-toast-container ${normalizedPosition}`;
|
|
154
|
+
document.body.appendChild(container);
|
|
155
|
+
}
|
|
156
|
+
return container;
|
|
157
|
+
}
|
|
158
|
+
function showToast(message, toastOptions, messageType = "log") {
|
|
10
159
|
if (!isBrowser()) {
|
|
11
160
|
return;
|
|
12
161
|
}
|
|
162
|
+
injectToastStyles();
|
|
163
|
+
const config = typeof toastOptions === "object" ? toastOptions : {};
|
|
164
|
+
let {
|
|
165
|
+
message: customMessage,
|
|
166
|
+
style: customStyle,
|
|
167
|
+
class: customClass,
|
|
168
|
+
position = "top-right",
|
|
169
|
+
stay = false,
|
|
170
|
+
duration = 3e3,
|
|
171
|
+
delay = 0
|
|
172
|
+
} = config;
|
|
13
173
|
const toast = document.createElement("div");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
174
|
+
toast.id = `emessage-toast-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
175
|
+
let toastClasses = ["emessage-toast"];
|
|
176
|
+
toastClasses.push(`emessage-toast-${messageType}`);
|
|
177
|
+
if (customClass) {
|
|
178
|
+
toastClasses.push(...customClass.split(" ").filter((c) => c));
|
|
179
|
+
}
|
|
180
|
+
toast.className = toastClasses.join(" ");
|
|
181
|
+
if (customStyle) {
|
|
182
|
+
toast.style.cssText += customStyle;
|
|
183
|
+
}
|
|
184
|
+
const messageElement = document.createElement("div");
|
|
185
|
+
messageElement.className = "emessage-toast-message";
|
|
186
|
+
if (typeof customMessage === "object" && customMessage !== null) {
|
|
187
|
+
console.warn("emessages: The `toast.message` property received an object (likely a React component), but it only accepts an HTML string. Please pass a string of HTML to render it correctly. Falling back to the default message.");
|
|
188
|
+
customMessage = void 0;
|
|
189
|
+
}
|
|
190
|
+
messageElement.innerHTML = customMessage || message;
|
|
191
|
+
toast.appendChild(messageElement);
|
|
192
|
+
const closeButton = document.createElement("button");
|
|
193
|
+
closeButton.className = "emessage-toast-close";
|
|
194
|
+
closeButton.innerHTML = "×";
|
|
195
|
+
closeButton.setAttribute("aria-label", "Close");
|
|
196
|
+
closeButton.onclick = () => removeToastElement(toast);
|
|
197
|
+
toast.appendChild(closeButton);
|
|
198
|
+
const container = getOrCreateToastContainer(position);
|
|
26
199
|
setTimeout(() => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
200
|
+
if (position.includes("bottom")) {
|
|
201
|
+
container.prepend(toast);
|
|
202
|
+
} else {
|
|
203
|
+
container.appendChild(toast);
|
|
204
|
+
}
|
|
205
|
+
requestAnimationFrame(() => {
|
|
206
|
+
toast.classList.add("visible");
|
|
207
|
+
});
|
|
208
|
+
}, delay);
|
|
209
|
+
if (!stay) {
|
|
210
|
+
const hideTimeout = setTimeout(() => removeToastElement(toast), delay + duration);
|
|
211
|
+
toast.addEventListener("mouseenter", () => clearTimeout(hideTimeout));
|
|
212
|
+
toast.addEventListener("mouseleave", () => {
|
|
213
|
+
if (!stay) {
|
|
214
|
+
setTimeout(() => removeToastElement(toast), 1e3);
|
|
31
215
|
}
|
|
32
216
|
});
|
|
33
|
-
}
|
|
217
|
+
}
|
|
34
218
|
}
|
|
35
219
|
|
|
36
220
|
// src/index.ts
|
|
@@ -102,7 +286,7 @@ function processEmessage(errorName, config) {
|
|
|
102
286
|
}
|
|
103
287
|
}
|
|
104
288
|
if (config.toast && isBrowser()) {
|
|
105
|
-
showToast(message, config.toast);
|
|
289
|
+
showToast(message, config.toast, consoleType);
|
|
106
290
|
}
|
|
107
291
|
if (config.callBack) {
|
|
108
292
|
try {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { StoredEmessage } from \"./types\";\r\n\r\nexport const individualMessageStore = new Map<string, StoredEmessage>();\r\nexport const globalMessageStore = new Map<string, StoredEmessage>();\r\n","import { ToastConfig } from \"./types\";\r\n\r\nexport function isBrowser(): boolean {\r\n return typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\r\n}\r\n\r\nexport function showToast(\r\n message: string,\r\n toastConfig: boolean | ToastConfig\r\n): void {\r\n if (!isBrowser()) {\r\n return;\r\n }\r\n\r\n const toast = document.createElement(\"div\");\r\n\r\n const config: ToastConfig = typeof toastConfig === \"object\" ? toastConfig : {};\r\n\r\n toast.textContent = config.message || message;\r\n\r\n // Base styles are applied via CSS, but some can be defaults.\r\n toast.className = \"emessage-toast\";\r\n if (config.style) {\r\n toast.classList.add(...config.style.split(\" \"));\r\n }\r\n\r\n // Positioning\r\n const position = config.position || \"top-right\";\r\n toast.setAttribute(\"data-position\", position);\r\n\r\n document.body.appendChild(toast);\r\n\r\n // Animate in\r\n setTimeout(() => {\r\n toast.classList.add(\"visible\");\r\n }, 10);\r\n\r\n // Animate out and remove\r\n setTimeout(() => {\r\n toast.classList.remove(\"visible\");\r\n toast.addEventListener(\"transitionend\", () => {\r\n if (toast.parentElement) {\r\n toast.parentElement.removeChild(toast);\r\n }\r\n });\r\n }, 3000);\r\n}\r\n","import { individualMessageStore, globalMessageStore } from \"./store\";\r\nimport type {\r\n EmessageConfig,\r\n EmessageOptions,\r\n StoredEmessage,\r\n ToastConfig,\r\n MessageType,\r\n} from \"./types\";\r\nimport { isBrowser, showToast } from \"./utils\";\r\n\r\nfunction parseConfig(\r\n config: Record<string, any>\r\n): { name: string; options: StoredEmessage } | null {\r\n const options: EmessageOptions = {};\r\n let message: string | null = null;\r\n let name: string | null = null;\r\n const optionKeys = [\"type\", \"break\", \"toast\", \"returnEM\", \"callBack\"];\r\n\r\n for (const key in config) {\r\n if (Object.prototype.hasOwnProperty.call(config, key)) {\r\n if (optionKeys.includes(key)) {\r\n (options as any)[key] = config[key];\r\n } else {\r\n if (name !== null) {\r\n console.warn(\r\n `emessages: Found multiple potential error names in one config object. Using first one found: \"${name}\".`\r\n );\r\n continue;\r\n }\r\n name = key;\r\n message = String(config[key]);\r\n }\r\n }\r\n }\r\n\r\n if (name === null || message === null) {\r\n console.error(\r\n \"emessages: Invalid config object. Could not find error name and message.\",\r\n config\r\n );\r\n return null;\r\n }\r\n\r\n return { name, options: { ...options, message } };\r\n}\r\n\r\nfunction processEmessage(\r\n errorName: string,\r\n config: StoredEmessage\r\n): string | void {\r\n const message = config.message;\r\n\r\n let consoleType: MessageType | false;\r\n if (config.type === false) {\r\n consoleType = false;\r\n } else if (config.type === true || config.type === undefined) {\r\n consoleType = \"err\";\r\n } else {\r\n consoleType = config.type;\r\n }\r\n\r\n // 1. Console log\r\n if (consoleType) {\r\n if (isBrowser()) {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(message);\r\n break;\r\n case \"war\":\r\n console.warn(message);\r\n break;\r\n case \"err\":\r\n console.error(message);\r\n break;\r\n }\r\n } else {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(`\\x1b[30;47m ${message} \\x1b[0m`);\r\n break;\r\n case \"war\":\r\n console.warn(`\\x1b[37;43m ${message} \\x1b[0m`);\r\n break;\r\n case \"err\":\r\n console.error(`\\x1b[37;41m ${message} \\x1b[0m`);\r\n break;\r\n }\r\n }\r\n }\r\n\r\n // 2. Toast notification\r\n if (config.toast && isBrowser()) {\r\n showToast(message, config.toast);\r\n }\r\n\r\n // 3. Callback\r\n if (config.callBack) {\r\n try {\r\n config.callBack();\r\n } catch (e: any) {\r\n console.error(\r\n `emessages: Error in callBack for \"${errorName}\":`,\r\n e.message\r\n );\r\n }\r\n }\r\n\r\n // 4. Return error message\r\n if (config.returnEM) {\r\n return message;\r\n }\r\n\r\n // 5. Break execution\r\n if (config.break ?? true) {\r\n if (isBrowser()) {\r\n throw new Error(message);\r\n } else {\r\n process.exit(1);\r\n }\r\n }\r\n}\r\n\r\nexport function Emessage(...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n individualMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n}\r\n\r\nEmessage.global = function (...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n globalMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n};\r\n\r\nexport function showE(error: string | Record<string, any>): string | void {\r\n let config: StoredEmessage | null = null;\r\n let errorName: string | null = null;\r\n\r\n if (typeof error === \"string\") {\r\n errorName = error;\r\n config =\r\n individualMessageStore.get(error) ?? globalMessageStore.get(error) ?? null;\r\n if (!config) {\r\n console.error(`emessages: Error \"${error}\" not found.`);\r\n return;\r\n }\r\n } else if (typeof error === \"object\" && error !== null) {\r\n const parsed = parseConfig(error);\r\n if (parsed) {\r\n errorName = parsed.name;\r\n config = parsed.options;\r\n } else {\r\n console.error(\"emessages: Invalid object passed to showE.\");\r\n return;\r\n }\r\n } else {\r\n console.error(\"emessages: Invalid argument passed to showE.\");\r\n return;\r\n }\r\n\r\n if (config && errorName) {\r\n return processEmessage(errorName, config);\r\n }\r\n}\r\n"],"mappings":";AAEO,IAAM,yBAAyB,oBAAI,IAA4B;AAC/D,IAAM,qBAAqB,oBAAI,IAA4B;;;ACD3D,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AACrE;AAEO,SAAS,UACd,SACA,aACM;AACN,MAAI,CAAC,UAAU,GAAG;AAChB;AAAA,EACF;AAEA,QAAM,QAAQ,SAAS,cAAc,KAAK;AAE1C,QAAM,SAAsB,OAAO,gBAAgB,WAAW,cAAc,CAAC;AAE7E,QAAM,cAAc,OAAO,WAAW;AAGtC,QAAM,YAAY;AAClB,MAAI,OAAO,OAAO;AAChB,UAAM,UAAU,IAAI,GAAG,OAAO,MAAM,MAAM,GAAG,CAAC;AAAA,EAChD;AAGA,QAAM,WAAW,OAAO,YAAY;AACpC,QAAM,aAAa,iBAAiB,QAAQ;AAE5C,WAAS,KAAK,YAAY,KAAK;AAG/B,aAAW,MAAM;AACf,UAAM,UAAU,IAAI,SAAS;AAAA,EAC/B,GAAG,EAAE;AAGL,aAAW,MAAM;AACf,UAAM,UAAU,OAAO,SAAS;AAChC,UAAM,iBAAiB,iBAAiB,MAAM;A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,QAAQ;AACX,cAAQ,MAAM,qBAAqB,KAAK,cAAc;AACtD;AAAA,IACF;AAAA,EACF,WAAW,OAAO,UAAU,YAAY,UAAU,MAAM;AACtD,UAAM,SAAS,YAAY,KAAK;AAChC,QAAI,QAAQ;AACV,kBAAY,OAAO;AACnB,eAAS,OAAO;AAAA,IAClB,OAAO;AACL,cAAQ,MAAM,4CAA4C;AAC1D;AAAA,IACF;AAAA,EACF,OAAO;AACL,YAAQ,MAAM,8CAA8C;AAC5D;AAAA,EACF;AAEA,MAAI,UAAU,WAAW;AACvB,WAAO,gBAAgB,WAAW,MAAM;AAAA,EAC1C;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/store.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { StoredEmessage } from \"./types\";\r\n\r\nexport const individualMessageStore = new Map<string, StoredEmessage>();\r\nexport const globalMessageStore = new Map<string, StoredEmessage>();\r\n","import { ToastConfig, MessageType } from \"./types\";\r\n\r\nexport function isBrowser(): boolean {\r\n return typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\r\n}\r\n\r\n\r\n/**\r\n * Removes a toast element from the DOM with a fade-out transition.\r\n * @param toastElement The toast element to remove.\r\n */\r\nfunction removeToastElement(toastElement: HTMLElement | null) {\r\n if (!toastElement || !toastElement.parentElement) return;\r\n\r\n toastElement.classList.remove(\"visible\");\r\n // Remove the element after the transition ends to allow for animation\r\n toastElement.addEventListener(\"transitionend\", () => {\r\n const container = toastElement.parentElement;\r\n if (container) {\r\n container.removeChild(toastElement);\r\n // If the container is now empty, remove it from the DOM\r\n if (container.childElementCount === 0 && container.parentElement) {\r\n container.parentElement.removeChild(container);\r\n }\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Initializes the global API for emessages, like window.emessages.closeToast\r\n */\r\nfunction initializeGlobalApi() {\r\n if (!isBrowser()) return;\r\n\r\n // Ensure the global namespace exists\r\n if (!(window as any).emessages) {\r\n (window as any).emessages = {};\r\n }\r\n\r\n // Attach the closeToast function if it doesn't exist\r\n if (!(window as any).emessages.closeToast) {\r\n (window as any).emessages.closeToast = function (eventOrId: Event | string) {\r\n let toastElement: HTMLElement | null = null;\r\n\r\n if (typeof eventOrId === 'string') {\r\n // Find toast by ID\r\n toastElement = document.getElementById(eventOrId);\r\n } else if (eventOrId && eventOrId.target) {\r\n // Find toast by traversing from the event target\r\n toastElement = (eventOrId.target as HTMLElement).closest('.emessage-toast');\r\n }\r\n\r\n if (toastElement) {\r\n removeToastElement(toastElement);\r\n } else {\r\n console.warn('emessages: closeToast() was called but could not find a toast element to close.');\r\n }\r\n };\r\n }\r\n}\r\n\r\n// Initialize the global API when the module is loaded\r\ninitializeGlobalApi();\r\n\r\n\r\n// Function to inject CSS for toasts\r\nfunction injectToastStyles() {\r\n if (!isBrowser()) return;\r\n\r\n const styleId = \"emessages-toast-styles\";\r\n if (document.getElementById(styleId)) {\r\n return; // Styles already injected\r\n }\r\n\r\n const style = document.createElement(\"style\");\r\n style.id = styleId;\r\n style.innerHTML = `\r\n .emessages-toast-container {\r\n position: fixed;\r\n display: flex;\r\n flex-direction: column;\r\n padding: 10px;\r\n pointer-events: none;\r\n z-index: 9999;\r\n box-sizing: border-box;\r\n }\r\n\r\n /* Positioning for containers */\r\n .emessages-toast-container.top-left { top: 0; left: 0; align-items: flex-start; }\r\n .emessages-toast-container.top-center { top: 0; left: 50%; transform: translateX(-50%); align-items: center; }\r\n .emessages-toast-container.top-right { top: 0; right: 0; align-items: flex-end; }\r\n .emessages-toast-container.bottom-left { bottom: 0; left: 0; align-items: flex-start; }\r\n .emessages-toast-container.bottom-center { bottom: 0; left: 50%; transform: translateX(-50%); align-items: center; }\r\n .emessages-toast-container.bottom-right { bottom: 0; right: 0; align-items: flex-end; }\r\n .emessages-toast-container.center { top: 50%; left: 50%; transform: translate(-50%, -50%); align-items: center; }\r\n .emessages-toast-container.center-left { top: 50%; left: 0; transform: translateY(-50%); align-items: flex-start; }\r\n .emessages-toast-container.center-right { top: 50%; right: 0; transform: translateY(-50%); align-items: flex-end; }\r\n\r\n\r\n .emessage-toast {\r\n padding: 12px 18px;\r\n margin: 8px;\r\n border-radius: 6px;\r\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";\r\n font-size: 14px;\r\n opacity: 0;\r\n transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;\r\n transform: translateY(20px);\r\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\r\n pointer-events: all;\r\n max-width: 350px;\r\n word-break: break-word;\r\n display: flex;\r\n justify-content: space-between;\r\n align-items: center;\r\n gap: 10px;\r\n box-sizing: border-box;\r\n }\r\n\r\n .emessage-toast.visible {\r\n opacity: 1;\r\n transform: translateY(0);\r\n }\r\n\r\n /* Default styles based on message type */\r\n .emessage-toast-err { background-color: #ef4444; color: white; } /* red-500 */\r\n .emessage-toast-war { background-color: #f59e0b; color: white; } /* amber-500 */\r\n .emessage-toast-log { background-color: #ffffff; color: #1f2937; border: 1px solid #e5e7eb; } /* white, gray-800 text, gray-200 border */\r\n\r\n .emessage-toast-message {\r\n flex-grow: 1;\r\n }\r\n\r\n .emessage-toast-close {\r\n background: none;\r\n border: none;\r\n color: inherit;\r\n font-size: 20px;\r\n font-weight: bold;\r\n cursor: pointer;\r\n line-height: 1;\r\n opacity: 0.7;\r\n padding: 0;\r\n margin-left: 15px;\r\n }\r\n .emessage-toast-close:hover {\r\n opacity: 1;\r\n }\r\n .emessage-toast-close:focus,\r\n .emessage-toast-close:focus-visible {\r\n outline: none;\r\n }\r\n `;\r\n // Prepend styles to give user stylesheets higher priority\r\n document.head.insertBefore(style, document.head.firstChild);\r\n}\r\n\r\n// Function to get or create a specific toast container for a position\r\nfunction getOrCreateToastContainer(position: string): HTMLElement {\r\n // Normalize position string to handle variants like \"top\" -> \"top-center\"\r\n const positionMap: Record<string, string> = {\r\n top: \"top-center\",\r\n bottom: \"bottom-center\",\r\n left: \"center-left\",\r\n right: \"center-right\",\r\n center: \"center\",\r\n \"top-right\": \"top-right\",\r\n \"top-left\": \"top-left\",\r\n \"top-center\": \"top-center\",\r\n \"bottom-right\": \"bottom-right\",\r\n \"bottom-left\": \"bottom-left\",\r\n \"bottom-center\": \"bottom-center\",\r\n \"center-left\": \"center-left\",\r\n \"center-right\": \"center-right\",\r\n };\r\n\r\n const normalizedPosition = positionMap[position.toLowerCase().replace(/\\s/g, \"-\")] || \"top-right\";\r\n const containerId = `emessages-toast-container-${normalizedPosition}`;\r\n let container = document.getElementById(containerId);\r\n\r\n if (!container) {\r\n container = document.createElement(\"div\");\r\n container.id = containerId;\r\n container.className = `emessages-toast-container ${normalizedPosition}`;\r\n document.body.appendChild(container);\r\n }\r\n return container;\r\n}\r\n\r\n\r\nexport function showToast(\r\n message: string,\r\n toastOptions: boolean | ToastConfig,\r\n messageType: MessageType = \"log\"\r\n): void {\r\n if (!isBrowser()) {\r\n return;\r\n }\r\n\r\n injectToastStyles();\r\n\r\n const config: ToastConfig = typeof toastOptions === \"object\" ? toastOptions : {};\r\n\r\n let {\r\n message: customMessage,\r\n style: customStyle,\r\n class: customClass,\r\n position = \"top-right\",\r\n stay = false,\r\n duration = 3000,\r\n delay = 0,\r\n } = config;\r\n \r\n const toast = document.createElement(\"div\");\r\n // Assign a unique ID for programmatic closing\r\n toast.id = `emessage-toast-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\r\n \r\n // Base class is applied first\r\n let toastClasses = ['emessage-toast'];\r\n \r\n // Add default type class. We use a separate class to avoid specificity conflicts.\r\n toastClasses.push(`emessage-toast-${messageType}`);\r\n \r\n // Add custom classes. These can now override the default type styles if they have the same specificity.\r\n if (customClass) {\r\n toastClasses.push(...customClass.split(' ').filter(c => c));\r\n }\r\n \r\n toast.className = toastClasses.join(' ');\r\n \r\n // Apply custom inline style from config (highest priority)\r\n if (customStyle) {\r\n toast.style.cssText += customStyle;\r\n }\r\n \r\n // Create a dedicated element for the message to avoid conflicts with the close button\r\n const messageElement = document.createElement('div');\r\n messageElement.className = 'emessage-toast-message';\r\n \r\n // Check if customMessage is a React element or other object, which is invalid.\r\n if (typeof customMessage === 'object' && customMessage !== null) {\r\n console.warn('emessages: The `toast.message` property received an object (likely a React component), but it only accepts an HTML string. Please pass a string of HTML to render it correctly. Falling back to the default message.');\r\n customMessage = undefined; // Use the default message instead\r\n }\r\n \r\n messageElement.innerHTML = customMessage || message;\r\n toast.appendChild(messageElement);\r\n \r\n \r\n // Add close button (always add for accessibility, but control removal logic)\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.className = \"emessage-toast-close\";\r\n closeButton.innerHTML = \"×\";\r\n closeButton.setAttribute(\"aria-label\", \"Close\");\r\n closeButton.onclick = () => removeToastElement(toast);\r\n toast.appendChild(closeButton);\r\n \r\n const container = getOrCreateToastContainer(position);\r\n \r\n // Delay the appearance of the toast\r\n setTimeout(() => {\r\n // For bottom-positioned toasts, insert at the top of the container\r\n if (position.includes('bottom')) {\r\n container.prepend(toast);\r\n } else {\r\n container.appendChild(toast);\r\n }\r\n \r\n // Allow the element to be in the DOM before transitioning\r\n requestAnimationFrame(() => {\r\n toast.classList.add(\"visible\");\r\n });\r\n }, delay);\r\n \r\n // Set up auto-hide if not staying\r\n if (!stay) {\r\n const hideTimeout = setTimeout(() => removeToastElement(toast), delay + duration);\r\n // Optional: pause on hover\r\n toast.addEventListener('mouseenter', () => clearTimeout(hideTimeout));\r\n toast.addEventListener('mouseleave', () => {\r\n if (!stay) {\r\n setTimeout(() => removeToastElement(toast), 1000); // Give some time before hiding on mouse leave\r\n }\r\n });\r\n }}\r\n","import { individualMessageStore, globalMessageStore } from \"./store\";\r\nimport type {\r\n EmessageConfig,\r\n EmessageOptions,\r\n StoredEmessage,\r\n ToastConfig,\r\n MessageType,\r\n} from \"./types\";\r\nimport { isBrowser, showToast } from \"./utils\";\r\n\r\nfunction parseConfig(\r\n config: Record<string, any>\r\n): { name: string; options: StoredEmessage } | null {\r\n const options: EmessageOptions = {};\r\n let message: string | null = null;\r\n let name: string | null = null;\r\n const optionKeys = [\"type\", \"break\", \"toast\", \"returnEM\", \"callBack\"];\r\n\r\n for (const key in config) {\r\n if (Object.prototype.hasOwnProperty.call(config, key)) {\r\n if (optionKeys.includes(key)) {\r\n (options as any)[key] = config[key];\r\n } else {\r\n if (name !== null) {\r\n console.warn(\r\n `emessages: Found multiple potential error names in one config object. Using first one found: \"${name}\".`\r\n );\r\n continue;\r\n }\r\n name = key;\r\n message = String(config[key]);\r\n }\r\n }\r\n }\r\n\r\n if (name === null || message === null) {\r\n console.error(\r\n \"emessages: Invalid config object. Could not find error name and message.\",\r\n config\r\n );\r\n return null;\r\n }\r\n\r\n return { name, options: { ...options, message } };\r\n}\r\n\r\nfunction processEmessage(\r\n errorName: string,\r\n config: StoredEmessage\r\n): string | void {\r\n const message = config.message;\r\n\r\n let consoleType: MessageType | false;\r\n if (config.type === false) {\r\n consoleType = false;\r\n } else if (config.type === true || config.type === undefined) {\r\n consoleType = \"err\";\r\n } else {\r\n consoleType = config.type;\r\n }\r\n\r\n // 1. Console log\r\n if (consoleType) {\r\n if (isBrowser()) {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(message);\r\n break;\r\n case \"war\":\r\n console.warn(message);\r\n break;\r\n case \"err\":\r\n console.error(message);\r\n break;\r\n }\r\n } else {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(`\\x1b[30;47m ${message} \\x1b[0m`);\r\n break;\r\n case \"war\":\r\n console.warn(`\\x1b[37;43m ${message} \\x1b[0m`);\r\n break;\r\n case \"err\":\r\n console.error(`\\x1b[37;41m ${message} \\x1b[0m`);\r\n break;\r\n }\r\n }\r\n }\r\n\r\n // 2. Toast notification\r\n if (config.toast && isBrowser()) {\r\n showToast(message, config.toast, consoleType as MessageType);\r\n }\r\n\r\n // 3. Callback\r\n if (config.callBack) {\r\n try {\r\n config.callBack();\r\n } catch (e: any) {\r\n console.error(\r\n `emessages: Error in callBack for \"${errorName}\":`,\r\n e.message\r\n );\r\n }\r\n }\r\n\r\n // 4. Return error message\r\n if (config.returnEM) {\r\n return message;\r\n }\r\n\r\n // 5. Break execution\r\n if (config.break ?? true) {\r\n if (isBrowser()) {\r\n throw new Error(message);\r\n } else {\r\n process.exit(1);\r\n }\r\n }\r\n}\r\n\r\nexport function Emessage(...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n individualMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n}\r\n\r\nEmessage.global = function (...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n globalMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n};\r\n\r\nexport function showE(error: string | Record<string, any>): string | void {\r\n let config: StoredEmessage | null = null;\r\n let errorName: string | null = null;\r\n\r\n if (typeof error === \"string\") {\r\n errorName = error;\r\n config =\r\n individualMessageStore.get(error) ?? globalMessageStore.get(error) ?? null;\r\n if (!config) {\r\n console.error(`emessages: Error \"${error}\" not found.`);\r\n return;\r\n }\r\n } else if (typeof error === \"object\" && error !== null) {\r\n const parsed = parseConfig(error);\r\n if (parsed) {\r\n errorName = parsed.name;\r\n config = parsed.options;\r\n } else {\r\n console.error(\"emessages: Invalid object passed to showE.\");\r\n return;\r\n }\r\n } else {\r\n console.error(\"emessages: Invalid argument passed to showE.\");\r\n return;\r\n }\r\n\r\n if (config && errorName) {\r\n return processEmessage(errorName, config);\r\n }\r\n}\r\n"],"mappings":";AAEO,IAAM,yBAAyB,oBAAI,IAA4B;AAC/D,IAAM,qBAAqB,oBAAI,IAA4B;;;ACD3D,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AACrE;AAOA,SAAS,mBAAmB,cAAkC;AAC5D,MAAI,CAAC,gBAAgB,CAAC,aAA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K,cAAc;AACtD;AAAA,IACF;AAAA,EACF,WAAW,OAAO,UAAU,YAAY,UAAU,MAAM;AACtD,UAAM,SAAS,YAAY,KAAK;AAChC,QAAI,QAAQ;AACV,kBAAY,OAAO;AACnB,eAAS,OAAO;AAAA,IAClB,OAAO;AACL,cAAQ,MAAM,4CAA4C;AAC1D;AAAA,IACF;AAAA,EACF,OAAO;AACL,YAAQ,MAAM,8CAA8C;AAC5D;AAAA,EACF;AAEA,MAAI,UAAU,WAAW;AACvB,WAAO,gBAAgB,WAAW,MAAM;AAAA,EAC1C;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emessages",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "A flexible error handling library for JS/TS. Define custom errors with console, toast, and callbacks, supporting global/local scopes and all environments.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "tsup"
|
|
31
31
|
},
|
|
32
|
+
"bin": {
|
|
33
|
+
"emessages": "./dist/cli.cjs"
|
|
34
|
+
},
|
|
32
35
|
"devDependencies": {
|
|
33
36
|
"@types/node": "^20.11.24",
|
|
34
37
|
"tsup": "^8.0.2",
|