@mingxy/opencode-mascot 0.3.9 → 0.4.1

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.9",
3
+ "version": "0.4.1",
4
4
  "description": "OpenCode TUI mascot plugin framework - customizable ASCII mascots for your terminal",
5
5
  "author": "mingxy",
6
6
  "license": "MIT",
@@ -20,7 +20,8 @@ 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
- let boxRef: any = null;
23
+ const [posX, setPosX] = createSignal(0);
24
+ const [posY, setPosY] = createSignal(0);
24
25
  let dragStartX = 0;
25
26
  let dragStartY = 0;
26
27
  let dragAnchorX = 0;
@@ -47,52 +48,55 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
47
48
  renderers[currentName()].showVersion(version);
48
49
  });
49
50
 
51
+ const stopDrag = () => {
52
+ isDragging = false;
53
+ renderers[currentName()].setDragging(false);
54
+ };
55
+
50
56
  return (
51
- <box
52
- alignItems="center"
53
- zIndex={9999}
54
- flexDirection="column"
55
- ref={(node: any) => { boxRef = node; }}
56
- onMouseDown={(e: any) => {
57
- const now = Date.now();
58
- if (now - lastClickTime < 300) {
59
- switchToNext();
60
- lastClickTime = 0;
61
- return;
62
- }
63
- lastClickTime = now;
57
+ <box height={5} zIndex={9999}>
58
+ <box
59
+ position="absolute"
60
+ left={posX()}
61
+ top={posY()}
62
+ alignItems="center"
63
+ flexDirection="column"
64
+ onMouseDown={(e: any) => {
65
+ const now = Date.now();
66
+ if (now - lastClickTime < 300) {
67
+ switchToNext();
68
+ lastClickTime = 0;
69
+ return;
70
+ }
71
+ lastClickTime = now;
64
72
 
65
- if (e.modifiers?.alt && boxRef) {
66
- dragStartX = e.x;
67
- dragStartY = e.y;
68
- dragAnchorX = boxRef.translateX || 0;
69
- dragAnchorY = boxRef.translateY || 0;
70
- isDragging = true;
71
- renderers[currentName()].setDragging(true);
72
- }
73
- }}
74
- onMouseDrag={(e: any) => {
75
- if (e.modifiers?.alt && isDragging && boxRef) {
76
- boxRef.translateX = dragAnchorX + (e.x - dragStartX);
77
- boxRef.translateY = dragAnchorY + (e.y - dragStartY);
78
- }
79
- }}
80
- onMouseUp={() => {
81
- isDragging = false;
82
- renderers[currentName()].setDragging(false);
83
- }}
84
- onMouseDragEnd={() => {
85
- isDragging = false;
86
- renderers[currentName()].setDragging(false);
87
- }}
88
- onMouseOut={() => {
89
- if (isDragging) {
90
- isDragging = false;
91
- renderers[currentName()].setDragging(false);
92
- }
93
- }}
94
- >
95
- {renderers[currentName()]?.element() ?? null}
73
+ if (e.modifiers?.alt) {
74
+ dragStartX = e.x;
75
+ dragStartY = e.y;
76
+ dragAnchorX = posX();
77
+ dragAnchorY = posY();
78
+ isDragging = true;
79
+ renderers[currentName()].setDragging(true);
80
+ e.preventDefault();
81
+ e.stopPropagation();
82
+ props.api.renderer.clearSelection();
83
+ }
84
+ }}
85
+ onMouseDrag={(e: any) => {
86
+ if (e.modifiers?.alt && isDragging) {
87
+ setPosX(dragAnchorX + (e.x - dragStartX));
88
+ setPosY(dragAnchorY + (e.y - dragStartY));
89
+ e.preventDefault();
90
+ e.stopPropagation();
91
+ props.api.renderer.clearSelection();
92
+ }
93
+ }}
94
+ onMouseUp={() => { stopDrag(); }}
95
+ onMouseDragEnd={() => { stopDrag(); }}
96
+ onMouseOut={() => { stopDrag(); }}
97
+ >
98
+ {renderers[currentName()]?.element() ?? null}
99
+ </box>
96
100
  </box>
97
101
  );
98
102
  }
@@ -225,6 +225,9 @@ 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
+ e.stopPropagation();
230
+ props.api.renderer.clearSelection();
228
231
  }
229
232
  }}
230
233
  onMouseUp={() => {
@@ -315,14 +315,12 @@ export function createAnimatedRenderer(pack: MascotPack): {
315
315
  const dm = dragMsg();
316
316
 
317
317
  return (
318
- <box flexDirection="column" width={10} overflow="visible" left={left} top={top}>
319
- {cel ? <text fg={flashColor() ?? fg} selectable={false}>{cel.text}</text> : null}
320
- {dm ? <text fg="#FF4081" selectable={false}>{dm}</text> : null}
321
- <box flexDirection="column" width={10} alignItems="flex-start">
322
- {lines.map((line: string) => (
323
- <text fg={flashColor() ?? fg} selectable={false}>{line}</text>
324
- ))}
325
- </box>
318
+ <box flexDirection="column" left={left} top={top}>
319
+ {cel ? <text fg={flashColor() ?? fg}>{cel.text}</text> : null}
320
+ {dm ? <text fg="#FF4081">{dm}</text> : null}
321
+ {lines.map((line: string) => (
322
+ <text fg={flashColor() ?? fg}>{line}</text>
323
+ ))}
326
324
  </box>
327
325
  );
328
326
  };