@evgkch/reactive-dom 0.1.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.
@@ -0,0 +1,260 @@
1
+ import * as R from "@evgkch/reactive";
2
+ import * as UI from "@evgkch/reactive-dom";
3
+
4
+ if (typeof document !== "undefined" && document.getElementById("app")) {
5
+ R.configure({ log: true });
6
+ UI.configure({ log: true });
7
+ }
8
+
9
+ // ── состояние ──────────────────────────────────────────────────────────────
10
+
11
+ const filter = R.Value("all");
12
+ const cpu = R.Value(42);
13
+ const mem = R.Value(61);
14
+ const uptime = R.Value(0);
15
+
16
+ const tasks = R.List([
17
+ R.Struct({ text: "infiltrate server", done: false }),
18
+ R.Struct({ text: "extract data", done: true }),
19
+ R.Struct({ text: "cover tracks", done: false }),
20
+ ]);
21
+
22
+ // fake metrics — change every second (only in browser)
23
+ if (typeof document !== "undefined" && document.getElementById("app")) {
24
+ setInterval(() => {
25
+ cpu.set(Math.max(10, Math.min(99, cpu.get() + Math.floor(Math.random() * 11) - 5)));
26
+ mem.set(Math.max(20, Math.min(95, mem.get() + Math.floor(Math.random() * 7) - 3)));
27
+ uptime.update((n) => n + 1);
28
+ }, 1000);
29
+ }
30
+
31
+ // ── утилиты ───────────────────────────────────────────────────────────────
32
+
33
+ function fmtUptime(s) {
34
+ const h = String(Math.floor(s / 3600)).padStart(2, '0');
35
+ const m = String(Math.floor((s % 3600) / 60)).padStart(2, '0');
36
+ const sec = String(s % 60).padStart(2, '0');
37
+ return `${h}:${m}:${sec}`;
38
+ }
39
+
40
+ function barClass(val) {
41
+ if (val >= 85) return 'crit';
42
+ if (val >= 65) return 'warn';
43
+ return '';
44
+ }
45
+
46
+ // ── TaskItem ──────────────────────────────────────────────────────────────
47
+
48
+ const TaskItem = UI.List(
49
+ `<li>
50
+ <input type="checkbox" class="task-check" data-ref="check" />
51
+ <span class="task-text" data-ref="text"></span>
52
+ <span class="task-status" data-ref="status"></span>
53
+ <button class="task-remove" data-ref="remove">kill</button>
54
+ </li>`,
55
+ (props, refs, ctx) => {
56
+ const check = refs.check;
57
+
58
+ ctx.batch(() => {
59
+ refs.text.textContent = props.item.text;
60
+ check.checked = props.item.done;
61
+ refs.el.className = props.item.done ? "done" : "";
62
+ refs.status.textContent = props.item.done ? "DONE" : "RUNNING";
63
+
64
+ const f = filter.get();
65
+ refs.el.style.display =
66
+ f === "all" ? "" :
67
+ f === "active" ? (props.item.done ? "none" : "") :
68
+ f === "done" ? (props.item.done ? "" : "none") : "";
69
+ });
70
+
71
+ check.onchange = () => { props.item.done = check.checked; };
72
+ refs.remove.onclick = () => tasks.splice(tasks.indexOf(props.item), 1);
73
+ }
74
+ );
75
+
76
+ // ── App ───────────────────────────────────────────────────────────────────
77
+
78
+ const App = UI.Struct(
79
+ `<div class="monitor">
80
+
81
+ <div class="titlebar">
82
+ <div class="titlebar-left">
83
+ <span class="dot dot-red"></span>
84
+ <span class="dot dot-yellow"></span>
85
+ <span class="dot dot-green"></span>
86
+ <span class="titlebar-title">SYS://TASK_MONITOR</span>
87
+ </div>
88
+ <div class="titlebar-right" data-ref="uptime">UP 00:00:00</div>
89
+ </div>
90
+
91
+ <div class="metrics">
92
+ <div class="metric">
93
+ <div class="metric-label">CPU</div>
94
+ <div class="metric-bar"><div class="metric-fill" data-ref="cpu-bar"></div></div>
95
+ <div class="metric-val" data-ref="cpu-val">0%</div>
96
+ </div>
97
+ <div class="metric">
98
+ <div class="metric-label">MEM</div>
99
+ <div class="metric-bar"><div class="metric-fill" data-ref="mem-bar"></div></div>
100
+ <div class="metric-val" data-ref="mem-val">0%</div>
101
+ </div>
102
+ <div class="metric">
103
+ <div class="metric-label">PROCS</div>
104
+ <div class="metric-bar"><div class="metric-fill" data-ref="procs-bar" style="background:#4488ff"></div></div>
105
+ <div class="metric-val" data-ref="procs-val">0</div>
106
+ </div>
107
+ </div>
108
+
109
+ <div class="input-row">
110
+ <span class="prompt">$</span>
111
+ <input class="new-input" data-ref="input" placeholder="spawn process..." />
112
+ <span class="kbd-hint">↵ enter</span>
113
+ </div>
114
+
115
+ <ul class="task-list" data-ref="list"></ul>
116
+ <p class="empty" data-ref="empty">no processes running</p>
117
+
118
+ <div class="statusbar">
119
+ <div class="status-left" data-ref="stats">
120
+ <span>procs: <span data-ref="total">0</span></span>
121
+ <span>running: <span data-ref="running">0</span></span>
122
+ <span>done: <span data-ref="done-count">0</span></span>
123
+ </div>
124
+ <div class="filters" data-ref="filters">
125
+ <button data-filter="all">all</button>
126
+ <button data-filter="active">running</button>
127
+ <button data-filter="done">done</button>
128
+ </div>
129
+ </div>
130
+
131
+ <div class="hotkeys">
132
+ <div class="hotkey"><kbd>↵</kbd> spawn</div>
133
+ <div class="hotkey"><kbd>1</kbd> all</div>
134
+ <div class="hotkey"><kbd>2</kbd> running</div>
135
+ <div class="hotkey"><kbd>3</kbd> done</div>
136
+ <div class="hotkey"><kbd>⌫</kbd> kill last</div>
137
+ <div class="hotkey"><kbd>ESC</kbd> clear</div>
138
+ </div>
139
+
140
+ </div>`,
141
+
142
+ (props, refs, ctx) => {
143
+ const input = refs.input;
144
+
145
+ // ── список ──────────────────────────────────────────────────────────
146
+ ctx.list(refs.list, tasks, (item) => ({ item }), TaskItem, {
147
+ onAdd: (el) =>
148
+ el.animate([
149
+ { opacity: 0, transform: "translateX(-8px)" },
150
+ { opacity: 1, transform: "translateX(0)" }
151
+ ], 160),
152
+ onRemove: (el, done) =>
153
+ el.animate([
154
+ { opacity: 1, transform: "translateX(0)" },
155
+ { opacity: 0, transform: "translateX(8px)" }
156
+ ], 130).finished.then(done),
157
+ });
158
+
159
+ // ── метрики ──────────────────────────────────────────────────────────
160
+ ctx.batch(() => {
161
+ const v = cpu.get();
162
+ refs['cpu-bar'].style.width = v + '%';
163
+ refs['cpu-bar'].className = 'metric-fill ' + barClass(v);
164
+ refs['cpu-val'].textContent = v + '%';
165
+ });
166
+
167
+ ctx.batch(() => {
168
+ const v = mem.get();
169
+ refs['mem-bar'].style.width = v + '%';
170
+ refs['mem-bar'].className = 'metric-fill ' + barClass(v);
171
+ refs['mem-val'].textContent = v + '%';
172
+ });
173
+
174
+ ctx.batch(() => {
175
+ const total = tasks.length;
176
+ const max = Math.max(total, 1);
177
+ refs['procs-bar'].style.width = Math.min(total / 10 * 100, 100) + '%';
178
+ refs['procs-val'].textContent = total;
179
+ });
180
+
181
+ ctx.batch(() => {
182
+ refs.uptime.textContent = 'UP ' + fmtUptime(uptime.get());
183
+ });
184
+
185
+ // ── статистика ────────────────────────────────────────────────────────
186
+ ctx.batch(() => {
187
+ let running = 0;
188
+ tasks.forEach(t => { if (!t.done) running++ });
189
+ const total = tasks.length;
190
+ const done = total - running;
191
+ refs.total.textContent = total;
192
+ refs.running.textContent = running;
193
+ refs['done-count'].textContent = done;
194
+ refs.empty.style.display = total === 0 ? 'block' : 'none';
195
+ });
196
+
197
+ // ── фильтры ──────────────────────────────────────────────────────────
198
+ ctx.batch(() => {
199
+ refs.filters.querySelectorAll('[data-filter]').forEach(btn => {
200
+ btn.className = filter.get() === btn.getAttribute('data-filter') ? 'active' : '';
201
+ });
202
+ });
203
+
204
+ refs.filters.addEventListener('click', e => {
205
+ const f = e.target?.getAttribute?.('data-filter');
206
+ if (f) filter.set(f);
207
+ });
208
+
209
+ // ── добавление ───────────────────────────────────────────────────────
210
+ function addTask() {
211
+ const text = input.value.trim();
212
+ if (!text) return;
213
+ tasks.push(R.Struct({ text, done: false }));
214
+ input.value = '';
215
+ }
216
+
217
+ input.addEventListener('keydown', e => {
218
+ if (e.key === 'Enter') addTask();
219
+ });
220
+
221
+ // ── горячие клавиши ──────────────────────────────────────────────────
222
+ document.addEventListener('keydown', e => {
223
+ // не перехватываем когда фокус в инпуте (кроме ESC и Backspace)
224
+ const inInput = document.activeElement === input;
225
+
226
+ if (e.key === 'Escape') {
227
+ input.value = '';
228
+ input.blur();
229
+ return;
230
+ }
231
+
232
+ if (inInput) return;
233
+
234
+ if (e.key === '1') { filter.set('all'); return; }
235
+ if (e.key === '2') { filter.set('active'); return; }
236
+ if (e.key === '3') { filter.set('done'); return; }
237
+
238
+ if (e.key === 'Backspace') {
239
+ // kill last — удалить последний незавершённый процесс
240
+ for (let i = tasks.length - 1; i >= 0; i--) {
241
+ if (!tasks[i].done) {
242
+ tasks.splice(i, 1);
243
+ break;
244
+ }
245
+ }
246
+ return;
247
+ }
248
+
249
+ // любой printable символ → фокус на инпут
250
+ if (e.key.length === 1 && !e.ctrlKey && !e.metaKey) {
251
+ input.focus();
252
+ }
253
+ });
254
+ }
255
+ );
256
+
257
+ export { App, filter, tasks };
258
+ if (typeof document !== "undefined" && document.getElementById("app")) {
259
+ document.getElementById("app").appendChild(App({}));
260
+ }
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Monitor — reactive-dom</title>
7
+ <script type="importmap">
8
+ {
9
+ "imports": {
10
+ "@evgkch/reactive": "/node_modules/@evgkch/reactive/dist/index.js",
11
+ "@evgkch/reactive-dom": "/dist/index.js"
12
+ }
13
+ }
14
+ </script>
15
+ <link rel="preconnect" href="https://fonts.googleapis.com">
16
+ <link href="https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@700;900&display=swap" rel="stylesheet">
17
+ <link rel="stylesheet" href="./styles.css">
18
+ </head>
19
+ <body>
20
+ <div id="app"></div>
21
+ <script type="module" src="./app.js"></script>
22
+ </body>
23
+ </html>
@@ -0,0 +1,425 @@
1
+ @import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap");
2
+
3
+ *,
4
+ *::before,
5
+ *::after {
6
+ box-sizing: border-box;
7
+ margin: 0;
8
+ padding: 0;
9
+ }
10
+
11
+ :root {
12
+ --bg: #080808;
13
+ --surface: #0f0f0f;
14
+ --border: #2a2a2a;
15
+ --ink: #d0d0d0;
16
+ --muted: #666;
17
+ --dim: #444;
18
+ --accent: #39ff14;
19
+ --red: #ff3333;
20
+ --yellow: #ffcc00;
21
+ --blue: #4488ff;
22
+ }
23
+
24
+ body {
25
+ font-family: "JetBrains Mono", monospace;
26
+ background: var(--bg);
27
+ color: var(--ink);
28
+ min-height: 100vh;
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: center;
32
+ padding: 2rem 1rem;
33
+ font-size: 12px;
34
+ line-height: 1.5;
35
+ }
36
+
37
+ /* ── монитор — основной контейнер ── */
38
+ .monitor {
39
+ width: 100%;
40
+ max-width: 480px;
41
+ border: 1px solid var(--border);
42
+ background: var(--surface);
43
+ }
44
+
45
+ /* ── строка с рамкой ── */
46
+ .row {
47
+ display: flex;
48
+ align-items: stretch;
49
+ border-bottom: 1px solid var(--border);
50
+ }
51
+
52
+ .row:last-child {
53
+ border-bottom: none;
54
+ }
55
+
56
+ .cell {
57
+ padding: 0.5rem 0.75rem;
58
+ flex: 1;
59
+ }
60
+
61
+ .cell + .cell {
62
+ border-left: 1px solid var(--border);
63
+ }
64
+
65
+ /* ── заголовок ── */
66
+ .titlebar {
67
+ display: flex;
68
+ align-items: center;
69
+ justify-content: space-between;
70
+ padding: 0.4rem 0.75rem;
71
+ border-bottom: 1px solid var(--border);
72
+ background: var(--bg);
73
+ }
74
+
75
+ .titlebar-left {
76
+ display: flex;
77
+ align-items: center;
78
+ gap: 0.5rem;
79
+ }
80
+
81
+ .dot {
82
+ width: 8px;
83
+ height: 8px;
84
+ border-radius: 50%;
85
+ display: inline-block;
86
+ }
87
+
88
+ .dot-red {
89
+ background: var(--red);
90
+ }
91
+ .dot-yellow {
92
+ background: var(--yellow);
93
+ }
94
+ .dot-green {
95
+ background: var(--accent);
96
+ }
97
+
98
+ .titlebar-title {
99
+ font-size: 11px;
100
+ font-weight: 700;
101
+ color: var(--ink);
102
+ letter-spacing: 0.1em;
103
+ margin-left: 0.5rem;
104
+ }
105
+
106
+ .titlebar-right {
107
+ font-size: 10px;
108
+ color: var(--muted);
109
+ letter-spacing: 0.05em;
110
+ }
111
+
112
+ /* ── метрики ── */
113
+ .metrics {
114
+ display: grid;
115
+ grid-template-columns: 1fr 1fr 1fr;
116
+ border-bottom: 1px solid var(--border);
117
+ }
118
+
119
+ .metric {
120
+ padding: 0.5rem 0.75rem;
121
+ border-right: 1px solid var(--border);
122
+ }
123
+
124
+ .metric:last-child {
125
+ border-right: none;
126
+ }
127
+
128
+ .metric-label {
129
+ font-size: 10px;
130
+ color: var(--muted);
131
+ letter-spacing: 0.08em;
132
+ margin-bottom: 0.25rem;
133
+ }
134
+
135
+ .metric-bar {
136
+ height: 3px;
137
+ background: var(--border);
138
+ margin-bottom: 0.2rem;
139
+ position: relative;
140
+ }
141
+
142
+ .metric-fill {
143
+ height: 100%;
144
+ background: var(--accent);
145
+ transition: width 0.8s ease;
146
+ }
147
+
148
+ .metric-fill.warn {
149
+ background: var(--yellow);
150
+ }
151
+ .metric-fill.crit {
152
+ background: var(--red);
153
+ }
154
+
155
+ .metric-val {
156
+ font-size: 11px;
157
+ font-weight: 700;
158
+ color: var(--ink);
159
+ }
160
+
161
+ /* ── input ── */
162
+ .input-row {
163
+ display: flex;
164
+ align-items: center;
165
+ border-bottom: 1px solid var(--border);
166
+ padding: 0 0.75rem;
167
+ background: var(--bg);
168
+ }
169
+
170
+ .prompt {
171
+ color: var(--accent);
172
+ font-weight: 700;
173
+ margin-right: 0.5rem;
174
+ flex-shrink: 0;
175
+ font-size: 12px;
176
+ }
177
+
178
+ .new-input {
179
+ flex: 1;
180
+ font-family: "JetBrains Mono", monospace;
181
+ font-size: 12px;
182
+ background: transparent;
183
+ border: none;
184
+ padding: 0.55rem 0;
185
+ color: var(--ink);
186
+ outline: none;
187
+ caret-color: var(--accent);
188
+ }
189
+
190
+ .new-input::placeholder {
191
+ color: var(--dim);
192
+ }
193
+
194
+ .kbd-hint {
195
+ font-size: 10px;
196
+ color: var(--dim);
197
+ flex-shrink: 0;
198
+ }
199
+
200
+ /* ── task list ── */
201
+ .task-list {
202
+ list-style: none;
203
+ min-height: 2rem;
204
+ }
205
+
206
+ .task-list li {
207
+ display: grid;
208
+ grid-template-columns: 18px 1fr auto auto;
209
+ align-items: center;
210
+ gap: 0.6rem;
211
+ padding: 0.45rem 0.75rem;
212
+ border-bottom: 1px solid #1a1a1a;
213
+ transition: background 0.1s;
214
+ cursor: default;
215
+ visibility: visible;
216
+ opacity: 1;
217
+ }
218
+
219
+ .task-list li:last-child {
220
+ border-bottom: none;
221
+ }
222
+ .task-list li:hover {
223
+ background: #131313;
224
+ }
225
+ .task-list li.done {
226
+ opacity: 0.5;
227
+ }
228
+ .task-list li.selected {
229
+ background: #141a14;
230
+ }
231
+
232
+ /* checkbox */
233
+ .task-check {
234
+ appearance: none;
235
+ width: 14px;
236
+ height: 14px;
237
+ border: 1px solid var(--muted);
238
+ cursor: pointer;
239
+ position: relative;
240
+ flex-shrink: 0;
241
+ transition: border-color 0.1s;
242
+ }
243
+
244
+ .task-check:hover {
245
+ border-color: var(--accent);
246
+ }
247
+ .task-check:checked {
248
+ border-color: var(--accent);
249
+ }
250
+
251
+ .task-check:checked::after {
252
+ content: "✓";
253
+ position: absolute;
254
+ inset: 0;
255
+ display: flex;
256
+ align-items: center;
257
+ justify-content: center;
258
+ font-size: 10px;
259
+ color: var(--accent);
260
+ font-weight: 700;
261
+ }
262
+
263
+ /* text */
264
+ .task-text {
265
+ font-size: 12px;
266
+ word-break: break-word;
267
+ color: var(--ink);
268
+ }
269
+
270
+ .task-list li.done .task-text {
271
+ color: var(--muted);
272
+ text-decoration: line-through;
273
+ text-decoration-color: #444;
274
+ }
275
+
276
+ /* status badge */
277
+ .task-status {
278
+ font-size: 10px;
279
+ letter-spacing: 0.06em;
280
+ color: var(--muted);
281
+ flex-shrink: 0;
282
+ width: 52px;
283
+ text-align: right;
284
+ }
285
+
286
+ .task-list li:not(.done) .task-status {
287
+ color: var(--blue);
288
+ }
289
+ .task-list li.done .task-status {
290
+ color: var(--dim);
291
+ }
292
+
293
+ /* remove */
294
+ .task-remove {
295
+ font-family: "JetBrains Mono", monospace;
296
+ font-size: 10px;
297
+ background: none;
298
+ border: none;
299
+ color: var(--dim);
300
+ cursor: pointer;
301
+ padding: 0.1rem 0.2rem;
302
+ opacity: 0;
303
+ transition:
304
+ opacity 0.1s,
305
+ color 0.1s;
306
+ flex-shrink: 0;
307
+ }
308
+
309
+ .task-list li:hover .task-remove {
310
+ opacity: 1;
311
+ }
312
+ .task-remove:hover {
313
+ color: var(--red);
314
+ }
315
+
316
+ /* ── footer ── */
317
+ .statusbar {
318
+ display: flex;
319
+ align-items: center;
320
+ justify-content: space-between;
321
+ padding: 0.35rem 0.75rem;
322
+ border-top: 1px solid var(--border);
323
+ background: var(--bg);
324
+ }
325
+
326
+ .status-left {
327
+ font-size: 10px;
328
+ color: var(--muted);
329
+ display: flex;
330
+ gap: 1rem;
331
+ }
332
+
333
+ .status-left span {
334
+ color: var(--ink);
335
+ }
336
+
337
+ .filters {
338
+ display: flex;
339
+ gap: 0;
340
+ }
341
+
342
+ .filters button {
343
+ font-family: "JetBrains Mono", monospace;
344
+ font-size: 10px;
345
+ background: none;
346
+ border: 1px solid transparent;
347
+ color: var(--muted);
348
+ cursor: pointer;
349
+ padding: 0.15rem 0.5rem;
350
+ letter-spacing: 0.05em;
351
+ transition:
352
+ color 0.1s,
353
+ border-color 0.1s;
354
+ }
355
+
356
+ .filters button:hover {
357
+ color: var(--ink);
358
+ }
359
+
360
+ .filters button.active {
361
+ color: var(--accent);
362
+ border-color: var(--border);
363
+ }
364
+
365
+ /* ── hotkeys panel ── */
366
+ .hotkeys {
367
+ display: flex;
368
+ gap: 1rem;
369
+ padding: 0.35rem 0.75rem;
370
+ border-top: 1px solid var(--border);
371
+ background: var(--bg);
372
+ flex-wrap: wrap;
373
+ }
374
+
375
+ .hotkey {
376
+ font-size: 10px;
377
+ color: var(--dim);
378
+ display: flex;
379
+ align-items: center;
380
+ gap: 0.3rem;
381
+ }
382
+
383
+ .hotkey kbd {
384
+ font-family: "JetBrains Mono", monospace;
385
+ font-size: 9px;
386
+ background: var(--border);
387
+ color: var(--ink);
388
+ padding: 0.1rem 0.3rem;
389
+ border-radius: 2px;
390
+ border-bottom: 1px solid #333;
391
+ }
392
+
393
+ /* ── empty ── */
394
+ .empty {
395
+ padding: 1.25rem 0.75rem;
396
+ font-size: 11px;
397
+ color: var(--dim);
398
+ border-bottom: 1px solid #1a1a1a;
399
+ }
400
+
401
+ .empty::before {
402
+ content: "// ";
403
+ color: var(--border);
404
+ }
405
+
406
+ /* ── анимация курсора в title ── */
407
+ .cursor {
408
+ display: inline-block;
409
+ width: 7px;
410
+ height: 13px;
411
+ background: var(--accent);
412
+ margin-left: 3px;
413
+ vertical-align: middle;
414
+ animation: blink 1s step-end infinite;
415
+ }
416
+
417
+ @keyframes blink {
418
+ 0%,
419
+ 100% {
420
+ opacity: 1;
421
+ }
422
+ 50% {
423
+ opacity: 0;
424
+ }
425
+ }