@kwirthmagnify/kwirth-homepage-matrix 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/front.js +87 -8
  2. package/package.json +1 -1
package/front.js CHANGED
@@ -65,7 +65,7 @@
65
65
  var MATRIX_GLOW = "rgba(0,255,65,0.3)";
66
66
  var EVENTS_LIMIT = 25;
67
67
  var POLL_INTERVAL_MS = 1e4;
68
- var MatrixRain = () => {
68
+ var MatrixRain = ({ speed, activeLines }) => {
69
69
  const canvasRef = (0, import_react.useRef)(null);
70
70
  (0, import_react.useEffect)(() => {
71
71
  const canvas = canvasRef.current;
@@ -75,22 +75,41 @@
75
75
  const fontSize = 22;
76
76
  const chars = "\u30A2\u30A4\u30A6\u30A8\u30AA\u30AB\u30AD\u30AF\u30B1\u30B3\u30B5\u30B7\u30B9\u30BB\u30BD\u30BF\u30C1\u30C4\u30C6\u30C8\u30CA\u30CB\u30CC\u30CD\u30CE\u30CF\u30D2\u30D5\u30D8\u30DB\u30DE\u30DF\u30E0\u30E1\u30E2\u30E4\u30E6\u30E8\u30E9\u30EA\u30EB\u30EC\u30ED\u30EF\u30F2\u30F30123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
77
77
  let drops = [];
78
+ let active = [];
78
79
  let animId;
79
80
  let frame = 0;
80
- const SPEED = 12;
81
+ const activateDrops = (cols, h, count) => {
82
+ const indices = Array.from({ length: cols }, (_, i) => i);
83
+ for (let i = indices.length - 1; i > 0; i--) {
84
+ const j = Math.floor(Math.random() * (i + 1));
85
+ [indices[i], indices[j]] = [indices[j], indices[i]];
86
+ }
87
+ const n = Math.min(count, cols);
88
+ indices.slice(0, n).forEach((i) => {
89
+ active[i] = true;
90
+ drops[i] = -Math.floor(Math.random() * (h / fontSize) * 2);
91
+ });
92
+ indices.slice(n).forEach((i) => {
93
+ active[i] = false;
94
+ drops[i] = -99999;
95
+ });
96
+ };
81
97
  const resize = (w, h) => {
82
98
  canvas.width = w;
83
99
  canvas.height = h;
84
100
  const cols = Math.floor(w / fontSize);
85
- drops = Array.from({ length: cols }, () => -Math.floor(Math.random() * (h / fontSize) * 4));
101
+ drops = new Array(cols).fill(0);
102
+ active = new Array(cols).fill(false);
103
+ activateDrops(cols, h, activeLines);
86
104
  };
87
105
  const draw = () => {
88
106
  frame++;
89
107
  ctx.fillStyle = "rgba(0,0,0,0.02)";
90
108
  ctx.fillRect(0, 0, canvas.width, canvas.height);
91
109
  ctx.font = `${fontSize}px monospace`;
92
- if (frame % SPEED === 0) {
110
+ if (frame % speed === 0) {
93
111
  for (let i = 0; i < drops.length; i++) {
112
+ if (!active[i]) continue;
94
113
  if (drops[i] > 0) {
95
114
  const bright = Math.random() > 0.97;
96
115
  ctx.fillStyle = bright ? "#ccffcc" : MATRIX_GREEN;
@@ -114,7 +133,7 @@
114
133
  cancelAnimationFrame(animId);
115
134
  observer.disconnect();
116
135
  };
117
- }, []);
136
+ }, [speed, activeLines]);
118
137
  return /* @__PURE__ */ import_react.default.createElement(
119
138
  "canvas",
120
139
  {
@@ -336,6 +355,10 @@
336
355
  channelObject: { clusterName, view: "cluster", namespace: "", group: "", pod: "", container: "" }
337
356
  });
338
357
  };
358
+ const showQuickAccess = props.config?.showQuickAccess ?? true;
359
+ const showRain = props.config?.showRain ?? true;
360
+ const rainSpeed = props.config?.rainSpeed ?? 12;
361
+ const rainActiveLines = props.config?.rainActiveLines ?? 50;
339
362
  const hasMagnify = props.frontChannels.has("magnify");
340
363
  const hasTopology = props.frontChannels.has("topology");
341
364
  const magnifyClass = props.frontChannels.get("magnify");
@@ -351,7 +374,7 @@
351
374
  boxShadow: `0 0 8px ${MATRIX_GLOW}`
352
375
  }
353
376
  };
354
- return /* @__PURE__ */ import_react.default.createElement(import_material.Box, { ref: containerRef, sx: { position: "relative", width: "100%", height: `${containerHeight}px`, overflow: "hidden", bgcolor: "#000" } }, /* @__PURE__ */ import_react.default.createElement(MatrixRain, null), /* @__PURE__ */ import_react.default.createElement(import_material.Box, { sx: {
377
+ return /* @__PURE__ */ import_react.default.createElement(import_material.Box, { ref: containerRef, sx: { position: "relative", width: "100%", height: `${containerHeight}px`, overflow: "hidden", bgcolor: "#000" } }, showRain && /* @__PURE__ */ import_react.default.createElement(MatrixRain, { speed: rainSpeed, activeLines: rainActiveLines }), /* @__PURE__ */ import_react.default.createElement(import_material.Box, { sx: {
355
378
  position: "relative",
356
379
  zIndex: 1,
357
380
  p: 3,
@@ -361,7 +384,7 @@
361
384
  gridTemplateColumns: "repeat(2, 1fr)",
362
385
  gap: 4,
363
386
  alignContent: "start"
364
- } }, /* @__PURE__ */ import_react.default.createElement(QuickAccessCard, { ...props }), props.clusters.map((cluster, idx) => {
387
+ } }, showQuickAccess && /* @__PURE__ */ import_react.default.createElement(QuickAccessCard, { ...props }), props.clusters.map((cluster, idx) => {
365
388
  const clusterChannelIds = new Set((cluster.kwirthData?.channels ?? []).map((ch) => ch.id));
366
389
  const clusterHasMagnify = hasMagnify && clusterChannelIds.has("magnify");
367
390
  const clusterHasTopology = hasTopology && clusterChannelIds.has("topology");
@@ -419,10 +442,66 @@
419
442
  }), props.clusters.length === 0 && /* @__PURE__ */ import_react.default.createElement(import_material.Typography, { sx: { fontFamily: "monospace", color: MATRIX_GREEN, p: 2, textShadow: `0 0 8px ${MATRIX_GREEN}` } }, "// Entering the matrix...")));
420
443
  };
421
444
 
445
+ // src/front/MatrixSetup.tsx
446
+ var import_react2 = __toESM(require_react(), 1);
447
+ var import_material2 = __toESM(require_material(), 1);
448
+ var MATRIX_GREEN2 = "#00ff41";
449
+ var MATRIX_DIM2 = "#006620";
450
+ var MatrixSetup = ({ config, onSave, onClose }) => {
451
+ const [showQuickAccess, setShowQuickAccess] = (0, import_react2.useState)(config.showQuickAccess ?? true);
452
+ const [showRain, setShowRain] = (0, import_react2.useState)(config.showRain ?? true);
453
+ const [rainSpeed, setRainSpeed] = (0, import_react2.useState)(config.rainSpeed ?? 12);
454
+ const [rainActiveLines, setRainActiveLines] = (0, import_react2.useState)(config.rainActiveLines ?? 50);
455
+ const checkSx = { color: MATRIX_DIM2, "&.Mui-checked": { color: MATRIX_GREEN2 } };
456
+ const labelSx = { fontFamily: "monospace", fontSize: "0.85rem", color: MATRIX_GREEN2 };
457
+ const sliderSx = { color: MATRIX_GREEN2, "& .MuiSlider-thumb": { bgcolor: MATRIX_GREEN2 }, "& .MuiSlider-rail": { bgcolor: MATRIX_DIM2 } };
458
+ return /* @__PURE__ */ import_react2.default.createElement(import_material2.Dialog, { open: true, PaperProps: { sx: { bgcolor: "#000", border: `1px solid ${MATRIX_GREEN2}`, boxShadow: `0 0 20px rgba(0,255,65,0.3)`, color: MATRIX_GREEN2, minWidth: 360 } } }, /* @__PURE__ */ import_react2.default.createElement(import_material2.DialogTitle, { sx: { fontFamily: "monospace", fontSize: "1rem", color: MATRIX_GREEN2, borderBottom: `1px solid ${MATRIX_DIM2}`, pb: 1 } }, "// matrix setup"), /* @__PURE__ */ import_react2.default.createElement(import_material2.DialogContent, null, /* @__PURE__ */ import_react2.default.createElement(import_material2.Stack, { direction: "column", spacing: 2.5, sx: { pt: 2 } }, /* @__PURE__ */ import_react2.default.createElement(
459
+ import_material2.FormControlLabel,
460
+ {
461
+ control: /* @__PURE__ */ import_react2.default.createElement(import_material2.Checkbox, { checked: showQuickAccess, onChange: (e) => setShowQuickAccess(e.target.checked), sx: checkSx }),
462
+ label: /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { sx: labelSx }, "Show tabs / workspaces card")
463
+ }
464
+ ), /* @__PURE__ */ import_react2.default.createElement(
465
+ import_material2.FormControlLabel,
466
+ {
467
+ control: /* @__PURE__ */ import_react2.default.createElement(import_material2.Checkbox, { checked: showRain, onChange: (e) => setShowRain(e.target.checked), sx: checkSx }),
468
+ label: /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { sx: labelSx }, "Falling code")
469
+ }
470
+ ), /* @__PURE__ */ import_react2.default.createElement(import_material2.Stack, { direction: "column", spacing: 0.5, sx: { opacity: showRain ? 1 : 0.3, pointerEvents: showRain ? "auto" : "none" } }, /* @__PURE__ */ import_react2.default.createElement(import_material2.Stack, { direction: "row", justifyContent: "space-between" }, /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { sx: { fontFamily: "monospace", fontSize: "0.75rem", color: MATRIX_DIM2 } }, "Speed"), /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { sx: { fontFamily: "monospace", fontSize: "0.75rem", color: MATRIX_GREEN2 } }, rainSpeed <= 5 ? "fast" : rainSpeed <= 12 ? "normal" : "slow")), /* @__PURE__ */ import_react2.default.createElement(
471
+ import_material2.Slider,
472
+ {
473
+ value: 21 - rainSpeed,
474
+ min: 1,
475
+ max: 20,
476
+ onChange: (_, v) => setRainSpeed(21 - v),
477
+ sx: sliderSx
478
+ }
479
+ ), /* @__PURE__ */ import_react2.default.createElement(import_material2.Stack, { direction: "row", justifyContent: "space-between" }, /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { sx: { fontFamily: "monospace", fontSize: "0.6rem", color: MATRIX_DIM2 } }, "slow"), /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { sx: { fontFamily: "monospace", fontSize: "0.6rem", color: MATRIX_DIM2 } }, "fast"))), /* @__PURE__ */ import_react2.default.createElement(import_material2.Stack, { direction: "column", spacing: 0.5, sx: { opacity: showRain ? 1 : 0.3, pointerEvents: showRain ? "auto" : "none" } }, /* @__PURE__ */ import_react2.default.createElement(import_material2.Stack, { direction: "row", justifyContent: "space-between" }, /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { sx: { fontFamily: "monospace", fontSize: "0.75rem", color: MATRIX_DIM2 } }, "Active lines"), /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { sx: { fontFamily: "monospace", fontSize: "0.75rem", color: MATRIX_GREEN2 } }, rainActiveLines)), /* @__PURE__ */ import_react2.default.createElement(
480
+ import_material2.Slider,
481
+ {
482
+ value: rainActiveLines,
483
+ min: 5,
484
+ max: 100,
485
+ onChange: (_, v) => setRainActiveLines(v),
486
+ sx: sliderSx
487
+ }
488
+ ), /* @__PURE__ */ import_react2.default.createElement(import_material2.Stack, { direction: "row", justifyContent: "space-between" }, /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { sx: { fontFamily: "monospace", fontSize: "0.6rem", color: MATRIX_DIM2 } }, "5"), /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { sx: { fontFamily: "monospace", fontSize: "0.6rem", color: MATRIX_DIM2 } }, "100"))))), /* @__PURE__ */ import_react2.default.createElement(import_material2.DialogActions, { sx: { borderTop: `1px solid ${MATRIX_DIM2}`, pt: 1 } }, /* @__PURE__ */ import_react2.default.createElement(
489
+ import_material2.Button,
490
+ {
491
+ onClick: () => onSave({ showQuickAccess, showRain, rainSpeed, rainActiveLines }),
492
+ variant: "contained",
493
+ sx: { bgcolor: MATRIX_GREEN2, color: "#000", fontFamily: "monospace", fontWeight: "bold", "&:hover": { bgcolor: "#00cc33" } }
494
+ },
495
+ "Save"
496
+ ), /* @__PURE__ */ import_react2.default.createElement(import_material2.Button, { onClick: onClose, sx: { color: MATRIX_DIM2, fontFamily: "monospace" } }, "Cancel")));
497
+ };
498
+
422
499
  // src/front/index.ts
423
500
  window.__kwirth_homepages__["matrix"] = {
424
501
  homepageId: "matrix",
425
502
  displayName: "Matrix",
426
- Component: Matrix
503
+ Component: Matrix,
504
+ SetupDialog: MatrixSetup,
505
+ defaultConfig: { showQuickAccess: true, showRain: true, rainSpeed: 12, rainActiveLines: 50 }
427
506
  };
428
507
  })();
package/package.json CHANGED
@@ -2,6 +2,6 @@
2
2
  "id": "matrix",
3
3
  "name": "@kwirthmagnify/kwirth-homepage-matrix",
4
4
  "displayName": "Matrix",
5
- "version": "0.1.2",
5
+ "version": "0.1.3",
6
6
  "description": "Matrix-style cluster overview homepage for Kwirth"
7
7
  }