@mingxy/opencode-mascot 0.4.23 → 0.4.25
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
|
@@ -5,7 +5,6 @@ import type { JSX } from "@opentui/solid";
|
|
|
5
5
|
import type { MascotPack } from "../core/types";
|
|
6
6
|
import { createAnimatedRenderer } from "../core/ascii-renderer";
|
|
7
7
|
import { onCelebrate, onVersion } from "../core/celebration-bus";
|
|
8
|
-
import { log } from "../core/logger";
|
|
9
8
|
|
|
10
9
|
interface HomeMascotProps {
|
|
11
10
|
mascots: Record<string, MascotPack>;
|
|
@@ -20,9 +19,11 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
|
|
|
20
19
|
const names = Object.keys(props.mascots);
|
|
21
20
|
const initialName = names[Math.floor(Math.random() * names.length)];
|
|
22
21
|
|
|
22
|
+
const cw = (typeof process !== "undefined" && process.stdout?.columns) || 80;
|
|
23
|
+
|
|
23
24
|
const [currentName, setCurrentName] = createSignal(initialName);
|
|
24
|
-
const [posX, setPosX] = createSignal(0);
|
|
25
|
-
const [posY, setPosY] = createSignal(
|
|
25
|
+
const [posX, setPosX] = createSignal(Math.floor(Math.random() * Math.max(0, cw - 20)));
|
|
26
|
+
const [posY, setPosY] = createSignal(Math.floor(Math.random() * 3));
|
|
26
27
|
const [zBoost, setZBoost] = createSignal(false);
|
|
27
28
|
let dragStartX = 0;
|
|
28
29
|
let dragStartY = 0;
|
|
@@ -66,7 +67,6 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
|
|
|
66
67
|
zIndex={zBoost() ? 9999 : 100}
|
|
67
68
|
flexDirection="column"
|
|
68
69
|
onMouseDown={(e: any) => {
|
|
69
|
-
log("MOUSE", `down x=${e.x} y=${e.y} alt=${!!e.modifiers?.alt} btn=${e.button}`);
|
|
70
70
|
const now = Date.now();
|
|
71
71
|
if (now - lastClickTime < 300) {
|
|
72
72
|
switchToNext();
|
|
@@ -81,22 +81,18 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
|
|
|
81
81
|
dragAnchorX = posX();
|
|
82
82
|
dragAnchorY = posY();
|
|
83
83
|
isDragging = true;
|
|
84
|
-
log("DRAG", `start anchorX=${dragAnchorX} anchorY=${dragAnchorY} startX=${dragStartX} startY=${dragStartY}`);
|
|
85
84
|
renderers[currentName()].setDragging(true);
|
|
86
85
|
props.api.renderer.clearSelection();
|
|
87
86
|
}
|
|
88
87
|
}}
|
|
89
88
|
onMouseDrag={(e: any) => {
|
|
90
|
-
if (isDragging) {
|
|
91
|
-
log("MOUSE", `drag x=${e.x} y=${e.y} alt=${!!e.modifiers?.alt} dx=${e.x - dragStartX} dy=${e.y - dragStartY}`);
|
|
92
|
-
}
|
|
93
89
|
if (e.modifiers?.alt && isDragging) {
|
|
94
90
|
setPosX(dragAnchorX + (e.x - dragStartX));
|
|
95
91
|
setPosY(dragAnchorY + (e.y - dragStartY));
|
|
96
92
|
}
|
|
97
93
|
}}
|
|
98
|
-
onMouseUp={() => {
|
|
99
|
-
onMouseDragEnd={() => {
|
|
94
|
+
onMouseUp={() => { stopDrag(); }}
|
|
95
|
+
onMouseDragEnd={() => { stopDrag(); }}
|
|
100
96
|
>
|
|
101
97
|
{renderers[currentName()]?.element() ?? null}
|
|
102
98
|
</box>
|
|
@@ -187,9 +187,12 @@ export function SidebarMascot(props: SidebarMascotProps): JSX.Element {
|
|
|
187
187
|
|
|
188
188
|
return (
|
|
189
189
|
<box
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
position="absolute"
|
|
191
|
+
left={posX()}
|
|
192
|
+
top={posY()}
|
|
193
|
+
alignItems="center"
|
|
194
|
+
zIndex={zBoost() ? 9999 : 100}
|
|
195
|
+
flexDirection="column"
|
|
193
196
|
ref={(node: any) => {
|
|
194
197
|
if (node) {
|
|
195
198
|
setContainerWidth(node.width || 0);
|
|
@@ -200,54 +203,45 @@ export function SidebarMascot(props: SidebarMascotProps): JSX.Element {
|
|
|
200
203
|
}
|
|
201
204
|
}
|
|
202
205
|
}}
|
|
206
|
+
onMouseDown={(e: any) => {
|
|
207
|
+
if (hideSide) { returnToView(); return; }
|
|
208
|
+
|
|
209
|
+
const now = Date.now();
|
|
210
|
+
if (now - lastClickTime < 300) {
|
|
211
|
+
switchToNext();
|
|
212
|
+
lastClickTime = 0;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
lastClickTime = now;
|
|
216
|
+
|
|
217
|
+
if (e.modifiers?.alt) {
|
|
218
|
+
dragStartX = e.x;
|
|
219
|
+
dragStartY = e.y;
|
|
220
|
+
dragAnchorX = posX();
|
|
221
|
+
dragAnchorY = posY();
|
|
222
|
+
isDragging = true;
|
|
223
|
+
renderers[currentName()].setDragging(true);
|
|
224
|
+
props.api.renderer.clearSelection();
|
|
225
|
+
}
|
|
226
|
+
}}
|
|
227
|
+
onMouseDrag={(e: any) => {
|
|
228
|
+
if (e.modifiers?.alt && isDragging) {
|
|
229
|
+
setPosX(clampX(dragAnchorX + (e.x - dragStartX)));
|
|
230
|
+
setPosY(clampY(dragAnchorY + (e.y - dragStartY)));
|
|
231
|
+
}
|
|
232
|
+
}}
|
|
233
|
+
onMouseUp={() => {
|
|
234
|
+
isDragging = false;
|
|
235
|
+
renderers[currentName()].setDragging(false);
|
|
236
|
+
checkEdge();
|
|
237
|
+
}}
|
|
238
|
+
onMouseDragEnd={() => {
|
|
239
|
+
isDragging = false;
|
|
240
|
+
renderers[currentName()].setDragging(false);
|
|
241
|
+
checkEdge();
|
|
242
|
+
}}
|
|
203
243
|
>
|
|
204
|
-
|
|
205
|
-
position="absolute"
|
|
206
|
-
left={posX()}
|
|
207
|
-
top={posY()}
|
|
208
|
-
alignItems="center"
|
|
209
|
-
zIndex={zBoost() ? 9999 : 100}
|
|
210
|
-
flexDirection="column"
|
|
211
|
-
onMouseDown={(e: any) => {
|
|
212
|
-
if (hideSide) { returnToView(); return; }
|
|
213
|
-
|
|
214
|
-
const now = Date.now();
|
|
215
|
-
if (now - lastClickTime < 300) {
|
|
216
|
-
switchToNext();
|
|
217
|
-
lastClickTime = 0;
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
lastClickTime = now;
|
|
221
|
-
|
|
222
|
-
if (e.modifiers?.alt) {
|
|
223
|
-
dragStartX = e.x;
|
|
224
|
-
dragStartY = e.y;
|
|
225
|
-
dragAnchorX = posX();
|
|
226
|
-
dragAnchorY = posY();
|
|
227
|
-
isDragging = true;
|
|
228
|
-
renderers[currentName()].setDragging(true);
|
|
229
|
-
props.api.renderer.clearSelection();
|
|
230
|
-
}
|
|
231
|
-
}}
|
|
232
|
-
onMouseDrag={(e: any) => {
|
|
233
|
-
if (e.modifiers?.alt && isDragging) {
|
|
234
|
-
setPosX(clampX(dragAnchorX + (e.x - dragStartX)));
|
|
235
|
-
setPosY(clampY(dragAnchorY + (e.y - dragStartY)));
|
|
236
|
-
}
|
|
237
|
-
}}
|
|
238
|
-
onMouseUp={() => {
|
|
239
|
-
isDragging = false;
|
|
240
|
-
renderers[currentName()].setDragging(false);
|
|
241
|
-
checkEdge();
|
|
242
|
-
}}
|
|
243
|
-
onMouseDragEnd={() => {
|
|
244
|
-
isDragging = false;
|
|
245
|
-
renderers[currentName()].setDragging(false);
|
|
246
|
-
checkEdge();
|
|
247
|
-
}}
|
|
248
|
-
>
|
|
249
|
-
{renderers[currentName()]?.element() ?? null}
|
|
250
|
-
</box>
|
|
244
|
+
{renderers[currentName()]?.element() ?? null}
|
|
251
245
|
</box>
|
|
252
246
|
);
|
|
253
247
|
}
|