emessages 2.2.5 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +32 -1
- package/dist/index.cjs +76 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -13
- package/dist/index.d.ts +15 -13
- package/dist/index.mjs +76 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -7
- package/dist/cli.cjs +0 -101
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.mjs +0 -78
- package/dist/cli.mjs.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 arhan
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 arhan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -137,9 +137,40 @@ Each config object passed to `Emessage` has one error name/message and a set of
|
|
|
137
137
|
- `style?`: `string`. Custom CSS classes to apply.
|
|
138
138
|
- `position?`: `string`. e.g., `"top-right"`, `"bottom-left"`, `"center"`.
|
|
139
139
|
|
|
140
|
-
### `showE(errorName | config)`
|
|
140
|
+
### `showE(errorName | config, argsM?)`
|
|
141
141
|
|
|
142
142
|
Triggers an error.
|
|
143
143
|
|
|
144
144
|
- `errorName: string`: The name of the pre-configured error to show. `showE` will look for a local definition first, then a global one.
|
|
145
145
|
- `config: object`: An inline config object for a one-off error message.
|
|
146
|
+
- `argsM?: Record<string, any>`: Runtime values used to build dynamic messages and evaluate dynamic options.
|
|
147
|
+
|
|
148
|
+
## Dynamic `argsM` Example
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
import { Emessage, showE } from "emessages";
|
|
152
|
+
|
|
153
|
+
const dataStore = {};
|
|
154
|
+
|
|
155
|
+
Emessage({
|
|
156
|
+
TEST3: (argsM) =>`Hello ${argsM.name}, your total marks are ${argsM.totalMarks}`,
|
|
157
|
+
type: (argsM) => (argsM.name ? "log" : "err"),
|
|
158
|
+
break: (argsM) => !(argsM.name && argsM.age && argsM.marks?.length > 0),
|
|
159
|
+
toast: (argsM) => !!(argsM.subject && argsM.marks),
|
|
160
|
+
callBack: (argsM) => {
|
|
161
|
+
dataStore.totalMarks = argsM.totalMarks;
|
|
162
|
+
dataStore.marksPercentage = argsM.getMarksPercentage(argsM.marks);
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
showE("TEST3", {
|
|
167
|
+
name: "Arhan",
|
|
168
|
+
age: 20,
|
|
169
|
+
subject: { sub1: "Math", sub2: "Science" },
|
|
170
|
+
marks: [90, 80, 70],
|
|
171
|
+
totalMarks: 240,
|
|
172
|
+
getMarksPercentage: (marks) => (marks.reduce((a, b) => a + b, 0) / 300) * 100,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
console.log(dataStore);
|
|
176
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -112,11 +112,9 @@ function injectToastStyles() {
|
|
|
112
112
|
pointer-events: all;
|
|
113
113
|
max-width: 350px;
|
|
114
114
|
word-break: break-word;
|
|
115
|
-
display: flex;
|
|
116
|
-
justify-content: space-between;
|
|
117
|
-
align-items: center;
|
|
118
|
-
gap: 10px;
|
|
119
115
|
box-sizing: border-box;
|
|
116
|
+
position: relative;
|
|
117
|
+
padding-right: 42px; /* keep content clear from the absolute close button */
|
|
120
118
|
}
|
|
121
119
|
|
|
122
120
|
.emessage-toast.visible {
|
|
@@ -130,20 +128,25 @@ function injectToastStyles() {
|
|
|
130
128
|
.emessage-toast-log { background-color: #ffffff; color: #1f2937; border: 1px solid #e5e7eb; } /* white, gray-800 text, gray-200 border */
|
|
131
129
|
|
|
132
130
|
.emessage-toast-message {
|
|
133
|
-
|
|
131
|
+
display: block;
|
|
132
|
+
width: 100%;
|
|
134
133
|
}
|
|
135
134
|
|
|
136
135
|
.emessage-toast-close {
|
|
136
|
+
position: absolute;
|
|
137
|
+
top: 8px;
|
|
138
|
+
right: 8px;
|
|
137
139
|
background: none;
|
|
138
140
|
border: none;
|
|
139
141
|
color: inherit;
|
|
140
|
-
font-size:
|
|
142
|
+
font-size: 18px;
|
|
141
143
|
font-weight: bold;
|
|
142
144
|
cursor: pointer;
|
|
143
145
|
line-height: 1;
|
|
144
146
|
opacity: 0.7;
|
|
145
|
-
padding:
|
|
146
|
-
margin
|
|
147
|
+
padding: 2px 6px;
|
|
148
|
+
margin: 0;
|
|
149
|
+
z-index: 1;
|
|
147
150
|
}
|
|
148
151
|
.emessage-toast-close:hover {
|
|
149
152
|
opacity: 1;
|
|
@@ -245,6 +248,51 @@ function showToast(message, toastOptions, messageType = "log") {
|
|
|
245
248
|
}
|
|
246
249
|
|
|
247
250
|
// src/index.ts
|
|
251
|
+
function resolveDynamicValue(value, argsM) {
|
|
252
|
+
if (typeof value === "function") {
|
|
253
|
+
return value(argsM);
|
|
254
|
+
}
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
function getByPath(target, path) {
|
|
258
|
+
const normalized = path.replace(/\[(\w+)\]/g, ".$1").replace(/^\./, "");
|
|
259
|
+
const segments = normalized.split(".").filter(Boolean);
|
|
260
|
+
let current = target;
|
|
261
|
+
for (const segment of segments) {
|
|
262
|
+
if (current == null) return void 0;
|
|
263
|
+
current = current[segment];
|
|
264
|
+
}
|
|
265
|
+
return current;
|
|
266
|
+
}
|
|
267
|
+
function interpolateArgsM(template, argsM) {
|
|
268
|
+
return template.replace(/\$\{\s*argsM\.([^}]+)\s*\}/g, (match, rawPath) => {
|
|
269
|
+
const path = String(rawPath).trim();
|
|
270
|
+
const value = getByPath(argsM, path);
|
|
271
|
+
if (value === void 0) return match;
|
|
272
|
+
if (typeof value === "object" && value !== null) {
|
|
273
|
+
try {
|
|
274
|
+
return JSON.stringify(value);
|
|
275
|
+
} catch {
|
|
276
|
+
return String(value);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return String(value);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function resolveToastConfig(toast, argsM) {
|
|
283
|
+
if (typeof toast !== "object" || toast === null) {
|
|
284
|
+
return toast;
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
message: resolveDynamicValue(toast.message, argsM),
|
|
288
|
+
style: resolveDynamicValue(toast.style, argsM),
|
|
289
|
+
class: resolveDynamicValue(toast.class, argsM),
|
|
290
|
+
position: toast.position,
|
|
291
|
+
stay: resolveDynamicValue(toast.stay, argsM),
|
|
292
|
+
duration: resolveDynamicValue(toast.duration, argsM),
|
|
293
|
+
delay: resolveDynamicValue(toast.delay, argsM)
|
|
294
|
+
};
|
|
295
|
+
}
|
|
248
296
|
function parseConfig(config) {
|
|
249
297
|
const options = {};
|
|
250
298
|
let message = null;
|
|
@@ -262,7 +310,7 @@ function parseConfig(config) {
|
|
|
262
310
|
continue;
|
|
263
311
|
}
|
|
264
312
|
name = key;
|
|
265
|
-
message =
|
|
313
|
+
message = config[key];
|
|
266
314
|
}
|
|
267
315
|
}
|
|
268
316
|
}
|
|
@@ -282,15 +330,16 @@ function parseConfig(config) {
|
|
|
282
330
|
}
|
|
283
331
|
return { name, options: { ...options, message } };
|
|
284
332
|
}
|
|
285
|
-
function processEmessage(errorName, config, errorToThrow) {
|
|
286
|
-
const message = config.message;
|
|
333
|
+
function processEmessage(errorName, config, argsM, errorToThrow) {
|
|
334
|
+
const message = interpolateArgsM(String(resolveDynamicValue(config.message, argsM) ?? ""), argsM);
|
|
287
335
|
let consoleType;
|
|
288
|
-
|
|
336
|
+
const resolvedType = resolveDynamicValue(config.type, argsM);
|
|
337
|
+
if (resolvedType === false) {
|
|
289
338
|
consoleType = false;
|
|
290
|
-
} else if (
|
|
339
|
+
} else if (resolvedType === true || resolvedType === void 0) {
|
|
291
340
|
consoleType = "err";
|
|
292
341
|
} else {
|
|
293
|
-
consoleType =
|
|
342
|
+
consoleType = resolvedType;
|
|
294
343
|
}
|
|
295
344
|
if (consoleType) {
|
|
296
345
|
if (isBrowser()) {
|
|
@@ -319,12 +368,13 @@ function processEmessage(errorName, config, errorToThrow) {
|
|
|
319
368
|
}
|
|
320
369
|
}
|
|
321
370
|
}
|
|
322
|
-
|
|
323
|
-
|
|
371
|
+
const resolvedToast = resolveDynamicValue(config.toast, argsM);
|
|
372
|
+
if (resolvedToast && isBrowser()) {
|
|
373
|
+
showToast(message, resolveToastConfig(resolvedToast, argsM), consoleType);
|
|
324
374
|
}
|
|
325
375
|
if (config.callBack) {
|
|
326
376
|
try {
|
|
327
|
-
config.callBack();
|
|
377
|
+
config.callBack(argsM);
|
|
328
378
|
} catch (e) {
|
|
329
379
|
console.error(
|
|
330
380
|
`emessages: Error in callBack for "${errorName}":`,
|
|
@@ -332,10 +382,11 @@ function processEmessage(errorName, config, errorToThrow) {
|
|
|
332
382
|
);
|
|
333
383
|
}
|
|
334
384
|
}
|
|
335
|
-
if (config.returnEM) {
|
|
385
|
+
if (resolveDynamicValue(config.returnEM, argsM)) {
|
|
336
386
|
return message;
|
|
337
387
|
}
|
|
338
|
-
|
|
388
|
+
const resolvedBreak = resolveDynamicValue(config.break, argsM);
|
|
389
|
+
if (resolvedBreak ?? true) {
|
|
339
390
|
if (isBrowser()) {
|
|
340
391
|
throw errorToThrow || new Error(message);
|
|
341
392
|
} else {
|
|
@@ -359,7 +410,7 @@ Emessage.global = function(...configs) {
|
|
|
359
410
|
}
|
|
360
411
|
}
|
|
361
412
|
};
|
|
362
|
-
function showE(error) {
|
|
413
|
+
function showE(error, argsM = {}) {
|
|
363
414
|
const errorForStack = new Error();
|
|
364
415
|
let config = null;
|
|
365
416
|
let errorName = null;
|
|
@@ -384,8 +435,11 @@ function showE(error) {
|
|
|
384
435
|
return;
|
|
385
436
|
}
|
|
386
437
|
if (config && errorName) {
|
|
387
|
-
errorForStack.message =
|
|
388
|
-
|
|
438
|
+
errorForStack.message = interpolateArgsM(
|
|
439
|
+
String(resolveDynamicValue(config.message, argsM) ?? ""),
|
|
440
|
+
argsM
|
|
441
|
+
);
|
|
442
|
+
return processEmessage(errorName, config, argsM, errorForStack);
|
|
389
443
|
}
|
|
390
444
|
}
|
|
391
445
|
// Annotate the CommonJS export names for ESM import in node:
|
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 // Apply default for 'break' if not explicitly set\r\n if (options.break === undefined) {\r\n if (options.type === \"war\" || options.type === \"log\") {\r\n options.break = false;\r\n } else {\r\n // Default for 'err' type or if type is not specified\r\n options.break = true;\r\n }\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 errorToThrow?: Error\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 errorToThrow || 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 const errorForStack = new Error();\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 errorForStack.message = config.message;\r\n return processEmessage(errorName, config, errorForStack);\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;AAAA,EAC/B;AAGA,MAAI,CAAE,OAAe,UAAU,YAAY;AACzC,IAAC,OAAe,UAAU,aAAa,SAAU,WAA2B;AAC1E,UAAI,eAAmC;AAEvC,UAAI,OAAO,cAAc,UAAU;AAEjC,uBAAe,SAAS,eAAe,SAAS;AAAA,MAClD,WAAW,aAAa,UAAU,QAAQ;AAExC,uBAAgB,UAAU,OAAuB,QAAQ,iBAAiB;AAAA,MAC5E;AAEA,UAAI,cAAc;AAChB,2BAAmB,YAAY;AAAA,MACjC,OAAO;AACL,gBAAQ,KAAK,iFAAiF;AAAA,MAChG;AAAA,IACF;AAAA,EACF;AACF;AAGA,oBAA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;AACL,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF;AAEO,SAAS,YAAY,SAA2B;AACrD,aAAW,UAAU,SAAS;AAC5B,UAAM,SAAS,YAAY,MAAM;AACjC,QAAI,QAAQ;AACV,6BAAuB,IAAI,OAAO,MAAM,OAAO,OAAO;AAAA,IACxD;AAAA,EACF;AACF;AAEA,SAAS,SAAS,YAAa,SAA2B;AACxD,aAAW,UAAU,SAAS;AAC5B,UAAM,SAAS,YAAY,MAAM;AACjC,QAAI,QAAQ;AACV,yBAAmB,IAAI,OAAO,MAAM,OAAO,OAAO;AAAA,IACpD;AAAA,EACF;AACF;AAEO,SAAS,MAAM,OAAoD;AACxE,QAAM,gBAAgB,IAAI,MAAM;AAChC,MAAI,SAAgC;AACpC,MAAI,YAA2B;AAE/B,MAAI,OAAO,UAAU,UAAU;AAC7B,gBAAY;AACZ,aACE,uBAAuB,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,KAAK;AACxE,QAAI,CAAC,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,kBAAc,UAAU,OAAO;AAC/B,WAAO,gBAAgB,WAAW,QAAQ,aAAa;AAAA,EACzD;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/store.ts","../src/utils.ts"],"sourcesContent":["import { individualMessageStore, globalMessageStore } from \"./store\";\r\nimport type {\n ArgsM,\n DynamicValue,\n EmessageConfig,\n EmessageOptions,\n StoredEmessage,\n ToastConfig,\n MessageType,\r\n} from \"./types\";\r\nimport { isBrowser, showToast } from \"./utils\";\n\nfunction resolveDynamicValue<T>(value: DynamicValue<T> | undefined, argsM: ArgsM): T | undefined {\n if (typeof value === \"function\") {\n return (value as (args: ArgsM) => T)(argsM);\n }\n return value;\n}\n\nfunction getByPath(target: ArgsM, path: string): any {\n const normalized = path.replace(/\\[(\\w+)\\]/g, \".$1\").replace(/^\\./, \"\");\n const segments = normalized.split(\".\").filter(Boolean);\n\n let current: any = target;\n for (const segment of segments) {\n if (current == null) return undefined;\n current = current[segment];\n }\n return current;\n}\n\nfunction interpolateArgsM(template: string, argsM: ArgsM): string {\n return template.replace(/\\$\\{\\s*argsM\\.([^}]+)\\s*\\}/g, (match, rawPath) => {\n const path = String(rawPath).trim();\n const value = getByPath(argsM, path);\n if (value === undefined) return match;\n if (typeof value === \"object\" && value !== null) {\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n }\n return String(value);\n });\n}\n\nfunction resolveToastConfig(toast: boolean | ToastConfig, argsM: ArgsM): boolean | ToastConfig {\n if (typeof toast !== \"object\" || toast === null) {\n return toast;\n }\n\n return {\n message: resolveDynamicValue(toast.message, argsM),\n style: resolveDynamicValue(toast.style, argsM),\n class: resolveDynamicValue(toast.class, argsM),\n position: toast.position,\n stay: resolveDynamicValue(toast.stay, argsM),\n duration: resolveDynamicValue(toast.duration, argsM),\n delay: resolveDynamicValue(toast.delay, argsM),\n };\n}\n\nfunction parseConfig(\n config: Record<string, any>\n): { name: string; options: StoredEmessage } | null {\n const options: EmessageOptions = {};\n let message: DynamicValue<string> | null = null;\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 }\n name = key;\n message = config[key];\n }\n }\n }\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 // Apply default for 'break' if not explicitly set\r\n if (options.break === undefined) {\r\n if (options.type === \"war\" || options.type === \"log\") {\r\n options.break = false;\r\n } else {\r\n // Default for 'err' type or if type is not specified\r\n options.break = true;\r\n }\r\n }\r\n\r\n return { name, options: { ...options, message } };\r\n}\r\n\r\nfunction processEmessage(\n errorName: string,\n config: StoredEmessage,\n argsM: ArgsM,\n errorToThrow?: Error\n): string | void {\n const message = interpolateArgsM(String(resolveDynamicValue(config.message, argsM) ?? \"\"), argsM);\n\n let consoleType: MessageType | false;\n const resolvedType = resolveDynamicValue(config.type, argsM);\n if (resolvedType === false) {\n consoleType = false;\n } else if (resolvedType === true || resolvedType === undefined) {\n consoleType = \"err\";\n } else {\n consoleType = resolvedType;\n }\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 const resolvedToast = resolveDynamicValue(config.toast, argsM);\n if (resolvedToast && isBrowser()) {\n showToast(message, resolveToastConfig(resolvedToast, argsM), consoleType as MessageType);\n }\n\n // 3. Callback\n if (config.callBack) {\n try {\n config.callBack(argsM);\n } catch (e: any) {\n console.error(\n `emessages: Error in callBack for \"${errorName}\":`,\n e.message\r\n );\r\n }\r\n }\r\n\n // 4. Return error message\n if (resolveDynamicValue(config.returnEM, argsM)) {\n return message;\n }\n\n // 5. Break execution\n const resolvedBreak = resolveDynamicValue(config.break, argsM);\n if (resolvedBreak ?? true) {\n if (isBrowser()) {\n throw errorToThrow || new Error(message);\n } else {\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>, argsM: ArgsM = {}): string | void {\n const errorForStack = new Error();\n let config: StoredEmessage | null = null;\n let errorName: string | null = null;\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\n if (config && errorName) {\n errorForStack.message = interpolateArgsM(\n String(resolveDynamicValue(config.message, argsM) ?? \"\"),\n argsM\n );\n return processEmessage(errorName, config, argsM, errorForStack);\n }\n}\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 {\n padding: 12px 18px;\n margin: 8px;\n border-radius: 6px;\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;\n word-break: break-word;\n box-sizing: border-box;\n position: relative;\n padding-right: 42px; /* keep content clear from the absolute close button */\n }\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 {\n display: block;\n width: 100%;\n }\n\n .emessage-toast-close {\n position: absolute;\n top: 8px;\n right: 8px;\n background: none;\n border: none;\n color: inherit;\n font-size: 18px;\n font-weight: bold;\n cursor: pointer;\n line-height: 1;\n opacity: 0.7;\n padding: 2px 6px;\n margin: 0;\n z-index: 1;\n }\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;AAAA,EAC/B;AAGA,MAAI,CAAE,OAAe,UAAU,YAAY;AACzC,IAAC,OAAe,UAAU,aAAa,SAAU,WAA2B;AAC1E,UAAI,eAAmC;AAEvC,UAAI,OAAO,cAAc,UAAU;AAEjC,uBAAe,SAAS,eAAe,SA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K;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,kBAAc,UAAU;AAAA,MACtB,OAAO,oBAAoB,OAAO,SAAS,KAAK,KAAK,EAAE;AAAA,MACvD;AAAA,IACF;AACA,WAAO,gBAAgB,WAAW,QAAQ,OAAO,aAAa;AAAA,EAChE;AACF;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
type MessageType = "log" | "war" | "err" | boolean;
|
|
2
|
+
type ArgsM = Record<string, any>;
|
|
3
|
+
type DynamicValue<T> = T | ((argsM: ArgsM) => T);
|
|
2
4
|
interface ToastConfig {
|
|
3
|
-
message?: string
|
|
4
|
-
style?: string
|
|
5
|
-
class?: string
|
|
5
|
+
message?: DynamicValue<string | undefined>;
|
|
6
|
+
style?: DynamicValue<string | undefined>;
|
|
7
|
+
class?: DynamicValue<string | undefined>;
|
|
6
8
|
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
|
|
9
|
+
stay?: DynamicValue<boolean | undefined>;
|
|
10
|
+
duration?: DynamicValue<number | undefined>;
|
|
11
|
+
delay?: DynamicValue<number | undefined>;
|
|
10
12
|
}
|
|
11
13
|
interface EmessageOptions {
|
|
12
|
-
type?: MessageType
|
|
13
|
-
break?: boolean
|
|
14
|
-
toast?: boolean | ToastConfig
|
|
15
|
-
returnEM?: boolean
|
|
16
|
-
callBack?: () => void;
|
|
14
|
+
type?: DynamicValue<MessageType>;
|
|
15
|
+
break?: DynamicValue<boolean>;
|
|
16
|
+
toast?: DynamicValue<boolean | ToastConfig>;
|
|
17
|
+
returnEM?: DynamicValue<boolean>;
|
|
18
|
+
callBack?: (argsM: ArgsM) => void;
|
|
17
19
|
}
|
|
18
20
|
interface EmessageConfig extends EmessageOptions {
|
|
19
|
-
[key: string]: string | MessageType | boolean | (() => void) |
|
|
21
|
+
[key: string]: string | DynamicValue<string | MessageType | boolean | ToastConfig | undefined> | ((argsM: ArgsM) => void) | undefined;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
declare function Emessage(...configs: EmessageConfig[]): void;
|
|
23
25
|
declare namespace Emessage {
|
|
24
26
|
var global: (...configs: EmessageConfig[]) => void;
|
|
25
27
|
}
|
|
26
|
-
declare function showE(error: string | Record<string, any
|
|
28
|
+
declare function showE(error: string | Record<string, any>, argsM?: ArgsM): string | void;
|
|
27
29
|
|
|
28
30
|
export { Emessage, showE };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
type MessageType = "log" | "war" | "err" | boolean;
|
|
2
|
+
type ArgsM = Record<string, any>;
|
|
3
|
+
type DynamicValue<T> = T | ((argsM: ArgsM) => T);
|
|
2
4
|
interface ToastConfig {
|
|
3
|
-
message?: string
|
|
4
|
-
style?: string
|
|
5
|
-
class?: string
|
|
5
|
+
message?: DynamicValue<string | undefined>;
|
|
6
|
+
style?: DynamicValue<string | undefined>;
|
|
7
|
+
class?: DynamicValue<string | undefined>;
|
|
6
8
|
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
|
|
9
|
+
stay?: DynamicValue<boolean | undefined>;
|
|
10
|
+
duration?: DynamicValue<number | undefined>;
|
|
11
|
+
delay?: DynamicValue<number | undefined>;
|
|
10
12
|
}
|
|
11
13
|
interface EmessageOptions {
|
|
12
|
-
type?: MessageType
|
|
13
|
-
break?: boolean
|
|
14
|
-
toast?: boolean | ToastConfig
|
|
15
|
-
returnEM?: boolean
|
|
16
|
-
callBack?: () => void;
|
|
14
|
+
type?: DynamicValue<MessageType>;
|
|
15
|
+
break?: DynamicValue<boolean>;
|
|
16
|
+
toast?: DynamicValue<boolean | ToastConfig>;
|
|
17
|
+
returnEM?: DynamicValue<boolean>;
|
|
18
|
+
callBack?: (argsM: ArgsM) => void;
|
|
17
19
|
}
|
|
18
20
|
interface EmessageConfig extends EmessageOptions {
|
|
19
|
-
[key: string]: string | MessageType | boolean | (() => void) |
|
|
21
|
+
[key: string]: string | DynamicValue<string | MessageType | boolean | ToastConfig | undefined> | ((argsM: ArgsM) => void) | undefined;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
declare function Emessage(...configs: EmessageConfig[]): void;
|
|
23
25
|
declare namespace Emessage {
|
|
24
26
|
var global: (...configs: EmessageConfig[]) => void;
|
|
25
27
|
}
|
|
26
|
-
declare function showE(error: string | Record<string, any
|
|
28
|
+
declare function showE(error: string | Record<string, any>, argsM?: ArgsM): string | void;
|
|
27
29
|
|
|
28
30
|
export { Emessage, showE };
|
package/dist/index.mjs
CHANGED
|
@@ -85,11 +85,9 @@ function injectToastStyles() {
|
|
|
85
85
|
pointer-events: all;
|
|
86
86
|
max-width: 350px;
|
|
87
87
|
word-break: break-word;
|
|
88
|
-
display: flex;
|
|
89
|
-
justify-content: space-between;
|
|
90
|
-
align-items: center;
|
|
91
|
-
gap: 10px;
|
|
92
88
|
box-sizing: border-box;
|
|
89
|
+
position: relative;
|
|
90
|
+
padding-right: 42px; /* keep content clear from the absolute close button */
|
|
93
91
|
}
|
|
94
92
|
|
|
95
93
|
.emessage-toast.visible {
|
|
@@ -103,20 +101,25 @@ function injectToastStyles() {
|
|
|
103
101
|
.emessage-toast-log { background-color: #ffffff; color: #1f2937; border: 1px solid #e5e7eb; } /* white, gray-800 text, gray-200 border */
|
|
104
102
|
|
|
105
103
|
.emessage-toast-message {
|
|
106
|
-
|
|
104
|
+
display: block;
|
|
105
|
+
width: 100%;
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
.emessage-toast-close {
|
|
109
|
+
position: absolute;
|
|
110
|
+
top: 8px;
|
|
111
|
+
right: 8px;
|
|
110
112
|
background: none;
|
|
111
113
|
border: none;
|
|
112
114
|
color: inherit;
|
|
113
|
-
font-size:
|
|
115
|
+
font-size: 18px;
|
|
114
116
|
font-weight: bold;
|
|
115
117
|
cursor: pointer;
|
|
116
118
|
line-height: 1;
|
|
117
119
|
opacity: 0.7;
|
|
118
|
-
padding:
|
|
119
|
-
margin
|
|
120
|
+
padding: 2px 6px;
|
|
121
|
+
margin: 0;
|
|
122
|
+
z-index: 1;
|
|
120
123
|
}
|
|
121
124
|
.emessage-toast-close:hover {
|
|
122
125
|
opacity: 1;
|
|
@@ -218,6 +221,51 @@ function showToast(message, toastOptions, messageType = "log") {
|
|
|
218
221
|
}
|
|
219
222
|
|
|
220
223
|
// src/index.ts
|
|
224
|
+
function resolveDynamicValue(value, argsM) {
|
|
225
|
+
if (typeof value === "function") {
|
|
226
|
+
return value(argsM);
|
|
227
|
+
}
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
function getByPath(target, path) {
|
|
231
|
+
const normalized = path.replace(/\[(\w+)\]/g, ".$1").replace(/^\./, "");
|
|
232
|
+
const segments = normalized.split(".").filter(Boolean);
|
|
233
|
+
let current = target;
|
|
234
|
+
for (const segment of segments) {
|
|
235
|
+
if (current == null) return void 0;
|
|
236
|
+
current = current[segment];
|
|
237
|
+
}
|
|
238
|
+
return current;
|
|
239
|
+
}
|
|
240
|
+
function interpolateArgsM(template, argsM) {
|
|
241
|
+
return template.replace(/\$\{\s*argsM\.([^}]+)\s*\}/g, (match, rawPath) => {
|
|
242
|
+
const path = String(rawPath).trim();
|
|
243
|
+
const value = getByPath(argsM, path);
|
|
244
|
+
if (value === void 0) return match;
|
|
245
|
+
if (typeof value === "object" && value !== null) {
|
|
246
|
+
try {
|
|
247
|
+
return JSON.stringify(value);
|
|
248
|
+
} catch {
|
|
249
|
+
return String(value);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return String(value);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
function resolveToastConfig(toast, argsM) {
|
|
256
|
+
if (typeof toast !== "object" || toast === null) {
|
|
257
|
+
return toast;
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
message: resolveDynamicValue(toast.message, argsM),
|
|
261
|
+
style: resolveDynamicValue(toast.style, argsM),
|
|
262
|
+
class: resolveDynamicValue(toast.class, argsM),
|
|
263
|
+
position: toast.position,
|
|
264
|
+
stay: resolveDynamicValue(toast.stay, argsM),
|
|
265
|
+
duration: resolveDynamicValue(toast.duration, argsM),
|
|
266
|
+
delay: resolveDynamicValue(toast.delay, argsM)
|
|
267
|
+
};
|
|
268
|
+
}
|
|
221
269
|
function parseConfig(config) {
|
|
222
270
|
const options = {};
|
|
223
271
|
let message = null;
|
|
@@ -235,7 +283,7 @@ function parseConfig(config) {
|
|
|
235
283
|
continue;
|
|
236
284
|
}
|
|
237
285
|
name = key;
|
|
238
|
-
message =
|
|
286
|
+
message = config[key];
|
|
239
287
|
}
|
|
240
288
|
}
|
|
241
289
|
}
|
|
@@ -255,15 +303,16 @@ function parseConfig(config) {
|
|
|
255
303
|
}
|
|
256
304
|
return { name, options: { ...options, message } };
|
|
257
305
|
}
|
|
258
|
-
function processEmessage(errorName, config, errorToThrow) {
|
|
259
|
-
const message = config.message;
|
|
306
|
+
function processEmessage(errorName, config, argsM, errorToThrow) {
|
|
307
|
+
const message = interpolateArgsM(String(resolveDynamicValue(config.message, argsM) ?? ""), argsM);
|
|
260
308
|
let consoleType;
|
|
261
|
-
|
|
309
|
+
const resolvedType = resolveDynamicValue(config.type, argsM);
|
|
310
|
+
if (resolvedType === false) {
|
|
262
311
|
consoleType = false;
|
|
263
|
-
} else if (
|
|
312
|
+
} else if (resolvedType === true || resolvedType === void 0) {
|
|
264
313
|
consoleType = "err";
|
|
265
314
|
} else {
|
|
266
|
-
consoleType =
|
|
315
|
+
consoleType = resolvedType;
|
|
267
316
|
}
|
|
268
317
|
if (consoleType) {
|
|
269
318
|
if (isBrowser()) {
|
|
@@ -292,12 +341,13 @@ function processEmessage(errorName, config, errorToThrow) {
|
|
|
292
341
|
}
|
|
293
342
|
}
|
|
294
343
|
}
|
|
295
|
-
|
|
296
|
-
|
|
344
|
+
const resolvedToast = resolveDynamicValue(config.toast, argsM);
|
|
345
|
+
if (resolvedToast && isBrowser()) {
|
|
346
|
+
showToast(message, resolveToastConfig(resolvedToast, argsM), consoleType);
|
|
297
347
|
}
|
|
298
348
|
if (config.callBack) {
|
|
299
349
|
try {
|
|
300
|
-
config.callBack();
|
|
350
|
+
config.callBack(argsM);
|
|
301
351
|
} catch (e) {
|
|
302
352
|
console.error(
|
|
303
353
|
`emessages: Error in callBack for "${errorName}":`,
|
|
@@ -305,10 +355,11 @@ function processEmessage(errorName, config, errorToThrow) {
|
|
|
305
355
|
);
|
|
306
356
|
}
|
|
307
357
|
}
|
|
308
|
-
if (config.returnEM) {
|
|
358
|
+
if (resolveDynamicValue(config.returnEM, argsM)) {
|
|
309
359
|
return message;
|
|
310
360
|
}
|
|
311
|
-
|
|
361
|
+
const resolvedBreak = resolveDynamicValue(config.break, argsM);
|
|
362
|
+
if (resolvedBreak ?? true) {
|
|
312
363
|
if (isBrowser()) {
|
|
313
364
|
throw errorToThrow || new Error(message);
|
|
314
365
|
} else {
|
|
@@ -332,7 +383,7 @@ Emessage.global = function(...configs) {
|
|
|
332
383
|
}
|
|
333
384
|
}
|
|
334
385
|
};
|
|
335
|
-
function showE(error) {
|
|
386
|
+
function showE(error, argsM = {}) {
|
|
336
387
|
const errorForStack = new Error();
|
|
337
388
|
let config = null;
|
|
338
389
|
let errorName = null;
|
|
@@ -357,8 +408,11 @@ function showE(error) {
|
|
|
357
408
|
return;
|
|
358
409
|
}
|
|
359
410
|
if (config && errorName) {
|
|
360
|
-
errorForStack.message =
|
|
361
|
-
|
|
411
|
+
errorForStack.message = interpolateArgsM(
|
|
412
|
+
String(resolveDynamicValue(config.message, argsM) ?? ""),
|
|
413
|
+
argsM
|
|
414
|
+
);
|
|
415
|
+
return processEmessage(errorName, config, argsM, errorForStack);
|
|
362
416
|
}
|
|
363
417
|
}
|
|
364
418
|
export {
|
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, 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 // Apply default for 'break' if not explicitly set\r\n if (options.break === undefined) {\r\n if (options.type === \"war\" || options.type === \"log\") {\r\n options.break = false;\r\n } else {\r\n // Default for 'err' type or if type is not specified\r\n options.break = true;\r\n }\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 errorToThrow?: Error\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 errorToThrow || 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 const errorForStack = new Error();\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 errorForStack.message = config.message;\r\n return processEmessage(errorName, config, errorForStack);\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,eA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M,OAAO,OAAO;AAAA,IACpD;AAAA,EACF;AACF;AAEO,SAAS,MAAM,OAAoD;AACxE,QAAM,gBAAgB,IAAI,MAAM;AAChC,MAAI,SAAgC;AACpC,MAAI,YAA2B;AAE/B,MAAI,OAAO,UAAU,UAAU;AAC7B,gBAAY;AACZ,aACE,uBAAuB,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,KAAK;AACxE,QAAI,CAAC,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,kBAAc,UAAU,OAAO;AAC/B,WAAO,gBAAgB,WAAW,QAAQ,aAAa;AAAA,EACzD;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 {\n padding: 12px 18px;\n margin: 8px;\n border-radius: 6px;\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;\n word-break: break-word;\n box-sizing: border-box;\n position: relative;\n padding-right: 42px; /* keep content clear from the absolute close button */\n }\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 {\n display: block;\n width: 100%;\n }\n\n .emessage-toast-close {\n position: absolute;\n top: 8px;\n right: 8px;\n background: none;\n border: none;\n color: inherit;\n font-size: 18px;\n font-weight: bold;\n cursor: pointer;\n line-height: 1;\n opacity: 0.7;\n padding: 2px 6px;\n margin: 0;\n z-index: 1;\n }\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 {\n ArgsM,\n DynamicValue,\n EmessageConfig,\n EmessageOptions,\n StoredEmessage,\n ToastConfig,\n MessageType,\r\n} from \"./types\";\r\nimport { isBrowser, showToast } from \"./utils\";\n\nfunction resolveDynamicValue<T>(value: DynamicValue<T> | undefined, argsM: ArgsM): T | undefined {\n if (typeof value === \"function\") {\n return (value as (args: ArgsM) => T)(argsM);\n }\n return value;\n}\n\nfunction getByPath(target: ArgsM, path: string): any {\n const normalized = path.replace(/\\[(\\w+)\\]/g, \".$1\").replace(/^\\./, \"\");\n const segments = normalized.split(\".\").filter(Boolean);\n\n let current: any = target;\n for (const segment of segments) {\n if (current == null) return undefined;\n current = current[segment];\n }\n return current;\n}\n\nfunction interpolateArgsM(template: string, argsM: ArgsM): string {\n return template.replace(/\\$\\{\\s*argsM\\.([^}]+)\\s*\\}/g, (match, rawPath) => {\n const path = String(rawPath).trim();\n const value = getByPath(argsM, path);\n if (value === undefined) return match;\n if (typeof value === \"object\" && value !== null) {\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n }\n return String(value);\n });\n}\n\nfunction resolveToastConfig(toast: boolean | ToastConfig, argsM: ArgsM): boolean | ToastConfig {\n if (typeof toast !== \"object\" || toast === null) {\n return toast;\n }\n\n return {\n message: resolveDynamicValue(toast.message, argsM),\n style: resolveDynamicValue(toast.style, argsM),\n class: resolveDynamicValue(toast.class, argsM),\n position: toast.position,\n stay: resolveDynamicValue(toast.stay, argsM),\n duration: resolveDynamicValue(toast.duration, argsM),\n delay: resolveDynamicValue(toast.delay, argsM),\n };\n}\n\nfunction parseConfig(\n config: Record<string, any>\n): { name: string; options: StoredEmessage } | null {\n const options: EmessageOptions = {};\n let message: DynamicValue<string> | null = null;\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 }\n name = key;\n message = config[key];\n }\n }\n }\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 // Apply default for 'break' if not explicitly set\r\n if (options.break === undefined) {\r\n if (options.type === \"war\" || options.type === \"log\") {\r\n options.break = false;\r\n } else {\r\n // Default for 'err' type or if type is not specified\r\n options.break = true;\r\n }\r\n }\r\n\r\n return { name, options: { ...options, message } };\r\n}\r\n\r\nfunction processEmessage(\n errorName: string,\n config: StoredEmessage,\n argsM: ArgsM,\n errorToThrow?: Error\n): string | void {\n const message = interpolateArgsM(String(resolveDynamicValue(config.message, argsM) ?? \"\"), argsM);\n\n let consoleType: MessageType | false;\n const resolvedType = resolveDynamicValue(config.type, argsM);\n if (resolvedType === false) {\n consoleType = false;\n } else if (resolvedType === true || resolvedType === undefined) {\n consoleType = \"err\";\n } else {\n consoleType = resolvedType;\n }\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 const resolvedToast = resolveDynamicValue(config.toast, argsM);\n if (resolvedToast && isBrowser()) {\n showToast(message, resolveToastConfig(resolvedToast, argsM), consoleType as MessageType);\n }\n\n // 3. Callback\n if (config.callBack) {\n try {\n config.callBack(argsM);\n } catch (e: any) {\n console.error(\n `emessages: Error in callBack for \"${errorName}\":`,\n e.message\r\n );\r\n }\r\n }\r\n\n // 4. Return error message\n if (resolveDynamicValue(config.returnEM, argsM)) {\n return message;\n }\n\n // 5. Break execution\n const resolvedBreak = resolveDynamicValue(config.break, argsM);\n if (resolvedBreak ?? true) {\n if (isBrowser()) {\n throw errorToThrow || new Error(message);\n } else {\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>, argsM: ArgsM = {}): string | void {\n const errorForStack = new Error();\n let config: StoredEmessage | null = null;\n let errorName: string | null = null;\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\n if (config && errorName) {\n errorForStack.message = interpolateArgsM(\n String(resolveDynamicValue(config.message, argsM) ?? \"\"),\n argsM\n );\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1
1
|
{
|
|
2
2
|
"name": "emessages",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
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",
|
|
@@ -27,14 +27,10 @@
|
|
|
27
27
|
"sideEffects": true,
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "tsup"
|
|
31
|
-
"postinstall": "node dist/cli.cjs"
|
|
32
|
-
},
|
|
33
|
-
"bin": {
|
|
34
|
-
"emessages": "./dist/cli.cjs"
|
|
30
|
+
"build": "tsup"
|
|
35
31
|
},
|
|
36
32
|
"devDependencies": {
|
|
37
|
-
"@types/node": "^20.
|
|
33
|
+
"@types/node": "^20.19.33",
|
|
38
34
|
"tsup": "^8.0.2",
|
|
39
35
|
"typescript": "^5.3.3"
|
|
40
36
|
}
|
package/dist/cli.cjs
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
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 readline = __toESM(require("readline"), 1);
|
|
30
|
-
var fileName = "EmessageGlobal";
|
|
31
|
-
var jsContent = `export const Emessage_global = [
|
|
32
|
-
{
|
|
33
|
-
GLOBAL_ERROR_MESSAGE: "Global error message.",
|
|
34
|
-
type:"war",
|
|
35
|
-
break:false,
|
|
36
|
-
toast: true
|
|
37
|
-
},
|
|
38
|
-
// {
|
|
39
|
-
// Add your custom global messages here.
|
|
40
|
-
// }
|
|
41
|
-
];
|
|
42
|
-
`;
|
|
43
|
-
var tsContent = `export const Emessage_global = [
|
|
44
|
-
{
|
|
45
|
-
GLOBAL_ERROR_MESSAGE: "Global error message.",
|
|
46
|
-
type:"war",
|
|
47
|
-
break:false,
|
|
48
|
-
toast: true
|
|
49
|
-
},
|
|
50
|
-
// {
|
|
51
|
-
// Add your custom global messages here.
|
|
52
|
-
// }
|
|
53
|
-
];
|
|
54
|
-
`;
|
|
55
|
-
function findProjectRoot(startDir) {
|
|
56
|
-
let currentDir = startDir;
|
|
57
|
-
while (currentDir !== path.parse(currentDir).root) {
|
|
58
|
-
if (fs.existsSync(path.join(currentDir, "package.json"))) {
|
|
59
|
-
return currentDir;
|
|
60
|
-
}
|
|
61
|
-
currentDir = path.dirname(currentDir);
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
function generateGlobalEmessageFile() {
|
|
66
|
-
const rl = readline.createInterface({
|
|
67
|
-
input: process.stdin,
|
|
68
|
-
output: process.stdout
|
|
69
|
-
});
|
|
70
|
-
rl.question("You want to create EmessageGlobal file: (y) ", (answer) => {
|
|
71
|
-
if (answer.toLowerCase() === "y" || answer.toLowerCase() === "yes" || answer === "") {
|
|
72
|
-
const cwd = process.cwd();
|
|
73
|
-
const projectRoot = findProjectRoot(cwd);
|
|
74
|
-
if (!projectRoot) {
|
|
75
|
-
console.error("Error: Could not find project root (package.json not found).");
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
79
|
-
const isTypeScriptProject = fs.existsSync(tsconfigPath);
|
|
80
|
-
const fileExtension = isTypeScriptProject ? "ts" : "js";
|
|
81
|
-
const content = isTypeScriptProject ? tsContent : jsContent;
|
|
82
|
-
const outputFileName = `${fileName}.${fileExtension}`;
|
|
83
|
-
const outputPath = path.join(projectRoot, outputFileName);
|
|
84
|
-
if (fs.existsSync(outputPath)) {
|
|
85
|
-
console.warn(`Warning: ${outputFileName} already exists. Skipping file creation.`);
|
|
86
|
-
process.exit(0);
|
|
87
|
-
}
|
|
88
|
-
try {
|
|
89
|
-
fs.writeFileSync(outputPath, content, "utf8");
|
|
90
|
-
console.log(`Successfully created ${outputFileName} in your project root.`);
|
|
91
|
-
console.log("You can now configure global messages by editing this file.");
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error(`Error creating ${outputFileName}:`, error.message);
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
rl.close();
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
generateGlobalEmessageFile();
|
|
101
|
-
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as readline from 'readline';\n\nconst fileName = 'EmessageGlobal';\nconst jsContent = `export const Emessage_global = [\n {\n GLOBAL_ERROR_MESSAGE: \"Global error message.\",\n type:\"war\",\n break:false,\n toast: true\n },\n // {\n // Add your custom global messages here.\n // }\n];\n`;\n\nconst tsContent = `export const Emessage_global = [\n {\n GLOBAL_ERROR_MESSAGE: \"Global error message.\",\n type:\"war\",\n break:false,\n toast: true\n },\n // {\n // Add your custom global messages here.\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 rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.question('You want to create EmessageGlobal file: (y) ', (answer) => {\n if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes' || answer === '') {\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 rl.close();\n });\n}\n\ngenerate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AAG,iBAAc,YAAY,SAAS,MAAM;AAC5C,gBAAQ,IAAI,wBAAwB,cAAc,wBAAwB;AAC1E,gBAAQ,IAAI,6DAA6D;AAAA,MAC7E,SAAS,OAAY;AACjB,gBAAQ,MAAM,kBAAkB,cAAc,KAAK,MAAM,OAAO;AAChE,gBAAQ,KAAK,CAAC;AAAA,MAClB;AAAA,IACJ;AACA,OAAG,MAAM;AAAA,EACb,CAAC;AACL;AAEA,2BAA2B;","names":[]}
|
package/dist/cli.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
package/dist/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
package/dist/cli.mjs
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// src/cli.ts
|
|
4
|
-
import * as fs from "fs";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import * as readline from "readline";
|
|
7
|
-
var fileName = "EmessageGlobal";
|
|
8
|
-
var jsContent = `export const Emessage_global = [
|
|
9
|
-
{
|
|
10
|
-
GLOBAL_ERROR_MESSAGE: "Global error message.",
|
|
11
|
-
type:"war",
|
|
12
|
-
break:false,
|
|
13
|
-
toast: true
|
|
14
|
-
},
|
|
15
|
-
// {
|
|
16
|
-
// Add your custom global messages here.
|
|
17
|
-
// }
|
|
18
|
-
];
|
|
19
|
-
`;
|
|
20
|
-
var tsContent = `export const Emessage_global = [
|
|
21
|
-
{
|
|
22
|
-
GLOBAL_ERROR_MESSAGE: "Global error message.",
|
|
23
|
-
type:"war",
|
|
24
|
-
break:false,
|
|
25
|
-
toast: true
|
|
26
|
-
},
|
|
27
|
-
// {
|
|
28
|
-
// Add your custom global messages here.
|
|
29
|
-
// }
|
|
30
|
-
];
|
|
31
|
-
`;
|
|
32
|
-
function findProjectRoot(startDir) {
|
|
33
|
-
let currentDir = startDir;
|
|
34
|
-
while (currentDir !== path.parse(currentDir).root) {
|
|
35
|
-
if (fs.existsSync(path.join(currentDir, "package.json"))) {
|
|
36
|
-
return currentDir;
|
|
37
|
-
}
|
|
38
|
-
currentDir = path.dirname(currentDir);
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
function generateGlobalEmessageFile() {
|
|
43
|
-
const rl = readline.createInterface({
|
|
44
|
-
input: process.stdin,
|
|
45
|
-
output: process.stdout
|
|
46
|
-
});
|
|
47
|
-
rl.question("You want to create EmessageGlobal file: (y) ", (answer) => {
|
|
48
|
-
if (answer.toLowerCase() === "y" || answer.toLowerCase() === "yes" || answer === "") {
|
|
49
|
-
const cwd = process.cwd();
|
|
50
|
-
const projectRoot = findProjectRoot(cwd);
|
|
51
|
-
if (!projectRoot) {
|
|
52
|
-
console.error("Error: Could not find project root (package.json not found).");
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
56
|
-
const isTypeScriptProject = fs.existsSync(tsconfigPath);
|
|
57
|
-
const fileExtension = isTypeScriptProject ? "ts" : "js";
|
|
58
|
-
const content = isTypeScriptProject ? tsContent : jsContent;
|
|
59
|
-
const outputFileName = `${fileName}.${fileExtension}`;
|
|
60
|
-
const outputPath = path.join(projectRoot, outputFileName);
|
|
61
|
-
if (fs.existsSync(outputPath)) {
|
|
62
|
-
console.warn(`Warning: ${outputFileName} already exists. Skipping file creation.`);
|
|
63
|
-
process.exit(0);
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
fs.writeFileSync(outputPath, content, "utf8");
|
|
67
|
-
console.log(`Successfully created ${outputFileName} in your project root.`);
|
|
68
|
-
console.log("You can now configure global messages by editing this file.");
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error(`Error creating ${outputFileName}:`, error.message);
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
rl.close();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
generateGlobalEmessageFile();
|
|
78
|
-
//# sourceMappingURL=cli.mjs.map
|
package/dist/cli.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as readline from 'readline';\n\nconst fileName = 'EmessageGlobal';\nconst jsContent = `export const Emessage_global = [\n {\n GLOBAL_ERROR_MESSAGE: \"Global error message.\",\n type:\"war\",\n break:false,\n toast: true\n },\n // {\n // Add your custom global messages here.\n // }\n];\n`;\n\nconst tsContent = `export const Emessage_global = [\n {\n GLOBAL_ERROR_MESSAGE: \"Global error message.\",\n type:\"war\",\n break:false,\n toast: true\n },\n // {\n // Add your custom global messages here.\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 rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.question('You want to create EmessageGlobal file: (y) ', (answer) => {\n if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes' || answer === '') {\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 rl.close();\n });\n}\n\ngenerateGlobalEmessageFile();\n"],"mappings":";;;AAEA,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,cAAc;AAE1B,IAAM,WAAW;AACjB,IAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAalB,IAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAalB,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,KAAc,yBAAgB;AAAA,IAChC,OAAO,QAAQ;AAAA,IACf,QAAQ,QAAQ;AAAA,EACpB,CAAC;AAED,KAAG,SAAS,gDAAgD,CAAC,WAAW;AACpE,QAAI,OAAO,YAAY,MAAM,OAAO,OAAO,YAAY,MAAM,SAAS,WAAW,IAAI;AACjF,YAAM,MAAM,QAAQ,IAAI;AACxB,YAAM,cAAc,gBAAgB,GAAG;AAEvC,UAAI,CAAC,aAAa;AACd,gBAAQ,MAAM,8DAA8D;AAC5E,gBAAQ,KAAK,CAAC;AAAA,MAClB;AAEA,YAAM,eAAoB,UAAK,aAAa,eAAe;AAC3D,YAAM,sBAAyB,cAAW,YAAY;AAEtD,YAAM,gBAAgB,sBAAsB,OAAO;AACnD,YAAM,UAAU,sBAAsB,YAAY;AAClD,YAAM,iBAAiB,GAAG,QAAQ,IAAI,aAAa;AACnD,YAAM,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