@mingxy/opencode-mascot 0.4.27 → 0.4.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/opencode-mascot",
3
- "version": "0.4.27",
3
+ "version": "0.4.29",
4
4
  "description": "OpenCode TUI mascot plugin framework - customizable ASCII mascots for your terminal",
5
5
  "author": "mingxy",
6
6
  "license": "MIT",
@@ -20,11 +20,16 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
20
20
  const initialName = names[Math.floor(Math.random() * names.length)];
21
21
 
22
22
  const cw = (typeof process !== "undefined" && process.stdout?.columns) || 80;
23
+ const ch = (typeof process !== "undefined" && process.stdout?.rows) || 24;
24
+
25
+ const initX = Math.floor(Math.random() * Math.max(0, cw - 12));
26
+ const initY = -(Math.floor(Math.random() * Math.min(ch - 8, 15)) + 3);
23
27
 
24
28
  const [currentName, setCurrentName] = createSignal(initialName);
25
- const [posX, setPosX] = createSignal(Math.floor(Math.random() * Math.max(0, cw - 20)));
26
- const [posY, setPosY] = createSignal(Math.floor(Math.random() * 3));
27
29
  const [zBoost, setZBoost] = createSignal(false);
30
+ let boxRef: any = null;
31
+ let curX = initX;
32
+ let curY = initY;
28
33
  let dragStartX = 0;
29
34
  let dragStartY = 0;
30
35
  let dragAnchorX = 0;
@@ -43,6 +48,13 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
43
48
  setCurrentName(names[(idx + 1) % names.length]);
44
49
  };
45
50
 
51
+ const applyPos = () => {
52
+ if (boxRef) {
53
+ boxRef.translateX = curX;
54
+ boxRef.translateY = curY;
55
+ }
56
+ };
57
+
46
58
  onCelebrate((newVersion) => {
47
59
  setZBoost(true);
48
60
  renderers[currentName()].celebrateUpdate(newVersion);
@@ -66,10 +78,12 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
66
78
 
67
79
  return (
68
80
  <box
69
- left={posX()}
70
- top={posY()}
71
81
  zIndex={zBoost() ? 9999 : 100}
72
82
  flexDirection="column"
83
+ ref={(node: any) => {
84
+ boxRef = node;
85
+ applyPos();
86
+ }}
73
87
  onMouseDown={(e: any) => {
74
88
  const now = Date.now();
75
89
  if (now - lastClickTime < 300) {
@@ -82,8 +96,8 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
82
96
  if (e.modifiers?.alt) {
83
97
  dragStartX = e.x;
84
98
  dragStartY = e.y;
85
- dragAnchorX = posX();
86
- dragAnchorY = posY();
99
+ dragAnchorX = curX;
100
+ dragAnchorY = curY;
87
101
  isDragging = true;
88
102
  renderers[currentName()].setDragging(true);
89
103
  props.api.renderer.clearSelection();
@@ -91,8 +105,9 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
91
105
  }}
92
106
  onMouseDrag={(e: any) => {
93
107
  if (e.modifiers?.alt && isDragging) {
94
- setPosX(dragAnchorX + (e.x - dragStartX));
95
- setPosY(dragAnchorY + (e.y - dragStartY));
108
+ curX = dragAnchorX + (e.x - dragStartX);
109
+ curY = dragAnchorY + (e.y - dragStartY);
110
+ applyPos();
96
111
  }
97
112
  }}
98
113
  onMouseUp={() => { stopDrag(); }}