@mingxy/opencode-mascot 0.3.2 → 0.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/opencode-mascot",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "OpenCode TUI mascot plugin framework - customizable ASCII mascots for your terminal",
5
5
  "author": "mingxy",
6
6
  "license": "MIT",
@@ -20,8 +20,7 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
20
20
  const initialName = names[Math.floor(Math.random() * names.length)];
21
21
 
22
22
  const [currentName, setCurrentName] = createSignal(initialName);
23
- const [posX, setPosX] = createSignal(0);
24
- const [posY, setPosY] = createSignal(0);
23
+ let boxRef: any = null;
25
24
  let dragStartX = 0;
26
25
  let dragStartY = 0;
27
26
  let dragAnchorX = 0;
@@ -49,16 +48,12 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
49
48
  });
50
49
 
51
50
  return (
52
- <box flexDirection="column" alignItems="center">
53
- <box height={5} width={10} />
54
- <box
55
- position="absolute"
56
- left={posX()}
57
- top={posY()}
58
- alignItems="center"
59
- zIndex={100}
60
- flexDirection="column"
61
- onMouseDown={(e: any) => {
51
+ <box
52
+ alignItems="center"
53
+ zIndex={100}
54
+ flexDirection="column"
55
+ ref={(node: any) => { boxRef = node; }}
56
+ onMouseDown={(e: any) => {
62
57
  const now = Date.now();
63
58
  if (now - lastClickTime < 300) {
64
59
  switchToNext();
@@ -67,11 +62,11 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
67
62
  }
68
63
  lastClickTime = now;
69
64
 
70
- if (e.modifiers?.alt) {
65
+ if (e.modifiers?.alt && boxRef) {
71
66
  dragStartX = e.x;
72
67
  dragStartY = e.y;
73
- dragAnchorX = posX();
74
- dragAnchorY = posY();
68
+ dragAnchorX = boxRef.translateX || 0;
69
+ dragAnchorY = boxRef.translateY || 0;
75
70
  isDragging = true;
76
71
  renderers[currentName()].setDragging(true);
77
72
  e.preventDefault();
@@ -80,11 +75,9 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
80
75
  }
81
76
  }}
82
77
  onMouseDrag={(e: any) => {
83
- if (e.modifiers?.alt && isDragging) {
84
- setPosX(dragAnchorX + (e.x - dragStartX));
85
- setPosY(dragAnchorY + (e.y - dragStartY));
86
- e.preventDefault();
87
- props.api.renderer.clearSelection();
78
+ if (e.modifiers?.alt && isDragging && boxRef) {
79
+ boxRef.translateX = dragAnchorX + (e.x - dragStartX);
80
+ boxRef.translateY = dragAnchorY + (e.y - dragStartY);
88
81
  }
89
82
  }}
90
83
  onMouseUp={() => {
@@ -103,7 +96,6 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
103
96
  }}
104
97
  >
105
98
  {renderers[currentName()]?.element() ?? null}
106
- </box>
107
99
  </box>
108
100
  );
109
101
  }
@@ -225,8 +225,6 @@ export function SidebarMascot(props: SidebarMascotProps): JSX.Element {
225
225
  if (e.modifiers?.alt && isDragging) {
226
226
  setPosX(clampX(dragAnchorX + (e.x - dragStartX)));
227
227
  setPosY(clampY(dragAnchorY + (e.y - dragStartY)));
228
- e.preventDefault();
229
- props.api.renderer.clearSelection();
230
228
  }
231
229
  }}
232
230
  onMouseUp={() => {