simuchat 1.0.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/README.md ADDED
File without changes
@@ -0,0 +1,406 @@
1
+ "use strict";
2
+ var SimuChat = (() => {
3
+ // src/players/Companion.ts
4
+ function AddMessageCompanion(message) {
5
+ const Chat = document.getElementById("Chat");
6
+ const msg = {
7
+ text: message,
8
+ type: "incoming",
9
+ time: GetCurrentTime()
10
+ };
11
+ this.messages.push(msg);
12
+ this.SaveMessages();
13
+ if (Chat) {
14
+ Chat.innerHTML += `
15
+ <div class="message incoming">
16
+ <div class="message-content">
17
+ <div class="message-text">${message}</div>
18
+ <div class="message-meta">
19
+ <span class="sender-name">${this.companionName}</span>
20
+ <span class="time">${msg.time}</span>
21
+ </div>
22
+ </div>
23
+ </div>`;
24
+ setTimeout(() => this.ScrollToBottom(), 0);
25
+ } else {
26
+ console.error("\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 Chat \u0434\u043B\u044F \u0440\u0435\u043D\u0434\u0435\u0440\u0438\u043D\u0433\u0430");
27
+ }
28
+ }
29
+
30
+ // src/players/Ego.ts
31
+ function AddMessageEgo(message) {
32
+ const Chat = document.getElementById("Chat");
33
+ const msg = {
34
+ text: message,
35
+ type: "outgoing",
36
+ time: GetCurrentTime()
37
+ };
38
+ this.messages.push(msg);
39
+ this.SaveMessages();
40
+ if (Chat) {
41
+ Chat.innerHTML += `
42
+ <div class="message outgoing">
43
+ <div class="message-content">
44
+ <div class="message-text">${message}</div>
45
+ <div class="message-meta">
46
+ <span class="sender-name">${this.egoName}</span>
47
+ <span class="time">${msg.time}</span>
48
+ </div>
49
+ </div>
50
+ </div>`;
51
+ setTimeout(() => this.ScrollToBottom(), 0);
52
+ } else {
53
+ console.error("\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 Chat \u0434\u043B\u044F \u0440\u0435\u043D\u0434\u0435\u0440\u0438\u043D\u0433\u0430");
54
+ }
55
+ }
56
+ function AddSampleAnswerEgo(...answers) {
57
+ return new Promise((resolve) => {
58
+ const Choices = document.getElementById("Choices");
59
+ if (Choices) {
60
+ Choices.innerHTML = "";
61
+ answers.forEach((answer) => {
62
+ const btn = document.createElement("button");
63
+ btn.className = "choice-btn";
64
+ btn.textContent = answer;
65
+ btn.addEventListener("click", () => {
66
+ this.lastChoice = answer;
67
+ this.AddMessageEgo(answer);
68
+ Choices.innerHTML = "";
69
+ resolve(answer);
70
+ });
71
+ Choices.appendChild(btn);
72
+ });
73
+ } else {
74
+ console.error("\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 Choices \u0434\u043B\u044F \u0440\u0435\u043D\u0434\u0435\u0440\u0438\u043D\u0433\u0430");
75
+ }
76
+ });
77
+ }
78
+
79
+ // src/Style.ts
80
+ function AddStyle(style, typeStyle) {
81
+ const Main = document.getElementById("Main");
82
+ switch (style) {
83
+ case "default":
84
+ break;
85
+ case "telegram":
86
+ switch (typeStyle) {
87
+ case "Forest":
88
+ if (Main) {
89
+ Main.style.backgroundImage = "url('https://github.com/SimuChat/Assets/blob/main/Telegram/Wallpapers/Forest.jpg?raw=true')";
90
+ } else {
91
+ console.error("\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 Main \u0434\u043B\u044F \u0440\u0435\u043D\u0434\u0435\u0440\u0438\u043D\u0433\u0430");
92
+ }
93
+ break;
94
+ case "Lighthouse":
95
+ if (Main) {
96
+ Main.style.backgroundImage = "url('https://github.com/SimuChat/Assets/blob/main/Telegram/Wallpapers/Lighthouse.jpg?raw=true')";
97
+ } else {
98
+ console.error("\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 Main \u0434\u043B\u044F \u0440\u0435\u043D\u0434\u0435\u0440\u0438\u043D\u0433\u0430");
99
+ }
100
+ break;
101
+ case "Paris":
102
+ if (Main) {
103
+ Main.style.backgroundImage = "url('https://github.com/SimuChat/Assets/blob/main/Telegram/Wallpapers/Paris.jpg?raw=true')";
104
+ } else {
105
+ console.error("\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 Main \u0434\u043B\u044F \u0440\u0435\u043D\u0434\u0435\u0440\u0438\u043D\u0433\u0430");
106
+ }
107
+ break;
108
+ case "Space":
109
+ if (Main) {
110
+ Main.style.backgroundImage = "url('https://github.com/SimuChat/Assets/blob/main/Telegram/Wallpapers/Space.jpg?raw=true')";
111
+ } else {
112
+ console.error("\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 Main \u0434\u043B\u044F \u0440\u0435\u043D\u0434\u0435\u0440\u0438\u043D\u0433\u0430");
113
+ }
114
+ break;
115
+ default:
116
+ console.error(`\u0421\u0442\u0438\u043B\u044C ${typeStyle} \u0432 Telegram \u043D\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442`);
117
+ }
118
+ break;
119
+ case "WhatsApp":
120
+ break;
121
+ default:
122
+ console.error(`\u0421\u0442\u0438\u043B\u044C ${style} \u043D\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442`);
123
+ }
124
+ }
125
+
126
+ // src/Animations.ts
127
+ function AnimTyping() {
128
+ StopAnimTyping();
129
+ const Chat = document.getElementById("Chat");
130
+ if (Chat) {
131
+ Chat.innerHTML += `
132
+ <div class="typing" id="Typing">
133
+ ${this.companionName}<span class="dots"></span>
134
+ </div>
135
+ `;
136
+ setTimeout(() => this.ScrollToBottom(), 0);
137
+ } else {
138
+ console.error("\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 Chat \u0434\u043B\u044F \u0440\u0435\u043D\u0434\u0435\u0440\u0438\u043D\u0433\u0430");
139
+ }
140
+ }
141
+ function StopAnimTyping() {
142
+ document.getElementById("Typing")?.remove();
143
+ }
144
+
145
+ // src/SimuChat.css
146
+ var SimuChat_default = `@import url('https://fonts.googleapis.com/css2?family=Unbounded:wght@200..900&display=swap');\r
147
+ \r
148
+ *,\r
149
+ *::before,\r
150
+ *::after {\r
151
+ box-sizing: border-box;\r
152
+ }\r
153
+ \r
154
+ html, body {\r
155
+ height: 100%;\r
156
+ margin: 0;\r
157
+ padding: 0;\r
158
+ overflow: hidden;\r
159
+ }\r
160
+ \r
161
+ body {\r
162
+ display: flex;\r
163
+ justify-content: center;\r
164
+ align-items: flex-start;\r
165
+ background-color: #f0f2f5;\r
166
+ }\r
167
+ \r
168
+ #Main,\r
169
+ #Main * {\r
170
+ font-family: "Unbounded", sans-serif;\r
171
+ }\r
172
+ \r
173
+ #Main {\r
174
+ width: 100%;\r
175
+ max-width: 500px;\r
176
+ height: 100%;\r
177
+ display: flex;\r
178
+ flex-direction: column;\r
179
+ border: 1px solid #ddd;\r
180
+ border-radius: 12px;\r
181
+ font-optical-sizing: auto;\r
182
+ font-weight: 400;\r
183
+ font-style: normal;\r
184
+ overflow: hidden;\r
185
+ box-shadow: 0 4px 12px rgba(0,0,0,0.08);\r
186
+ margin: 0 auto;\r
187
+ }\r
188
+ \r
189
+ .chat-header {\r
190
+ height: 50px;\r
191
+ display: flex;\r
192
+ justify-content: space-between;\r
193
+ align-items: center;\r
194
+ padding: 0 14px;\r
195
+ border-bottom: 1px solid #eee;\r
196
+ background-color: #fff;\r
197
+ font-weight: bold;\r
198
+ color: #111;\r
199
+ }\r
200
+ \r
201
+ .chat-status {\r
202
+ font-size: 12px;\r
203
+ color: #28a745;\r
204
+ }\r
205
+ \r
206
+ .chat-messages {\r
207
+ flex: 1;\r
208
+ padding: 10px;\r
209
+ display: flex;\r
210
+ flex-direction: column;\r
211
+ gap: 4px;\r
212
+ overflow-y: auto;\r
213
+ min-height: 0;\r
214
+ }\r
215
+ \r
216
+ .message {\r
217
+ display: flex;\r
218
+ flex-direction: column;\r
219
+ max-width: 75%;\r
220
+ }\r
221
+ \r
222
+ .message-content {\r
223
+ display: flex;\r
224
+ flex-direction: column;\r
225
+ }\r
226
+ \r
227
+ .message.incoming {\r
228
+ align-self: flex-start;\r
229
+ }\r
230
+ \r
231
+ .message.incoming .message-text {\r
232
+ background-color: #e5e5ea;\r
233
+ color: #000;\r
234
+ padding: 8px 12px;\r
235
+ border-radius: 16px 16px 16px 0;\r
236
+ }\r
237
+ \r
238
+ .message.incoming .message-meta {\r
239
+ font-size: 11px;\r
240
+ color: #555;\r
241
+ margin-top: 2px;\r
242
+ display: flex;\r
243
+ gap: 6px;\r
244
+ }\r
245
+ \r
246
+ .message.outgoing {\r
247
+ align-self: flex-end;\r
248
+ }\r
249
+ \r
250
+ .message.outgoing .message-text {\r
251
+ background-color: #007bff;\r
252
+ color: #fff;\r
253
+ padding: 8px 12px;\r
254
+ border-radius: 16px 16px 0 16px;\r
255
+ }\r
256
+ \r
257
+ .message.outgoing .message-meta {\r
258
+ font-size: 11px;\r
259
+ color: #555;\r
260
+ margin-top: 2px;\r
261
+ display: flex;\r
262
+ gap: 6px;\r
263
+ justify-content: flex-end;\r
264
+ }\r
265
+ \r
266
+ .message-choices {\r
267
+ display: flex;\r
268
+ flex-direction: column;\r
269
+ padding: 10px;\r
270
+ gap: 4px;\r
271
+ border-top: 1px solid #eee;\r
272
+ background-color: #fff;\r
273
+ }\r
274
+ \r
275
+ .choice-btn {\r
276
+ border: 1px solid #ccc;\r
277
+ border-radius: 20px;\r
278
+ padding: 8px 12px;\r
279
+ background-color: #fff;\r
280
+ cursor: pointer;\r
281
+ text-align: left;\r
282
+ font-size: 14px;\r
283
+ transition: background-color 0.2s;\r
284
+ }\r
285
+ \r
286
+ .choice-btn:hover {\r
287
+ background-color: #f0f0f0;\r
288
+ }\r
289
+ \r
290
+ .typing {\r
291
+ font-size: 13px;\r
292
+ color: #666;\r
293
+ padding-top: 10px;\r
294
+ }\r
295
+ \r
296
+ .dots::after {\r
297
+ content: "";\r
298
+ animation: dots 1.5s infinite;\r
299
+ }\r
300
+ \r
301
+ @keyframes dots {\r
302
+ 0% { content: ""; }\r
303
+ 33% { content: "."; }\r
304
+ 66% { content: ".."; }\r
305
+ 100% { content: "..."; }\r
306
+ }`;
307
+
308
+ // src/SimuChat.ts
309
+ var SimuChat = class {
310
+ messages;
311
+ stepIndex = 0;
312
+ stepKey = "SimuChatStep";
313
+ lastChoice = null;
314
+ egoName;
315
+ companionName;
316
+ RenderMessages() {
317
+ const Chat = document.getElementById("Chat");
318
+ if (!Chat) {
319
+ console.error("\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 Chat \u0434\u043B\u044F \u0440\u0435\u043D\u0434\u0435\u0440\u0438\u043D\u0433\u0430");
320
+ return;
321
+ }
322
+ Chat.innerHTML = "";
323
+ const Data = localStorage.getItem("Messages");
324
+ if (!Data) return;
325
+ this.messages = JSON.parse(Data);
326
+ this.messages.forEach((msg) => {
327
+ Chat.innerHTML += `
328
+ <div class="message ${msg.type}">
329
+ <div class="message-content">
330
+ <div class="message-text">${msg.text}</div>
331
+ <div class="message-meta">
332
+ <span class="sender-name">${msg.type === "incoming" ? this.companionName : this.egoName}</span>
333
+ <span class="time">${msg.time}</span>
334
+ </div>
335
+ </div>
336
+ </div>`;
337
+ });
338
+ setTimeout(() => this.ScrollToBottom(), 0);
339
+ }
340
+ ScrollToBottom() {
341
+ const Chat = document.getElementById("Chat");
342
+ if (!Chat) return;
343
+ Chat.scrollTop = Chat.scrollHeight;
344
+ }
345
+ SaveMessages() {
346
+ localStorage.setItem("Messages", JSON.stringify(this.messages));
347
+ }
348
+ SaveStep() {
349
+ localStorage.setItem(this.stepKey, String(this.stepIndex));
350
+ }
351
+ LoadStep() {
352
+ const Step = localStorage.getItem(this.stepKey);
353
+ if (Step) this.stepIndex = Number(Step);
354
+ }
355
+ constructor(egoName, companionName, style, typeStyle) {
356
+ this.messages = [];
357
+ this.egoName = egoName;
358
+ this.companionName = companionName;
359
+ const StyleCSS = document.createElement("style");
360
+ StyleCSS.textContent = SimuChat_default;
361
+ document.head.appendChild(StyleCSS);
362
+ const Main = document.getElementById("Main");
363
+ if (Main) {
364
+ Main.innerHTML = `
365
+ <div class="chat-header">
366
+ <span class="chat-title">${this.companionName}</span>
367
+ <span class="chat-status">\u25CF \u0432 \u0441\u0435\u0442\u0438</span>
368
+ </div>
369
+
370
+ <div id="Chat" class="chat-messages"></div>
371
+
372
+ <div id="Choices" class="message-choices"></div>`;
373
+ } else {
374
+ console.error("\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 Main \u0434\u043B\u044F \u0440\u0435\u043D\u0434\u0435\u0440\u0438\u043D\u0433\u0430");
375
+ }
376
+ AddStyle(style, typeStyle);
377
+ this.RenderMessages();
378
+ this.LoadStep();
379
+ setTimeout(() => this.ScrollToBottom(), 0);
380
+ }
381
+ async run(steps) {
382
+ for (let i = this.stepIndex; i < steps.length; i++) {
383
+ await steps[i]();
384
+ this.stepIndex++;
385
+ this.SaveStep();
386
+ }
387
+ }
388
+ AddMessageCompanion = AddMessageCompanion;
389
+ AddMessageEgo = AddMessageEgo;
390
+ AddSampleAnswerEgo = AddSampleAnswerEgo;
391
+ AnimTyping = AnimTyping;
392
+ StopAnimTyping = StopAnimTyping;
393
+ Delay(duration) {
394
+ return new Promise((resolve) => setTimeout(resolve, duration));
395
+ }
396
+ };
397
+ function GetCurrentTime() {
398
+ const now = /* @__PURE__ */ new Date();
399
+ const hours = String(now.getHours()).padStart(2, "0");
400
+ const minutes = String(now.getMinutes()).padStart(2, "0");
401
+ return `${hours}:${minutes}`;
402
+ }
403
+
404
+ // index.ts
405
+ window.SimuChat = SimuChat;
406
+ })();
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "simuchat",
3
+ "version": "1.0.0",
4
+ "description": "SimuChat is a lightweight TypeScript library for building interactive chat simulations and dialogue-based experiences directly in the browser",
5
+ "keywords": ["SimuChat", "Messenger", "Chat", "Simulation", "Browser", "TypeScript", "JavaScript"],
6
+ "homepage": "",
7
+ "license": "MIT",
8
+ "files": ["dist"],
9
+ "main": "dist/SimuChat.js",
10
+ "bugs": {
11
+ "url": "https://",
12
+ "email": "sigmentiumplay@gmail.com"
13
+ },
14
+ "scripts": {
15
+ "build": "npx esbuild index.ts --bundle --outfile=dist/SimuChat.js --platform=browser --format=iife --global-name=SimuChat --loader:.css=text",
16
+ "prepublishOnly": "npm run build"
17
+ },
18
+ "dependencies": {
19
+ "esbuild": "^0.27.4"
20
+ }
21
+ }